Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ported from
OpenSUSE:nodejs8-8.17.0-lp152.147.1:CVE-2019-15604.patch

Original commit message:

commit f940bee
Author: Fedor Indutny <fedor@indutny.com>
Date:   Tue Nov 26 12:47:00 2019 -0800

    crypto: fix assertion caused by unsupported ext

    `X509V3_EXT_print` can return value different from `1` if the X509
    extension does not support printing to a buffer. Instead of failing with
    an unrecoverable assertion - replace the relevant value in the hashmap
    with a JS null value.

    Fixes: https://hackerone.com/reports/746733

    Backport-PR-URL: https://github.com/nodejs-private/node-private/pull/193
    PR-URL: https://github.com/nodejs-private/node-private/pull/175
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

Signed-off-by: Su Baocheng <baocheng.su@siemens.com>
  • Loading branch information
BaochengSu committed Oct 21, 2020
1 parent bdb063b commit d6c4973
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1743,9 +1743,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
ext = X509_get_ext(cert, index);
CHECK_NE(ext, nullptr);

if (!SafeX509ExtPrint(bio, ext)) {
rv = X509V3_EXT_print(bio, ext, 0, 0);
CHECK_EQ(rv, 1);
if (!SafeX509ExtPrint(bio, ext) &&
X509V3_EXT_print(bio, ext, 0, 0) != 1) {
info->Set(context, keys[i], Null(env->isolate())).FromJust();
(void) BIO_reset(bio);
continue;
}

BIO_get_mem_ptr(bio, &mem);
Expand Down
79 changes: 79 additions & 0 deletions test/parallel/test-tls-cert-ext-encoding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

// NOTE: This certificate is hand-generated, hence it is not located in
// `test/fixtures/keys` to avoid confusion.
//
// The key property of this cert is that subjectAltName contains a string with
// a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UVqHneRcrDBytdG6MoIqHhZJwBeii/EES9
tpWwWbzYYh+38aGGLIF2h5UlVpr0bdBVVUg+uVX3y/Qmu2Qv4CrAO2IPV6JER9Ni
wl3ktzNjOMAUQG6BCRSqRQIDAQABoxswGTAXBgNVHREEEDAOlwwqLmxvY2FsLmhv
c3QwDQYJKoZIhvcNAQENBQADggEBAH5ThRLDLwOGuhKsifyiq7k8gbx1FqRegO7H
SIiIYYB35v5Pk0ZPN8QBJwNQzJEjUMjCpHXNdBxknBXRaA8vkbnryMfJm37gPTwA
m6r0uEG78WgcEAe8bgf9iKtQGP/iydKXpSSpDgKoHbswIxD5qtzT+o6VNnkRTSfK
/OGwakluFSoJ/Q9rLpR8lKjA01BhetXMmHbETiY8LSkxOymMldXSzUTD1WdrVn8U
L3dobxT//R/0GraKXG02mf3gZNlb0MMTvW0pVwVy39YmcPEGh8L0hWh1rpAA/VXC
f79uOowv3lLTzQ9na5EThA0tp8d837hdYrrIHh5cfTqBDxG0Tu8=
-----END CERTIFICATE-----
`;

const tls = require('tls');

const options = {
key: pem,
cert: pem,
};

const server = tls.createServer(options, (socket) => {
socket.end();
});
server.listen(0, common.mustCall(function() {
const client = tls.connect({
port: this.address().port,
rejectUnauthorized: false
}, common.mustCall(() => {
// This should not crash process:
client.getPeerCertificate();

server.close();
client.end();
}));
}));

0 comments on commit d6c4973

Please sign in to comment.