Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 2 | #include <mbedtls/ssl.h> |
Manuel Pégourié-Gonnard | 5e94dde | 2015-05-26 11:57:05 +0200 | [diff] [blame] | 3 | #include <mbedtls/ssl_internal.h> |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 4 | #include <mbedtls/md.h> |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 5 | |
| 6 | /* |
| 7 | * Helper function setting up inverse record transformations |
| 8 | * using given cipher, hash, EtM mode, authentication tag length, |
| 9 | * and version. |
| 10 | */ |
| 11 | |
| 12 | #define CHK( x ) \ |
| 13 | do \ |
| 14 | { \ |
| 15 | if( !( x ) ) \ |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 16 | { \ |
Hanno Becker | 1acadb7 | 2019-04-05 09:55:37 +0100 | [diff] [blame] | 17 | ret = -1; \ |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 18 | goto cleanup; \ |
| 19 | } \ |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 20 | } while( 0 ) |
| 21 | |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 22 | #if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX |
| 23 | #define SSL_CID_LEN_MIN MBEDTLS_SSL_CID_IN_LEN_MAX |
| 24 | #else |
| 25 | #define SSL_CID_LEN_MIN MBEDTLS_SSL_CID_OUT_LEN_MAX |
| 26 | #endif |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 27 | |
| 28 | static int build_transforms( mbedtls_ssl_transform *t_in, |
| 29 | mbedtls_ssl_transform *t_out, |
| 30 | int cipher_type, int hash_id, |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 31 | int etm, int tag_mode, int ver, |
| 32 | size_t cid0_len, |
| 33 | size_t cid1_len ) |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 34 | { |
| 35 | mbedtls_cipher_info_t const *cipher_info; |
Hanno Becker | 1acadb7 | 2019-04-05 09:55:37 +0100 | [diff] [blame] | 36 | int ret = 0; |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 37 | |
| 38 | size_t keylen, maclen, ivlen; |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 39 | unsigned char *key0 = NULL, *key1 = NULL; |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 40 | unsigned char iv_enc[16], iv_dec[16]; |
| 41 | |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 42 | #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 43 | unsigned char cid0[ SSL_CID_LEN_MIN ]; |
| 44 | unsigned char cid1[ SSL_CID_LEN_MIN ]; |
| 45 | |
| 46 | rnd_std_rand( NULL, cid0, sizeof( cid0 ) ); |
| 47 | rnd_std_rand( NULL, cid1, sizeof( cid1 ) ); |
Hanno Becker | 505089d | 2019-05-01 09:45:57 +0100 | [diff] [blame] | 48 | #else |
| 49 | ((void) cid0_len); |
| 50 | ((void) cid1_len); |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 51 | #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 52 | |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 53 | maclen = 0; |
| 54 | |
| 55 | /* Pick cipher */ |
| 56 | cipher_info = mbedtls_cipher_info_from_type( cipher_type ); |
| 57 | CHK( cipher_info != NULL ); |
| 58 | CHK( cipher_info->iv_size <= 16 ); |
| 59 | CHK( cipher_info->key_bitlen % 8 == 0 ); |
| 60 | |
| 61 | /* Pick keys */ |
| 62 | keylen = cipher_info->key_bitlen / 8; |
Hanno Becker | a131766 | 2019-04-05 09:56:10 +0100 | [diff] [blame] | 63 | /* Allocate `keylen + 1` bytes to ensure that we get |
| 64 | * a non-NULL pointers from `mbedtls_calloc` even if |
| 65 | * `keylen == 0` in the case of the NULL cipher. */ |
| 66 | CHK( ( key0 = mbedtls_calloc( 1, keylen + 1 ) ) != NULL ); |
| 67 | CHK( ( key1 = mbedtls_calloc( 1, keylen + 1 ) ) != NULL ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 68 | memset( key0, 0x1, keylen ); |
| 69 | memset( key1, 0x2, keylen ); |
| 70 | |
| 71 | /* Setup cipher contexts */ |
| 72 | CHK( mbedtls_cipher_setup( &t_in->cipher_ctx_enc, cipher_info ) == 0 ); |
| 73 | CHK( mbedtls_cipher_setup( &t_in->cipher_ctx_dec, cipher_info ) == 0 ); |
| 74 | CHK( mbedtls_cipher_setup( &t_out->cipher_ctx_enc, cipher_info ) == 0 ); |
| 75 | CHK( mbedtls_cipher_setup( &t_out->cipher_ctx_dec, cipher_info ) == 0 ); |
| 76 | |
| 77 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 78 | if( cipher_info->mode == MBEDTLS_MODE_CBC ) |
| 79 | { |
| 80 | CHK( mbedtls_cipher_set_padding_mode( &t_in->cipher_ctx_enc, |
| 81 | MBEDTLS_PADDING_NONE ) == 0 ); |
| 82 | CHK( mbedtls_cipher_set_padding_mode( &t_in->cipher_ctx_dec, |
| 83 | MBEDTLS_PADDING_NONE ) == 0 ); |
| 84 | CHK( mbedtls_cipher_set_padding_mode( &t_out->cipher_ctx_enc, |
| 85 | MBEDTLS_PADDING_NONE ) == 0 ); |
| 86 | CHK( mbedtls_cipher_set_padding_mode( &t_out->cipher_ctx_dec, |
| 87 | MBEDTLS_PADDING_NONE ) == 0 ); |
| 88 | } |
| 89 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 90 | |
| 91 | CHK( mbedtls_cipher_setkey( &t_in->cipher_ctx_enc, key0, |
| 92 | keylen << 3, MBEDTLS_ENCRYPT ) == 0 ); |
| 93 | CHK( mbedtls_cipher_setkey( &t_in->cipher_ctx_dec, key1, |
| 94 | keylen << 3, MBEDTLS_DECRYPT ) == 0 ); |
| 95 | CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_enc, key1, |
| 96 | keylen << 3, MBEDTLS_ENCRYPT ) == 0 ); |
| 97 | CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_dec, key0, |
| 98 | keylen << 3, MBEDTLS_DECRYPT ) == 0 ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 99 | |
| 100 | /* Setup MAC contexts */ |
| 101 | #if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC) |
| 102 | if( cipher_info->mode == MBEDTLS_MODE_CBC || |
| 103 | cipher_info->mode == MBEDTLS_MODE_STREAM ) |
| 104 | { |
| 105 | mbedtls_md_info_t const *md_info; |
| 106 | unsigned char *md0, *md1; |
| 107 | |
| 108 | /* Pick hash */ |
| 109 | md_info = mbedtls_md_info_from_type( hash_id ); |
| 110 | CHK( md_info != NULL ); |
| 111 | |
| 112 | /* Pick hash keys */ |
| 113 | maclen = mbedtls_md_get_size( md_info ); |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 114 | CHK( ( md0 = mbedtls_calloc( 1, maclen ) ) != NULL ); |
| 115 | CHK( ( md1 = mbedtls_calloc( 1, maclen ) ) != NULL ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 116 | memset( md0, 0x5, maclen ); |
| 117 | memset( md1, 0x6, maclen ); |
| 118 | |
| 119 | CHK( mbedtls_md_setup( &t_out->md_ctx_enc, md_info, 1 ) == 0 ); |
| 120 | CHK( mbedtls_md_setup( &t_out->md_ctx_dec, md_info, 1 ) == 0 ); |
| 121 | CHK( mbedtls_md_setup( &t_in->md_ctx_enc, md_info, 1 ) == 0 ); |
| 122 | CHK( mbedtls_md_setup( &t_in->md_ctx_dec, md_info, 1 ) == 0 ); |
| 123 | |
| 124 | if( ver > MBEDTLS_SSL_MINOR_VERSION_0 ) |
| 125 | { |
| 126 | CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_enc, |
| 127 | md0, maclen ) == 0 ); |
| 128 | CHK( mbedtls_md_hmac_starts( &t_in->md_ctx_dec, |
| 129 | md1, maclen ) == 0 ); |
| 130 | CHK( mbedtls_md_hmac_starts( &t_out->md_ctx_enc, |
| 131 | md1, maclen ) == 0 ); |
| 132 | CHK( mbedtls_md_hmac_starts( &t_out->md_ctx_dec, |
| 133 | md0, maclen ) == 0 ); |
| 134 | } |
| 135 | #if defined(MBEDTLS_SSL_PROTO_SSL3) |
| 136 | else |
| 137 | { |
| 138 | memcpy( &t_in->mac_enc, md0, maclen ); |
| 139 | memcpy( &t_in->mac_dec, md1, maclen ); |
| 140 | memcpy( &t_out->mac_enc, md1, maclen ); |
| 141 | memcpy( &t_out->mac_dec, md0, maclen ); |
| 142 | } |
| 143 | #endif |
| 144 | |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 145 | mbedtls_free( md0 ); |
| 146 | mbedtls_free( md1 ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 147 | } |
| 148 | #else |
| 149 | ((void) hash_id); |
| 150 | #endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */ |
| 151 | |
| 152 | |
| 153 | /* Pick IV's (regardless of whether they |
| 154 | * are being used by the transform). */ |
| 155 | ivlen = cipher_info->iv_size; |
| 156 | memset( iv_enc, 0x3, sizeof( iv_enc ) ); |
| 157 | memset( iv_dec, 0x4, sizeof( iv_dec ) ); |
| 158 | |
| 159 | /* |
| 160 | * Setup transforms |
| 161 | */ |
| 162 | |
Jaeden Amero | 2eaf2c7 | 2019-06-05 13:32:08 +0100 | [diff] [blame] | 163 | #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \ |
| 164 | defined(MBEDTLS_SSL_SOME_MODES_USE_MAC) |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 165 | t_out->encrypt_then_mac = etm; |
| 166 | t_in->encrypt_then_mac = etm; |
| 167 | #else |
| 168 | ((void) etm); |
| 169 | #endif |
| 170 | |
Hanno Becker | ac8c984 | 2019-07-05 13:53:06 +0100 | [diff] [blame^] | 171 | #if !defined(MBEDTLS_SSL_CONF_FIXED_MINOR_VER) |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 172 | t_out->minor_ver = ver; |
| 173 | t_in->minor_ver = ver; |
Hanno Becker | ac8c984 | 2019-07-05 13:53:06 +0100 | [diff] [blame^] | 174 | #endif |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 175 | t_out->ivlen = ivlen; |
| 176 | t_in->ivlen = ivlen; |
| 177 | |
| 178 | switch( cipher_info->mode ) |
| 179 | { |
| 180 | case MBEDTLS_MODE_GCM: |
| 181 | case MBEDTLS_MODE_CCM: |
| 182 | t_out->fixed_ivlen = 4; |
| 183 | t_in->fixed_ivlen = 4; |
| 184 | t_out->maclen = 0; |
| 185 | t_in->maclen = 0; |
| 186 | switch( tag_mode ) |
| 187 | { |
| 188 | case 0: /* Full tag */ |
| 189 | t_out->taglen = 16; |
| 190 | t_in->taglen = 16; |
| 191 | break; |
| 192 | case 1: /* Partial tag */ |
| 193 | t_out->taglen = 8; |
| 194 | t_in->taglen = 8; |
| 195 | break; |
| 196 | default: |
| 197 | return( 1 ); |
| 198 | } |
| 199 | break; |
| 200 | |
| 201 | case MBEDTLS_MODE_CHACHAPOLY: |
| 202 | t_out->fixed_ivlen = 12; |
| 203 | t_in->fixed_ivlen = 12; |
| 204 | t_out->maclen = 0; |
| 205 | t_in->maclen = 0; |
| 206 | switch( tag_mode ) |
| 207 | { |
| 208 | case 0: /* Full tag */ |
| 209 | t_out->taglen = 16; |
| 210 | t_in->taglen = 16; |
| 211 | break; |
| 212 | case 1: /* Partial tag */ |
| 213 | t_out->taglen = 8; |
| 214 | t_in->taglen = 8; |
| 215 | break; |
| 216 | default: |
| 217 | return( 1 ); |
| 218 | } |
| 219 | break; |
| 220 | |
| 221 | case MBEDTLS_MODE_STREAM: |
| 222 | case MBEDTLS_MODE_CBC: |
| 223 | t_out->fixed_ivlen = 0; /* redundant, must be 0 */ |
| 224 | t_in->fixed_ivlen = 0; /* redundant, must be 0 */ |
| 225 | t_out->taglen = 0; |
| 226 | t_in->taglen = 0; |
| 227 | switch( tag_mode ) |
| 228 | { |
| 229 | case 0: /* Full tag */ |
| 230 | t_out->maclen = maclen; |
| 231 | t_in->maclen = maclen; |
| 232 | break; |
| 233 | case 1: /* Partial tag */ |
| 234 | t_out->maclen = 10; |
| 235 | t_in->maclen = 10; |
| 236 | break; |
| 237 | default: |
| 238 | return( 1 ); |
| 239 | } |
| 240 | break; |
| 241 | default: |
| 242 | return( 1 ); |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | /* Setup IV's */ |
| 247 | |
| 248 | memcpy( &t_in->iv_dec, iv_dec, sizeof( iv_dec ) ); |
| 249 | memcpy( &t_in->iv_enc, iv_enc, sizeof( iv_enc ) ); |
| 250 | memcpy( &t_out->iv_dec, iv_enc, sizeof( iv_enc ) ); |
| 251 | memcpy( &t_out->iv_enc, iv_dec, sizeof( iv_dec ) ); |
| 252 | |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 253 | #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 254 | /* Add CID */ |
| 255 | memcpy( &t_in->in_cid, cid0, cid0_len ); |
| 256 | memcpy( &t_in->out_cid, cid1, cid1_len ); |
| 257 | t_in->in_cid_len = cid0_len; |
| 258 | t_in->out_cid_len = cid1_len; |
| 259 | memcpy( &t_out->in_cid, cid1, cid1_len ); |
| 260 | memcpy( &t_out->out_cid, cid0, cid0_len ); |
| 261 | t_out->in_cid_len = cid1_len; |
| 262 | t_out->out_cid_len = cid0_len; |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 263 | #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 264 | |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 265 | cleanup: |
| 266 | |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 267 | mbedtls_free( key0 ); |
| 268 | mbedtls_free( key1 ); |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 269 | |
Hanno Becker | 1acadb7 | 2019-04-05 09:55:37 +0100 | [diff] [blame] | 270 | return( ret ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 273 | /* |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 274 | * Populate a session structure for serialization tests. |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 275 | * Choose dummy values, mostly non-0 to distinguish from the init default. |
| 276 | */ |
| 277 | static int ssl_populate_session( mbedtls_ssl_session *session, |
Manuel Pégourié-Gonnard | d1a5451 | 2019-05-24 09:54:21 +0200 | [diff] [blame] | 278 | int ticket_len, |
| 279 | const char *crt_file ) |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 280 | { |
| 281 | #if defined(MBEDTLS_HAVE_TIME) |
| 282 | session->start = mbedtls_time( NULL ) - 42; |
| 283 | #endif |
Hanno Becker | e02758c | 2019-06-26 15:31:31 +0100 | [diff] [blame] | 284 | #if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE) |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 285 | session->ciphersuite = 0xabcd; |
Hanno Becker | e02758c | 2019-06-26 15:31:31 +0100 | [diff] [blame] | 286 | #endif |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 287 | session->compression = 1; |
| 288 | session->id_len = sizeof( session->id ); |
| 289 | memset( session->id, 66, session->id_len ); |
Manuel Pégourié-Gonnard | d1a5451 | 2019-05-24 09:54:21 +0200 | [diff] [blame] | 290 | memset( session->master, 17, sizeof( session->master ) ); |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 291 | |
Manuel Pégourié-Gonnard | 749312f | 2019-05-24 10:17:52 +0200 | [diff] [blame] | 292 | #if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_FS_IO) |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 293 | if( strlen( crt_file ) != 0 ) |
| 294 | { |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 295 | mbedtls_x509_crt tmp_crt; |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 296 | int ret; |
Manuel Pégourié-Gonnard | aab6204 | 2019-05-24 09:40:17 +0200 | [diff] [blame] | 297 | |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 298 | mbedtls_x509_crt_init( &tmp_crt ); |
| 299 | ret = mbedtls_x509_crt_parse_file( &tmp_crt, crt_file ); |
| 300 | if( ret != 0 ) |
| 301 | return( ret ); |
| 302 | |
Hanno Becker | 5882dd0 | 2019-06-06 16:25:57 +0100 | [diff] [blame] | 303 | #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) |
| 304 | /* Move temporary CRT. */ |
| 305 | session->peer_cert = mbedtls_calloc( 1, sizeof( *session->peer_cert ) ); |
| 306 | if( session->peer_cert == NULL ) |
| 307 | return( -1 ); |
| 308 | *session->peer_cert = tmp_crt; |
| 309 | memset( &tmp_crt, 0, sizeof( tmp_crt ) ); |
| 310 | #elif defined(MBEDTLS_SSL_RENEGOTIATION) |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 311 | /* Calculate digest of temporary CRT. */ |
| 312 | session->peer_cert_digest = |
| 313 | mbedtls_calloc( 1, MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN ); |
| 314 | if( session->peer_cert_digest == NULL ) |
| 315 | return( -1 ); |
| 316 | ret = mbedtls_md( mbedtls_md_info_from_type( |
| 317 | MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE ), |
| 318 | tmp_crt.raw.p, tmp_crt.raw.len, |
| 319 | session->peer_cert_digest ); |
| 320 | if( ret != 0 ) |
| 321 | return( ret ); |
| 322 | session->peer_cert_digest_type = |
| 323 | MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE; |
| 324 | session->peer_cert_digest_len = |
| 325 | MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN; |
Hanno Becker | 5882dd0 | 2019-06-06 16:25:57 +0100 | [diff] [blame] | 326 | #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE && MBEDTLS_SSL_RENEGOTIATION */ |
Manuel Pégourié-Gonnard | aab6204 | 2019-05-24 09:40:17 +0200 | [diff] [blame] | 327 | |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 328 | mbedtls_x509_crt_free( &tmp_crt ); |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 329 | } |
| 330 | #else |
| 331 | (void) crt_file; |
| 332 | #endif |
| 333 | session->verify_result = 0xdeadbeef; |
| 334 | |
| 335 | #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C) |
| 336 | if( ticket_len != 0 ) |
| 337 | { |
| 338 | session->ticket = mbedtls_calloc( 1, ticket_len ); |
Manuel Pégourié-Gonnard | d1a5451 | 2019-05-24 09:54:21 +0200 | [diff] [blame] | 339 | if( session->ticket == NULL ) |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 340 | return( -1 ); |
| 341 | memset( session->ticket, 33, ticket_len ); |
| 342 | } |
| 343 | session->ticket_len = ticket_len; |
| 344 | session->ticket_lifetime = 86401; |
| 345 | #else |
| 346 | (void) ticket_len; |
| 347 | #endif |
| 348 | |
| 349 | #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) |
| 350 | session->mfl_code = 1; |
| 351 | #endif |
| 352 | #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) |
| 353 | session->trunc_hmac = 1; |
| 354 | #endif |
| 355 | #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) |
| 356 | session->encrypt_then_mac = 1; |
| 357 | #endif |
| 358 | |
| 359 | return( 0 ); |
| 360 | } |
| 361 | |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 362 | /* END_HEADER */ |
| 363 | |
| 364 | /* BEGIN_DEPENDENCIES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 365 | * depends_on:MBEDTLS_SSL_TLS_C |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 366 | * END_DEPENDENCIES |
| 367 | */ |
| 368 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 369 | /* BEGIN_CASE depends_on:MBEDTLS_SSL_DTLS_ANTI_REPLAY */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 370 | void ssl_dtls_replay( data_t * prevs, data_t * new, int ret ) |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 371 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 372 | uint32_t len = 0; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 373 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 374 | mbedtls_ssl_config conf; |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 375 | |
Manuel Pégourié-Gonnard | 41d479e | 2015-04-29 00:48:22 +0200 | [diff] [blame] | 376 | mbedtls_ssl_init( &ssl ); |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 377 | mbedtls_ssl_config_init( &conf ); |
Manuel Pégourié-Gonnard | 41d479e | 2015-04-29 00:48:22 +0200 | [diff] [blame] | 378 | |
Manuel Pégourié-Gonnard | 419d5ae | 2015-05-04 19:32:36 +0200 | [diff] [blame] | 379 | TEST_ASSERT( mbedtls_ssl_config_defaults( &conf, |
| 380 | MBEDTLS_SSL_IS_CLIENT, |
Manuel Pégourié-Gonnard | b31c5f6 | 2015-06-17 13:53:47 +0200 | [diff] [blame] | 381 | MBEDTLS_SSL_TRANSPORT_DATAGRAM, |
| 382 | MBEDTLS_SSL_PRESET_DEFAULT ) == 0 ); |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 383 | TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 ); |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 384 | |
| 385 | /* Read previous record numbers */ |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 386 | for( len = 0; len < prevs->len; len += 6 ) |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 387 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 388 | memcpy( ssl.in_ctr + 2, prevs->x + len, 6 ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 389 | mbedtls_ssl_dtls_replay_update( &ssl ); |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* Check new number */ |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 393 | memcpy( ssl.in_ctr + 2, new->x, 6 ); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 394 | TEST_ASSERT( mbedtls_ssl_dtls_replay_check( &ssl ) == ret ); |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 395 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 396 | mbedtls_ssl_free( &ssl ); |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 397 | mbedtls_ssl_config_free( &conf ); |
Manuel Pégourié-Gonnard | 4956fd7 | 2014-09-24 11:13:44 +0200 | [diff] [blame] | 398 | } |
| 399 | /* END_CASE */ |
Hanno Becker | b25c0c7 | 2017-05-05 11:24:30 +0100 | [diff] [blame] | 400 | |
| 401 | /* BEGIN_CASE depends_on:MBEDTLS_X509_CRT_PARSE_C */ |
| 402 | void ssl_set_hostname_twice( char *hostname0, char *hostname1 ) |
| 403 | { |
| 404 | mbedtls_ssl_context ssl; |
| 405 | mbedtls_ssl_init( &ssl ); |
| 406 | |
| 407 | TEST_ASSERT( mbedtls_ssl_set_hostname( &ssl, hostname0 ) == 0 ); |
| 408 | TEST_ASSERT( mbedtls_ssl_set_hostname( &ssl, hostname1 ) == 0 ); |
| 409 | |
| 410 | mbedtls_ssl_free( &ssl ); |
| 411 | } |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 412 | /* END_CASE */ |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 413 | |
| 414 | /* BEGIN_CASE */ |
| 415 | void ssl_crypt_record( int cipher_type, int hash_id, |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 416 | int etm, int tag_mode, int ver, |
| 417 | int cid0_len, int cid1_len ) |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 418 | { |
| 419 | /* |
| 420 | * Test several record encryptions and decryptions |
| 421 | * with plenty of space before and after the data |
| 422 | * within the record buffer. |
| 423 | */ |
| 424 | |
| 425 | int ret; |
| 426 | int num_records = 16; |
| 427 | mbedtls_ssl_context ssl; /* ONLY for debugging */ |
| 428 | |
| 429 | mbedtls_ssl_transform t0, t1; |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 430 | unsigned char *buf = NULL; |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 431 | size_t const buflen = 512; |
| 432 | mbedtls_record rec, rec_backup; |
| 433 | |
| 434 | mbedtls_ssl_init( &ssl ); |
| 435 | mbedtls_ssl_transform_init( &t0 ); |
| 436 | mbedtls_ssl_transform_init( &t1 ); |
Hanno Becker | ac8c984 | 2019-07-05 13:53:06 +0100 | [diff] [blame^] | 437 | |
| 438 | #if defined(MBEDTLS_SSL_CONF_FIXED_MINOR_VER) |
| 439 | TEST_ASSUME( ver == MBEDTLS_SSL_CONF_FIXED_MINOR_VER ); |
| 440 | #endif |
| 441 | |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 442 | TEST_ASSERT( build_transforms( &t0, &t1, cipher_type, hash_id, |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 443 | etm, tag_mode, ver, |
| 444 | (size_t) cid0_len, |
| 445 | (size_t) cid1_len ) == 0 ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 446 | |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 447 | TEST_ASSERT( ( buf = mbedtls_calloc( 1, buflen ) ) != NULL ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 448 | |
| 449 | while( num_records-- > 0 ) |
| 450 | { |
| 451 | mbedtls_ssl_transform *t_dec, *t_enc; |
| 452 | /* Take turns in who's sending and who's receiving. */ |
| 453 | if( num_records % 3 == 0 ) |
| 454 | { |
| 455 | t_dec = &t0; |
| 456 | t_enc = &t1; |
| 457 | } |
| 458 | else |
| 459 | { |
| 460 | t_dec = &t1; |
| 461 | t_enc = &t0; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * The record header affects the transformation in two ways: |
| 466 | * 1) It determines the AEAD additional data |
| 467 | * 2) The record counter sometimes determines the IV. |
| 468 | * |
| 469 | * Apart from that, the fields don't have influence. |
| 470 | * In particular, it is currently not the responsibility |
| 471 | * of ssl_encrypt/decrypt_buf to check if the transform |
| 472 | * version matches the record version, or that the |
| 473 | * type is sensible. |
| 474 | */ |
| 475 | |
| 476 | memset( rec.ctr, num_records, sizeof( rec.ctr ) ); |
| 477 | rec.type = 42; |
| 478 | rec.ver[0] = num_records; |
| 479 | rec.ver[1] = num_records; |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 480 | #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 481 | rec.cid_len = 0; |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 482 | #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 483 | |
| 484 | rec.buf = buf; |
| 485 | rec.buf_len = buflen; |
| 486 | rec.data_offset = 16; |
| 487 | /* Make sure to vary the length to exercise different |
| 488 | * paddings. */ |
| 489 | rec.data_len = 1 + num_records; |
| 490 | |
| 491 | memset( rec.buf + rec.data_offset, 42, rec.data_len ); |
| 492 | |
| 493 | /* Make a copy for later comparison */ |
| 494 | rec_backup = rec; |
| 495 | |
| 496 | /* Encrypt record */ |
| 497 | ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec, |
| 498 | rnd_std_rand, NULL ); |
| 499 | TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 500 | if( ret != 0 ) |
| 501 | { |
| 502 | continue; |
| 503 | } |
| 504 | |
| 505 | /* Decrypt record with t_dec */ |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 506 | ret = mbedtls_ssl_decrypt_buf( &ssl, t_dec, &rec ); |
| 507 | TEST_ASSERT( ret == 0 ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 508 | |
| 509 | /* Compare results */ |
| 510 | TEST_ASSERT( rec.type == rec_backup.type ); |
| 511 | TEST_ASSERT( memcmp( rec.ctr, rec_backup.ctr, 8 ) == 0 ); |
| 512 | TEST_ASSERT( rec.ver[0] == rec_backup.ver[0] ); |
| 513 | TEST_ASSERT( rec.ver[1] == rec_backup.ver[1] ); |
| 514 | TEST_ASSERT( rec.data_len == rec_backup.data_len ); |
| 515 | TEST_ASSERT( rec.data_offset == rec_backup.data_offset ); |
| 516 | TEST_ASSERT( memcmp( rec.buf + rec.data_offset, |
| 517 | rec_backup.buf + rec_backup.data_offset, |
| 518 | rec.data_len ) == 0 ); |
| 519 | } |
| 520 | |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 521 | exit: |
| 522 | |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 523 | /* Cleanup */ |
| 524 | mbedtls_ssl_free( &ssl ); |
| 525 | mbedtls_ssl_transform_free( &t0 ); |
| 526 | mbedtls_ssl_transform_free( &t1 ); |
| 527 | |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 528 | mbedtls_free( buf ); |
Hanno Becker | 611a83b | 2018-01-03 14:27:32 +0000 | [diff] [blame] | 529 | } |
| 530 | /* END_CASE */ |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 531 | |
| 532 | /* BEGIN_CASE */ |
| 533 | void ssl_crypt_record_small( int cipher_type, int hash_id, |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 534 | int etm, int tag_mode, int ver, |
| 535 | int cid0_len, int cid1_len ) |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 536 | { |
| 537 | /* |
| 538 | * Test pairs of encryption and decryption with an increasing |
| 539 | * amount of space in the record buffer - in more detail: |
| 540 | * 1) Try to encrypt with 0, 1, 2, ... bytes available |
| 541 | * in front of the plaintext, and expect the encryption |
| 542 | * to succeed starting from some offset. Always keep |
| 543 | * enough space in the end of the buffer. |
| 544 | * 2) Try to encrypt with 0, 1, 2, ... bytes available |
| 545 | * at the end of the plaintext, and expect the encryption |
| 546 | * to succeed starting from some offset. Always keep |
| 547 | * enough space at the beginning of the buffer. |
| 548 | * 3) Try to encrypt with 0, 1, 2, ... bytes available |
| 549 | * both at the front and end of the plaintext, |
| 550 | * and expect the encryption to succeed starting from |
| 551 | * some offset. |
| 552 | * |
| 553 | * If encryption succeeds, check that decryption succeeds |
| 554 | * and yields the original record. |
| 555 | */ |
| 556 | |
| 557 | mbedtls_ssl_context ssl; /* ONLY for debugging */ |
| 558 | |
| 559 | mbedtls_ssl_transform t0, t1; |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 560 | unsigned char *buf = NULL; |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 561 | size_t const buflen = 256; |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 562 | mbedtls_record rec, rec_backup; |
| 563 | |
| 564 | int ret; |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 565 | int mode; /* Mode 1, 2 or 3 as explained above */ |
| 566 | size_t offset; /* Available space at beginning/end/both */ |
| 567 | size_t threshold = 96; /* Maximum offset to test against */ |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 568 | |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 569 | size_t default_pre_padding = 64; /* Pre-padding to use in mode 2 */ |
| 570 | size_t default_post_padding = 128; /* Post-padding to use in mode 1 */ |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 571 | |
| 572 | int seen_success; /* Indicates if in the current mode we've |
| 573 | * already seen a successful test. */ |
| 574 | |
| 575 | mbedtls_ssl_init( &ssl ); |
| 576 | mbedtls_ssl_transform_init( &t0 ); |
| 577 | mbedtls_ssl_transform_init( &t1 ); |
| 578 | TEST_ASSERT( build_transforms( &t0, &t1, cipher_type, hash_id, |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 579 | etm, tag_mode, ver, |
| 580 | (size_t) cid0_len, |
| 581 | (size_t) cid1_len ) == 0 ); |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 582 | |
Hanno Becker | ac8c984 | 2019-07-05 13:53:06 +0100 | [diff] [blame^] | 583 | #if defined(MBEDTLS_SSL_CONF_FIXED_MINOR_VER) |
| 584 | TEST_ASSUME( ver == MBEDTLS_SSL_CONF_FIXED_MINOR_VER ); |
| 585 | #endif |
| 586 | |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 587 | TEST_ASSERT( ( buf = mbedtls_calloc( 1, buflen ) ) != NULL ); |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 588 | |
| 589 | for( mode=1; mode <= 3; mode++ ) |
| 590 | { |
| 591 | seen_success = 0; |
| 592 | for( offset=0; offset <= threshold; offset++ ) |
| 593 | { |
| 594 | mbedtls_ssl_transform *t_dec, *t_enc; |
Hanno Becker | 36fb379 | 2019-04-29 17:24:44 +0100 | [diff] [blame] | 595 | t_dec = &t0; |
| 596 | t_enc = &t1; |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 597 | |
| 598 | memset( rec.ctr, offset, sizeof( rec.ctr ) ); |
| 599 | rec.type = 42; |
| 600 | rec.ver[0] = offset; |
| 601 | rec.ver[1] = offset; |
| 602 | rec.buf = buf; |
| 603 | rec.buf_len = buflen; |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 604 | #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) |
Hanno Becker | d8f753b | 2019-04-29 17:30:59 +0100 | [diff] [blame] | 605 | rec.cid_len = 0; |
Hanno Becker | a5a2b08 | 2019-05-15 14:03:01 +0100 | [diff] [blame] | 606 | #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */ |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 607 | |
| 608 | switch( mode ) |
| 609 | { |
| 610 | case 1: /* Space in the beginning */ |
| 611 | rec.data_offset = offset; |
| 612 | rec.data_len = buflen - offset - default_post_padding; |
| 613 | break; |
| 614 | |
| 615 | case 2: /* Space in the end */ |
| 616 | rec.data_offset = default_pre_padding; |
| 617 | rec.data_len = buflen - default_pre_padding - offset; |
| 618 | break; |
| 619 | |
| 620 | case 3: /* Space in the beginning and end */ |
| 621 | rec.data_offset = offset; |
| 622 | rec.data_len = buflen - 2 * offset; |
| 623 | break; |
| 624 | |
| 625 | default: |
| 626 | TEST_ASSERT( 0 ); |
| 627 | break; |
| 628 | } |
| 629 | |
| 630 | memset( rec.buf + rec.data_offset, 42, rec.data_len ); |
| 631 | |
| 632 | /* Make a copy for later comparison */ |
| 633 | rec_backup = rec; |
| 634 | |
| 635 | /* Encrypt record */ |
| 636 | ret = mbedtls_ssl_encrypt_buf( &ssl, t_enc, &rec, rnd_std_rand, NULL ); |
| 637 | |
| 638 | if( ( mode == 1 || mode == 2 ) && seen_success ) |
| 639 | { |
| 640 | TEST_ASSERT( ret == 0 ); |
| 641 | } |
| 642 | else |
| 643 | { |
| 644 | TEST_ASSERT( ret == 0 || ret == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 645 | if( ret == 0 ) |
| 646 | seen_success = 1; |
| 647 | } |
| 648 | |
| 649 | if( ret != 0 ) |
| 650 | continue; |
| 651 | |
| 652 | /* Decrypt record with t_dec */ |
| 653 | TEST_ASSERT( mbedtls_ssl_decrypt_buf( &ssl, t_dec, &rec ) == 0 ); |
| 654 | |
| 655 | /* Compare results */ |
| 656 | TEST_ASSERT( rec.type == rec_backup.type ); |
| 657 | TEST_ASSERT( memcmp( rec.ctr, rec_backup.ctr, 8 ) == 0 ); |
| 658 | TEST_ASSERT( rec.ver[0] == rec_backup.ver[0] ); |
| 659 | TEST_ASSERT( rec.ver[1] == rec_backup.ver[1] ); |
| 660 | TEST_ASSERT( rec.data_len == rec_backup.data_len ); |
| 661 | TEST_ASSERT( rec.data_offset == rec_backup.data_offset ); |
| 662 | TEST_ASSERT( memcmp( rec.buf + rec.data_offset, |
| 663 | rec_backup.buf + rec_backup.data_offset, |
| 664 | rec.data_len ) == 0 ); |
| 665 | } |
| 666 | |
| 667 | TEST_ASSERT( seen_success == 1 ); |
| 668 | } |
| 669 | |
Hanno Becker | 5c1176e | 2019-03-01 11:21:44 +0000 | [diff] [blame] | 670 | exit: |
| 671 | |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 672 | /* Cleanup */ |
| 673 | mbedtls_ssl_free( &ssl ); |
| 674 | mbedtls_ssl_transform_free( &t0 ); |
| 675 | mbedtls_ssl_transform_free( &t1 ); |
| 676 | |
Hanno Becker | afc528a | 2019-04-04 16:31:26 +0100 | [diff] [blame] | 677 | mbedtls_free( buf ); |
Hanno Becker | d300003 | 2018-01-05 15:20:24 +0000 | [diff] [blame] | 678 | } |
| 679 | /* END_CASE */ |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 680 | |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 681 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 682 | void ssl_serialize_session_save_load( int ticket_len, char *crt_file ) |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 683 | { |
| 684 | mbedtls_ssl_session original, restored; |
| 685 | unsigned char *buf = NULL; |
| 686 | size_t len; |
| 687 | |
| 688 | /* |
| 689 | * Test that a save-load pair is the identity |
| 690 | */ |
| 691 | |
| 692 | mbedtls_ssl_session_init( &original ); |
| 693 | mbedtls_ssl_session_init( &restored ); |
| 694 | |
| 695 | /* Prepare a dummy session to work on */ |
| 696 | TEST_ASSERT( ssl_populate_session( &original, ticket_len, crt_file ) == 0 ); |
| 697 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 698 | /* Serialize it */ |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 699 | TEST_ASSERT( mbedtls_ssl_session_save( &original, NULL, 0, &len ) |
| 700 | == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 701 | TEST_ASSERT( ( buf = mbedtls_calloc( 1, len ) ) != NULL ); |
| 702 | TEST_ASSERT( mbedtls_ssl_session_save( &original, buf, len, &len ) |
| 703 | == 0 ); |
| 704 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 705 | /* Restore session from serialized data */ |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 706 | TEST_ASSERT( mbedtls_ssl_session_load( &restored, buf, len) == 0 ); |
| 707 | |
| 708 | /* |
| 709 | * Make sure both session structures are identical |
| 710 | */ |
| 711 | #if defined(MBEDTLS_HAVE_TIME) |
| 712 | TEST_ASSERT( original.start == restored.start ); |
| 713 | #endif |
Hanno Becker | e02758c | 2019-06-26 15:31:31 +0100 | [diff] [blame] | 714 | #if !defined(MBEDTLS_SSL_CONF_SINGLE_CIPHERSUITE) |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 715 | TEST_ASSERT( original.ciphersuite == restored.ciphersuite ); |
Hanno Becker | e02758c | 2019-06-26 15:31:31 +0100 | [diff] [blame] | 716 | #endif |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 717 | TEST_ASSERT( original.compression == restored.compression ); |
| 718 | TEST_ASSERT( original.id_len == restored.id_len ); |
| 719 | TEST_ASSERT( memcmp( original.id, |
| 720 | restored.id, sizeof( original.id ) ) == 0 ); |
| 721 | TEST_ASSERT( memcmp( original.master, |
| 722 | restored.master, sizeof( original.master ) ) == 0 ); |
| 723 | |
| 724 | #if defined(MBEDTLS_X509_CRT_PARSE_C) |
Hanno Becker | 2e6d347 | 2019-02-06 15:40:27 +0000 | [diff] [blame] | 725 | #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 726 | TEST_ASSERT( ( original.peer_cert == NULL ) == |
| 727 | ( restored.peer_cert == NULL ) ); |
| 728 | if( original.peer_cert != NULL ) |
| 729 | { |
| 730 | TEST_ASSERT( original.peer_cert->raw.len == |
| 731 | restored.peer_cert->raw.len ); |
| 732 | TEST_ASSERT( memcmp( original.peer_cert->raw.p, |
| 733 | restored.peer_cert->raw.p, |
| 734 | original.peer_cert->raw.len ) == 0 ); |
| 735 | } |
Hanno Becker | 5882dd0 | 2019-06-06 16:25:57 +0100 | [diff] [blame] | 736 | #elif defined(MBEDTLS_SSL_RENEGOTIATION) |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 737 | TEST_ASSERT( original.peer_cert_digest_type == |
| 738 | restored.peer_cert_digest_type ); |
| 739 | TEST_ASSERT( original.peer_cert_digest_len == |
| 740 | restored.peer_cert_digest_len ); |
| 741 | TEST_ASSERT( ( original.peer_cert_digest == NULL ) == |
| 742 | ( restored.peer_cert_digest == NULL ) ); |
| 743 | if( original.peer_cert_digest != NULL ) |
| 744 | { |
| 745 | TEST_ASSERT( memcmp( original.peer_cert_digest, |
| 746 | restored.peer_cert_digest, |
| 747 | original.peer_cert_digest_len ) == 0 ); |
| 748 | } |
Hanno Becker | 5882dd0 | 2019-06-06 16:25:57 +0100 | [diff] [blame] | 749 | #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE && MBEDTLS_SSL_RENEGOTIATION */ |
Hanno Becker | 4a2f8e5 | 2019-02-06 15:23:38 +0000 | [diff] [blame] | 750 | #endif /* MBEDTLS_X509_CRT_PARSE_C */ |
Manuel Pégourié-Gonnard | 2a62a05 | 2019-05-24 09:41:39 +0200 | [diff] [blame] | 751 | TEST_ASSERT( original.verify_result == restored.verify_result ); |
| 752 | |
| 753 | #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C) |
| 754 | TEST_ASSERT( original.ticket_len == restored.ticket_len ); |
| 755 | if( original.ticket_len != 0 ) |
| 756 | { |
| 757 | TEST_ASSERT( original.ticket != NULL ); |
| 758 | TEST_ASSERT( restored.ticket != NULL ); |
| 759 | TEST_ASSERT( memcmp( original.ticket, |
| 760 | restored.ticket, original.ticket_len ) == 0 ); |
| 761 | } |
| 762 | TEST_ASSERT( original.ticket_lifetime == restored.ticket_lifetime ); |
| 763 | #endif |
| 764 | |
| 765 | #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) |
| 766 | TEST_ASSERT( original.mfl_code == restored.mfl_code ); |
| 767 | #endif |
| 768 | |
| 769 | #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) |
| 770 | TEST_ASSERT( original.trunc_hmac == restored.trunc_hmac ); |
| 771 | #endif |
| 772 | |
| 773 | #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) |
| 774 | TEST_ASSERT( original.encrypt_then_mac == restored.encrypt_then_mac ); |
| 775 | #endif |
| 776 | |
| 777 | exit: |
| 778 | mbedtls_ssl_session_free( &original ); |
| 779 | mbedtls_ssl_session_free( &restored ); |
| 780 | mbedtls_free( buf ); |
| 781 | } |
| 782 | /* END_CASE */ |
| 783 | |
Manuel Pégourié-Gonnard | c4f5080 | 2019-06-03 10:53:47 +0200 | [diff] [blame] | 784 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 785 | void ssl_serialize_session_load_save( int ticket_len, char *crt_file ) |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 786 | { |
| 787 | mbedtls_ssl_session session; |
| 788 | unsigned char *buf1 = NULL, *buf2 = NULL; |
| 789 | size_t len0, len1, len2; |
| 790 | |
| 791 | /* |
| 792 | * Test that a load-save pair is the identity |
| 793 | */ |
| 794 | |
| 795 | mbedtls_ssl_session_init( &session ); |
| 796 | |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 797 | /* Prepare a dummy session to work on */ |
Manuel Pégourié-Gonnard | aab6204 | 2019-05-24 09:40:17 +0200 | [diff] [blame] | 798 | TEST_ASSERT( ssl_populate_session( &session, ticket_len, crt_file ) == 0 ); |
Manuel Pégourié-Gonnard | 16f6bb1 | 2019-05-23 10:06:14 +0200 | [diff] [blame] | 799 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 800 | /* Get desired buffer size for serializing */ |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 801 | TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &len0 ) |
| 802 | == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 803 | |
| 804 | /* Allocate first buffer */ |
| 805 | buf1 = mbedtls_calloc( 1, len0 ); |
| 806 | TEST_ASSERT( buf1 != NULL ); |
| 807 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 808 | /* Serialize to buffer and free live session */ |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 809 | TEST_ASSERT( mbedtls_ssl_session_save( &session, buf1, len0, &len1 ) |
| 810 | == 0 ); |
| 811 | TEST_ASSERT( len0 == len1 ); |
| 812 | mbedtls_ssl_session_free( &session ); |
| 813 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 814 | /* Restore session from serialized data */ |
Manuel Pégourié-Gonnard | d1a5451 | 2019-05-24 09:54:21 +0200 | [diff] [blame] | 815 | TEST_ASSERT( mbedtls_ssl_session_load( &session, buf1, len1 ) == 0 ); |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 816 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 817 | /* Allocate second buffer and serialize to it */ |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 818 | buf2 = mbedtls_calloc( 1, len0 ); |
Manuel Pégourié-Gonnard | 081b152 | 2019-05-24 09:52:10 +0200 | [diff] [blame] | 819 | TEST_ASSERT( buf2 != NULL ); |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 820 | TEST_ASSERT( mbedtls_ssl_session_save( &session, buf2, len0, &len2 ) |
| 821 | == 0 ); |
| 822 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 823 | /* Make sure both serialized versions are identical */ |
Manuel Pégourié-Gonnard | dfa5a7a | 2019-05-23 09:30:55 +0200 | [diff] [blame] | 824 | TEST_ASSERT( len1 == len2 ); |
| 825 | TEST_ASSERT( memcmp( buf1, buf2, len1 ) == 0 ); |
| 826 | |
| 827 | exit: |
| 828 | mbedtls_ssl_session_free( &session ); |
| 829 | mbedtls_free( buf1 ); |
| 830 | mbedtls_free( buf2 ); |
| 831 | } |
| 832 | /* END_CASE */ |
Manuel Pégourié-Gonnard | 98fccc3 | 2019-05-23 10:38:11 +0200 | [diff] [blame] | 833 | |
| 834 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 835 | void ssl_serialize_session_save_buf_size( int ticket_len, char *crt_file ) |
Manuel Pégourié-Gonnard | 98fccc3 | 2019-05-23 10:38:11 +0200 | [diff] [blame] | 836 | { |
| 837 | mbedtls_ssl_session session; |
| 838 | unsigned char *buf = NULL; |
| 839 | size_t good_len, bad_len, test_len; |
| 840 | |
| 841 | /* |
| 842 | * Test that session_save() fails cleanly on small buffers |
| 843 | */ |
| 844 | |
| 845 | mbedtls_ssl_session_init( &session ); |
| 846 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 847 | /* Prepare dummy session and get serialized size */ |
Manuel Pégourié-Gonnard | aab6204 | 2019-05-24 09:40:17 +0200 | [diff] [blame] | 848 | TEST_ASSERT( ssl_populate_session( &session, ticket_len, crt_file ) == 0 ); |
Manuel Pégourié-Gonnard | 98fccc3 | 2019-05-23 10:38:11 +0200 | [diff] [blame] | 849 | TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &good_len ) |
| 850 | == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 851 | |
| 852 | /* Try all possible bad lengths */ |
| 853 | for( bad_len = 1; bad_len < good_len; bad_len++ ) |
| 854 | { |
| 855 | /* Allocate exact size so that asan/valgrind can detect any overwrite */ |
| 856 | mbedtls_free( buf ); |
| 857 | TEST_ASSERT( ( buf = mbedtls_calloc( 1, bad_len ) ) != NULL ); |
| 858 | TEST_ASSERT( mbedtls_ssl_session_save( &session, buf, bad_len, |
| 859 | &test_len ) |
| 860 | == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 861 | TEST_ASSERT( test_len == good_len ); |
| 862 | } |
| 863 | |
| 864 | exit: |
| 865 | mbedtls_ssl_session_free( &session ); |
| 866 | mbedtls_free( buf ); |
| 867 | } |
| 868 | /* END_CASE */ |
Manuel Pégourié-Gonnard | 5709811 | 2019-05-23 12:28:45 +0200 | [diff] [blame] | 869 | |
| 870 | /* BEGIN_CASE */ |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 871 | void ssl_serialize_session_load_buf_size( int ticket_len, char *crt_file ) |
Manuel Pégourié-Gonnard | 5709811 | 2019-05-23 12:28:45 +0200 | [diff] [blame] | 872 | { |
| 873 | mbedtls_ssl_session session; |
| 874 | unsigned char *good_buf = NULL, *bad_buf = NULL; |
| 875 | size_t good_len, bad_len; |
| 876 | |
| 877 | /* |
| 878 | * Test that session_load() fails cleanly on small buffers |
| 879 | */ |
| 880 | |
| 881 | mbedtls_ssl_session_init( &session ); |
| 882 | |
Manuel Pégourié-Gonnard | 35ccdbb | 2019-06-03 09:55:16 +0200 | [diff] [blame] | 883 | /* Prepare serialized session data */ |
Manuel Pégourié-Gonnard | aab6204 | 2019-05-24 09:40:17 +0200 | [diff] [blame] | 884 | TEST_ASSERT( ssl_populate_session( &session, ticket_len, crt_file ) == 0 ); |
Manuel Pégourié-Gonnard | 5709811 | 2019-05-23 12:28:45 +0200 | [diff] [blame] | 885 | TEST_ASSERT( mbedtls_ssl_session_save( &session, NULL, 0, &good_len ) |
| 886 | == MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); |
| 887 | TEST_ASSERT( ( good_buf = mbedtls_calloc( 1, good_len ) ) != NULL ); |
| 888 | TEST_ASSERT( mbedtls_ssl_session_save( &session, good_buf, good_len, |
| 889 | &good_len ) == 0 ); |
| 890 | mbedtls_ssl_session_free( &session ); |
| 891 | |
| 892 | /* Try all possible bad lengths */ |
| 893 | for( bad_len = 0; bad_len < good_len; bad_len++ ) |
| 894 | { |
| 895 | /* Allocate exact size so that asan/valgrind can detect any overread */ |
| 896 | mbedtls_free( bad_buf ); |
| 897 | bad_buf = mbedtls_calloc( 1, bad_len ? bad_len : 1 ); |
| 898 | TEST_ASSERT( bad_buf != NULL ); |
| 899 | memcpy( bad_buf, good_buf, bad_len ); |
| 900 | |
| 901 | TEST_ASSERT( mbedtls_ssl_session_load( &session, bad_buf, bad_len ) |
| 902 | == MBEDTLS_ERR_SSL_BAD_INPUT_DATA ); |
| 903 | } |
| 904 | |
| 905 | exit: |
| 906 | mbedtls_ssl_session_free( &session ); |
| 907 | mbedtls_free( good_buf ); |
| 908 | mbedtls_free( bad_buf ); |
| 909 | } |
| 910 | /* END_CASE */ |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 911 | |
Hanno Becker | 08ec129 | 2019-05-29 12:44:28 +0100 | [diff] [blame] | 912 | /* BEGIN_CASE */ |
| 913 | void ssl_session_serialize_version_check( int corrupt_major, |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 914 | int corrupt_minor, |
| 915 | int corrupt_patch, |
| 916 | int corrupt_config ) |
| 917 | { |
Hanno Becker | 08ec129 | 2019-05-29 12:44:28 +0100 | [diff] [blame] | 918 | unsigned char serialized_session[ 2048 ]; |
| 919 | size_t serialized_session_len; |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 920 | unsigned cur_byte; |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 921 | mbedtls_ssl_session session; |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 922 | uint8_t should_corrupt_byte[] = { corrupt_major == 1, |
| 923 | corrupt_minor == 1, |
| 924 | corrupt_patch == 1, |
| 925 | corrupt_config == 1, |
| 926 | corrupt_config == 1 }; |
| 927 | |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 928 | mbedtls_ssl_session_init( &session ); |
| 929 | |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 930 | /* Infer length of serialized session. */ |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 931 | TEST_ASSERT( mbedtls_ssl_session_save( &session, |
Hanno Becker | 08ec129 | 2019-05-29 12:44:28 +0100 | [diff] [blame] | 932 | serialized_session, |
| 933 | sizeof( serialized_session ), |
| 934 | &serialized_session_len ) == 0 ); |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 935 | |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 936 | mbedtls_ssl_session_free( &session ); |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 937 | |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 938 | /* Without any modification, we should be able to successfully |
Hanno Becker | 08ec129 | 2019-05-29 12:44:28 +0100 | [diff] [blame] | 939 | * de-serialize the session - double-check that. */ |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 940 | TEST_ASSERT( mbedtls_ssl_session_load( &session, |
Hanno Becker | 08ec129 | 2019-05-29 12:44:28 +0100 | [diff] [blame] | 941 | serialized_session, |
| 942 | serialized_session_len ) == 0 ); |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 943 | mbedtls_ssl_session_free( &session ); |
| 944 | |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 945 | /* Go through the bytes in the serialized session header and |
| 946 | * corrupt them bit-by-bit. */ |
| 947 | for( cur_byte = 0; cur_byte < sizeof( should_corrupt_byte ); cur_byte++ ) |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 948 | { |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 949 | int cur_bit; |
| 950 | unsigned char * const byte = &serialized_session[ cur_byte ]; |
| 951 | |
| 952 | if( should_corrupt_byte[ cur_byte ] == 0 ) |
| 953 | continue; |
| 954 | |
| 955 | for( cur_bit = 0; cur_bit < CHAR_BIT; cur_bit++ ) |
| 956 | { |
| 957 | unsigned char const corrupted_bit = 0x1u << cur_bit; |
| 958 | /* Modify a single bit in the serialized session. */ |
| 959 | *byte ^= corrupted_bit; |
| 960 | |
| 961 | /* Attempt to deserialize */ |
| 962 | TEST_ASSERT( mbedtls_ssl_session_load( &session, |
| 963 | serialized_session, |
| 964 | serialized_session_len ) == |
Hanno Becker | 5dbcc9f | 2019-06-03 12:58:39 +0100 | [diff] [blame] | 965 | MBEDTLS_ERR_SSL_VERSION_MISMATCH ); |
Hanno Becker | f78af37 | 2019-05-29 12:45:21 +0100 | [diff] [blame] | 966 | |
| 967 | /* Undo the change */ |
| 968 | *byte ^= corrupted_bit; |
| 969 | } |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 970 | } |
| 971 | |
Hanno Becker | f99ec26 | 2019-05-21 16:39:30 +0100 | [diff] [blame] | 972 | } |
| 973 | /* END_CASE */ |