Skip to content

Commit

Permalink
Validate UZI number before credential creation
Browse files Browse the repository at this point in the history
Moved UZI number validation to check before generating uraCredential, ensuring serialNumber matches UZI number early in the process. Also removed redundant serialNumber parameter from uraCredential function.
  • Loading branch information
rolandgroen committed Nov 1, 2024
1 parent 956e42c commit 8b1feb5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions uzi_vc_issuer/ura_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ func BuildUraVerifiableCredential(chain []*x509.Certificate, signingKey *rsa.Pri
if err != nil {
return nil, err
}
template, err := uraCredential(did, otherNameValue, serialNumber, subjectDID)
uzi, _, _, err := x509_cert.ParseUraFromOtherNameValue(otherNameValue)
if err != nil {
return nil, err
}
if uzi != serialNumber {
return nil, errors.New("serial number does not match UZI number")
}
template, err := uraCredential(did, otherNameValue, subjectDID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -255,16 +262,9 @@ func convertHeaders(headers map[string]interface{}) (jws.Headers, error) {

// uraCredential generates a VerifiableCredential for a given URA and UZI number, including the subject's DID.
// It sets a 1-year expiration period from the current issuance date.
func uraCredential(issuer string, otherNameValue string, serialNumber string, subjectDID string) (*vc.VerifiableCredential, error) {
func uraCredential(issuer string, otherNameValue string, subjectDID string) (*vc.VerifiableCredential, error) {
exp := time.Now().Add(time.Hour * 24 * 365 * 100)
iat := time.Now()
uzi, _, _, err := x509_cert.ParseUraFromOtherNameValue(otherNameValue)
if err != nil {
return nil, err
}
if uzi != serialNumber {
return nil, errors.New("serial number does not match UZI number")
}
return &vc.VerifiableCredential{
Issuer: ssi.MustParseURI(issuer),
Context: []ssi.URI{ssi.MustParseURI("https://www.w3.org/2018/credentials/v1")},
Expand All @@ -274,9 +274,8 @@ func uraCredential(issuer string, otherNameValue string, serialNumber string, su
ExpirationDate: &exp,
CredentialSubject: []interface{}{
map[string]interface{}{
"id": subjectDID,
"serialNumber": serialNumber,
"otherName": otherNameValue,
"id": subjectDID,
"otherName": otherNameValue,
},
},
}, nil
Expand Down

0 comments on commit 8b1feb5

Please sign in to comment.