Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: talk/app/webrtc/test/fakedtlsidentitystore.h

Issue 1269843005: Added DtlsCertificate, a ref counted object owning an SSLIdentity (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Merge with master Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
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 <string> 31 #include <string>
32 32
33 #include "talk/app/webrtc/dtlscertificate.h"
33 #include "talk/app/webrtc/dtlsidentitystore.h" 34 #include "talk/app/webrtc/dtlsidentitystore.h"
34 #include "talk/app/webrtc/peerconnectioninterface.h" 35 #include "talk/app/webrtc/peerconnectioninterface.h"
35 36
36 static const char kRSA_PRIVATE_KEY_PEM[] = 37 static const char kRSA_PRIVATE_KEY_PEM[] =
37 "-----BEGIN RSA PRIVATE KEY-----\n" 38 "-----BEGIN RSA PRIVATE KEY-----\n"
38 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" 39 "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n"
39 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" 40 "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n"
40 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" 41 "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n"
41 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" 42 "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n"
42 "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n" 43 "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& 82 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>&
82 observer) override { 83 observer) override {
83 // TODO(hbos): Should be able to generate KT_ECDSA too. 84 // TODO(hbos): Should be able to generate KT_ECDSA too.
84 DCHECK(key_type == rtc::KT_RSA || should_fail_); 85 DCHECK(key_type == rtc::KT_RSA || should_fail_);
85 MessageData* msg = new MessageData( 86 MessageData* msg = new MessageData(
86 rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>(observer)); 87 rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>(observer));
87 rtc::Thread::Current()->Post( 88 rtc::Thread::Current()->Post(
88 this, should_fail_ ? MSG_FAILURE : MSG_SUCCESS, msg); 89 this, should_fail_ ? MSG_FAILURE : MSG_SUCCESS, msg);
89 } 90 }
90 91
92 static rtc::scoped_refptr<webrtc::DtlsCertificate> GenerateCertificate() {
93 std::string cert;
94 std::string key;
95 GenerateIdentity(&cert, &key);
96
97 std::string pem_cert = rtc::SSLIdentity::DerToPem(
98 rtc::kPemTypeCertificate,
99 reinterpret_cast<const unsigned char*>(cert.data()),
100 cert.length());
101 std::string pem_key = rtc::SSLIdentity::DerToPem(
102 rtc::kPemTypeRsaPrivateKey,
103 reinterpret_cast<const unsigned char*>(key.data()),
104 key.length());
105 rtc::scoped_ptr<rtc::SSLIdentity> identity(
106 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert));
107
108 return webrtc::DtlsCertificate::Create(identity.Pass());
109 }
110
91 private: 111 private:
92 enum { 112 enum {
93 MSG_SUCCESS, 113 MSG_SUCCESS,
94 MSG_FAILURE, 114 MSG_FAILURE,
95 }; 115 };
96 116
97 // rtc::MessageHandler implementation. 117 // rtc::MessageHandler implementation.
98 void OnMessage(rtc::Message* msg) { 118 void OnMessage(rtc::Message* msg) {
99 MessageData* message_data = static_cast<MessageData*>(msg->pdata); 119 MessageData* message_data = static_cast<MessageData*>(msg->pdata);
100 rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver> observer = 120 rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver> observer =
101 message_data->data(); 121 message_data->data();
102 switch (msg->message_id) { 122 switch (msg->message_id) {
103 case MSG_SUCCESS: { 123 case MSG_SUCCESS: {
104 std::string cert; 124 std::string cert;
105 std::string key; 125 std::string key;
106 rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, &cert); 126 rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, &cert);
107 rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", kRSA_PRIVATE_KEY_PEM, 127 rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", kRSA_PRIVATE_KEY_PEM,
108 &key); 128 &key);
109 observer->OnSuccess(cert, key); 129 observer->OnSuccess(cert, key);
110 break; 130 break;
111 } 131 }
112 case MSG_FAILURE: 132 case MSG_FAILURE:
113 observer->OnFailure(0); 133 observer->OnFailure(0);
114 break; 134 break;
115 } 135 }
116 delete message_data; 136 delete message_data;
117 } 137 }
118 138
139 static void GenerateIdentity(
140 std::string* der_cert,
141 std::string* der_key) {
142 rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, der_cert);
143 rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY",
144 kRSA_PRIVATE_KEY_PEM,
145 der_key);
146 }
147
119 bool should_fail_; 148 bool should_fail_;
120 }; 149 };
121 150
122 #endif // TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ 151 #endif // TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698