This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: x509 certificate subject parsing fail
Fixes #1568.
- Loading branch information
Showing
4 changed files
with
112 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,12 +153,12 @@ CryptoStream.prototype.setEncoding = function(encoding) { | |
}; | ||
|
||
|
||
// EG '/C=US/ST=CA/L=SF/O=Joyent/OU=Node.js/CN=ca1/[email protected]' | ||
// Example: | ||
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\[email protected] | ||
function parseCertString(s) { | ||
var out = {}; | ||
var parts = s.split('/'); | ||
// Note: can always skip the first one. | ||
for (var i = 1; i < parts.length; i++) { | ||
var parts = s.split('\n'); | ||
for (var i = 0, len = parts.length; i < len; i++) { | ||
var sepIndex = parts[i].indexOf('='); | ||
if (sepIndex > 0) { | ||
var key = parts[i].slice(0, sepIndex); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIID8DCCAtigAwIBAgIJALmw0zKhqlY1MA0GCSqGSIb3DQEBBQUAMFgxDjAMBgNV | ||
BAMTBWFsaWNlMUYwRAYDVR0RFD11bmlmb3JtUmVzb3VyY2VJZGVudGlmaWVyOmh0 | ||
dHA6Ly9sb2NhbGhvc3Q6ODAwMC9hbGljZS5mb2FmI21lMB4XDTExMD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QucSpyOMmGGPYYw2zmg0nNXdQauYWDUZIaDwQ6 | ||
tM/pi2ewYubHPZdwJv5jvxTN3Z7RuuGHM+aLAZSAqSgAi0ml8PYYd2eRzXMaEI0c | ||
eajcEvVa405aYT6dxuF1qqRDYx14As/R7O5RKCpz7wsxD6ICD/Ynv3GCUGxANQim | ||
bcCjpg== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
if (!process.versions.openssl) { | ||
console.error("Skipping because node compiled without OpenSSL."); | ||
process.exit(0); | ||
} | ||
|
||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var tls = require('tls'); | ||
var fs = require('fs'); | ||
var util = require('util'); | ||
var join = require('path').join; | ||
var spawn = require('child_process').spawn; | ||
|
||
var options = { | ||
key: fs.readFileSync(join(common.fixturesDir, 'agent.key')), | ||
cert: fs.readFileSync(join(common.fixturesDir, 'alice.crt')) | ||
}; | ||
var verified = false; | ||
|
||
var server = tls.createServer(options, function(cleartext) { | ||
cleartext.end('World'); | ||
}); | ||
server.listen(common.PORT, function() { | ||
var socket = tls.connect(common.PORT, function() { | ||
var peerCert = socket.getPeerCertificate(); | ||
common.debug(util.inspect(peerCert)); | ||
assert.equal(peerCert.subject.subjectAltName, | ||
'uniformResourceIdentifier:http://localhost:8000/alice.foaf#me'); | ||
verified = true; | ||
server.close(); | ||
}); | ||
socket.end('Hello'); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.ok(verified); | ||
}); |