Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2013 Google Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ | |
| 29 #define TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ | |
| 30 | |
| 31 #include "talk/app/webrtc/peerconnectioninterface.h" | |
| 32 | |
| 33 static const char kRSA_PRIVATE_KEY_PEM[] = | |
| 34 "-----BEGIN RSA PRIVATE KEY-----\n" | |
| 35 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" | |
| 36 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" | |
| 37 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" | |
| 38 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" | |
| 39 "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n" | |
| 40 "2TwXH9QANf4at4d9n/R6rzwpAJOpgwZgKvdQjkfrKTtgLV+/dawvpxUYkRH4JZM1\n" | |
| 41 "CVGukMfKNrSVH4Ap4QJBAOJmGV1ASPnB4r4nc99at7JuIJmd7fmuVUwUgYi4XgaR\n" | |
| 42 "WhScBsgYwZ/JoywdyZJgnbcrTDuVcWG56B3vXbhdpMsCQQDf9zeJrjnPZ3Cqm79y\n" | |
| 43 "kdqANep0uwZciiNiWxsQrCHztywOvbFhdp8iYVFG9EK8DMY41Y5TxUwsHD+67zao\n" | |
| 44 "ZNqJAkEA1suLUP/GvL8IwuRneQd2tWDqqRQ/Td3qq03hP7e77XtF/buya3Ghclo5\n" | |
| 45 "54czUR89QyVfJEC6278nzA7n2h1uVQJAcG6mztNL6ja/dKZjYZye2CY44QjSlLo0\n" | |
| 46 "MTgTSjdfg/28fFn2Jjtqf9Pi/X+50LWI/RcYMC2no606wRk9kyOuIQJBAK6VSAim\n" | |
| 47 "1pOEjsYQn0X5KEIrz1G3bfCbB848Ime3U2/FWlCHMr6ch8kCZ5d1WUeJD3LbwMNG\n" | |
| 48 "UCXiYxSsu20QNVw=\n" | |
| 49 "-----END RSA PRIVATE KEY-----\n"; | |
| 50 | |
| 51 static const char kCERT_PEM[] = | |
| 52 "-----BEGIN CERTIFICATE-----\n" | |
| 53 "MIIBmTCCAQKgAwIBAgIEbzBSAjANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDEwZX\n" | |
| 54 "ZWJSVEMwHhcNMTQwMTAyMTgyNDQ3WhcNMTQwMjAxMTgyNDQ3WjARMQ8wDQYDVQQD\n" | |
| 55 "EwZXZWJSVEMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYRkbhmI7kVA/rM\n" | |
| 56 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" | |
| 57 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" | |
| 58 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAEwDQYJKoZIhvcNAQELBQADgYEAUflI\n" | |
| 59 "VUe5Krqf5RVa5C3u/UTAOAUJBiDS3VANTCLBxjuMsvqOG0WvaYWP3HYPgrz0jXK2\n" | |
| 60 "LJE/mGw3MyFHEqi81jh95J+ypl6xKW6Rm8jKLR87gUvCaVYn/Z4/P3AqcQTB7wOv\n" | |
| 61 "UD0A8qfhfDM+LK6rPAnCsVN0NRDY3jvd6rzix9M=\n" | |
| 62 "-----END CERTIFICATE-----\n"; | |
| 63 | |
| 64 using webrtc::DTLSIdentityRequestObserver; | |
| 65 | |
| 66 class FakeIdentityService : public webrtc::DTLSIdentityServiceInterface, | |
| 67 public rtc::MessageHandler { | |
|
hbos
2015/06/12 12:46:55
This file has been renamed to fakedtlsidentitystor
| |
| 68 public: | |
| 69 struct Request { | |
| 70 Request(const std::string& common_name, | |
| 71 DTLSIdentityRequestObserver* observer) | |
| 72 : common_name(common_name), observer(observer) {} | |
| 73 | |
| 74 std::string common_name; | |
| 75 rtc::scoped_refptr<DTLSIdentityRequestObserver> observer; | |
| 76 }; | |
| 77 typedef rtc::TypedMessageData<Request> MessageData; | |
| 78 | |
| 79 FakeIdentityService() : should_fail_(false) {} | |
| 80 | |
| 81 void set_should_fail(bool should_fail) { | |
| 82 should_fail_ = should_fail; | |
| 83 } | |
| 84 | |
| 85 // DTLSIdentityServiceInterface implemenation. | |
| 86 virtual bool RequestIdentity(const std::string& identity_name, | |
| 87 const std::string& common_name, | |
| 88 DTLSIdentityRequestObserver* observer) { | |
| 89 MessageData* msg = new MessageData(Request(common_name, observer)); | |
| 90 if (should_fail_) { | |
| 91 rtc::Thread::Current()->Post(this, MSG_FAILURE, msg); | |
| 92 } else { | |
| 93 rtc::Thread::Current()->Post(this, MSG_SUCCESS, msg); | |
| 94 } | |
| 95 return true; | |
| 96 } | |
| 97 | |
| 98 private: | |
| 99 enum { | |
| 100 MSG_SUCCESS, | |
| 101 MSG_FAILURE, | |
| 102 }; | |
| 103 | |
| 104 // rtc::MessageHandler implementation. | |
| 105 void OnMessage(rtc::Message* msg) { | |
| 106 FakeIdentityService::MessageData* message_data = | |
| 107 static_cast<FakeIdentityService::MessageData*>(msg->pdata); | |
| 108 DTLSIdentityRequestObserver* observer = message_data->data().observer.get(); | |
| 109 switch (msg->message_id) { | |
| 110 case MSG_SUCCESS: { | |
| 111 std::string cert, key; | |
| 112 GenerateIdentity(message_data->data().common_name, &cert, &key); | |
| 113 observer->OnSuccess(cert, key); | |
| 114 break; | |
| 115 } | |
| 116 case MSG_FAILURE: | |
| 117 observer->OnFailure(0); | |
| 118 break; | |
| 119 } | |
| 120 delete message_data; | |
| 121 } | |
| 122 | |
| 123 void GenerateIdentity( | |
| 124 const std::string& common_name, | |
| 125 std::string* der_cert, | |
| 126 std::string* der_key) { | |
| 127 rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, der_cert); | |
| 128 rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", | |
| 129 kRSA_PRIVATE_KEY_PEM, | |
| 130 der_key); | |
| 131 } | |
| 132 | |
| 133 bool should_fail_; | |
| 134 }; | |
| 135 | |
| 136 #endif // TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ | |
| OLD | NEW |