| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67d792a commit 5723c4c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,50 +73,60 @@ exports.createSecureContext = function createSecureContext(options, context) { | |||
| 73 | 73 | ||
| 74 | 74 | var c = new SecureContext(options.secureProtocol, secureOptions, context); | |
| 75 | 75 | var i; | |
| 76 | + var val; | ||
| 76 | 77 | ||
| 77 | 78 | if (context) return c; | |
| 78 | 79 | ||
| 79 | 80 | // NOTE: It's important to add CA before the cert to be able to load | |
| 80 | 81 | // cert's issuer in C++ code. | |
| 81 | - if (options.ca) { | ||
| 82 | - if (Array.isArray(options.ca)) { | ||
| 83 | - options.ca.forEach((ca) => { | ||
| 84 | - validateKeyCert(ca, 'ca'); | ||
| 85 | - c.context.addCACert(ca); | ||
| 86 | - }); | ||
| 82 | + var ca = options.ca; | ||
| 83 | + if (ca !== undefined) { | ||
| 84 | + if (Array.isArray(ca)) { | ||
| 85 | + for (i = 0; i < ca.length; ++i) { | ||
| 86 | + val = ca[i]; | ||
| 87 | + validateKeyCert(val, 'ca'); | ||
| 88 | + c.context.addCACert(val); | ||
| 89 | + } | ||
| 87 | 90 | } else { | |
| 88 | - validateKeyCert(options.ca, 'ca'); | ||
| 89 | - c.context.addCACert(options.ca); | ||
| 91 | + validateKeyCert(ca, 'ca'); | ||
| 92 | + c.context.addCACert(ca); | ||
| 90 | 93 | } | |
| 91 | 94 | } else { | |
| 92 | 95 | c.context.addRootCerts(); | |
| 93 | 96 | } | |
| 94 | 97 | ||
| 95 | - if (options.cert) { | ||
| 96 | - if (Array.isArray(options.cert)) { | ||
| 97 | - options.cert.forEach((cert) => { | ||
| 98 | - validateKeyCert(cert, 'cert'); | ||
| 99 | - c.context.setCert(cert); | ||
| 100 | - }); | ||
| 98 | + var cert = options.cert; | ||
| 99 | + if (cert !== undefined) { | ||
| 100 | + if (Array.isArray(cert)) { | ||
| 101 | + for (i = 0; i < cert.length; ++i) { | ||
| 102 | + val = cert[i]; | ||
| 103 | + validateKeyCert(val, 'cert'); | ||
| 104 | + c.context.setCert(val); | ||
| 105 | + } | ||
| 101 | 106 | } else { | |
| 102 | - validateKeyCert(options.cert, 'cert'); | ||
| 103 | - c.context.setCert(options.cert); | ||
| 107 | + validateKeyCert(cert, 'cert'); | ||
| 108 | + c.context.setCert(cert); | ||
| 104 | 109 | } | |
| 105 | 110 | } | |
| 106 | 111 | ||
| 107 | 112 | // NOTE: It is important to set the key after the cert. | |
| 108 | 113 | // `ssl_set_pkey` returns `0` when the key does not match the cert, but | |
| 109 | 114 | // `ssl_set_cert` returns `1` and nullifies the key in the SSL structure | |
| 110 | 115 | // which leads to the crash later on. | |
| 111 | - if (options.key) { | ||
| 112 | - if (Array.isArray(options.key)) { | ||
| 113 | - options.key.forEach((k) => { | ||
| 114 | - validateKeyCert(k.pem || k, 'key'); | ||
| 115 | - c.context.setKey(k.pem || k, k.passphrase || options.passphrase); | ||
| 116 | - }); | ||
| 116 | + var key = options.key; | ||
| 117 | + var passphrase = options.passphrase; | ||
| 118 | + if (key !== undefined) { | ||
| 119 | + if (Array.isArray(key)) { | ||
| 120 | + for (i = 0; i < key.length; ++i) { | ||
| 121 | + val = key[i]; | ||
| 122 | + // eslint-disable-next-line eqeqeq | ||
| 123 | + const pem = (val != undefined && val.pem !== undefined ? val.pem : val); | ||
| 124 | + validateKeyCert(pem, 'key'); | ||
| 125 | + c.context.setKey(pem, val.passphrase || passphrase); | ||
| 126 | + } | ||
| 117 | 127 | } else { | |
| 118 | - validateKeyCert(options.key, 'key'); | ||
| 119 | - c.context.setKey(options.key, options.passphrase); | ||
| 128 | + validateKeyCert(key, 'key'); | ||
| 129 | + c.context.setKey(key, passphrase); | ||
| 120 | 130 | } | |
| 121 | 131 | } | |
| 122 | 132 | ||
@@ -152,7 +162,6 @@ exports.createSecureContext = function createSecureContext(options, context) { | |||
| 152 | 162 | ||
| 153 | 163 | if (options.pfx) { | |
| 154 | 164 | var pfx = options.pfx; | |
| 155 | - var passphrase = options.passphrase; | ||
| 156 | 165 | ||
| 157 | 166 | if (!crypto) | |
| 158 | 167 | crypto = require('crypto'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments