Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 2 | * All rights reserved. |
| 3 | * |
| 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. All advertising materials mentioning features or use of this software |
| 31 | * must display the following acknowledgement: |
| 32 | * "This product includes cryptographic software written by |
| 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. |
| 51 | * |
| 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence |
| 55 | * [including the GNU Public Licence.] |
| 56 | */ |
| 57 | /* ==================================================================== |
| 58 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. |
| 59 | * |
| 60 | * Redistribution and use in source and binary forms, with or without |
| 61 | * modification, are permitted provided that the following conditions |
| 62 | * are met: |
| 63 | * |
| 64 | * 1. Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * |
| 67 | * 2. Redistributions in binary form must reproduce the above copyright |
| 68 | * notice, this list of conditions and the following disclaimer in |
| 69 | * the documentation and/or other materials provided with the |
| 70 | * distribution. |
| 71 | * |
| 72 | * 3. All advertising materials mentioning features or use of this |
| 73 | * software must display the following acknowledgment: |
| 74 | * "This product includes software developed by the OpenSSL Project |
| 75 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
| 76 | * |
| 77 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 78 | * endorse or promote products derived from this software without |
| 79 | * prior written permission. For written permission, please contact |
| 80 | * openssl-core@openssl.org. |
| 81 | * |
| 82 | * 5. Products derived from this software may not be called "OpenSSL" |
| 83 | * nor may "OpenSSL" appear in their names without prior written |
| 84 | * permission of the OpenSSL Project. |
| 85 | * |
| 86 | * 6. Redistributions of any form whatsoever must retain the following |
| 87 | * acknowledgment: |
| 88 | * "This product includes software developed by the OpenSSL Project |
| 89 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
| 90 | * |
| 91 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 92 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 93 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 94 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 95 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 96 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 97 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 98 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 99 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 100 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 101 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 102 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 103 | * ==================================================================== |
| 104 | * |
| 105 | * This product includes cryptographic software written by Eric Young |
| 106 | * (eay@cryptsoft.com). This product includes software written by Tim |
| 107 | * Hudson (tjh@cryptsoft.com). |
| 108 | * |
| 109 | */ |
| 110 | /* ==================================================================== |
| 111 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 112 | * ECC cipher suite support in OpenSSL originally developed by |
| 113 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
| 114 | */ |
| 115 | /* ==================================================================== |
| 116 | * Copyright 2005 Nokia. All rights reserved. |
| 117 | * |
| 118 | * The portions of the attached software ("Contribution") is developed by |
| 119 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source |
| 120 | * license. |
| 121 | * |
| 122 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of |
| 123 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites |
| 124 | * support (see RFC 4279) to OpenSSL. |
| 125 | * |
| 126 | * No patent licenses or other rights except those expressly stated in |
| 127 | * the OpenSSL open source license shall be deemed granted or received |
| 128 | * expressly, by implication, estoppel, or otherwise. |
| 129 | * |
| 130 | * No assurances are provided by Nokia that the Contribution does not |
| 131 | * infringe the patent or other intellectual property rights of any third |
| 132 | * party or that the license provides you with all the necessary rights |
| 133 | * to make use of the Contribution. |
| 134 | * |
| 135 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN |
| 136 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA |
| 137 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY |
| 138 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR |
| 139 | * OTHERWISE. */ |
| 140 | |
David Benjamin | 9e4e01e | 2015-09-15 01:48:04 -0400 | [diff] [blame] | 141 | #include <openssl/ssl.h> |
| 142 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 143 | #include <assert.h> |
David Benjamin | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 144 | #include <string.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 145 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 146 | #include <openssl/buf.h> |
David Benjamin | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 147 | #include <openssl/err.h> |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 148 | #include <openssl/md5.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 149 | #include <openssl/mem.h> |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 150 | #include <openssl/sha.h> |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 151 | #include <openssl/stack.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 152 | |
David Benjamin | 2ee94aa | 2015-04-07 22:38:30 -0400 | [diff] [blame] | 153 | #include "internal.h" |
Steven Valdez | cb96654 | 2016-08-17 16:56:14 -0400 | [diff] [blame] | 154 | #include "../crypto/internal.h" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 155 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 156 | |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 157 | namespace bssl { |
| 158 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 159 | /* kCiphers is an array of all supported ciphers, sorted by id. */ |
David Benjamin | 20c3731 | 2015-11-11 21:33:18 -0800 | [diff] [blame] | 160 | static const SSL_CIPHER kCiphers[] = { |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 161 | /* The RSA ciphers */ |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 162 | /* Cipher 02 */ |
| 163 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 164 | SSL3_TXT_RSA_NULL_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 165 | "TLS_RSA_WITH_NULL_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 166 | SSL3_CK_RSA_NULL_SHA, |
| 167 | SSL_kRSA, |
| 168 | SSL_aRSA, |
| 169 | SSL_eNULL, |
| 170 | SSL_SHA1, |
| 171 | SSL_HANDSHAKE_MAC_DEFAULT, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 172 | }, |
| 173 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 174 | /* Cipher 0A */ |
| 175 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 176 | SSL3_TXT_RSA_DES_192_CBC3_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 177 | "TLS_RSA_WITH_3DES_EDE_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 178 | SSL3_CK_RSA_DES_192_CBC3_SHA, |
| 179 | SSL_kRSA, |
| 180 | SSL_aRSA, |
| 181 | SSL_3DES, |
| 182 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 183 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 184 | }, |
| 185 | |
| 186 | |
| 187 | /* New AES ciphersuites */ |
| 188 | |
| 189 | /* Cipher 2F */ |
| 190 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 191 | TLS1_TXT_RSA_WITH_AES_128_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 192 | "TLS_RSA_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 193 | TLS1_CK_RSA_WITH_AES_128_SHA, |
| 194 | SSL_kRSA, |
| 195 | SSL_aRSA, |
| 196 | SSL_AES128, |
| 197 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 198 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 199 | }, |
| 200 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 201 | /* Cipher 35 */ |
| 202 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 203 | TLS1_TXT_RSA_WITH_AES_256_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 204 | "TLS_RSA_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 205 | TLS1_CK_RSA_WITH_AES_256_SHA, |
| 206 | SSL_kRSA, |
| 207 | SSL_aRSA, |
| 208 | SSL_AES256, |
| 209 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 210 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 211 | }, |
| 212 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 213 | |
| 214 | /* TLS v1.2 ciphersuites */ |
| 215 | |
| 216 | /* Cipher 3C */ |
| 217 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 218 | TLS1_TXT_RSA_WITH_AES_128_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 219 | "TLS_RSA_WITH_AES_128_CBC_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 220 | TLS1_CK_RSA_WITH_AES_128_SHA256, |
| 221 | SSL_kRSA, |
| 222 | SSL_aRSA, |
| 223 | SSL_AES128, |
| 224 | SSL_SHA256, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 225 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 226 | }, |
| 227 | |
| 228 | /* Cipher 3D */ |
| 229 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 230 | TLS1_TXT_RSA_WITH_AES_256_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 231 | "TLS_RSA_WITH_AES_256_CBC_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 232 | TLS1_CK_RSA_WITH_AES_256_SHA256, |
| 233 | SSL_kRSA, |
| 234 | SSL_aRSA, |
| 235 | SSL_AES256, |
| 236 | SSL_SHA256, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 237 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 238 | }, |
| 239 | |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 240 | /* PSK cipher suites. */ |
| 241 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 242 | /* Cipher 8C */ |
| 243 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 244 | TLS1_TXT_PSK_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 245 | "TLS_PSK_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 246 | TLS1_CK_PSK_WITH_AES_128_CBC_SHA, |
| 247 | SSL_kPSK, |
| 248 | SSL_aPSK, |
| 249 | SSL_AES128, |
| 250 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 251 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 252 | }, |
| 253 | |
| 254 | /* Cipher 8D */ |
| 255 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 256 | TLS1_TXT_PSK_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 257 | "TLS_PSK_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 258 | TLS1_CK_PSK_WITH_AES_256_CBC_SHA, |
| 259 | SSL_kPSK, |
| 260 | SSL_aPSK, |
| 261 | SSL_AES256, |
| 262 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 263 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 264 | }, |
| 265 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 266 | /* GCM ciphersuites from RFC5288 */ |
| 267 | |
| 268 | /* Cipher 9C */ |
| 269 | { |
| 270 | TLS1_TXT_RSA_WITH_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 271 | "TLS_RSA_WITH_AES_128_GCM_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 272 | TLS1_CK_RSA_WITH_AES_128_GCM_SHA256, |
| 273 | SSL_kRSA, |
| 274 | SSL_aRSA, |
| 275 | SSL_AES128GCM, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 276 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 277 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 278 | }, |
| 279 | |
| 280 | /* Cipher 9D */ |
| 281 | { |
| 282 | TLS1_TXT_RSA_WITH_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 283 | "TLS_RSA_WITH_AES_256_GCM_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 284 | TLS1_CK_RSA_WITH_AES_256_GCM_SHA384, |
| 285 | SSL_kRSA, |
| 286 | SSL_aRSA, |
| 287 | SSL_AES256GCM, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 288 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 289 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 290 | }, |
| 291 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 292 | /* TLS 1.3 suites. */ |
| 293 | |
| 294 | /* Cipher 1301 */ |
| 295 | { |
| 296 | TLS1_TXT_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 297 | "TLS_AES_128_GCM_SHA256", |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 298 | TLS1_CK_AES_128_GCM_SHA256, |
| 299 | SSL_kGENERIC, |
| 300 | SSL_aGENERIC, |
| 301 | SSL_AES128GCM, |
| 302 | SSL_AEAD, |
| 303 | SSL_HANDSHAKE_MAC_SHA256, |
| 304 | }, |
| 305 | |
| 306 | /* Cipher 1302 */ |
| 307 | { |
| 308 | TLS1_TXT_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 309 | "TLS_AES_256_GCM_SHA384", |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 310 | TLS1_CK_AES_256_GCM_SHA384, |
| 311 | SSL_kGENERIC, |
| 312 | SSL_aGENERIC, |
| 313 | SSL_AES256GCM, |
| 314 | SSL_AEAD, |
| 315 | SSL_HANDSHAKE_MAC_SHA384, |
| 316 | }, |
| 317 | |
| 318 | /* Cipher 1303 */ |
| 319 | { |
| 320 | TLS1_TXT_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 321 | "TLS_CHACHA20_POLY1305_SHA256", |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 322 | TLS1_CK_CHACHA20_POLY1305_SHA256, |
| 323 | SSL_kGENERIC, |
| 324 | SSL_aGENERIC, |
| 325 | SSL_CHACHA20POLY1305, |
| 326 | SSL_AEAD, |
| 327 | SSL_HANDSHAKE_MAC_SHA256, |
| 328 | }, |
| 329 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 330 | /* Cipher C009 */ |
| 331 | { |
| 332 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 333 | "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 334 | TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 335 | SSL_kECDHE, |
| 336 | SSL_aECDSA, |
| 337 | SSL_AES128, |
| 338 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 339 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 340 | }, |
| 341 | |
| 342 | /* Cipher C00A */ |
| 343 | { |
| 344 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 345 | "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 346 | TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
| 347 | SSL_kECDHE, |
| 348 | SSL_aECDSA, |
| 349 | SSL_AES256, |
| 350 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 351 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 352 | }, |
| 353 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 354 | /* Cipher C013 */ |
| 355 | { |
| 356 | TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 357 | "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 358 | TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 359 | SSL_kECDHE, |
| 360 | SSL_aRSA, |
| 361 | SSL_AES128, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 362 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 363 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 364 | }, |
| 365 | |
| 366 | /* Cipher C014 */ |
| 367 | { |
| 368 | TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 369 | "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 370 | TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 371 | SSL_kECDHE, |
| 372 | SSL_aRSA, |
| 373 | SSL_AES256, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 374 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 375 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 376 | }, |
| 377 | |
| 378 | |
| 379 | /* HMAC based TLS v1.2 ciphersuites from RFC5289 */ |
| 380 | |
| 381 | /* Cipher C023 */ |
| 382 | { |
| 383 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 384 | "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 385 | TLS1_CK_ECDHE_ECDSA_WITH_AES_128_SHA256, |
| 386 | SSL_kECDHE, |
| 387 | SSL_aECDSA, |
| 388 | SSL_AES128, |
| 389 | SSL_SHA256, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 390 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 391 | }, |
| 392 | |
| 393 | /* Cipher C024 */ |
| 394 | { |
| 395 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 396 | "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 397 | TLS1_CK_ECDHE_ECDSA_WITH_AES_256_SHA384, |
| 398 | SSL_kECDHE, |
| 399 | SSL_aECDSA, |
| 400 | SSL_AES256, |
| 401 | SSL_SHA384, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 402 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 403 | }, |
| 404 | |
| 405 | /* Cipher C027 */ |
| 406 | { |
| 407 | TLS1_TXT_ECDHE_RSA_WITH_AES_128_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 408 | "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 409 | TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256, |
| 410 | SSL_kECDHE, |
| 411 | SSL_aRSA, |
| 412 | SSL_AES128, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 413 | SSL_SHA256, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 414 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 415 | }, |
| 416 | |
| 417 | /* Cipher C028 */ |
| 418 | { |
| 419 | TLS1_TXT_ECDHE_RSA_WITH_AES_256_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 420 | "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 421 | TLS1_CK_ECDHE_RSA_WITH_AES_256_SHA384, |
| 422 | SSL_kECDHE, |
| 423 | SSL_aRSA, |
| 424 | SSL_AES256, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 425 | SSL_SHA384, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 426 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 427 | }, |
| 428 | |
| 429 | |
| 430 | /* GCM based TLS v1.2 ciphersuites from RFC5289 */ |
| 431 | |
| 432 | /* Cipher C02B */ |
| 433 | { |
| 434 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 435 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 436 | TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 437 | SSL_kECDHE, |
| 438 | SSL_aECDSA, |
| 439 | SSL_AES128GCM, |
| 440 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 441 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 442 | }, |
| 443 | |
| 444 | /* Cipher C02C */ |
| 445 | { |
| 446 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 447 | "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 448 | TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
| 449 | SSL_kECDHE, |
| 450 | SSL_aECDSA, |
| 451 | SSL_AES256GCM, |
| 452 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 453 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 454 | }, |
| 455 | |
| 456 | /* Cipher C02F */ |
| 457 | { |
| 458 | TLS1_TXT_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 459 | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 460 | TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 461 | SSL_kECDHE, |
| 462 | SSL_aRSA, |
| 463 | SSL_AES128GCM, |
| 464 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 465 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 466 | }, |
| 467 | |
| 468 | /* Cipher C030 */ |
| 469 | { |
| 470 | TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 471 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 472 | TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 473 | SSL_kECDHE, |
| 474 | SSL_aRSA, |
| 475 | SSL_AES256GCM, |
| 476 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 477 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 478 | }, |
| 479 | |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 480 | /* ECDHE-PSK cipher suites. */ |
| 481 | |
| 482 | /* Cipher C035 */ |
| 483 | { |
| 484 | TLS1_TXT_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 485 | "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA", |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 486 | TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 487 | SSL_kECDHE, |
| 488 | SSL_aPSK, |
| 489 | SSL_AES128, |
| 490 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 491 | SSL_HANDSHAKE_MAC_DEFAULT, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 492 | }, |
| 493 | |
| 494 | /* Cipher C036 */ |
| 495 | { |
| 496 | TLS1_TXT_ECDHE_PSK_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 497 | "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA", |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 498 | TLS1_CK_ECDHE_PSK_WITH_AES_256_CBC_SHA, |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 499 | SSL_kECDHE, |
| 500 | SSL_aPSK, |
| 501 | SSL_AES256, |
| 502 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 503 | SSL_HANDSHAKE_MAC_DEFAULT, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 504 | }, |
| 505 | |
| 506 | /* ChaCha20-Poly1305 cipher suites. */ |
| 507 | |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 508 | /* Cipher CCA8 */ |
| 509 | { |
| 510 | TLS1_TXT_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 511 | "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 512 | TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 513 | SSL_kECDHE, |
| 514 | SSL_aRSA, |
| 515 | SSL_CHACHA20POLY1305, |
| 516 | SSL_AEAD, |
| 517 | SSL_HANDSHAKE_MAC_SHA256, |
| 518 | }, |
| 519 | |
| 520 | /* Cipher CCA9 */ |
| 521 | { |
| 522 | TLS1_TXT_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 523 | "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 524 | TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, |
| 525 | SSL_kECDHE, |
| 526 | SSL_aECDSA, |
| 527 | SSL_CHACHA20POLY1305, |
| 528 | SSL_AEAD, |
| 529 | SSL_HANDSHAKE_MAC_SHA256, |
| 530 | }, |
| 531 | |
| 532 | /* Cipher CCAB */ |
| 533 | { |
| 534 | TLS1_TXT_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 535 | "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256", |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 536 | TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, |
| 537 | SSL_kECDHE, |
| 538 | SSL_aPSK, |
| 539 | SSL_CHACHA20POLY1305, |
| 540 | SSL_AEAD, |
| 541 | SSL_HANDSHAKE_MAC_SHA256, |
| 542 | }, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 543 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 544 | }; |
| 545 | |
Steven Valdez | cb96654 | 2016-08-17 16:56:14 -0400 | [diff] [blame] | 546 | static const size_t kCiphersLen = OPENSSL_ARRAY_SIZE(kCiphers); |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 547 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 548 | #define CIPHER_ADD 1 |
| 549 | #define CIPHER_KILL 2 |
| 550 | #define CIPHER_DEL 3 |
| 551 | #define CIPHER_ORD 4 |
| 552 | #define CIPHER_SPECIAL 5 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 553 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 554 | typedef struct cipher_order_st { |
| 555 | const SSL_CIPHER *cipher; |
| 556 | int active; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 557 | int in_group; |
| 558 | struct cipher_order_st *next, *prev; |
| 559 | } CIPHER_ORDER; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 560 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 561 | typedef struct cipher_alias_st { |
| 562 | /* name is the name of the cipher alias. */ |
| 563 | const char *name; |
| 564 | |
| 565 | /* The following fields are bitmasks for the corresponding fields on |
| 566 | * |SSL_CIPHER|. A cipher matches a cipher alias iff, for each bitmask, the |
| 567 | * bit corresponding to the cipher's value is set to 1. If any bitmask is |
| 568 | * all zeroes, the alias matches nothing. Use |~0u| for the default value. */ |
| 569 | uint32_t algorithm_mkey; |
| 570 | uint32_t algorithm_auth; |
| 571 | uint32_t algorithm_enc; |
| 572 | uint32_t algorithm_mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 573 | |
| 574 | /* min_version, if non-zero, matches all ciphers which were added in that |
| 575 | * particular protocol version. */ |
| 576 | uint16_t min_version; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 577 | } CIPHER_ALIAS; |
| 578 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 579 | static const CIPHER_ALIAS kCipherAliases[] = { |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 580 | /* "ALL" doesn't include eNULL. It must be explicitly enabled. */ |
| 581 | {"ALL", ~0u, ~0u, ~SSL_eNULL, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 582 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 583 | /* The "COMPLEMENTOFDEFAULT" rule is omitted. It matches nothing. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 584 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 585 | /* key exchange aliases |
| 586 | * (some of those using only a single bit here combine |
Matthew Braithwaite | 7e06de5 | 2017-04-10 15:52:14 -0700 | [diff] [blame] | 587 | * multiple key exchange algs according to the RFCs. */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 588 | {"kRSA", SSL_kRSA, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 589 | |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 590 | {"kECDHE", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 591 | {"kEECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 592 | {"ECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 593 | |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 594 | {"kPSK", SSL_kPSK, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 595 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 596 | /* server authentication aliases */ |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 597 | {"aRSA", ~0u, SSL_aRSA, ~SSL_eNULL, ~0u, 0}, |
| 598 | {"aECDSA", ~0u, SSL_aECDSA, ~0u, ~0u, 0}, |
| 599 | {"ECDSA", ~0u, SSL_aECDSA, ~0u, ~0u, 0}, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 600 | {"aPSK", ~0u, SSL_aPSK, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 601 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 602 | /* aliases combining key exchange and server authentication */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 603 | {"ECDHE", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 604 | {"EECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 605 | {"RSA", SSL_kRSA, SSL_aRSA, ~SSL_eNULL, ~0u, 0}, |
| 606 | {"PSK", SSL_kPSK, SSL_aPSK, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 607 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 608 | /* symmetric encryption aliases */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 609 | {"3DES", ~0u, ~0u, SSL_3DES, ~0u, 0}, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 610 | {"AES128", ~0u, ~0u, SSL_AES128 | SSL_AES128GCM, ~0u, 0}, |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 611 | {"AES256", ~0u, ~0u, SSL_AES256 | SSL_AES256GCM, ~0u, 0}, |
| 612 | {"AES", ~0u, ~0u, SSL_AES, ~0u, 0}, |
| 613 | {"AESGCM", ~0u, ~0u, SSL_AES128GCM | SSL_AES256GCM, ~0u, 0}, |
Adam Langley | 2e83924 | 2017-01-19 15:12:44 -0800 | [diff] [blame] | 614 | {"CHACHA20", ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 615 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 616 | /* MAC aliases */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 617 | {"SHA1", ~0u, ~0u, ~SSL_eNULL, SSL_SHA1, 0}, |
| 618 | {"SHA", ~0u, ~0u, ~SSL_eNULL, SSL_SHA1, 0}, |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 619 | {"SHA256", ~0u, ~0u, ~0u, SSL_SHA256, 0}, |
| 620 | {"SHA384", ~0u, ~0u, ~0u, SSL_SHA384, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 621 | |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 622 | /* Legacy protocol minimum version aliases. "TLSv1" is intentionally the |
| 623 | * same as "SSLv3". */ |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 624 | {"SSLv3", ~0u, ~0u, ~SSL_eNULL, ~0u, SSL3_VERSION}, |
| 625 | {"TLSv1", ~0u, ~0u, ~SSL_eNULL, ~0u, SSL3_VERSION}, |
| 626 | {"TLSv1.2", ~0u, ~0u, ~SSL_eNULL, ~0u, TLS1_2_VERSION}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 627 | |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 628 | /* Legacy strength classes. */ |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 629 | {"HIGH", ~0u, ~0u, ~SSL_eNULL, ~0u, 0}, |
| 630 | {"FIPS", ~0u, ~0u, ~SSL_eNULL, ~0u, 0}, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 631 | }; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 632 | |
Steven Valdez | cb96654 | 2016-08-17 16:56:14 -0400 | [diff] [blame] | 633 | static const size_t kCipherAliasesLen = OPENSSL_ARRAY_SIZE(kCipherAliases); |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 634 | |
| 635 | static int ssl_cipher_id_cmp(const void *in_a, const void *in_b) { |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 636 | const SSL_CIPHER *a = reinterpret_cast<const SSL_CIPHER *>(in_a); |
| 637 | const SSL_CIPHER *b = reinterpret_cast<const SSL_CIPHER *>(in_b); |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 638 | |
| 639 | if (a->id > b->id) { |
| 640 | return 1; |
| 641 | } else if (a->id < b->id) { |
| 642 | return -1; |
| 643 | } else { |
| 644 | return 0; |
| 645 | } |
| 646 | } |
| 647 | |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 648 | int ssl_cipher_get_evp_aead(const EVP_AEAD **out_aead, |
| 649 | size_t *out_mac_secret_len, |
| 650 | size_t *out_fixed_iv_len, |
Steven Valdez | 2f3404b | 2017-05-24 16:54:35 -0400 | [diff] [blame] | 651 | const SSL_CIPHER *cipher, uint16_t version, int is_dtls) { |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 652 | *out_aead = NULL; |
| 653 | *out_mac_secret_len = 0; |
| 654 | *out_fixed_iv_len = 0; |
Adam Langley | c9fb375 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 655 | |
Steven Valdez | 2f3404b | 2017-05-24 16:54:35 -0400 | [diff] [blame] | 656 | const int is_tls12 = version == TLS1_2_VERSION && !is_dtls; |
| 657 | |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 658 | if (cipher->algorithm_mac == SSL_AEAD) { |
| 659 | if (cipher->algorithm_enc == SSL_AES128GCM) { |
Steven Valdez | 2f3404b | 2017-05-24 16:54:35 -0400 | [diff] [blame] | 660 | *out_aead = |
| 661 | is_tls12 ? EVP_aead_aes_128_gcm_tls12() : EVP_aead_aes_128_gcm(); |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 662 | *out_fixed_iv_len = 4; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 663 | } else if (cipher->algorithm_enc == SSL_AES256GCM) { |
Steven Valdez | 2f3404b | 2017-05-24 16:54:35 -0400 | [diff] [blame] | 664 | *out_aead = |
| 665 | is_tls12 ? EVP_aead_aes_256_gcm_tls12() : EVP_aead_aes_256_gcm(); |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 666 | *out_fixed_iv_len = 4; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 667 | } else if (cipher->algorithm_enc == SSL_CHACHA20POLY1305) { |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 668 | *out_aead = EVP_aead_chacha20_poly1305(); |
| 669 | *out_fixed_iv_len = 12; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 670 | } else { |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 671 | return 0; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | /* In TLS 1.3, the iv_len is equal to the AEAD nonce length whereas the code |
| 675 | * above computes the TLS 1.2 construction. */ |
| 676 | if (version >= TLS1_3_VERSION) { |
| 677 | *out_fixed_iv_len = EVP_AEAD_nonce_length(*out_aead); |
| 678 | } |
| 679 | } else if (cipher->algorithm_mac == SSL_SHA1) { |
| 680 | if (cipher->algorithm_enc == SSL_eNULL) { |
| 681 | if (version == SSL3_VERSION) { |
| 682 | *out_aead = EVP_aead_null_sha1_ssl3(); |
| 683 | } else { |
| 684 | *out_aead = EVP_aead_null_sha1_tls(); |
| 685 | } |
| 686 | } else if (cipher->algorithm_enc == SSL_3DES) { |
| 687 | if (version == SSL3_VERSION) { |
| 688 | *out_aead = EVP_aead_des_ede3_cbc_sha1_ssl3(); |
| 689 | *out_fixed_iv_len = 8; |
| 690 | } else if (version == TLS1_VERSION) { |
| 691 | *out_aead = EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(); |
| 692 | *out_fixed_iv_len = 8; |
| 693 | } else { |
| 694 | *out_aead = EVP_aead_des_ede3_cbc_sha1_tls(); |
| 695 | } |
| 696 | } else if (cipher->algorithm_enc == SSL_AES128) { |
| 697 | if (version == SSL3_VERSION) { |
| 698 | *out_aead = EVP_aead_aes_128_cbc_sha1_ssl3(); |
| 699 | *out_fixed_iv_len = 16; |
| 700 | } else if (version == TLS1_VERSION) { |
| 701 | *out_aead = EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(); |
| 702 | *out_fixed_iv_len = 16; |
| 703 | } else { |
| 704 | *out_aead = EVP_aead_aes_128_cbc_sha1_tls(); |
| 705 | } |
| 706 | } else if (cipher->algorithm_enc == SSL_AES256) { |
| 707 | if (version == SSL3_VERSION) { |
| 708 | *out_aead = EVP_aead_aes_256_cbc_sha1_ssl3(); |
| 709 | *out_fixed_iv_len = 16; |
| 710 | } else if (version == TLS1_VERSION) { |
| 711 | *out_aead = EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(); |
| 712 | *out_fixed_iv_len = 16; |
| 713 | } else { |
| 714 | *out_aead = EVP_aead_aes_256_cbc_sha1_tls(); |
| 715 | } |
| 716 | } else { |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | *out_mac_secret_len = SHA_DIGEST_LENGTH; |
| 721 | } else if (cipher->algorithm_mac == SSL_SHA256) { |
| 722 | if (cipher->algorithm_enc == SSL_AES128) { |
| 723 | *out_aead = EVP_aead_aes_128_cbc_sha256_tls(); |
| 724 | } else if (cipher->algorithm_enc == SSL_AES256) { |
| 725 | *out_aead = EVP_aead_aes_256_cbc_sha256_tls(); |
| 726 | } else { |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | *out_mac_secret_len = SHA256_DIGEST_LENGTH; |
| 731 | } else if (cipher->algorithm_mac == SSL_SHA384) { |
| 732 | if (cipher->algorithm_enc != SSL_AES256) { |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | *out_aead = EVP_aead_aes_256_cbc_sha384_tls(); |
| 737 | *out_mac_secret_len = SHA384_DIGEST_LENGTH; |
| 738 | } else { |
| 739 | return 0; |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 740 | } |
Steven Valdez | 7975056 | 2016-06-16 06:38:04 -0400 | [diff] [blame] | 741 | |
Steven Valdez | 7975056 | 2016-06-16 06:38:04 -0400 | [diff] [blame] | 742 | return 1; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 743 | } |
Adam Langley | c9fb375 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 744 | |
David Benjamin | ca9e8f5 | 2017-08-09 15:02:34 -0400 | [diff] [blame] | 745 | const EVP_MD *ssl_get_handshake_digest(uint16_t version, |
| 746 | const SSL_CIPHER *cipher) { |
| 747 | switch (cipher->algorithm_prf) { |
David Benjamin | b088331 | 2015-08-06 09:54:13 -0400 | [diff] [blame] | 748 | case SSL_HANDSHAKE_MAC_DEFAULT: |
Steven Valdez | 908ac19 | 2017-01-12 13:17:07 -0500 | [diff] [blame] | 749 | return version >= TLS1_2_VERSION ? EVP_sha256() : EVP_md5_sha1(); |
David Benjamin | b088331 | 2015-08-06 09:54:13 -0400 | [diff] [blame] | 750 | case SSL_HANDSHAKE_MAC_SHA256: |
| 751 | return EVP_sha256(); |
| 752 | case SSL_HANDSHAKE_MAC_SHA384: |
| 753 | return EVP_sha384(); |
| 754 | default: |
David Benjamin | ca9e8f5 | 2017-08-09 15:02:34 -0400 | [diff] [blame] | 755 | assert(0); |
David Benjamin | b088331 | 2015-08-06 09:54:13 -0400 | [diff] [blame] | 756 | return NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 757 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Adam Langley | 22df691 | 2017-07-25 12:27:37 -0700 | [diff] [blame] | 760 | static bool is_cipher_list_separator(char c, int is_strict) { |
| 761 | if (c == ':') { |
| 762 | return true; |
| 763 | } |
| 764 | return !is_strict && (c == ' ' || c == ';' || c == ','); |
| 765 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 766 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 767 | /* rule_equals returns one iff the NUL-terminated string |rule| is equal to the |
| 768 | * |buf_len| bytes at |buf|. */ |
| 769 | static int rule_equals(const char *rule, const char *buf, size_t buf_len) { |
| 770 | /* |strncmp| alone only checks that |buf| is a prefix of |rule|. */ |
| 771 | return strncmp(rule, buf, buf_len) == 0 && rule[buf_len] == '\0'; |
| 772 | } |
| 773 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 774 | static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 775 | CIPHER_ORDER **tail) { |
| 776 | if (curr == *tail) { |
| 777 | return; |
| 778 | } |
| 779 | if (curr == *head) { |
| 780 | *head = curr->next; |
| 781 | } |
| 782 | if (curr->prev != NULL) { |
| 783 | curr->prev->next = curr->next; |
| 784 | } |
| 785 | if (curr->next != NULL) { |
| 786 | curr->next->prev = curr->prev; |
| 787 | } |
| 788 | (*tail)->next = curr; |
| 789 | curr->prev = *tail; |
| 790 | curr->next = NULL; |
| 791 | *tail = curr; |
| 792 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 793 | |
| 794 | static void ll_append_head(CIPHER_ORDER **head, CIPHER_ORDER *curr, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 795 | CIPHER_ORDER **tail) { |
| 796 | if (curr == *head) { |
| 797 | return; |
| 798 | } |
| 799 | if (curr == *tail) { |
| 800 | *tail = curr->prev; |
| 801 | } |
| 802 | if (curr->next != NULL) { |
| 803 | curr->next->prev = curr->prev; |
| 804 | } |
| 805 | if (curr->prev != NULL) { |
| 806 | curr->prev->next = curr->next; |
| 807 | } |
| 808 | (*head)->prev = curr; |
| 809 | curr->next = *head; |
| 810 | curr->prev = NULL; |
| 811 | *head = curr; |
| 812 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 813 | |
David Benjamin | 82c9e90 | 2014-12-12 15:55:27 -0500 | [diff] [blame] | 814 | static void ssl_cipher_collect_ciphers(const SSL_PROTOCOL_METHOD *ssl_method, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 815 | CIPHER_ORDER *co_list, |
| 816 | CIPHER_ORDER **head_p, |
| 817 | CIPHER_ORDER **tail_p) { |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 818 | /* The set of ciphers is static, but some subset may be unsupported by |
| 819 | * |ssl_method|, so the list may be smaller. */ |
| 820 | size_t co_list_num = 0; |
David Benjamin | 5409123 | 2016-09-05 12:47:25 -0400 | [diff] [blame] | 821 | for (size_t i = 0; i < kCiphersLen; i++) { |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 822 | const SSL_CIPHER *cipher = &kCiphers[i]; |
David Benjamin | abbbee1 | 2016-10-31 19:20:42 -0400 | [diff] [blame] | 823 | if (ssl_method->supports_cipher(cipher) && |
| 824 | /* TLS 1.3 ciphers do not participate in this mechanism. */ |
| 825 | cipher->algorithm_mkey != SSL_kGENERIC) { |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 826 | co_list[co_list_num].cipher = cipher; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 827 | co_list[co_list_num].next = NULL; |
| 828 | co_list[co_list_num].prev = NULL; |
| 829 | co_list[co_list_num].active = 0; |
| 830 | co_list[co_list_num].in_group = 0; |
| 831 | co_list_num++; |
| 832 | } |
| 833 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 834 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 835 | /* Prepare linked list from list entries. */ |
| 836 | if (co_list_num > 0) { |
| 837 | co_list[0].prev = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 838 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 839 | if (co_list_num > 1) { |
| 840 | co_list[0].next = &co_list[1]; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 841 | |
David Benjamin | 5409123 | 2016-09-05 12:47:25 -0400 | [diff] [blame] | 842 | for (size_t i = 1; i < co_list_num - 1; i++) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 843 | co_list[i].prev = &co_list[i - 1]; |
| 844 | co_list[i].next = &co_list[i + 1]; |
| 845 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 846 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 847 | co_list[co_list_num - 1].prev = &co_list[co_list_num - 2]; |
| 848 | } |
| 849 | |
| 850 | co_list[co_list_num - 1].next = NULL; |
| 851 | |
| 852 | *head_p = &co_list[0]; |
| 853 | *tail_p = &co_list[co_list_num - 1]; |
| 854 | } |
| 855 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 856 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 857 | /* ssl_cipher_apply_rule applies the rule type |rule| to ciphers matching its |
| 858 | * parameters in the linked list from |*head_p| to |*tail_p|. It writes the new |
| 859 | * head and tail of the list to |*head_p| and |*tail_p|, respectively. |
| 860 | * |
| 861 | * - If |cipher_id| is non-zero, only that cipher is selected. |
| 862 | * - Otherwise, if |strength_bits| is non-negative, it selects ciphers |
| 863 | * of that strength. |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 864 | * - Otherwise, it selects ciphers that match each bitmasks in |alg_*| and |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 865 | * |min_version|. */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 866 | static void ssl_cipher_apply_rule( |
David Benjamin | 107db58 | 2015-04-08 00:41:59 -0400 | [diff] [blame] | 867 | uint32_t cipher_id, uint32_t alg_mkey, uint32_t alg_auth, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 868 | uint32_t alg_enc, uint32_t alg_mac, uint16_t min_version, int rule, |
| 869 | int strength_bits, int in_group, CIPHER_ORDER **head_p, |
| 870 | CIPHER_ORDER **tail_p) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 871 | CIPHER_ORDER *head, *tail, *curr, *next, *last; |
| 872 | const SSL_CIPHER *cp; |
| 873 | int reverse = 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 874 | |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 875 | if (cipher_id == 0 && strength_bits == -1 && min_version == 0 && |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 876 | (alg_mkey == 0 || alg_auth == 0 || alg_enc == 0 || alg_mac == 0)) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 877 | /* The rule matches nothing, so bail early. */ |
| 878 | return; |
| 879 | } |
| 880 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 881 | if (rule == CIPHER_DEL) { |
| 882 | /* needed to maintain sorting between currently deleted ciphers */ |
| 883 | reverse = 1; |
| 884 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 885 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 886 | head = *head_p; |
| 887 | tail = *tail_p; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 888 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 889 | if (reverse) { |
| 890 | next = tail; |
| 891 | last = head; |
| 892 | } else { |
| 893 | next = head; |
| 894 | last = tail; |
| 895 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 896 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 897 | curr = NULL; |
| 898 | for (;;) { |
| 899 | if (curr == last) { |
| 900 | break; |
| 901 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 902 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 903 | curr = next; |
| 904 | if (curr == NULL) { |
| 905 | break; |
| 906 | } |
Adam Langley | e3142a7 | 2014-07-24 17:56:48 -0700 | [diff] [blame] | 907 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 908 | next = reverse ? curr->prev : curr->next; |
| 909 | cp = curr->cipher; |
Adam Langley | e3142a7 | 2014-07-24 17:56:48 -0700 | [diff] [blame] | 910 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 911 | /* Selection criteria is either a specific cipher, the value of |
| 912 | * |strength_bits|, or the algorithms used. */ |
| 913 | if (cipher_id != 0) { |
| 914 | if (cipher_id != cp->id) { |
| 915 | continue; |
| 916 | } |
| 917 | } else if (strength_bits >= 0) { |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 918 | if (strength_bits != SSL_CIPHER_get_bits(cp, NULL)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 919 | continue; |
| 920 | } |
David Benjamin | 881f196 | 2016-08-10 18:29:12 -0400 | [diff] [blame] | 921 | } else { |
| 922 | if (!(alg_mkey & cp->algorithm_mkey) || |
| 923 | !(alg_auth & cp->algorithm_auth) || |
| 924 | !(alg_enc & cp->algorithm_enc) || |
| 925 | !(alg_mac & cp->algorithm_mac) || |
| 926 | (min_version != 0 && SSL_CIPHER_get_min_version(cp) != min_version)) { |
| 927 | continue; |
| 928 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 929 | } |
Adam Langley | e3142a7 | 2014-07-24 17:56:48 -0700 | [diff] [blame] | 930 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 931 | /* add the cipher if it has not been added yet. */ |
| 932 | if (rule == CIPHER_ADD) { |
| 933 | /* reverse == 0 */ |
| 934 | if (!curr->active) { |
| 935 | ll_append_tail(&head, curr, &tail); |
| 936 | curr->active = 1; |
| 937 | curr->in_group = in_group; |
| 938 | } |
| 939 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 940 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 941 | /* Move the added cipher to this location */ |
| 942 | else if (rule == CIPHER_ORD) { |
| 943 | /* reverse == 0 */ |
| 944 | if (curr->active) { |
| 945 | ll_append_tail(&head, curr, &tail); |
| 946 | curr->in_group = 0; |
| 947 | } |
| 948 | } else if (rule == CIPHER_DEL) { |
| 949 | /* reverse == 1 */ |
| 950 | if (curr->active) { |
| 951 | /* most recently deleted ciphersuites get best positions |
| 952 | * for any future CIPHER_ADD (note that the CIPHER_DEL loop |
| 953 | * works in reverse to maintain the order) */ |
| 954 | ll_append_head(&head, curr, &tail); |
| 955 | curr->active = 0; |
| 956 | curr->in_group = 0; |
| 957 | } |
| 958 | } else if (rule == CIPHER_KILL) { |
| 959 | /* reverse == 0 */ |
| 960 | if (head == curr) { |
| 961 | head = curr->next; |
| 962 | } else { |
| 963 | curr->prev->next = curr->next; |
| 964 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 965 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 966 | if (tail == curr) { |
| 967 | tail = curr->prev; |
| 968 | } |
| 969 | curr->active = 0; |
| 970 | if (curr->next != NULL) { |
| 971 | curr->next->prev = curr->prev; |
| 972 | } |
| 973 | if (curr->prev != NULL) { |
| 974 | curr->prev->next = curr->next; |
| 975 | } |
| 976 | curr->next = NULL; |
| 977 | curr->prev = NULL; |
| 978 | } |
| 979 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 980 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 981 | *head_p = head; |
| 982 | *tail_p = tail; |
| 983 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 984 | |
| 985 | static int ssl_cipher_strength_sort(CIPHER_ORDER **head_p, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 986 | CIPHER_ORDER **tail_p) { |
| 987 | int max_strength_bits, i, *number_uses; |
| 988 | CIPHER_ORDER *curr; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 989 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 990 | /* This routine sorts the ciphers with descending strength. The sorting must |
| 991 | * keep the pre-sorted sequence, so we apply the normal sorting routine as |
| 992 | * '+' movement to the end of the list. */ |
| 993 | max_strength_bits = 0; |
| 994 | curr = *head_p; |
| 995 | while (curr != NULL) { |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 996 | if (curr->active && |
| 997 | SSL_CIPHER_get_bits(curr->cipher, NULL) > max_strength_bits) { |
| 998 | max_strength_bits = SSL_CIPHER_get_bits(curr->cipher, NULL); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 999 | } |
| 1000 | curr = curr->next; |
| 1001 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1002 | |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1003 | number_uses = (int *)OPENSSL_malloc((max_strength_bits + 1) * sizeof(int)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1004 | if (!number_uses) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1005 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1006 | return 0; |
| 1007 | } |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 1008 | OPENSSL_memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1009 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1010 | /* Now find the strength_bits values actually used. */ |
| 1011 | curr = *head_p; |
| 1012 | while (curr != NULL) { |
| 1013 | if (curr->active) { |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1014 | number_uses[SSL_CIPHER_get_bits(curr->cipher, NULL)]++; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1015 | } |
| 1016 | curr = curr->next; |
| 1017 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1018 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1019 | /* Go through the list of used strength_bits values in descending order. */ |
| 1020 | for (i = max_strength_bits; i >= 0; i--) { |
| 1021 | if (number_uses[i] > 0) { |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1022 | ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, CIPHER_ORD, i, 0, head_p, tail_p); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | OPENSSL_free(number_uses); |
| 1027 | return 1; |
| 1028 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1029 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1030 | static int ssl_cipher_process_rulestr(const SSL_PROTOCOL_METHOD *ssl_method, |
| 1031 | const char *rule_str, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1032 | CIPHER_ORDER **head_p, |
Matthew Braithwaite | a57dcfb | 2017-02-17 22:08:23 -0800 | [diff] [blame] | 1033 | CIPHER_ORDER **tail_p, int strict) { |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1034 | uint32_t alg_mkey, alg_auth, alg_enc, alg_mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1035 | uint16_t min_version; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1036 | const char *l, *buf; |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1037 | int multi, skip_rule, rule, in_group = 0, has_group = 0; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1038 | size_t j, buf_len; |
| 1039 | uint32_t cipher_id; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1040 | char ch; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1041 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1042 | l = rule_str; |
| 1043 | for (;;) { |
| 1044 | ch = *l; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1045 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1046 | if (ch == '\0') { |
| 1047 | break; /* done */ |
| 1048 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1049 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1050 | if (in_group) { |
| 1051 | if (ch == ']') { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1052 | if (*tail_p) { |
| 1053 | (*tail_p)->in_group = 0; |
| 1054 | } |
| 1055 | in_group = 0; |
| 1056 | l++; |
| 1057 | continue; |
| 1058 | } |
David Benjamin | 37d9246 | 2014-09-20 17:54:24 -0400 | [diff] [blame] | 1059 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1060 | if (ch == '|') { |
| 1061 | rule = CIPHER_ADD; |
| 1062 | l++; |
| 1063 | continue; |
| 1064 | } else if (!(ch >= 'a' && ch <= 'z') && !(ch >= 'A' && ch <= 'Z') && |
| 1065 | !(ch >= '0' && ch <= '9')) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1066 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_OPERATOR_IN_GROUP); |
Adam Langley | f139c99 | 2016-10-02 09:56:09 -0700 | [diff] [blame] | 1067 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1068 | } else { |
| 1069 | rule = CIPHER_ADD; |
| 1070 | } |
| 1071 | } else if (ch == '-') { |
| 1072 | rule = CIPHER_DEL; |
| 1073 | l++; |
| 1074 | } else if (ch == '+') { |
| 1075 | rule = CIPHER_ORD; |
| 1076 | l++; |
| 1077 | } else if (ch == '!') { |
| 1078 | rule = CIPHER_KILL; |
| 1079 | l++; |
| 1080 | } else if (ch == '@') { |
| 1081 | rule = CIPHER_SPECIAL; |
| 1082 | l++; |
| 1083 | } else if (ch == '[') { |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1084 | assert(!in_group); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1085 | in_group = 1; |
| 1086 | has_group = 1; |
| 1087 | l++; |
| 1088 | continue; |
| 1089 | } else { |
| 1090 | rule = CIPHER_ADD; |
| 1091 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1092 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1093 | /* If preference groups are enabled, the only legal operator is +. |
| 1094 | * Otherwise the in_group bits will get mixed up. */ |
| 1095 | if (has_group && rule != CIPHER_ADD) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1096 | OPENSSL_PUT_ERROR(SSL, SSL_R_MIXED_SPECIAL_OPERATOR_WITH_GROUPS); |
Adam Langley | f139c99 | 2016-10-02 09:56:09 -0700 | [diff] [blame] | 1097 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1098 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1099 | |
Adam Langley | 22df691 | 2017-07-25 12:27:37 -0700 | [diff] [blame] | 1100 | if (is_cipher_list_separator(ch, strict)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1101 | l++; |
| 1102 | continue; |
| 1103 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1104 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1105 | multi = 0; |
| 1106 | cipher_id = 0; |
| 1107 | alg_mkey = ~0u; |
| 1108 | alg_auth = ~0u; |
| 1109 | alg_enc = ~0u; |
| 1110 | alg_mac = ~0u; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1111 | min_version = 0; |
| 1112 | skip_rule = 0; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1113 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1114 | for (;;) { |
| 1115 | ch = *l; |
| 1116 | buf = l; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1117 | buf_len = 0; |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 1118 | while ((ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || |
| 1119 | (ch >= 'a' && ch <= 'z') || ch == '-' || ch == '.' || ch == '_') { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1120 | ch = *(++l); |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1121 | buf_len++; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1122 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1123 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1124 | if (buf_len == 0) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1125 | /* We hit something we cannot deal with, it is no command or separator |
| 1126 | * nor alphanumeric, so we call this an error. */ |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1127 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
Adam Langley | f99f244 | 2016-10-02 09:53:38 -0700 | [diff] [blame] | 1128 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1129 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1130 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1131 | if (rule == CIPHER_SPECIAL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1132 | break; |
| 1133 | } |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1134 | |
| 1135 | /* Look for a matching exact cipher. These aren't allowed in multipart |
| 1136 | * rules. */ |
| 1137 | if (!multi && ch != '+') { |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1138 | for (j = 0; j < kCiphersLen; j++) { |
| 1139 | const SSL_CIPHER *cipher = &kCiphers[j]; |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 1140 | if (rule_equals(cipher->name, buf, buf_len) || |
| 1141 | rule_equals(cipher->standard_name, buf, buf_len)) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1142 | cipher_id = cipher->id; |
| 1143 | break; |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | if (cipher_id == 0) { |
| 1148 | /* If not an exact cipher, look for a matching cipher alias. */ |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1149 | for (j = 0; j < kCipherAliasesLen; j++) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1150 | if (rule_equals(kCipherAliases[j].name, buf, buf_len)) { |
| 1151 | alg_mkey &= kCipherAliases[j].algorithm_mkey; |
| 1152 | alg_auth &= kCipherAliases[j].algorithm_auth; |
| 1153 | alg_enc &= kCipherAliases[j].algorithm_enc; |
| 1154 | alg_mac &= kCipherAliases[j].algorithm_mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1155 | |
| 1156 | if (min_version != 0 && |
| 1157 | min_version != kCipherAliases[j].min_version) { |
| 1158 | skip_rule = 1; |
| 1159 | } else { |
| 1160 | min_version = kCipherAliases[j].min_version; |
| 1161 | } |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | } |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1165 | if (j == kCipherAliasesLen) { |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1166 | skip_rule = 1; |
Matthew Braithwaite | a57dcfb | 2017-02-17 22:08:23 -0800 | [diff] [blame] | 1167 | if (strict) { |
| 1168 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
| 1169 | return 0; |
| 1170 | } |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | /* Check for a multipart rule. */ |
| 1175 | if (ch != '+') { |
| 1176 | break; |
| 1177 | } |
| 1178 | l++; |
| 1179 | multi = 1; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1180 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1181 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1182 | /* Ok, we have the rule, now apply it. */ |
| 1183 | if (rule == CIPHER_SPECIAL) { |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1184 | if (buf_len != 8 || strncmp(buf, "STRENGTH", 8) != 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1185 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1186 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1187 | } |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1188 | if (!ssl_cipher_strength_sort(head_p, tail_p)) { |
Adam Langley | f139c99 | 2016-10-02 09:56:09 -0700 | [diff] [blame] | 1189 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1190 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1191 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1192 | /* We do not support any "multi" options together with "@", so throw away |
| 1193 | * the rest of the command, if any left, until end or ':' is found. */ |
Adam Langley | 22df691 | 2017-07-25 12:27:37 -0700 | [diff] [blame] | 1194 | while (*l != '\0' && !is_cipher_list_separator(*l, strict)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1195 | l++; |
| 1196 | } |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1197 | } else if (!skip_rule) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1198 | ssl_cipher_apply_rule(cipher_id, alg_mkey, alg_auth, alg_enc, alg_mac, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1199 | min_version, rule, -1, in_group, head_p, tail_p); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1200 | } |
| 1201 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1202 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1203 | if (in_group) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1204 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
Adam Langley | f139c99 | 2016-10-02 09:56:09 -0700 | [diff] [blame] | 1205 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1206 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1207 | |
Adam Langley | f139c99 | 2016-10-02 09:56:09 -0700 | [diff] [blame] | 1208 | return 1; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1209 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1210 | |
Matthew Braithwaite | 6ad20dc | 2017-02-21 16:41:33 -0800 | [diff] [blame] | 1211 | int ssl_create_cipher_list( |
| 1212 | const SSL_PROTOCOL_METHOD *ssl_method, |
| 1213 | struct ssl_cipher_preference_list_st **out_cipher_list, |
| 1214 | const char *rule_str, int strict) { |
David Benjamin | d2cb1c1 | 2016-11-02 17:49:09 -0400 | [diff] [blame] | 1215 | STACK_OF(SSL_CIPHER) *cipherstack = NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1216 | CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1217 | uint8_t *in_group_flags = NULL; |
| 1218 | unsigned int num_in_group_flags = 0; |
| 1219 | struct ssl_cipher_preference_list_st *pref_list = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1220 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1221 | /* Return with error if nothing to do. */ |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1222 | if (rule_str == NULL || out_cipher_list == NULL) { |
Matthew Braithwaite | 6ad20dc | 2017-02-21 16:41:33 -0800 | [diff] [blame] | 1223 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1224 | } |
David Benjamin | 5213df4 | 2014-08-20 14:19:54 -0400 | [diff] [blame] | 1225 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1226 | /* Now we have to collect the available ciphers from the compiled in ciphers. |
| 1227 | * We cannot get more than the number compiled in, so it is used for |
| 1228 | * allocation. */ |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1229 | co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * kCiphersLen); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1230 | if (co_list == NULL) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1231 | OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); |
Matthew Braithwaite | 6ad20dc | 2017-02-21 16:41:33 -0800 | [diff] [blame] | 1232 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1233 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1234 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1235 | ssl_cipher_collect_ciphers(ssl_method, co_list, &head, &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1236 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1237 | /* Now arrange all ciphers by preference: |
| 1238 | * TODO(davidben): Compute this order once and copy it. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1239 | |
David Benjamin | abbbee1 | 2016-10-31 19:20:42 -0400 | [diff] [blame] | 1240 | /* Everything else being equal, prefer ECDHE_ECDSA and ECDHE_RSA over other |
| 1241 | * key exchange mechanisms */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1242 | ssl_cipher_apply_rule(0, SSL_kECDHE, SSL_aECDSA, ~0u, ~0u, 0, CIPHER_ADD, -1, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1243 | 0, &head, &tail); |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1244 | ssl_cipher_apply_rule(0, SSL_kECDHE, ~0u, ~0u, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1245 | &head, &tail); |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1246 | ssl_cipher_apply_rule(0, ~0u, ~0u, ~0u, ~0u, 0, CIPHER_DEL, -1, 0, &head, |
| 1247 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1248 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1249 | /* Order the bulk ciphers. First the preferred AEAD ciphers. We prefer |
| 1250 | * CHACHA20 unless there is hardware support for fast and constant-time |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1251 | * AES_GCM. Of the two CHACHA20 variants, the new one is preferred over the |
| 1252 | * old one. */ |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1253 | if (EVP_has_aes_hardware()) { |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1254 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES128GCM, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1255 | &head, &tail); |
David Benjamin | 4333665 | 2016-03-03 15:32:29 -0500 | [diff] [blame] | 1256 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES256GCM, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1257 | &head, &tail); |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1258 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0, CIPHER_ADD, |
| 1259 | -1, 0, &head, &tail); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1260 | } else { |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1261 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0, CIPHER_ADD, |
| 1262 | -1, 0, &head, &tail); |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1263 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES128GCM, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1264 | &head, &tail); |
David Benjamin | 4333665 | 2016-03-03 15:32:29 -0500 | [diff] [blame] | 1265 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES256GCM, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1266 | &head, &tail); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1267 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1268 | |
David Benjamin | 4333665 | 2016-03-03 15:32:29 -0500 | [diff] [blame] | 1269 | /* Then the legacy non-AEAD ciphers: AES_128_CBC, AES_256_CBC, |
Matthew Braithwaite | 8aaa9e1 | 2016-09-07 15:09:58 -0700 | [diff] [blame] | 1270 | * 3DES_EDE_CBC_SHA. */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1271 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES128, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1272 | &head, &tail); |
David Benjamin | 4333665 | 2016-03-03 15:32:29 -0500 | [diff] [blame] | 1273 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES256, ~0u, 0, CIPHER_ADD, -1, 0, |
| 1274 | &head, &tail); |
| 1275 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_3DES, ~0u, 0, CIPHER_ADD, -1, 0, &head, |
| 1276 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1277 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1278 | /* Temporarily enable everything else for sorting */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1279 | ssl_cipher_apply_rule(0, ~0u, ~0u, ~0u, ~0u, 0, CIPHER_ADD, -1, 0, &head, |
| 1280 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1281 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1282 | /* Move ciphers without forward secrecy to the end. */ |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1283 | ssl_cipher_apply_rule(0, (SSL_kRSA | SSL_kPSK), ~0u, ~0u, ~0u, 0, |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1284 | CIPHER_ORD, -1, 0, &head, &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1285 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1286 | /* Now disable everything (maintaining the ordering!) */ |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1287 | ssl_cipher_apply_rule(0, ~0u, ~0u, ~0u, ~0u, 0, CIPHER_DEL, -1, 0, &head, |
| 1288 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1289 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1290 | /* If the rule_string begins with DEFAULT, apply the default rule before |
| 1291 | * using the (possibly available) additional rules. */ |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1292 | const char *rule_p = rule_str; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1293 | if (strncmp(rule_str, "DEFAULT", 7) == 0) { |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1294 | if (!ssl_cipher_process_rulestr(ssl_method, SSL_DEFAULT_CIPHER_LIST, &head, |
Matthew Braithwaite | a57dcfb | 2017-02-17 22:08:23 -0800 | [diff] [blame] | 1295 | &tail, strict)) { |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1296 | goto err; |
| 1297 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1298 | rule_p += 7; |
| 1299 | if (*rule_p == ':') { |
| 1300 | rule_p++; |
| 1301 | } |
| 1302 | } |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1303 | |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1304 | if (*rule_p != '\0' && |
Matthew Braithwaite | a57dcfb | 2017-02-17 22:08:23 -0800 | [diff] [blame] | 1305 | !ssl_cipher_process_rulestr(ssl_method, rule_p, &head, &tail, strict)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1306 | goto err; |
| 1307 | } |
| 1308 | |
| 1309 | /* Allocate new "cipherstack" for the result, return with error |
| 1310 | * if we cannot get one. */ |
| 1311 | cipherstack = sk_SSL_CIPHER_new_null(); |
| 1312 | if (cipherstack == NULL) { |
| 1313 | goto err; |
| 1314 | } |
| 1315 | |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1316 | in_group_flags = (uint8_t *)OPENSSL_malloc(kCiphersLen); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1317 | if (!in_group_flags) { |
| 1318 | goto err; |
| 1319 | } |
| 1320 | |
| 1321 | /* The cipher selection for the list is done. The ciphers are added |
| 1322 | * to the resulting precedence to the STACK_OF(SSL_CIPHER). */ |
| 1323 | for (curr = head; curr != NULL; curr = curr->next) { |
| 1324 | if (curr->active) { |
David Benjamin | 2adb7ec | 2015-01-11 19:59:06 -0500 | [diff] [blame] | 1325 | if (!sk_SSL_CIPHER_push(cipherstack, curr->cipher)) { |
| 1326 | goto err; |
| 1327 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1328 | in_group_flags[num_in_group_flags++] = curr->in_group; |
| 1329 | } |
| 1330 | } |
| 1331 | OPENSSL_free(co_list); /* Not needed any longer */ |
| 1332 | co_list = NULL; |
| 1333 | |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1334 | pref_list = (ssl_cipher_preference_list_st *)OPENSSL_malloc( |
| 1335 | sizeof(struct ssl_cipher_preference_list_st)); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1336 | if (!pref_list) { |
| 1337 | goto err; |
| 1338 | } |
| 1339 | pref_list->ciphers = cipherstack; |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1340 | pref_list->in_group_flags = (uint8_t *)OPENSSL_malloc(num_in_group_flags); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1341 | if (!pref_list->in_group_flags) { |
| 1342 | goto err; |
| 1343 | } |
David Benjamin | 17cf2cb | 2016-12-13 01:07:13 -0500 | [diff] [blame] | 1344 | OPENSSL_memcpy(pref_list->in_group_flags, in_group_flags, num_in_group_flags); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1345 | OPENSSL_free(in_group_flags); |
| 1346 | in_group_flags = NULL; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1347 | if (*out_cipher_list != NULL) { |
| 1348 | ssl_cipher_preference_list_free(*out_cipher_list); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1349 | } |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1350 | *out_cipher_list = pref_list; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1351 | pref_list = NULL; |
| 1352 | |
David Benjamin | 91222b8 | 2017-03-09 20:10:56 -0500 | [diff] [blame] | 1353 | /* Configuring an empty cipher list is an error but still updates the |
| 1354 | * output. */ |
| 1355 | if (sk_SSL_CIPHER_num((*out_cipher_list)->ciphers) == 0) { |
| 1356 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH); |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
Matthew Braithwaite | 6ad20dc | 2017-02-21 16:41:33 -0800 | [diff] [blame] | 1360 | return 1; |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1361 | |
| 1362 | err: |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1363 | OPENSSL_free(co_list); |
| 1364 | OPENSSL_free(in_group_flags); |
| 1365 | sk_SSL_CIPHER_free(cipherstack); |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1366 | if (pref_list) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1367 | OPENSSL_free(pref_list->in_group_flags); |
| 1368 | } |
David Benjamin | 2755a3e | 2015-04-22 16:17:58 -0400 | [diff] [blame] | 1369 | OPENSSL_free(pref_list); |
Matthew Braithwaite | 6ad20dc | 2017-02-21 16:41:33 -0800 | [diff] [blame] | 1370 | return 0; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1371 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1372 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1373 | uint16_t ssl_cipher_get_value(const SSL_CIPHER *cipher) { |
| 1374 | uint32_t id = cipher->id; |
| 1375 | /* All ciphers are SSLv3. */ |
| 1376 | assert((id & 0xff000000) == 0x03000000); |
| 1377 | return id & 0xffff; |
| 1378 | } |
| 1379 | |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1380 | uint32_t ssl_cipher_auth_mask_for_key(const EVP_PKEY *key) { |
| 1381 | switch (EVP_PKEY_id(key)) { |
| 1382 | case EVP_PKEY_RSA: |
| 1383 | return SSL_aRSA; |
| 1384 | case EVP_PKEY_EC: |
| 1385 | case EVP_PKEY_ED25519: |
| 1386 | /* Ed25519 keys in TLS 1.2 repurpose the ECDSA ciphers. */ |
| 1387 | return SSL_aECDSA; |
| 1388 | default: |
| 1389 | return 0; |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | int ssl_cipher_uses_certificate_auth(const SSL_CIPHER *cipher) { |
| 1394 | return (cipher->algorithm_auth & SSL_aCERT) != 0; |
| 1395 | } |
| 1396 | |
| 1397 | int ssl_cipher_requires_server_key_exchange(const SSL_CIPHER *cipher) { |
| 1398 | /* Ephemeral Diffie-Hellman key exchanges require a ServerKeyExchange. */ |
| 1399 | if (cipher->algorithm_mkey & SSL_kECDHE) { |
| 1400 | return 1; |
| 1401 | } |
| 1402 | |
| 1403 | /* It is optional in all others. */ |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | size_t ssl_cipher_get_record_split_len(const SSL_CIPHER *cipher) { |
| 1408 | size_t block_size; |
| 1409 | switch (cipher->algorithm_enc) { |
| 1410 | case SSL_3DES: |
| 1411 | block_size = 8; |
| 1412 | break; |
| 1413 | case SSL_AES128: |
| 1414 | case SSL_AES256: |
| 1415 | block_size = 16; |
| 1416 | break; |
| 1417 | default: |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | /* All supported TLS 1.0 ciphers use SHA-1. */ |
| 1422 | assert(cipher->algorithm_mac == SSL_SHA1); |
| 1423 | size_t ret = 1 + SHA_DIGEST_LENGTH; |
| 1424 | ret += block_size - (ret % block_size); |
| 1425 | return ret; |
| 1426 | } |
| 1427 | |
| 1428 | } // namespace bssl |
| 1429 | |
| 1430 | using namespace bssl; |
| 1431 | |
| 1432 | const SSL_CIPHER *SSL_get_cipher_by_value(uint16_t value) { |
| 1433 | SSL_CIPHER c; |
| 1434 | |
| 1435 | c.id = 0x03000000L | value; |
| 1436 | return reinterpret_cast<const SSL_CIPHER *>(bsearch( |
| 1437 | &c, kCiphers, kCiphersLen, sizeof(SSL_CIPHER), ssl_cipher_id_cmp)); |
| 1438 | } |
| 1439 | |
| 1440 | uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *cipher) { return cipher->id; } |
| 1441 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1442 | int SSL_CIPHER_is_AES(const SSL_CIPHER *cipher) { |
| 1443 | return (cipher->algorithm_enc & SSL_AES) != 0; |
| 1444 | } |
| 1445 | |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1446 | int SSL_CIPHER_has_SHA1_HMAC(const SSL_CIPHER *cipher) { |
| 1447 | return (cipher->algorithm_mac & SSL_SHA1) != 0; |
| 1448 | } |
| 1449 | |
David Benjamin | a211aee | 2016-02-24 17:18:44 -0500 | [diff] [blame] | 1450 | int SSL_CIPHER_has_SHA256_HMAC(const SSL_CIPHER *cipher) { |
| 1451 | return (cipher->algorithm_mac & SSL_SHA256) != 0; |
| 1452 | } |
| 1453 | |
Alessandro Ghedini | 48b6b8f | 2017-05-12 12:53:31 +0100 | [diff] [blame] | 1454 | int SSL_CIPHER_has_SHA384_HMAC(const SSL_CIPHER *cipher) { |
| 1455 | return (cipher->algorithm_mac & SSL_SHA384) != 0; |
| 1456 | } |
| 1457 | |
David Benjamin | 348f0d8 | 2017-08-10 16:06:27 -0400 | [diff] [blame^] | 1458 | int SSL_CIPHER_is_aead(const SSL_CIPHER *cipher) { |
Alessandro Ghedini | 0726fb7 | 2017-01-17 13:27:08 +0000 | [diff] [blame] | 1459 | return (cipher->algorithm_mac & SSL_AEAD) != 0; |
| 1460 | } |
| 1461 | |
David Benjamin | 348f0d8 | 2017-08-10 16:06:27 -0400 | [diff] [blame^] | 1462 | int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *cipher) { |
| 1463 | switch (cipher->algorithm_enc) { |
| 1464 | case SSL_eNULL: |
| 1465 | return NID_undef; |
| 1466 | case SSL_3DES: |
| 1467 | return NID_des_ede3_cbc; |
| 1468 | case SSL_AES128: |
| 1469 | return NID_aes_128_cbc; |
| 1470 | case SSL_AES256: |
| 1471 | return NID_aes_256_cbc; |
| 1472 | case SSL_AES128GCM: |
| 1473 | return NID_aes_128_gcm; |
| 1474 | case SSL_AES256GCM: |
| 1475 | return NID_aes_256_gcm; |
| 1476 | case SSL_CHACHA20POLY1305: |
| 1477 | return NID_chacha20_poly1305; |
| 1478 | } |
| 1479 | assert(0); |
| 1480 | return NID_undef; |
| 1481 | } |
| 1482 | |
| 1483 | int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *cipher) { |
| 1484 | switch (cipher->algorithm_mac) { |
| 1485 | case SSL_AEAD: |
| 1486 | return NID_undef; |
| 1487 | case SSL_SHA1: |
| 1488 | return NID_sha1; |
| 1489 | case SSL_SHA256: |
| 1490 | return NID_sha256; |
| 1491 | case SSL_SHA384: |
| 1492 | return NID_sha384; |
| 1493 | } |
| 1494 | assert(0); |
| 1495 | return NID_undef; |
| 1496 | } |
| 1497 | |
| 1498 | int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *cipher) { |
| 1499 | switch (cipher->algorithm_mkey) { |
| 1500 | case SSL_kRSA: |
| 1501 | return NID_kx_rsa; |
| 1502 | case SSL_kECDHE: |
| 1503 | return NID_kx_ecdhe; |
| 1504 | case SSL_kPSK: |
| 1505 | return NID_kx_psk; |
| 1506 | case SSL_kGENERIC: |
| 1507 | return NID_kx_any; |
| 1508 | } |
| 1509 | assert(0); |
| 1510 | return NID_undef; |
| 1511 | } |
| 1512 | |
| 1513 | int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *cipher) { |
| 1514 | switch (cipher->algorithm_auth) { |
| 1515 | case SSL_aRSA: |
| 1516 | return NID_auth_rsa; |
| 1517 | case SSL_aECDSA: |
| 1518 | return NID_auth_ecdsa; |
| 1519 | case SSL_aPSK: |
| 1520 | return NID_auth_psk; |
| 1521 | case SSL_aGENERIC: |
| 1522 | return NID_auth_any; |
| 1523 | } |
| 1524 | assert(0); |
| 1525 | return NID_undef; |
| 1526 | } |
| 1527 | |
| 1528 | int SSL_CIPHER_is_AEAD(const SSL_CIPHER *cipher) { |
| 1529 | return SSL_CIPHER_is_aead(cipher); |
| 1530 | } |
| 1531 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1532 | int SSL_CIPHER_is_AESGCM(const SSL_CIPHER *cipher) { |
David Benjamin | c0125ef | 2015-09-09 09:11:07 -0400 | [diff] [blame] | 1533 | return (cipher->algorithm_enc & (SSL_AES128GCM | SSL_AES256GCM)) != 0; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1534 | } |
| 1535 | |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1536 | int SSL_CIPHER_is_AES128GCM(const SSL_CIPHER *cipher) { |
| 1537 | return (cipher->algorithm_enc & SSL_AES128GCM) != 0; |
| 1538 | } |
| 1539 | |
Adam Langley | b00061c | 2015-11-16 17:44:52 -0800 | [diff] [blame] | 1540 | int SSL_CIPHER_is_AES128CBC(const SSL_CIPHER *cipher) { |
| 1541 | return (cipher->algorithm_enc & SSL_AES128) != 0; |
| 1542 | } |
| 1543 | |
| 1544 | int SSL_CIPHER_is_AES256CBC(const SSL_CIPHER *cipher) { |
| 1545 | return (cipher->algorithm_enc & SSL_AES256) != 0; |
| 1546 | } |
| 1547 | |
David Benjamin | 51a01a5 | 2015-10-29 13:19:56 -0400 | [diff] [blame] | 1548 | int SSL_CIPHER_is_CHACHA20POLY1305(const SSL_CIPHER *cipher) { |
Adam Langley | 2e83924 | 2017-01-19 15:12:44 -0800 | [diff] [blame] | 1549 | return (cipher->algorithm_enc & SSL_CHACHA20POLY1305) != 0; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1550 | } |
| 1551 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1552 | int SSL_CIPHER_is_NULL(const SSL_CIPHER *cipher) { |
| 1553 | return (cipher->algorithm_enc & SSL_eNULL) != 0; |
| 1554 | } |
| 1555 | |
| 1556 | int SSL_CIPHER_is_block_cipher(const SSL_CIPHER *cipher) { |
Matthew Braithwaite | 8aaa9e1 | 2016-09-07 15:09:58 -0700 | [diff] [blame] | 1557 | return (cipher->algorithm_enc & SSL_eNULL) == 0 && |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1558 | cipher->algorithm_mac != SSL_AEAD; |
| 1559 | } |
| 1560 | |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1561 | int SSL_CIPHER_is_ECDSA(const SSL_CIPHER *cipher) { |
| 1562 | return (cipher->algorithm_auth & SSL_aECDSA) != 0; |
| 1563 | } |
| 1564 | |
David Benjamin | 4cc36ad | 2015-12-19 14:23:26 -0500 | [diff] [blame] | 1565 | int SSL_CIPHER_is_ECDHE(const SSL_CIPHER *cipher) { |
| 1566 | return (cipher->algorithm_mkey & SSL_kECDHE) != 0; |
| 1567 | } |
| 1568 | |
David Benjamin | 745745d | 2017-01-10 08:34:14 -0500 | [diff] [blame] | 1569 | int SSL_CIPHER_is_static_RSA(const SSL_CIPHER *cipher) { |
| 1570 | return (cipher->algorithm_mkey & SSL_kRSA) != 0; |
| 1571 | } |
| 1572 | |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1573 | uint16_t SSL_CIPHER_get_min_version(const SSL_CIPHER *cipher) { |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1574 | if (cipher->algorithm_mkey == SSL_kGENERIC || |
| 1575 | cipher->algorithm_auth == SSL_aGENERIC) { |
| 1576 | return TLS1_3_VERSION; |
| 1577 | } |
| 1578 | |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1579 | if (cipher->algorithm_prf != SSL_HANDSHAKE_MAC_DEFAULT) { |
| 1580 | /* Cipher suites before TLS 1.2 use the default PRF, while all those added |
| 1581 | * afterwards specify a particular hash. */ |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1582 | return TLS1_2_VERSION; |
| 1583 | } |
| 1584 | return SSL3_VERSION; |
| 1585 | } |
| 1586 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1587 | uint16_t SSL_CIPHER_get_max_version(const SSL_CIPHER *cipher) { |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1588 | if (cipher->algorithm_mkey == SSL_kGENERIC || |
| 1589 | cipher->algorithm_auth == SSL_aGENERIC) { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1590 | return TLS1_3_VERSION; |
| 1591 | } |
| 1592 | return TLS1_2_VERSION; |
| 1593 | } |
| 1594 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1595 | /* return the actual cipher being used */ |
| 1596 | const char *SSL_CIPHER_get_name(const SSL_CIPHER *cipher) { |
| 1597 | if (cipher != NULL) { |
| 1598 | return cipher->name; |
| 1599 | } |
| 1600 | |
| 1601 | return "(NONE)"; |
| 1602 | } |
| 1603 | |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 1604 | const char *SSL_CIPHER_standard_name(const SSL_CIPHER *cipher) { |
| 1605 | return cipher->standard_name; |
| 1606 | } |
| 1607 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1608 | const char *SSL_CIPHER_get_kx_name(const SSL_CIPHER *cipher) { |
| 1609 | if (cipher == NULL) { |
| 1610 | return ""; |
| 1611 | } |
| 1612 | |
| 1613 | switch (cipher->algorithm_mkey) { |
| 1614 | case SSL_kRSA: |
| 1615 | return "RSA"; |
| 1616 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1617 | case SSL_kECDHE: |
| 1618 | switch (cipher->algorithm_auth) { |
| 1619 | case SSL_aECDSA: |
| 1620 | return "ECDHE_ECDSA"; |
| 1621 | case SSL_aRSA: |
| 1622 | return "ECDHE_RSA"; |
| 1623 | case SSL_aPSK: |
| 1624 | return "ECDHE_PSK"; |
| 1625 | default: |
| 1626 | assert(0); |
| 1627 | return "UNKNOWN"; |
| 1628 | } |
| 1629 | |
| 1630 | case SSL_kPSK: |
| 1631 | assert(cipher->algorithm_auth == SSL_aPSK); |
| 1632 | return "PSK"; |
| 1633 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1634 | case SSL_kGENERIC: |
| 1635 | assert(cipher->algorithm_auth == SSL_aGENERIC); |
| 1636 | return "GENERIC"; |
| 1637 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1638 | default: |
| 1639 | assert(0); |
| 1640 | return "UNKNOWN"; |
| 1641 | } |
| 1642 | } |
| 1643 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1644 | char *SSL_CIPHER_get_rfc_name(const SSL_CIPHER *cipher) { |
| 1645 | if (cipher == NULL) { |
| 1646 | return NULL; |
| 1647 | } |
| 1648 | |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 1649 | return OPENSSL_strdup(SSL_CIPHER_standard_name(cipher)); |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | int SSL_CIPHER_get_bits(const SSL_CIPHER *cipher, int *out_alg_bits) { |
| 1653 | if (cipher == NULL) { |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1657 | int alg_bits, strength_bits; |
| 1658 | switch (cipher->algorithm_enc) { |
| 1659 | case SSL_AES128: |
| 1660 | case SSL_AES128GCM: |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1661 | alg_bits = 128; |
| 1662 | strength_bits = 128; |
| 1663 | break; |
| 1664 | |
| 1665 | case SSL_AES256: |
| 1666 | case SSL_AES256GCM: |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1667 | case SSL_CHACHA20POLY1305: |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1668 | alg_bits = 256; |
| 1669 | strength_bits = 256; |
| 1670 | break; |
| 1671 | |
| 1672 | case SSL_3DES: |
| 1673 | alg_bits = 168; |
| 1674 | strength_bits = 112; |
| 1675 | break; |
| 1676 | |
| 1677 | case SSL_eNULL: |
| 1678 | alg_bits = 0; |
| 1679 | strength_bits = 0; |
| 1680 | break; |
| 1681 | |
| 1682 | default: |
| 1683 | assert(0); |
| 1684 | alg_bits = 0; |
| 1685 | strength_bits = 0; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1686 | } |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1687 | |
| 1688 | if (out_alg_bits != NULL) { |
| 1689 | *out_alg_bits = alg_bits; |
| 1690 | } |
| 1691 | return strength_bits; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1694 | const char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, |
| 1695 | int len) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1696 | const char *kx, *au, *enc, *mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1697 | uint32_t alg_mkey, alg_auth, alg_enc, alg_mac; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1698 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1699 | alg_mkey = cipher->algorithm_mkey; |
| 1700 | alg_auth = cipher->algorithm_auth; |
| 1701 | alg_enc = cipher->algorithm_enc; |
| 1702 | alg_mac = cipher->algorithm_mac; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1703 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1704 | switch (alg_mkey) { |
| 1705 | case SSL_kRSA: |
| 1706 | kx = "RSA"; |
| 1707 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1708 | |
David Benjamin | 7061e28 | 2015-03-19 11:10:48 -0400 | [diff] [blame] | 1709 | case SSL_kECDHE: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1710 | kx = "ECDH"; |
| 1711 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1712 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1713 | case SSL_kPSK: |
| 1714 | kx = "PSK"; |
| 1715 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1716 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1717 | case SSL_kGENERIC: |
| 1718 | kx = "GENERIC"; |
| 1719 | break; |
| 1720 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1721 | default: |
| 1722 | kx = "unknown"; |
| 1723 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1724 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1725 | switch (alg_auth) { |
| 1726 | case SSL_aRSA: |
| 1727 | au = "RSA"; |
| 1728 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1729 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1730 | case SSL_aECDSA: |
| 1731 | au = "ECDSA"; |
| 1732 | break; |
Adam Langley | 4d4bff8 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1733 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1734 | case SSL_aPSK: |
| 1735 | au = "PSK"; |
| 1736 | break; |
Adam Langley | 4d4bff8 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1737 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1738 | case SSL_aGENERIC: |
| 1739 | au = "GENERIC"; |
| 1740 | break; |
| 1741 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1742 | default: |
| 1743 | au = "unknown"; |
| 1744 | break; |
| 1745 | } |
Adam Langley | de0b202 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1746 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1747 | switch (alg_enc) { |
| 1748 | case SSL_3DES: |
| 1749 | enc = "3DES(168)"; |
| 1750 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1751 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1752 | case SSL_AES128: |
| 1753 | enc = "AES(128)"; |
| 1754 | break; |
| 1755 | |
| 1756 | case SSL_AES256: |
| 1757 | enc = "AES(256)"; |
| 1758 | break; |
| 1759 | |
| 1760 | case SSL_AES128GCM: |
| 1761 | enc = "AESGCM(128)"; |
| 1762 | break; |
| 1763 | |
| 1764 | case SSL_AES256GCM: |
| 1765 | enc = "AESGCM(256)"; |
| 1766 | break; |
| 1767 | |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1768 | case SSL_CHACHA20POLY1305: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1769 | enc = "ChaCha20-Poly1305"; |
| 1770 | break; |
| 1771 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1772 | case SSL_eNULL: |
| 1773 | enc="None"; |
| 1774 | break; |
| 1775 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1776 | default: |
| 1777 | enc = "unknown"; |
| 1778 | break; |
| 1779 | } |
| 1780 | |
| 1781 | switch (alg_mac) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1782 | case SSL_SHA1: |
| 1783 | mac = "SHA1"; |
| 1784 | break; |
| 1785 | |
| 1786 | case SSL_SHA256: |
| 1787 | mac = "SHA256"; |
| 1788 | break; |
| 1789 | |
| 1790 | case SSL_SHA384: |
| 1791 | mac = "SHA384"; |
| 1792 | break; |
| 1793 | |
| 1794 | case SSL_AEAD: |
| 1795 | mac = "AEAD"; |
| 1796 | break; |
| 1797 | |
| 1798 | default: |
| 1799 | mac = "unknown"; |
| 1800 | break; |
| 1801 | } |
| 1802 | |
| 1803 | if (buf == NULL) { |
| 1804 | len = 128; |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1805 | buf = (char *)OPENSSL_malloc(len); |
David Benjamin | 1eed2c0 | 2015-02-08 23:20:06 -0500 | [diff] [blame] | 1806 | if (buf == NULL) { |
| 1807 | return NULL; |
| 1808 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1809 | } else if (len < 128) { |
| 1810 | return "Buffer too small"; |
| 1811 | } |
| 1812 | |
Brian Smith | 0687bdf | 2016-01-17 09:18:26 -1000 | [diff] [blame] | 1813 | BIO_snprintf(buf, len, "%-23s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n", |
| 1814 | cipher->name, kx, au, enc, mac); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1815 | return buf; |
| 1816 | } |
| 1817 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1818 | const char *SSL_CIPHER_get_version(const SSL_CIPHER *cipher) { |
| 1819 | return "TLSv1/SSLv3"; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1820 | } |
| 1821 | |
David Benjamin | d55bd79 | 2017-05-18 11:33:08 -0400 | [diff] [blame] | 1822 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void) { return NULL; } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1823 | |
Matt Braithwaite | 6a1275b | 2015-06-26 12:09:10 -0700 | [diff] [blame] | 1824 | int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) { return 1; } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1825 | |
Matt Braithwaite | 6a1275b | 2015-06-26 12:09:10 -0700 | [diff] [blame] | 1826 | const char *SSL_COMP_get_name(const COMP_METHOD *comp) { return NULL; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1827 | |
Adam Langley | 3e9e043 | 2016-10-03 15:58:07 -0700 | [diff] [blame] | 1828 | void SSL_COMP_free_compression_methods(void) {} |