David Benjamin | 2e52121 | 2014-07-16 14:37:51 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2014, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
| 15 | #include <stdio.h> |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 16 | #include <string.h> |
David Benjamin | 1269ddd | 2015-10-18 15:18:55 -0400 | [diff] [blame] | 17 | #include <time.h> |
David Benjamin | 2e52121 | 2014-07-16 14:37:51 -0400 | [diff] [blame] | 18 | |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 19 | #include <algorithm> |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 20 | #include <string> |
| 21 | #include <vector> |
| 22 | |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 23 | #include <openssl/base64.h> |
| 24 | #include <openssl/bio.h> |
David Benjamin | 7a1eefd | 2015-10-17 23:39:22 -0400 | [diff] [blame] | 25 | #include <openssl/crypto.h> |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 26 | #include <openssl/err.h> |
| 27 | #include <openssl/ssl.h> |
| 28 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 29 | #include "test/scoped_types.h" |
Sigbjorn Vik | 2b23d24 | 2015-06-29 15:07:26 +0200 | [diff] [blame] | 30 | #include "../crypto/test/test_util.h" |
| 31 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 32 | |
| 33 | struct ExpectedCipher { |
| 34 | unsigned long id; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 35 | int in_group_flag; |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 36 | }; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 37 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 38 | struct CipherTest { |
| 39 | // The rule string to apply. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 40 | const char *rule; |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 41 | // The list of expected ciphers, in order, terminated with -1. |
| 42 | const ExpectedCipher *expected; |
| 43 | }; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 44 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 45 | // Selecting individual ciphers should work. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 46 | static const char kRule1[] = |
| 47 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 48 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 49 | "ECDHE-ECDSA-AES128-GCM-SHA256:" |
| 50 | "ECDHE-RSA-AES128-GCM-SHA256"; |
| 51 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 52 | static const ExpectedCipher kExpected1[] = { |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 53 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, 0 }, |
| 54 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 55 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 0 }, |
| 56 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 57 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 58 | }; |
| 59 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 60 | // + reorders selected ciphers to the end, keeping their relative |
| 61 | // order. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 62 | static const char kRule2[] = |
| 63 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 64 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 65 | "ECDHE-ECDSA-AES128-GCM-SHA256:" |
| 66 | "ECDHE-RSA-AES128-GCM-SHA256:" |
| 67 | "+aRSA"; |
| 68 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 69 | static const ExpectedCipher kExpected2[] = { |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 70 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 71 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 0 }, |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 72 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 73 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 74 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 75 | }; |
| 76 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 77 | // ! banishes ciphers from future selections. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 78 | static const char kRule3[] = |
| 79 | "!aRSA:" |
| 80 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 81 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 82 | "ECDHE-ECDSA-AES128-GCM-SHA256:" |
| 83 | "ECDHE-RSA-AES128-GCM-SHA256"; |
| 84 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 85 | static const ExpectedCipher kExpected3[] = { |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 86 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 87 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 88 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 89 | }; |
| 90 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 91 | // Multiple masks can be ANDed in a single rule. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 92 | static const char kRule4[] = "kRSA+AESGCM+AES128"; |
| 93 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 94 | static const ExpectedCipher kExpected4[] = { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 95 | { TLS1_CK_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 96 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 97 | }; |
| 98 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 99 | // - removes selected ciphers, but preserves their order for future |
| 100 | // selections. Select AES_128_GCM, but order the key exchanges RSA, |
| 101 | // DHE_RSA, ECDHE_RSA. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 102 | static const char kRule5[] = |
David Benjamin | 7061e28 | 2015-03-19 11:10:48 -0400 | [diff] [blame] | 103 | "ALL:-kECDHE:-kDHE:-kRSA:-ALL:" |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 104 | "AESGCM+AES128+aRSA"; |
| 105 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 106 | static const ExpectedCipher kExpected5[] = { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 107 | { TLS1_CK_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
| 108 | { TLS1_CK_DHE_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
| 109 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 110 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 111 | }; |
| 112 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 113 | // Unknown selectors are no-ops. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 114 | static const char kRule6[] = |
| 115 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 116 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 117 | "ECDHE-ECDSA-AES128-GCM-SHA256:" |
| 118 | "ECDHE-RSA-AES128-GCM-SHA256:" |
| 119 | "BOGUS1:-BOGUS2:+BOGUS3:!BOGUS4"; |
| 120 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 121 | static const ExpectedCipher kExpected6[] = { |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 122 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, 0 }, |
| 123 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 124 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 0 }, |
| 125 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 126 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 127 | }; |
| 128 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 129 | // Square brackets specify equi-preference groups. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 130 | static const char kRule7[] = |
| 131 | "[ECDHE-ECDSA-CHACHA20-POLY1305|ECDHE-ECDSA-AES128-GCM-SHA256]:" |
| 132 | "[ECDHE-RSA-CHACHA20-POLY1305]:" |
| 133 | "ECDHE-RSA-AES128-GCM-SHA256"; |
| 134 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 135 | static const ExpectedCipher kExpected7[] = { |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 136 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, 1 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 137 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, 0 }, |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 138 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 139 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 140 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 141 | }; |
| 142 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 143 | // @STRENGTH performs a stable strength-sort of the selected |
| 144 | // ciphers and only the selected ciphers. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 145 | static const char kRule8[] = |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 146 | // To simplify things, banish all but {ECDHE_RSA,RSA} x |
| 147 | // {CHACHA20,AES_256_CBC,AES_128_CBC,RC4} x SHA1. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 148 | "!kEDH:!AESGCM:!3DES:!SHA256:!MD5:!SHA384:" |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 149 | // Order some ciphers backwards by strength. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 150 | "ALL:-CHACHA20:-AES256:-AES128:-RC4:-ALL:" |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 151 | // Select ECDHE ones and sort them by strength. Ties should resolve |
| 152 | // based on the order above. |
David Benjamin | 7061e28 | 2015-03-19 11:10:48 -0400 | [diff] [blame] | 153 | "kECDHE:@STRENGTH:-ALL:" |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 154 | // Now bring back everything uses RSA. ECDHE_RSA should be first, |
| 155 | // sorted by strength. Then RSA, backwards by strength. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 156 | "aRSA"; |
| 157 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 158 | static const ExpectedCipher kExpected8[] = { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 159 | { TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA, 0 }, |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 160 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 161 | { TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA, 0 }, |
| 162 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA, 0 }, |
| 163 | { SSL3_CK_RSA_RC4_128_SHA, 0 }, |
| 164 | { TLS1_CK_RSA_WITH_AES_128_SHA, 0 }, |
| 165 | { TLS1_CK_RSA_WITH_AES_256_SHA, 0 }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 166 | { 0, 0 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 169 | // Exact ciphers may not be used in multi-part rules; they are treated |
| 170 | // as unknown aliases. |
| 171 | static const char kRule9[] = |
| 172 | "ECDHE-ECDSA-CHACHA20-POLY1305:" |
| 173 | "ECDHE-RSA-CHACHA20-POLY1305:" |
| 174 | "!ECDHE-RSA-CHACHA20-POLY1305+RSA:" |
| 175 | "!ECDSA+ECDHE-ECDSA-CHACHA20-POLY1305"; |
| 176 | |
| 177 | static const ExpectedCipher kExpected9[] = { |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 178 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, 0 }, |
| 179 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, 0 }, |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 180 | { 0, 0 }, |
| 181 | }; |
| 182 | |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 183 | // SSLv3 matches everything that existed before TLS 1.2. |
| 184 | static const char kRule10[] = "AES128-SHA:AES128-SHA256:!SSLv3"; |
| 185 | |
| 186 | static const ExpectedCipher kExpected10[] = { |
| 187 | { TLS1_CK_RSA_WITH_AES_128_SHA256, 0 }, |
| 188 | { 0, 0 }, |
| 189 | }; |
| 190 | |
| 191 | // TLSv1.2 matches everything added in TLS 1.2. |
| 192 | static const char kRule11[] = "AES128-SHA:AES128-SHA256:!TLSv1.2"; |
| 193 | |
| 194 | static const ExpectedCipher kExpected11[] = { |
| 195 | { TLS1_CK_RSA_WITH_AES_128_SHA, 0 }, |
| 196 | { 0, 0 }, |
| 197 | }; |
| 198 | |
| 199 | // The two directives have no intersection. |
| 200 | static const char kRule12[] = "AES128-SHA:AES128-SHA256:!TLSv1.2+SSLv3"; |
| 201 | |
| 202 | static const ExpectedCipher kExpected12[] = { |
| 203 | { TLS1_CK_RSA_WITH_AES_128_SHA, 0 }, |
| 204 | { TLS1_CK_RSA_WITH_AES_128_SHA256, 0 }, |
| 205 | { 0, 0 }, |
| 206 | }; |
| 207 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 208 | static CipherTest kCipherTests[] = { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 209 | { kRule1, kExpected1 }, |
| 210 | { kRule2, kExpected2 }, |
| 211 | { kRule3, kExpected3 }, |
| 212 | { kRule4, kExpected4 }, |
| 213 | { kRule5, kExpected5 }, |
| 214 | { kRule6, kExpected6 }, |
| 215 | { kRule7, kExpected7 }, |
| 216 | { kRule8, kExpected8 }, |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 217 | { kRule9, kExpected9 }, |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 218 | { kRule10, kExpected10 }, |
| 219 | { kRule11, kExpected11 }, |
| 220 | { kRule12, kExpected12 }, |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 221 | { NULL, NULL }, |
| 222 | }; |
| 223 | |
| 224 | static const char *kBadRules[] = { |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 225 | // Invalid brackets. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 226 | "[ECDHE-RSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256", |
| 227 | "RSA]", |
| 228 | "[[RSA]]", |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 229 | // Operators inside brackets. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 230 | "[+RSA]", |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 231 | // Unknown directive. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 232 | "@BOGUS", |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 233 | // Empty cipher lists error at SSL_CTX_set_cipher_list. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 234 | "", |
| 235 | "BOGUS", |
David Benjamin | 32fbdf2 | 2015-04-07 01:14:06 -0400 | [diff] [blame] | 236 | // COMPLEMENTOFDEFAULT is empty. |
| 237 | "COMPLEMENTOFDEFAULT", |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 238 | // Invalid command. |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 239 | "?BAR", |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 240 | // Special operators are not allowed if groups are used. |
David Benjamin | 37d9246 | 2014-09-20 17:54:24 -0400 | [diff] [blame] | 241 | "[ECDHE-RSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256]:+FOO", |
| 242 | "[ECDHE-RSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256]:!FOO", |
| 243 | "[ECDHE-RSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256]:-FOO", |
| 244 | "[ECDHE-RSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256]:@STRENGTH", |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 245 | NULL, |
| 246 | }; |
| 247 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 248 | static const char *kMustNotIncludeNull[] = { |
| 249 | "ALL", |
| 250 | "DEFAULT", |
| 251 | "ALL:!eNULL", |
| 252 | "ALL:!NULL", |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame^] | 253 | "MEDIUM", |
| 254 | "HIGH", |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 255 | "FIPS", |
| 256 | "SHA", |
| 257 | "SHA1", |
| 258 | "RSA", |
| 259 | "SSLv3", |
| 260 | "TLSv1", |
| 261 | "TLSv1.2", |
| 262 | NULL |
| 263 | }; |
| 264 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 265 | static void PrintCipherPreferenceList(ssl_cipher_preference_list_st *list) { |
| 266 | bool in_group = false; |
| 267 | for (size_t i = 0; i < sk_SSL_CIPHER_num(list->ciphers); i++) { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 268 | const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(list->ciphers, i); |
| 269 | if (!in_group && list->in_group_flags[i]) { |
| 270 | fprintf(stderr, "\t[\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 271 | in_group = true; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 272 | } |
| 273 | fprintf(stderr, "\t"); |
| 274 | if (in_group) { |
| 275 | fprintf(stderr, " "); |
| 276 | } |
| 277 | fprintf(stderr, "%s\n", SSL_CIPHER_get_name(cipher)); |
| 278 | if (in_group && !list->in_group_flags[i]) { |
| 279 | fprintf(stderr, "\t]\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 280 | in_group = false; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 285 | static bool TestCipherRule(CipherTest *t) { |
| 286 | ScopedSSL_CTX ctx(SSL_CTX_new(TLS_method())); |
| 287 | if (!ctx) { |
| 288 | return false; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 289 | } |
| 290 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 291 | if (!SSL_CTX_set_cipher_list(ctx.get(), t->rule)) { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 292 | fprintf(stderr, "Error testing cipher rule '%s'\n", t->rule); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 293 | return false; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 294 | } |
| 295 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 296 | // Compare the two lists. |
| 297 | size_t i; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 298 | for (i = 0; i < sk_SSL_CIPHER_num(ctx->cipher_list->ciphers); i++) { |
| 299 | const SSL_CIPHER *cipher = |
| 300 | sk_SSL_CIPHER_value(ctx->cipher_list->ciphers, i); |
| 301 | if (t->expected[i].id != SSL_CIPHER_get_id(cipher) || |
| 302 | t->expected[i].in_group_flag != ctx->cipher_list->in_group_flags[i]) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 303 | fprintf(stderr, "Error: cipher rule '%s' evaluated to:\n", t->rule); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 304 | PrintCipherPreferenceList(ctx->cipher_list); |
| 305 | return false; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 309 | if (t->expected[i].id != 0) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 310 | fprintf(stderr, "Error: cipher rule '%s' evaluated to:\n", t->rule); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 311 | PrintCipherPreferenceList(ctx->cipher_list); |
| 312 | return false; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 313 | } |
| 314 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 315 | return true; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 318 | static bool TestRuleDoesNotIncludeNull(const char *rule) { |
| 319 | ScopedSSL_CTX ctx(SSL_CTX_new(SSLv23_server_method())); |
| 320 | if (!ctx) { |
| 321 | return false; |
| 322 | } |
| 323 | if (!SSL_CTX_set_cipher_list(ctx.get(), rule)) { |
| 324 | fprintf(stderr, "Error: cipher rule '%s' failed\n", rule); |
| 325 | return false; |
| 326 | } |
| 327 | for (size_t i = 0; i < sk_SSL_CIPHER_num(ctx->cipher_list->ciphers); i++) { |
| 328 | if (SSL_CIPHER_is_NULL(sk_SSL_CIPHER_value(ctx->cipher_list->ciphers, i))) { |
| 329 | fprintf(stderr, "Error: cipher rule '%s' includes NULL\n",rule); |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | return true; |
| 334 | } |
| 335 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 336 | static bool TestCipherRules() { |
| 337 | for (size_t i = 0; kCipherTests[i].rule != NULL; i++) { |
| 338 | if (!TestCipherRule(&kCipherTests[i])) { |
| 339 | return false; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 343 | for (size_t i = 0; kBadRules[i] != NULL; i++) { |
| 344 | ScopedSSL_CTX ctx(SSL_CTX_new(SSLv23_server_method())); |
| 345 | if (!ctx) { |
| 346 | return false; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 347 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 348 | if (SSL_CTX_set_cipher_list(ctx.get(), kBadRules[i])) { |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 349 | fprintf(stderr, "Cipher rule '%s' unexpectedly succeeded\n", kBadRules[i]); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 350 | return false; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 351 | } |
| 352 | ERR_clear_error(); |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 355 | for (size_t i = 0; kMustNotIncludeNull[i] != NULL; i++) { |
| 356 | if (!TestRuleDoesNotIncludeNull(kMustNotIncludeNull[i])) { |
| 357 | return false; |
| 358 | } |
| 359 | } |
| 360 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 361 | return true; |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 362 | } |
David Benjamin | 2e52121 | 2014-07-16 14:37:51 -0400 | [diff] [blame] | 363 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 364 | // kOpenSSLSession is a serialized SSL_SESSION generated from openssl |
| 365 | // s_client -sess_out. |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 366 | static const char kOpenSSLSession[] = |
David Benjamin | 688d8df | 2014-11-02 23:06:42 -0500 | [diff] [blame] | 367 | "MIIFpQIBAQICAwMEAsAvBCAG5Q1ndq4Yfmbeo1zwLkNRKmCXGdNgWvGT3cskV0yQ" |
| 368 | "kAQwJlrlzkAWBOWiLj/jJ76D7l+UXoizP2KI2C7I2FccqMmIfFmmkUy32nIJ0mZH" |
| 369 | "IWoJoQYCBFRDO46iBAICASyjggR6MIIEdjCCA16gAwIBAgIIK9dUvsPWSlUwDQYJ" |
| 370 | "KoZIhvcNAQEFBQAwSTELMAkGA1UEBhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMx" |
| 371 | "JTAjBgNVBAMTHEdvb2dsZSBJbnRlcm5ldCBBdXRob3JpdHkgRzIwHhcNMTQxMDA4" |
| 372 | "MTIwNzU3WhcNMTUwMTA2MDAwMDAwWjBoMQswCQYDVQQGEwJVU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b2dsZS5jb20vR0lBRzIuY3JsMA0GCSqGSIb3DQEBBQUAA4IBAQCa" |
| 388 | "OXCBdoqUy5bxyq+Wrh1zsyyCFim1PH5VU2+yvDSWrgDY8ibRGJmfff3r4Lud5kal" |
| 389 | "dKs9k8YlKD3ITG7P0YT/Rk8hLgfEuLcq5cc0xqmE42xJ+Eo2uzq9rYorc5emMCxf" |
| 390 | "5L0TJOXZqHQpOEcuptZQ4OjdYMfSxk5UzueUhA3ogZKRcRkdB3WeWRp+nYRhx4St" |
| 391 | "o2rt2A0MKmY9165GHUqMK9YaaXHDXqBu7Sefr1uSoAP9gyIJKeihMivsGqJ1TD6Z" |
| 392 | "cc6LMe+dN2P8cZEQHtD1y296ul4Mivqk3jatUVL8/hCwgch9A8O4PGZq9WqBfEWm" |
| 393 | "IyHh1dPtbg1lOXdYCWtjpAIEAKUDAgEUqQUCAwGJwKqBpwSBpBwUQvoeOk0Kg36S" |
| 394 | "YTcLEkXqKwOBfF9vE4KX0NxeLwjcDTpsuh3qXEaZ992r1N38VDcyS6P7I6HBYN9B" |
| 395 | "sNHM362zZnY27GpTw+Kwd751CLoXFPoaMOe57dbBpXoro6Pd3BTbf/Tzr88K06yE" |
| 396 | "OTDKPNj3+inbMaVigtK4PLyPq+Topyzvx9USFgRvyuoxn0Hgb+R0A3j6SLRuyOdA" |
| 397 | "i4gv7Y5oliyn"; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 398 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 399 | // kCustomSession is a custom serialized SSL_SESSION generated by |
| 400 | // filling in missing fields from |kOpenSSLSession|. This includes |
| 401 | // providing |peer_sha256|, so |peer| is not serialized. |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 402 | static const char kCustomSession[] = |
David Benjamin | 688d8df | 2014-11-02 23:06:42 -0500 | [diff] [blame] | 403 | "MIIBdgIBAQICAwMEAsAvBCAG5Q1ndq4Yfmbeo1zwLkNRKmCXGdNgWvGT3cskV0yQ" |
| 404 | "kAQwJlrlzkAWBOWiLj/jJ76D7l+UXoizP2KI2C7I2FccqMmIfFmmkUy32nIJ0mZH" |
| 405 | "IWoJoQYCBFRDO46iBAICASykAwQBAqUDAgEUphAEDnd3dy5nb29nbGUuY29tqAcE" |
| 406 | "BXdvcmxkqQUCAwGJwKqBpwSBpBwUQvoeOk0Kg36SYTcLEkXqKwOBfF9vE4KX0Nxe" |
| 407 | "LwjcDTpsuh3qXEaZ992r1N38VDcyS6P7I6HBYN9BsNHM362zZnY27GpTw+Kwd751" |
| 408 | "CLoXFPoaMOe57dbBpXoro6Pd3BTbf/Tzr88K06yEOTDKPNj3+inbMaVigtK4PLyP" |
| 409 | "q+Topyzvx9USFgRvyuoxn0Hgb+R0A3j6SLRuyOdAi4gv7Y5oliynrSIEIAYGBgYG" |
| 410 | "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGrgMEAQevAwQBBLADBAEF"; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 411 | |
David Benjamin | 26416e9 | 2015-08-22 16:04:17 -0400 | [diff] [blame] | 412 | // kBoringSSLSession is a serialized SSL_SESSION generated from bssl client. |
| 413 | static const char kBoringSSLSession[] = |
| 414 | "MIIRwQIBAQICAwMEAsAvBCDdoGxGK26mR+8lM0uq6+k9xYuxPnwAjpcF9n0Yli9R" |
| 415 | "kQQwbyshfWhdi5XQ1++7n2L1qqrcVlmHBPpr6yknT/u4pUrpQB5FZ7vqvNn8MdHf" |
| 416 | "9rWgoQYCBFXgs7uiBAICHCCjggR6MIIEdjCCA16gAwIBAgIIf+yfD7Y6UicwDQYJ" |
| 417 | "KoZIhvcNAQELBQAwSTELMAkGA1UEBhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMx" |
| 418 | "JTAjBgNVBAMTHEdvb2dsZSBJbnRlcm5ldCBBdXRob3JpdHkgRzIwHhcNMTUwODE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| "MDAwMDAwWjBoMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG" |
| 449 | "A1UEBwwNTW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEXMBUGA1UE" |
| 450 | "AwwOd3d3Lmdvb2dsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB" |
| 451 | "AQC0MeG5YGQ0t+IeJeoneP/PrhEaieibeKYkbKVLNZpoPLuBinvhkXZo3DC133Np" |
| 452 | "CBpy6ZktBwamqyixAyuk/NU6OjgXqwwxfQ7di1AInLIU792c7hFyNXSUCG7At8If" |
| 453 | "i3YwBX9Ba6u/1d6rWTGZJrdCq3QU11RkKYyTq2KT5mceTv9iGKqSkSTlp8puy/9S" |
| 454 | "Z/3DbU3U+BuqCFqeSlz7zjwFmk35acdCilpJlVDDN5C/RCh8/UKc8PaL+cxlt531" |
| 455 | "qoTENvYrflBno14YEZlCBZsPiFeUSILpKEj3Ccwhy0eLEucWQ72YZU8mUzXBoXGn" |
| 456 | "0zA0crFl5ci/2sTBBGZsylNBAgMBAAGjggFBMIIBPTAdBgNVHSUEFjAUBggrBgEF" |
| 457 | "BQcDAQYIKwYBBQUHAwIwGQYDVR0RBBIwEIIOd3d3Lmdvb2dsZS5jb20waAYIKwYB" |
| 458 | "BQUHAQEEXDBaMCsGCCsGAQUFBzAChh9odHRwOi8vcGtpLmdvb2dsZS5jb20vR0lB" |
| 459 | "RzIuY3J0MCsGCCsGAQUFBzABhh9odHRwOi8vY2xpZW50czEuZ29vZ2xlLmNvbS9v" |
| 460 | "Y3NwMB0GA1UdDgQWBBS/bzHxcE73Q4j3slC4BLbMtLjGGjAMBgNVHRMBAf8EAjAA" |
| 461 | "MB8GA1UdIwQYMBaAFErdBhYbvPZotXb1gba7Yhq6WoEvMBcGA1UdIAQQMA4wDAYK" |
| 462 | "KwYBBAHWeQIFATAwBgNVHR8EKTAnMCWgI6Ahhh9odHRwOi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ZYR/Nnag+YyuENWllhMgZxUYi+FOVvuOAShDGKuy6lyARxzmZ" |
| 478 | "EASg8GF6lSWMTlJ14rbtCMoU/M4iarNOz0YDl5cDfsCx3nuvRTPPuj5xt970JSXC" |
| 479 | "DTWJnZ37DhF5iR43xa+OcmkCAwEAAaOB5zCB5DAfBgNVHSMEGDAWgBTAephojYn7" |
| 480 | "qwVkDBF9qn1luMrMTjAdBgNVHQ4EFgQUSt0GFhu89mi1dvWBtrtiGrpagS8wDgYD" |
| 481 | "VR0PAQH/BAQDAgEGMC4GCCsGAQUFBwEBBCIwIDAeBggrBgEFBQcwAYYSaHR0cDov" |
| 482 | "L2cuc3ltY2QuY29tMBIGA1UdEwEB/wQIMAYBAf8CAQAwNQYDVR0fBC4wLDAqoCig" |
| 483 | "JoYkaHR0cDovL2cuc3ltY2IuY29tL2NybHMvZ3RnbG9iYWwuY3JsMBcGA1UdIAQQ" |
| 484 | "MA4wDAYKKwYBBAHWeQIFATANBgkqhkiG9w0BAQsFAAOCAQEAqvqpIM1qZ4PtXtR+" |
| 485 | "3h3Ef+AlBgDFJPupyC1tft6dgmUsgWM0Zj7pUsIItMsv91+ZOmqcUHqFBYx90SpI" |
| 486 | "hNMJbHzCzTWf84LuUt5oX+QAihcglvcpjZpNy6jehsgNb1aHA30DP9z6eX0hGfnI" |
| 487 | "Oi9RdozHQZJxjyXON/hKTAAj78Q1EK7gI4BzfE00LshukNYQHpmEcxpw8u1VDu4X" |
| 488 | "Bupn7jLrLN1nBz/2i8Jw3lsA5rsb0zYaImxssDVCbJAJPZPpZAkiDoUGn8JzIdPm" |
| 489 | "X4DkjYUiOnMDsWCOrmji9D6X52ASCWg23jrW4kOVWzeBkoEfu43XrVJkFleW2V40" |
| 490 | "fsg12DCCA30wggLmoAMCAQICAxK75jANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQG" |
| 491 | "EwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUg" |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rKBCM/wCMfHcX5m7sLt1Dsf//DwyE7WQziwuTB9GNBV" |
| 507 | "g6JqyzYRnOhIZqNtf7gT1Ef+i1pcc/yu2RsyGTirlzQUqpbS66McFAhJtrvlke+D" |
| 508 | "NusdVm/K2rxzY5Dkf3s+Iss9B+1fOHSc4wNQTqGvmO5h8oQ/Eg=="; |
| 509 | |
David Benjamin | f297e02 | 2015-05-28 19:55:29 -0400 | [diff] [blame] | 510 | // kBadSessionExtraField is a custom serialized SSL_SESSION generated by replacing |
| 511 | // the final (optional) element of |kCustomSession| with tag number 30. |
| 512 | static const char kBadSessionExtraField[] = |
| 513 | "MIIBdgIBAQICAwMEAsAvBCAG5Q1ndq4Yfmbeo1zwLkNRKmCXGdNgWvGT3cskV0yQ" |
| 514 | "kAQwJlrlzkAWBOWiLj/jJ76D7l+UXoizP2KI2C7I2FccqMmIfFmmkUy32nIJ0mZH" |
| 515 | "IWoJoQYCBFRDO46iBAICASykAwQBAqUDAgEUphAEDnd3dy5nb29nbGUuY29tqAcE" |
| 516 | "BXdvcmxkqQUCAwGJwKqBpwSBpBwUQvoeOk0Kg36SYTcLEkXqKwOBfF9vE4KX0Nxe" |
| 517 | "LwjcDTpsuh3qXEaZ992r1N38VDcyS6P7I6HBYN9BsNHM362zZnY27GpTw+Kwd751" |
| 518 | "CLoXFPoaMOe57dbBpXoro6Pd3BTbf/Tzr88K06yEOTDKPNj3+inbMaVigtK4PLyP" |
| 519 | "q+Topyzvx9USFgRvyuoxn0Hgb+R0A3j6SLRuyOdAi4gv7Y5oliynrSIEIAYGBgYG" |
| 520 | "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGrgMEAQevAwQBBL4DBAEF"; |
| 521 | |
David Benjamin | 338e067 | 2015-05-28 20:00:08 -0400 | [diff] [blame] | 522 | // kBadSessionVersion is a custom serialized SSL_SESSION generated by replacing |
| 523 | // the version of |kCustomSession| with 2. |
| 524 | static const char kBadSessionVersion[] = |
| 525 | "MIIBdgIBAgICAwMEAsAvBCAG5Q1ndq4Yfmbeo1zwLkNRKmCXGdNgWvGT3cskV0yQ" |
| 526 | "kAQwJlrlzkAWBOWiLj/jJ76D7l+UXoizP2KI2C7I2FccqMmIfFmmkUy32nIJ0mZH" |
| 527 | "IWoJoQYCBFRDO46iBAICASykAwQBAqUDAgEUphAEDnd3dy5nb29nbGUuY29tqAcE" |
| 528 | "BXdvcmxkqQUCAwGJwKqBpwSBpBwUQvoeOk0Kg36SYTcLEkXqKwOBfF9vE4KX0Nxe" |
| 529 | "LwjcDTpsuh3qXEaZ992r1N38VDcyS6P7I6HBYN9BsNHM362zZnY27GpTw+Kwd751" |
| 530 | "CLoXFPoaMOe57dbBpXoro6Pd3BTbf/Tzr88K06yEOTDKPNj3+inbMaVigtK4PLyP" |
| 531 | "q+Topyzvx9USFgRvyuoxn0Hgb+R0A3j6SLRuyOdAi4gv7Y5oliynrSIEIAYGBgYG" |
| 532 | "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGrgMEAQevAwQBBLADBAEF"; |
| 533 | |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 534 | // kBadSessionTrailingData is a custom serialized SSL_SESSION with trailing data |
| 535 | // appended. |
| 536 | static const char kBadSessionTrailingData[] = |
| 537 | "MIIBdgIBAQICAwMEAsAvBCAG5Q1ndq4Yfmbeo1zwLkNRKmCXGdNgWvGT3cskV0yQ" |
| 538 | "kAQwJlrlzkAWBOWiLj/jJ76D7l+UXoizP2KI2C7I2FccqMmIfFmmkUy32nIJ0mZH" |
| 539 | "IWoJoQYCBFRDO46iBAICASykAwQBAqUDAgEUphAEDnd3dy5nb29nbGUuY29tqAcE" |
| 540 | "BXdvcmxkqQUCAwGJwKqBpwSBpBwUQvoeOk0Kg36SYTcLEkXqKwOBfF9vE4KX0Nxe" |
| 541 | "LwjcDTpsuh3qXEaZ992r1N38VDcyS6P7I6HBYN9BsNHM362zZnY27GpTw+Kwd751" |
| 542 | "CLoXFPoaMOe57dbBpXoro6Pd3BTbf/Tzr88K06yEOTDKPNj3+inbMaVigtK4PLyP" |
| 543 | "q+Topyzvx9USFgRvyuoxn0Hgb+R0A3j6SLRuyOdAi4gv7Y5oliynrSIEIAYGBgYG" |
| 544 | "BgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGrgMEAQevAwQBBLADBAEFAAAA"; |
| 545 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 546 | static bool DecodeBase64(std::vector<uint8_t> *out, const char *in) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 547 | size_t len; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 548 | if (!EVP_DecodedLength(&len, strlen(in))) { |
| 549 | fprintf(stderr, "EVP_DecodedLength failed\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 550 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 551 | } |
| 552 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 553 | out->resize(len); |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 554 | if (!EVP_DecodeBase64(out->data(), &len, len, (const uint8_t *)in, |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 555 | strlen(in))) { |
| 556 | fprintf(stderr, "EVP_DecodeBase64 failed\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 557 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 558 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 559 | out->resize(len); |
| 560 | return true; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 561 | } |
| 562 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 563 | static bool TestSSL_SESSIONEncoding(const char *input_b64) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 564 | const uint8_t *cptr; |
| 565 | uint8_t *ptr; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 566 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 567 | // Decode the input. |
| 568 | std::vector<uint8_t> input; |
| 569 | if (!DecodeBase64(&input, input_b64)) { |
| 570 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 571 | } |
| 572 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 573 | // Verify the SSL_SESSION decodes. |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 574 | ScopedSSL_SESSION session(SSL_SESSION_from_bytes(input.data(), input.size())); |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 575 | if (!session) { |
| 576 | fprintf(stderr, "SSL_SESSION_from_bytes failed\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 577 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 578 | } |
| 579 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 580 | // Verify the SSL_SESSION encoding round-trips. |
| 581 | size_t encoded_len; |
| 582 | ScopedOpenSSLBytes encoded; |
| 583 | uint8_t *encoded_raw; |
| 584 | if (!SSL_SESSION_to_bytes(session.get(), &encoded_raw, &encoded_len)) { |
David Benjamin | 3cac450 | 2014-10-21 01:46:30 -0400 | [diff] [blame] | 585 | fprintf(stderr, "SSL_SESSION_to_bytes failed\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 586 | return false; |
David Benjamin | 3cac450 | 2014-10-21 01:46:30 -0400 | [diff] [blame] | 587 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 588 | encoded.reset(encoded_raw); |
| 589 | if (encoded_len != input.size() || |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 590 | memcmp(input.data(), encoded.get(), input.size()) != 0) { |
David Benjamin | 3cac450 | 2014-10-21 01:46:30 -0400 | [diff] [blame] | 591 | fprintf(stderr, "SSL_SESSION_to_bytes did not round-trip\n"); |
Sigbjorn Vik | 2b23d24 | 2015-06-29 15:07:26 +0200 | [diff] [blame] | 592 | hexdump(stderr, "Before: ", input.data(), input.size()); |
| 593 | hexdump(stderr, "After: ", encoded_raw, encoded_len); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 594 | return false; |
David Benjamin | 3cac450 | 2014-10-21 01:46:30 -0400 | [diff] [blame] | 595 | } |
David Benjamin | 3cac450 | 2014-10-21 01:46:30 -0400 | [diff] [blame] | 596 | |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 597 | // Verify the SSL_SESSION also decodes with the legacy API. |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 598 | cptr = input.data(); |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 599 | session.reset(d2i_SSL_SESSION(NULL, &cptr, input.size())); |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 600 | if (!session || cptr != input.data() + input.size()) { |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 601 | fprintf(stderr, "d2i_SSL_SESSION failed\n"); |
| 602 | return false; |
| 603 | } |
| 604 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 605 | // Verify the SSL_SESSION encoding round-trips via the legacy API. |
| 606 | int len = i2d_SSL_SESSION(session.get(), NULL); |
| 607 | if (len < 0 || (size_t)len != input.size()) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 608 | fprintf(stderr, "i2d_SSL_SESSION(NULL) returned invalid length\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 609 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 610 | } |
| 611 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 612 | encoded.reset((uint8_t *)OPENSSL_malloc(input.size())); |
| 613 | if (!encoded) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 614 | fprintf(stderr, "malloc failed\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 615 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 616 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 617 | |
| 618 | ptr = encoded.get(); |
| 619 | len = i2d_SSL_SESSION(session.get(), &ptr); |
| 620 | if (len < 0 || (size_t)len != input.size()) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 621 | fprintf(stderr, "i2d_SSL_SESSION returned invalid length\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 622 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 623 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 624 | if (ptr != encoded.get() + input.size()) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 625 | fprintf(stderr, "i2d_SSL_SESSION did not advance ptr correctly\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 626 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 627 | } |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 628 | if (memcmp(input.data(), encoded.get(), input.size()) != 0) { |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 629 | fprintf(stderr, "i2d_SSL_SESSION did not round-trip\n"); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 630 | return false; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 631 | } |
| 632 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 633 | return true; |
David Benjamin | 751e889 | 2014-10-19 00:59:36 -0400 | [diff] [blame] | 634 | } |
| 635 | |
David Benjamin | f297e02 | 2015-05-28 19:55:29 -0400 | [diff] [blame] | 636 | static bool TestBadSSL_SESSIONEncoding(const char *input_b64) { |
| 637 | std::vector<uint8_t> input; |
| 638 | if (!DecodeBase64(&input, input_b64)) { |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | // Verify that the SSL_SESSION fails to decode. |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 643 | ScopedSSL_SESSION session(SSL_SESSION_from_bytes(input.data(), input.size())); |
David Benjamin | f297e02 | 2015-05-28 19:55:29 -0400 | [diff] [blame] | 644 | if (session) { |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 645 | fprintf(stderr, "SSL_SESSION_from_bytes unexpectedly succeeded\n"); |
David Benjamin | f297e02 | 2015-05-28 19:55:29 -0400 | [diff] [blame] | 646 | return false; |
| 647 | } |
| 648 | ERR_clear_error(); |
| 649 | return true; |
| 650 | } |
| 651 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 652 | static bool TestDefaultVersion(uint16_t version, |
| 653 | const SSL_METHOD *(*method)(void)) { |
| 654 | ScopedSSL_CTX ctx(SSL_CTX_new(method())); |
| 655 | if (!ctx) { |
| 656 | return false; |
David Benjamin | 82c9e90 | 2014-12-12 15:55:27 -0500 | [diff] [blame] | 657 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 658 | return ctx->min_version == version && ctx->max_version == version; |
David Benjamin | 82c9e90 | 2014-12-12 15:55:27 -0500 | [diff] [blame] | 659 | } |
| 660 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 661 | static bool CipherGetRFCName(std::string *out, uint16_t value) { |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 662 | const SSL_CIPHER *cipher = SSL_get_cipher_by_value(value); |
| 663 | if (cipher == NULL) { |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 664 | return false; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 665 | } |
David Benjamin | 67be048 | 2015-04-20 16:19:00 -0400 | [diff] [blame] | 666 | ScopedOpenSSLString rfc_name(SSL_CIPHER_get_rfc_name(cipher)); |
David Benjamin | 3fa65f0 | 2015-05-15 19:11:57 -0400 | [diff] [blame] | 667 | if (!rfc_name) { |
| 668 | return false; |
| 669 | } |
David Benjamin | 67be048 | 2015-04-20 16:19:00 -0400 | [diff] [blame] | 670 | out->assign(rfc_name.get()); |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 671 | return true; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | typedef struct { |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 675 | int id; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 676 | const char *rfc_name; |
| 677 | } CIPHER_RFC_NAME_TEST; |
| 678 | |
| 679 | static const CIPHER_RFC_NAME_TEST kCipherRFCNameTests[] = { |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 680 | { SSL3_CK_RSA_DES_192_CBC3_SHA, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" }, |
| 681 | { SSL3_CK_RSA_RC4_128_MD5, "TLS_RSA_WITH_RC4_MD5" }, |
| 682 | { TLS1_CK_RSA_WITH_AES_128_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA" }, |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 683 | { TLS1_CK_DHE_RSA_WITH_AES_256_SHA, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" }, |
| 684 | { TLS1_CK_DHE_RSA_WITH_AES_256_SHA256, |
| 685 | "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" }, |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 686 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256, |
| 687 | "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" }, |
| 688 | { TLS1_CK_ECDHE_RSA_WITH_AES_256_SHA384, |
| 689 | "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" }, |
| 690 | { TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 691 | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" }, |
| 692 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 693 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" }, |
| 694 | { TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
| 695 | "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" }, |
| 696 | { TLS1_CK_PSK_WITH_RC4_128_SHA, "TLS_PSK_WITH_RC4_SHA" }, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 697 | { TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
| 698 | "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" }, |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 699 | // These names are non-standard: |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 700 | { TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD, |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 701 | "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" }, |
Brian Smith | 271777f | 2015-10-03 13:53:33 -1000 | [diff] [blame] | 702 | { TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD, |
David Benjamin | 2bdb35c | 2015-02-21 11:03:06 -0500 | [diff] [blame] | 703 | "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" }, |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 704 | }; |
| 705 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 706 | static bool TestCipherGetRFCName(void) { |
| 707 | for (size_t i = 0; |
| 708 | i < sizeof(kCipherRFCNameTests) / sizeof(kCipherRFCNameTests[0]); i++) { |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 709 | const CIPHER_RFC_NAME_TEST *test = &kCipherRFCNameTests[i]; |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 710 | std::string rfc_name; |
| 711 | if (!CipherGetRFCName(&rfc_name, test->id & 0xffff)) { |
| 712 | fprintf(stderr, "SSL_CIPHER_get_rfc_name failed\n"); |
| 713 | return false; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 714 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 715 | if (rfc_name != test->rfc_name) { |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 716 | fprintf(stderr, "SSL_CIPHER_get_rfc_name: got '%s', wanted '%s'\n", |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 717 | rfc_name.c_str(), test->rfc_name); |
| 718 | return false; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 719 | } |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 720 | } |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 721 | return true; |
David Benjamin | 6522625 | 2015-02-05 16:49:47 -0500 | [diff] [blame] | 722 | } |
| 723 | |
David Benjamin | 422fe08 | 2015-07-21 22:03:43 -0400 | [diff] [blame] | 724 | // CreateSessionWithTicket returns a sample |SSL_SESSION| with the ticket |
| 725 | // replaced for one of length |ticket_len| or nullptr on failure. |
| 726 | static ScopedSSL_SESSION CreateSessionWithTicket(size_t ticket_len) { |
| 727 | std::vector<uint8_t> der; |
| 728 | if (!DecodeBase64(&der, kOpenSSLSession)) { |
| 729 | return nullptr; |
| 730 | } |
David Benjamin | ef14b2d | 2015-11-11 14:01:27 -0800 | [diff] [blame] | 731 | ScopedSSL_SESSION session(SSL_SESSION_from_bytes(der.data(), der.size())); |
David Benjamin | 422fe08 | 2015-07-21 22:03:43 -0400 | [diff] [blame] | 732 | if (!session) { |
| 733 | return nullptr; |
| 734 | } |
| 735 | |
| 736 | // Swap out the ticket for a garbage one. |
| 737 | OPENSSL_free(session->tlsext_tick); |
| 738 | session->tlsext_tick = reinterpret_cast<uint8_t*>(OPENSSL_malloc(ticket_len)); |
| 739 | if (session->tlsext_tick == nullptr) { |
| 740 | return nullptr; |
| 741 | } |
| 742 | memset(session->tlsext_tick, 'a', ticket_len); |
| 743 | session->tlsext_ticklen = ticket_len; |
David Benjamin | 1269ddd | 2015-10-18 15:18:55 -0400 | [diff] [blame] | 744 | |
| 745 | // Fix up the timeout. |
| 746 | session->time = time(NULL); |
David Benjamin | 422fe08 | 2015-07-21 22:03:43 -0400 | [diff] [blame] | 747 | return session; |
| 748 | } |
| 749 | |
| 750 | // GetClientHelloLen creates a client SSL connection with a ticket of length |
| 751 | // |ticket_len| and records the ClientHello. It returns the length of the |
| 752 | // ClientHello, not including the record header, on success and zero on error. |
| 753 | static size_t GetClientHelloLen(size_t ticket_len) { |
| 754 | ScopedSSL_CTX ctx(SSL_CTX_new(TLS_method())); |
| 755 | ScopedSSL_SESSION session = CreateSessionWithTicket(ticket_len); |
| 756 | if (!ctx || !session) { |
| 757 | return 0; |
| 758 | } |
| 759 | ScopedSSL ssl(SSL_new(ctx.get())); |
| 760 | ScopedBIO bio(BIO_new(BIO_s_mem())); |
| 761 | if (!ssl || !bio || !SSL_set_session(ssl.get(), session.get())) { |
| 762 | return 0; |
| 763 | } |
| 764 | // Do not configure a reading BIO, but record what's written to a memory BIO. |
| 765 | SSL_set_bio(ssl.get(), nullptr /* rbio */, BIO_up_ref(bio.get())); |
| 766 | int ret = SSL_connect(ssl.get()); |
| 767 | if (ret > 0) { |
| 768 | // SSL_connect should fail without a BIO to write to. |
| 769 | return 0; |
| 770 | } |
| 771 | ERR_clear_error(); |
| 772 | |
| 773 | const uint8_t *unused; |
| 774 | size_t client_hello_len; |
| 775 | if (!BIO_mem_contents(bio.get(), &unused, &client_hello_len) || |
| 776 | client_hello_len <= SSL3_RT_HEADER_LENGTH) { |
| 777 | return 0; |
| 778 | } |
| 779 | return client_hello_len - SSL3_RT_HEADER_LENGTH; |
| 780 | } |
| 781 | |
| 782 | struct PaddingTest { |
| 783 | size_t input_len, padded_len; |
| 784 | }; |
| 785 | |
| 786 | static const PaddingTest kPaddingTests[] = { |
| 787 | // ClientHellos of length below 0x100 do not require padding. |
| 788 | {0xfe, 0xfe}, |
| 789 | {0xff, 0xff}, |
| 790 | // ClientHellos of length 0x100 through 0x1fb are padded up to 0x200. |
| 791 | {0x100, 0x200}, |
| 792 | {0x123, 0x200}, |
| 793 | {0x1fb, 0x200}, |
| 794 | // ClientHellos of length 0x1fc through 0x1ff get padded beyond 0x200. The |
| 795 | // padding extension takes a minimum of four bytes plus one required content |
| 796 | // byte. (To work around yet more server bugs, we avoid empty final |
| 797 | // extensions.) |
| 798 | {0x1fc, 0x201}, |
| 799 | {0x1fd, 0x202}, |
| 800 | {0x1fe, 0x203}, |
| 801 | {0x1ff, 0x204}, |
| 802 | // Finally, larger ClientHellos need no padding. |
| 803 | {0x200, 0x200}, |
| 804 | {0x201, 0x201}, |
| 805 | }; |
| 806 | |
| 807 | static bool TestPaddingExtension() { |
| 808 | // Sample a baseline length. |
| 809 | size_t base_len = GetClientHelloLen(1); |
| 810 | if (base_len == 0) { |
| 811 | return false; |
| 812 | } |
| 813 | |
| 814 | for (const PaddingTest &test : kPaddingTests) { |
| 815 | if (base_len > test.input_len) { |
| 816 | fprintf(stderr, "Baseline ClientHello too long.\n"); |
| 817 | return false; |
| 818 | } |
| 819 | |
| 820 | size_t padded_len = GetClientHelloLen(1 + test.input_len - base_len); |
| 821 | if (padded_len != test.padded_len) { |
| 822 | fprintf(stderr, "%u-byte ClientHello padded to %u bytes, not %u.\n", |
| 823 | static_cast<unsigned>(test.input_len), |
| 824 | static_cast<unsigned>(padded_len), |
| 825 | static_cast<unsigned>(test.padded_len)); |
| 826 | return false; |
| 827 | } |
| 828 | } |
| 829 | return true; |
| 830 | } |
| 831 | |
David Benjamin | 1d128f3 | 2015-09-08 17:41:40 -0400 | [diff] [blame] | 832 | // Test that |SSL_get_client_CA_list| echoes back the configured parameter even |
| 833 | // before configuring as a server. |
| 834 | static bool TestClientCAList() { |
| 835 | ScopedSSL_CTX ctx(SSL_CTX_new(TLS_method())); |
| 836 | if (!ctx) { |
| 837 | return false; |
| 838 | } |
| 839 | ScopedSSL ssl(SSL_new(ctx.get())); |
| 840 | if (!ssl) { |
| 841 | return false; |
| 842 | } |
| 843 | |
| 844 | STACK_OF(X509_NAME) *stack = sk_X509_NAME_new_null(); |
| 845 | if (stack == nullptr) { |
| 846 | return false; |
| 847 | } |
| 848 | // |SSL_set_client_CA_list| takes ownership. |
| 849 | SSL_set_client_CA_list(ssl.get(), stack); |
| 850 | |
| 851 | return SSL_get_client_CA_list(ssl.get()) == stack; |
| 852 | } |
| 853 | |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 854 | static void AppendSession(SSL_SESSION *session, void *arg) { |
| 855 | std::vector<SSL_SESSION*> *out = |
| 856 | reinterpret_cast<std::vector<SSL_SESSION*>*>(arg); |
| 857 | out->push_back(session); |
| 858 | } |
| 859 | |
| 860 | // ExpectCache returns true if |ctx|'s session cache consists of |expected|, in |
| 861 | // order. |
| 862 | static bool ExpectCache(SSL_CTX *ctx, |
| 863 | const std::vector<SSL_SESSION*> &expected) { |
| 864 | // Check the linked list. |
| 865 | SSL_SESSION *ptr = ctx->session_cache_head; |
| 866 | for (SSL_SESSION *session : expected) { |
| 867 | if (ptr != session) { |
| 868 | return false; |
| 869 | } |
| 870 | // TODO(davidben): This is an absurd way to denote the end of the list. |
| 871 | if (ptr->next == |
| 872 | reinterpret_cast<SSL_SESSION *>(&ctx->session_cache_tail)) { |
| 873 | ptr = nullptr; |
| 874 | } else { |
| 875 | ptr = ptr->next; |
| 876 | } |
| 877 | } |
| 878 | if (ptr != nullptr) { |
| 879 | return false; |
| 880 | } |
| 881 | |
| 882 | // Check the hash table. |
| 883 | std::vector<SSL_SESSION*> actual, expected_copy; |
| 884 | lh_SSL_SESSION_doall_arg(SSL_CTX_sessions(ctx), AppendSession, &actual); |
| 885 | expected_copy = expected; |
| 886 | |
| 887 | std::sort(actual.begin(), actual.end()); |
| 888 | std::sort(expected_copy.begin(), expected_copy.end()); |
| 889 | |
| 890 | return actual == expected_copy; |
| 891 | } |
| 892 | |
| 893 | static ScopedSSL_SESSION CreateTestSession(uint32_t number) { |
| 894 | ScopedSSL_SESSION ret(SSL_SESSION_new()); |
| 895 | if (!ret) { |
| 896 | return nullptr; |
| 897 | } |
| 898 | |
| 899 | ret->session_id_length = SSL3_SSL_SESSION_ID_LENGTH; |
| 900 | memset(ret->session_id, 0, ret->session_id_length); |
| 901 | memcpy(ret->session_id, &number, sizeof(number)); |
| 902 | return ret; |
| 903 | } |
| 904 | |
| 905 | // TODO(davidben): Switch this to a |std::vector<ScopedSSL_SESSION>| once we can |
| 906 | // rely on a move-aware |std::vector|. |
David Benjamin | 0a870c2 | 2015-10-26 15:45:39 -0400 | [diff] [blame] | 907 | class ScopedSessionVector { |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 908 | public: |
David Benjamin | 0a870c2 | 2015-10-26 15:45:39 -0400 | [diff] [blame] | 909 | explicit ScopedSessionVector(std::vector<SSL_SESSION*> *sessions) |
| 910 | : sessions_(sessions) {} |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 911 | |
David Benjamin | 0a870c2 | 2015-10-26 15:45:39 -0400 | [diff] [blame] | 912 | ~ScopedSessionVector() { |
| 913 | for (SSL_SESSION *session : *sessions_) { |
| 914 | SSL_SESSION_free(session); |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
| 918 | private: |
David Benjamin | 0a870c2 | 2015-10-26 15:45:39 -0400 | [diff] [blame] | 919 | std::vector<SSL_SESSION*> *const sessions_; |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 920 | }; |
| 921 | |
| 922 | // Test that the internal session cache behaves as expected. |
| 923 | static bool TestInternalSessionCache() { |
| 924 | ScopedSSL_CTX ctx(SSL_CTX_new(TLS_method())); |
| 925 | if (!ctx) { |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | // Prepare 10 test sessions. |
| 930 | std::vector<SSL_SESSION*> sessions; |
David Benjamin | 0a870c2 | 2015-10-26 15:45:39 -0400 | [diff] [blame] | 931 | ScopedSessionVector cleanup(&sessions); |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 932 | for (int i = 0; i < 10; i++) { |
| 933 | ScopedSSL_SESSION session = CreateTestSession(i); |
| 934 | if (!session) { |
| 935 | return false; |
| 936 | } |
| 937 | sessions.push_back(session.release()); |
| 938 | } |
| 939 | |
| 940 | SSL_CTX_sess_set_cache_size(ctx.get(), 5); |
| 941 | |
| 942 | // Insert all the test sessions. |
| 943 | for (SSL_SESSION *session : sessions) { |
| 944 | if (!SSL_CTX_add_session(ctx.get(), session)) { |
| 945 | return false; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | // Only the last five should be in the list. |
| 950 | std::vector<SSL_SESSION*> expected; |
| 951 | expected.push_back(sessions[9]); |
| 952 | expected.push_back(sessions[8]); |
| 953 | expected.push_back(sessions[7]); |
| 954 | expected.push_back(sessions[6]); |
| 955 | expected.push_back(sessions[5]); |
| 956 | if (!ExpectCache(ctx.get(), expected)) { |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | // Inserting an element already in the cache should fail. |
| 961 | if (SSL_CTX_add_session(ctx.get(), sessions[7]) || |
| 962 | !ExpectCache(ctx.get(), expected)) { |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | // Although collisions should be impossible (256-bit session IDs), the cache |
| 967 | // must handle them gracefully. |
| 968 | ScopedSSL_SESSION collision(CreateTestSession(7)); |
| 969 | if (!collision || !SSL_CTX_add_session(ctx.get(), collision.get())) { |
| 970 | return false; |
| 971 | } |
| 972 | expected.clear(); |
| 973 | expected.push_back(collision.get()); |
| 974 | expected.push_back(sessions[9]); |
| 975 | expected.push_back(sessions[8]); |
| 976 | expected.push_back(sessions[6]); |
| 977 | expected.push_back(sessions[5]); |
| 978 | if (!ExpectCache(ctx.get(), expected)) { |
| 979 | return false; |
| 980 | } |
| 981 | |
| 982 | // Removing sessions behaves correctly. |
| 983 | if (!SSL_CTX_remove_session(ctx.get(), sessions[6])) { |
| 984 | return false; |
| 985 | } |
| 986 | expected.clear(); |
| 987 | expected.push_back(collision.get()); |
| 988 | expected.push_back(sessions[9]); |
| 989 | expected.push_back(sessions[8]); |
| 990 | expected.push_back(sessions[5]); |
| 991 | if (!ExpectCache(ctx.get(), expected)) { |
| 992 | return false; |
| 993 | } |
| 994 | |
| 995 | // Removing sessions requires an exact match. |
| 996 | if (SSL_CTX_remove_session(ctx.get(), sessions[0]) || |
| 997 | SSL_CTX_remove_session(ctx.get(), sessions[7]) || |
| 998 | !ExpectCache(ctx.get(), expected)) { |
| 999 | return false; |
| 1000 | } |
| 1001 | |
| 1002 | return true; |
| 1003 | } |
| 1004 | |
David Benjamin | 1d128f3 | 2015-09-08 17:41:40 -0400 | [diff] [blame] | 1005 | int main() { |
David Benjamin | 7a1eefd | 2015-10-17 23:39:22 -0400 | [diff] [blame] | 1006 | CRYPTO_library_init(); |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 1007 | |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 1008 | if (!TestCipherRules() || |
| 1009 | !TestSSL_SESSIONEncoding(kOpenSSLSession) || |
| 1010 | !TestSSL_SESSIONEncoding(kCustomSession) || |
David Benjamin | 26416e9 | 2015-08-22 16:04:17 -0400 | [diff] [blame] | 1011 | !TestSSL_SESSIONEncoding(kBoringSSLSession) || |
David Benjamin | f297e02 | 2015-05-28 19:55:29 -0400 | [diff] [blame] | 1012 | !TestBadSSL_SESSIONEncoding(kBadSessionExtraField) || |
David Benjamin | 338e067 | 2015-05-28 20:00:08 -0400 | [diff] [blame] | 1013 | !TestBadSSL_SESSIONEncoding(kBadSessionVersion) || |
David Benjamin | fd67aa8 | 2015-06-15 19:41:48 -0400 | [diff] [blame] | 1014 | !TestBadSSL_SESSIONEncoding(kBadSessionTrailingData) || |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 1015 | !TestDefaultVersion(0, &TLS_method) || |
| 1016 | !TestDefaultVersion(SSL3_VERSION, &SSLv3_method) || |
| 1017 | !TestDefaultVersion(TLS1_VERSION, &TLSv1_method) || |
| 1018 | !TestDefaultVersion(TLS1_1_VERSION, &TLSv1_1_method) || |
David Benjamin | 6879373 | 2015-05-04 20:20:48 -0400 | [diff] [blame] | 1019 | !TestDefaultVersion(TLS1_2_VERSION, &TLSv1_2_method) || |
David Benjamin | 1d77e56 | 2015-03-22 17:22:08 -0400 | [diff] [blame] | 1020 | !TestDefaultVersion(0, &DTLS_method) || |
| 1021 | !TestDefaultVersion(DTLS1_VERSION, &DTLSv1_method) || |
| 1022 | !TestDefaultVersion(DTLS1_2_VERSION, &DTLSv1_2_method) || |
David Benjamin | 422fe08 | 2015-07-21 22:03:43 -0400 | [diff] [blame] | 1023 | !TestCipherGetRFCName() || |
David Benjamin | 1d128f3 | 2015-09-08 17:41:40 -0400 | [diff] [blame] | 1024 | !TestPaddingExtension() || |
David Benjamin | 0f65395 | 2015-10-18 14:28:01 -0400 | [diff] [blame] | 1025 | !TestClientCAList() || |
| 1026 | !TestInternalSessionCache()) { |
Brian Smith | 83a8298 | 2015-04-09 16:21:10 -1000 | [diff] [blame] | 1027 | ERR_print_errors_fp(stderr); |
David Benjamin | bb0a17c | 2014-09-20 15:35:39 -0400 | [diff] [blame] | 1028 | return 1; |
| 1029 | } |
| 1030 | |
David Benjamin | 2e52121 | 2014-07-16 14:37:51 -0400 | [diff] [blame] | 1031 | printf("PASS\n"); |
| 1032 | return 0; |
| 1033 | } |