Skip to content

Commit 9b672bc

Browse files
ssudakoichik
authored andcommitted
tls: parsing multiple values of a key in ssl certificate
Fixes nodejs#2864.
1 parent 36761b2 commit 9b672bc

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

lib/tls.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,14 @@ function parseCertString(s) {
197197
if (sepIndex > 0) {
198198
var key = parts[i].slice(0, sepIndex);
199199
var value = parts[i].slice(sepIndex + 1);
200-
out[key] = value;
200+
if (key in out) {
201+
if (!Array.isArray(out[key])) {
202+
out[key] = [out[key]];
203+
}
204+
out[key].push(value);
205+
} else {
206+
out[key] = value;
207+
}
201208
}
202209
}
203210
return out;

test/fixtures/multi-alice.crt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDnjCCAoYCCQCXooHS0l6bHDANBgkqhkiG9w0BAQUFADCBkDELMAkGA1UEBhMC
3+
QVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdp
4+
dHMgUHR5IEx0ZDEfMB0GA1UECwwWSW5mb3JtYXRpb24gVGVjaG5vbG9neTEUMBIG
5+
A1UECwwLRW5naW5lZXJpbmcxEjAQBgNVBAsMCU1hcmtldGluZzAeFw0xMjAzMDQx
6+
NDA4MDVaFw0xMjA0MDMxNDA4MDVaMIGQMQswCQYDVQQGEwJBVTETMBEGA1UECAwK
7+
U29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMR8w
8+
HQYDVQQLDBZJbmZvcm1hdGlvbiBUZWNobm9sb2d5MRQwEgYDVQQLDAtFbmdpbmVl
9+
cmluZzESMBAGA1UECwwJTWFya2V0aW5nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
10+
MIIBCgKCAQEAz+LXZOjcQCJq3+ZKUFabj71oo/ex/XsBcFqtBThjjTw9CVEVwfPQ
11+
Qp4XwtPiB204vnYXwQ1/R2NdTQqCZu47l79LssL/u2a5Y9+0NEU3nQA5qdt+1FAE
12+
0c5oexPimXOrR3GWfKz7PmZ2O0117IeCUUXPG5U8umhDe/4mDF4ZNJiKc404Wthq
13+
uTqgS7rLQZHhZ6D0EnGnOkzlmxJMYPNHSOY1/6ivdNUUcC87awNEA3lgfhy25IyB
14+
K3QJc+aYKNTbt70Lery3bu2wWLFGtmNiGlQTS4JsxImRsECTI727ObS7/FWAQsqW
15+
+COL0Sa5BuMFrFIpjPrEe0ih7vRRbdmXRwIDAQABMA0GCSqGSIb3DQEBBQUAA4IB
16+
AQC7kyzjGXy7SnT1tvefdvtdAtErDuD375/sB2l1V72+BNXlIlddmEC8IkAVSKg2
17+
5Y7MuQ4yMsHlhrdUxj/XOOVMHY/49xsZiN5hF2jb2mdq7KdvlVMYqyf126bW2mOx
18+
cLVSiuucdp88zoJopWBUnNyVOYhh18St9bNosGgPzppGBCpL+MJvoSn3wrnFn8ER
19+
wwN1m3ga590wHa4fny+qlD/hJNww16wbwgdF9NqsuR/e+sj9ZsoIYRCF8iKBajzt
20+
3o7cZIRlvGtJfJRM87YCAn4BR3JgQPXfbhx31KwtMXtAJNzOHk26bblW3jTC8c7+
21+
Cu1gNEM083vUq6/UxJUM8lOM
22+
-----END CERTIFICATE-----
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
if (!process.versions.openssl) {
23+
console.error('Skipping because node compiled without OpenSSL.');
24+
process.exit(0);
25+
}
26+
27+
var common = require('../common');
28+
var assert = require('assert');
29+
var tls = require('tls');
30+
var fs = require('fs');
31+
var util = require('util');
32+
var join = require('path').join;
33+
var spawn = require('child_process').spawn;
34+
35+
var options = {
36+
key: fs.readFileSync(join(common.fixturesDir, 'agent.key')),
37+
cert: fs.readFileSync(join(common.fixturesDir, 'multi-alice.crt'))
38+
};
39+
var verified = false;
40+
41+
var server = tls.createServer(options, function(cleartext) {
42+
cleartext.end('World');
43+
});
44+
server.listen(common.PORT, function() {
45+
var socket = tls.connect({port: common.PORT}, function() {
46+
var peerCert = socket.getPeerCertificate();
47+
common.debug(util.inspect(peerCert));
48+
assert.deepEqual(peerCert.subject.OU,
49+
['Information Technology', 'Engineering', 'Marketing']);
50+
verified = true;
51+
server.close();
52+
});
53+
socket.end('Hello');
54+
});
55+
56+
process.on('exit', function() {
57+
assert.ok(verified);
58+
});

0 commit comments

Comments
 (0)