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. |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 7 | * |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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). |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 14 | * |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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. |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 21 | * |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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 :-). |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 39 | * |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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. |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 51 | * |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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 |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 65 | * notice, this list of conditions and the following disclaimer. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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. |
Adam Langley | e745b25 | 2018-02-26 14:02:17 -0800 | [diff] [blame] | 112 | * ECC cipher suite support in OpenSSL originally developed by |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 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 | f0ae170 | 2015-04-07 23:05:04 -0400 | [diff] [blame] | 146 | #include <openssl/err.h> |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 147 | #include <openssl/md5.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 148 | #include <openssl/mem.h> |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 149 | #include <openssl/sha.h> |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 150 | #include <openssl/stack.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 151 | |
David Benjamin | 2ee94aa | 2015-04-07 22:38:30 -0400 | [diff] [blame] | 152 | #include "internal.h" |
Steven Valdez | cb96654 | 2016-08-17 16:56:14 -0400 | [diff] [blame] | 153 | #include "../crypto/internal.h" |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 154 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 155 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 156 | BSSL_NAMESPACE_BEGIN |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 157 | |
MichaĆ Janiszewski | c4f3b8a | 2018-07-30 22:50:40 +0200 | [diff] [blame] | 158 | static constexpr SSL_CIPHER kCiphers[] = { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 159 | // The RSA ciphers |
| 160 | // Cipher 02 |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 161 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 162 | SSL3_TXT_RSA_NULL_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 163 | "TLS_RSA_WITH_NULL_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 164 | SSL3_CK_RSA_NULL_SHA, |
| 165 | SSL_kRSA, |
| 166 | SSL_aRSA, |
| 167 | SSL_eNULL, |
| 168 | SSL_SHA1, |
| 169 | SSL_HANDSHAKE_MAC_DEFAULT, |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 170 | }, |
| 171 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 172 | // Cipher 0A |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 173 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 174 | SSL3_TXT_RSA_DES_192_CBC3_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 175 | "TLS_RSA_WITH_3DES_EDE_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 176 | SSL3_CK_RSA_DES_192_CBC3_SHA, |
| 177 | SSL_kRSA, |
| 178 | SSL_aRSA, |
| 179 | SSL_3DES, |
| 180 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 181 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 182 | }, |
| 183 | |
| 184 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 185 | // New AES ciphersuites |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 186 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 187 | // Cipher 2F |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 188 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 189 | TLS1_TXT_RSA_WITH_AES_128_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 190 | "TLS_RSA_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 191 | TLS1_CK_RSA_WITH_AES_128_SHA, |
| 192 | SSL_kRSA, |
| 193 | SSL_aRSA, |
| 194 | SSL_AES128, |
| 195 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 196 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 197 | }, |
| 198 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 199 | // Cipher 35 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 200 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 201 | TLS1_TXT_RSA_WITH_AES_256_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 202 | "TLS_RSA_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 203 | TLS1_CK_RSA_WITH_AES_256_SHA, |
| 204 | SSL_kRSA, |
| 205 | SSL_aRSA, |
| 206 | SSL_AES256, |
| 207 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 208 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 209 | }, |
| 210 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 211 | // PSK cipher suites. |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 212 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 213 | // Cipher 8C |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 214 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 215 | TLS1_TXT_PSK_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 216 | "TLS_PSK_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 217 | TLS1_CK_PSK_WITH_AES_128_CBC_SHA, |
| 218 | SSL_kPSK, |
| 219 | SSL_aPSK, |
| 220 | SSL_AES128, |
| 221 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 222 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 223 | }, |
| 224 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 225 | // Cipher 8D |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 226 | { |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 227 | TLS1_TXT_PSK_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 228 | "TLS_PSK_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 229 | TLS1_CK_PSK_WITH_AES_256_CBC_SHA, |
| 230 | SSL_kPSK, |
| 231 | SSL_aPSK, |
| 232 | SSL_AES256, |
| 233 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 234 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 235 | }, |
| 236 | |
David Benjamin | 8648c53 | 2021-08-19 18:02:37 -0400 | [diff] [blame] | 237 | // GCM ciphersuites from RFC 5288 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 238 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 239 | // Cipher 9C |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 240 | { |
| 241 | TLS1_TXT_RSA_WITH_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 242 | "TLS_RSA_WITH_AES_128_GCM_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 243 | TLS1_CK_RSA_WITH_AES_128_GCM_SHA256, |
| 244 | SSL_kRSA, |
| 245 | SSL_aRSA, |
| 246 | SSL_AES128GCM, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 247 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 248 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 249 | }, |
| 250 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 251 | // Cipher 9D |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 252 | { |
| 253 | TLS1_TXT_RSA_WITH_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 254 | "TLS_RSA_WITH_AES_256_GCM_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 255 | TLS1_CK_RSA_WITH_AES_256_GCM_SHA384, |
| 256 | SSL_kRSA, |
| 257 | SSL_aRSA, |
| 258 | SSL_AES256GCM, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 259 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 260 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 261 | }, |
| 262 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 263 | // TLS 1.3 suites. |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 264 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 265 | // Cipher 1301 |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 266 | { |
Bob Beck | a6981a3 | 2022-07-19 09:20:50 -0600 | [diff] [blame] | 267 | TLS1_3_RFC_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 268 | "TLS_AES_128_GCM_SHA256", |
David Benjamin | dfddbc4 | 2022-07-18 16:08:06 -0400 | [diff] [blame] | 269 | TLS1_3_CK_AES_128_GCM_SHA256, |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 270 | SSL_kGENERIC, |
| 271 | SSL_aGENERIC, |
| 272 | SSL_AES128GCM, |
| 273 | SSL_AEAD, |
| 274 | SSL_HANDSHAKE_MAC_SHA256, |
| 275 | }, |
| 276 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 277 | // Cipher 1302 |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 278 | { |
Bob Beck | a6981a3 | 2022-07-19 09:20:50 -0600 | [diff] [blame] | 279 | TLS1_3_RFC_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 280 | "TLS_AES_256_GCM_SHA384", |
David Benjamin | dfddbc4 | 2022-07-18 16:08:06 -0400 | [diff] [blame] | 281 | TLS1_3_CK_AES_256_GCM_SHA384, |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 282 | SSL_kGENERIC, |
| 283 | SSL_aGENERIC, |
| 284 | SSL_AES256GCM, |
| 285 | SSL_AEAD, |
| 286 | SSL_HANDSHAKE_MAC_SHA384, |
| 287 | }, |
| 288 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 289 | // Cipher 1303 |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 290 | { |
Bob Beck | a6981a3 | 2022-07-19 09:20:50 -0600 | [diff] [blame] | 291 | TLS1_3_RFC_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 292 | "TLS_CHACHA20_POLY1305_SHA256", |
David Benjamin | dfddbc4 | 2022-07-18 16:08:06 -0400 | [diff] [blame] | 293 | TLS1_3_CK_CHACHA20_POLY1305_SHA256, |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 294 | SSL_kGENERIC, |
| 295 | SSL_aGENERIC, |
| 296 | SSL_CHACHA20POLY1305, |
| 297 | SSL_AEAD, |
| 298 | SSL_HANDSHAKE_MAC_SHA256, |
| 299 | }, |
| 300 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 301 | // Cipher C009 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 302 | { |
| 303 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 304 | "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 305 | TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, |
| 306 | SSL_kECDHE, |
| 307 | SSL_aECDSA, |
| 308 | SSL_AES128, |
| 309 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 310 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 311 | }, |
| 312 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 313 | // Cipher C00A |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 314 | { |
| 315 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 316 | "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 317 | TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, |
| 318 | SSL_kECDHE, |
| 319 | SSL_aECDSA, |
| 320 | SSL_AES256, |
| 321 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 322 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 323 | }, |
| 324 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 325 | // Cipher C013 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 326 | { |
| 327 | TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 328 | "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 329 | TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA, |
| 330 | SSL_kECDHE, |
| 331 | SSL_aRSA, |
| 332 | SSL_AES128, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 333 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 334 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 335 | }, |
| 336 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 337 | // Cipher C014 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 338 | { |
| 339 | TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 340 | "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 341 | TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA, |
| 342 | SSL_kECDHE, |
| 343 | SSL_aRSA, |
| 344 | SSL_AES256, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 345 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 346 | SSL_HANDSHAKE_MAC_DEFAULT, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 347 | }, |
| 348 | |
David Benjamin | 8648c53 | 2021-08-19 18:02:37 -0400 | [diff] [blame] | 349 | // GCM based TLS v1.2 ciphersuites from RFC 5289 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 350 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 351 | // Cipher C02B |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 352 | { |
| 353 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 354 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 355 | TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 356 | SSL_kECDHE, |
| 357 | SSL_aECDSA, |
| 358 | SSL_AES128GCM, |
| 359 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 360 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 361 | }, |
| 362 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 363 | // Cipher C02C |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 364 | { |
| 365 | TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 366 | "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 367 | TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
| 368 | SSL_kECDHE, |
| 369 | SSL_aECDSA, |
| 370 | SSL_AES256GCM, |
| 371 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 372 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 373 | }, |
| 374 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 375 | // Cipher C02F |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 376 | { |
| 377 | TLS1_TXT_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 378 | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 379 | TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 380 | SSL_kECDHE, |
| 381 | SSL_aRSA, |
| 382 | SSL_AES128GCM, |
| 383 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 384 | SSL_HANDSHAKE_MAC_SHA256, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 385 | }, |
| 386 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 387 | // Cipher C030 |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 388 | { |
| 389 | TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 390 | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 391 | TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 392 | SSL_kECDHE, |
| 393 | SSL_aRSA, |
| 394 | SSL_AES256GCM, |
| 395 | SSL_AEAD, |
David Benjamin | b2a985b | 2015-06-21 15:13:57 -0400 | [diff] [blame] | 396 | SSL_HANDSHAKE_MAC_SHA384, |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 397 | }, |
| 398 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 399 | // ECDHE-PSK cipher suites. |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 400 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 401 | // Cipher C035 |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 402 | { |
| 403 | TLS1_TXT_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 404 | "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA", |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 405 | TLS1_CK_ECDHE_PSK_WITH_AES_128_CBC_SHA, |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 406 | SSL_kECDHE, |
| 407 | SSL_aPSK, |
| 408 | SSL_AES128, |
| 409 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 410 | SSL_HANDSHAKE_MAC_DEFAULT, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 411 | }, |
| 412 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 413 | // Cipher C036 |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 414 | { |
| 415 | TLS1_TXT_ECDHE_PSK_WITH_AES_256_CBC_SHA, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 416 | "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA", |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 417 | TLS1_CK_ECDHE_PSK_WITH_AES_256_CBC_SHA, |
David Benjamin | ff2df33 | 2015-11-18 10:01:16 -0500 | [diff] [blame] | 418 | SSL_kECDHE, |
| 419 | SSL_aPSK, |
| 420 | SSL_AES256, |
| 421 | SSL_SHA1, |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 422 | SSL_HANDSHAKE_MAC_DEFAULT, |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 423 | }, |
| 424 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 425 | // ChaCha20-Poly1305 cipher suites. |
Adam Langley | 85bc560 | 2015-06-09 09:54:04 -0700 | [diff] [blame] | 426 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 427 | // Cipher CCA8 |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 428 | { |
| 429 | TLS1_TXT_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 430 | "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 431 | TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, |
| 432 | SSL_kECDHE, |
| 433 | SSL_aRSA, |
| 434 | SSL_CHACHA20POLY1305, |
| 435 | SSL_AEAD, |
| 436 | SSL_HANDSHAKE_MAC_SHA256, |
| 437 | }, |
| 438 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 439 | // Cipher CCA9 |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 440 | { |
| 441 | TLS1_TXT_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 442 | "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 443 | TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, |
| 444 | SSL_kECDHE, |
| 445 | SSL_aECDSA, |
| 446 | SSL_CHACHA20POLY1305, |
| 447 | SSL_AEAD, |
| 448 | SSL_HANDSHAKE_MAC_SHA256, |
| 449 | }, |
| 450 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 451 | // Cipher CCAB |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 452 | { |
| 453 | TLS1_TXT_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 454 | "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256", |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 455 | TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, |
| 456 | SSL_kECDHE, |
| 457 | SSL_aPSK, |
| 458 | SSL_CHACHA20POLY1305, |
| 459 | SSL_AEAD, |
| 460 | SSL_HANDSHAKE_MAC_SHA256, |
| 461 | }, |
Matt Braithwaite | 053931e | 2016-05-25 12:06:05 -0700 | [diff] [blame] | 462 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 463 | }; |
| 464 | |
Matthew Braithwaite | d2ed382 | 2018-07-10 16:27:22 -0700 | [diff] [blame] | 465 | Span<const SSL_CIPHER> AllCiphers() { |
| 466 | return MakeConstSpan(kCiphers, OPENSSL_ARRAY_SIZE(kCiphers)); |
| 467 | } |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 468 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 469 | #define CIPHER_ADD 1 |
| 470 | #define CIPHER_KILL 2 |
| 471 | #define CIPHER_DEL 3 |
| 472 | #define CIPHER_ORD 4 |
| 473 | #define CIPHER_SPECIAL 5 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 474 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 475 | typedef struct cipher_order_st { |
| 476 | const SSL_CIPHER *cipher; |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 477 | bool active; |
| 478 | bool in_group; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 479 | struct cipher_order_st *next, *prev; |
| 480 | } CIPHER_ORDER; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 481 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 482 | typedef struct cipher_alias_st { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 483 | // name is the name of the cipher alias. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 484 | const char *name; |
| 485 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 486 | // The following fields are bitmasks for the corresponding fields on |
| 487 | // |SSL_CIPHER|. A cipher matches a cipher alias iff, for each bitmask, the |
| 488 | // bit corresponding to the cipher's value is set to 1. If any bitmask is |
| 489 | // all zeroes, the alias matches nothing. Use |~0u| for the default value. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 490 | uint32_t algorithm_mkey; |
| 491 | uint32_t algorithm_auth; |
| 492 | uint32_t algorithm_enc; |
| 493 | uint32_t algorithm_mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 494 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 495 | // min_version, if non-zero, matches all ciphers which were added in that |
| 496 | // particular protocol version. |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 497 | uint16_t min_version; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 498 | } CIPHER_ALIAS; |
| 499 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 500 | static const CIPHER_ALIAS kCipherAliases[] = { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 501 | // "ALL" doesn't include eNULL. It must be explicitly enabled. |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 502 | {"ALL", ~0u, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 503 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 504 | // The "COMPLEMENTOFDEFAULT" rule is omitted. It matches nothing. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 505 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 506 | // key exchange aliases |
| 507 | // (some of those using only a single bit here combine |
| 508 | // multiple key exchange algs according to the RFCs. |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 509 | {"kRSA", SSL_kRSA, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 510 | |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 511 | {"kECDHE", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 512 | {"kEECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 513 | {"ECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 514 | |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 515 | {"kPSK", SSL_kPSK, ~0u, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 516 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 517 | // server authentication aliases |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 518 | {"aRSA", ~0u, SSL_aRSA, ~0u, ~0u, 0}, |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 519 | {"aECDSA", ~0u, SSL_aECDSA, ~0u, ~0u, 0}, |
| 520 | {"ECDSA", ~0u, SSL_aECDSA, ~0u, ~0u, 0}, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 521 | {"aPSK", ~0u, SSL_aPSK, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 522 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 523 | // aliases combining key exchange and server authentication |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 524 | {"ECDHE", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
| 525 | {"EECDH", SSL_kECDHE, ~0u, ~0u, ~0u, 0}, |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 526 | {"RSA", SSL_kRSA, SSL_aRSA, ~0u, ~0u, 0}, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 527 | {"PSK", SSL_kPSK, SSL_aPSK, ~0u, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 528 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 529 | // symmetric encryption aliases |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 530 | {"3DES", ~0u, ~0u, SSL_3DES, ~0u, 0}, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 531 | {"AES128", ~0u, ~0u, SSL_AES128 | SSL_AES128GCM, ~0u, 0}, |
Matthew Braithwaite | 651aaef | 2016-12-08 16:14:36 -0800 | [diff] [blame] | 532 | {"AES256", ~0u, ~0u, SSL_AES256 | SSL_AES256GCM, ~0u, 0}, |
| 533 | {"AES", ~0u, ~0u, SSL_AES, ~0u, 0}, |
| 534 | {"AESGCM", ~0u, ~0u, SSL_AES128GCM | SSL_AES256GCM, ~0u, 0}, |
Adam Langley | 2e83924 | 2017-01-19 15:12:44 -0800 | [diff] [blame] | 535 | {"CHACHA20", ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 536 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 537 | // MAC aliases |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 538 | {"SHA1", ~0u, ~0u, ~0u, SSL_SHA1, 0}, |
| 539 | {"SHA", ~0u, ~0u, ~0u, SSL_SHA1, 0}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 540 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 541 | // Legacy protocol minimum version aliases. "TLSv1" is intentionally the |
| 542 | // same as "SSLv3". |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 543 | {"SSLv3", ~0u, ~0u, ~0u, ~0u, SSL3_VERSION}, |
| 544 | {"TLSv1", ~0u, ~0u, ~0u, ~0u, SSL3_VERSION}, |
| 545 | {"TLSv1.2", ~0u, ~0u, ~0u, ~0u, TLS1_2_VERSION}, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 546 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 547 | // Legacy strength classes. |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 548 | {"HIGH", ~0u, ~0u, ~0u, ~0u, 0}, |
| 549 | {"FIPS", ~0u, ~0u, ~0u, ~0u, 0}, |
David Benjamin | 0ca9214 | 2018-05-03 11:35:10 -0400 | [diff] [blame] | 550 | |
| 551 | // Temporary no-op aliases corresponding to removed SHA-2 legacy CBC |
| 552 | // ciphers. These should be removed after 2018-05-14. |
| 553 | {"SHA256", 0, 0, 0, 0, 0}, |
| 554 | {"SHA384", 0, 0, 0, 0, 0}, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 555 | }; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 556 | |
Steven Valdez | cb96654 | 2016-08-17 16:56:14 -0400 | [diff] [blame] | 557 | static const size_t kCipherAliasesLen = OPENSSL_ARRAY_SIZE(kCipherAliases); |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 558 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 559 | bool ssl_cipher_get_evp_aead(const EVP_AEAD **out_aead, |
| 560 | size_t *out_mac_secret_len, |
| 561 | size_t *out_fixed_iv_len, const SSL_CIPHER *cipher, |
David Benjamin | 8525ff3 | 2018-09-05 18:44:15 -0500 | [diff] [blame] | 562 | uint16_t version, bool is_dtls) { |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 563 | *out_aead = NULL; |
| 564 | *out_mac_secret_len = 0; |
| 565 | *out_fixed_iv_len = 0; |
Adam Langley | c9fb375 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 566 | |
David Benjamin | 8525ff3 | 2018-09-05 18:44:15 -0500 | [diff] [blame] | 567 | const bool is_tls12 = version == TLS1_2_VERSION && !is_dtls; |
| 568 | const bool is_tls13 = version == TLS1_3_VERSION && !is_dtls; |
Steven Valdez | 2f3404b | 2017-05-24 16:54:35 -0400 | [diff] [blame] | 569 | |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 570 | if (cipher->algorithm_mac == SSL_AEAD) { |
| 571 | if (cipher->algorithm_enc == SSL_AES128GCM) { |
Adam Langley | bcfb499 | 2018-06-18 14:04:41 -0700 | [diff] [blame] | 572 | if (is_tls12) { |
| 573 | *out_aead = EVP_aead_aes_128_gcm_tls12(); |
| 574 | } else if (is_tls13) { |
| 575 | *out_aead = EVP_aead_aes_128_gcm_tls13(); |
| 576 | } else { |
| 577 | *out_aead = EVP_aead_aes_128_gcm(); |
| 578 | } |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 579 | *out_fixed_iv_len = 4; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 580 | } else if (cipher->algorithm_enc == SSL_AES256GCM) { |
Adam Langley | bcfb499 | 2018-06-18 14:04:41 -0700 | [diff] [blame] | 581 | if (is_tls12) { |
| 582 | *out_aead = EVP_aead_aes_256_gcm_tls12(); |
| 583 | } else if (is_tls13) { |
| 584 | *out_aead = EVP_aead_aes_256_gcm_tls13(); |
| 585 | } else { |
| 586 | *out_aead = EVP_aead_aes_256_gcm(); |
| 587 | } |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 588 | *out_fixed_iv_len = 4; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 589 | } else if (cipher->algorithm_enc == SSL_CHACHA20POLY1305) { |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 590 | *out_aead = EVP_aead_chacha20_poly1305(); |
| 591 | *out_fixed_iv_len = 12; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 592 | } else { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 593 | return false; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 594 | } |
| 595 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 596 | // In TLS 1.3, the iv_len is equal to the AEAD nonce length whereas the code |
| 597 | // above computes the TLS 1.2 construction. |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 598 | if (version >= TLS1_3_VERSION) { |
| 599 | *out_fixed_iv_len = EVP_AEAD_nonce_length(*out_aead); |
| 600 | } |
| 601 | } else if (cipher->algorithm_mac == SSL_SHA1) { |
| 602 | if (cipher->algorithm_enc == SSL_eNULL) { |
David Benjamin | 9bb15f5 | 2018-06-26 00:07:40 -0400 | [diff] [blame] | 603 | *out_aead = EVP_aead_null_sha1_tls(); |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 604 | } else if (cipher->algorithm_enc == SSL_3DES) { |
David Benjamin | 9bb15f5 | 2018-06-26 00:07:40 -0400 | [diff] [blame] | 605 | if (version == TLS1_VERSION) { |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 606 | *out_aead = EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(); |
| 607 | *out_fixed_iv_len = 8; |
| 608 | } else { |
| 609 | *out_aead = EVP_aead_des_ede3_cbc_sha1_tls(); |
| 610 | } |
| 611 | } else if (cipher->algorithm_enc == SSL_AES128) { |
David Benjamin | 9bb15f5 | 2018-06-26 00:07:40 -0400 | [diff] [blame] | 612 | if (version == TLS1_VERSION) { |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 613 | *out_aead = EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(); |
| 614 | *out_fixed_iv_len = 16; |
| 615 | } else { |
| 616 | *out_aead = EVP_aead_aes_128_cbc_sha1_tls(); |
| 617 | } |
| 618 | } else if (cipher->algorithm_enc == SSL_AES256) { |
David Benjamin | 9bb15f5 | 2018-06-26 00:07:40 -0400 | [diff] [blame] | 619 | if (version == TLS1_VERSION) { |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 620 | *out_aead = EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(); |
| 621 | *out_fixed_iv_len = 16; |
| 622 | } else { |
| 623 | *out_aead = EVP_aead_aes_256_cbc_sha1_tls(); |
| 624 | } |
| 625 | } else { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 626 | return false; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | *out_mac_secret_len = SHA_DIGEST_LENGTH; |
David Benjamin | 305e6fb | 2016-10-27 18:19:00 -0400 | [diff] [blame] | 630 | } else { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 631 | return false; |
David Benjamin | ea72bd0 | 2014-12-21 21:27:41 -0500 | [diff] [blame] | 632 | } |
Steven Valdez | 7975056 | 2016-06-16 06:38:04 -0400 | [diff] [blame] | 633 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 634 | return true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 635 | } |
Adam Langley | c9fb375 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 636 | |
David Benjamin | ca9e8f5 | 2017-08-09 15:02:34 -0400 | [diff] [blame] | 637 | const EVP_MD *ssl_get_handshake_digest(uint16_t version, |
| 638 | const SSL_CIPHER *cipher) { |
| 639 | switch (cipher->algorithm_prf) { |
David Benjamin | b088331 | 2015-08-06 09:54:13 -0400 | [diff] [blame] | 640 | case SSL_HANDSHAKE_MAC_DEFAULT: |
Steven Valdez | 908ac19 | 2017-01-12 13:17:07 -0500 | [diff] [blame] | 641 | return version >= TLS1_2_VERSION ? EVP_sha256() : EVP_md5_sha1(); |
David Benjamin | b088331 | 2015-08-06 09:54:13 -0400 | [diff] [blame] | 642 | case SSL_HANDSHAKE_MAC_SHA256: |
| 643 | return EVP_sha256(); |
| 644 | case SSL_HANDSHAKE_MAC_SHA384: |
| 645 | return EVP_sha384(); |
| 646 | default: |
David Benjamin | ca9e8f5 | 2017-08-09 15:02:34 -0400 | [diff] [blame] | 647 | assert(0); |
David Benjamin | b088331 | 2015-08-06 09:54:13 -0400 | [diff] [blame] | 648 | return NULL; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 649 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 650 | } |
| 651 | |
David Benjamin | 8525ff3 | 2018-09-05 18:44:15 -0500 | [diff] [blame] | 652 | static bool is_cipher_list_separator(char c, bool is_strict) { |
Adam Langley | 22df691 | 2017-07-25 12:27:37 -0700 | [diff] [blame] | 653 | if (c == ':') { |
| 654 | return true; |
| 655 | } |
| 656 | return !is_strict && (c == ' ' || c == ';' || c == ','); |
| 657 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 658 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 659 | // rule_equals returns whether the NUL-terminated string |rule| is equal to the |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 660 | // |buf_len| bytes at |buf|. |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 661 | static bool rule_equals(const char *rule, const char *buf, size_t buf_len) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 662 | // |strncmp| alone only checks that |buf| is a prefix of |rule|. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 663 | return strncmp(rule, buf, buf_len) == 0 && rule[buf_len] == '\0'; |
| 664 | } |
| 665 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 666 | static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 667 | CIPHER_ORDER **tail) { |
| 668 | if (curr == *tail) { |
| 669 | return; |
| 670 | } |
| 671 | if (curr == *head) { |
| 672 | *head = curr->next; |
| 673 | } |
| 674 | if (curr->prev != NULL) { |
| 675 | curr->prev->next = curr->next; |
| 676 | } |
| 677 | if (curr->next != NULL) { |
| 678 | curr->next->prev = curr->prev; |
| 679 | } |
| 680 | (*tail)->next = curr; |
| 681 | curr->prev = *tail; |
| 682 | curr->next = NULL; |
| 683 | *tail = curr; |
| 684 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 685 | |
| 686 | static void ll_append_head(CIPHER_ORDER **head, CIPHER_ORDER *curr, |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 687 | CIPHER_ORDER **tail) { |
| 688 | if (curr == *head) { |
| 689 | return; |
| 690 | } |
| 691 | if (curr == *tail) { |
| 692 | *tail = curr->prev; |
| 693 | } |
| 694 | if (curr->next != NULL) { |
| 695 | curr->next->prev = curr->prev; |
| 696 | } |
| 697 | if (curr->prev != NULL) { |
| 698 | curr->prev->next = curr->next; |
| 699 | } |
| 700 | (*head)->prev = curr; |
| 701 | curr->next = *head; |
| 702 | curr->prev = NULL; |
| 703 | *head = curr; |
| 704 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 705 | |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 706 | static bool ssl_cipher_collect_ciphers(Array<CIPHER_ORDER> *out_co_list, |
| 707 | CIPHER_ORDER **out_head, |
| 708 | CIPHER_ORDER **out_tail) { |
| 709 | Array<CIPHER_ORDER> co_list; |
Matthew Braithwaite | d2ed382 | 2018-07-10 16:27:22 -0700 | [diff] [blame] | 710 | if (!co_list.Init(OPENSSL_ARRAY_SIZE(kCiphers))) { |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 711 | return false; |
| 712 | } |
| 713 | |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 714 | size_t co_list_num = 0; |
David Benjamin | 5be3a74 | 2017-10-28 16:08:58 -0400 | [diff] [blame] | 715 | for (const SSL_CIPHER &cipher : kCiphers) { |
| 716 | // TLS 1.3 ciphers do not participate in this mechanism. |
| 717 | if (cipher.algorithm_mkey != SSL_kGENERIC) { |
| 718 | co_list[co_list_num].cipher = &cipher; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 719 | co_list[co_list_num].next = NULL; |
| 720 | co_list[co_list_num].prev = NULL; |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 721 | co_list[co_list_num].active = false; |
| 722 | co_list[co_list_num].in_group = false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 723 | co_list_num++; |
| 724 | } |
| 725 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 726 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 727 | // Prepare linked list from list entries. |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 728 | if (co_list_num > 0) { |
| 729 | co_list[0].prev = NULL; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 730 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 731 | if (co_list_num > 1) { |
| 732 | co_list[0].next = &co_list[1]; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 733 | |
David Benjamin | 5409123 | 2016-09-05 12:47:25 -0400 | [diff] [blame] | 734 | for (size_t i = 1; i < co_list_num - 1; i++) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 735 | co_list[i].prev = &co_list[i - 1]; |
| 736 | co_list[i].next = &co_list[i + 1]; |
| 737 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 738 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 739 | co_list[co_list_num - 1].prev = &co_list[co_list_num - 2]; |
| 740 | } |
| 741 | |
| 742 | co_list[co_list_num - 1].next = NULL; |
| 743 | |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 744 | *out_head = &co_list[0]; |
| 745 | *out_tail = &co_list[co_list_num - 1]; |
| 746 | } else { |
| 747 | *out_head = nullptr; |
| 748 | *out_tail = nullptr; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 749 | } |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 750 | *out_co_list = std::move(co_list); |
| 751 | return true; |
| 752 | } |
| 753 | |
| 754 | SSLCipherPreferenceList::~SSLCipherPreferenceList() { |
| 755 | OPENSSL_free(in_group_flags); |
| 756 | } |
| 757 | |
| 758 | bool SSLCipherPreferenceList::Init(UniquePtr<STACK_OF(SSL_CIPHER)> ciphers_arg, |
| 759 | Span<const bool> in_group_flags_arg) { |
| 760 | if (sk_SSL_CIPHER_num(ciphers_arg.get()) != in_group_flags_arg.size()) { |
| 761 | OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | Array<bool> copy; |
| 766 | if (!copy.CopyFrom(in_group_flags_arg)) { |
| 767 | return false; |
| 768 | } |
| 769 | ciphers = std::move(ciphers_arg); |
| 770 | size_t unused_len; |
| 771 | copy.Release(&in_group_flags, &unused_len); |
| 772 | return true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 773 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 774 | |
Matthew Braithwaite | d2ed382 | 2018-07-10 16:27:22 -0700 | [diff] [blame] | 775 | bool SSLCipherPreferenceList::Init(const SSLCipherPreferenceList& other) { |
| 776 | size_t size = sk_SSL_CIPHER_num(other.ciphers.get()); |
| 777 | Span<const bool> other_flags(other.in_group_flags, size); |
| 778 | UniquePtr<STACK_OF(SSL_CIPHER)> other_ciphers(sk_SSL_CIPHER_dup( |
| 779 | other.ciphers.get())); |
| 780 | if (!other_ciphers) { |
| 781 | return false; |
| 782 | } |
| 783 | return Init(std::move(other_ciphers), other_flags); |
| 784 | } |
| 785 | |
| 786 | void SSLCipherPreferenceList::Remove(const SSL_CIPHER *cipher) { |
| 787 | size_t index; |
| 788 | if (!sk_SSL_CIPHER_find(ciphers.get(), &index, cipher)) { |
| 789 | return; |
| 790 | } |
| 791 | if (!in_group_flags[index] /* last element of group */ && index > 0) { |
| 792 | in_group_flags[index-1] = false; |
| 793 | } |
| 794 | for (size_t i = index; i < sk_SSL_CIPHER_num(ciphers.get()) - 1; ++i) { |
| 795 | in_group_flags[i] = in_group_flags[i+1]; |
| 796 | } |
| 797 | sk_SSL_CIPHER_delete(ciphers.get(), index); |
| 798 | } |
| 799 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 800 | // ssl_cipher_apply_rule applies the rule type |rule| to ciphers matching its |
| 801 | // parameters in the linked list from |*head_p| to |*tail_p|. It writes the new |
| 802 | // head and tail of the list to |*head_p| and |*tail_p|, respectively. |
| 803 | // |
| 804 | // - If |cipher_id| is non-zero, only that cipher is selected. |
| 805 | // - Otherwise, if |strength_bits| is non-negative, it selects ciphers |
| 806 | // of that strength. |
| 807 | // - Otherwise, it selects ciphers that match each bitmasks in |alg_*| and |
| 808 | // |min_version|. |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 809 | static void ssl_cipher_apply_rule( |
David Benjamin | 107db58 | 2015-04-08 00:41:59 -0400 | [diff] [blame] | 810 | uint32_t cipher_id, uint32_t alg_mkey, uint32_t alg_auth, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 811 | uint32_t alg_enc, uint32_t alg_mac, uint16_t min_version, int rule, |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 812 | int strength_bits, bool in_group, CIPHER_ORDER **head_p, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 813 | CIPHER_ORDER **tail_p) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 814 | CIPHER_ORDER *head, *tail, *curr, *next, *last; |
| 815 | const SSL_CIPHER *cp; |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 816 | bool reverse = false; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 817 | |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 818 | if (cipher_id == 0 && strength_bits == -1 && min_version == 0 && |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 819 | (alg_mkey == 0 || alg_auth == 0 || alg_enc == 0 || alg_mac == 0)) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 820 | // The rule matches nothing, so bail early. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 824 | if (rule == CIPHER_DEL) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 825 | // needed to maintain sorting between currently deleted ciphers |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 826 | reverse = true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 827 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 828 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 829 | head = *head_p; |
| 830 | tail = *tail_p; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 831 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 832 | if (reverse) { |
| 833 | next = tail; |
| 834 | last = head; |
| 835 | } else { |
| 836 | next = head; |
| 837 | last = tail; |
| 838 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 839 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 840 | curr = NULL; |
| 841 | for (;;) { |
| 842 | if (curr == last) { |
| 843 | break; |
| 844 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 845 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 846 | curr = next; |
| 847 | if (curr == NULL) { |
| 848 | break; |
| 849 | } |
Adam Langley | e3142a7 | 2014-07-24 17:56:48 -0700 | [diff] [blame] | 850 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 851 | next = reverse ? curr->prev : curr->next; |
| 852 | cp = curr->cipher; |
Adam Langley | e3142a7 | 2014-07-24 17:56:48 -0700 | [diff] [blame] | 853 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 854 | // Selection criteria is either a specific cipher, the value of |
| 855 | // |strength_bits|, or the algorithms used. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 856 | if (cipher_id != 0) { |
| 857 | if (cipher_id != cp->id) { |
| 858 | continue; |
| 859 | } |
| 860 | } else if (strength_bits >= 0) { |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 861 | if (strength_bits != SSL_CIPHER_get_bits(cp, NULL)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 862 | continue; |
| 863 | } |
David Benjamin | 881f196 | 2016-08-10 18:29:12 -0400 | [diff] [blame] | 864 | } else { |
| 865 | if (!(alg_mkey & cp->algorithm_mkey) || |
| 866 | !(alg_auth & cp->algorithm_auth) || |
| 867 | !(alg_enc & cp->algorithm_enc) || |
| 868 | !(alg_mac & cp->algorithm_mac) || |
David Benjamin | 3b903f2 | 2017-09-29 18:44:56 -0400 | [diff] [blame] | 869 | (min_version != 0 && SSL_CIPHER_get_min_version(cp) != min_version) || |
| 870 | // The NULL cipher must be selected explicitly. |
| 871 | cp->algorithm_enc == SSL_eNULL) { |
David Benjamin | 881f196 | 2016-08-10 18:29:12 -0400 | [diff] [blame] | 872 | continue; |
| 873 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 874 | } |
Adam Langley | e3142a7 | 2014-07-24 17:56:48 -0700 | [diff] [blame] | 875 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 876 | // add the cipher if it has not been added yet. |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 877 | if (rule == CIPHER_ADD) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 878 | // reverse == false |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 879 | if (!curr->active) { |
| 880 | ll_append_tail(&head, curr, &tail); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 881 | curr->active = true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 882 | curr->in_group = in_group; |
| 883 | } |
| 884 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 885 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 886 | // Move the added cipher to this location |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 887 | else if (rule == CIPHER_ORD) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 888 | // reverse == false |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 889 | if (curr->active) { |
| 890 | ll_append_tail(&head, curr, &tail); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 891 | curr->in_group = false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 892 | } |
| 893 | } else if (rule == CIPHER_DEL) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 894 | // reverse == true |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 895 | if (curr->active) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 896 | // most recently deleted ciphersuites get best positions |
| 897 | // for any future CIPHER_ADD (note that the CIPHER_DEL loop |
| 898 | // works in reverse to maintain the order) |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 899 | ll_append_head(&head, curr, &tail); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 900 | curr->active = false; |
| 901 | curr->in_group = false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 902 | } |
| 903 | } else if (rule == CIPHER_KILL) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 904 | // reverse == false |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 905 | if (head == curr) { |
| 906 | head = curr->next; |
| 907 | } else { |
| 908 | curr->prev->next = curr->next; |
| 909 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 910 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 911 | if (tail == curr) { |
| 912 | tail = curr->prev; |
| 913 | } |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 914 | curr->active = false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 915 | if (curr->next != NULL) { |
| 916 | curr->next->prev = curr->prev; |
| 917 | } |
| 918 | if (curr->prev != NULL) { |
| 919 | curr->prev->next = curr->next; |
| 920 | } |
| 921 | curr->next = NULL; |
| 922 | curr->prev = NULL; |
| 923 | } |
| 924 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 925 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 926 | *head_p = head; |
| 927 | *tail_p = tail; |
| 928 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 929 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 930 | static bool ssl_cipher_strength_sort(CIPHER_ORDER **head_p, |
| 931 | CIPHER_ORDER **tail_p) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 932 | // This routine sorts the ciphers with descending strength. The sorting must |
| 933 | // keep the pre-sorted sequence, so we apply the normal sorting routine as |
| 934 | // '+' movement to the end of the list. |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 935 | int max_strength_bits = 0; |
| 936 | CIPHER_ORDER *curr = *head_p; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 937 | while (curr != NULL) { |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 938 | if (curr->active && |
| 939 | SSL_CIPHER_get_bits(curr->cipher, NULL) > max_strength_bits) { |
| 940 | max_strength_bits = SSL_CIPHER_get_bits(curr->cipher, NULL); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 941 | } |
| 942 | curr = curr->next; |
| 943 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 944 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 945 | Array<int> number_uses; |
| 946 | if (!number_uses.Init(max_strength_bits + 1)) { |
| 947 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 948 | } |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 949 | OPENSSL_memset(number_uses.data(), 0, (max_strength_bits + 1) * sizeof(int)); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 950 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 951 | // Now find the strength_bits values actually used. |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 952 | curr = *head_p; |
| 953 | while (curr != NULL) { |
| 954 | if (curr->active) { |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 955 | number_uses[SSL_CIPHER_get_bits(curr->cipher, NULL)]++; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 956 | } |
| 957 | curr = curr->next; |
| 958 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 959 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 960 | // Go through the list of used strength_bits values in descending order. |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 961 | for (int i = max_strength_bits; i >= 0; i--) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 962 | if (number_uses[i] > 0) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 963 | ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, CIPHER_ORD, i, false, head_p, |
| 964 | tail_p); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 968 | return true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 969 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 970 | |
David Benjamin | 5be3a74 | 2017-10-28 16:08:58 -0400 | [diff] [blame] | 971 | static bool ssl_cipher_process_rulestr(const char *rule_str, |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 972 | CIPHER_ORDER **head_p, |
| 973 | CIPHER_ORDER **tail_p, bool strict) { |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 974 | uint32_t alg_mkey, alg_auth, alg_enc, alg_mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 975 | uint16_t min_version; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 976 | const char *l, *buf; |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 977 | int rule; |
| 978 | bool multi, skip_rule, in_group = false, has_group = false; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 979 | size_t j, buf_len; |
| 980 | uint32_t cipher_id; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 981 | char ch; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 982 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 983 | l = rule_str; |
| 984 | for (;;) { |
| 985 | ch = *l; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 986 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 987 | if (ch == '\0') { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 988 | break; // done |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 989 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 990 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 991 | if (in_group) { |
| 992 | if (ch == ']') { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 993 | if (*tail_p) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 994 | (*tail_p)->in_group = false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 995 | } |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 996 | in_group = false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 997 | l++; |
| 998 | continue; |
| 999 | } |
David Benjamin | 37d9246 | 2014-09-20 17:54:24 -0400 | [diff] [blame] | 1000 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1001 | if (ch == '|') { |
| 1002 | rule = CIPHER_ADD; |
| 1003 | l++; |
| 1004 | continue; |
Bob Beck | 00c70b8 | 2023-02-01 12:41:49 -0700 | [diff] [blame] | 1005 | } else if (!OPENSSL_isalnum(ch)) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1006 | OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_OPERATOR_IN_GROUP); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1007 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1008 | } else { |
| 1009 | rule = CIPHER_ADD; |
| 1010 | } |
| 1011 | } else if (ch == '-') { |
| 1012 | rule = CIPHER_DEL; |
| 1013 | l++; |
| 1014 | } else if (ch == '+') { |
| 1015 | rule = CIPHER_ORD; |
| 1016 | l++; |
| 1017 | } else if (ch == '!') { |
| 1018 | rule = CIPHER_KILL; |
| 1019 | l++; |
| 1020 | } else if (ch == '@') { |
| 1021 | rule = CIPHER_SPECIAL; |
| 1022 | l++; |
| 1023 | } else if (ch == '[') { |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1024 | assert(!in_group); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1025 | in_group = true; |
| 1026 | has_group = true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1027 | l++; |
| 1028 | continue; |
| 1029 | } else { |
| 1030 | rule = CIPHER_ADD; |
| 1031 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1032 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1033 | // If preference groups are enabled, the only legal operator is +. |
| 1034 | // Otherwise the in_group bits will get mixed up. |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1035 | if (has_group && rule != CIPHER_ADD) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1036 | OPENSSL_PUT_ERROR(SSL, SSL_R_MIXED_SPECIAL_OPERATOR_WITH_GROUPS); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1037 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1038 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1039 | |
Adam Langley | 22df691 | 2017-07-25 12:27:37 -0700 | [diff] [blame] | 1040 | if (is_cipher_list_separator(ch, strict)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1041 | l++; |
| 1042 | continue; |
| 1043 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1044 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1045 | multi = false; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1046 | cipher_id = 0; |
| 1047 | alg_mkey = ~0u; |
| 1048 | alg_auth = ~0u; |
| 1049 | alg_enc = ~0u; |
| 1050 | alg_mac = ~0u; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1051 | min_version = 0; |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1052 | skip_rule = false; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1053 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1054 | for (;;) { |
| 1055 | ch = *l; |
| 1056 | buf = l; |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1057 | buf_len = 0; |
Bob Beck | 00c70b8 | 2023-02-01 12:41:49 -0700 | [diff] [blame] | 1058 | while (OPENSSL_isalnum(ch) || ch == '-' || ch == '.' || ch == '_') { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1059 | ch = *(++l); |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1060 | buf_len++; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1061 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1062 | |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1063 | if (buf_len == 0) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1064 | // We hit something we cannot deal with, it is no command or separator |
| 1065 | // nor alphanumeric, so we call this an error. |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1066 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1067 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1068 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1069 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1070 | if (rule == CIPHER_SPECIAL) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1071 | break; |
| 1072 | } |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1073 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1074 | // Look for a matching exact cipher. These aren't allowed in multipart |
| 1075 | // rules. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1076 | if (!multi && ch != '+') { |
Matthew Braithwaite | d2ed382 | 2018-07-10 16:27:22 -0700 | [diff] [blame] | 1077 | for (j = 0; j < OPENSSL_ARRAY_SIZE(kCiphers); j++) { |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1078 | const SSL_CIPHER *cipher = &kCiphers[j]; |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 1079 | if (rule_equals(cipher->name, buf, buf_len) || |
| 1080 | rule_equals(cipher->standard_name, buf, buf_len)) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1081 | cipher_id = cipher->id; |
| 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | if (cipher_id == 0) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1087 | // If not an exact cipher, look for a matching cipher alias. |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1088 | for (j = 0; j < kCipherAliasesLen; j++) { |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1089 | if (rule_equals(kCipherAliases[j].name, buf, buf_len)) { |
| 1090 | alg_mkey &= kCipherAliases[j].algorithm_mkey; |
| 1091 | alg_auth &= kCipherAliases[j].algorithm_auth; |
| 1092 | alg_enc &= kCipherAliases[j].algorithm_enc; |
| 1093 | alg_mac &= kCipherAliases[j].algorithm_mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1094 | |
| 1095 | if (min_version != 0 && |
| 1096 | min_version != kCipherAliases[j].min_version) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1097 | skip_rule = true; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1098 | } else { |
| 1099 | min_version = kCipherAliases[j].min_version; |
| 1100 | } |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1101 | break; |
| 1102 | } |
| 1103 | } |
David Benjamin | a1c90a5 | 2015-05-30 17:03:14 -0400 | [diff] [blame] | 1104 | if (j == kCipherAliasesLen) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1105 | skip_rule = true; |
Matthew Braithwaite | a57dcfb | 2017-02-17 22:08:23 -0800 | [diff] [blame] | 1106 | if (strict) { |
| 1107 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1108 | return false; |
Matthew Braithwaite | a57dcfb | 2017-02-17 22:08:23 -0800 | [diff] [blame] | 1109 | } |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1113 | // Check for a multipart rule. |
David Benjamin | 0344daf | 2015-04-08 02:08:01 -0400 | [diff] [blame] | 1114 | if (ch != '+') { |
| 1115 | break; |
| 1116 | } |
| 1117 | l++; |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1118 | multi = true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1119 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1120 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1121 | // Ok, we have the rule, now apply it. |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1122 | if (rule == CIPHER_SPECIAL) { |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1123 | if (buf_len != 8 || strncmp(buf, "STRENGTH", 8) != 0) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1124 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1125 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1126 | } |
David Benjamin | bf5f192 | 2017-07-01 11:13:53 -0400 | [diff] [blame] | 1127 | if (!ssl_cipher_strength_sort(head_p, tail_p)) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1128 | return false; |
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 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1131 | // We do not support any "multi" options together with "@", so throw away |
| 1132 | // 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] | 1133 | while (*l != '\0' && !is_cipher_list_separator(*l, strict)) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1134 | l++; |
| 1135 | } |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1136 | } else if (!skip_rule) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1137 | 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] | 1138 | min_version, rule, -1, in_group, head_p, tail_p); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1139 | } |
| 1140 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1141 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1142 | if (in_group) { |
David Benjamin | 3570d73 | 2015-06-29 00:28:17 -0400 | [diff] [blame] | 1143 | OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMMAND); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1144 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1145 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1146 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1147 | return true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1148 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1149 | |
David Benjamin | 0ce090a | 2018-07-02 20:24:40 -0400 | [diff] [blame] | 1150 | bool ssl_create_cipher_list(UniquePtr<SSLCipherPreferenceList> *out_cipher_list, |
Bob Beck | 8cacbd9 | 2023-04-05 14:38:38 -0600 | [diff] [blame] | 1151 | const bool has_aes_hw, const char *rule_str, |
| 1152 | bool strict) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1153 | // Return with error if nothing to do. |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1154 | if (rule_str == NULL || out_cipher_list == NULL) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1155 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1156 | } |
David Benjamin | 5213df4 | 2014-08-20 14:19:54 -0400 | [diff] [blame] | 1157 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1158 | // Now we have to collect the available ciphers from the compiled in ciphers. |
| 1159 | // We cannot get more than the number compiled in, so it is used for |
| 1160 | // allocation. |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1161 | Array<CIPHER_ORDER> co_list; |
| 1162 | CIPHER_ORDER *head = nullptr, *tail = nullptr; |
| 1163 | if (!ssl_cipher_collect_ciphers(&co_list, &head, &tail)) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1164 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1165 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1166 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1167 | // Now arrange all ciphers by preference: |
| 1168 | // TODO(davidben): Compute this order once and copy it. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1169 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1170 | // Everything else being equal, prefer ECDHE_ECDSA and ECDHE_RSA over other |
| 1171 | // key exchange mechanisms |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1172 | ssl_cipher_apply_rule(0, SSL_kECDHE, SSL_aECDSA, ~0u, ~0u, 0, CIPHER_ADD, -1, |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1173 | false, &head, &tail); |
| 1174 | ssl_cipher_apply_rule(0, SSL_kECDHE, ~0u, ~0u, ~0u, 0, CIPHER_ADD, -1, false, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1175 | &head, &tail); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1176 | ssl_cipher_apply_rule(0, ~0u, ~0u, ~0u, ~0u, 0, CIPHER_DEL, -1, false, &head, |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1177 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1178 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1179 | // Order the bulk ciphers. First the preferred AEAD ciphers. We prefer |
| 1180 | // CHACHA20 unless there is hardware support for fast and constant-time |
| 1181 | // AES_GCM. Of the two CHACHA20 variants, the new one is preferred over the |
| 1182 | // old one. |
Bob Beck | 8cacbd9 | 2023-04-05 14:38:38 -0600 | [diff] [blame] | 1183 | if (has_aes_hw) { |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1184 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES128GCM, ~0u, 0, CIPHER_ADD, -1, |
| 1185 | false, &head, &tail); |
| 1186 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES256GCM, ~0u, 0, CIPHER_ADD, -1, |
| 1187 | false, &head, &tail); |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1188 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0, CIPHER_ADD, |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1189 | -1, false, &head, &tail); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1190 | } else { |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1191 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_CHACHA20POLY1305, ~0u, 0, CIPHER_ADD, |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1192 | -1, false, &head, &tail); |
| 1193 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES128GCM, ~0u, 0, CIPHER_ADD, -1, |
| 1194 | false, &head, &tail); |
| 1195 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES256GCM, ~0u, 0, CIPHER_ADD, -1, |
| 1196 | false, &head, &tail); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1197 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1198 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1199 | // Then the legacy non-AEAD ciphers: AES_128_CBC, AES_256_CBC, |
| 1200 | // 3DES_EDE_CBC_SHA. |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1201 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES128, ~0u, 0, CIPHER_ADD, -1, false, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1202 | &head, &tail); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1203 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_AES256, ~0u, 0, CIPHER_ADD, -1, false, |
David Benjamin | 4333665 | 2016-03-03 15:32:29 -0500 | [diff] [blame] | 1204 | &head, &tail); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1205 | ssl_cipher_apply_rule(0, ~0u, ~0u, SSL_3DES, ~0u, 0, CIPHER_ADD, -1, false, |
| 1206 | &head, &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1207 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1208 | // Temporarily enable everything else for sorting |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1209 | ssl_cipher_apply_rule(0, ~0u, ~0u, ~0u, ~0u, 0, CIPHER_ADD, -1, false, &head, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1210 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1211 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1212 | // Move ciphers without forward secrecy to the end. |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1213 | ssl_cipher_apply_rule(0, (SSL_kRSA | SSL_kPSK), ~0u, ~0u, ~0u, 0, CIPHER_ORD, |
| 1214 | -1, false, &head, &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1215 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1216 | // Now disable everything (maintaining the ordering!) |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1217 | ssl_cipher_apply_rule(0, ~0u, ~0u, ~0u, ~0u, 0, CIPHER_DEL, -1, false, &head, |
David Benjamin | d6e9eec | 2015-11-18 09:48:55 -0500 | [diff] [blame] | 1218 | &tail); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1219 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1220 | // If the rule_string begins with DEFAULT, apply the default rule before |
| 1221 | // using the (possibly available) additional rules. |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1222 | const char *rule_p = rule_str; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1223 | if (strncmp(rule_str, "DEFAULT", 7) == 0) { |
David Benjamin | 5be3a74 | 2017-10-28 16:08:58 -0400 | [diff] [blame] | 1224 | if (!ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST, &head, &tail, |
| 1225 | strict)) { |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1226 | return false; |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1227 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1228 | rule_p += 7; |
| 1229 | if (*rule_p == ':') { |
| 1230 | rule_p++; |
| 1231 | } |
| 1232 | } |
Adam Langley | 858a88d | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1233 | |
David Benjamin | 11a7b3c | 2016-11-03 17:03:48 -0400 | [diff] [blame] | 1234 | if (*rule_p != '\0' && |
David Benjamin | 5be3a74 | 2017-10-28 16:08:58 -0400 | [diff] [blame] | 1235 | !ssl_cipher_process_rulestr(rule_p, &head, &tail, strict)) { |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1236 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1239 | // Allocate new "cipherstack" for the result, return with error |
| 1240 | // if we cannot get one. |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1241 | UniquePtr<STACK_OF(SSL_CIPHER)> cipherstack(sk_SSL_CIPHER_new_null()); |
| 1242 | Array<bool> in_group_flags; |
| 1243 | if (cipherstack == nullptr || |
Matthew Braithwaite | d2ed382 | 2018-07-10 16:27:22 -0700 | [diff] [blame] | 1244 | !in_group_flags.Init(OPENSSL_ARRAY_SIZE(kCiphers))) { |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1245 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1248 | // The cipher selection for the list is done. The ciphers are added |
| 1249 | // to the resulting precedence to the STACK_OF(SSL_CIPHER). |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1250 | size_t num_in_group_flags = 0; |
| 1251 | for (CIPHER_ORDER *curr = head; curr != NULL; curr = curr->next) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1252 | if (curr->active) { |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1253 | if (!sk_SSL_CIPHER_push(cipherstack.get(), curr->cipher)) { |
| 1254 | return false; |
David Benjamin | 2adb7ec | 2015-01-11 19:59:06 -0500 | [diff] [blame] | 1255 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1256 | in_group_flags[num_in_group_flags++] = curr->in_group; |
| 1257 | } |
| 1258 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1259 | |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1260 | UniquePtr<SSLCipherPreferenceList> pref_list = |
| 1261 | MakeUnique<SSLCipherPreferenceList>(); |
| 1262 | if (!pref_list || |
| 1263 | !pref_list->Init( |
| 1264 | std::move(cipherstack), |
| 1265 | MakeConstSpan(in_group_flags).subspan(0, num_in_group_flags))) { |
| 1266 | return false; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1267 | } |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1268 | |
David Benjamin | 0ce090a | 2018-07-02 20:24:40 -0400 | [diff] [blame] | 1269 | *out_cipher_list = std::move(pref_list); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1270 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1271 | // Configuring an empty cipher list is an error but still updates the |
| 1272 | // output. |
David Benjamin | 48b276d | 2018-04-12 17:37:32 -0400 | [diff] [blame] | 1273 | if (sk_SSL_CIPHER_num((*out_cipher_list)->ciphers.get()) == 0) { |
David Benjamin | 91222b8 | 2017-03-09 20:10:56 -0500 | [diff] [blame] | 1274 | OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH); |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1275 | return false; |
David Benjamin | 91222b8 | 2017-03-09 20:10:56 -0500 | [diff] [blame] | 1276 | } |
| 1277 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1278 | return true; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1279 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1280 | |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1281 | uint32_t ssl_cipher_auth_mask_for_key(const EVP_PKEY *key) { |
| 1282 | switch (EVP_PKEY_id(key)) { |
| 1283 | case EVP_PKEY_RSA: |
| 1284 | return SSL_aRSA; |
| 1285 | case EVP_PKEY_EC: |
| 1286 | case EVP_PKEY_ED25519: |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1287 | // Ed25519 keys in TLS 1.2 repurpose the ECDSA ciphers. |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1288 | return SSL_aECDSA; |
| 1289 | default: |
| 1290 | return 0; |
| 1291 | } |
| 1292 | } |
| 1293 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1294 | bool ssl_cipher_uses_certificate_auth(const SSL_CIPHER *cipher) { |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1295 | return (cipher->algorithm_auth & SSL_aCERT) != 0; |
| 1296 | } |
| 1297 | |
David Benjamin | f496249 | 2017-09-27 19:34:32 -0400 | [diff] [blame] | 1298 | bool ssl_cipher_requires_server_key_exchange(const SSL_CIPHER *cipher) { |
| 1299 | // Ephemeral Diffie-Hellman key exchanges require a ServerKeyExchange. It is |
| 1300 | // optional or omitted in all others. |
| 1301 | return (cipher->algorithm_mkey & SSL_kECDHE) != 0; |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | size_t ssl_cipher_get_record_split_len(const SSL_CIPHER *cipher) { |
| 1305 | size_t block_size; |
| 1306 | switch (cipher->algorithm_enc) { |
| 1307 | case SSL_3DES: |
| 1308 | block_size = 8; |
| 1309 | break; |
| 1310 | case SSL_AES128: |
| 1311 | case SSL_AES256: |
| 1312 | block_size = 16; |
| 1313 | break; |
| 1314 | default: |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1318 | // All supported TLS 1.0 ciphers use SHA-1. |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1319 | assert(cipher->algorithm_mac == SSL_SHA1); |
| 1320 | size_t ret = 1 + SHA_DIGEST_LENGTH; |
| 1321 | ret += block_size - (ret % block_size); |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 1325 | BSSL_NAMESPACE_END |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1326 | |
| 1327 | using namespace bssl; |
| 1328 | |
David Benjamin | 493d5cb | 2022-04-18 17:20:27 -0400 | [diff] [blame] | 1329 | static constexpr int ssl_cipher_id_cmp(const SSL_CIPHER *a, |
| 1330 | const SSL_CIPHER *b) { |
| 1331 | if (a->id > b->id) { |
| 1332 | return 1; |
| 1333 | } |
| 1334 | if (a->id < b->id) { |
| 1335 | return -1; |
| 1336 | } |
| 1337 | return 0; |
MichaĆ Janiszewski | c4f3b8a | 2018-07-30 22:50:40 +0200 | [diff] [blame] | 1338 | } |
| 1339 | |
David Benjamin | 493d5cb | 2022-04-18 17:20:27 -0400 | [diff] [blame] | 1340 | static int ssl_cipher_id_cmp_void(const void *in_a, const void *in_b) { |
| 1341 | return ssl_cipher_id_cmp(reinterpret_cast<const SSL_CIPHER *>(in_a), |
| 1342 | reinterpret_cast<const SSL_CIPHER *>(in_b)); |
MichaĆ Janiszewski | c4f3b8a | 2018-07-30 22:50:40 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
David Benjamin | 493d5cb | 2022-04-18 17:20:27 -0400 | [diff] [blame] | 1345 | template <size_t N> |
| 1346 | static constexpr bool ssl_ciphers_sorted(const SSL_CIPHER (&ciphers)[N]) { |
| 1347 | for (size_t i = 1; i < N; i++) { |
| 1348 | if (ssl_cipher_id_cmp(&ciphers[i - 1], &ciphers[i]) >= 0) { |
| 1349 | return false; |
| 1350 | } |
| 1351 | } |
| 1352 | return true; |
MichaĆ Janiszewski | c4f3b8a | 2018-07-30 22:50:40 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
David Benjamin | 493d5cb | 2022-04-18 17:20:27 -0400 | [diff] [blame] | 1355 | static_assert(ssl_ciphers_sorted(kCiphers), |
MichaĆ Janiszewski | c4f3b8a | 2018-07-30 22:50:40 +0200 | [diff] [blame] | 1356 | "Ciphers are not sorted, bsearch won't work"); |
| 1357 | |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1358 | const SSL_CIPHER *SSL_get_cipher_by_value(uint16_t value) { |
| 1359 | SSL_CIPHER c; |
| 1360 | |
| 1361 | c.id = 0x03000000L | value; |
| 1362 | return reinterpret_cast<const SSL_CIPHER *>(bsearch( |
Matthew Braithwaite | d2ed382 | 2018-07-10 16:27:22 -0700 | [diff] [blame] | 1363 | &c, kCiphers, OPENSSL_ARRAY_SIZE(kCiphers), sizeof(SSL_CIPHER), |
David Benjamin | 493d5cb | 2022-04-18 17:20:27 -0400 | [diff] [blame] | 1364 | ssl_cipher_id_cmp_void)); |
David Benjamin | 86e95b8 | 2017-07-18 16:34:25 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | uint32_t SSL_CIPHER_get_id(const SSL_CIPHER *cipher) { return cipher->id; } |
| 1368 | |
David Benjamin | 3743aaf | 2020-09-21 13:55:16 -0400 | [diff] [blame] | 1369 | uint16_t SSL_CIPHER_get_protocol_id(const SSL_CIPHER *cipher) { |
| 1370 | // All OpenSSL cipher IDs are prefaced with 0x03. Historically this referred |
| 1371 | // to SSLv2 vs SSLv3. |
| 1372 | assert((cipher->id & 0xff000000) == 0x03000000); |
Adam Langley | 04a89c8 | 2019-09-18 14:31:00 -0700 | [diff] [blame] | 1373 | return static_cast<uint16_t>(cipher->id); |
| 1374 | } |
| 1375 | |
David Benjamin | 3743aaf | 2020-09-21 13:55:16 -0400 | [diff] [blame] | 1376 | uint16_t SSL_CIPHER_get_value(const SSL_CIPHER *cipher) { |
| 1377 | return SSL_CIPHER_get_protocol_id(cipher); |
| 1378 | } |
| 1379 | |
David Benjamin | 348f0d8 | 2017-08-10 16:06:27 -0400 | [diff] [blame] | 1380 | int SSL_CIPHER_is_aead(const SSL_CIPHER *cipher) { |
Alessandro Ghedini | 0726fb7 | 2017-01-17 13:27:08 +0000 | [diff] [blame] | 1381 | return (cipher->algorithm_mac & SSL_AEAD) != 0; |
| 1382 | } |
| 1383 | |
David Benjamin | 348f0d8 | 2017-08-10 16:06:27 -0400 | [diff] [blame] | 1384 | int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *cipher) { |
| 1385 | switch (cipher->algorithm_enc) { |
| 1386 | case SSL_eNULL: |
| 1387 | return NID_undef; |
| 1388 | case SSL_3DES: |
| 1389 | return NID_des_ede3_cbc; |
| 1390 | case SSL_AES128: |
| 1391 | return NID_aes_128_cbc; |
| 1392 | case SSL_AES256: |
| 1393 | return NID_aes_256_cbc; |
| 1394 | case SSL_AES128GCM: |
| 1395 | return NID_aes_128_gcm; |
| 1396 | case SSL_AES256GCM: |
| 1397 | return NID_aes_256_gcm; |
| 1398 | case SSL_CHACHA20POLY1305: |
| 1399 | return NID_chacha20_poly1305; |
| 1400 | } |
| 1401 | assert(0); |
| 1402 | return NID_undef; |
| 1403 | } |
| 1404 | |
| 1405 | int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *cipher) { |
| 1406 | switch (cipher->algorithm_mac) { |
| 1407 | case SSL_AEAD: |
| 1408 | return NID_undef; |
| 1409 | case SSL_SHA1: |
| 1410 | return NID_sha1; |
David Benjamin | 348f0d8 | 2017-08-10 16:06:27 -0400 | [diff] [blame] | 1411 | } |
| 1412 | assert(0); |
| 1413 | return NID_undef; |
| 1414 | } |
| 1415 | |
| 1416 | int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *cipher) { |
| 1417 | switch (cipher->algorithm_mkey) { |
| 1418 | case SSL_kRSA: |
| 1419 | return NID_kx_rsa; |
| 1420 | case SSL_kECDHE: |
| 1421 | return NID_kx_ecdhe; |
| 1422 | case SSL_kPSK: |
| 1423 | return NID_kx_psk; |
| 1424 | case SSL_kGENERIC: |
| 1425 | return NID_kx_any; |
| 1426 | } |
| 1427 | assert(0); |
| 1428 | return NID_undef; |
| 1429 | } |
| 1430 | |
| 1431 | int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *cipher) { |
| 1432 | switch (cipher->algorithm_auth) { |
| 1433 | case SSL_aRSA: |
| 1434 | return NID_auth_rsa; |
| 1435 | case SSL_aECDSA: |
| 1436 | return NID_auth_ecdsa; |
| 1437 | case SSL_aPSK: |
| 1438 | return NID_auth_psk; |
| 1439 | case SSL_aGENERIC: |
| 1440 | return NID_auth_any; |
| 1441 | } |
| 1442 | assert(0); |
| 1443 | return NID_undef; |
| 1444 | } |
| 1445 | |
David Benjamin | b1b76ae | 2017-09-21 17:03:34 -0400 | [diff] [blame] | 1446 | int SSL_CIPHER_get_prf_nid(const SSL_CIPHER *cipher) { |
| 1447 | switch (cipher->algorithm_prf) { |
| 1448 | case SSL_HANDSHAKE_MAC_DEFAULT: |
| 1449 | return NID_md5_sha1; |
| 1450 | case SSL_HANDSHAKE_MAC_SHA256: |
| 1451 | return NID_sha256; |
| 1452 | case SSL_HANDSHAKE_MAC_SHA384: |
| 1453 | return NID_sha384; |
| 1454 | } |
| 1455 | assert(0); |
| 1456 | return NID_undef; |
| 1457 | } |
| 1458 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1459 | int SSL_CIPHER_is_block_cipher(const SSL_CIPHER *cipher) { |
Matthew Braithwaite | 8aaa9e1 | 2016-09-07 15:09:58 -0700 | [diff] [blame] | 1460 | return (cipher->algorithm_enc & SSL_eNULL) == 0 && |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1461 | cipher->algorithm_mac != SSL_AEAD; |
| 1462 | } |
| 1463 | |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1464 | uint16_t SSL_CIPHER_get_min_version(const SSL_CIPHER *cipher) { |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1465 | if (cipher->algorithm_mkey == SSL_kGENERIC || |
| 1466 | cipher->algorithm_auth == SSL_aGENERIC) { |
| 1467 | return TLS1_3_VERSION; |
| 1468 | } |
| 1469 | |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1470 | if (cipher->algorithm_prf != SSL_HANDSHAKE_MAC_DEFAULT) { |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1471 | // Cipher suites before TLS 1.2 use the default PRF, while all those added |
| 1472 | // afterwards specify a particular hash. |
David Benjamin | ef793f4 | 2015-11-05 18:16:27 -0500 | [diff] [blame] | 1473 | return TLS1_2_VERSION; |
| 1474 | } |
| 1475 | return SSL3_VERSION; |
| 1476 | } |
| 1477 | |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1478 | uint16_t SSL_CIPHER_get_max_version(const SSL_CIPHER *cipher) { |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1479 | if (cipher->algorithm_mkey == SSL_kGENERIC || |
| 1480 | cipher->algorithm_auth == SSL_aGENERIC) { |
Nick Harper | 1fd39d8 | 2016-06-14 18:14:35 -0700 | [diff] [blame] | 1481 | return TLS1_3_VERSION; |
| 1482 | } |
| 1483 | return TLS1_2_VERSION; |
| 1484 | } |
| 1485 | |
David Benjamin | c11ea942 | 2017-08-29 16:33:21 -0400 | [diff] [blame] | 1486 | // return the actual cipher being used |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1487 | const char *SSL_CIPHER_get_name(const SSL_CIPHER *cipher) { |
| 1488 | if (cipher != NULL) { |
| 1489 | return cipher->name; |
| 1490 | } |
| 1491 | |
| 1492 | return "(NONE)"; |
| 1493 | } |
| 1494 | |
David Benjamin | 6fff386 | 2017-06-21 21:07:04 -0400 | [diff] [blame] | 1495 | const char *SSL_CIPHER_standard_name(const SSL_CIPHER *cipher) { |
| 1496 | return cipher->standard_name; |
| 1497 | } |
| 1498 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1499 | const char *SSL_CIPHER_get_kx_name(const SSL_CIPHER *cipher) { |
| 1500 | if (cipher == NULL) { |
| 1501 | return ""; |
| 1502 | } |
| 1503 | |
| 1504 | switch (cipher->algorithm_mkey) { |
| 1505 | case SSL_kRSA: |
| 1506 | return "RSA"; |
| 1507 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1508 | case SSL_kECDHE: |
| 1509 | switch (cipher->algorithm_auth) { |
| 1510 | case SSL_aECDSA: |
| 1511 | return "ECDHE_ECDSA"; |
| 1512 | case SSL_aRSA: |
| 1513 | return "ECDHE_RSA"; |
| 1514 | case SSL_aPSK: |
| 1515 | return "ECDHE_PSK"; |
| 1516 | default: |
| 1517 | assert(0); |
| 1518 | return "UNKNOWN"; |
| 1519 | } |
| 1520 | |
| 1521 | case SSL_kPSK: |
| 1522 | assert(cipher->algorithm_auth == SSL_aPSK); |
| 1523 | return "PSK"; |
| 1524 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1525 | case SSL_kGENERIC: |
| 1526 | assert(cipher->algorithm_auth == SSL_aGENERIC); |
| 1527 | return "GENERIC"; |
| 1528 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1529 | default: |
| 1530 | assert(0); |
| 1531 | return "UNKNOWN"; |
| 1532 | } |
| 1533 | } |
| 1534 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1535 | int SSL_CIPHER_get_bits(const SSL_CIPHER *cipher, int *out_alg_bits) { |
| 1536 | if (cipher == NULL) { |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1540 | int alg_bits, strength_bits; |
| 1541 | switch (cipher->algorithm_enc) { |
| 1542 | case SSL_AES128: |
| 1543 | case SSL_AES128GCM: |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1544 | alg_bits = 128; |
| 1545 | strength_bits = 128; |
| 1546 | break; |
| 1547 | |
| 1548 | case SSL_AES256: |
| 1549 | case SSL_AES256GCM: |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1550 | case SSL_CHACHA20POLY1305: |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1551 | alg_bits = 256; |
| 1552 | strength_bits = 256; |
| 1553 | break; |
| 1554 | |
| 1555 | case SSL_3DES: |
| 1556 | alg_bits = 168; |
| 1557 | strength_bits = 112; |
| 1558 | break; |
| 1559 | |
| 1560 | case SSL_eNULL: |
| 1561 | alg_bits = 0; |
| 1562 | strength_bits = 0; |
| 1563 | break; |
| 1564 | |
| 1565 | default: |
| 1566 | assert(0); |
| 1567 | alg_bits = 0; |
| 1568 | strength_bits = 0; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1569 | } |
David Benjamin | 9f2e277 | 2015-11-18 09:59:43 -0500 | [diff] [blame] | 1570 | |
| 1571 | if (out_alg_bits != NULL) { |
| 1572 | *out_alg_bits = alg_bits; |
| 1573 | } |
| 1574 | return strength_bits; |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1575 | } |
| 1576 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1577 | const char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, |
| 1578 | int len) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1579 | const char *kx, *au, *enc, *mac; |
David Benjamin | dcb6ef0 | 2015-11-06 15:35:54 -0500 | [diff] [blame] | 1580 | uint32_t alg_mkey, alg_auth, alg_enc, alg_mac; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1581 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1582 | alg_mkey = cipher->algorithm_mkey; |
| 1583 | alg_auth = cipher->algorithm_auth; |
| 1584 | alg_enc = cipher->algorithm_enc; |
| 1585 | alg_mac = cipher->algorithm_mac; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1586 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1587 | switch (alg_mkey) { |
| 1588 | case SSL_kRSA: |
| 1589 | kx = "RSA"; |
| 1590 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1591 | |
David Benjamin | 7061e28 | 2015-03-19 11:10:48 -0400 | [diff] [blame] | 1592 | case SSL_kECDHE: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1593 | kx = "ECDH"; |
| 1594 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1595 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1596 | case SSL_kPSK: |
| 1597 | kx = "PSK"; |
| 1598 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1599 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1600 | case SSL_kGENERIC: |
| 1601 | kx = "GENERIC"; |
| 1602 | break; |
| 1603 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1604 | default: |
| 1605 | kx = "unknown"; |
| 1606 | } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1607 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1608 | switch (alg_auth) { |
| 1609 | case SSL_aRSA: |
| 1610 | au = "RSA"; |
| 1611 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1612 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1613 | case SSL_aECDSA: |
| 1614 | au = "ECDSA"; |
| 1615 | break; |
Adam Langley | 4d4bff8 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1616 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1617 | case SSL_aPSK: |
| 1618 | au = "PSK"; |
| 1619 | break; |
Adam Langley | 4d4bff8 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1620 | |
Steven Valdez | 803c77a | 2016-09-06 14:13:43 -0400 | [diff] [blame] | 1621 | case SSL_aGENERIC: |
| 1622 | au = "GENERIC"; |
| 1623 | break; |
| 1624 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1625 | default: |
| 1626 | au = "unknown"; |
| 1627 | break; |
| 1628 | } |
Adam Langley | de0b202 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1629 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1630 | switch (alg_enc) { |
| 1631 | case SSL_3DES: |
| 1632 | enc = "3DES(168)"; |
| 1633 | break; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1634 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1635 | case SSL_AES128: |
| 1636 | enc = "AES(128)"; |
| 1637 | break; |
| 1638 | |
| 1639 | case SSL_AES256: |
| 1640 | enc = "AES(256)"; |
| 1641 | break; |
| 1642 | |
| 1643 | case SSL_AES128GCM: |
| 1644 | enc = "AESGCM(128)"; |
| 1645 | break; |
| 1646 | |
| 1647 | case SSL_AES256GCM: |
| 1648 | enc = "AESGCM(256)"; |
| 1649 | break; |
| 1650 | |
David Benjamin | 13414b3 | 2015-12-09 23:02:39 -0500 | [diff] [blame] | 1651 | case SSL_CHACHA20POLY1305: |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1652 | enc = "ChaCha20-Poly1305"; |
| 1653 | break; |
| 1654 | |
Matt Braithwaite | af09675 | 2015-09-02 19:48:16 -0700 | [diff] [blame] | 1655 | case SSL_eNULL: |
| 1656 | enc="None"; |
| 1657 | break; |
| 1658 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1659 | default: |
| 1660 | enc = "unknown"; |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | switch (alg_mac) { |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1665 | case SSL_SHA1: |
| 1666 | mac = "SHA1"; |
| 1667 | break; |
| 1668 | |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1669 | case SSL_AEAD: |
| 1670 | mac = "AEAD"; |
| 1671 | break; |
| 1672 | |
| 1673 | default: |
| 1674 | mac = "unknown"; |
| 1675 | break; |
| 1676 | } |
| 1677 | |
| 1678 | if (buf == NULL) { |
| 1679 | len = 128; |
David Benjamin | e64d2c7 | 2017-07-12 16:31:08 -0400 | [diff] [blame] | 1680 | buf = (char *)OPENSSL_malloc(len); |
David Benjamin | 1eed2c0 | 2015-02-08 23:20:06 -0500 | [diff] [blame] | 1681 | if (buf == NULL) { |
| 1682 | return NULL; |
| 1683 | } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1684 | } else if (len < 128) { |
| 1685 | return "Buffer too small"; |
| 1686 | } |
| 1687 | |
Brian Smith | 0687bdf | 2016-01-17 09:18:26 -1000 | [diff] [blame] | 1688 | BIO_snprintf(buf, len, "%-23s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n", |
| 1689 | cipher->name, kx, au, enc, mac); |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1690 | return buf; |
| 1691 | } |
| 1692 | |
David Benjamin | 71f0794 | 2015-04-08 02:36:59 -0400 | [diff] [blame] | 1693 | const char *SSL_CIPHER_get_version(const SSL_CIPHER *cipher) { |
| 1694 | return "TLSv1/SSLv3"; |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
David Benjamin | d55bd79 | 2017-05-18 11:33:08 -0400 | [diff] [blame] | 1697 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void) { return NULL; } |
Adam Langley | fcf2583 | 2014-12-18 17:42:32 -0800 | [diff] [blame] | 1698 | |
Matt Braithwaite | 6a1275b | 2015-06-26 12:09:10 -0700 | [diff] [blame] | 1699 | 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] | 1700 | |
Matt Braithwaite | 6a1275b | 2015-06-26 12:09:10 -0700 | [diff] [blame] | 1701 | const char *SSL_COMP_get_name(const COMP_METHOD *comp) { return NULL; } |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1702 | |
Adam Langley | fa3e9c3 | 2018-03-14 17:32:04 -0700 | [diff] [blame] | 1703 | const char *SSL_COMP_get0_name(const SSL_COMP *comp) { return comp->name; } |
| 1704 | |
| 1705 | int SSL_COMP_get_id(const SSL_COMP *comp) { return comp->id; } |
| 1706 | |
Adam Langley | 3e9e043 | 2016-10-03 15:58:07 -0700 | [diff] [blame] | 1707 | void SSL_COMP_free_compression_methods(void) {} |