1
1
'use strict' ;
2
- const fs = require ( 'fs ' ) ;
2
+ const asn1 = require ( 'asn1.js ' ) ;
3
3
const crypto = require ( 'crypto' ) ;
4
+ const fs = require ( 'fs' ) ;
4
5
const rfc5280 = require ( 'asn1.js-rfc5280' ) ;
5
- const asn1 = require ( 'asn1.js' ) ;
6
6
const BN = asn1 . bignum ;
7
7
8
8
const id_at_commonName = [ 2 , 5 , 4 , 3 ] ;
@@ -12,7 +12,7 @@ const sigalg = 'RSA-SHA256';
12
12
13
13
const private_key = fs . readFileSync ( './0-dns-key.pem' ) ;
14
14
// public key file can be generated from the private key with
15
- // openssl rsa -in 0-dns-key.pem -RSAPublicKey_out -outform der \
15
+ // openssl rsa -in 0-dns-key.pem -RSAPublicKey_out -outform der
16
16
// -out 0-dns-rsapub.der
17
17
const public_key = fs . readFileSync ( './0-dns-rsapub.der' ) ;
18
18
@@ -30,32 +30,32 @@ const PrintStr = asn1.define('PrintStr', function() {
30
30
const issuer = PrintStr . encode ( 'ca.example.com' , 'der' ) ;
31
31
const subject = PrintStr . encode ( 'evil.example.com' , 'der' ) ;
32
32
33
- const tbs =
34
- { version : 'v3' ,
35
- serialNumber : new BN ( '01' , 16 ) ,
36
- signature : { algorithm : sha256WithRSAEncryption , parameters : null_ } ,
37
- issuer : { type : 'rdnSequence' ,
38
- value : [ [ { type : id_at_commonName , value : issuer } ] ] } ,
39
- validity :
40
- { notBefore : { type : 'utcTime' , value : now } ,
41
- notAfter : { type : 'utcTime' , value : now + days * 86400000 } } ,
42
- subject : { type : 'rdnSequence' ,
43
- value : [ [ { type : id_at_commonName , value : subject } ] ] } ,
44
- subjectPublicKeyInfo :
45
- { algorithm : { algorithm : rsaEncryption , parameters : null_ } ,
46
- subjectPublicKey : { unused : 0 , data : public_key } } ,
47
- extensions :
48
- [ { extnID : 'subjectAlternativeName' ,
49
- critical : false ,
50
- // subjectAltName which contains '\0' character to check CVE-2009-2408
51
- extnValue : [
52
- { type : 'dNSName' , value : 'good.example.org\u0000.evil.example.com' } ,
53
- { type : 'dNSName' , value : 'just-another.example.com' } ,
54
- { type : 'iPAddress' , value : Buffer . from ( '08080808' , 'hex' ) } ,
55
- { type : 'iPAddress' , value : Buffer . from ( '08080404' , 'hex' ) } ,
56
- { type : 'dNSName' , value : 'last.example.com' } ] }
57
- ]
58
- } ;
33
+ const tbs = {
34
+ version : 'v3' ,
35
+ serialNumber : new BN ( '01' , 16 ) ,
36
+ signature : { algorithm : sha256WithRSAEncryption , parameters : null_ } ,
37
+ issuer : { type : 'rdnSequence' ,
38
+ value : [ [ { type : id_at_commonName , value : issuer } ] ] } ,
39
+ validity :
40
+ { notBefore : { type : 'utcTime' , value : now } ,
41
+ notAfter : { type : 'utcTime' , value : now + days * 86400000 } } ,
42
+ subject : { type : 'rdnSequence' ,
43
+ value : [ [ { type : id_at_commonName , value : subject } ] ] } ,
44
+ subjectPublicKeyInfo :
45
+ { algorithm : { algorithm : rsaEncryption , parameters : null_ } ,
46
+ subjectPublicKey : { unused : 0 , data : public_key } } ,
47
+ extensions :
48
+ [ { extnID : 'subjectAlternativeName' ,
49
+ critical : false ,
50
+ // subjectAltName which contains '\0' character to check CVE-2009-2408
51
+ extnValue : [
52
+ { type : 'dNSName' , value : 'good.example.org\u0000.evil.example.com' } ,
53
+ { type : 'dNSName' , value : 'just-another.example.com' } ,
54
+ { type : 'iPAddress' , value : Buffer . from ( '08080808' , 'hex' ) } ,
55
+ { type : 'iPAddress' , value : Buffer . from ( '08080404' , 'hex' ) } ,
56
+ { type : 'dNSName' , value : 'last.example.com' } ] }
57
+ ]
58
+ } ;
59
59
60
60
const tbs_der = rfc5280 . TBSCertificate . encode ( tbs , 'der' ) ;
61
61
@@ -65,10 +65,10 @@ const signature = sign.sign(private_key);
65
65
66
66
const cert = {
67
67
tbsCertificate : tbs ,
68
- signatureAlgorithm : { algorithm : sha256WithRSAEncryption , parameters : null_ } ,
68
+ signatureAlgorithm : { algorithm : sha256WithRSAEncryption , parameters : null_ } ,
69
69
signature :
70
70
{ unused : 0 ,
71
- data : signature }
71
+ data : signature }
72
72
} ;
73
73
const pem = rfc5280 . Certificate . encode ( cert , 'pem' , { label : 'CERTIFICATE' } ) ;
74
74
0 commit comments