-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
test: add script to create 0-dns-cert.pem #11579
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
Changes from 1 commit
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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| -----BEGIN CERTIFICATE----- | ||
| MIIDGDCCAgCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAZMRcwFQYDVQQDEw5jYS5l | ||
| eGFtcGxlLmNvbTAeFw0xNzAyMjcxMDE3NDNaFw0yNzAyMjUxMDE3NDNaMBsxGTAX | ||
| BgNVBAMTEGV2aWwuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw | ||
| ggEKAoIBAQDFyJT0kv2P9L6iNY6TL7IZonAR8R9ev7iD1tR5ycMEpM/y6WTefIco | ||
| civMcBGVZWtCgkoePHiveH9UIep7HFGB4gxCYDZFYB46yGS0YH2fB5GWXTLYObYa | ||
| zxuEhgFRG0DLIwNDRLW0+0FG3disp7YdRHBtdbL58F/qNORqPEjIpoQxOJc2UqX2 | ||
| /gfomJRdFW/PSgN7uH2QwMzRQRIrKmyAFzeuEWVP+UAV4853Yg66PmYpAASyt069 | ||
| sE8QNTNE75KrerMmYzH7AmTEGvY8bukrDuVQZce2/lcK2rAE+G6at2eBNMZKOnzR | ||
| y9kWIiJ3rR7+WK55EKelLz0doZFKteu1AgMBAAGjaTBnMGUGA1UdEQReMFyCImdv | ||
| b2QuZXhhbXBsZS5vcmcALmV2aWwuZXhhbXBsZS5jb22CGGp1c3QtYW5vdGhlci5l | ||
| eGFtcGxlLmNvbYcECAgICIcECAgEBIIQbGFzdC5leGFtcGxlLmNvbTANBgkqhkiG | ||
| 9w0BAQsFAAOCAQEAXhkEwOXbwumH5Whf++QWUhdv5cTuS5MEel4dtiPafZ3x9R0F | ||
| 4hL7yN10igHJm8m2vvTeiFJBEksvjKDY+Xuc1omcj5rqpAMP5nTiOZdzld/NsFrr | ||
| 1eYOtdFSO+Te6g3jPNJf+42wbUWaE9sUfOtkBL4d6SVkN37I2W6P2AKynI2jneOp | ||
| Z4CCF58oC4b7MrfFo1LXW8EdSjfK5ejFse6xZe6WNAahi7vDS7RJEyoq3EeZ4+A0 | ||
| DvrSjCuretoVAC/U7gUxs467yM3ZCujqZ4OANVQF6knRziTJEF5c1aXOzM563FT3 | ||
| ufeH36lO0ImzE+a2g6et3BZDL2PQLmBF3F6clQ== | ||
| -----END CERTIFICATE----- | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| -----BEGIN RSA PRIVATE KEY----- | ||
| MIIEowIBAAKCAQEAxciU9JL9j/S+ojWOky+yGaJwEfEfXr+4g9bUecnDBKTP8ulk | ||
| 3nyHKHIrzHARlWVrQoJKHjx4r3h/VCHqexxRgeIMQmA2RWAeOshktGB9nweRll0y | ||
| 2Dm2Gs8bhIYBURtAyyMDQ0S1tPtBRt3YrKe2HURwbXWy+fBf6jTkajxIyKaEMTiX | ||
| NlKl9v4H6JiUXRVvz0oDe7h9kMDM0UESKypsgBc3rhFlT/lAFePOd2IOuj5mKQAE | ||
| srdOvbBPEDUzRO+Sq3qzJmMx+wJkxBr2PG7pKw7lUGXHtv5XCtqwBPhumrdngTTG | ||
| Sjp80cvZFiIid60e/liueRCnpS89HaGRSrXrtQIDAQABAoIBABcGA3j5B3VTi0F8 | ||
| tI0jtzrOsvcTt5AjB0qpnnBS8VXADcj8LFbN7jniGIEi5pkahkLmwdQFPBNJFqFn | ||
| lVEheceB1eWAJ7EpwDsdisOIm/cAPY1gagPLrAww4cYqh0q2vnMnL0EMZY6c1Pt3 | ||
| 5borh8KebewAEIaR2ch8wb4wKFTbAM0DftYBFzHAF88OeCuIpdsk2Tz0sVQ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3vECE7n8dBizFHgja76l1ia+0z | ||
| -----END RSA PRIVATE KEY----- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ## Purpose | ||
| The test cert file for use `test/parallel/test-tls-0-dns-altname.js` | ||
| can be created by using `asn1.js` and `asn1.js-rfc5280`, | ||
|
|
||
| ## How to create a test cert. | ||
|
|
||
| ```sh | ||
| $ openssl genrsa -out 0-dns-key.pem 2048 | ||
| Generating RSA private key, 2048 bit long modulus | ||
| ...................+++ | ||
| ..............................................................................................+++ | ||
| e is 65537 (0x10001) | ||
| $ openssl rsa -in 0-dns-key.pem -RSAPublicKey_out -outform der -out 0-dns-rsapub.der | ||
| writing RSA key | ||
| $ npm install | ||
| [email protected] /home/github/node/test/fixtures/0-dns | ||
| +-- [email protected] | ||
| | +-- [email protected] | ||
| | +-- [email protected] | ||
| | `-- [email protected] | ||
| `-- [email protected] | ||
|
|
||
| $ node ./createCert.js | ||
| $ openssl x509 -text -in 0-dns-cert.pem | ||
| (You can not see evel.example.com in subjectAltName field) | ||
|
||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| 'use strict'; | ||
|
||
| const fs = require('fs'); | ||
| const crypto = require('crypto'); | ||
| const rfc5280 = require('asn1.js-rfc5280'); | ||
| const asn1 = require('asn1.js'); | ||
| const BN = asn1.bignum; | ||
|
||
|
|
||
| const id_at_commonName = [ 2, 5, 4, 3 ]; | ||
|
||
| const rsaEncryption = [1, 2, 840, 113549, 1, 1, 1]; | ||
| const sha256WithRSAEncryption = [1, 2, 840, 113549, 1, 1, 11]; | ||
| const sigalg = 'RSA-SHA256'; | ||
|
|
||
| const private_key = fs.readFileSync('./0-dns-key.pem'); | ||
| // public key file can be generated from the private key with | ||
| // openssl rsa -in 0-dns-key.pem -RSAPublicKey_out -outform der \ | ||
|
||
| // -out 0-dns-rsapub.der | ||
| const public_key = fs.readFileSync('./0-dns-rsapub.der'); | ||
|
|
||
| const now = Date.now(); | ||
| const days = 3650; | ||
|
|
||
| const Null_ = asn1.define('Null_', function() { | ||
| this.null_(); | ||
| }); | ||
| const null_ = Null_.encode('der'); | ||
|
|
||
| const PrintStr = asn1.define('PrintStr', function() { | ||
| this.printstr(); | ||
| }); | ||
| const issuer = PrintStr.encode('ca.example.com', 'der'); | ||
| const subject = PrintStr.encode('evil.example.com', 'der'); | ||
|
|
||
| const tbs = | ||
| { version: 'v3', | ||
|
||
| serialNumber: new BN('01', 16), | ||
| signature: { algorithm: sha256WithRSAEncryption, parameters: null_}, | ||
| issuer: { type: 'rdnSequence', | ||
| value: [ [{type: id_at_commonName, value: issuer}] ] }, | ||
| validity: | ||
| { notBefore: { type: 'utcTime', value: now }, | ||
| notAfter: { type: 'utcTime', value: now + days * 86400000} }, | ||
| subject: { type: 'rdnSequence', | ||
| value: [ [{type: id_at_commonName, value: subject}] ] }, | ||
| subjectPublicKeyInfo: | ||
| { algorithm: { algorithm: rsaEncryption, parameters: null_}, | ||
| subjectPublicKey: { unused: 0, data: public_key} }, | ||
| extensions: | ||
| [ { extnID: 'subjectAlternativeName', | ||
| critical: false, | ||
| // subjectAltName which contains '\0' character to check CVE-2009-2408 | ||
| extnValue: [ | ||
| { type: 'dNSName', value: 'good.example.org\u0000.evil.example.com' }, | ||
| { type: 'dNSName', value: 'just-another.example.com' }, | ||
| { type: 'iPAddress', value: Buffer.from('08080808', 'hex') }, | ||
| { type: 'iPAddress', value: Buffer.from('08080404', 'hex') }, | ||
| { type: 'dNSName', value: 'last.example.com' } ] } | ||
| ] | ||
| }; | ||
|
|
||
| const tbs_der = rfc5280.TBSCertificate.encode(tbs, 'der'); | ||
|
|
||
| const sign = crypto.createSign(sigalg); | ||
| sign.update(tbs_der); | ||
| const signature = sign.sign(private_key); | ||
|
|
||
| const cert = { | ||
| tbsCertificate: tbs, | ||
| signatureAlgorithm: { algorithm: sha256WithRSAEncryption, parameters: null_}, | ||
|
||
| signature: | ||
| { unused: 0, | ||
| data: signature} | ||
| }; | ||
| const pem = rfc5280.Certificate.encode(cert, 'pem', {label: 'CERTIFICATE'}); | ||
|
|
||
| fs.writeFileSync('./0-dns-cert.pem', pem); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "name": "0-dns", | ||
| "version": "1.0.0", | ||
| "description": "create certificate for 0-dns test", | ||
| "main": "createCert.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "author": "", | ||
| "license": "SEE LICENSE IN ../../../LICENSE", | ||
| "private": true, | ||
| "dependencies": { | ||
| "asn1.js": "^4.9.1", | ||
| "asn1.js-rfc5280": "^1.2.2" | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
|
|
||
| // check getPeerCertificate can properly handle '\0' for fix CVE-2009-2408 | ||
|
||
|
|
||
| if (!common.hasCrypto) { | ||
| common.skip('missing crypto'); | ||
| return; | ||
|
|
@@ -11,8 +13,8 @@ const tls = require('tls'); | |
| const fs = require('fs'); | ||
|
|
||
| const server = tls.createServer({ | ||
| key: fs.readFileSync(common.fixturesDir + '/keys/0-dns-key.pem'), | ||
| cert: fs.readFileSync(common.fixturesDir + '/keys/0-dns-cert.pem') | ||
| key: fs.readFileSync(common.fixturesDir + '/0-dns/0-dns-key.pem'), | ||
| cert: fs.readFileSync(common.fixturesDir + '/0-dns/0-dns-cert.pem') | ||
| }, function(c) { | ||
| c.once('data', function() { | ||
| c.destroy(); | ||
|
|
@@ -24,11 +26,11 @@ const server = tls.createServer({ | |
| }, common.mustCall(function() { | ||
| const cert = c.getPeerCertificate(); | ||
| assert.strictEqual(cert.subjectaltname, | ||
| 'DNS:google.com\0.evil.com, ' + | ||
| 'DNS:just-another.com, ' + | ||
| 'DNS:good.example.org\0.evil.example.com, ' + | ||
| 'DNS:just-another.example.com, ' + | ||
| 'IP Address:8.8.8.8, ' + | ||
| 'IP Address:8.8.4.4, ' + | ||
| 'DNS:last.com'); | ||
| 'DNS:last.example.com'); | ||
| c.write('ok'); | ||
| })); | ||
| })); | ||
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.
missing newline
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.
Done