Index: talk/app/webrtc/test/fakedtlsidentitystore.h |
diff --git a/talk/app/webrtc/test/fakedtlsidentitystore.h b/talk/app/webrtc/test/fakedtlsidentitystore.h |
index 0f9bdb9e6c974fb3b133e9bebf91da3ce0d7e6ba..5e596ca91e26b360c059f6ef1adc5df8b49b0d52 100644 |
--- a/talk/app/webrtc/test/fakedtlsidentitystore.h |
+++ b/talk/app/webrtc/test/fakedtlsidentitystore.h |
@@ -34,36 +34,67 @@ |
#include "talk/app/webrtc/peerconnectioninterface.h" |
#include "webrtc/base/rtccertificate.h" |
-static const char kRSA_PRIVATE_KEY_PEM[] = |
- "-----BEGIN RSA PRIVATE KEY-----\n" |
- "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" |
- "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" |
- "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" |
- "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" |
- "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n" |
- "2TwXH9QANf4at4d9n/R6rzwpAJOpgwZgKvdQjkfrKTtgLV+/dawvpxUYkRH4JZM1\n" |
- "CVGukMfKNrSVH4Ap4QJBAOJmGV1ASPnB4r4nc99at7JuIJmd7fmuVUwUgYi4XgaR\n" |
- "WhScBsgYwZ/JoywdyZJgnbcrTDuVcWG56B3vXbhdpMsCQQDf9zeJrjnPZ3Cqm79y\n" |
- "kdqANep0uwZciiNiWxsQrCHztywOvbFhdp8iYVFG9EK8DMY41Y5TxUwsHD+67zao\n" |
- "ZNqJAkEA1suLUP/GvL8IwuRneQd2tWDqqRQ/Td3qq03hP7e77XtF/buya3Ghclo5\n" |
- "54czUR89QyVfJEC6278nzA7n2h1uVQJAcG6mztNL6ja/dKZjYZye2CY44QjSlLo0\n" |
- "MTgTSjdfg/28fFn2Jjtqf9Pi/X+50LWI/RcYMC2no606wRk9kyOuIQJBAK6VSAim\n" |
- "1pOEjsYQn0X5KEIrz1G3bfCbB848Ime3U2/FWlCHMr6ch8kCZ5d1WUeJD3LbwMNG\n" |
- "UCXiYxSsu20QNVw=\n" |
- "-----END RSA PRIVATE KEY-----\n"; |
- |
-static const char kCERT_PEM[] = |
- "-----BEGIN CERTIFICATE-----\n" |
- "MIIBmTCCAQKgAwIBAgIEbzBSAjANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDEwZX\n" |
- "ZWJSVEMwHhcNMTQwMTAyMTgyNDQ3WhcNMTQwMjAxMTgyNDQ3WjARMQ8wDQYDVQQD\n" |
- "EwZXZWJSVEMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYRkbhmI7kVA/rM\n" |
- "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" |
- "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" |
- "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAEwDQYJKoZIhvcNAQELBQADgYEAUflI\n" |
- "VUe5Krqf5RVa5C3u/UTAOAUJBiDS3VANTCLBxjuMsvqOG0WvaYWP3HYPgrz0jXK2\n" |
- "LJE/mGw3MyFHEqi81jh95J+ypl6xKW6Rm8jKLR87gUvCaVYn/Z4/P3AqcQTB7wOv\n" |
- "UD0A8qfhfDM+LK6rPAnCsVN0NRDY3jvd6rzix9M=\n" |
- "-----END CERTIFICATE-----\n"; |
+static const struct { |
+ const char* rsa_private_key_pem; |
+ const char* cert_pem; |
+} kKeysAndCerts[] = { |
+ {"-----BEGIN RSA PRIVATE KEY-----\n" |
+ "MIICdwIBADANBgkqhkiG9w0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TjAdBgNV\n" |
+ "HQ4EFgQUx2tbJdlcSTCepn09UdYORXKuSTAwHwYDVR0jBBgwFoAUx2tbJdlcSTCe\n" |
+ "pn09UdYORXKuSTAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQAmp9Id\n" |
+ "E716gHMqeBG4S2FCgVFCr0a0ugkaneQAN/c2L9CbMemEN9W6jvucUIVOtYd90dDW\n" |
+ "lXuowWmT/JctPe3D2qt4yvYW3puECHk2tVQmrJOZiZiTRtWm6HxkmoUYHYp/DtaS\n" |
+ "1Xe29gSTnZtI5sQCrGMzk3SGRSSs7ejLKiVDBQ==\n" |
+ "-----END CERTIFICATE-----\n"}}; |
class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface, |
public rtc::MessageHandler { |
@@ -77,6 +108,9 @@ class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface, |
should_fail_ = should_fail; |
} |
+ void use_original_key() { key_index_ = 0; } |
+ void use_alternate_key() { key_index_ = 1; } |
+ |
void RequestIdentity( |
rtc::KeyType key_type, |
const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& |
@@ -92,8 +126,9 @@ class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface, |
static rtc::scoped_refptr<rtc::RTCCertificate> GenerateCertificate() { |
std::string cert; |
std::string key; |
- rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, &cert); |
- rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", kRSA_PRIVATE_KEY_PEM, &key); |
+ rtc::SSLIdentity::PemToDer("CERTIFICATE", kKeysAndCerts[0].cert_pem, &cert); |
+ rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", |
+ kKeysAndCerts[0].rsa_private_key_pem, &key); |
std::string pem_cert = rtc::SSLIdentity::DerToPem( |
rtc::kPemTypeCertificate, |
@@ -115,6 +150,11 @@ class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface, |
MSG_FAILURE, |
}; |
+ const char* get_key() { |
+ return kKeysAndCerts[key_index_].rsa_private_key_pem; |
+ } |
+ const char* get_cert() { return kKeysAndCerts[key_index_].cert_pem; } |
+ |
// rtc::MessageHandler implementation. |
void OnMessage(rtc::Message* msg) { |
MessageData* message_data = static_cast<MessageData*>(msg->pdata); |
@@ -124,9 +164,8 @@ class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface, |
case MSG_SUCCESS: { |
std::string cert; |
std::string key; |
- rtc::SSLIdentity::PemToDer("CERTIFICATE", kCERT_PEM, &cert); |
- rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", kRSA_PRIVATE_KEY_PEM, |
- &key); |
+ rtc::SSLIdentity::PemToDer("CERTIFICATE", get_cert(), &cert); |
+ rtc::SSLIdentity::PemToDer("RSA PRIVATE KEY", get_key(), &key); |
observer->OnSuccess(cert, key); |
break; |
} |
@@ -138,6 +177,7 @@ class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface, |
} |
bool should_fail_; |
+ int key_index_ = 0; |
}; |
#endif // TALK_APP_WEBRTC_TEST_FAKEDTLSIDENTITYSERVICE_H_ |