| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 607f545 commit aefb20a
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,6 +129,8 @@ template class SSLWrap<TLSWrap>; | |||
| 129 | 129 | template void SSLWrap<TLSWrap>::AddMethods(Environment* env, | |
| 130 | 130 | Local<FunctionTemplate> t); | |
| 131 | 131 | template void SSLWrap<TLSWrap>::InitNPN(SecureContext* sc); | |
| 132 | + template void SSLWrap<TLSWrap>::SetSNIContext(SecureContext* sc); | ||
| 133 | + template int SSLWrap<TLSWrap>::SetCACerts(SecureContext* sc); | ||
| 132 | 134 | template SSL_SESSION* SSLWrap<TLSWrap>::GetSessionCallback( | |
| 133 | 135 | SSL* s, | |
| 134 | 136 | unsigned char* key, | |
@@ -2165,6 +2167,8 @@ void SSLWrap<Base>::CertCbDone(const FunctionCallbackInfo<Value>& args) { | |||
| 2165 | 2167 | rv = SSL_use_PrivateKey(w->ssl_, pkey); | |
| 2166 | 2168 | if (rv && chain != nullptr) | |
| 2167 | 2169 | rv = SSL_set1_chain(w->ssl_, chain); | |
| 2170 | + if (rv) | ||
| 2171 | + rv = w->SetCACerts(sc); | ||
| 2168 | 2172 | if (!rv) { | |
| 2169 | 2173 | unsigned long err = ERR_get_error(); | |
| 2170 | 2174 | if (!err) | |
@@ -2215,6 +2219,30 @@ void SSLWrap<Base>::DestroySSL() { | |||
| 2215 | 2219 | } | |
| 2216 | 2220 | ||
| 2217 | 2221 | ||
| 2222 | + template <class Base> | ||
| 2223 | + void SSLWrap<Base>::SetSNIContext(SecureContext* sc) { | ||
| 2224 | + InitNPN(sc); | ||
| 2225 | + CHECK_EQ(SSL_set_SSL_CTX(ssl_, sc->ctx_), sc->ctx_); | ||
| 2226 | + | ||
| 2227 | + SetCACerts(sc); | ||
| 2228 | + } | ||
| 2229 | + | ||
| 2230 | + | ||
| 2231 | + template <class Base> | ||
| 2232 | + int SSLWrap<Base>::SetCACerts(SecureContext* sc) { | ||
| 2233 | + int err = SSL_set1_verify_cert_store(ssl_, SSL_CTX_get_cert_store(sc->ctx_)); | ||
| 2234 | + if (err != 1) | ||
| 2235 | + return err; | ||
| 2236 | + | ||
| 2237 | + STACK_OF(X509_NAME)* list = SSL_dup_CA_list( | ||
| 2238 | + SSL_CTX_get_client_CA_list(sc->ctx_)); | ||
| 2239 | + | ||
| 2240 | + // NOTE: `SSL_set_client_CA_list` takes the ownership of `list` | ||
| 2241 | + SSL_set_client_CA_list(ssl_, list); | ||
| 2242 | + return 1; | ||
| 2243 | + } | ||
| 2244 | + | ||
| 2245 | + | ||
| 2218 | 2246 | void Connection::OnClientHelloParseEnd(void* arg) { | |
| 2219 | 2247 | Connection* conn = static_cast<Connection*>(arg); | |
| 2220 | 2248 | ||
@@ -2528,8 +2556,7 @@ int Connection::SelectSNIContextCallback_(SSL *s, int *ad, void* arg) { | |||
| 2528 | 2556 | if (secure_context_constructor_template->HasInstance(ret)) { | |
| 2529 | 2557 | conn->sni_context_.Reset(env->isolate(), ret); | |
| 2530 | 2558 | SecureContext* sc = Unwrap<SecureContext>(ret.As<Object>()); | |
| 2531 | - InitNPN(sc); | ||
| 2532 | - SSL_set_SSL_CTX(s, sc->ctx_); | ||
| 2559 | + conn->SetSNIContext(sc); | ||
| 2533 | 2560 | } else { | |
| 2534 | 2561 | return SSL_TLSEXT_ERR_NOACK; | |
| 2535 | 2562 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -279,6 +279,8 @@ class SSLWrap { | |||
| 279 | 279 | ||
| 280 | 280 | void DestroySSL(); | |
| 281 | 281 | void WaitForCertCb(CertCb cb, void* arg); | |
| 282 | + void SetSNIContext(SecureContext* sc); | ||
| 283 | + int SetCACerts(SecureContext* sc); | ||
| 282 | 284 | ||
| 283 | 285 | inline Environment* ssl_env() const { | |
| 284 | 286 | return env_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -867,8 +867,7 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { | |||
| 867 | 867 | p->sni_context_.Reset(env->isolate(), ctx); | |
| 868 | 868 | ||
| 869 | 869 | SecureContext* sc = Unwrap<SecureContext>(ctx.As<Object>()); | |
| 870 | - InitNPN(sc); | ||
| 871 | - SSL_set_SSL_CTX(s, sc->ctx_); | ||
| 870 | + p->SetSNIContext(sc); | ||
| 872 | 871 | return SSL_TLSEXT_ERR_OK; | |
| 873 | 872 | } | |
| 874 | 873 | #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,8 @@ function loadPEM(n) { | |||
| 26 | 26 | var serverOptions = { | |
| 27 | 27 | key: loadPEM('agent2-key'), | |
| 28 | 28 | cert: loadPEM('agent2-cert'), | |
| 29 | + requestCert: true, | ||
| 30 | + rejectUnauthorized: false, | ||
| 29 | 31 | SNICallback: function(servername, callback) { | |
| 30 | 32 | var context = SNIContexts[servername]; | |
| 31 | 33 | ||
@@ -46,7 +48,8 @@ var serverOptions = { | |||
| 46 | 48 | var SNIContexts = { | |
| 47 | 49 | 'a.example.com': { | |
| 48 | 50 | key: loadPEM('agent1-key'), | |
| 49 | - cert: loadPEM('agent1-cert') | ||
| 51 | + cert: loadPEM('agent1-cert'), | ||
| 52 | + ca: [ loadPEM('ca2-cert') ] | ||
| 50 | 53 | }, | |
| 51 | 54 | 'b.example.com': { | |
| 52 | 55 | key: loadPEM('agent3-key'), | |
@@ -66,6 +69,13 @@ var clientsOptions = [{ | |||
| 66 | 69 | ca: [loadPEM('ca1-cert')], | |
| 67 | 70 | servername: 'a.example.com', | |
| 68 | 71 | rejectUnauthorized: false | |
| 72 | + }, { | ||
| 73 | + port: serverPort, | ||
| 74 | + key: loadPEM('agent4-key'), | ||
| 75 | + cert: loadPEM('agent4-cert'), | ||
| 76 | + ca: [loadPEM('ca1-cert')], | ||
| 77 | + servername: 'a.example.com', | ||
| 78 | + rejectUnauthorized: false | ||
| 69 | 79 | }, { | |
| 70 | 80 | port: serverPort, | |
| 71 | 81 | key: loadPEM('agent2-key'), | |
@@ -97,7 +107,7 @@ let serverError; | |||
| 97 | 107 | let clientError; | |
| 98 | 108 | ||
| 99 | 109 | var server = tls.createServer(serverOptions, function(c) { | |
| 100 | - serverResults.push(c.servername); | ||
| 110 | + serverResults.push({ sni: c.servername, authorized: c.authorized }); | ||
| 101 | 111 | }); | |
| 102 | 112 | ||
| 103 | 113 | server.on('clientError', function(err) { | |
@@ -144,9 +154,16 @@ function startTest() { | |||
| 144 | 154 | } | |
| 145 | 155 | ||
| 146 | 156 | process.on('exit', function() { | |
| 147 | - assert.deepEqual(serverResults, ['a.example.com', 'b.example.com', | ||
| 148 | - 'c.wrong.com', null]); | ||
| 149 | - assert.deepEqual(clientResults, [true, true, false, false]); | ||
| 150 | - assert.deepEqual(clientErrors, [null, null, null, 'socket hang up']); | ||
| 151 | - assert.deepEqual(serverErrors, [null, null, null, 'Invalid SNI context']); | ||
| 157 | + assert.deepEqual(serverResults, [ | ||
| 158 | + { sni: 'a.example.com', authorized: false }, | ||
| 159 | + { sni: 'a.example.com', authorized: true }, | ||
| 160 | + { sni: 'b.example.com', authorized: false }, | ||
| 161 | + { sni: 'c.wrong.com', authorized: false }, | ||
| 162 | + null | ||
| 163 | + ]); | ||
| 164 | + assert.deepEqual(clientResults, [true, true, true, false, false]); | ||
| 165 | + assert.deepEqual(clientErrors, [null, null, null, null, 'socket hang up']); | ||
| 166 | + assert.deepEqual(serverErrors, [ | ||
| 167 | + null, null, null, null, 'Invalid SNI context' | ||
| 168 | + ]); | ||
| 152 | 169 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments