Skip to content

Commit f30c7c4

Browse files
sam-githubrvagg
authored andcommitted
tls: include RSA bit size in X.509 public key info
For symmetricality with the EC public key info, and because its useful. PR-URL: #24358 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 37f0bd7 commit f30c7c4

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

doc/api/tls.md

+1
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ The certificate may contain information about the public key, depending on
688688
the key type.
689689

690690
For RSA keys, the following properties may be defined:
691+
* `bits` {number} The RSA bit size. Example: `1024`.
691692
* `exponent` {string} The RSA exponent, as a string in hexadecimal number
692693
notation. Example: `'0x010001'`.
693694
* `modulus` {string} The RSA modulus, as a hexadecimal string. Example:

src/node_crypto.cc

+4
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,10 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
16621662
mem->length).ToLocalChecked()).FromJust();
16631663
USE(BIO_reset(bio.get()));
16641664

1665+
int bits = BN_num_bits(n);
1666+
info->Set(context, env->bits_string(),
1667+
Integer::New(env->isolate(), bits)).FromJust();
1668+
16651669
uint64_t exponent_word = static_cast<uint64_t>(BN_get_word(e));
16661670
uint32_t lo = static_cast<uint32_t>(exponent_word);
16671671
uint32_t hi = static_cast<uint32_t>(exponent_word >> 32);

test/parallel/test-tls-peer-certificate.js

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ connect({
5555
assert.strictEqual(peerCert.subject.emailAddress, 'ry@tinyclouds.org');
5656
assert.strictEqual(peerCert.serialNumber, 'ECC9B856270DA9A8');
5757
assert.strictEqual(peerCert.exponent, '0x10001');
58+
assert.strictEqual(peerCert.bits, 1024);
59+
// The conversion to bits is odd because modulus isn't a buffer, its a hex
60+
// string. There are two hex chars for every byte of modulus, and 8 bits per
61+
// byte.
62+
assert.strictEqual(peerCert.modulus.length / 2 * 8, peerCert.bits);
5863
assert.strictEqual(
5964
peerCert.fingerprint,
6065
'D7:FD:F6:42:92:A8:83:51:8E:80:48:62:66:DA:85:C2:EE:A6:A1:CD'

0 commit comments

Comments
 (0)