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/test/base_test_server.h" | 5 #include "net/test/base_test_server.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (cipher & BaseTestServer::HTTPSOptions::BULK_CIPHER_AES256) | 48 if (cipher & BaseTestServer::HTTPSOptions::BULK_CIPHER_AES256) |
49 values->Append(base::Value::CreateStringValue("aes256")); | 49 values->Append(base::Value::CreateStringValue("aes256")); |
50 if (cipher & BaseTestServer::HTTPSOptions::BULK_CIPHER_3DES) | 50 if (cipher & BaseTestServer::HTTPSOptions::BULK_CIPHER_3DES) |
51 values->Append(base::Value::CreateStringValue("3des")); | 51 values->Append(base::Value::CreateStringValue("3des")); |
52 } | 52 } |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 BaseTestServer::HTTPSOptions::HTTPSOptions() | 56 BaseTestServer::HTTPSOptions::HTTPSOptions() |
57 : server_certificate(CERT_OK), | 57 : server_certificate(CERT_OK), |
| 58 ocsp_status(OCSP_OK), |
58 request_client_certificate(false), | 59 request_client_certificate(false), |
59 bulk_ciphers(HTTPSOptions::BULK_CIPHER_ANY), | 60 bulk_ciphers(HTTPSOptions::BULK_CIPHER_ANY), |
60 record_resume(false) {} | 61 record_resume(false) {} |
61 | 62 |
62 BaseTestServer::HTTPSOptions::HTTPSOptions( | 63 BaseTestServer::HTTPSOptions::HTTPSOptions( |
63 BaseTestServer::HTTPSOptions::ServerCertificate cert) | 64 BaseTestServer::HTTPSOptions::ServerCertificate cert) |
64 : server_certificate(cert), | 65 : server_certificate(cert), |
65 request_client_certificate(false), | 66 request_client_certificate(false), |
66 bulk_ciphers(HTTPSOptions::BULK_CIPHER_ANY), | 67 bulk_ciphers(HTTPSOptions::BULK_CIPHER_ANY), |
67 record_resume(false) {} | 68 record_resume(false) {} |
68 | 69 |
69 BaseTestServer::HTTPSOptions::~HTTPSOptions() {} | 70 BaseTestServer::HTTPSOptions::~HTTPSOptions() {} |
70 | 71 |
71 FilePath BaseTestServer::HTTPSOptions::GetCertificateFile() const { | 72 FilePath BaseTestServer::HTTPSOptions::GetCertificateFile() const { |
72 switch (server_certificate) { | 73 switch (server_certificate) { |
73 case CERT_OK: | 74 case CERT_OK: |
74 case CERT_MISMATCHED_NAME: | 75 case CERT_MISMATCHED_NAME: |
75 return FilePath(FILE_PATH_LITERAL("ok_cert.pem")); | 76 return FilePath(FILE_PATH_LITERAL("ok_cert.pem")); |
76 case CERT_EXPIRED: | 77 case CERT_EXPIRED: |
77 return FilePath(FILE_PATH_LITERAL("expired_cert.pem")); | 78 return FilePath(FILE_PATH_LITERAL("expired_cert.pem")); |
78 case CERT_CHAIN_WRONG_ROOT: | 79 case CERT_CHAIN_WRONG_ROOT: |
79 // This chain uses its own dedicated test root certificate to avoid | 80 // This chain uses its own dedicated test root certificate to avoid |
80 // side-effects that may affect testing. | 81 // side-effects that may affect testing. |
81 return FilePath(FILE_PATH_LITERAL("redundant-server-chain.pem")); | 82 return FilePath(FILE_PATH_LITERAL("redundant-server-chain.pem")); |
| 83 case CERT_AUTO: |
| 84 return FilePath(); |
82 default: | 85 default: |
83 NOTREACHED(); | 86 NOTREACHED(); |
84 } | 87 } |
85 return FilePath(); | 88 return FilePath(); |
86 } | 89 } |
87 | 90 |
| 91 std::string BaseTestServer::HTTPSOptions::GetOCSPArgument() const { |
| 92 if (server_certificate != CERT_AUTO) |
| 93 return ""; |
| 94 |
| 95 switch (ocsp_status) { |
| 96 case OCSP_OK: |
| 97 return "ok"; |
| 98 case OCSP_REVOKED: |
| 99 return "revoked"; |
| 100 case OCSP_INVALID: |
| 101 return "invalid"; |
| 102 default: |
| 103 NOTREACHED(); |
| 104 return ""; |
| 105 } |
| 106 } |
| 107 |
88 const char BaseTestServer::kLocalhost[] = "127.0.0.1"; | 108 const char BaseTestServer::kLocalhost[] = "127.0.0.1"; |
89 const char BaseTestServer::kGDataAuthToken[] = "testtoken"; | 109 const char BaseTestServer::kGDataAuthToken[] = "testtoken"; |
90 | 110 |
91 BaseTestServer::BaseTestServer(Type type, const std::string& host) | 111 BaseTestServer::BaseTestServer(Type type, const std::string& host) |
92 : type_(type), | 112 : type_(type), |
93 started_(false), | 113 started_(false), |
94 log_to_console_(false) { | 114 log_to_console_(false) { |
95 Init(host); | 115 Init(host); |
96 } | 116 } |
97 | 117 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 DCHECK(arguments); | 322 DCHECK(arguments); |
303 | 323 |
304 arguments->SetString("host", host_port_pair_.host()); | 324 arguments->SetString("host", host_port_pair_.host()); |
305 arguments->SetInteger("port", host_port_pair_.port()); | 325 arguments->SetInteger("port", host_port_pair_.port()); |
306 arguments->SetString("data-dir", document_root_.value()); | 326 arguments->SetString("data-dir", document_root_.value()); |
307 | 327 |
308 if (VLOG_IS_ON(1) || log_to_console_) | 328 if (VLOG_IS_ON(1) || log_to_console_) |
309 arguments->Set("log-to-console", base::Value::CreateNullValue()); | 329 arguments->Set("log-to-console", base::Value::CreateNullValue()); |
310 | 330 |
311 if (type_ == TYPE_HTTPS) { | 331 if (type_ == TYPE_HTTPS) { |
| 332 arguments->Set("https", base::Value::CreateNullValue()); |
| 333 |
312 // Check the certificate arguments of the HTTPS server. | 334 // Check the certificate arguments of the HTTPS server. |
313 FilePath certificate_path(certificates_dir_); | 335 FilePath certificate_path(certificates_dir_); |
314 certificate_path = certificate_path.Append( | 336 FilePath certificate_file(https_options_.GetCertificateFile()); |
315 https_options_.GetCertificateFile()); | 337 if (!certificate_file.value().empty()) { |
316 if (certificate_path.IsAbsolute() && | 338 certificate_path = certificate_path.Append(certificate_file); |
317 !file_util::PathExists(certificate_path)) { | 339 if (certificate_path.IsAbsolute() && |
318 LOG(ERROR) << "Certificate path " << certificate_path.value() | 340 !file_util::PathExists(certificate_path)) { |
319 << " doesn't exist. Can't launch https server."; | 341 LOG(ERROR) << "Certificate path " << certificate_path.value() |
320 return false; | 342 << " doesn't exist. Can't launch https server."; |
| 343 return false; |
| 344 } |
| 345 arguments->SetString("cert-and-key-file", certificate_path.value()); |
321 } | 346 } |
322 arguments->SetString("https", certificate_path.value()); | 347 |
| 348 std::string ocsp_arg = https_options_.GetOCSPArgument(); |
| 349 if (!ocsp_arg.empty()) |
| 350 arguments->SetString("ocsp", ocsp_arg); |
323 | 351 |
324 // Check the client certificate related arguments. | 352 // Check the client certificate related arguments. |
325 if (https_options_.request_client_certificate) | 353 if (https_options_.request_client_certificate) |
326 arguments->Set("ssl-client-auth", base::Value::CreateNullValue()); | 354 arguments->Set("ssl-client-auth", base::Value::CreateNullValue()); |
327 scoped_ptr<base::ListValue> ssl_client_certs(new base::ListValue()); | 355 scoped_ptr<base::ListValue> ssl_client_certs(new base::ListValue()); |
328 | 356 |
329 std::vector<FilePath>::const_iterator it; | 357 std::vector<FilePath>::const_iterator it; |
330 for (it = https_options_.client_authorities.begin(); | 358 for (it = https_options_.client_authorities.begin(); |
331 it != https_options_.client_authorities.end(); ++it) { | 359 it != https_options_.client_authorities.end(); ++it) { |
332 if (it->IsAbsolute() && !file_util::PathExists(*it)) { | 360 if (it->IsAbsolute() && !file_util::PathExists(*it)) { |
(...skipping 12 matching lines...) Expand all Loading... |
345 GetCiphersList(https_options_.bulk_ciphers, bulk_cipher_values.get()); | 373 GetCiphersList(https_options_.bulk_ciphers, bulk_cipher_values.get()); |
346 if (bulk_cipher_values->GetSize()) | 374 if (bulk_cipher_values->GetSize()) |
347 arguments->Set("ssl-bulk-cipher", bulk_cipher_values.release()); | 375 arguments->Set("ssl-bulk-cipher", bulk_cipher_values.release()); |
348 if (https_options_.record_resume) | 376 if (https_options_.record_resume) |
349 arguments->Set("https-record-resume", base::Value::CreateNullValue()); | 377 arguments->Set("https-record-resume", base::Value::CreateNullValue()); |
350 } | 378 } |
351 return true; | 379 return true; |
352 } | 380 } |
353 | 381 |
354 } // namespace net | 382 } // namespace net |
OLD | NEW |