henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2011, Google Inc. |
| 4 | * Portions Copyright 2011, RTFM, Inc. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are met: |
| 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright notice, |
| 10 | * this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer in the documentation |
| 13 | * and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | #include <algorithm> |
| 31 | #include <set> |
| 32 | #include <string> |
| 33 | |
| 34 | #include "talk/base/gunit.h" |
| 35 | #include "talk/base/helpers.h" |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame^] | 36 | #include "talk/base/scoped_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | #include "talk/base/ssladapter.h" |
| 38 | #include "talk/base/sslconfig.h" |
| 39 | #include "talk/base/sslidentity.h" |
| 40 | #include "talk/base/sslstreamadapter.h" |
| 41 | #include "talk/base/stream.h" |
| 42 | |
| 43 | static const int kBlockSize = 4096; |
| 44 | static const char kAES_CM_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; |
| 45 | static const char kAES_CM_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32"; |
| 46 | static const char kExporterLabel[] = "label"; |
| 47 | static const unsigned char kExporterContext[] = "context"; |
| 48 | static int kExporterContextLen = sizeof(kExporterContext); |
| 49 | |
| 50 | static const char kRSA_PRIVATE_KEY_PEM[] = |
| 51 | "-----BEGIN RSA PRIVATE KEY-----\n" |
| 52 | "MIICXQIBAAKBgQDCueE4a9hDMZ3sbVZdlXOz9ZA+cvzie3zJ9gXnT/BCt9P4b9HE\n" |
| 53 | "vD/tr73YBqD3Wr5ZWScmyGYF9EMn0r3rzBxv6oooLU5TdUvOm4rzUjkCLQaQML8o\n" |
| 54 | "NxXq+qW/j3zUKGikLhaaAl/amaX2zSWUsRQ1CpngQ3+tmDNH4/25TncNmQIDAQAB\n" |
| 55 | "AoGAUcuU0Id0k10fMjYHZk4mCPzot2LD2Tr4Aznl5vFMQipHzv7hhZtx2xzMSRcX\n" |
| 56 | "vG+Qr6VkbcUWHgApyWubvZXCh3+N7Vo2aYdMAQ8XqmFpBdIrL5CVdVfqFfEMlgEy\n" |
| 57 | "LSZNG5klnrIfl3c7zQVovLr4eMqyl2oGfAqPQz75+fecv1UCQQD6wNHch9NbAG1q\n" |
| 58 | "yuFEhMARB6gDXb+5SdzFjjtTWW5uJfm4DcZLoYyaIZm0uxOwsUKd0Rsma+oGitS1\n" |
| 59 | "CXmuqfpPAkEAxszyN3vIdpD44SREEtyKZBMNOk5pEIIGdbeMJC5/XHvpxww9xkoC\n" |
| 60 | "+39NbvUZYd54uT+rafbx4QZKc0h9xA/HlwJBAL37lYVWy4XpPv1olWCKi9LbUCqs\n" |
| 61 | "vvQtyD1N1BkEayy9TQRsO09WKOcmigRqsTJwOx7DLaTgokEuspYvhagWVPUCQE/y\n" |
| 62 | "0+YkTbYBD1Xbs9SyBKXCU6uDJRWSdO6aZi2W1XloC9gUwDMiSJjD1Wwt/YsyYPJ+\n" |
| 63 | "/Hyc5yFL2l0KZimW/vkCQQCjuZ/lPcH46EuzhdbRfumDOG5N3ld7UhGI1TIRy17W\n" |
| 64 | "dGF90cG33/L6BfS8Ll+fkkW/2AMRk8FDvF4CZi2nfW4L\n" |
| 65 | "-----END RSA PRIVATE KEY-----\n"; |
| 66 | |
| 67 | static const char kCERT_PEM[] = |
| 68 | "-----BEGIN CERTIFICATE-----\n" |
| 69 | "MIIBmTCCAQICCQCPNJORW/M13DANBgkqhkiG9w0BAQUFADARMQ8wDQYDVQQDDAZ3\n" |
| 70 | "ZWJydGMwHhcNMTMwNjE0MjIzMDAxWhcNMTQwNjE0MjIzMDAxWjARMQ8wDQYDVQQD\n" |
| 71 | "DAZ3ZWJydGMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMK54Thr2EMxnext\n" |
| 72 | "Vl2Vc7P1kD5y/OJ7fMn2BedP8EK30/hv0cS8P+2vvdgGoPdavllZJybIZgX0QyfS\n" |
| 73 | "vevMHG/qiigtTlN1S86bivNSOQItBpAwvyg3Fer6pb+PfNQoaKQuFpoCX9qZpfbN\n" |
| 74 | "JZSxFDUKmeBDf62YM0fj/blOdw2ZAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAECMt\n" |
| 75 | "UZb35H8TnjGx4XPzco/kbnurMLFFWcuve/DwTsuf10Ia9N4md8LY0UtgIgtyNqWc\n" |
| 76 | "ZwyRMwxONF6ty3wcaIiPbGqiAa55T3YRuPibkRmck9CjrmM9JAtyvqHnpHd2TsBD\n" |
| 77 | "qCV42aXS3onOXDQ1ibuWq0fr0//aj0wo4KV474c=\n" |
| 78 | "-----END CERTIFICATE-----\n"; |
| 79 | |
| 80 | #define MAYBE_SKIP_TEST(feature) \ |
| 81 | if (!(talk_base::SSLStreamAdapter::feature())) { \ |
| 82 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 83 | return; \ |
| 84 | } |
| 85 | |
| 86 | class SSLStreamAdapterTestBase; |
| 87 | |
| 88 | class SSLDummyStream : public talk_base::StreamInterface, |
| 89 | public sigslot::has_slots<> { |
| 90 | public: |
| 91 | explicit SSLDummyStream(SSLStreamAdapterTestBase *test, |
| 92 | const std::string &side, |
| 93 | talk_base::FifoBuffer *in, |
| 94 | talk_base::FifoBuffer *out) : |
| 95 | test_(test), |
| 96 | side_(side), |
| 97 | in_(in), |
| 98 | out_(out), |
| 99 | first_packet_(true) { |
| 100 | in_->SignalEvent.connect(this, &SSLDummyStream::OnEventIn); |
| 101 | out_->SignalEvent.connect(this, &SSLDummyStream::OnEventOut); |
| 102 | } |
| 103 | |
| 104 | virtual talk_base::StreamState GetState() const { return talk_base::SS_OPEN; } |
| 105 | |
| 106 | virtual talk_base::StreamResult Read(void* buffer, size_t buffer_len, |
| 107 | size_t* read, int* error) { |
| 108 | talk_base::StreamResult r; |
| 109 | |
| 110 | r = in_->Read(buffer, buffer_len, read, error); |
| 111 | if (r == talk_base::SR_BLOCK) |
| 112 | return talk_base::SR_BLOCK; |
| 113 | if (r == talk_base::SR_EOS) |
| 114 | return talk_base::SR_EOS; |
| 115 | |
| 116 | if (r != talk_base::SR_SUCCESS) { |
| 117 | ADD_FAILURE(); |
| 118 | return talk_base::SR_ERROR; |
| 119 | } |
| 120 | |
| 121 | return talk_base::SR_SUCCESS; |
| 122 | } |
| 123 | |
| 124 | // Catch readability events on in and pass them up. |
| 125 | virtual void OnEventIn(talk_base::StreamInterface *stream, int sig, |
| 126 | int err) { |
| 127 | int mask = (talk_base::SE_READ | talk_base::SE_CLOSE); |
| 128 | |
| 129 | if (sig & mask) { |
| 130 | LOG(LS_INFO) << "SSLDummyStream::OnEvent side=" << side_ << " sig=" |
| 131 | << sig << " forwarding upward"; |
| 132 | PostEvent(sig & mask, 0); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // Catch writeability events on out and pass them up. |
| 137 | virtual void OnEventOut(talk_base::StreamInterface *stream, int sig, |
| 138 | int err) { |
| 139 | if (sig & talk_base::SE_WRITE) { |
| 140 | LOG(LS_INFO) << "SSLDummyStream::OnEvent side=" << side_ << " sig=" |
| 141 | << sig << " forwarding upward"; |
| 142 | |
| 143 | PostEvent(sig & talk_base::SE_WRITE, 0); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Write to the outgoing FifoBuffer |
| 148 | talk_base::StreamResult WriteData(const void* data, size_t data_len, |
| 149 | size_t* written, int* error) { |
| 150 | return out_->Write(data, data_len, written, error); |
| 151 | } |
| 152 | |
| 153 | // Defined later |
| 154 | virtual talk_base::StreamResult Write(const void* data, size_t data_len, |
| 155 | size_t* written, int* error); |
| 156 | |
| 157 | virtual void Close() { |
| 158 | LOG(LS_INFO) << "Closing outbound stream"; |
| 159 | out_->Close(); |
| 160 | } |
| 161 | |
| 162 | private: |
| 163 | SSLStreamAdapterTestBase *test_; |
| 164 | const std::string side_; |
| 165 | talk_base::FifoBuffer *in_; |
| 166 | talk_base::FifoBuffer *out_; |
| 167 | bool first_packet_; |
| 168 | }; |
| 169 | |
| 170 | static const int kFifoBufferSize = 4096; |
| 171 | |
| 172 | class SSLStreamAdapterTestBase : public testing::Test, |
| 173 | public sigslot::has_slots<> { |
| 174 | public: |
| 175 | SSLStreamAdapterTestBase(const std::string& client_cert_pem, |
| 176 | const std::string& client_private_key_pem, |
| 177 | bool dtls) : |
| 178 | client_buffer_(kFifoBufferSize), server_buffer_(kFifoBufferSize), |
| 179 | client_stream_( |
| 180 | new SSLDummyStream(this, "c2s", &client_buffer_, &server_buffer_)), |
| 181 | server_stream_( |
| 182 | new SSLDummyStream(this, "s2c", &server_buffer_, &client_buffer_)), |
| 183 | client_ssl_(talk_base::SSLStreamAdapter::Create(client_stream_)), |
| 184 | server_ssl_(talk_base::SSLStreamAdapter::Create(server_stream_)), |
| 185 | client_identity_(NULL), server_identity_(NULL), |
| 186 | delay_(0), mtu_(1460), loss_(0), lose_first_packet_(false), |
| 187 | damage_(false), dtls_(dtls), |
| 188 | handshake_wait_(5000), identities_set_(false) { |
| 189 | // Set use of the test RNG to get predictable loss patterns. |
| 190 | talk_base::SetRandomTestMode(true); |
| 191 | |
| 192 | // Set up the slots |
| 193 | client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 194 | server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 195 | |
| 196 | if (!client_cert_pem.empty() && !client_private_key_pem.empty()) { |
| 197 | client_identity_ = talk_base::SSLIdentity::FromPEMStrings( |
| 198 | client_private_key_pem, client_cert_pem); |
| 199 | } else { |
| 200 | client_identity_ = talk_base::SSLIdentity::Generate("client"); |
| 201 | } |
| 202 | server_identity_ = talk_base::SSLIdentity::Generate("server"); |
| 203 | |
| 204 | client_ssl_->SetIdentity(client_identity_); |
| 205 | server_ssl_->SetIdentity(server_identity_); |
| 206 | } |
| 207 | |
| 208 | ~SSLStreamAdapterTestBase() { |
| 209 | // Put it back for the next test. |
| 210 | talk_base::SetRandomTestMode(false); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 211 | talk_base::CleanupSSL(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void SetUpTestCase() { |
| 215 | talk_base::InitializeSSL(); |
| 216 | } |
| 217 | |
| 218 | virtual void OnEvent(talk_base::StreamInterface *stream, int sig, int err) { |
| 219 | LOG(LS_INFO) << "SSLStreamAdapterTestBase::OnEvent sig=" << sig; |
| 220 | |
| 221 | if (sig & talk_base::SE_READ) { |
| 222 | ReadData(stream); |
| 223 | } |
| 224 | |
| 225 | if ((stream == client_ssl_.get()) && (sig & talk_base::SE_WRITE)) { |
| 226 | WriteData(); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | void SetPeerIdentitiesByCertificate(bool correct) { |
| 231 | LOG(LS_INFO) << "Setting peer identities by certificate"; |
| 232 | |
| 233 | if (correct) { |
| 234 | client_ssl_->SetPeerCertificate(server_identity_->certificate(). |
| 235 | GetReference()); |
| 236 | server_ssl_->SetPeerCertificate(client_identity_->certificate(). |
| 237 | GetReference()); |
| 238 | } else { |
| 239 | // If incorrect, set up to expect our own certificate at the peer |
| 240 | client_ssl_->SetPeerCertificate(client_identity_->certificate(). |
| 241 | GetReference()); |
| 242 | server_ssl_->SetPeerCertificate(server_identity_->certificate(). |
| 243 | GetReference()); |
| 244 | } |
| 245 | identities_set_ = true; |
| 246 | } |
| 247 | |
| 248 | void SetPeerIdentitiesByDigest(bool correct) { |
| 249 | unsigned char digest[20]; |
| 250 | size_t digest_len; |
| 251 | bool rv; |
| 252 | |
| 253 | LOG(LS_INFO) << "Setting peer identities by digest"; |
| 254 | |
| 255 | rv = server_identity_->certificate().ComputeDigest(talk_base::DIGEST_SHA_1, |
| 256 | digest, 20, |
| 257 | &digest_len); |
| 258 | ASSERT_TRUE(rv); |
| 259 | if (!correct) { |
| 260 | LOG(LS_INFO) << "Setting bogus digest for server cert"; |
| 261 | digest[0]++; |
| 262 | } |
| 263 | rv = client_ssl_->SetPeerCertificateDigest(talk_base::DIGEST_SHA_1, digest, |
| 264 | digest_len); |
| 265 | ASSERT_TRUE(rv); |
| 266 | |
| 267 | |
| 268 | rv = client_identity_->certificate().ComputeDigest(talk_base::DIGEST_SHA_1, |
| 269 | digest, 20, &digest_len); |
| 270 | ASSERT_TRUE(rv); |
| 271 | if (!correct) { |
| 272 | LOG(LS_INFO) << "Setting bogus digest for client cert"; |
| 273 | digest[0]++; |
| 274 | } |
| 275 | rv = server_ssl_->SetPeerCertificateDigest(talk_base::DIGEST_SHA_1, digest, |
| 276 | digest_len); |
| 277 | ASSERT_TRUE(rv); |
| 278 | |
| 279 | identities_set_ = true; |
| 280 | } |
| 281 | |
| 282 | void TestHandshake(bool expect_success = true) { |
| 283 | server_ssl_->SetMode(dtls_ ? talk_base::SSL_MODE_DTLS : |
| 284 | talk_base::SSL_MODE_TLS); |
| 285 | client_ssl_->SetMode(dtls_ ? talk_base::SSL_MODE_DTLS : |
| 286 | talk_base::SSL_MODE_TLS); |
| 287 | |
| 288 | if (!dtls_) { |
| 289 | // Make sure we simulate a reliable network for TLS. |
| 290 | // This is just a check to make sure that people don't write wrong |
| 291 | // tests. |
| 292 | ASSERT((mtu_ == 1460) && (loss_ == 0) && (lose_first_packet_ == 0)); |
| 293 | } |
| 294 | |
| 295 | if (!identities_set_) |
| 296 | SetPeerIdentitiesByDigest(true); |
| 297 | |
| 298 | // Start the handshake |
| 299 | int rv; |
| 300 | |
| 301 | server_ssl_->SetServerRole(); |
| 302 | rv = server_ssl_->StartSSLWithPeer(); |
| 303 | ASSERT_EQ(0, rv); |
| 304 | |
| 305 | rv = client_ssl_->StartSSLWithPeer(); |
| 306 | ASSERT_EQ(0, rv); |
| 307 | |
| 308 | // Now run the handshake |
| 309 | if (expect_success) { |
| 310 | EXPECT_TRUE_WAIT((client_ssl_->GetState() == talk_base::SS_OPEN) |
| 311 | && (server_ssl_->GetState() == talk_base::SS_OPEN), |
| 312 | handshake_wait_); |
| 313 | } else { |
| 314 | EXPECT_TRUE_WAIT(client_ssl_->GetState() == talk_base::SS_CLOSED, |
| 315 | handshake_wait_); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | talk_base::StreamResult DataWritten(SSLDummyStream *from, const void *data, |
| 320 | size_t data_len, size_t *written, |
| 321 | int *error) { |
| 322 | // Randomly drop loss_ percent of packets |
| 323 | if (talk_base::CreateRandomId() % 100 < static_cast<uint32>(loss_)) { |
| 324 | LOG(LS_INFO) << "Randomly dropping packet, size=" << data_len; |
| 325 | *written = data_len; |
| 326 | return talk_base::SR_SUCCESS; |
| 327 | } |
| 328 | if (dtls_ && (data_len > mtu_)) { |
| 329 | LOG(LS_INFO) << "Dropping packet > mtu, size=" << data_len; |
| 330 | *written = data_len; |
| 331 | return talk_base::SR_SUCCESS; |
| 332 | } |
| 333 | |
| 334 | // Optionally damage application data (type 23). Note that we don't damage |
| 335 | // handshake packets and we damage the last byte to keep the header |
| 336 | // intact but break the MAC. |
| 337 | if (damage_ && (*static_cast<const unsigned char *>(data) == 23)) { |
| 338 | std::vector<char> buf(data_len); |
| 339 | |
| 340 | LOG(LS_INFO) << "Damaging packet"; |
| 341 | |
| 342 | memcpy(&buf[0], data, data_len); |
| 343 | buf[data_len - 1]++; |
| 344 | |
| 345 | return from->WriteData(&buf[0], data_len, written, error); |
| 346 | } |
| 347 | |
| 348 | return from->WriteData(data, data_len, written, error); |
| 349 | } |
| 350 | |
| 351 | void SetDelay(int delay) { |
| 352 | delay_ = delay; |
| 353 | } |
| 354 | int GetDelay() { return delay_; } |
| 355 | |
| 356 | void SetLoseFirstPacket(bool lose) { |
| 357 | lose_first_packet_ = lose; |
| 358 | } |
| 359 | bool GetLoseFirstPacket() { return lose_first_packet_; } |
| 360 | |
| 361 | void SetLoss(int percent) { |
| 362 | loss_ = percent; |
| 363 | } |
| 364 | |
| 365 | void SetDamage() { |
| 366 | damage_ = true; |
| 367 | } |
| 368 | |
| 369 | void SetMtu(size_t mtu) { |
| 370 | mtu_ = mtu; |
| 371 | } |
| 372 | |
| 373 | void SetHandshakeWait(int wait) { |
| 374 | handshake_wait_ = wait; |
| 375 | } |
| 376 | |
| 377 | void SetDtlsSrtpCiphers(const std::vector<std::string> &ciphers, |
| 378 | bool client) { |
| 379 | if (client) |
| 380 | client_ssl_->SetDtlsSrtpCiphers(ciphers); |
| 381 | else |
| 382 | server_ssl_->SetDtlsSrtpCiphers(ciphers); |
| 383 | } |
| 384 | |
| 385 | bool GetDtlsSrtpCipher(bool client, std::string *retval) { |
| 386 | if (client) |
| 387 | return client_ssl_->GetDtlsSrtpCipher(retval); |
| 388 | else |
| 389 | return server_ssl_->GetDtlsSrtpCipher(retval); |
| 390 | } |
| 391 | |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame^] | 392 | bool GetPeerCertificate(bool client, talk_base::SSLCertificate** cert) { |
| 393 | if (client) |
| 394 | return client_ssl_->GetPeerCertificate(cert); |
| 395 | else |
| 396 | return server_ssl_->GetPeerCertificate(cert); |
| 397 | } |
| 398 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 399 | bool ExportKeyingMaterial(const char *label, |
| 400 | const unsigned char *context, |
| 401 | size_t context_len, |
| 402 | bool use_context, |
| 403 | bool client, |
| 404 | unsigned char *result, |
| 405 | size_t result_len) { |
| 406 | if (client) |
| 407 | return client_ssl_->ExportKeyingMaterial(label, |
| 408 | context, context_len, |
| 409 | use_context, |
| 410 | result, result_len); |
| 411 | else |
| 412 | return server_ssl_->ExportKeyingMaterial(label, |
| 413 | context, context_len, |
| 414 | use_context, |
| 415 | result, result_len); |
| 416 | } |
| 417 | |
| 418 | // To be implemented by subclasses. |
| 419 | virtual void WriteData() = 0; |
| 420 | virtual void ReadData(talk_base::StreamInterface *stream) = 0; |
| 421 | virtual void TestTransfer(int size) = 0; |
| 422 | |
| 423 | protected: |
| 424 | talk_base::FifoBuffer client_buffer_; |
| 425 | talk_base::FifoBuffer server_buffer_; |
| 426 | SSLDummyStream *client_stream_; // freed by client_ssl_ destructor |
| 427 | SSLDummyStream *server_stream_; // freed by server_ssl_ destructor |
| 428 | talk_base::scoped_ptr<talk_base::SSLStreamAdapter> client_ssl_; |
| 429 | talk_base::scoped_ptr<talk_base::SSLStreamAdapter> server_ssl_; |
| 430 | talk_base::SSLIdentity *client_identity_; // freed by client_ssl_ destructor |
| 431 | talk_base::SSLIdentity *server_identity_; // freed by server_ssl_ destructor |
| 432 | int delay_; |
| 433 | size_t mtu_; |
| 434 | int loss_; |
| 435 | bool lose_first_packet_; |
| 436 | bool damage_; |
| 437 | bool dtls_; |
| 438 | int handshake_wait_; |
| 439 | bool identities_set_; |
| 440 | }; |
| 441 | |
| 442 | class SSLStreamAdapterTestTLS : public SSLStreamAdapterTestBase { |
| 443 | public: |
| 444 | SSLStreamAdapterTestTLS() : |
| 445 | SSLStreamAdapterTestBase("", "", false) { |
| 446 | }; |
| 447 | |
| 448 | // Test data transfer for TLS |
| 449 | virtual void TestTransfer(int size) { |
| 450 | LOG(LS_INFO) << "Starting transfer test with " << size << " bytes"; |
| 451 | // Create some dummy data to send. |
| 452 | size_t received; |
| 453 | |
| 454 | send_stream_.ReserveSize(size); |
| 455 | for (int i = 0; i < size; ++i) { |
| 456 | char ch = static_cast<char>(i); |
| 457 | send_stream_.Write(&ch, 1, NULL, NULL); |
| 458 | } |
| 459 | send_stream_.Rewind(); |
| 460 | |
| 461 | // Prepare the receive stream. |
| 462 | recv_stream_.ReserveSize(size); |
| 463 | |
| 464 | // Start sending |
| 465 | WriteData(); |
| 466 | |
| 467 | // Wait for the client to close |
| 468 | EXPECT_TRUE_WAIT(server_ssl_->GetState() == talk_base::SS_CLOSED, 10000); |
| 469 | |
| 470 | // Now check the data |
| 471 | recv_stream_.GetSize(&received); |
| 472 | |
| 473 | EXPECT_EQ(static_cast<size_t>(size), received); |
| 474 | EXPECT_EQ(0, memcmp(send_stream_.GetBuffer(), |
| 475 | recv_stream_.GetBuffer(), size)); |
| 476 | } |
| 477 | |
| 478 | void WriteData() { |
| 479 | size_t position, tosend, size; |
| 480 | talk_base::StreamResult rv; |
| 481 | size_t sent; |
| 482 | char block[kBlockSize]; |
| 483 | |
| 484 | send_stream_.GetSize(&size); |
| 485 | if (!size) |
| 486 | return; |
| 487 | |
| 488 | for (;;) { |
| 489 | send_stream_.GetPosition(&position); |
| 490 | if (send_stream_.Read(block, sizeof(block), &tosend, NULL) != |
| 491 | talk_base::SR_EOS) { |
| 492 | rv = client_ssl_->Write(block, tosend, &sent, 0); |
| 493 | |
| 494 | if (rv == talk_base::SR_SUCCESS) { |
| 495 | send_stream_.SetPosition(position + sent); |
| 496 | LOG(LS_VERBOSE) << "Sent: " << position + sent; |
| 497 | } else if (rv == talk_base::SR_BLOCK) { |
| 498 | LOG(LS_VERBOSE) << "Blocked..."; |
| 499 | send_stream_.SetPosition(position); |
| 500 | break; |
| 501 | } else { |
| 502 | ADD_FAILURE(); |
| 503 | break; |
| 504 | } |
| 505 | } else { |
| 506 | // Now close |
| 507 | LOG(LS_INFO) << "Wrote " << position << " bytes. Closing"; |
| 508 | client_ssl_->Close(); |
| 509 | break; |
| 510 | } |
| 511 | } |
| 512 | }; |
| 513 | |
| 514 | virtual void ReadData(talk_base::StreamInterface *stream) { |
| 515 | char buffer[1600]; |
| 516 | size_t bread; |
| 517 | int err2; |
| 518 | talk_base::StreamResult r; |
| 519 | |
| 520 | for (;;) { |
| 521 | r = stream->Read(buffer, sizeof(buffer), &bread, &err2); |
| 522 | |
| 523 | if (r == talk_base::SR_ERROR || r == talk_base::SR_EOS) { |
| 524 | // Unfortunately, errors are the way that the stream adapter |
| 525 | // signals close in OpenSSL |
| 526 | stream->Close(); |
| 527 | return; |
| 528 | } |
| 529 | |
| 530 | if (r == talk_base::SR_BLOCK) |
| 531 | break; |
| 532 | |
| 533 | ASSERT_EQ(talk_base::SR_SUCCESS, r); |
| 534 | LOG(LS_INFO) << "Read " << bread; |
| 535 | |
| 536 | recv_stream_.Write(buffer, bread, NULL, NULL); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | private: |
| 541 | talk_base::MemoryStream send_stream_; |
| 542 | talk_base::MemoryStream recv_stream_; |
| 543 | }; |
| 544 | |
| 545 | class SSLStreamAdapterTestDTLS : public SSLStreamAdapterTestBase { |
| 546 | public: |
| 547 | SSLStreamAdapterTestDTLS() : |
| 548 | SSLStreamAdapterTestBase("", "", true), |
| 549 | packet_size_(1000), count_(0), sent_(0) { |
| 550 | } |
| 551 | |
| 552 | SSLStreamAdapterTestDTLS(const std::string& cert_pem, |
| 553 | const std::string& private_key_pem) : |
| 554 | SSLStreamAdapterTestBase(cert_pem, private_key_pem, true), |
| 555 | packet_size_(1000), count_(0), sent_(0) { |
| 556 | } |
| 557 | |
| 558 | virtual void WriteData() { |
| 559 | unsigned char *packet = new unsigned char[1600]; |
| 560 | |
| 561 | do { |
| 562 | memset(packet, sent_ & 0xff, packet_size_); |
| 563 | *(reinterpret_cast<uint32_t *>(packet)) = sent_; |
| 564 | |
| 565 | size_t sent; |
| 566 | int rv = client_ssl_->Write(packet, packet_size_, &sent, 0); |
| 567 | if (rv == talk_base::SR_SUCCESS) { |
| 568 | LOG(LS_VERBOSE) << "Sent: " << sent_; |
| 569 | sent_++; |
| 570 | } else if (rv == talk_base::SR_BLOCK) { |
| 571 | LOG(LS_VERBOSE) << "Blocked..."; |
| 572 | break; |
| 573 | } else { |
| 574 | ADD_FAILURE(); |
| 575 | break; |
| 576 | } |
| 577 | } while (sent_ < count_); |
| 578 | |
| 579 | delete [] packet; |
| 580 | } |
| 581 | |
| 582 | virtual void ReadData(talk_base::StreamInterface *stream) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 583 | unsigned char buffer[2000]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 584 | size_t bread; |
| 585 | int err2; |
| 586 | talk_base::StreamResult r; |
| 587 | |
| 588 | for (;;) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 589 | r = stream->Read(buffer, 2000, &bread, &err2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 590 | |
| 591 | if (r == talk_base::SR_ERROR) { |
| 592 | // Unfortunately, errors are the way that the stream adapter |
| 593 | // signals close right now |
| 594 | stream->Close(); |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | if (r == talk_base::SR_BLOCK) |
| 599 | break; |
| 600 | |
| 601 | ASSERT_EQ(talk_base::SR_SUCCESS, r); |
| 602 | LOG(LS_INFO) << "Read " << bread; |
| 603 | |
| 604 | // Now parse the datagram |
| 605 | ASSERT_EQ(packet_size_, bread); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 606 | unsigned char* ptr_to_buffer = buffer; |
| 607 | uint32_t packet_num = *(reinterpret_cast<uint32_t *>(ptr_to_buffer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 608 | |
| 609 | for (size_t i = 4; i < packet_size_; i++) { |
| 610 | ASSERT_EQ((packet_num & 0xff), buffer[i]); |
| 611 | } |
| 612 | received_.insert(packet_num); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | virtual void TestTransfer(int count) { |
| 617 | count_ = count; |
| 618 | |
| 619 | WriteData(); |
| 620 | |
| 621 | EXPECT_TRUE_WAIT(sent_ == count_, 10000); |
| 622 | LOG(LS_INFO) << "sent_ == " << sent_; |
| 623 | |
| 624 | if (damage_) { |
| 625 | WAIT(false, 2000); |
| 626 | EXPECT_EQ(0U, received_.size()); |
| 627 | } else if (loss_ == 0) { |
| 628 | EXPECT_EQ_WAIT(static_cast<size_t>(sent_), received_.size(), 1000); |
| 629 | } else { |
| 630 | LOG(LS_INFO) << "Sent " << sent_ << " packets; received " << |
| 631 | received_.size(); |
| 632 | } |
| 633 | }; |
| 634 | |
| 635 | private: |
| 636 | size_t packet_size_; |
| 637 | int count_; |
| 638 | int sent_; |
| 639 | std::set<int> received_; |
| 640 | }; |
| 641 | |
| 642 | |
| 643 | talk_base::StreamResult SSLDummyStream::Write(const void* data, size_t data_len, |
| 644 | size_t* written, int* error) { |
| 645 | *written = data_len; |
| 646 | |
| 647 | LOG(LS_INFO) << "Writing to loopback " << data_len; |
| 648 | |
| 649 | if (first_packet_) { |
| 650 | first_packet_ = false; |
| 651 | if (test_->GetLoseFirstPacket()) { |
| 652 | LOG(LS_INFO) << "Losing initial packet of length " << data_len; |
| 653 | return talk_base::SR_SUCCESS; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | return test_->DataWritten(this, data, data_len, written, error); |
| 658 | |
| 659 | return talk_base::SR_SUCCESS; |
| 660 | }; |
| 661 | |
| 662 | class SSLStreamAdapterTestDTLSFromPEMStrings : public SSLStreamAdapterTestDTLS { |
| 663 | public: |
| 664 | SSLStreamAdapterTestDTLSFromPEMStrings() : |
| 665 | SSLStreamAdapterTestDTLS(kCERT_PEM, kRSA_PRIVATE_KEY_PEM) { |
| 666 | } |
| 667 | }; |
| 668 | |
| 669 | // Basic tests: TLS |
| 670 | |
| 671 | // Test that we cannot read/write if we have not yet handshaked. |
| 672 | // This test only applies to NSS because OpenSSL has passthrough |
| 673 | // semantics for I/O before the handshake is started. |
| 674 | #if SSL_USE_NSS |
| 675 | TEST_F(SSLStreamAdapterTestTLS, TestNoReadWriteBeforeConnect) { |
| 676 | talk_base::StreamResult rv; |
| 677 | char block[kBlockSize]; |
| 678 | size_t dummy; |
| 679 | |
| 680 | rv = client_ssl_->Write(block, sizeof(block), &dummy, NULL); |
| 681 | ASSERT_EQ(talk_base::SR_BLOCK, rv); |
| 682 | |
| 683 | rv = client_ssl_->Read(block, sizeof(block), &dummy, NULL); |
| 684 | ASSERT_EQ(talk_base::SR_BLOCK, rv); |
| 685 | } |
| 686 | #endif |
| 687 | |
| 688 | |
| 689 | // Test that we can make a handshake work |
| 690 | TEST_F(SSLStreamAdapterTestTLS, TestTLSConnect) { |
| 691 | TestHandshake(); |
| 692 | }; |
| 693 | |
| 694 | // Test transfer -- trivial |
| 695 | TEST_F(SSLStreamAdapterTestTLS, TestTLSTransfer) { |
| 696 | TestHandshake(); |
| 697 | TestTransfer(100000); |
| 698 | }; |
| 699 | |
| 700 | // Test read-write after close. |
| 701 | TEST_F(SSLStreamAdapterTestTLS, ReadWriteAfterClose) { |
| 702 | TestHandshake(); |
| 703 | TestTransfer(100000); |
| 704 | client_ssl_->Close(); |
| 705 | |
| 706 | talk_base::StreamResult rv; |
| 707 | char block[kBlockSize]; |
| 708 | size_t dummy; |
| 709 | |
| 710 | // It's an error to write after closed. |
| 711 | rv = client_ssl_->Write(block, sizeof(block), &dummy, NULL); |
| 712 | ASSERT_EQ(talk_base::SR_ERROR, rv); |
| 713 | |
| 714 | // But after closed read gives you EOS. |
| 715 | rv = client_ssl_->Read(block, sizeof(block), &dummy, NULL); |
| 716 | ASSERT_EQ(talk_base::SR_EOS, rv); |
| 717 | }; |
| 718 | |
| 719 | // Test a handshake with a bogus peer digest |
| 720 | TEST_F(SSLStreamAdapterTestTLS, TestTLSBogusDigest) { |
| 721 | SetPeerIdentitiesByDigest(false); |
| 722 | TestHandshake(false); |
| 723 | }; |
| 724 | |
| 725 | // Test a handshake with a peer certificate |
| 726 | TEST_F(SSLStreamAdapterTestTLS, TestTLSPeerCertificate) { |
| 727 | SetPeerIdentitiesByCertificate(true); |
| 728 | TestHandshake(); |
| 729 | }; |
| 730 | |
| 731 | // Test a handshake with a bogus peer certificate |
| 732 | TEST_F(SSLStreamAdapterTestTLS, TestTLSBogusPeerCertificate) { |
| 733 | SetPeerIdentitiesByCertificate(false); |
| 734 | TestHandshake(false); |
| 735 | }; |
| 736 | // Test moving a bunch of data |
| 737 | |
| 738 | // Basic tests: DTLS |
| 739 | // Test that we can make a handshake work |
| 740 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSConnect) { |
| 741 | MAYBE_SKIP_TEST(HaveDtls); |
| 742 | TestHandshake(); |
| 743 | }; |
| 744 | |
| 745 | // Test that we can make a handshake work if the first packet in |
| 746 | // each direction is lost. This gives us predictable loss |
| 747 | // rather than having to tune random |
| 748 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSConnectWithLostFirstPacket) { |
| 749 | MAYBE_SKIP_TEST(HaveDtls); |
| 750 | SetLoseFirstPacket(true); |
| 751 | TestHandshake(); |
| 752 | }; |
| 753 | |
| 754 | // Test a handshake with loss and delay |
| 755 | TEST_F(SSLStreamAdapterTestDTLS, |
| 756 | TestDTLSConnectWithLostFirstPacketDelay2s) { |
| 757 | MAYBE_SKIP_TEST(HaveDtls); |
| 758 | SetLoseFirstPacket(true); |
| 759 | SetDelay(2000); |
| 760 | SetHandshakeWait(20000); |
| 761 | TestHandshake(); |
| 762 | }; |
| 763 | |
| 764 | // Test a handshake with small MTU |
| 765 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSConnectWithSmallMtu) { |
| 766 | MAYBE_SKIP_TEST(HaveDtls); |
| 767 | SetMtu(700); |
| 768 | SetHandshakeWait(20000); |
| 769 | TestHandshake(); |
| 770 | }; |
| 771 | |
| 772 | // Test transfer -- trivial |
| 773 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSTransfer) { |
| 774 | MAYBE_SKIP_TEST(HaveDtls); |
| 775 | TestHandshake(); |
| 776 | TestTransfer(100); |
| 777 | }; |
| 778 | |
| 779 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSTransferWithLoss) { |
| 780 | MAYBE_SKIP_TEST(HaveDtls); |
| 781 | TestHandshake(); |
| 782 | SetLoss(10); |
| 783 | TestTransfer(100); |
| 784 | }; |
| 785 | |
| 786 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSTransferWithDamage) { |
| 787 | MAYBE_SKIP_TEST(HaveDtls); |
| 788 | SetDamage(); // Must be called first because first packet |
| 789 | // write happens at end of handshake. |
| 790 | TestHandshake(); |
| 791 | TestTransfer(100); |
| 792 | }; |
| 793 | |
| 794 | // Test DTLS-SRTP with all high ciphers |
| 795 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSSrtpHigh) { |
| 796 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 797 | std::vector<std::string> high; |
| 798 | high.push_back(kAES_CM_HMAC_SHA1_80); |
| 799 | SetDtlsSrtpCiphers(high, true); |
| 800 | SetDtlsSrtpCiphers(high, false); |
| 801 | TestHandshake(); |
| 802 | |
| 803 | std::string client_cipher; |
| 804 | ASSERT_TRUE(GetDtlsSrtpCipher(true, &client_cipher)); |
| 805 | std::string server_cipher; |
| 806 | ASSERT_TRUE(GetDtlsSrtpCipher(false, &server_cipher)); |
| 807 | |
| 808 | ASSERT_EQ(client_cipher, server_cipher); |
| 809 | ASSERT_EQ(client_cipher, kAES_CM_HMAC_SHA1_80); |
| 810 | }; |
| 811 | |
| 812 | // Test DTLS-SRTP with all low ciphers |
| 813 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSSrtpLow) { |
| 814 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 815 | std::vector<std::string> low; |
| 816 | low.push_back(kAES_CM_HMAC_SHA1_32); |
| 817 | SetDtlsSrtpCiphers(low, true); |
| 818 | SetDtlsSrtpCiphers(low, false); |
| 819 | TestHandshake(); |
| 820 | |
| 821 | std::string client_cipher; |
| 822 | ASSERT_TRUE(GetDtlsSrtpCipher(true, &client_cipher)); |
| 823 | std::string server_cipher; |
| 824 | ASSERT_TRUE(GetDtlsSrtpCipher(false, &server_cipher)); |
| 825 | |
| 826 | ASSERT_EQ(client_cipher, server_cipher); |
| 827 | ASSERT_EQ(client_cipher, kAES_CM_HMAC_SHA1_32); |
| 828 | }; |
| 829 | |
| 830 | |
| 831 | // Test DTLS-SRTP with a mismatch -- should not converge |
| 832 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSSrtpHighLow) { |
| 833 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 834 | std::vector<std::string> high; |
| 835 | high.push_back(kAES_CM_HMAC_SHA1_80); |
| 836 | std::vector<std::string> low; |
| 837 | low.push_back(kAES_CM_HMAC_SHA1_32); |
| 838 | SetDtlsSrtpCiphers(high, true); |
| 839 | SetDtlsSrtpCiphers(low, false); |
| 840 | TestHandshake(); |
| 841 | |
| 842 | std::string client_cipher; |
| 843 | ASSERT_FALSE(GetDtlsSrtpCipher(true, &client_cipher)); |
| 844 | std::string server_cipher; |
| 845 | ASSERT_FALSE(GetDtlsSrtpCipher(false, &server_cipher)); |
| 846 | }; |
| 847 | |
| 848 | // Test DTLS-SRTP with each side being mixed -- should select high |
| 849 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSSrtpMixed) { |
| 850 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 851 | std::vector<std::string> mixed; |
| 852 | mixed.push_back(kAES_CM_HMAC_SHA1_80); |
| 853 | mixed.push_back(kAES_CM_HMAC_SHA1_32); |
| 854 | SetDtlsSrtpCiphers(mixed, true); |
| 855 | SetDtlsSrtpCiphers(mixed, false); |
| 856 | TestHandshake(); |
| 857 | |
| 858 | std::string client_cipher; |
| 859 | ASSERT_TRUE(GetDtlsSrtpCipher(true, &client_cipher)); |
| 860 | std::string server_cipher; |
| 861 | ASSERT_TRUE(GetDtlsSrtpCipher(false, &server_cipher)); |
| 862 | |
| 863 | ASSERT_EQ(client_cipher, server_cipher); |
| 864 | ASSERT_EQ(client_cipher, kAES_CM_HMAC_SHA1_80); |
| 865 | }; |
| 866 | |
| 867 | // Test an exporter |
| 868 | TEST_F(SSLStreamAdapterTestDTLS, TestDTLSExporter) { |
| 869 | MAYBE_SKIP_TEST(HaveExporter); |
| 870 | TestHandshake(); |
| 871 | unsigned char client_out[20]; |
| 872 | unsigned char server_out[20]; |
| 873 | |
| 874 | bool result; |
| 875 | result = ExportKeyingMaterial(kExporterLabel, |
| 876 | kExporterContext, kExporterContextLen, |
| 877 | true, true, |
| 878 | client_out, sizeof(client_out)); |
| 879 | ASSERT_TRUE(result); |
| 880 | |
| 881 | result = ExportKeyingMaterial(kExporterLabel, |
| 882 | kExporterContext, kExporterContextLen, |
| 883 | true, false, |
| 884 | server_out, sizeof(server_out)); |
| 885 | ASSERT_TRUE(result); |
| 886 | |
| 887 | ASSERT_TRUE(!memcmp(client_out, server_out, sizeof(client_out))); |
| 888 | } |
| 889 | |
| 890 | // Test data transfer using certs created from strings. |
| 891 | TEST_F(SSLStreamAdapterTestDTLSFromPEMStrings, TestTransfer) { |
| 892 | MAYBE_SKIP_TEST(HaveDtls); |
| 893 | TestHandshake(); |
| 894 | TestTransfer(100); |
| 895 | } |
wu@webrtc.org | 4551b79 | 2013-10-09 15:37:36 +0000 | [diff] [blame^] | 896 | |
| 897 | // Test getting the remote certificate. |
| 898 | TEST_F(SSLStreamAdapterTestDTLSFromPEMStrings, TestDTLSGetPeerCertificate) { |
| 899 | MAYBE_SKIP_TEST(HaveDtls); |
| 900 | |
| 901 | // Peer certificates haven't been received yet. |
| 902 | talk_base::scoped_ptr<talk_base::SSLCertificate> client_peer_cert; |
| 903 | ASSERT_FALSE(GetPeerCertificate(true, client_peer_cert.accept())); |
| 904 | ASSERT_FALSE(client_peer_cert != NULL); |
| 905 | |
| 906 | talk_base::scoped_ptr<talk_base::SSLCertificate> server_peer_cert; |
| 907 | ASSERT_FALSE(GetPeerCertificate(false, server_peer_cert.accept())); |
| 908 | ASSERT_FALSE(server_peer_cert != NULL); |
| 909 | |
| 910 | TestHandshake(); |
| 911 | |
| 912 | // The client should have a peer certificate after the handshake. |
| 913 | ASSERT_TRUE(GetPeerCertificate(true, client_peer_cert.accept())); |
| 914 | ASSERT_TRUE(client_peer_cert != NULL); |
| 915 | |
| 916 | // It's not kCERT_PEM. |
| 917 | std::string client_peer_string = client_peer_cert->ToPEMString(); |
| 918 | ASSERT_NE(kCERT_PEM, client_peer_string); |
| 919 | |
| 920 | // It must not have a chain, because the test certs are self-signed. |
| 921 | talk_base::SSLCertChain* client_peer_chain; |
| 922 | ASSERT_FALSE(client_peer_cert->GetChain(&client_peer_chain)); |
| 923 | |
| 924 | // The server should have a peer certificate after the handshake. |
| 925 | ASSERT_TRUE(GetPeerCertificate(false, server_peer_cert.accept())); |
| 926 | ASSERT_TRUE(server_peer_cert != NULL); |
| 927 | |
| 928 | // It's kCERT_PEM |
| 929 | ASSERT_EQ(kCERT_PEM, server_peer_cert->ToPEMString()); |
| 930 | |
| 931 | // It must not have a chain, because the test certs are self-signed. |
| 932 | talk_base::SSLCertChain* server_peer_chain; |
| 933 | ASSERT_FALSE(server_peer_cert->GetChain(&server_peer_chain)); |
| 934 | } |