Skip to content
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

Asn1 validator node ed25519 #680

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Conversation

aljones15
Copy link
Contributor

Adds:

  • ASN1 validators for der format ed25519 public and private keys
  • Adds the OID for ed25519 keys
  • Adds extract functions so node 12 ed25519 keys can be imported now.

@aljones15 aljones15 self-assigned this May 21, 2019
@dlongley
Copy link
Member

Some of the docs in here make it seem like the functions are specific to node.js buffers, etc. -- when they aren't. The docs can mention that if you're using node's API that the functions will be particularly helpful, but they should lead by saying that the functions, for example, convert a DER-formatted PKCS#8 private key to a raw private key.

We may also want the functions to be something like publicKeyFromDer() and publicKeyToDer() ... or something that more closely approximates existing the forge API. I think we need a short bikeshedding around. cc: @mattcollier, @davidlehn

lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
tests/unit/ed25519.js Outdated Show resolved Hide resolved
@aljones15 aljones15 force-pushed the asn1-validator-node-ed25519 branch from f5b03bb to ce9cf21 Compare May 22, 2019 20:32
@aljones15 aljones15 requested a review from davidlehn June 18, 2019 17:47
@aljones15 aljones15 force-pushed the asn1-validator-node-ed25519 branch 2 times, most recently from 0cba333 to 00f1b3d Compare July 16, 2019 17:08
lib/ed25519.js Outdated Show resolved Hide resolved
Copy link
Contributor

@mattcollier mattcollier left a comment

Choose a reason for hiding this comment

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

Test suite is passing here and it's working well in crypto-ld. I'm happy with it.

Thank you @aljones15

@aljones15
Copy link
Contributor Author

aljones15 commented Jul 17, 2019

@mattcollier sorry you had to change those consts but thanks for updating this.

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

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

There a few simple changes we want here then I think we can merge.

lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
@mattcollier
Copy link
Contributor

@dlongley @aljones15 I'll handle Longley's comments.

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

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

I approve on the condition that the other changes I mentioned are applied.

Thanks!

lib/ed25519.js Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
lib/ed25519.js Outdated Show resolved Hide resolved
@mattcollier
Copy link
Contributor

@davidlehn I leave it to you to approve/merge and publish this. I'm not an owner on NPM. Thanks!

Copy link
Member

@dlongley dlongley left a comment

Choose a reason for hiding this comment

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

Unfortunately, looking at this with @davidlehn has pointed out that this PR actually still needs work. I checked other APIs and we don't do publicKeyFromDer etc. We should not bake in specific buffer requirements when coming from DER since we have a bunch of other APIs that handle that stuff.

We need to change the publicKeyFromDer API to publicKeyFromAsn1 API (same for privateKey) and let the caller supply an ASN.1 object using our other APIs.

/**
* Takes in a public key exported in DER and returns the raw key value.
*
* @param {NativeBuffer} publicKeyBuffer - A DER formatted public key.
Copy link
Member

@dlongley dlongley Jul 18, 2019

Choose a reason for hiding this comment

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

Any use of NativeBuffer in the docs should change -- this isn't a public name. It should be {Uint8Array|Buffer}. But, that being said -- we need to change this API to take in ASN.1 input anyway, not DER.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This actually is a jsdoc thing NativeBuffer here refers to a jsdoc type declared earlier in the file:

/**
 * NativeBuffer is either a Buffer or a Uint8Array.
 * @type {Buffer|Uint8Array}
*/

@aljones15
Copy link
Contributor Author

@dlongley @mattcollier this can be closed correct? another PR added this feature I believe.

@dlongley
Copy link
Member

I don't know what the status is, but so we can better track it I'm linking to that other PR: #697.

@davidlehn
Copy link
Member

#697 was merged and released causing conflicts here. If some of this patch should still be merged, please rebase and update as needed.

@aljones15
Copy link
Contributor Author

if I recall correctly this PR is not needed because it turns out the ed25519 keys use a common DER format that we already have a validator for. I believe this can be closed @dlongley

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants