OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/spawned_test_server/base_test_server.h" | 5 #include "net/test/spawned_test_server/base_test_server.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ptr_util.h" |
17 #include "base/path_service.h" | 18 #include "base/path_service.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "net/base/address_list.h" | 20 #include "net/base/address_list.h" |
20 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
21 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
22 #include "net/base/port_util.h" | 23 #include "net/base/port_util.h" |
23 #include "net/base/test_completion_callback.h" | 24 #include "net/base/test_completion_callback.h" |
24 #include "net/cert/test_root_certs.h" | 25 #include "net/cert/test_root_certs.h" |
25 #include "net/cert/x509_certificate.h" | 26 #include "net/cert/x509_certificate.h" |
26 #include "net/dns/host_resolver.h" | 27 #include "net/dns/host_resolver.h" |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 // { argument-name: argument-value, ... } | 529 // { argument-name: argument-value, ... } |
529 // Returns false if an invalid configuration is specified. | 530 // Returns false if an invalid configuration is specified. |
530 bool BaseTestServer::GenerateArguments(base::DictionaryValue* arguments) const { | 531 bool BaseTestServer::GenerateArguments(base::DictionaryValue* arguments) const { |
531 DCHECK(arguments); | 532 DCHECK(arguments); |
532 | 533 |
533 arguments->SetString("host", host_port_pair_.host()); | 534 arguments->SetString("host", host_port_pair_.host()); |
534 arguments->SetInteger("port", host_port_pair_.port()); | 535 arguments->SetInteger("port", host_port_pair_.port()); |
535 arguments->SetString("data-dir", document_root_.value()); | 536 arguments->SetString("data-dir", document_root_.value()); |
536 | 537 |
537 if (VLOG_IS_ON(1) || log_to_console_) | 538 if (VLOG_IS_ON(1) || log_to_console_) |
538 arguments->Set("log-to-console", base::Value::CreateNullValue()); | 539 arguments->Set("log-to-console", base::MakeUnique<base::Value>()); |
539 | 540 |
540 if (ws_basic_auth_) { | 541 if (ws_basic_auth_) { |
541 DCHECK(type_ == TYPE_WS || type_ == TYPE_WSS); | 542 DCHECK(type_ == TYPE_WS || type_ == TYPE_WSS); |
542 arguments->Set("ws-basic-auth", base::Value::CreateNullValue()); | 543 arguments->Set("ws-basic-auth", base::MakeUnique<base::Value>()); |
543 } | 544 } |
544 | 545 |
545 if (no_anonymous_ftp_user_) { | 546 if (no_anonymous_ftp_user_) { |
546 DCHECK_EQ(TYPE_FTP, type_); | 547 DCHECK_EQ(TYPE_FTP, type_); |
547 arguments->Set("no-anonymous-ftp-user", base::Value::CreateNullValue()); | 548 arguments->Set("no-anonymous-ftp-user", base::MakeUnique<base::Value>()); |
548 } | 549 } |
549 | 550 |
550 if (UsingSSL(type_)) { | 551 if (UsingSSL(type_)) { |
551 // Check the certificate arguments of the HTTPS server. | 552 // Check the certificate arguments of the HTTPS server. |
552 base::FilePath certificate_path(certificates_dir_); | 553 base::FilePath certificate_path(certificates_dir_); |
553 base::FilePath certificate_file(ssl_options_.GetCertificateFile()); | 554 base::FilePath certificate_file(ssl_options_.GetCertificateFile()); |
554 if (!certificate_file.value().empty()) { | 555 if (!certificate_file.value().empty()) { |
555 certificate_path = certificate_path.Append(certificate_file); | 556 certificate_path = certificate_path.Append(certificate_file); |
556 if (certificate_path.IsAbsolute() && | 557 if (certificate_path.IsAbsolute() && |
557 !base::PathExists(certificate_path)) { | 558 !base::PathExists(certificate_path)) { |
558 LOG(ERROR) << "Certificate path " << certificate_path.value() | 559 LOG(ERROR) << "Certificate path " << certificate_path.value() |
559 << " doesn't exist. Can't launch https server."; | 560 << " doesn't exist. Can't launch https server."; |
560 return false; | 561 return false; |
561 } | 562 } |
562 arguments->SetString("cert-and-key-file", certificate_path.value()); | 563 arguments->SetString("cert-and-key-file", certificate_path.value()); |
563 } | 564 } |
564 | 565 |
565 // Check the client certificate related arguments. | 566 // Check the client certificate related arguments. |
566 if (ssl_options_.request_client_certificate) | 567 if (ssl_options_.request_client_certificate) |
567 arguments->Set("ssl-client-auth", base::Value::CreateNullValue()); | 568 arguments->Set("ssl-client-auth", base::MakeUnique<base::Value>()); |
568 std::unique_ptr<base::ListValue> ssl_client_certs(new base::ListValue()); | 569 std::unique_ptr<base::ListValue> ssl_client_certs(new base::ListValue()); |
569 | 570 |
570 std::vector<base::FilePath>::const_iterator it; | 571 std::vector<base::FilePath>::const_iterator it; |
571 for (it = ssl_options_.client_authorities.begin(); | 572 for (it = ssl_options_.client_authorities.begin(); |
572 it != ssl_options_.client_authorities.end(); ++it) { | 573 it != ssl_options_.client_authorities.end(); ++it) { |
573 if (it->IsAbsolute() && !base::PathExists(*it)) { | 574 if (it->IsAbsolute() && !base::PathExists(*it)) { |
574 LOG(ERROR) << "Client authority path " << it->value() | 575 LOG(ERROR) << "Client authority path " << it->value() |
575 << " doesn't exist. Can't launch https server."; | 576 << " doesn't exist. Can't launch https server."; |
576 return false; | 577 return false; |
577 } | 578 } |
578 ssl_client_certs->AppendString(it->value()); | 579 ssl_client_certs->AppendString(it->value()); |
579 } | 580 } |
580 | 581 |
581 if (ssl_client_certs->GetSize()) | 582 if (ssl_client_certs->GetSize()) |
582 arguments->Set("ssl-client-ca", ssl_client_certs.release()); | 583 arguments->Set("ssl-client-ca", ssl_client_certs.release()); |
583 | 584 |
584 std::unique_ptr<base::ListValue> client_cert_types(new base::ListValue()); | 585 std::unique_ptr<base::ListValue> client_cert_types(new base::ListValue()); |
585 for (size_t i = 0; i < ssl_options_.client_cert_types.size(); i++) { | 586 for (size_t i = 0; i < ssl_options_.client_cert_types.size(); i++) { |
586 client_cert_types->AppendString( | 587 client_cert_types->AppendString( |
587 GetClientCertType(ssl_options_.client_cert_types[i])); | 588 GetClientCertType(ssl_options_.client_cert_types[i])); |
588 } | 589 } |
589 if (client_cert_types->GetSize()) | 590 if (client_cert_types->GetSize()) |
590 arguments->Set("ssl-client-cert-type", client_cert_types.release()); | 591 arguments->Set("ssl-client-cert-type", client_cert_types.release()); |
591 } | 592 } |
592 | 593 |
593 if (type_ == TYPE_HTTPS) { | 594 if (type_ == TYPE_HTTPS) { |
594 arguments->Set("https", base::Value::CreateNullValue()); | 595 arguments->Set("https", base::MakeUnique<base::Value>()); |
595 | 596 |
596 if (ssl_options_.server_certificate == | 597 if (ssl_options_.server_certificate == |
597 SSLOptions::CERT_AUTO_AIA_INTERMEDIATE) | 598 SSLOptions::CERT_AUTO_AIA_INTERMEDIATE) |
598 arguments->Set("aia-intermediate", base::Value::CreateNullValue()); | 599 arguments->Set("aia-intermediate", base::MakeUnique<base::Value>()); |
599 | 600 |
600 std::string ocsp_arg = ssl_options_.GetOCSPArgument(); | 601 std::string ocsp_arg = ssl_options_.GetOCSPArgument(); |
601 if (!ocsp_arg.empty()) | 602 if (!ocsp_arg.empty()) |
602 arguments->SetString("ocsp", ocsp_arg); | 603 arguments->SetString("ocsp", ocsp_arg); |
603 | 604 |
604 std::string ocsp_date_arg = ssl_options_.GetOCSPDateArgument(); | 605 std::string ocsp_date_arg = ssl_options_.GetOCSPDateArgument(); |
605 if (!ocsp_date_arg.empty()) | 606 if (!ocsp_date_arg.empty()) |
606 arguments->SetString("ocsp-date", ocsp_date_arg); | 607 arguments->SetString("ocsp-date", ocsp_date_arg); |
607 | 608 |
608 std::string ocsp_produced_arg = ssl_options_.GetOCSPProducedArgument(); | 609 std::string ocsp_produced_arg = ssl_options_.GetOCSPProducedArgument(); |
609 if (!ocsp_produced_arg.empty()) | 610 if (!ocsp_produced_arg.empty()) |
610 arguments->SetString("ocsp-produced", ocsp_produced_arg); | 611 arguments->SetString("ocsp-produced", ocsp_produced_arg); |
611 | 612 |
612 if (ssl_options_.cert_serial != 0) { | 613 if (ssl_options_.cert_serial != 0) { |
613 arguments->SetInteger("cert-serial", ssl_options_.cert_serial); | 614 arguments->SetInteger("cert-serial", ssl_options_.cert_serial); |
614 } | 615 } |
615 | 616 |
616 // Check key exchange argument. | 617 // Check key exchange argument. |
617 std::unique_ptr<base::ListValue> key_exchange_values(new base::ListValue()); | 618 std::unique_ptr<base::ListValue> key_exchange_values(new base::ListValue()); |
618 GetKeyExchangesList(ssl_options_.key_exchanges, key_exchange_values.get()); | 619 GetKeyExchangesList(ssl_options_.key_exchanges, key_exchange_values.get()); |
619 if (key_exchange_values->GetSize()) | 620 if (key_exchange_values->GetSize()) |
620 arguments->Set("ssl-key-exchange", key_exchange_values.release()); | 621 arguments->Set("ssl-key-exchange", key_exchange_values.release()); |
621 // Check bulk cipher argument. | 622 // Check bulk cipher argument. |
622 std::unique_ptr<base::ListValue> bulk_cipher_values(new base::ListValue()); | 623 std::unique_ptr<base::ListValue> bulk_cipher_values(new base::ListValue()); |
623 GetCiphersList(ssl_options_.bulk_ciphers, bulk_cipher_values.get()); | 624 GetCiphersList(ssl_options_.bulk_ciphers, bulk_cipher_values.get()); |
624 if (bulk_cipher_values->GetSize()) | 625 if (bulk_cipher_values->GetSize()) |
625 arguments->Set("ssl-bulk-cipher", bulk_cipher_values.release()); | 626 arguments->Set("ssl-bulk-cipher", bulk_cipher_values.release()); |
626 if (ssl_options_.record_resume) | 627 if (ssl_options_.record_resume) |
627 arguments->Set("https-record-resume", base::Value::CreateNullValue()); | 628 arguments->Set("https-record-resume", base::MakeUnique<base::Value>()); |
628 if (ssl_options_.tls_intolerant != SSLOptions::TLS_INTOLERANT_NONE) { | 629 if (ssl_options_.tls_intolerant != SSLOptions::TLS_INTOLERANT_NONE) { |
629 arguments->SetInteger("tls-intolerant", ssl_options_.tls_intolerant); | 630 arguments->SetInteger("tls-intolerant", ssl_options_.tls_intolerant); |
630 arguments->Set("tls-intolerance-type", GetTLSIntoleranceType( | 631 arguments->Set("tls-intolerance-type", GetTLSIntoleranceType( |
631 ssl_options_.tls_intolerance_type)); | 632 ssl_options_.tls_intolerance_type)); |
632 } | 633 } |
633 if (ssl_options_.fallback_scsv_enabled) | 634 if (ssl_options_.fallback_scsv_enabled) |
634 arguments->Set("fallback-scsv", base::Value::CreateNullValue()); | 635 arguments->Set("fallback-scsv", base::MakeUnique<base::Value>()); |
635 if (!ssl_options_.signed_cert_timestamps_tls_ext.empty()) { | 636 if (!ssl_options_.signed_cert_timestamps_tls_ext.empty()) { |
636 std::string b64_scts_tls_ext; | 637 std::string b64_scts_tls_ext; |
637 base::Base64Encode(ssl_options_.signed_cert_timestamps_tls_ext, | 638 base::Base64Encode(ssl_options_.signed_cert_timestamps_tls_ext, |
638 &b64_scts_tls_ext); | 639 &b64_scts_tls_ext); |
639 arguments->SetString("signed-cert-timestamps-tls-ext", b64_scts_tls_ext); | 640 arguments->SetString("signed-cert-timestamps-tls-ext", b64_scts_tls_ext); |
640 } | 641 } |
641 if (ssl_options_.staple_ocsp_response) | 642 if (ssl_options_.staple_ocsp_response) |
642 arguments->Set("staple-ocsp-response", base::Value::CreateNullValue()); | 643 arguments->Set("staple-ocsp-response", base::MakeUnique<base::Value>()); |
643 if (ssl_options_.ocsp_server_unavailable) { | 644 if (ssl_options_.ocsp_server_unavailable) { |
644 arguments->Set("ocsp-server-unavailable", | 645 arguments->Set("ocsp-server-unavailable", |
645 base::Value::CreateNullValue()); | 646 base::MakeUnique<base::Value>()); |
646 } | 647 } |
647 if (!ssl_options_.alpn_protocols.empty()) { | 648 if (!ssl_options_.alpn_protocols.empty()) { |
648 std::unique_ptr<base::ListValue> alpn_protocols(new base::ListValue()); | 649 std::unique_ptr<base::ListValue> alpn_protocols(new base::ListValue()); |
649 for (const std::string& proto : ssl_options_.alpn_protocols) { | 650 for (const std::string& proto : ssl_options_.alpn_protocols) { |
650 alpn_protocols->AppendString(proto); | 651 alpn_protocols->AppendString(proto); |
651 } | 652 } |
652 arguments->Set("alpn-protocols", std::move(alpn_protocols)); | 653 arguments->Set("alpn-protocols", std::move(alpn_protocols)); |
653 } | 654 } |
654 if (!ssl_options_.npn_protocols.empty()) { | 655 if (!ssl_options_.npn_protocols.empty()) { |
655 std::unique_ptr<base::ListValue> npn_protocols(new base::ListValue()); | 656 std::unique_ptr<base::ListValue> npn_protocols(new base::ListValue()); |
656 for (const std::string& proto : ssl_options_.npn_protocols) { | 657 for (const std::string& proto : ssl_options_.npn_protocols) { |
657 npn_protocols->AppendString(proto); | 658 npn_protocols->AppendString(proto); |
658 } | 659 } |
659 arguments->Set("npn-protocols", std::move(npn_protocols)); | 660 arguments->Set("npn-protocols", std::move(npn_protocols)); |
660 } | 661 } |
661 if (ssl_options_.alert_after_handshake) | 662 if (ssl_options_.alert_after_handshake) |
662 arguments->Set("alert-after-handshake", base::Value::CreateNullValue()); | 663 arguments->Set("alert-after-handshake", base::MakeUnique<base::Value>()); |
663 | 664 |
664 if (ssl_options_.disable_channel_id) | 665 if (ssl_options_.disable_channel_id) |
665 arguments->Set("disable-channel-id", base::Value::CreateNullValue()); | 666 arguments->Set("disable-channel-id", base::MakeUnique<base::Value>()); |
666 if (ssl_options_.disable_extended_master_secret) { | 667 if (ssl_options_.disable_extended_master_secret) { |
667 arguments->Set("disable-extended-master-secret", | 668 arguments->Set("disable-extended-master-secret", |
668 base::Value::CreateNullValue()); | 669 base::MakeUnique<base::Value>()); |
669 } | 670 } |
670 if (!ssl_options_.supported_token_binding_params.empty()) { | 671 if (!ssl_options_.supported_token_binding_params.empty()) { |
671 std::unique_ptr<base::ListValue> token_binding_params( | 672 std::unique_ptr<base::ListValue> token_binding_params( |
672 new base::ListValue()); | 673 new base::ListValue()); |
673 arguments->Set( | 674 arguments->Set( |
674 "token-binding-params", | 675 "token-binding-params", |
675 GetTokenBindingParams(ssl_options_.supported_token_binding_params)); | 676 GetTokenBindingParams(ssl_options_.supported_token_binding_params)); |
676 } | 677 } |
677 } | 678 } |
678 | 679 |
679 return GenerateAdditionalArguments(arguments); | 680 return GenerateAdditionalArguments(arguments); |
680 } | 681 } |
681 | 682 |
682 bool BaseTestServer::GenerateAdditionalArguments( | 683 bool BaseTestServer::GenerateAdditionalArguments( |
683 base::DictionaryValue* arguments) const { | 684 base::DictionaryValue* arguments) const { |
684 return true; | 685 return true; |
685 } | 686 } |
686 | 687 |
687 } // namespace net | 688 } // namespace net |
OLD | NEW |