OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
7 | 7 |
8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 // TLS extension number use for Token Binding. | 86 // TLS extension number use for Token Binding. |
87 const unsigned int kTbExtNum = 30033; | 87 const unsigned int kTbExtNum = 30033; |
88 | 88 |
89 // Token Binding ProtocolVersions supported. | 89 // Token Binding ProtocolVersions supported. |
90 const uint8_t kTbProtocolVersionMajor = 0; | 90 const uint8_t kTbProtocolVersionMajor = 0; |
91 const uint8_t kTbProtocolVersionMinor = 3; | 91 const uint8_t kTbProtocolVersionMinor = 3; |
92 const uint8_t kTbMinProtocolVersionMajor = 0; | 92 const uint8_t kTbMinProtocolVersionMajor = 0; |
93 const uint8_t kTbMinProtocolVersionMinor = 2; | 93 const uint8_t kTbMinProtocolVersionMinor = 2; |
94 | 94 |
95 void FreeX509Stack(STACK_OF(X509)* ptr) { | |
96 sk_X509_pop_free(ptr, X509_free); | |
97 } | |
98 | |
99 using ScopedX509Stack = crypto::ScopedOpenSSL<STACK_OF(X509), FreeX509Stack>; | |
100 | |
101 // Used for encoding the |connection_status| field of an SSLInfo object. | |
102 int EncodeSSLConnectionStatus(uint16 cipher_suite, | |
103 int compression, | |
104 int version) { | |
105 return cipher_suite | | |
106 ((compression & SSL_CONNECTION_COMPRESSION_MASK) << | |
107 SSL_CONNECTION_COMPRESSION_SHIFT) | | |
108 ((version & SSL_CONNECTION_VERSION_MASK) << | |
109 SSL_CONNECTION_VERSION_SHIFT); | |
110 } | |
111 | |
112 // Returns the net SSL version number (see ssl_connection_status_flags.h) for | |
113 // this SSL connection. | |
114 int GetNetSSLVersion(SSL* ssl) { | |
115 switch (SSL_version(ssl)) { | |
116 case TLS1_VERSION: | |
117 return SSL_CONNECTION_VERSION_TLS1; | |
118 case TLS1_1_VERSION: | |
119 return SSL_CONNECTION_VERSION_TLS1_1; | |
120 case TLS1_2_VERSION: | |
121 return SSL_CONNECTION_VERSION_TLS1_2; | |
122 default: | |
123 NOTREACHED(); | |
124 return SSL_CONNECTION_VERSION_UNKNOWN; | |
125 } | |
126 } | |
127 | |
128 ScopedX509 OSCertHandleToOpenSSL( | |
129 X509Certificate::OSCertHandle os_handle) { | |
130 #if defined(USE_OPENSSL_CERTS) | |
131 return ScopedX509(X509Certificate::DupOSCertHandle(os_handle)); | |
132 #else // !defined(USE_OPENSSL_CERTS) | |
133 std::string der_encoded; | |
134 if (!X509Certificate::GetDEREncoded(os_handle, &der_encoded)) | |
135 return ScopedX509(); | |
136 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_encoded.data()); | |
137 return ScopedX509(d2i_X509(NULL, &bytes, der_encoded.size())); | |
138 #endif // defined(USE_OPENSSL_CERTS) | |
139 } | |
140 | |
141 ScopedX509Stack OSCertHandlesToOpenSSL( | |
142 const X509Certificate::OSCertHandles& os_handles) { | |
143 ScopedX509Stack stack(sk_X509_new_null()); | |
144 for (size_t i = 0; i < os_handles.size(); i++) { | |
145 ScopedX509 x509 = OSCertHandleToOpenSSL(os_handles[i]); | |
146 if (!x509) | |
147 return ScopedX509Stack(); | |
148 sk_X509_push(stack.get(), x509.release()); | |
149 } | |
150 return stack.Pass(); | |
151 } | |
152 | |
153 bool EVP_MDToPrivateKeyHash(const EVP_MD* md, SSLPrivateKey::Hash* hash) { | 95 bool EVP_MDToPrivateKeyHash(const EVP_MD* md, SSLPrivateKey::Hash* hash) { |
154 switch (EVP_MD_type(md)) { | 96 switch (EVP_MD_type(md)) { |
155 case NID_md5_sha1: | 97 case NID_md5_sha1: |
156 *hash = SSLPrivateKey::Hash::MD5_SHA1; | 98 *hash = SSLPrivateKey::Hash::MD5_SHA1; |
157 return true; | 99 return true; |
158 case NID_sha1: | 100 case NID_sha1: |
159 *hash = SSLPrivateKey::Hash::SHA1; | 101 *hash = SSLPrivateKey::Hash::SHA1; |
160 return true; | 102 return true; |
161 case NID_sha256: | 103 case NID_sha256: |
162 *hash = SSLPrivateKey::Hash::SHA256; | 104 *hash = SSLPrivateKey::Hash::SHA256; |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2262 tb_was_negotiated_ = true; | 2204 tb_was_negotiated_ = true; |
2263 return 1; | 2205 return 1; |
2264 } | 2206 } |
2265 } | 2207 } |
2266 | 2208 |
2267 *out_alert_value = SSL_AD_ILLEGAL_PARAMETER; | 2209 *out_alert_value = SSL_AD_ILLEGAL_PARAMETER; |
2268 return 0; | 2210 return 0; |
2269 } | 2211 } |
2270 | 2212 |
2271 } // namespace net | 2213 } // namespace net |
OLD | NEW |