Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

feat: DID schema to support publicKeyJwk & secp256k1 #1510

Merged
merged 1 commit into from Mar 25, 2020

Conversation

sudeshrshetty
Copy link
Contributor

  • PublicKeys to support publicKeyJwk
  • Support for JWK public key decode including secp256k1
  • Context URI updated to validate https://www.w3.org/ns/did/v1 as well
    as the older URI https://w3id.org/did/v1
  • Removed public key max number of properties validation, as per spec
    'The public key objects MAY include additional properties'
  • closes DID Schema: Support publicKeyJwk #1509

Signed-off-by: sudesh.shetty sudesh.shetty@securekey.com

go.sum Show resolved Hide resolved
return nil, fmt.Errorf("unable to read JWK, %w", err)
}

if strings.EqualFold(key.Kty, secp256k1Kty) && strings.EqualFold(key.Crv, secp256k1Crv) {
Copy link
Contributor

@troyronda troyronda Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments on the various conditions in this function would be helpful (linked to the JWK data model).

(this very specific case seems a bit suspicious).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other cases we aren't covering yet?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more generic, I would override UnmarshalJSON() of JWK to support secp256k1 elliptic curve (MarshallJSON() for symmetry). And I would create e.g. Bytes() method returning []byte for JWK as well where x509.MarshalPKIXPublicKey() could be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sudeshrshetty the above is just my personal opinion, I'm OK with your solution in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@troyronda almost all cases are covered by go-jose, my implementation only covers 'EC/secp256k1', rest of the types will be handled by go-jose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdimak sounds good actually, I agree. I will add that as part of upcoming PR. Created an issue #1513 for this.

}
}

func ecPublicKey(xBuffer, yBuffer *byteBuffer) ([]byte, error) {
Copy link
Contributor

@baha-ai baha-ai Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this function to btcPublicKey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"kid": "sample@sample.id",
"x": "wQehEGTVCu32yp8IwTaBCqPUIYslyd-WoFRsfDKE9II",
"y": "rIJO8RmkExUecJ5i15L9OC7rl7pwmYFR8QQgdM1ERWI",
"alg": "EdDSA"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right: "alg": "EdDSA"
with
"crv": "secp256k1",

secp256k1 is an ECDSA curve to my knowledge. We only support Ed25519 as EdDSA curve.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's only sample input I generated for tests, you are right EdDSA also works.

"kid": "sample@sample.id",
"x": "wQehEGTVCu32yp8IwTaBCqPUIYslyd-WoFRsfDKE9II",
"y": "",
"alg": "EdDSA"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, alg is ignored by JWK parser since it uses 'kty=EC' and logic based on curve, I fixed tests by regenerating JWK using ES256(ECDSA using P-256)

"kid": "sample@sample.id",
"x": "",
"y": "",
"alg": "EdDSA"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

"kid": "sample@sample.id",
"x": "x",
"y": "y",
"alg": "EdDSA"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

"kid": "sample@sample.id",
"x": "{",
"y": "y",
"alg": "EdDSA"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.. I think we need a mapping validation between alg and crv as they're related

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see a validation check between crv and alg that we currently support as follows:
ECDSA crv is valid only for P-256, P-384, P-521 and secp256k1 algs
EdDSA crv is valid only for Ed25519 alg

If we wanna support other key algs, we should add them to the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, go-jose library is doing that, I just branched out my logic when I see 'kty=EC,crv=secp256k1'. 'alg' is not mandatory field in jwk if crv/ec are explanatory enough.

@codecov
Copy link

codecov bot commented Mar 25, 2020

Codecov Report

Merging #1510 into master will decrease coverage by 0.04%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1510      +/-   ##
==========================================
- Coverage   91.32%   91.27%   -0.05%     
==========================================
  Files         150      151       +1     
  Lines       10219    10285      +66     
==========================================
+ Hits         9332     9388      +56     
- Misses        511      517       +6     
- Partials      376      380       +4     
Impacted Files Coverage Δ
pkg/doc/jose/jws.go 94.63% <ø> (-0.31%) ⬇️
pkg/doc/did/doc.go 91.61% <66.66%> (-1.01%) ⬇️
pkg/doc/jose/jwk.go 90.47% <90.47%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8af7f59...d83de36. Read the comment docs.

- PublicKeys to support `publicKeyJwk`
- Support for JWK public key decode including `secp256k1`
- Context URI updated to validate `https://www.w3.org/ns/did/v1` as well
as the older URI `https://w3id.org/did/v1`
- Removed public key max number of  properties validation, as per spec
'The public key objects MAY include additional properties'
- closes hyperledger-archives#1509

Signed-off-by: sudesh.shetty <sudesh.shetty@securekey.com>
@troyronda troyronda merged commit 2d68a48 into hyperledger-archives:master Mar 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

DID Schema: Support publicKeyJwk
5 participants