-
Notifications
You must be signed in to change notification settings - Fork 293
Add support for COSE keys and key sets #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: marco/pkix
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -63,6 +63,11 @@ enum KeyType { | |||||||||||||||||||||||||||||||||||||
| Ed25519 = 1; | ||||||||||||||||||||||||||||||||||||||
| Secp256k1 = 2; | ||||||||||||||||||||||||||||||||||||||
| ECDSA = 3; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| PKIX = 0x40; | ||||||||||||||||||||||||||||||||||||||
| PKCS8 = 0x41; | ||||||||||||||||||||||||||||||||||||||
| COSE_KEY = 0x42; | ||||||||||||||||||||||||||||||||||||||
| COSE_KEY_SET = 0x43; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| message PublicKey { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -110,11 +115,13 @@ The second is for generating peer ids; this is discussed in the section below. | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ### Key Types | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Four key types are supported: | ||||||||||||||||||||||||||||||||||||||
| The following key types are supported: | ||||||||||||||||||||||||||||||||||||||
| - RSA | ||||||||||||||||||||||||||||||||||||||
| - Ed25519 | ||||||||||||||||||||||||||||||||||||||
| - Secp256k1 | ||||||||||||||||||||||||||||||||||||||
| - ECDSA | ||||||||||||||||||||||||||||||||||||||
| - PKIX Encoded Public Keys | ||||||||||||||||||||||||||||||||||||||
| - PKCS#8 Encoded Private Keys | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Implementations MUST support Ed25519. Implementations SHOULD support RSA if they wish to | ||||||||||||||||||||||||||||||||||||||
| interoperate with the mainline IPFS DHT and the default IPFS bootstrap nodes. Implementations MAY | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -185,6 +192,39 @@ To sign a message, we hash the message with SHA 256, and then sign it with the | |||||||||||||||||||||||||||||||||||||
| [ECDSA standard algorithm](https://tools.ietf.org/html/rfc6979), then we encode | ||||||||||||||||||||||||||||||||||||||
| it using [DER-encoded ASN.1.](https://wiki.openssl.org/index.php/DER) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #### PKIX Public Keys | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The PKIX key type only encodes public keys. The Data field is the [PKIX | ||||||||||||||||||||||||||||||||||||||
| encoding](https://www.rfc-editor.org/rfc/rfc5280) of the public key. The public | ||||||||||||||||||||||||||||||||||||||
| key and algorithm are identified by the [Subject Public Key | ||||||||||||||||||||||||||||||||||||||
| Info](https://www.rfc-editor.org/rfc/rfc5280#section-4.1.2.7) field. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Signature Verification is defined by the key algorithm used. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| For backwards compatibility, if a key algorithm has a prior libp2p specific encoding, implementers SHOULD prefer that. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #### PKCS#8 Private Keys | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The PKCS8 key type only encodes private keys. The Data field is the [PKCS#8 encoding](https://www.rfc-editor.org/rfc/rfc5958.html) of the private key. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Signing is defined by the key algorithm used. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| For backwards compatibility, if a key algorithm has a prior libp2p specific encoding, implementers SHOULD prefer that. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #### COSE Key | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The Data field is defined by [Section 7 of RFC | ||||||||||||||||||||||||||||||||||||||
| 9052](https://www.rfc-editor.org/rfc/rfc9052#section-7). | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+214
to
+217
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something I realized in the context of libp2p is that PeerID is a hash of this protobuf. RFC 9052 Problem: Two conformant COSE encoders can produce different Fix: unsure, maybe require RFC 8949 §4.2 Core Deterministic Encoding for
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. 9052 has encoding restrictions, but they don't apply to the keys.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also found this RFC: https://datatracker.ietf.org/doc/html/rfc9679 which sounds like what we should use instead of trying to define this. |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The `COSE_Key` MUST be encoded using [CBOR Core Deterministic Encoding (RFC 8949 §4.2)](https://www.rfc-editor.org/rfc/rfc8949#section-4.2). Implementations MUST reject non-deterministic encodings. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Signing and verification for each member are defined by that member's COSE `alg` parameter. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| #### COSE KeySet | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The Data field is defined by [Section 7 of RFC | ||||||||||||||||||||||||||||||||||||||
| 9052](https://www.rfc-editor.org/rfc/rfc9052#section-7). | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+223
to
+226
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PeerID semantics feel undefined? Fix: spell out identity and verification rules, or drop I think it may be beneficial to keep it to support hybrid keys and signatures, for example when we have both ed25519+something post-quantum secure, and requiring both sigs/handshakes etc. so maybe:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to back out the cose keyset changes. It only gives us an array of cose keys. You could imagine having a array of these protobufs instead.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you mean? Current wire format for RFC for Of course this is just an option, we dont have to support o require hybrid signatures this way, or at all, and can defer to future codes, but feels sensible to preregister
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean using multiple protobuf messages instead of a COSE array. Maybe this doesn't work and the COSE array is better. I'm not sure. We'd also need to define how to hash the key set properly. |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ### Test vectors | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The following test vectors are hex-encoded bytes of the above described protobuf encoding. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other ones look like
Secp256k1and RFC 9052 usesCOSE_KeySet.Perhaps rename to match the RFC?