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 #include "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include "crypto/ec_private_key.h" | 7 #include "crypto/ec_private_key.h" |
8 #include "crypto/ec_signature_creator.h" | 8 #include "crypto/ec_signature_creator.h" |
9 #include "crypto/signature_creator.h" | 9 #include "crypto/signature_creator.h" |
10 #include "net/base/asn1_util.h" | 10 #include "net/base/asn1_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 transport_params_, | 56 transport_params_, |
57 MEDIUM, | 57 MEDIUM, |
58 callback.callback(), | 58 callback.callback(), |
59 http_session_->GetTransportSocketPool(), | 59 http_session_->GetTransportSocketPool(), |
60 BoundNetLog())); | 60 BoundNetLog())); |
61 EXPECT_EQ(OK, callback.WaitForResult()); | 61 EXPECT_EQ(OK, callback.WaitForResult()); |
62 return session_->InitializeWithSocket(connection.release(), false, OK); | 62 return session_->InitializeWithSocket(connection.release(), false, OK); |
63 } | 63 } |
64 | 64 |
65 void TestSendCredentials( | 65 void TestSendCredentials( |
66 OriginBoundCertService* obc_service, | 66 ServerBoundCertService* server_bound_cert_service, |
67 const std::string& cert, | 67 const std::string& cert, |
68 const std::string& proof, | 68 const std::string& proof, |
69 SSLClientCertType type); | 69 SSLClientCertType type); |
70 | 70 |
71 SpdySessionDependencies session_deps_; | 71 SpdySessionDependencies session_deps_; |
72 scoped_ptr<OrderedSocketData> data_; | 72 scoped_ptr<OrderedSocketData> data_; |
73 scoped_refptr<HttpNetworkSession> http_session_; | 73 scoped_refptr<HttpNetworkSession> http_session_; |
74 scoped_refptr<SpdySession> session_; | 74 scoped_refptr<SpdySession> session_; |
75 scoped_refptr<TransportSocketParams> transport_params_; | 75 scoped_refptr<TransportSocketParams> transport_params_; |
76 }; | 76 }; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 // Because we abandoned the stream, we don't expect to find a session in the | 238 // Because we abandoned the stream, we don't expect to find a session in the |
239 // pool anymore. | 239 // pool anymore. |
240 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 240 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
241 EXPECT_TRUE(data()->at_read_eof()); | 241 EXPECT_TRUE(data()->at_read_eof()); |
242 EXPECT_TRUE(data()->at_write_eof()); | 242 EXPECT_TRUE(data()->at_write_eof()); |
243 } | 243 } |
244 | 244 |
245 namespace { | 245 namespace { |
246 | 246 |
247 void GetECOriginBoundCertAndProof(const std::string& origin, | 247 void GetECServerBoundCertAndProof( |
248 OriginBoundCertService* obc_service, | 248 const std::string& origin, |
249 std::string* cert, | 249 ServerBoundCertService* server_bound_cert_service, |
250 std::string* proof) { | 250 std::string* cert, |
| 251 std::string* proof) { |
251 TestCompletionCallback callback; | 252 TestCompletionCallback callback; |
252 std::vector<uint8> requested_cert_types; | 253 std::vector<uint8> requested_cert_types; |
253 requested_cert_types.push_back(CLIENT_CERT_ECDSA_SIGN); | 254 requested_cert_types.push_back(CLIENT_CERT_ECDSA_SIGN); |
254 SSLClientCertType cert_type; | 255 SSLClientCertType cert_type; |
255 std::string key; | 256 std::string key; |
256 OriginBoundCertService::RequestHandle request_handle; | 257 ServerBoundCertService::RequestHandle request_handle; |
257 int rv = obc_service->GetOriginBoundCert(origin, requested_cert_types, | 258 int rv = server_bound_cert_service->GetDomainBoundCert( |
258 &cert_type, &key, cert, | 259 origin, requested_cert_types, &cert_type, &key, cert, callback.callback(), |
259 callback.callback(), | 260 &request_handle); |
260 &request_handle); | |
261 EXPECT_EQ(ERR_IO_PENDING, rv); | 261 EXPECT_EQ(ERR_IO_PENDING, rv); |
262 EXPECT_EQ(OK, callback.WaitForResult()); | 262 EXPECT_EQ(OK, callback.WaitForResult()); |
263 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, cert_type); | 263 EXPECT_EQ(CLIENT_CERT_ECDSA_SIGN, cert_type); |
264 | 264 |
265 unsigned char secret[32]; | 265 unsigned char secret[32]; |
266 memset(secret, 'A', arraysize(secret)); | 266 memset(secret, 'A', arraysize(secret)); |
267 | 267 |
268 // Convert the key string into a vector<unit8> | 268 // Convert the key string into a vector<unit8> |
269 std::vector<uint8> key_data(key.begin(), key.end()); | 269 std::vector<uint8> key_data(key.begin(), key.end()); |
270 | 270 |
271 base::StringPiece spki_piece; | 271 base::StringPiece spki_piece; |
272 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(*cert, &spki_piece)); | 272 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(*cert, &spki_piece)); |
273 std::vector<uint8> spki(spki_piece.data(), | 273 std::vector<uint8> spki(spki_piece.data(), |
274 spki_piece.data() + spki_piece.size()); | 274 spki_piece.data() + spki_piece.size()); |
275 | 275 |
276 std::vector<uint8> proof_data; | 276 std::vector<uint8> proof_data; |
277 scoped_ptr<crypto::ECPrivateKey> private_key( | 277 scoped_ptr<crypto::ECPrivateKey> private_key( |
278 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( | 278 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( |
279 OriginBoundCertService::kEPKIPassword, key_data, spki)); | 279 ServerBoundCertService::kEPKIPassword, key_data, spki)); |
280 scoped_ptr<crypto::ECSignatureCreator> creator( | 280 scoped_ptr<crypto::ECSignatureCreator> creator( |
281 crypto::ECSignatureCreator::Create(private_key.get())); | 281 crypto::ECSignatureCreator::Create(private_key.get())); |
282 creator->Sign(secret, arraysize(secret), &proof_data); | 282 creator->Sign(secret, arraysize(secret), &proof_data); |
283 proof->assign(proof_data.begin(), proof_data.end()); | 283 proof->assign(proof_data.begin(), proof_data.end()); |
284 } | 284 } |
285 | 285 |
286 } // namespace | 286 } // namespace |
287 | 287 |
288 // TODO(rch): When openssl supports origin bound certifictes, this | 288 // TODO(rch): When openssl supports server bound certifictes, this |
289 // guard can be removed | 289 // guard can be removed |
290 #if !defined(USE_OPENSSL) | 290 #if !defined(USE_OPENSSL) |
291 // Test that if we request a resource for a new origin on a session that | 291 // Test that if we request a resource for a new origin on a session that |
292 // used origin bound certificates, that we send a CREDENTIAL frame for | 292 // used domain bound certificates, that we send a CREDENTIAL frame for |
293 // the new origin before we send the new request. | 293 // the new domain before we send the new request. |
294 void SpdyHttpStreamSpdy3Test::TestSendCredentials( | 294 void SpdyHttpStreamSpdy3Test::TestSendCredentials( |
295 OriginBoundCertService* obc_service, | 295 ServerBoundCertService* server_bound_cert_service, |
296 const std::string& cert, | 296 const std::string& cert, |
297 const std::string& proof, | 297 const std::string& proof, |
298 SSLClientCertType type) { | 298 SSLClientCertType type) { |
299 EnableCompression(false); | 299 EnableCompression(false); |
300 | 300 |
301 spdy::SpdyCredential cred; | 301 spdy::SpdyCredential cred; |
302 cred.slot = 1; | 302 cred.slot = 1; |
303 cred.proof = proof; | 303 cred.proof = proof; |
304 cred.certs.push_back(cert); | 304 cred.certs.push_back(cert); |
305 | 305 |
(...skipping 18 matching lines...) Expand all Loading... |
324 HostPortPair host_port_pair("www.google.com", 80); | 324 HostPortPair host_port_pair("www.google.com", 80); |
325 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | 325 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
326 | 326 |
327 DeterministicMockClientSocketFactory* socket_factory = | 327 DeterministicMockClientSocketFactory* socket_factory = |
328 session_deps_.deterministic_socket_factory.get(); | 328 session_deps_.deterministic_socket_factory.get(); |
329 scoped_refptr<DeterministicSocketData> data( | 329 scoped_refptr<DeterministicSocketData> data( |
330 new DeterministicSocketData(reads, arraysize(reads), | 330 new DeterministicSocketData(reads, arraysize(reads), |
331 writes, arraysize(writes))); | 331 writes, arraysize(writes))); |
332 socket_factory->AddSocketDataProvider(data.get()); | 332 socket_factory->AddSocketDataProvider(data.get()); |
333 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 333 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
334 ssl.origin_bound_cert_type = type; | 334 ssl.domain_bound_cert_type = type; |
335 ssl.origin_bound_cert_service = obc_service; | 335 ssl.server_bound_cert_service = server_bound_cert_service; |
336 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY3; | 336 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY3; |
337 socket_factory->AddSSLSocketDataProvider(&ssl); | 337 socket_factory->AddSSLSocketDataProvider(&ssl); |
338 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( | 338 http_session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
339 &session_deps_); | 339 &session_deps_); |
340 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); | 340 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); |
341 transport_params_ = new TransportSocketParams(host_port_pair, | 341 transport_params_ = new TransportSocketParams(host_port_pair, |
342 MEDIUM, false, false); | 342 MEDIUM, false, false); |
343 TestCompletionCallback callback; | 343 TestCompletionCallback callback; |
344 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 344 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
345 SSLConfig ssl_config; | 345 SSLConfig ssl_config; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 private: | 448 private: |
449 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); | 449 DISALLOW_COPY_AND_ASSIGN(MockECSignatureCreatorFactory); |
450 }; | 450 }; |
451 | 451 |
452 TEST_F(SpdyHttpStreamSpdy3Test, SendCredentialsEC) { | 452 TEST_F(SpdyHttpStreamSpdy3Test, SendCredentialsEC) { |
453 scoped_ptr<crypto::ECSignatureCreatorFactory> ec_signature_creator_factory( | 453 scoped_ptr<crypto::ECSignatureCreatorFactory> ec_signature_creator_factory( |
454 new MockECSignatureCreatorFactory()); | 454 new MockECSignatureCreatorFactory()); |
455 crypto::ECSignatureCreator::SetFactoryForTesting( | 455 crypto::ECSignatureCreator::SetFactoryForTesting( |
456 ec_signature_creator_factory.get()); | 456 ec_signature_creator_factory.get()); |
457 | 457 |
458 scoped_ptr<OriginBoundCertService> obc_service( | 458 scoped_ptr<ServerBoundCertService> server_bound_cert_service( |
459 new OriginBoundCertService(new DefaultOriginBoundCertStore(NULL))); | 459 new ServerBoundCertService(new DefaultServerBoundCertStore(NULL))); |
460 std::string cert; | 460 std::string cert; |
461 std::string proof; | 461 std::string proof; |
462 GetECOriginBoundCertAndProof("http://www.gmail.com/", obc_service.get(), | 462 GetECServerBoundCertAndProof("http://www.gmail.com/", |
| 463 server_bound_cert_service.get(), |
463 &cert, &proof); | 464 &cert, &proof); |
464 | 465 |
465 TestSendCredentials(obc_service.get(), cert, proof, CLIENT_CERT_ECDSA_SIGN); | 466 TestSendCredentials(server_bound_cert_service.get(), cert, proof, |
| 467 CLIENT_CERT_ECDSA_SIGN); |
466 } | 468 } |
467 | 469 |
468 #endif // !defined(USE_OPENSSL) | 470 #endif // !defined(USE_OPENSSL) |
469 | 471 |
470 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 472 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
471 // methods. | 473 // methods. |
472 | 474 |
473 } // namespace net | 475 } // namespace net |
OLD | NEW |