-
-
Notifications
You must be signed in to change notification settings - Fork 119
adds support for brainpoolP256r1 #646
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: 4.2.x
Are you sure you want to change the base?
Conversation
|
Thank you. |
Spomky
left a comment
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.
Hi @robertboeser,
Please fix the issues I spotted.
Also, would you mind adding some tests to confirm:
- BP-256 key creation
- PEM import/export to check the OID
- OpenSSL compatibility
Many thanks.
Regards.
| { | ||
| $der = match ($jwk->get('crv')) { | ||
| 'P-256' => self::p256PublicKey(), | ||
| 'BP-256' => self::p256PublicKey(), |
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.
This is not correct as the OID is different for BP public keys
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.
Should be as follows:
private static function bp256PublicKey(): string
{
return pack(
'H*',
'305a' // SEQUENCE, length 90
. '3014' // SEQUENCE, length 20
. '0607' // OID, length 7
. '2a8648ce3d0201' // 1.2.840.10045.2.1 = EC Public Key
. '0609' // OID, length 9
. '2b2403030208010107' // 1.3.36.3.3.2.8.1.1.7 = brainpoolP256r1
. '0342' // BIT STRING, length 66
. '00' // prepend with NUL
);
}| { | ||
| $der = match ($jwk->get('crv')) { | ||
| 'P-256' => self::p256PrivateKey($jwk), | ||
| 'BP-256' => self::p256PrivateKey($jwk), |
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.
Same here. The OID is different for BP private keys
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.
Should be as follows:
private static function bp256PrivateKey(JWK $jwk): string
{
$d = $jwk->get('d');
if (!is_string($d)) {
throw new InvalidArgumentException('Unable to get the private key');
}
$d = unpack('H*', str_pad(Base64UrlSafe::decodeNoPadding($d), 32, "\0", STR_PAD_LEFT));
if (!is_array($d) || !isset($d[1])) {
throw new InvalidArgumentException('Unable to get the private key');
}
return pack(
'H*',
'3078' // SEQUENCE, length 120
. '020101' // INTEGER, 1
. '0420' // OCTET STRING, length 32
. $d[1]
. 'a00b' // TAGGED OBJECT #0, length 11
. '0609' // OID, length 9
. '2b2403030208010107' // 1.3.36.3.3.2.8.1.1.7
. 'a144' // TAGGED OBJECT #1, length 68
. '0342' // BIT STRING, length 66
. '00'
);
}
Target branch: 4.2.x
Includes:
I needed support for the brainpool curve, so I added support for it. Maybe it is useful for somebody else, too.