Commit ca000edb authored by Sietse Ringers's avatar Sietse Ringers
Browse files

feat: enforce correctness of conjunctions in session requests

Within an inner conjunction of a session request, distinct attributes that come
from the same credential type must always be adjacent. This is now enforced in
the irmaclient and server packages when receiving session requests.
parent 3a09637f
...@@ -204,6 +204,24 @@ func (c AttributeCon) CredentialTypes() []CredentialTypeIdentifier { ...@@ -204,6 +204,24 @@ func (c AttributeCon) CredentialTypes() []CredentialTypeIdentifier {
return result return result
} }
func (c AttributeCon) Validate() error {
// Unlike AttributeDisCon, we don't have to check here that the current instance is of length 0,
// as that is actually a valid conjunction: one that specifies that the containing disjunction
// is optional.
credtypes := map[CredentialTypeIdentifier]struct{}{}
var last CredentialTypeIdentifier
for _, attr := range c {
typ := attr.Type.CredentialTypeIdentifier()
if _, contains := credtypes[typ]; contains && last != typ {
return errors.New("Within inner conjunctions, attributes from the same credential type must be adjacent")
}
last = typ
credtypes[typ] = struct{}{}
}
return nil
}
func (c *AttributeCon) MarshalJSON() ([]byte, error) { func (c *AttributeCon) MarshalJSON() ([]byte, error) {
var vals bool var vals bool
m := map[AttributeTypeIdentifier]*string{} m := map[AttributeTypeIdentifier]*string{}
...@@ -280,6 +298,19 @@ func (c AttributeCon) Satisfy(proofs gabi.ProofList, indices []*DisclosedAttribu ...@@ -280,6 +298,19 @@ func (c AttributeCon) Satisfy(proofs gabi.ProofList, indices []*DisclosedAttribu
return true, attrs, nil return true, attrs, nil
} }
func (dc AttributeDisCon) Validate() error {
if len(dc) == 0 {
return errors.New("Empty disjunction")
}
var err error
for _, con := range dc {
if err = con.Validate(); err != nil {
return err
}
}
return nil
}
func (dc AttributeDisCon) Satisfy(proofs gabi.ProofList, indices []*DisclosedAttributeIndex, conf *Configuration) (bool, []*DisclosedAttribute, error) { func (dc AttributeDisCon) Satisfy(proofs gabi.ProofList, indices []*DisclosedAttributeIndex, conf *Configuration) (bool, []*DisclosedAttribute, error) {
for _, con := range dc { for _, con := range dc {
satisfied, attrs, err := con.Satisfy(proofs, indices, conf) satisfied, attrs, err := con.Satisfy(proofs, indices, conf)
...@@ -417,9 +448,10 @@ func (dr *DisclosureRequest) Validate() error { ...@@ -417,9 +448,10 @@ func (dr *DisclosureRequest) Validate() error {
if len(dr.Disclose) == 0 { if len(dr.Disclose) == 0 {
return errors.New("Disclosure request had no attributes") return errors.New("Disclosure request had no attributes")
} }
var err error
for _, discon := range dr.Disclose { for _, discon := range dr.Disclose {
if len(discon) == 0 { if err = discon.Validate(); err != nil {
return errors.New("Empty disjunction") return err
} }
} }
return nil return nil
...@@ -552,6 +584,12 @@ func (ir *IssuanceRequest) Validate() error { ...@@ -552,6 +584,12 @@ func (ir *IssuanceRequest) Validate() error {
return errors.New("Expired credential request") return errors.New("Expired credential request")
} }
} }
var err error
for _, discon := range ir.Disclose {
if err = discon.Validate(); err != nil {
return err
}
}
return nil return nil
} }
...@@ -595,9 +633,10 @@ func (sr *SignatureRequest) Validate() error { ...@@ -595,9 +633,10 @@ func (sr *SignatureRequest) Validate() error {
if len(sr.Disclose) == 0 { if len(sr.Disclose) == 0 {
return errors.New("Signature request had no attributes") return errors.New("Signature request had no attributes")
} }
var err error
for _, discon := range sr.Disclose { for _, discon := range sr.Disclose {
if len(discon) == 0 { if err = discon.Validate(); err != nil {
return errors.New("Empty disjunction") return err
} }
} }
return nil return nil
......
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