OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 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, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 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 | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #ifndef TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ | 28 #ifndef TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ |
29 #define TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ | 29 #define TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ |
30 | 30 |
31 #include "talk/app/webrtc/dtlscertificate.h" | |
32 #include "talk/app/webrtc/dtlsidentitystore.h" | |
31 #include "talk/app/webrtc/peerconnectioninterface.h" | 33 #include "talk/app/webrtc/peerconnectioninterface.h" |
32 | 34 |
33 static const char kRSA_PRIVATE_KEY_PEM[] = | 35 static const char kRSA_PRIVATE_KEY_PEM[] = |
34 "-----BEGIN RSA PRIVATE KEY-----\n" | 36 "-----BEGIN RSA PRIVATE KEY-----\n" |
35 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" | 37 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" |
36 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" | 38 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" |
37 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" | 39 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" |
38 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" | 40 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" |
39 "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n" | 41 "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n" |
40 "2TwXH9QANf4at4d9n/R6rzwpAJOpgwZgKvdQjkfrKTtgLV+/dawvpxUYkRH4JZM1\n" | 42 "2TwXH9QANf4at4d9n/R6rzwpAJOpgwZgKvdQjkfrKTtgLV+/dawvpxUYkRH4JZM1\n" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 DTLSIdentityRequestObserver* observer) { | 90 DTLSIdentityRequestObserver* observer) { |
89 MessageData* msg = new MessageData(Request(common_name, observer)); | 91 MessageData* msg = new MessageData(Request(common_name, observer)); |
90 if (should_fail_) { | 92 if (should_fail_) { |
91 rtc::Thread::Current()->Post(this, MSG_FAILURE, msg); | 93 rtc::Thread::Current()->Post(this, MSG_FAILURE, msg); |
92 } else { | 94 } else { |
93 rtc::Thread::Current()->Post(this, MSG_SUCCESS, msg); | 95 rtc::Thread::Current()->Post(this, MSG_SUCCESS, msg); |
94 } | 96 } |
95 return true; | 97 return true; |
96 } | 98 } |
97 | 99 |
100 static rtc::scoped_refptr<webrtc::DtlsCertificate> GenerateCertificate() { | |
101 std::string cert; | |
102 std::string key; | |
103 GenerateIdentity(webrtc::DtlsIdentityStore::kIdentityName, &cert, &key); | |
104 | |
105 std::string pem_cert = rtc::SSLIdentity::DerToPem( | |
106 rtc::kPemTypeCertificate, | |
107 reinterpret_cast<const unsigned char*>(cert.data()), | |
108 cert.length()); | |
109 std::string pem_key = rtc::SSLIdentity::DerToPem( | |
110 rtc::kPemTypeRsaPrivateKey, | |
111 reinterpret_cast<const unsigned char*>(key.data()), | |
112 key.length()); | |
113 rtc::scoped_ptr<rtc::SSLIdentity> identity( | |
114 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert)); | |
115 | |
116 return webrtc::DtlsCertificate::Create(identity.Pass()); | |
117 } | |
118 | |
98 private: | 119 private: |
99 enum { | 120 enum { |
100 MSG_SUCCESS, | 121 MSG_SUCCESS, |
101 MSG_FAILURE, | 122 MSG_FAILURE, |
102 }; | 123 }; |
103 | 124 |
104 // rtc::MessageHandler implementation. | 125 // rtc::MessageHandler implementation. |
105 void OnMessage(rtc::Message* msg) { | 126 void OnMessage(rtc::Message* msg) { |
106 FakeIdentityService::MessageData* message_data = | 127 FakeIdentityService::MessageData* message_data = |
107 static_cast<FakeIdentityService::MessageData*>(msg->pdata); | 128 static_cast<FakeIdentityService::MessageData*>(msg->pdata); |
108 DTLSIdentityRequestObserver* observer = message_data->data().observer.get(); | 129 DTLSIdentityRequestObserver* observer = message_data->data().observer.get(); |
109 switch (msg->message_id) { | 130 switch (msg->message_id) { |
110 case MSG_SUCCESS: { | 131 case MSG_SUCCESS: { |
111 std::string cert, key; | 132 std::string cert, key; |
112 GenerateIdentity(message_data->data().common_name, &cert, &key); | 133 GenerateIdentity(message_data->data().common_name, &cert, &key); |
113 observer->OnSuccess(cert, key); | 134 observer->OnSuccess(cert, key); |
114 break; | 135 break; |
115 } | 136 } |
116 case MSG_FAILURE: | 137 case MSG_FAILURE: |
117 observer->OnFailure(0); | 138 observer->OnFailure(0); |
118 break; | 139 break; |
119 } | 140 } |
120 delete message_data; | 141 delete message_data; |
121 } | 142 } |
122 | 143 |
123 void GenerateIdentity( | 144 static void GenerateIdentity( |
Henrik Grunell WebRTC
2015/08/05 07:41:20
Make this an ordinary function in the implementati
hbos
2015/08/06 12:11:34
We talked about this and decided it didn't matter
Henrik Grunell WebRTC
2015/08/06 14:06:52
Acknowledged.
| |
124 const std::string& common_name, | 145 const std::string& common_name, |
125 std::string* der_cert, | 146 std::string* der_cert, |
126 std::string* der_key) { | 147 std::string* der_key) { |
127 rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, der_cert); | 148 rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, der_cert); |
128 rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", | 149 rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", |
129 kRSA_PRIVATE_KEY_PEM, | 150 kRSA_PRIVATE_KEY_PEM, |
130 der_key); | 151 der_key); |
131 } | 152 } |
132 | 153 |
133 bool should_fail_; | 154 bool should_fail_; |
134 }; | 155 }; |
135 | 156 |
136 #endif // TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ | 157 #endif // TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ |
OLD | NEW |