Commit 993d43bf authored by Sietse Ringers's avatar Sietse Ringers

refactor: add JSON-LD @context in attribute-based signatures

parent b1129984
......@@ -11,18 +11,25 @@ import (
"github.com/privacybydesign/gabi/big"
)
const SignedMessageLDContext = "https://irma.app/ld/signature/v2"
// SignedMessage is a message signed with an attribute-based signature
// The 'realnonce' will be calculated as: SigRequest.GetNonce() = ASN1(nonce, SHA256(message), timestampSignature)
type SignedMessage struct {
LDContext string `json:"@context"`
Signature gabi.ProofList `json:"signature"`
Indices DisclosedAttributeIndices `json:"indices"`
Nonce *big.Int `json:"nonce"`
Context *big.Int `json:"context"`
Message string `json:"message"`
Timestamp *atum.Timestamp `json:"timestamp"`
}
// Message version. Current version is 2.
Version int `json:"v,omitempty"`
func (sm *SignedMessage) Version() int {
if sm.LDContext == "" {
return 1
}
return 2
}
func (sm *SignedMessage) GetNonce() *big.Int {
......
......@@ -20,10 +20,10 @@ type LogEntry struct {
request irma.SessionRequest // cached parsed version of Request; get with LogEntry.SessionRequest()
// Session type-specific info
Removed map[irma.CredentialTypeIdentifier][]irma.TranslatedString `json:",omitempty"` // In case of credential removal
SignedMessage []byte `json:",omitempty"` // In case of signature sessions
Timestamp *atum.Timestamp `json:",omitempty"` // In case of signature sessions
SignatureVersion int `json:",omitempty"` // In case of signature sessions
Removed map[irma.CredentialTypeIdentifier][]irma.TranslatedString `json:",omitempty"` // In case of credential removal
SignedMessage []byte `json:",omitempty"` // In case of signature sessions
Timestamp *atum.Timestamp `json:",omitempty"` // In case of signature sessions
SignedMessageLDContext string `json:",omitempty"` // In case of signature sessions
IssueCommitment *irma.IssueCommitmentMessage `json:",omitempty"`
Disclosure *irma.Disclosure `json:",omitempty"`
......@@ -106,12 +106,12 @@ func (entry *LogEntry) GetSignedMessage() (abs *irma.SignedMessage, err error) {
}
sigrequest := request.(*irma.SignatureRequest)
return &irma.SignedMessage{
LDContext: entry.SignedMessageLDContext,
Signature: entry.Disclosure.Proofs,
Nonce: sigrequest.Nonce,
Context: sigrequest.Context,
Message: string(entry.SignedMessage),
Timestamp: entry.Timestamp,
Version: entry.SignatureVersion,
}, nil
}
......@@ -135,7 +135,7 @@ func (session *session) createLogEntry(response interface{}) (*LogEntry, error)
request := session.request.(*irma.SignatureRequest)
entry.SignedMessage = []byte(request.Message)
entry.Timestamp = request.Timestamp
entry.SignatureVersion = 2
entry.SignedMessageLDContext = irma.SignedMessageLDContext
fallthrough
case irma.ActionDisclosing:
......
......@@ -433,13 +433,13 @@ func (sr *SignatureRequest) SignatureFromMessage(message interface{}) (*SignedMe
}
return &SignedMessage{
LDContext: SignedMessageLDContext,
Signature: signature.Proofs,
Indices: signature.Indices,
Nonce: sr.Nonce,
Context: sr.Context,
Message: sr.Message,
Timestamp: sr.Timestamp,
Version: 2,
}, nil
}
......
......@@ -114,7 +114,7 @@ func (sm *SignedMessage) VerifyTimestamp(message string, conf *Configuration) er
}
}
bts, err := TimestampRequest(message, sigs, disclosed, sm.Version >= 2, conf)
bts, err := TimestampRequest(message, sigs, disclosed, sm.Version() >= 2, conf)
if err != nil {
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment