henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | #include <algorithm> |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 13 | #include <memory> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 14 | #include <set> |
| 15 | #include <string> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/bufferqueue.h" |
| 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/gunit.h" |
| 20 | #include "rtc_base/helpers.h" |
| 21 | #include "rtc_base/ssladapter.h" |
| 22 | #include "rtc_base/sslidentity.h" |
| 23 | #include "rtc_base/sslstreamadapter.h" |
| 24 | #include "rtc_base/stream.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 25 | |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 26 | using ::testing::WithParamInterface; |
| 27 | using ::testing::Values; |
| 28 | using ::testing::Combine; |
| 29 | using ::testing::tuple; |
| 30 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 31 | static const int kBlockSize = 4096; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 32 | static const char kExporterLabel[] = "label"; |
| 33 | static const unsigned char kExporterContext[] = "context"; |
| 34 | static int kExporterContextLen = sizeof(kExporterContext); |
| 35 | |
| 36 | static const char kRSA_PRIVATE_KEY_PEM[] = |
| 37 | "-----BEGIN RSA PRIVATE KEY-----\n" |
| 38 | "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMYRkbhmI7kVA/rM\n" |
| 39 | "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" |
| 40 | "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" |
| 41 | "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAECgYAvgOs4FJcgvp+TuREx7YtiYVsH\n" |
| 42 | "mwQPTum2z/8VzWGwR8BBHBvIpVe1MbD/Y4seyI2aco/7UaisatSgJhsU46/9Y4fq\n" |
| 43 | "2TwXH9QANf4at4d9n/R6rzwpAJOpgwZgKvdQjkfrKTtgLV+/dawvpxUYkRH4JZM1\n" |
| 44 | "CVGukMfKNrSVH4Ap4QJBAOJmGV1ASPnB4r4nc99at7JuIJmd7fmuVUwUgYi4XgaR\n" |
| 45 | "WhScBsgYwZ/JoywdyZJgnbcrTDuVcWG56B3vXbhdpMsCQQDf9zeJrjnPZ3Cqm79y\n" |
| 46 | "kdqANep0uwZciiNiWxsQrCHztywOvbFhdp8iYVFG9EK8DMY41Y5TxUwsHD+67zao\n" |
| 47 | "ZNqJAkEA1suLUP/GvL8IwuRneQd2tWDqqRQ/Td3qq03hP7e77XtF/buya3Ghclo5\n" |
| 48 | "54czUR89QyVfJEC6278nzA7n2h1uVQJAcG6mztNL6ja/dKZjYZye2CY44QjSlLo0\n" |
| 49 | "MTgTSjdfg/28fFn2Jjtqf9Pi/X+50LWI/RcYMC2no606wRk9kyOuIQJBAK6VSAim\n" |
| 50 | "1pOEjsYQn0X5KEIrz1G3bfCbB848Ime3U2/FWlCHMr6ch8kCZ5d1WUeJD3LbwMNG\n" |
| 51 | "UCXiYxSsu20QNVw=\n" |
| 52 | "-----END RSA PRIVATE KEY-----\n"; |
| 53 | |
| 54 | static const char kCERT_PEM[] = |
| 55 | "-----BEGIN CERTIFICATE-----\n" |
| 56 | "MIIBmTCCAQKgAwIBAgIEbzBSAjANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDEwZX\n" |
| 57 | "ZWJSVEMwHhcNMTQwMTAyMTgyNDQ3WhcNMTQwMjAxMTgyNDQ3WjARMQ8wDQYDVQQD\n" |
| 58 | "EwZXZWJSVEMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMYRkbhmI7kVA/rM\n" |
| 59 | "czsZ+6JDhDvnkF+vn6yCAGuRPV03zuRqZtDy4N4to7PZu9PjqrRl7nDMXrG3YG9y\n" |
| 60 | "rlIAZ72KjcKKFAJxQyAKLCIdawKRyp8RdK3LEySWEZb0AV58IadqPZDTNHHRX8dz\n" |
| 61 | "5aTSMsbbkZ+C/OzTnbiMqLL/vg6jAgMBAAEwDQYJKoZIhvcNAQELBQADgYEAUflI\n" |
| 62 | "VUe5Krqf5RVa5C3u/UTAOAUJBiDS3VANTCLBxjuMsvqOG0WvaYWP3HYPgrz0jXK2\n" |
| 63 | "LJE/mGw3MyFHEqi81jh95J+ypl6xKW6Rm8jKLR87gUvCaVYn/Z4/P3AqcQTB7wOv\n" |
| 64 | "UD0A8qfhfDM+LK6rPAnCsVN0NRDY3jvd6rzix9M=\n" |
| 65 | "-----END CERTIFICATE-----\n"; |
| 66 | |
Jian Cui | 0a8798b | 2017-11-16 16:58:02 -0800 | [diff] [blame] | 67 | static const char kIntCert1[] = |
| 68 | "-----BEGIN CERTIFICATE-----\n" |
| 69 | "MIIEUjCCAjqgAwIBAgIBAjANBgkqhkiG9w0BAQsFADCBljELMAkGA1UEBhMCVVMx\n" |
| 70 | "EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxFDAS\n" |
| 71 | "BgNVBAoMC0dvb2dsZSwgSW5jMQwwCgYDVQQLDANHVFAxFzAVBgNVBAMMDnRlbGVw\n" |
| 72 | "aG9ueS5nb29nMR0wGwYJKoZIhvcNAQkBFg5ndHBAZ29vZ2xlLmNvbTAeFw0xNzA5\n" |
| 73 | "MjYwNDA5MDNaFw0yMDA2MjIwNDA5MDNaMGQxCzAJBgNVBAYTAlVTMQswCQYDVQQI\n" |
| 74 | "DAJDQTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEXMBUGA1UECgwOdGVsZXBob255\n" |
| 75 | "Lmdvb2cxFzAVBgNVBAMMDnRlbGVwaG9ueS5nb29nMIGfMA0GCSqGSIb3DQEBAQUA\n" |
| 76 | "A4GNADCBiQKBgQDJXWeeU1v1+wlqkVobzI3aN7Uh2iVQA9YCdq5suuabtiD/qoOD\n" |
| 77 | "NKpmQqsx7WZGGWSZTDFEBaUpvIK7Hb+nzRqk6iioPCFOFuarm6GxO1xVneImMuE6\n" |
| 78 | "tuWb3YZPr+ikChJbl11y5UcSbg0QsbeUc+jHl5umNvrL85Y+z8SP0rxbBwIDAQAB\n" |
| 79 | "o2AwXjAdBgNVHQ4EFgQU7tdZobqlN8R8V72FQnRxmqq8tKswHwYDVR0jBBgwFoAU\n" |
| 80 | "5GgKMUtcxkQ2dJrtNR5YOlIAPDswDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMC\n" |
| 81 | "AQYwDQYJKoZIhvcNAQELBQADggIBADObh9Z+z14FmP9zSenhFtq7hFnmNrSkklk8\n" |
| 82 | "eyYWXKfOuIriEQQBZsz76ZcnzStih8Rj+yQ0AXydk4fJ5LOwC2cUqQBar17g6Pd2\n" |
| 83 | "8g4SIL4azR9WvtiSvpuGlwp25b+yunaacDne6ebnf/MUiiKT5w61Xo3cEPVfl38e\n" |
| 84 | "/Up2l0bioid5enUTmg6LY6RxDO6tnZQkz3XD+nNSwT4ehtkqFpHYWjErj0BbkDM2\n" |
| 85 | "hiVc/JsYOZn3DmuOlHVHU6sKwqh3JEyvHO/d7DGzMGWHpHwv2mCTJq6l/sR95Tc2\n" |
| 86 | "GaQZgGDVNs9pdEouJCDm9e/PbQWRYhnat82PTkXx/6mDAAwdZlIi/pACzq8K4p7e\n" |
| 87 | "6hF0t8uKGnXJubHPXxlnJU6yxZ0yWmivAGjwWK4ur832gKlho4jeMDhiI/T3QPpl\n" |
| 88 | "iMNsIvxRhdD+GxJkQP1ezayw8s+Uc9KwKglrkBSRRDLCJUfPOvMmXLUDSTMX7kp4\n" |
| 89 | "/Ak1CA8dVLJIlfEjLBUuvAttlP7+7lsKNgxAjCxZkWLXIyGULzNPQwVWkGfCbrQs\n" |
| 90 | "XyMvSbFsSIb7blV7eLlmf9a+2RprUUkc2ALXLLCI9YQXmxm2beBfMyNmmebwBJzT\n" |
| 91 | "B0OR+5pFFNTJPoNlqpdrDsGrDu7JlUtk0ZLZzYyKXbgy2qXxfd4OWzXXjxpLMszZ\n" |
| 92 | "LDIpOAkj\n" |
| 93 | "-----END CERTIFICATE-----\n"; |
| 94 | |
| 95 | static const char kCACert[] = |
| 96 | "-----BEGIN CERTIFICATE-----\n" |
| 97 | "MIIGETCCA/mgAwIBAgIJAKN9r/BdbGUJMA0GCSqGSIb3DQEBCwUAMIGWMQswCQYD\n" |
| 98 | "VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4g\n" |
| 99 | "VmlldzEUMBIGA1UECgwLR29vZ2xlLCBJbmMxDDAKBgNVBAsMA0dUUDEXMBUGA1UE\n" |
| 100 | "AwwOdGVsZXBob255Lmdvb2cxHTAbBgkqhkiG9w0BCQEWDmd0cEBnb29nbGUuY29t\n" |
| 101 | "MB4XDTE3MDcyNzIzMDE0NVoXDTE3MDgyNjIzMDE0NVowgZYxCzAJBgNVBAYTAlVT\n" |
| 102 | "MRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRQw\n" |
| 103 | "EgYDVQQKDAtHb29nbGUsIEluYzEMMAoGA1UECwwDR1RQMRcwFQYDVQQDDA50ZWxl\n" |
| 104 | "cGhvbnkuZ29vZzEdMBsGCSqGSIb3DQEJARYOZ3RwQGdvb2dsZS5jb20wggIiMA0G\n" |
| 105 | "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCfvpF7aBV5Hp1EHsWoIlL3GeHwh8dS\n" |
| 106 | "lv9VQCegN9rD06Ny7MgcED5AiK2vqXmUmOVS+7NbATkdVYN/eozDhKtN3Q3n87kJ\n" |
| 107 | "Nt/TD/TcZZHOZIGsRPbrf2URK26E/5KzTzbzXVBOA1e+gSj+EBbltGqb01ZO5ErF\n" |
| 108 | "iPGViPM/HpYKdq6mfz2bS5PhU67XZMM2zvToyReQ/Fjm/6PJhwKSRXSgZF5djPhk\n" |
| 109 | "2LfOKMLS0AeZtd2C4DFsCU41lfLUkybioDgFuzTQ3TFi1K8A07KYTMmLY/yQppnf\n" |
| 110 | "SpNX58shlVhM+Ed37K1Z0rU0OfVCZ5P+KKaSSfMranjlU7zeUIhZYjqq/EYrEhbS\n" |
| 111 | "dLnNHwgJrqxzId3kq8uuLM6+VB7JZKnZLfT90GdAbX4+tutNe21smmogF9f80vEy\n" |
| 112 | "gM4tOp9rXrvz9vCwWHXVY9kdKemdLAsREoO6MS9k2ctK4jj80o2dROuFC6Q3e7mz\n" |
| 113 | "RjvZr5Tvi464c2o9o/jNlJ0O6q7V2eQzohD+7VnV5QPpRGXxlIeqpR2zoAg+WtRS\n" |
| 114 | "4OgHOVYiD3M6uAlggJA5pcDjMfkEZ+pkhtVcT4qMCEoruk6GbyPxS565oSHu16bH\n" |
| 115 | "EjeCqbZOVND5T3oA7nz6aQSs8sJabt0jmxUkGVnE+4ZDIuuRtkRma+0P/96Mtqor\n" |
| 116 | "OlpNWY1OBDY64QIDAQABo2AwXjAdBgNVHQ4EFgQU5GgKMUtcxkQ2dJrtNR5YOlIA\n" |
| 117 | "PDswHwYDVR0jBBgwFoAU5GgKMUtcxkQ2dJrtNR5YOlIAPDswDwYDVR0TAQH/BAUw\n" |
| 118 | "AwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggIBAARQly5/bB6VUL2C\n" |
| 119 | "ykDYgWt48go407pAra6tL2kjpdfxV5PdL7iMZRkeht00vj+BVahIqZKrNOa/f5Fx\n" |
| 120 | "vlpahZFu0PDN436aQwRZ9qWut2qDOK0/z9Hhj6NWybquRFwMwqkPG/ivLMDU8Dmj\n" |
| 121 | "CIplpngPYNwXCs0KzdjSXYxqxJbwMjQXELD+/RcurY0oTtJMM1/2vKQMzw24UJqe\n" |
| 122 | "XLJAlsnd2AnWzWNUEviDZY89j9NdkHerBmV2gGzcU+X5lgOO5M8odBv0ZC9D+a6Z\n" |
| 123 | "QPZAOfdGVw60hhGvTW5s/s0dHwCpegRidhs0MD0fTmwwjYFBSmUx3Gztr4JTzOOr\n" |
| 124 | "7e5daJuak2ujQ5DqcGBvt1gePjSudb5brS7JQtN8tI/FyrnR4q/OuOwv1EvlC5RG\n" |
| 125 | "hLX+TXaWqFxB1Hd8ebKRR40mboFG6KcUI3lLBthDvQE7jnq48QfZMjlMQK0ZF1l7\n" |
| 126 | "SrlwRXWA74bU8CLJvnZKKo9p4TsTiDYGSYC6tNHKj5s3TGWL46oqGyZ0KdGNhrtC\n" |
| 127 | "rIGenMhth1vPYjyy0XuGBndXT85yi+IM2l8g8oU845+plxIhgpSI8bbC0oLwnhQ5\n" |
| 128 | "ARfsiYLkXDE7imSS0CSUmye76372mlzAIB1is4bBB/SzpPQtBuB9LDKtONgpSGHn\n" |
| 129 | "dGaXBy+qbVXVyGXaeEbIRjtJ6m92\n" |
| 130 | "-----END CERTIFICATE-----\n"; |
| 131 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 132 | class SSLStreamAdapterTestBase; |
| 133 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 134 | class SSLDummyStreamBase : public rtc::StreamInterface, |
| 135 | public sigslot::has_slots<> { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 136 | public: |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 137 | SSLDummyStreamBase(SSLStreamAdapterTestBase* test, |
| 138 | const std::string &side, |
| 139 | rtc::StreamInterface* in, |
| 140 | rtc::StreamInterface* out) : |
| 141 | test_base_(test), |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 142 | side_(side), |
| 143 | in_(in), |
| 144 | out_(out), |
| 145 | first_packet_(true) { |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 146 | in_->SignalEvent.connect(this, &SSLDummyStreamBase::OnEventIn); |
| 147 | out_->SignalEvent.connect(this, &SSLDummyStreamBase::OnEventOut); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 148 | } |
| 149 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 150 | rtc::StreamState GetState() const override { return rtc::SS_OPEN; } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 151 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 152 | rtc::StreamResult Read(void* buffer, size_t buffer_len, |
| 153 | size_t* read, int* error) override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 154 | rtc::StreamResult r; |
| 155 | |
| 156 | r = in_->Read(buffer, buffer_len, read, error); |
| 157 | if (r == rtc::SR_BLOCK) |
| 158 | return rtc::SR_BLOCK; |
| 159 | if (r == rtc::SR_EOS) |
| 160 | return rtc::SR_EOS; |
| 161 | |
| 162 | if (r != rtc::SR_SUCCESS) { |
| 163 | ADD_FAILURE(); |
| 164 | return rtc::SR_ERROR; |
| 165 | } |
| 166 | |
| 167 | return rtc::SR_SUCCESS; |
| 168 | } |
| 169 | |
| 170 | // Catch readability events on in and pass them up. |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 171 | void OnEventIn(rtc::StreamInterface* stream, int sig, int err) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 172 | int mask = (rtc::SE_READ | rtc::SE_CLOSE); |
| 173 | |
| 174 | if (sig & mask) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 175 | RTC_LOG(LS_VERBOSE) << "SSLDummyStreamBase::OnEvent side=" << side_ |
| 176 | << " sig=" << sig << " forwarding upward"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 177 | PostEvent(sig & mask, 0); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Catch writeability events on out and pass them up. |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 182 | void OnEventOut(rtc::StreamInterface* stream, int sig, int err) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 183 | if (sig & rtc::SE_WRITE) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 184 | RTC_LOG(LS_VERBOSE) << "SSLDummyStreamBase::OnEvent side=" << side_ |
| 185 | << " sig=" << sig << " forwarding upward"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 186 | |
| 187 | PostEvent(sig & rtc::SE_WRITE, 0); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Write to the outgoing FifoBuffer |
| 192 | rtc::StreamResult WriteData(const void* data, size_t data_len, |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 193 | size_t* written, int* error) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 194 | return out_->Write(data, data_len, written, error); |
| 195 | } |
| 196 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 197 | rtc::StreamResult Write(const void* data, size_t data_len, |
| 198 | size_t* written, int* error) override; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 199 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 200 | void Close() override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 201 | RTC_LOG(LS_INFO) << "Closing outbound stream"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 202 | out_->Close(); |
| 203 | } |
| 204 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 205 | protected: |
| 206 | SSLStreamAdapterTestBase* test_base_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 207 | const std::string side_; |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 208 | rtc::StreamInterface* in_; |
| 209 | rtc::StreamInterface* out_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 210 | bool first_packet_; |
| 211 | }; |
| 212 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 213 | class SSLDummyStreamTLS : public SSLDummyStreamBase { |
| 214 | public: |
| 215 | SSLDummyStreamTLS(SSLStreamAdapterTestBase* test, |
| 216 | const std::string& side, |
| 217 | rtc::FifoBuffer* in, |
| 218 | rtc::FifoBuffer* out) : |
| 219 | SSLDummyStreamBase(test, side, in, out) { |
| 220 | } |
| 221 | }; |
| 222 | |
| 223 | class BufferQueueStream : public rtc::BufferQueue, |
| 224 | public rtc::StreamInterface { |
| 225 | public: |
| 226 | BufferQueueStream(size_t capacity, size_t default_size) |
| 227 | : rtc::BufferQueue(capacity, default_size) { |
| 228 | } |
| 229 | |
| 230 | // Implementation of abstract StreamInterface methods. |
| 231 | |
| 232 | // A buffer queue stream is always "open". |
| 233 | rtc::StreamState GetState() const override { return rtc::SS_OPEN; } |
| 234 | |
| 235 | // Reading a buffer queue stream will either succeed or block. |
| 236 | rtc::StreamResult Read(void* buffer, size_t buffer_len, |
| 237 | size_t* read, int* error) override { |
| 238 | if (!ReadFront(buffer, buffer_len, read)) { |
| 239 | return rtc::SR_BLOCK; |
| 240 | } |
| 241 | return rtc::SR_SUCCESS; |
| 242 | } |
| 243 | |
| 244 | // Writing to a buffer queue stream will either succeed or block. |
| 245 | rtc::StreamResult Write(const void* data, size_t data_len, |
| 246 | size_t* written, int* error) override { |
| 247 | if (!WriteBack(data, data_len, written)) { |
| 248 | return rtc::SR_BLOCK; |
| 249 | } |
| 250 | return rtc::SR_SUCCESS; |
| 251 | } |
| 252 | |
| 253 | // A buffer queue stream can not be closed. |
| 254 | void Close() override {} |
| 255 | |
| 256 | protected: |
| 257 | void NotifyReadableForTest() override { |
| 258 | PostEvent(rtc::SE_READ, 0); |
| 259 | } |
| 260 | |
| 261 | void NotifyWritableForTest() override { |
| 262 | PostEvent(rtc::SE_WRITE, 0); |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | class SSLDummyStreamDTLS : public SSLDummyStreamBase { |
| 267 | public: |
| 268 | SSLDummyStreamDTLS(SSLStreamAdapterTestBase* test, |
| 269 | const std::string& side, |
| 270 | BufferQueueStream* in, |
| 271 | BufferQueueStream* out) : |
| 272 | SSLDummyStreamBase(test, side, in, out) { |
| 273 | } |
| 274 | }; |
| 275 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 276 | static const int kFifoBufferSize = 4096; |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 277 | static const int kBufferCapacity = 1; |
| 278 | static const size_t kDefaultBufferSize = 2048; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 279 | |
| 280 | class SSLStreamAdapterTestBase : public testing::Test, |
| 281 | public sigslot::has_slots<> { |
| 282 | public: |
torbjorng | 4e57247 | 2015-10-08 09:42:49 -0700 | [diff] [blame] | 283 | SSLStreamAdapterTestBase( |
| 284 | const std::string& client_cert_pem, |
| 285 | const std::string& client_private_key_pem, |
| 286 | bool dtls, |
| 287 | rtc::KeyParams client_key_type = rtc::KeyParams(rtc::KT_DEFAULT), |
| 288 | rtc::KeyParams server_key_type = rtc::KeyParams(rtc::KT_DEFAULT)) |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 289 | : client_cert_pem_(client_cert_pem), |
| 290 | client_private_key_pem_(client_private_key_pem), |
| 291 | client_key_type_(client_key_type), |
| 292 | server_key_type_(server_key_type), |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 293 | client_stream_(nullptr), |
| 294 | server_stream_(nullptr), |
| 295 | client_identity_(nullptr), |
| 296 | server_identity_(nullptr), |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 297 | delay_(0), |
| 298 | mtu_(1460), |
| 299 | loss_(0), |
| 300 | lose_first_packet_(false), |
| 301 | damage_(false), |
| 302 | dtls_(dtls), |
| 303 | handshake_wait_(5000), |
| 304 | identities_set_(false) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 305 | // Set use of the test RNG to get predictable loss patterns. |
| 306 | rtc::SetRandomTestMode(true); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Steve Anton | 9de3aac | 2017-10-24 10:08:26 -0700 | [diff] [blame] | 309 | ~SSLStreamAdapterTestBase() override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 310 | // Put it back for the next test. |
| 311 | rtc::SetRandomTestMode(false); |
| 312 | } |
| 313 | |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 314 | void SetUp() override { |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 315 | CreateStreams(); |
| 316 | |
| 317 | client_ssl_.reset(rtc::SSLStreamAdapter::Create(client_stream_)); |
| 318 | server_ssl_.reset(rtc::SSLStreamAdapter::Create(server_stream_)); |
| 319 | |
| 320 | // Set up the slots |
| 321 | client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 322 | server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 323 | |
| 324 | if (!client_cert_pem_.empty() && !client_private_key_pem_.empty()) { |
| 325 | client_identity_ = rtc::SSLIdentity::FromPEMStrings( |
| 326 | client_private_key_pem_, client_cert_pem_); |
| 327 | } else { |
| 328 | client_identity_ = rtc::SSLIdentity::Generate("client", client_key_type_); |
| 329 | } |
| 330 | server_identity_ = rtc::SSLIdentity::Generate("server", server_key_type_); |
| 331 | |
| 332 | client_ssl_->SetIdentity(client_identity_); |
| 333 | server_ssl_->SetIdentity(server_identity_); |
| 334 | } |
| 335 | |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 336 | void TearDown() override { |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 337 | client_ssl_.reset(nullptr); |
| 338 | server_ssl_.reset(nullptr); |
| 339 | } |
| 340 | |
| 341 | virtual void CreateStreams() = 0; |
| 342 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 343 | // Recreate the client/server identities with the specified validity period. |
| 344 | // |not_before| and |not_after| are offsets from the current time in number |
| 345 | // of seconds. |
| 346 | void ResetIdentitiesWithValidity(int not_before, int not_after) { |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 347 | CreateStreams(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 348 | |
| 349 | client_ssl_.reset(rtc::SSLStreamAdapter::Create(client_stream_)); |
| 350 | server_ssl_.reset(rtc::SSLStreamAdapter::Create(server_stream_)); |
| 351 | |
| 352 | client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 353 | server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 354 | |
Torbjorn Granlund | 46c9cc0 | 2015-12-01 13:06:34 +0100 | [diff] [blame] | 355 | time_t now = time(nullptr); |
| 356 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 357 | rtc::SSLIdentityParams client_params; |
torbjorng | 4e57247 | 2015-10-08 09:42:49 -0700 | [diff] [blame] | 358 | client_params.key_params = rtc::KeyParams(rtc::KT_DEFAULT); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 359 | client_params.common_name = "client"; |
Torbjorn Granlund | 46c9cc0 | 2015-12-01 13:06:34 +0100 | [diff] [blame] | 360 | client_params.not_before = now + not_before; |
| 361 | client_params.not_after = now + not_after; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 362 | client_identity_ = rtc::SSLIdentity::GenerateForTest(client_params); |
| 363 | |
| 364 | rtc::SSLIdentityParams server_params; |
torbjorng | 4e57247 | 2015-10-08 09:42:49 -0700 | [diff] [blame] | 365 | server_params.key_params = rtc::KeyParams(rtc::KT_DEFAULT); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 366 | server_params.common_name = "server"; |
Torbjorn Granlund | 46c9cc0 | 2015-12-01 13:06:34 +0100 | [diff] [blame] | 367 | server_params.not_before = now + not_before; |
| 368 | server_params.not_after = now + not_after; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 369 | server_identity_ = rtc::SSLIdentity::GenerateForTest(server_params); |
| 370 | |
| 371 | client_ssl_->SetIdentity(client_identity_); |
| 372 | server_ssl_->SetIdentity(server_identity_); |
| 373 | } |
| 374 | |
| 375 | virtual void OnEvent(rtc::StreamInterface *stream, int sig, int err) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 376 | RTC_LOG(LS_VERBOSE) << "SSLStreamAdapterTestBase::OnEvent sig=" << sig; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 377 | |
| 378 | if (sig & rtc::SE_READ) { |
| 379 | ReadData(stream); |
| 380 | } |
| 381 | |
| 382 | if ((stream == client_ssl_.get()) && (sig & rtc::SE_WRITE)) { |
| 383 | WriteData(); |
| 384 | } |
| 385 | } |
| 386 | |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 387 | void SetPeerIdentitiesByDigest(bool correct, bool expect_success) { |
| 388 | unsigned char server_digest[20]; |
| 389 | size_t server_digest_len; |
| 390 | unsigned char client_digest[20]; |
| 391 | size_t client_digest_len; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 392 | bool rv; |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 393 | rtc::SSLPeerCertificateDigestError err; |
| 394 | rtc::SSLPeerCertificateDigestError expected_err = |
| 395 | expect_success |
| 396 | ? rtc::SSLPeerCertificateDigestError::NONE |
| 397 | : rtc::SSLPeerCertificateDigestError::VERIFICATION_FAILED; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 398 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 399 | RTC_LOG(LS_INFO) << "Setting peer identities by digest"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 400 | |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 401 | rv = server_identity_->certificate().ComputeDigest( |
| 402 | rtc::DIGEST_SHA_1, server_digest, 20, &server_digest_len); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 403 | ASSERT_TRUE(rv); |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 404 | rv = client_identity_->certificate().ComputeDigest( |
| 405 | rtc::DIGEST_SHA_1, client_digest, 20, &client_digest_len); |
| 406 | ASSERT_TRUE(rv); |
| 407 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 408 | if (!correct) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 409 | RTC_LOG(LS_INFO) << "Setting bogus digest for server cert"; |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 410 | server_digest[0]++; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 411 | } |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 412 | rv = client_ssl_->SetPeerCertificateDigest(rtc::DIGEST_SHA_1, server_digest, |
| 413 | server_digest_len, &err); |
| 414 | EXPECT_EQ(expected_err, err); |
| 415 | EXPECT_EQ(expect_success, rv); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 416 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 417 | if (!correct) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 418 | RTC_LOG(LS_INFO) << "Setting bogus digest for client cert"; |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 419 | client_digest[0]++; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 420 | } |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 421 | rv = server_ssl_->SetPeerCertificateDigest(rtc::DIGEST_SHA_1, client_digest, |
| 422 | client_digest_len, &err); |
| 423 | EXPECT_EQ(expected_err, err); |
| 424 | EXPECT_EQ(expect_success, rv); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 425 | |
| 426 | identities_set_ = true; |
| 427 | } |
| 428 | |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 429 | void SetupProtocolVersions(rtc::SSLProtocolVersion server_version, |
| 430 | rtc::SSLProtocolVersion client_version) { |
| 431 | server_ssl_->SetMaxProtocolVersion(server_version); |
| 432 | client_ssl_->SetMaxProtocolVersion(client_version); |
| 433 | } |
| 434 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 435 | void TestHandshake(bool expect_success = true) { |
| 436 | server_ssl_->SetMode(dtls_ ? rtc::SSL_MODE_DTLS : |
| 437 | rtc::SSL_MODE_TLS); |
| 438 | client_ssl_->SetMode(dtls_ ? rtc::SSL_MODE_DTLS : |
| 439 | rtc::SSL_MODE_TLS); |
| 440 | |
| 441 | if (!dtls_) { |
| 442 | // Make sure we simulate a reliable network for TLS. |
| 443 | // This is just a check to make sure that people don't write wrong |
| 444 | // tests. |
nisse | c16fa5e | 2017-02-07 07:18:43 -0800 | [diff] [blame] | 445 | RTC_CHECK_EQ(1460, mtu_); |
| 446 | RTC_CHECK(!loss_); |
| 447 | RTC_CHECK(!lose_first_packet_); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | if (!identities_set_) |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 451 | SetPeerIdentitiesByDigest(true, true); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 452 | |
| 453 | // Start the handshake |
| 454 | int rv; |
| 455 | |
| 456 | server_ssl_->SetServerRole(); |
Taylor Brandstetter | c8762a8 | 2016-08-11 12:01:49 -0700 | [diff] [blame] | 457 | rv = server_ssl_->StartSSL(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 458 | ASSERT_EQ(0, rv); |
| 459 | |
Taylor Brandstetter | c8762a8 | 2016-08-11 12:01:49 -0700 | [diff] [blame] | 460 | rv = client_ssl_->StartSSL(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 461 | ASSERT_EQ(0, rv); |
| 462 | |
| 463 | // Now run the handshake |
| 464 | if (expect_success) { |
| 465 | EXPECT_TRUE_WAIT((client_ssl_->GetState() == rtc::SS_OPEN) |
| 466 | && (server_ssl_->GetState() == rtc::SS_OPEN), |
| 467 | handshake_wait_); |
| 468 | } else { |
| 469 | EXPECT_TRUE_WAIT(client_ssl_->GetState() == rtc::SS_CLOSED, |
| 470 | handshake_wait_); |
| 471 | } |
| 472 | } |
| 473 | |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 474 | // This tests that the handshake can complete before the identity is |
| 475 | // verified, and the identity will be verified after the fact. |
| 476 | void TestHandshakeWithDelayedIdentity(bool valid_identity) { |
| 477 | server_ssl_->SetMode(dtls_ ? rtc::SSL_MODE_DTLS : rtc::SSL_MODE_TLS); |
| 478 | client_ssl_->SetMode(dtls_ ? rtc::SSL_MODE_DTLS : rtc::SSL_MODE_TLS); |
| 479 | |
| 480 | if (!dtls_) { |
| 481 | // Make sure we simulate a reliable network for TLS. |
| 482 | // This is just a check to make sure that people don't write wrong |
| 483 | // tests. |
nisse | c16fa5e | 2017-02-07 07:18:43 -0800 | [diff] [blame] | 484 | RTC_CHECK_EQ(1460, mtu_); |
| 485 | RTC_CHECK(!loss_); |
| 486 | RTC_CHECK(!lose_first_packet_); |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | // Start the handshake |
| 490 | int rv; |
| 491 | |
| 492 | server_ssl_->SetServerRole(); |
| 493 | rv = server_ssl_->StartSSL(); |
| 494 | ASSERT_EQ(0, rv); |
| 495 | |
| 496 | rv = client_ssl_->StartSSL(); |
| 497 | ASSERT_EQ(0, rv); |
| 498 | |
| 499 | // Now run the handshake. |
| 500 | EXPECT_TRUE_WAIT( |
| 501 | client_ssl_->IsTlsConnected() && server_ssl_->IsTlsConnected(), |
| 502 | handshake_wait_); |
| 503 | |
| 504 | // Until the identity has been verified, the state should still be |
| 505 | // SS_OPENING and writes should return SR_BLOCK. |
| 506 | EXPECT_EQ(rtc::SS_OPENING, client_ssl_->GetState()); |
| 507 | EXPECT_EQ(rtc::SS_OPENING, server_ssl_->GetState()); |
| 508 | unsigned char packet[1]; |
| 509 | size_t sent; |
| 510 | EXPECT_EQ(rtc::SR_BLOCK, client_ssl_->Write(&packet, 1, &sent, 0)); |
| 511 | EXPECT_EQ(rtc::SR_BLOCK, server_ssl_->Write(&packet, 1, &sent, 0)); |
| 512 | |
| 513 | // If we set an invalid identity at this point, SetPeerCertificateDigest |
| 514 | // should return false. |
| 515 | SetPeerIdentitiesByDigest(valid_identity, valid_identity); |
| 516 | // State should then transition to SS_OPEN or SS_CLOSED based on validation |
| 517 | // of the identity. |
| 518 | if (valid_identity) { |
| 519 | EXPECT_EQ(rtc::SS_OPEN, client_ssl_->GetState()); |
| 520 | EXPECT_EQ(rtc::SS_OPEN, server_ssl_->GetState()); |
| 521 | } else { |
| 522 | EXPECT_EQ(rtc::SS_CLOSED, client_ssl_->GetState()); |
| 523 | EXPECT_EQ(rtc::SS_CLOSED, server_ssl_->GetState()); |
| 524 | } |
| 525 | } |
| 526 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 527 | rtc::StreamResult DataWritten(SSLDummyStreamBase *from, const void *data, |
| 528 | size_t data_len, size_t *written, |
| 529 | int *error) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 530 | // Randomly drop loss_ percent of packets |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 531 | if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 532 | RTC_LOG(LS_VERBOSE) << "Randomly dropping packet, size=" << data_len; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 533 | *written = data_len; |
| 534 | return rtc::SR_SUCCESS; |
| 535 | } |
| 536 | if (dtls_ && (data_len > mtu_)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 537 | RTC_LOG(LS_VERBOSE) << "Dropping packet > mtu, size=" << data_len; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 538 | *written = data_len; |
| 539 | return rtc::SR_SUCCESS; |
| 540 | } |
| 541 | |
| 542 | // Optionally damage application data (type 23). Note that we don't damage |
| 543 | // handshake packets and we damage the last byte to keep the header |
| 544 | // intact but break the MAC. |
| 545 | if (damage_ && (*static_cast<const unsigned char *>(data) == 23)) { |
| 546 | std::vector<char> buf(data_len); |
| 547 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 548 | RTC_LOG(LS_VERBOSE) << "Damaging packet"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 549 | |
| 550 | memcpy(&buf[0], data, data_len); |
| 551 | buf[data_len - 1]++; |
| 552 | |
| 553 | return from->WriteData(&buf[0], data_len, written, error); |
| 554 | } |
| 555 | |
| 556 | return from->WriteData(data, data_len, written, error); |
| 557 | } |
| 558 | |
| 559 | void SetDelay(int delay) { |
| 560 | delay_ = delay; |
| 561 | } |
| 562 | int GetDelay() { return delay_; } |
| 563 | |
| 564 | void SetLoseFirstPacket(bool lose) { |
| 565 | lose_first_packet_ = lose; |
| 566 | } |
| 567 | bool GetLoseFirstPacket() { return lose_first_packet_; } |
| 568 | |
| 569 | void SetLoss(int percent) { |
| 570 | loss_ = percent; |
| 571 | } |
| 572 | |
| 573 | void SetDamage() { |
| 574 | damage_ = true; |
| 575 | } |
| 576 | |
| 577 | void SetMtu(size_t mtu) { |
| 578 | mtu_ = mtu; |
| 579 | } |
| 580 | |
| 581 | void SetHandshakeWait(int wait) { |
| 582 | handshake_wait_ = wait; |
| 583 | } |
| 584 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 585 | void SetDtlsSrtpCryptoSuites(const std::vector<int>& ciphers, bool client) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 586 | if (client) |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 587 | client_ssl_->SetDtlsSrtpCryptoSuites(ciphers); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 588 | else |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 589 | server_ssl_->SetDtlsSrtpCryptoSuites(ciphers); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 592 | bool GetDtlsSrtpCryptoSuite(bool client, int* retval) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 593 | if (client) |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 594 | return client_ssl_->GetDtlsSrtpCryptoSuite(retval); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 595 | else |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 596 | return server_ssl_->GetDtlsSrtpCryptoSuite(retval); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 597 | } |
| 598 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 599 | std::unique_ptr<rtc::SSLCertificate> GetPeerCertificate(bool client) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 600 | if (client) |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 601 | return client_ssl_->GetPeerCertificate(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 602 | else |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 603 | return server_ssl_->GetPeerCertificate(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 606 | bool GetSslCipherSuite(bool client, int* retval) { |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 607 | if (client) |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 608 | return client_ssl_->GetSslCipherSuite(retval); |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 609 | else |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 610 | return server_ssl_->GetSslCipherSuite(retval); |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 611 | } |
| 612 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 613 | int GetSslVersion(bool client) { |
| 614 | if (client) |
| 615 | return client_ssl_->GetSslVersion(); |
| 616 | else |
| 617 | return server_ssl_->GetSslVersion(); |
| 618 | } |
| 619 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 620 | bool ExportKeyingMaterial(const char *label, |
| 621 | const unsigned char *context, |
| 622 | size_t context_len, |
| 623 | bool use_context, |
| 624 | bool client, |
| 625 | unsigned char *result, |
| 626 | size_t result_len) { |
| 627 | if (client) |
| 628 | return client_ssl_->ExportKeyingMaterial(label, |
| 629 | context, context_len, |
| 630 | use_context, |
| 631 | result, result_len); |
| 632 | else |
| 633 | return server_ssl_->ExportKeyingMaterial(label, |
| 634 | context, context_len, |
| 635 | use_context, |
| 636 | result, result_len); |
| 637 | } |
| 638 | |
| 639 | // To be implemented by subclasses. |
| 640 | virtual void WriteData() = 0; |
| 641 | virtual void ReadData(rtc::StreamInterface *stream) = 0; |
| 642 | virtual void TestTransfer(int size) = 0; |
| 643 | |
| 644 | protected: |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 645 | std::string client_cert_pem_; |
| 646 | std::string client_private_key_pem_; |
| 647 | rtc::KeyParams client_key_type_; |
| 648 | rtc::KeyParams server_key_type_; |
| 649 | SSLDummyStreamBase *client_stream_; // freed by client_ssl_ destructor |
| 650 | SSLDummyStreamBase *server_stream_; // freed by server_ssl_ destructor |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 651 | std::unique_ptr<rtc::SSLStreamAdapter> client_ssl_; |
| 652 | std::unique_ptr<rtc::SSLStreamAdapter> server_ssl_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 653 | rtc::SSLIdentity *client_identity_; // freed by client_ssl_ destructor |
| 654 | rtc::SSLIdentity *server_identity_; // freed by server_ssl_ destructor |
| 655 | int delay_; |
| 656 | size_t mtu_; |
| 657 | int loss_; |
| 658 | bool lose_first_packet_; |
| 659 | bool damage_; |
| 660 | bool dtls_; |
| 661 | int handshake_wait_; |
| 662 | bool identities_set_; |
| 663 | }; |
| 664 | |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 665 | class SSLStreamAdapterTestTLS |
| 666 | : public SSLStreamAdapterTestBase, |
torbjorng | 4e57247 | 2015-10-08 09:42:49 -0700 | [diff] [blame] | 667 | public WithParamInterface<tuple<rtc::KeyParams, rtc::KeyParams>> { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 668 | public: |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 669 | SSLStreamAdapterTestTLS() |
| 670 | : SSLStreamAdapterTestBase("", |
| 671 | "", |
| 672 | false, |
| 673 | ::testing::get<0>(GetParam()), |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 674 | ::testing::get<1>(GetParam())), |
| 675 | client_buffer_(kFifoBufferSize), |
| 676 | server_buffer_(kFifoBufferSize) { |
| 677 | } |
| 678 | |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 679 | void CreateStreams() override { |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 680 | client_stream_ = |
| 681 | new SSLDummyStreamTLS(this, "c2s", &client_buffer_, &server_buffer_); |
| 682 | server_stream_ = |
| 683 | new SSLDummyStreamTLS(this, "s2c", &server_buffer_, &client_buffer_); |
| 684 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 685 | |
| 686 | // Test data transfer for TLS |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 687 | void TestTransfer(int size) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 688 | RTC_LOG(LS_INFO) << "Starting transfer test with " << size << " bytes"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 689 | // Create some dummy data to send. |
| 690 | size_t received; |
| 691 | |
| 692 | send_stream_.ReserveSize(size); |
| 693 | for (int i = 0; i < size; ++i) { |
| 694 | char ch = static_cast<char>(i); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 695 | send_stream_.Write(&ch, 1, nullptr, nullptr); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 696 | } |
| 697 | send_stream_.Rewind(); |
| 698 | |
| 699 | // Prepare the receive stream. |
| 700 | recv_stream_.ReserveSize(size); |
| 701 | |
| 702 | // Start sending |
| 703 | WriteData(); |
| 704 | |
| 705 | // Wait for the client to close |
| 706 | EXPECT_TRUE_WAIT(server_ssl_->GetState() == rtc::SS_CLOSED, 10000); |
| 707 | |
| 708 | // Now check the data |
| 709 | recv_stream_.GetSize(&received); |
| 710 | |
| 711 | EXPECT_EQ(static_cast<size_t>(size), received); |
| 712 | EXPECT_EQ(0, memcmp(send_stream_.GetBuffer(), |
| 713 | recv_stream_.GetBuffer(), size)); |
| 714 | } |
| 715 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 716 | void WriteData() override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 717 | size_t position, tosend, size; |
| 718 | rtc::StreamResult rv; |
| 719 | size_t sent; |
| 720 | char block[kBlockSize]; |
| 721 | |
| 722 | send_stream_.GetSize(&size); |
| 723 | if (!size) |
| 724 | return; |
| 725 | |
| 726 | for (;;) { |
| 727 | send_stream_.GetPosition(&position); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 728 | if (send_stream_.Read(block, sizeof(block), &tosend, nullptr) != |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 729 | rtc::SR_EOS) { |
| 730 | rv = client_ssl_->Write(block, tosend, &sent, 0); |
| 731 | |
| 732 | if (rv == rtc::SR_SUCCESS) { |
| 733 | send_stream_.SetPosition(position + sent); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 734 | RTC_LOG(LS_VERBOSE) << "Sent: " << position + sent; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 735 | } else if (rv == rtc::SR_BLOCK) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 736 | RTC_LOG(LS_VERBOSE) << "Blocked..."; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 737 | send_stream_.SetPosition(position); |
| 738 | break; |
| 739 | } else { |
| 740 | ADD_FAILURE(); |
| 741 | break; |
| 742 | } |
| 743 | } else { |
| 744 | // Now close |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 745 | RTC_LOG(LS_INFO) << "Wrote " << position << " bytes. Closing"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 746 | client_ssl_->Close(); |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | }; |
| 751 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 752 | void ReadData(rtc::StreamInterface *stream) override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 753 | char buffer[1600]; |
| 754 | size_t bread; |
| 755 | int err2; |
| 756 | rtc::StreamResult r; |
| 757 | |
| 758 | for (;;) { |
| 759 | r = stream->Read(buffer, sizeof(buffer), &bread, &err2); |
| 760 | |
| 761 | if (r == rtc::SR_ERROR || r == rtc::SR_EOS) { |
| 762 | // Unfortunately, errors are the way that the stream adapter |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 763 | // signals close in OpenSSL. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 764 | stream->Close(); |
| 765 | return; |
| 766 | } |
| 767 | |
| 768 | if (r == rtc::SR_BLOCK) |
| 769 | break; |
| 770 | |
| 771 | ASSERT_EQ(rtc::SR_SUCCESS, r); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 772 | RTC_LOG(LS_VERBOSE) << "Read " << bread; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 773 | |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 774 | recv_stream_.Write(buffer, bread, nullptr, nullptr); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
| 778 | private: |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 779 | rtc::FifoBuffer client_buffer_; |
| 780 | rtc::FifoBuffer server_buffer_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 781 | rtc::MemoryStream send_stream_; |
| 782 | rtc::MemoryStream recv_stream_; |
| 783 | }; |
| 784 | |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 785 | class SSLStreamAdapterTestDTLS |
| 786 | : public SSLStreamAdapterTestBase, |
torbjorng | 4e57247 | 2015-10-08 09:42:49 -0700 | [diff] [blame] | 787 | public WithParamInterface<tuple<rtc::KeyParams, rtc::KeyParams>> { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 788 | public: |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 789 | SSLStreamAdapterTestDTLS() |
| 790 | : SSLStreamAdapterTestBase("", |
| 791 | "", |
| 792 | true, |
| 793 | ::testing::get<0>(GetParam()), |
| 794 | ::testing::get<1>(GetParam())), |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 795 | client_buffer_(kBufferCapacity, kDefaultBufferSize), |
| 796 | server_buffer_(kBufferCapacity, kDefaultBufferSize), |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 797 | packet_size_(1000), |
| 798 | count_(0), |
| 799 | sent_(0) {} |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 800 | |
| 801 | SSLStreamAdapterTestDTLS(const std::string& cert_pem, |
| 802 | const std::string& private_key_pem) : |
| 803 | SSLStreamAdapterTestBase(cert_pem, private_key_pem, true), |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 804 | client_buffer_(kBufferCapacity, kDefaultBufferSize), |
| 805 | server_buffer_(kBufferCapacity, kDefaultBufferSize), |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 806 | packet_size_(1000), count_(0), sent_(0) { |
| 807 | } |
| 808 | |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 809 | void CreateStreams() override { |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 810 | client_stream_ = |
| 811 | new SSLDummyStreamDTLS(this, "c2s", &client_buffer_, &server_buffer_); |
| 812 | server_stream_ = |
| 813 | new SSLDummyStreamDTLS(this, "s2c", &server_buffer_, &client_buffer_); |
| 814 | } |
| 815 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 816 | void WriteData() override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 817 | unsigned char *packet = new unsigned char[1600]; |
| 818 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 819 | while (sent_ < count_) { |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 820 | unsigned int rand_state = sent_; |
| 821 | packet[0] = sent_; |
| 822 | for (size_t i = 1; i < packet_size_; i++) { |
| 823 | // This is a simple LC PRNG. Keep in synch with identical code below. |
| 824 | rand_state = (rand_state * 251 + 19937) >> 7; |
| 825 | packet[i] = rand_state & 0xff; |
| 826 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 827 | |
| 828 | size_t sent; |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 829 | rtc::StreamResult rv = client_ssl_->Write(packet, packet_size_, &sent, 0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 830 | if (rv == rtc::SR_SUCCESS) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 831 | RTC_LOG(LS_VERBOSE) << "Sent: " << sent_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 832 | sent_++; |
| 833 | } else if (rv == rtc::SR_BLOCK) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 834 | RTC_LOG(LS_VERBOSE) << "Blocked..."; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 835 | break; |
| 836 | } else { |
| 837 | ADD_FAILURE(); |
| 838 | break; |
| 839 | } |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 840 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 841 | |
| 842 | delete [] packet; |
| 843 | } |
| 844 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 845 | void ReadData(rtc::StreamInterface *stream) override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 846 | unsigned char buffer[2000]; |
| 847 | size_t bread; |
| 848 | int err2; |
| 849 | rtc::StreamResult r; |
| 850 | |
| 851 | for (;;) { |
| 852 | r = stream->Read(buffer, 2000, &bread, &err2); |
| 853 | |
| 854 | if (r == rtc::SR_ERROR) { |
| 855 | // Unfortunately, errors are the way that the stream adapter |
| 856 | // signals close right now |
| 857 | stream->Close(); |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | if (r == rtc::SR_BLOCK) |
| 862 | break; |
| 863 | |
| 864 | ASSERT_EQ(rtc::SR_SUCCESS, r); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 865 | RTC_LOG(LS_VERBOSE) << "Read " << bread; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 866 | |
| 867 | // Now parse the datagram |
| 868 | ASSERT_EQ(packet_size_, bread); |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 869 | unsigned char packet_num = buffer[0]; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 870 | |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 871 | unsigned int rand_state = packet_num; |
| 872 | for (size_t i = 1; i < packet_size_; i++) { |
| 873 | // This is a simple LC PRNG. Keep in synch with identical code above. |
| 874 | rand_state = (rand_state * 251 + 19937) >> 7; |
| 875 | ASSERT_EQ(rand_state & 0xff, buffer[i]); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 876 | } |
| 877 | received_.insert(packet_num); |
| 878 | } |
| 879 | } |
| 880 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 881 | void TestTransfer(int count) override { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 882 | count_ = count; |
| 883 | |
| 884 | WriteData(); |
| 885 | |
| 886 | EXPECT_TRUE_WAIT(sent_ == count_, 10000); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 887 | RTC_LOG(LS_INFO) << "sent_ == " << sent_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 888 | |
| 889 | if (damage_) { |
| 890 | WAIT(false, 2000); |
| 891 | EXPECT_EQ(0U, received_.size()); |
| 892 | } else if (loss_ == 0) { |
| 893 | EXPECT_EQ_WAIT(static_cast<size_t>(sent_), received_.size(), 1000); |
| 894 | } else { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 895 | RTC_LOG(LS_INFO) << "Sent " << sent_ << " packets; received " |
| 896 | << received_.size(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 897 | } |
| 898 | }; |
| 899 | |
| 900 | private: |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 901 | BufferQueueStream client_buffer_; |
| 902 | BufferQueueStream server_buffer_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 903 | size_t packet_size_; |
| 904 | int count_; |
| 905 | int sent_; |
| 906 | std::set<int> received_; |
| 907 | }; |
| 908 | |
| 909 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 910 | rtc::StreamResult SSLDummyStreamBase::Write(const void* data, size_t data_len, |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 911 | size_t* written, int* error) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 912 | RTC_LOG(LS_VERBOSE) << "Writing to loopback " << data_len; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 913 | |
| 914 | if (first_packet_) { |
| 915 | first_packet_ = false; |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 916 | if (test_base_->GetLoseFirstPacket()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 917 | RTC_LOG(LS_INFO) << "Losing initial packet of length " << data_len; |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 918 | *written = data_len; // Fake successful writing also to writer. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 919 | return rtc::SR_SUCCESS; |
| 920 | } |
| 921 | } |
| 922 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 923 | return test_base_->DataWritten(this, data, data_len, written, error); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 924 | }; |
| 925 | |
| 926 | class SSLStreamAdapterTestDTLSFromPEMStrings : public SSLStreamAdapterTestDTLS { |
| 927 | public: |
| 928 | SSLStreamAdapterTestDTLSFromPEMStrings() : |
| 929 | SSLStreamAdapterTestDTLS(kCERT_PEM, kRSA_PRIVATE_KEY_PEM) { |
| 930 | } |
| 931 | }; |
| 932 | |
Jian Cui | 0a8798b | 2017-11-16 16:58:02 -0800 | [diff] [blame] | 933 | // Test fixture for certificate chaining. Server will push more than one |
| 934 | // certificate. |
| 935 | class SSLStreamAdapterTestDTLSCertChain : public SSLStreamAdapterTestDTLS { |
| 936 | public: |
| 937 | SSLStreamAdapterTestDTLSCertChain() : SSLStreamAdapterTestDTLS("", ""){}; |
| 938 | void SetUp() override { |
| 939 | CreateStreams(); |
| 940 | |
| 941 | client_ssl_.reset(rtc::SSLStreamAdapter::Create(client_stream_)); |
| 942 | server_ssl_.reset(rtc::SSLStreamAdapter::Create(server_stream_)); |
| 943 | |
| 944 | // Set up the slots |
| 945 | client_ssl_->SignalEvent.connect( |
| 946 | reinterpret_cast<SSLStreamAdapterTestBase*>(this), |
| 947 | &SSLStreamAdapterTestBase::OnEvent); |
| 948 | server_ssl_->SignalEvent.connect( |
| 949 | reinterpret_cast<SSLStreamAdapterTestBase*>(this), |
| 950 | &SSLStreamAdapterTestBase::OnEvent); |
| 951 | |
| 952 | if (!client_cert_pem_.empty() && !client_private_key_pem_.empty()) { |
| 953 | client_identity_ = rtc::SSLIdentity::FromPEMStrings( |
| 954 | client_private_key_pem_, client_cert_pem_); |
| 955 | } else { |
| 956 | client_identity_ = rtc::SSLIdentity::Generate("client", client_key_type_); |
| 957 | } |
| 958 | |
| 959 | client_ssl_->SetIdentity(client_identity_); |
| 960 | } |
| 961 | }; |
| 962 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 963 | // Basic tests: TLS |
| 964 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 965 | // Test that we can make a handshake work |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 966 | TEST_P(SSLStreamAdapterTestTLS, TestTLSConnect) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 967 | TestHandshake(); |
| 968 | }; |
| 969 | |
Jian Cui | 0a8798b | 2017-11-16 16:58:02 -0800 | [diff] [blame] | 970 | TEST_P(SSLStreamAdapterTestTLS, GetPeerCertChainWithOneCertificate) { |
| 971 | TestHandshake(); |
| 972 | std::unique_ptr<rtc::SSLCertChain> cert_chain = |
| 973 | client_ssl_->GetPeerSSLCertChain(); |
| 974 | std::unique_ptr<rtc::SSLCertificate> certificate = |
| 975 | client_ssl_->GetPeerCertificate(); |
| 976 | ASSERT_NE(nullptr, cert_chain); |
| 977 | EXPECT_EQ(1u, cert_chain->GetSize()); |
| 978 | EXPECT_EQ(cert_chain->Get(0).ToPEMString(), certificate->ToPEMString()); |
| 979 | } |
| 980 | |
| 981 | TEST_F(SSLStreamAdapterTestDTLSCertChain, TwoCertHandshake) { |
| 982 | server_identity_ = rtc::SSLIdentity::FromPEMChainStrings( |
| 983 | kRSA_PRIVATE_KEY_PEM, std::string(kCERT_PEM) + kCACert); |
| 984 | server_ssl_->SetIdentity(server_identity_); |
| 985 | TestHandshake(); |
| 986 | std::unique_ptr<rtc::SSLCertChain> peer_cert_chain = |
| 987 | client_ssl_->GetPeerSSLCertChain(); |
| 988 | ASSERT_NE(nullptr, peer_cert_chain); |
| 989 | ASSERT_EQ(2u, peer_cert_chain->GetSize()); |
| 990 | EXPECT_EQ(kCERT_PEM, peer_cert_chain->Get(0).ToPEMString()); |
| 991 | EXPECT_EQ(kCACert, peer_cert_chain->Get(1).ToPEMString()); |
| 992 | } |
| 993 | |
David Benjamin | ea84b6b | 2017-12-01 17:25:45 -0500 | [diff] [blame] | 994 | TEST_F(SSLStreamAdapterTestDTLSCertChain, TwoCertHandshakeWithCopy) { |
| 995 | std::unique_ptr<rtc::SSLIdentity> identity( |
| 996 | rtc::SSLIdentity::FromPEMChainStrings(kRSA_PRIVATE_KEY_PEM, |
| 997 | std::string(kCERT_PEM) + kCACert)); |
| 998 | server_identity_ = identity->GetReference(); |
| 999 | server_ssl_->SetIdentity(server_identity_); |
| 1000 | TestHandshake(); |
| 1001 | std::unique_ptr<rtc::SSLCertChain> peer_cert_chain = |
| 1002 | client_ssl_->GetPeerSSLCertChain(); |
| 1003 | ASSERT_NE(nullptr, peer_cert_chain); |
| 1004 | ASSERT_EQ(2u, peer_cert_chain->GetSize()); |
| 1005 | EXPECT_EQ(kCERT_PEM, peer_cert_chain->Get(0).ToPEMString()); |
| 1006 | EXPECT_EQ(kCACert, peer_cert_chain->Get(1).ToPEMString()); |
| 1007 | } |
| 1008 | |
Jian Cui | 0a8798b | 2017-11-16 16:58:02 -0800 | [diff] [blame] | 1009 | TEST_F(SSLStreamAdapterTestDTLSCertChain, ThreeCertHandshake) { |
| 1010 | server_identity_ = rtc::SSLIdentity::FromPEMChainStrings( |
| 1011 | kRSA_PRIVATE_KEY_PEM, std::string(kCERT_PEM) + kIntCert1 + kCACert); |
| 1012 | server_ssl_->SetIdentity(server_identity_); |
| 1013 | TestHandshake(); |
| 1014 | std::unique_ptr<rtc::SSLCertChain> peer_cert_chain = |
| 1015 | client_ssl_->GetPeerSSLCertChain(); |
| 1016 | ASSERT_NE(nullptr, peer_cert_chain); |
| 1017 | ASSERT_EQ(3u, peer_cert_chain->GetSize()); |
| 1018 | EXPECT_EQ(kCERT_PEM, peer_cert_chain->Get(0).ToPEMString()); |
| 1019 | EXPECT_EQ(kIntCert1, peer_cert_chain->Get(1).ToPEMString()); |
| 1020 | EXPECT_EQ(kCACert, peer_cert_chain->Get(2).ToPEMString()); |
| 1021 | } |
| 1022 | |
jiayl@webrtc.org | f1d751c | 2014-09-25 16:38:46 +0000 | [diff] [blame] | 1023 | // Test that closing the connection on one side updates the other side. |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1024 | TEST_P(SSLStreamAdapterTestTLS, TestTLSClose) { |
jiayl@webrtc.org | f1d751c | 2014-09-25 16:38:46 +0000 | [diff] [blame] | 1025 | TestHandshake(); |
| 1026 | client_ssl_->Close(); |
| 1027 | EXPECT_EQ_WAIT(rtc::SS_CLOSED, server_ssl_->GetState(), handshake_wait_); |
| 1028 | }; |
| 1029 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1030 | // Test transfer -- trivial |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1031 | TEST_P(SSLStreamAdapterTestTLS, TestTLSTransfer) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1032 | TestHandshake(); |
| 1033 | TestTransfer(100000); |
| 1034 | }; |
| 1035 | |
| 1036 | // Test read-write after close. |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1037 | TEST_P(SSLStreamAdapterTestTLS, ReadWriteAfterClose) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1038 | TestHandshake(); |
| 1039 | TestTransfer(100000); |
| 1040 | client_ssl_->Close(); |
| 1041 | |
| 1042 | rtc::StreamResult rv; |
| 1043 | char block[kBlockSize]; |
| 1044 | size_t dummy; |
| 1045 | |
| 1046 | // It's an error to write after closed. |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 1047 | rv = client_ssl_->Write(block, sizeof(block), &dummy, nullptr); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1048 | ASSERT_EQ(rtc::SR_ERROR, rv); |
| 1049 | |
| 1050 | // But after closed read gives you EOS. |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 1051 | rv = client_ssl_->Read(block, sizeof(block), &dummy, nullptr); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1052 | ASSERT_EQ(rtc::SR_EOS, rv); |
| 1053 | }; |
| 1054 | |
| 1055 | // Test a handshake with a bogus peer digest |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1056 | TEST_P(SSLStreamAdapterTestTLS, TestTLSBogusDigest) { |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 1057 | SetPeerIdentitiesByDigest(false, true); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1058 | TestHandshake(false); |
| 1059 | }; |
| 1060 | |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 1061 | TEST_P(SSLStreamAdapterTestTLS, TestTLSDelayedIdentity) { |
| 1062 | TestHandshakeWithDelayedIdentity(true); |
| 1063 | }; |
| 1064 | |
| 1065 | TEST_P(SSLStreamAdapterTestTLS, TestTLSDelayedIdentityWithBogusDigest) { |
| 1066 | TestHandshakeWithDelayedIdentity(false); |
| 1067 | }; |
| 1068 | |
| 1069 | // Test that the correct error is returned when SetPeerCertificateDigest is |
| 1070 | // called with an unknown algorithm. |
| 1071 | TEST_P(SSLStreamAdapterTestTLS, |
| 1072 | TestSetPeerCertificateDigestWithUnknownAlgorithm) { |
| 1073 | unsigned char server_digest[20]; |
| 1074 | size_t server_digest_len; |
| 1075 | bool rv; |
| 1076 | rtc::SSLPeerCertificateDigestError err; |
| 1077 | |
| 1078 | rv = server_identity_->certificate().ComputeDigest( |
| 1079 | rtc::DIGEST_SHA_1, server_digest, 20, &server_digest_len); |
| 1080 | ASSERT_TRUE(rv); |
| 1081 | |
| 1082 | rv = client_ssl_->SetPeerCertificateDigest("unknown algorithm", server_digest, |
| 1083 | server_digest_len, &err); |
| 1084 | EXPECT_EQ(rtc::SSLPeerCertificateDigestError::UNKNOWN_ALGORITHM, err); |
| 1085 | EXPECT_FALSE(rv); |
| 1086 | } |
| 1087 | |
| 1088 | // Test that the correct error is returned when SetPeerCertificateDigest is |
| 1089 | // called with an invalid digest length. |
| 1090 | TEST_P(SSLStreamAdapterTestTLS, TestSetPeerCertificateDigestWithInvalidLength) { |
| 1091 | unsigned char server_digest[20]; |
| 1092 | size_t server_digest_len; |
| 1093 | bool rv; |
| 1094 | rtc::SSLPeerCertificateDigestError err; |
| 1095 | |
| 1096 | rv = server_identity_->certificate().ComputeDigest( |
| 1097 | rtc::DIGEST_SHA_1, server_digest, 20, &server_digest_len); |
| 1098 | ASSERT_TRUE(rv); |
| 1099 | |
| 1100 | rv = client_ssl_->SetPeerCertificateDigest(rtc::DIGEST_SHA_1, server_digest, |
| 1101 | server_digest_len - 1, &err); |
| 1102 | EXPECT_EQ(rtc::SSLPeerCertificateDigestError::INVALID_LENGTH, err); |
| 1103 | EXPECT_FALSE(rv); |
| 1104 | } |
| 1105 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1106 | // Test moving a bunch of data |
| 1107 | |
| 1108 | // Basic tests: DTLS |
| 1109 | // Test that we can make a handshake work |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1110 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSConnect) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1111 | TestHandshake(); |
| 1112 | }; |
| 1113 | |
| 1114 | // Test that we can make a handshake work if the first packet in |
| 1115 | // each direction is lost. This gives us predictable loss |
| 1116 | // rather than having to tune random |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1117 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSConnectWithLostFirstPacket) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1118 | SetLoseFirstPacket(true); |
| 1119 | TestHandshake(); |
| 1120 | }; |
| 1121 | |
| 1122 | // Test a handshake with loss and delay |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1123 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSConnectWithLostFirstPacketDelay2s) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1124 | SetLoseFirstPacket(true); |
| 1125 | SetDelay(2000); |
| 1126 | SetHandshakeWait(20000); |
| 1127 | TestHandshake(); |
| 1128 | }; |
| 1129 | |
| 1130 | // Test a handshake with small MTU |
pbos@webrtc.org | 127ca3f | 2014-10-09 07:52:03 +0000 | [diff] [blame] | 1131 | // Disabled due to https://code.google.com/p/webrtc/issues/detail?id=3910 |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1132 | TEST_P(SSLStreamAdapterTestDTLS, DISABLED_TestDTLSConnectWithSmallMtu) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1133 | SetMtu(700); |
| 1134 | SetHandshakeWait(20000); |
| 1135 | TestHandshake(); |
| 1136 | }; |
| 1137 | |
| 1138 | // Test transfer -- trivial |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 1139 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSTransfer) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1140 | TestHandshake(); |
| 1141 | TestTransfer(100); |
| 1142 | }; |
| 1143 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 1144 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSTransferWithLoss) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1145 | TestHandshake(); |
| 1146 | SetLoss(10); |
| 1147 | TestTransfer(100); |
| 1148 | }; |
| 1149 | |
jbauch | e488a0d | 2015-11-19 05:17:58 -0800 | [diff] [blame] | 1150 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSTransferWithDamage) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1151 | SetDamage(); // Must be called first because first packet |
| 1152 | // write happens at end of handshake. |
| 1153 | TestHandshake(); |
| 1154 | TestTransfer(100); |
| 1155 | }; |
| 1156 | |
deadbeef | 89824f6 | 2016-09-30 11:55:43 -0700 | [diff] [blame] | 1157 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSDelayedIdentity) { |
| 1158 | TestHandshakeWithDelayedIdentity(true); |
| 1159 | }; |
| 1160 | |
| 1161 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSDelayedIdentityWithBogusDigest) { |
| 1162 | TestHandshakeWithDelayedIdentity(false); |
| 1163 | }; |
| 1164 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1165 | // Test DTLS-SRTP with all high ciphers |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1166 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHigh) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1167 | std::vector<int> high; |
| 1168 | high.push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 1169 | SetDtlsSrtpCryptoSuites(high, true); |
| 1170 | SetDtlsSrtpCryptoSuites(high, false); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1171 | TestHandshake(); |
| 1172 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1173 | int client_cipher; |
| 1174 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1175 | int server_cipher; |
| 1176 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1177 | |
| 1178 | ASSERT_EQ(client_cipher, server_cipher); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1179 | ASSERT_EQ(client_cipher, rtc::SRTP_AES128_CM_SHA1_80); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1180 | }; |
| 1181 | |
| 1182 | // Test DTLS-SRTP with all low ciphers |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1183 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpLow) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1184 | std::vector<int> low; |
| 1185 | low.push_back(rtc::SRTP_AES128_CM_SHA1_32); |
| 1186 | SetDtlsSrtpCryptoSuites(low, true); |
| 1187 | SetDtlsSrtpCryptoSuites(low, false); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1188 | TestHandshake(); |
| 1189 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1190 | int client_cipher; |
| 1191 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1192 | int server_cipher; |
| 1193 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1194 | |
| 1195 | ASSERT_EQ(client_cipher, server_cipher); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1196 | ASSERT_EQ(client_cipher, rtc::SRTP_AES128_CM_SHA1_32); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1197 | }; |
| 1198 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1199 | // Test DTLS-SRTP with a mismatch -- should not converge |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1200 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHighLow) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1201 | std::vector<int> high; |
| 1202 | high.push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 1203 | std::vector<int> low; |
| 1204 | low.push_back(rtc::SRTP_AES128_CM_SHA1_32); |
| 1205 | SetDtlsSrtpCryptoSuites(high, true); |
| 1206 | SetDtlsSrtpCryptoSuites(low, false); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1207 | TestHandshake(); |
| 1208 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1209 | int client_cipher; |
| 1210 | ASSERT_FALSE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1211 | int server_cipher; |
| 1212 | ASSERT_FALSE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1213 | }; |
| 1214 | |
| 1215 | // Test DTLS-SRTP with each side being mixed -- should select high |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1216 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpMixed) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1217 | std::vector<int> mixed; |
| 1218 | mixed.push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 1219 | mixed.push_back(rtc::SRTP_AES128_CM_SHA1_32); |
| 1220 | SetDtlsSrtpCryptoSuites(mixed, true); |
| 1221 | SetDtlsSrtpCryptoSuites(mixed, false); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1222 | TestHandshake(); |
| 1223 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1224 | int client_cipher; |
| 1225 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1226 | int server_cipher; |
| 1227 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1228 | |
| 1229 | ASSERT_EQ(client_cipher, server_cipher); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 1230 | ASSERT_EQ(client_cipher, rtc::SRTP_AES128_CM_SHA1_80); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1231 | }; |
| 1232 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1233 | // Test DTLS-SRTP with all GCM-128 ciphers. |
| 1234 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpGCM128) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1235 | std::vector<int> gcm128; |
| 1236 | gcm128.push_back(rtc::SRTP_AEAD_AES_128_GCM); |
| 1237 | SetDtlsSrtpCryptoSuites(gcm128, true); |
| 1238 | SetDtlsSrtpCryptoSuites(gcm128, false); |
| 1239 | TestHandshake(); |
| 1240 | |
| 1241 | int client_cipher; |
| 1242 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1243 | int server_cipher; |
| 1244 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
| 1245 | |
| 1246 | ASSERT_EQ(client_cipher, server_cipher); |
| 1247 | ASSERT_EQ(client_cipher, rtc::SRTP_AEAD_AES_128_GCM); |
| 1248 | }; |
| 1249 | |
| 1250 | // Test DTLS-SRTP with all GCM-256 ciphers. |
| 1251 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpGCM256) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1252 | std::vector<int> gcm256; |
| 1253 | gcm256.push_back(rtc::SRTP_AEAD_AES_256_GCM); |
| 1254 | SetDtlsSrtpCryptoSuites(gcm256, true); |
| 1255 | SetDtlsSrtpCryptoSuites(gcm256, false); |
| 1256 | TestHandshake(); |
| 1257 | |
| 1258 | int client_cipher; |
| 1259 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1260 | int server_cipher; |
| 1261 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
| 1262 | |
| 1263 | ASSERT_EQ(client_cipher, server_cipher); |
| 1264 | ASSERT_EQ(client_cipher, rtc::SRTP_AEAD_AES_256_GCM); |
| 1265 | }; |
| 1266 | |
| 1267 | // Test DTLS-SRTP with mixed GCM-128/-256 ciphers -- should not converge. |
| 1268 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpGCMMismatch) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1269 | std::vector<int> gcm128; |
| 1270 | gcm128.push_back(rtc::SRTP_AEAD_AES_128_GCM); |
| 1271 | std::vector<int> gcm256; |
| 1272 | gcm256.push_back(rtc::SRTP_AEAD_AES_256_GCM); |
| 1273 | SetDtlsSrtpCryptoSuites(gcm128, true); |
| 1274 | SetDtlsSrtpCryptoSuites(gcm256, false); |
| 1275 | TestHandshake(); |
| 1276 | |
| 1277 | int client_cipher; |
| 1278 | ASSERT_FALSE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1279 | int server_cipher; |
| 1280 | ASSERT_FALSE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
| 1281 | }; |
| 1282 | |
| 1283 | // Test DTLS-SRTP with both GCM-128/-256 ciphers -- should select GCM-256. |
| 1284 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpGCMMixed) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1285 | std::vector<int> gcmBoth; |
| 1286 | gcmBoth.push_back(rtc::SRTP_AEAD_AES_256_GCM); |
| 1287 | gcmBoth.push_back(rtc::SRTP_AEAD_AES_128_GCM); |
| 1288 | SetDtlsSrtpCryptoSuites(gcmBoth, true); |
| 1289 | SetDtlsSrtpCryptoSuites(gcmBoth, false); |
| 1290 | TestHandshake(); |
| 1291 | |
| 1292 | int client_cipher; |
| 1293 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(true, &client_cipher)); |
| 1294 | int server_cipher; |
| 1295 | ASSERT_TRUE(GetDtlsSrtpCryptoSuite(false, &server_cipher)); |
| 1296 | |
| 1297 | ASSERT_EQ(client_cipher, server_cipher); |
| 1298 | ASSERT_EQ(client_cipher, rtc::SRTP_AEAD_AES_256_GCM); |
| 1299 | }; |
| 1300 | |
| 1301 | // Test SRTP cipher suite lengths. |
| 1302 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpKeyAndSaltLengths) { |
| 1303 | int key_len; |
| 1304 | int salt_len; |
| 1305 | |
| 1306 | ASSERT_FALSE(rtc::GetSrtpKeyAndSaltLengths( |
| 1307 | rtc::SRTP_INVALID_CRYPTO_SUITE, &key_len, &salt_len)); |
| 1308 | |
| 1309 | ASSERT_TRUE(rtc::GetSrtpKeyAndSaltLengths( |
| 1310 | rtc::SRTP_AES128_CM_SHA1_32, &key_len, &salt_len)); |
| 1311 | ASSERT_EQ(128/8, key_len); |
| 1312 | ASSERT_EQ(112/8, salt_len); |
| 1313 | |
| 1314 | ASSERT_TRUE(rtc::GetSrtpKeyAndSaltLengths( |
| 1315 | rtc::SRTP_AES128_CM_SHA1_80, &key_len, &salt_len)); |
| 1316 | ASSERT_EQ(128/8, key_len); |
| 1317 | ASSERT_EQ(112/8, salt_len); |
| 1318 | |
| 1319 | ASSERT_TRUE(rtc::GetSrtpKeyAndSaltLengths( |
| 1320 | rtc::SRTP_AEAD_AES_128_GCM, &key_len, &salt_len)); |
| 1321 | ASSERT_EQ(128/8, key_len); |
| 1322 | ASSERT_EQ(96/8, salt_len); |
| 1323 | |
| 1324 | ASSERT_TRUE(rtc::GetSrtpKeyAndSaltLengths( |
| 1325 | rtc::SRTP_AEAD_AES_256_GCM, &key_len, &salt_len)); |
| 1326 | ASSERT_EQ(256/8, key_len); |
| 1327 | ASSERT_EQ(96/8, salt_len); |
| 1328 | }; |
| 1329 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1330 | // Test an exporter |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1331 | TEST_P(SSLStreamAdapterTestDTLS, TestDTLSExporter) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1332 | TestHandshake(); |
| 1333 | unsigned char client_out[20]; |
| 1334 | unsigned char server_out[20]; |
| 1335 | |
| 1336 | bool result; |
| 1337 | result = ExportKeyingMaterial(kExporterLabel, |
| 1338 | kExporterContext, kExporterContextLen, |
| 1339 | true, true, |
| 1340 | client_out, sizeof(client_out)); |
| 1341 | ASSERT_TRUE(result); |
| 1342 | |
| 1343 | result = ExportKeyingMaterial(kExporterLabel, |
| 1344 | kExporterContext, kExporterContextLen, |
| 1345 | true, false, |
| 1346 | server_out, sizeof(server_out)); |
| 1347 | ASSERT_TRUE(result); |
| 1348 | |
| 1349 | ASSERT_TRUE(!memcmp(client_out, server_out, sizeof(client_out))); |
| 1350 | } |
| 1351 | |
| 1352 | // Test not yet valid certificates are not rejected. |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1353 | TEST_P(SSLStreamAdapterTestDTLS, TestCertNotYetValid) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1354 | long one_day = 60 * 60 * 24; |
| 1355 | // Make the certificates not valid until one day later. |
| 1356 | ResetIdentitiesWithValidity(one_day, one_day); |
| 1357 | TestHandshake(); |
| 1358 | } |
| 1359 | |
| 1360 | // Test expired certificates are not rejected. |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1361 | TEST_P(SSLStreamAdapterTestDTLS, TestCertExpired) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1362 | long one_day = 60 * 60 * 24; |
| 1363 | // Make the certificates already expired. |
| 1364 | ResetIdentitiesWithValidity(-one_day, -one_day); |
| 1365 | TestHandshake(); |
| 1366 | } |
| 1367 | |
| 1368 | // Test data transfer using certs created from strings. |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 1369 | TEST_F(SSLStreamAdapterTestDTLSFromPEMStrings, TestTransfer) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1370 | TestHandshake(); |
| 1371 | TestTransfer(100); |
| 1372 | } |
| 1373 | |
| 1374 | // Test getting the remote certificate. |
torbjorng | 7593aad | 2015-11-19 12:20:51 -0800 | [diff] [blame] | 1375 | TEST_F(SSLStreamAdapterTestDTLSFromPEMStrings, TestDTLSGetPeerCertificate) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1376 | // Peer certificates haven't been received yet. |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1377 | ASSERT_FALSE(GetPeerCertificate(true)); |
| 1378 | ASSERT_FALSE(GetPeerCertificate(false)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1379 | |
| 1380 | TestHandshake(); |
| 1381 | |
| 1382 | // The client should have a peer certificate after the handshake. |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 1383 | std::unique_ptr<rtc::SSLCertificate> client_peer_cert = |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1384 | GetPeerCertificate(true); |
| 1385 | ASSERT_TRUE(client_peer_cert); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1386 | |
| 1387 | // It's not kCERT_PEM. |
| 1388 | std::string client_peer_string = client_peer_cert->ToPEMString(); |
| 1389 | ASSERT_NE(kCERT_PEM, client_peer_string); |
| 1390 | |
| 1391 | // It must not have a chain, because the test certs are self-signed. |
kwiberg | f5d4786 | 2016-03-15 12:53:24 -0700 | [diff] [blame] | 1392 | ASSERT_FALSE(client_peer_cert->GetChain()); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1393 | |
| 1394 | // The server should have a peer certificate after the handshake. |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 1395 | std::unique_ptr<rtc::SSLCertificate> server_peer_cert = |
kwiberg | b4d01c4 | 2016-04-06 05:15:06 -0700 | [diff] [blame] | 1396 | GetPeerCertificate(false); |
| 1397 | ASSERT_TRUE(server_peer_cert); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1398 | |
| 1399 | // It's kCERT_PEM |
| 1400 | ASSERT_EQ(kCERT_PEM, server_peer_cert->ToPEMString()); |
| 1401 | |
| 1402 | // It must not have a chain, because the test certs are self-signed. |
kwiberg | f5d4786 | 2016-03-15 12:53:24 -0700 | [diff] [blame] | 1403 | ASSERT_FALSE(server_peer_cert->GetChain()); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1404 | } |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 1405 | |
| 1406 | // Test getting the used DTLS ciphers. |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1407 | // DTLS 1.2 enabled for neither client nor server -> DTLS 1.0 will be used. |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1408 | TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuite) { |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1409 | SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_10, rtc::SSL_PROTOCOL_DTLS_10); |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 1410 | TestHandshake(); |
| 1411 | |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1412 | int client_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1413 | ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1414 | int server_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1415 | ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 1416 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1417 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_10, GetSslVersion(true)); |
| 1418 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_10, GetSslVersion(false)); |
| 1419 | |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 1420 | ASSERT_EQ(client_cipher, server_cipher); |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1421 | ASSERT_TRUE(rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1422 | server_cipher, ::testing::get<1>(GetParam()).type())); |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | // Test getting the used DTLS 1.2 ciphers. |
| 1426 | // DTLS 1.2 enabled for client and server -> DTLS 1.2 will be used. |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1427 | TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuiteDtls12Both) { |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1428 | SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_12, rtc::SSL_PROTOCOL_DTLS_12); |
| 1429 | TestHandshake(); |
| 1430 | |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1431 | int client_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1432 | ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1433 | int server_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1434 | ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1435 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1436 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_12, GetSslVersion(true)); |
| 1437 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_12, GetSslVersion(false)); |
| 1438 | |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1439 | ASSERT_EQ(client_cipher, server_cipher); |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1440 | ASSERT_TRUE(rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1441 | server_cipher, ::testing::get<1>(GetParam()).type())); |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | // DTLS 1.2 enabled for client only -> DTLS 1.0 will be used. |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1445 | TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuiteDtls12Client) { |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1446 | SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_10, rtc::SSL_PROTOCOL_DTLS_12); |
| 1447 | TestHandshake(); |
| 1448 | |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1449 | int client_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1450 | ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1451 | int server_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1452 | ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1453 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1454 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_10, GetSslVersion(true)); |
| 1455 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_10, GetSslVersion(false)); |
| 1456 | |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1457 | ASSERT_EQ(client_cipher, server_cipher); |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1458 | ASSERT_TRUE(rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1459 | server_cipher, ::testing::get<1>(GetParam()).type())); |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | // DTLS 1.2 enabled for server only -> DTLS 1.0 will be used. |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1463 | TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuiteDtls12Server) { |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1464 | SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_12, rtc::SSL_PROTOCOL_DTLS_10); |
| 1465 | TestHandshake(); |
| 1466 | |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1467 | int client_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1468 | ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); |
Guo-wei Shieh | 6caafbe | 2015-10-05 12:43:27 -0700 | [diff] [blame] | 1469 | int server_cipher; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1470 | ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1471 | |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1472 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_10, GetSslVersion(true)); |
| 1473 | ASSERT_EQ(rtc::SSL_PROTOCOL_DTLS_10, GetSslVersion(false)); |
| 1474 | |
Joachim Bauch | 831c558 | 2015-05-20 12:48:41 +0200 | [diff] [blame] | 1475 | ASSERT_EQ(client_cipher, server_cipher); |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 1476 | ASSERT_TRUE(rtc::SSLStreamAdapter::IsAcceptableCipher( |
| 1477 | server_cipher, ::testing::get<1>(GetParam()).type())); |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 1478 | } |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 1479 | |
torbjorng | 4e57247 | 2015-10-08 09:42:49 -0700 | [diff] [blame] | 1480 | // The RSA keysizes here might look strange, why not include the RFC's size |
| 1481 | // 2048?. The reason is test case slowness; testing two sizes to exercise |
| 1482 | // parametrization is sufficient. |
| 1483 | INSTANTIATE_TEST_CASE_P( |
| 1484 | SSLStreamAdapterTestsTLS, |
| 1485 | SSLStreamAdapterTestTLS, |
| 1486 | Combine(Values(rtc::KeyParams::RSA(1024, 65537), |
| 1487 | rtc::KeyParams::RSA(1152, 65537), |
| 1488 | rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), |
| 1489 | Values(rtc::KeyParams::RSA(1024, 65537), |
| 1490 | rtc::KeyParams::RSA(1152, 65537), |
| 1491 | rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| 1492 | INSTANTIATE_TEST_CASE_P( |
| 1493 | SSLStreamAdapterTestsDTLS, |
| 1494 | SSLStreamAdapterTestDTLS, |
| 1495 | Combine(Values(rtc::KeyParams::RSA(1024, 65537), |
| 1496 | rtc::KeyParams::RSA(1152, 65537), |
| 1497 | rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), |
| 1498 | Values(rtc::KeyParams::RSA(1024, 65537), |
| 1499 | rtc::KeyParams::RSA(1152, 65537), |
| 1500 | rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |