Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 0cffabc

Browse files
Added readme section and todos properly (#379)
1 parent 42074c8 commit 0cffabc

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

sd-jwt/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ See the [SDK Building](../README.md#building) section.
5858

5959
## Contributing
6060
See the general [CONTRIBUTING](../CONTRIBUTING.md) guide.
61+
62+
## Issues
63+
See current issues [here](https://github.com/TBD54566975/ssi-sdk/issues?q=is%3Aissue+is%3Aopen+label%3Asd-jwt).

sd-jwt/sd_jwt.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import (
1818
"github.com/pkg/errors"
1919
)
2020

21+
const (
22+
sdClaimName = "_sd"
23+
sdAlgClaimName = "_sd_alg"
24+
sha256Alg = "sha-256"
25+
)
26+
2127
// CreatePresentation creates the Combined Format for Presentation as specified in https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-04.html#name-combined-format-for-present
2228
// jwtAndDisclosures is a Combined Format for Issuance as specified in https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-04.html#name-combined-format-for-issuanc.
2329
// disclosuresToPresent is a set of which the indices of the disclosures that the presentation should contain.
@@ -244,8 +250,7 @@ func (csb claimSetBlinder) toBlindedClaimsAndDisclosures(
244250
hashedDisclosures[i], hashedDisclosures[j] = hashedDisclosures[j], hashedDisclosures[i]
245251
})
246252

247-
//TODO: Add holder binding as specified in RFC7800
248-
blindedClaims["_sd"] = hashedDisclosures
253+
blindedClaims[sdClaimName] = hashedDisclosures
249254
return blindedClaims, allDisclosures, nil
250255
}
251256

@@ -287,7 +292,7 @@ func (s SDJWTSigner) BlindAndSign(claimsData []byte, claimsToBlind map[string]Bl
287292
return nil, errors.Wrap(err, "blinding claims")
288293
}
289294

290-
blindedClaims["_sd_alg"] = "sha-256"
295+
blindedClaims[sdAlgClaimName] = sha256Alg
291296
blindedClaimsData, err := json.Marshal(blindedClaims)
292297
if err != nil {
293298
return nil, errors.Wrap(err, "marshalling blinded claims")
@@ -316,9 +321,9 @@ func sha256Digest(data []byte) []byte {
316321

317322
// GetHashAlg returns the hashFunc specified in the token.
318323
func GetHashAlg(t jwt.Token) (HashFunc, error) {
319-
hashName := "sha-256"
324+
hashName := sha256Alg
320325
if t != nil {
321-
if hashNameValue, ok := t.Get("_sd_alg"); ok {
326+
if hashNameValue, ok := t.Get(sdAlgClaimName); ok {
322327
hashName, ok = hashNameValue.(string)
323328
if !ok {
324329
return nil, errors.New("converting _sd_alg claim value to string")
@@ -327,7 +332,7 @@ func GetHashAlg(t jwt.Token) (HashFunc, error) {
327332
}
328333

329334
switch hashName {
330-
case "sha-256":
335+
case sha256Alg:
331336
return sha256Digest, nil
332337
default:
333338
return nil, errors.Errorf("unsupported hash name %q", hashName)
@@ -419,13 +424,13 @@ type VerificationOptions struct {
419424
alg string
420425
issuerKey any
421426
desiredNonce, desiredAudience string
422-
resolveHolderKey func(jwt.Token) any
427+
resolveHolderKey func(jwt.Token) gocrypto.PublicKey
423428
}
424429

425430
// VerifySDPresentation takes in a combined presentation format as defined in https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-04.html#name-combined-format-for-present
426431
// and Verifies it according to https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-04.html#name-verification-by-the-verifie
427432
// Succesful verifications return a processed SD-JWT payload.
428-
// TODO: only accept certain algos for validating the JWT, and the holder binding JWT
433+
// TODO(https://github.com/TBD54566975/ssi-sdk/issues/378): only accept certain algos for validating the JWT, and the holder binding JWT
429434
func VerifySDPresentation(presentation []byte, verificationOptions VerificationOptions) (map[string]any, error) {
430435
// 2. Separate the Presentation into the SD-JWT, the Disclosures (if any), and the Holder Binding JWT (if provided).
431436
sdParts := strings.Split(string(presentation), "~")
@@ -477,7 +482,7 @@ func VerifySDPresentation(presentation []byte, verificationOptions VerificationO
477482
holderKey := verificationOptions.resolveHolderKey(sdToken)
478483

479484
//Ensure that a signing algorithm was used that was deemed secure for the application. Refer to [RFC8725], Sections 3.1 and 3.2 for details. The none algorithm MUST NOT be accepted.
480-
// TODO: get the algo from the cnf
485+
//TODO(https://github.com/TBD54566975/ssi-sdk/issues/377): support holder binding properly as specified in RFC7800. Alg should be coming from CNF.
481486
holderBindingAlg := jwa.ES256K
482487

483488
//Validate the signature over the Holder Binding JWT.
@@ -523,7 +528,7 @@ func processPayload(claims map[string]any, disclosuresByDigest map[string]*Discl
523528
}
524529
}
525530
}
526-
sdClaimValue, ok := claims["_sd"]
531+
sdClaimValue, ok := claims[sdClaimName]
527532
if !ok {
528533
return nil
529534
}
@@ -569,8 +574,8 @@ func processPayload(claims map[string]any, disclosuresByDigest map[string]*Discl
569574
}
570575
}
571576

572-
delete(claims, "_sd")
573-
delete(claims, "_sd_alg")
577+
delete(claims, sdClaimName)
578+
delete(claims, sdAlgClaimName)
574579
for k, v := range newClaims {
575580
claims[k] = v
576581
}
@@ -651,7 +656,7 @@ func getDigestsForSlice(c []any) []string {
651656
func getDigestsForMap(c map[string]any) []string {
652657
var digests []string
653658
for k, v := range c {
654-
if k == "_sd" {
659+
if k == sdClaimName {
655660
for _, vv := range v.([]any) {
656661
digests = append(digests, vv.(string))
657662
}

0 commit comments

Comments
 (0)