| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/t1_enc.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
| 3 | * Copyright 2005 Nokia. All rights reserved. | - | ||||||||||||
| 4 | * | - | ||||||||||||
| 5 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||
| 6 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||
| 7 | * in the file LICENSE in the source distribution or at | - | ||||||||||||
| 8 | * https://www.openssl.org/source/license.html | - | ||||||||||||
| 9 | */ | - | ||||||||||||
| 10 | - | |||||||||||||
| 11 | #include <stdio.h> | - | ||||||||||||
| 12 | #include "ssl_locl.h" | - | ||||||||||||
| 13 | #include <openssl/comp.h> | - | ||||||||||||
| 14 | #include <openssl/evp.h> | - | ||||||||||||
| 15 | #include <openssl/kdf.h> | - | ||||||||||||
| 16 | #include <openssl/rand.h> | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | /* seed1 through seed5 are concatenated */ | - | ||||||||||||
| 19 | static int tls1_PRF(SSL *s, | - | ||||||||||||
| 20 | const void *seed1, size_t seed1_len, | - | ||||||||||||
| 21 | const void *seed2, size_t seed2_len, | - | ||||||||||||
| 22 | const void *seed3, size_t seed3_len, | - | ||||||||||||
| 23 | const void *seed4, size_t seed4_len, | - | ||||||||||||
| 24 | const void *seed5, size_t seed5_len, | - | ||||||||||||
| 25 | const unsigned char *sec, size_t slen, | - | ||||||||||||
| 26 | unsigned char *out, size_t olen, int fatal) | - | ||||||||||||
| 27 | { | - | ||||||||||||
| 28 | const EVP_MD *md = ssl_prf_md(s); | - | ||||||||||||
| 29 | EVP_PKEY_CTX *pctx = NULL; | - | ||||||||||||
| 30 | int ret = 0; | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | if (md == NULL) {
| 0-9903 | ||||||||||||
| 33 | /* Should never happen */ | - | ||||||||||||
| 34 | if (fatal)
| 0 | ||||||||||||
| 35 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_PRF, never executed: ossl_statem_fatal((s), (80), (284), ((4|64)), __FILE__ , 36 ) ; | 0 | ||||||||||||
| 36 | ERR_R_INTERNAL_ERROR); never executed: ossl_statem_fatal((s), (80), (284), ((4|64)), __FILE__ , 36 ) ; | 0 | ||||||||||||
| 37 | else | - | ||||||||||||
| 38 | SSLerr(SSL_F_TLS1_PRF, ERR_R_INTERNAL_ERROR); never executed: ERR_put_error(20,(284),((4|64)),__FILE__,38); | 0 | ||||||||||||
| 39 | return 0; never executed: return 0; | 0 | ||||||||||||
| 40 | } | - | ||||||||||||
| 41 | pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL); | - | ||||||||||||
| 42 | if (pctx == NULL || EVP_PKEY_derive_init(pctx) <= 0
| 0-9903 | ||||||||||||
| 43 | || EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) <= 0
| 0-9903 | ||||||||||||
| 44 | || EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, (int)slen) <= 0
| 0-9903 | ||||||||||||
| 45 | || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed1, (int)seed1_len) <= 0
| 0-9903 | ||||||||||||
| 46 | || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed2, (int)seed2_len) <= 0
| 0-9903 | ||||||||||||
| 47 | || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed3, (int)seed3_len) <= 0
| 0-9903 | ||||||||||||
| 48 | || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed4, (int)seed4_len) <= 0
| 0-9903 | ||||||||||||
| 49 | || EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed5, (int)seed5_len) <= 0
| 0-9903 | ||||||||||||
| 50 | || EVP_PKEY_derive(pctx, out, &olen) <= 0) {
| 0-9903 | ||||||||||||
| 51 | if (fatal)
| 0 | ||||||||||||
| 52 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_PRF, never executed: ossl_statem_fatal((s), (80), (284), ((4|64)), __FILE__ , 53 ) ; | 0 | ||||||||||||
| 53 | ERR_R_INTERNAL_ERROR); never executed: ossl_statem_fatal((s), (80), (284), ((4|64)), __FILE__ , 53 ) ; | 0 | ||||||||||||
| 54 | else | - | ||||||||||||
| 55 | SSLerr(SSL_F_TLS1_PRF, ERR_R_INTERNAL_ERROR); never executed: ERR_put_error(20,(284),((4|64)),__FILE__,55); | 0 | ||||||||||||
| 56 | goto err; never executed: goto err; | 0 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | ret = 1; | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | err: code before this statement executed 9903 times by 1 test: err:Executed by:
| 9903 | ||||||||||||
| 62 | EVP_PKEY_CTX_free(pctx); | - | ||||||||||||
| 63 | return ret; executed 9903 times by 1 test: return ret;Executed by:
| 9903 | ||||||||||||
| 64 | } | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | static int tls1_generate_key_block(SSL *s, unsigned char *km, size_t num) | - | ||||||||||||
| 67 | { | - | ||||||||||||
| 68 | int ret; | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | /* Calls SSLfatal() as required */ | - | ||||||||||||
| 71 | ret = tls1_PRF(s, | - | ||||||||||||
| 72 | TLS_MD_KEY_EXPANSION_CONST, | - | ||||||||||||
| 73 | TLS_MD_KEY_EXPANSION_CONST_SIZE, s->s3->server_random, | - | ||||||||||||
| 74 | SSL3_RANDOM_SIZE, s->s3->client_random, SSL3_RANDOM_SIZE, | - | ||||||||||||
| 75 | NULL, 0, NULL, 0, s->session->master_key, | - | ||||||||||||
| 76 | s->session->master_key_length, km, num, 1); | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | return ret; executed 2685 times by 1 test: return ret;Executed by:
| 2685 | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | int tls1_change_cipher_state(SSL *s, int which) | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | unsigned char *p, *mac_secret; | - | ||||||||||||
| 84 | unsigned char tmp1[EVP_MAX_KEY_LENGTH]; | - | ||||||||||||
| 85 | unsigned char tmp2[EVP_MAX_KEY_LENGTH]; | - | ||||||||||||
| 86 | unsigned char iv1[EVP_MAX_IV_LENGTH * 2]; | - | ||||||||||||
| 87 | unsigned char iv2[EVP_MAX_IV_LENGTH * 2]; | - | ||||||||||||
| 88 | unsigned char *ms, *key, *iv; | - | ||||||||||||
| 89 | EVP_CIPHER_CTX *dd; | - | ||||||||||||
| 90 | const EVP_CIPHER *c; | - | ||||||||||||
| 91 | #ifndef OPENSSL_NO_COMP | - | ||||||||||||
| 92 | const SSL_COMP *comp; | - | ||||||||||||
| 93 | #endif | - | ||||||||||||
| 94 | const EVP_MD *m; | - | ||||||||||||
| 95 | int mac_type; | - | ||||||||||||
| 96 | size_t *mac_secret_size; | - | ||||||||||||
| 97 | EVP_MD_CTX *mac_ctx; | - | ||||||||||||
| 98 | EVP_PKEY *mac_key; | - | ||||||||||||
| 99 | size_t n, i, j, k, cl; | - | ||||||||||||
| 100 | int reuse_dd = 0; | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | c = s->s3->tmp.new_sym_enc; | - | ||||||||||||
| 103 | m = s->s3->tmp.new_hash; | - | ||||||||||||
| 104 | mac_type = s->s3->tmp.new_mac_pkey_type; | - | ||||||||||||
| 105 | #ifndef OPENSSL_NO_COMP | - | ||||||||||||
| 106 | comp = s->s3->tmp.new_compression; | - | ||||||||||||
| 107 | #endif | - | ||||||||||||
| 108 | - | |||||||||||||
| 109 | if (which & SSL3_CC_READ) {
| 2469-2522 | ||||||||||||
| 110 | if (s->ext.use_etm)
| 1085-1384 | ||||||||||||
| 111 | s->s3->flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC_READ; executed 1085 times by 1 test: s->s3->flags |= 0x0100;Executed by:
| 1085 | ||||||||||||
| 112 | else | - | ||||||||||||
| 113 | s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC_READ; executed 1384 times by 1 test: s->s3->flags &= ~0x0100;Executed by:
| 1384 | ||||||||||||
| 114 | - | |||||||||||||
| 115 | if (s->s3->tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
| 0-2469 | ||||||||||||
| 116 | s->mac_flags |= SSL_MAC_FLAG_READ_MAC_STREAM; never executed: s->mac_flags |= 1; | 0 | ||||||||||||
| 117 | else | - | ||||||||||||
| 118 | s->mac_flags &= ~SSL_MAC_FLAG_READ_MAC_STREAM; executed 2469 times by 1 test: s->mac_flags &= ~1;Executed by:
| 2469 | ||||||||||||
| 119 | - | |||||||||||||
| 120 | if (s->enc_read_ctx != NULL) {
| 44-2425 | ||||||||||||
| 121 | reuse_dd = 1; | - | ||||||||||||
| 122 | } else if ((s->enc_read_ctx = EVP_CIPHER_CTX_new()) == NULL) { executed 44 times by 1 test: end of blockExecuted by:
| 0-2425 | ||||||||||||
| 123 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 124 | ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 125 | goto err; never executed: goto err; | 0 | ||||||||||||
| 126 | } else { | - | ||||||||||||
| 127 | /* | - | ||||||||||||
| 128 | * make sure it's initialised in case we exit later with an error | - | ||||||||||||
| 129 | */ | - | ||||||||||||
| 130 | EVP_CIPHER_CTX_reset(s->enc_read_ctx); | - | ||||||||||||
| 131 | } executed 2425 times by 1 test: end of blockExecuted by:
| 2425 | ||||||||||||
| 132 | dd = s->enc_read_ctx; | - | ||||||||||||
| 133 | mac_ctx = ssl_replace_hash(&s->read_hash, NULL); | - | ||||||||||||
| 134 | if (mac_ctx == NULL)
| 0-2469 | ||||||||||||
| 135 | goto err; never executed: goto err; | 0 | ||||||||||||
| 136 | #ifndef OPENSSL_NO_COMP | - | ||||||||||||
| 137 | COMP_CTX_free(s->expand); | - | ||||||||||||
| 138 | s->expand = NULL; | - | ||||||||||||
| 139 | if (comp != NULL) {
| 0-2469 | ||||||||||||
| 140 | s->expand = COMP_CTX_new(comp->method); | - | ||||||||||||
| 141 | if (s->expand == NULL) {
| 0 | ||||||||||||
| 142 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, | - | ||||||||||||
| 143 | SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 144 | SSL_R_COMPRESSION_LIBRARY_ERROR); | - | ||||||||||||
| 145 | goto err; never executed: goto err; | 0 | ||||||||||||
| 146 | } | - | ||||||||||||
| 147 | } never executed: end of block | 0 | ||||||||||||
| 148 | #endif | - | ||||||||||||
| 149 | /* | - | ||||||||||||
| 150 | * this is done by dtls1_reset_seq_numbers for DTLS | - | ||||||||||||
| 151 | */ | - | ||||||||||||
| 152 | if (!SSL_IS_DTLS(s))
| 355-2114 | ||||||||||||
| 153 | RECORD_LAYER_reset_read_sequence(&s->rlayer); executed 2114 times by 1 test: RECORD_LAYER_reset_read_sequence(&s->rlayer);Executed by:
| 2114 | ||||||||||||
| 154 | mac_secret = &(s->s3->read_mac_secret[0]); | - | ||||||||||||
| 155 | mac_secret_size = &(s->s3->read_mac_secret_size); | - | ||||||||||||
| 156 | } else { executed 2469 times by 1 test: end of blockExecuted by:
| 2469 | ||||||||||||
| 157 | s->statem.enc_write_state = ENC_WRITE_STATE_INVALID; | - | ||||||||||||
| 158 | if (s->ext.use_etm)
| 1137-1385 | ||||||||||||
| 159 | s->s3->flags |= TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE; executed 1137 times by 1 test: s->s3->flags |= 0x0400;Executed by:
| 1137 | ||||||||||||
| 160 | else | - | ||||||||||||
| 161 | s->s3->flags &= ~TLS1_FLAGS_ENCRYPT_THEN_MAC_WRITE; executed 1385 times by 1 test: s->s3->flags &= ~0x0400;Executed by:
| 1385 | ||||||||||||
| 162 | - | |||||||||||||
| 163 | if (s->s3->tmp.new_cipher->algorithm2 & TLS1_STREAM_MAC)
| 0-2522 | ||||||||||||
| 164 | s->mac_flags |= SSL_MAC_FLAG_WRITE_MAC_STREAM; never executed: s->mac_flags |= 2; | 0 | ||||||||||||
| 165 | else | - | ||||||||||||
| 166 | s->mac_flags &= ~SSL_MAC_FLAG_WRITE_MAC_STREAM; executed 2522 times by 1 test: s->mac_flags &= ~2;Executed by:
| 2522 | ||||||||||||
| 167 | if (s->enc_write_ctx != NULL && !SSL_IS_DTLS(s)) {
| 18-2478 | ||||||||||||
| 168 | reuse_dd = 1; | - | ||||||||||||
| 169 | } else if ((s->enc_write_ctx = EVP_CIPHER_CTX_new()) == NULL) { executed 26 times by 1 test: end of blockExecuted by:
| 0-2496 | ||||||||||||
| 170 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 171 | ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 172 | goto err; never executed: goto err; | 0 | ||||||||||||
| 173 | } | - | ||||||||||||
| 174 | dd = s->enc_write_ctx; | - | ||||||||||||
| 175 | if (SSL_IS_DTLS(s)) {
| 359-2163 | ||||||||||||
| 176 | mac_ctx = EVP_MD_CTX_new(); | - | ||||||||||||
| 177 | if (mac_ctx == NULL) {
| 0-359 | ||||||||||||
| 178 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, | - | ||||||||||||
| 179 | SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 180 | ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 181 | goto err; never executed: goto err; | 0 | ||||||||||||
| 182 | } | - | ||||||||||||
| 183 | s->write_hash = mac_ctx; | - | ||||||||||||
| 184 | } else { executed 359 times by 1 test: end of blockExecuted by:
| 359 | ||||||||||||
| 185 | mac_ctx = ssl_replace_hash(&s->write_hash, NULL); | - | ||||||||||||
| 186 | if (mac_ctx == NULL) {
| 0-2163 | ||||||||||||
| 187 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, | - | ||||||||||||
| 188 | SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 189 | ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 190 | goto err; never executed: goto err; | 0 | ||||||||||||
| 191 | } | - | ||||||||||||
| 192 | } executed 2163 times by 1 test: end of blockExecuted by:
| 2163 | ||||||||||||
| 193 | #ifndef OPENSSL_NO_COMP | - | ||||||||||||
| 194 | COMP_CTX_free(s->compress); | - | ||||||||||||
| 195 | s->compress = NULL; | - | ||||||||||||
| 196 | if (comp != NULL) {
| 0-2522 | ||||||||||||
| 197 | s->compress = COMP_CTX_new(comp->method); | - | ||||||||||||
| 198 | if (s->compress == NULL) {
| 0 | ||||||||||||
| 199 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, | - | ||||||||||||
| 200 | SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 201 | SSL_R_COMPRESSION_LIBRARY_ERROR); | - | ||||||||||||
| 202 | goto err; never executed: goto err; | 0 | ||||||||||||
| 203 | } | - | ||||||||||||
| 204 | } never executed: end of block | 0 | ||||||||||||
| 205 | #endif | - | ||||||||||||
| 206 | /* | - | ||||||||||||
| 207 | * this is done by dtls1_reset_seq_numbers for DTLS | - | ||||||||||||
| 208 | */ | - | ||||||||||||
| 209 | if (!SSL_IS_DTLS(s))
| 359-2163 | ||||||||||||
| 210 | RECORD_LAYER_reset_write_sequence(&s->rlayer); executed 2163 times by 1 test: RECORD_LAYER_reset_write_sequence(&s->rlayer);Executed by:
| 2163 | ||||||||||||
| 211 | mac_secret = &(s->s3->write_mac_secret[0]); | - | ||||||||||||
| 212 | mac_secret_size = &(s->s3->write_mac_secret_size); | - | ||||||||||||
| 213 | } executed 2522 times by 1 test: end of blockExecuted by:
| 2522 | ||||||||||||
| 214 | - | |||||||||||||
| 215 | if (reuse_dd)
| 70-4921 | ||||||||||||
| 216 | EVP_CIPHER_CTX_reset(dd); executed 70 times by 1 test: EVP_CIPHER_CTX_reset(dd);Executed by:
| 70 | ||||||||||||
| 217 | - | |||||||||||||
| 218 | p = s->s3->tmp.key_block; | - | ||||||||||||
| 219 | i = *mac_secret_size = s->s3->tmp.new_mac_secret_size; | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | /* TODO(size_t): convert me */ | - | ||||||||||||
| 222 | cl = EVP_CIPHER_key_length(c); | - | ||||||||||||
| 223 | j = cl; | - | ||||||||||||
| 224 | /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */ | - | ||||||||||||
| 225 | /* If GCM/CCM mode only part of IV comes from PRF */ | - | ||||||||||||
| 226 | if (EVP_CIPHER_mode(c) == EVP_CIPH_GCM_MODE)
| 2070-2921 | ||||||||||||
| 227 | k = EVP_GCM_TLS_FIXED_IV_LEN; executed 2070 times by 1 test: k = 4;Executed by:
| 2070 | ||||||||||||
| 228 | else if (EVP_CIPHER_mode(c) == EVP_CIPH_CCM_MODE)
| 126-2795 | ||||||||||||
| 229 | k = EVP_CCM_TLS_FIXED_IV_LEN; executed 126 times by 1 test: k = 4;Executed by:
| 126 | ||||||||||||
| 230 | else | - | ||||||||||||
| 231 | k = EVP_CIPHER_iv_length(c); executed 2795 times by 1 test: k = EVP_CIPHER_iv_length(c);Executed by:
| 2795 | ||||||||||||
| 232 | if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||
| 1456-3535 | ||||||||||||
| 233 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)) {
| 1217-2318 | ||||||||||||
| 234 | ms = &(p[0]); | - | ||||||||||||
| 235 | n = i + i; | - | ||||||||||||
| 236 | key = &(p[n]); | - | ||||||||||||
| 237 | n += j + j; | - | ||||||||||||
| 238 | iv = &(p[n]); | - | ||||||||||||
| 239 | n += k + k; | - | ||||||||||||
| 240 | } else { executed 2673 times by 1 test: end of blockExecuted by:
| 2673 | ||||||||||||
| 241 | n = i; | - | ||||||||||||
| 242 | ms = &(p[n]); | - | ||||||||||||
| 243 | n += i + j; | - | ||||||||||||
| 244 | key = &(p[n]); | - | ||||||||||||
| 245 | n += j + k; | - | ||||||||||||
| 246 | iv = &(p[n]); | - | ||||||||||||
| 247 | n += k; | - | ||||||||||||
| 248 | } executed 2318 times by 1 test: end of blockExecuted by:
| 2318 | ||||||||||||
| 249 | - | |||||||||||||
| 250 | if (n > s->s3->tmp.key_block_length) {
| 0-4991 | ||||||||||||
| 251 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 252 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 253 | goto err; never executed: goto err; | 0 | ||||||||||||
| 254 | } | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | memcpy(mac_secret, ms, i); | - | ||||||||||||
| 257 | - | |||||||||||||
| 258 | if (!(EVP_CIPHER_flags(c) & EVP_CIPH_FLAG_AEAD_CIPHER)) {
| 2245-2746 | ||||||||||||
| 259 | /* TODO(size_t): Convert this function */ | - | ||||||||||||
| 260 | mac_key = EVP_PKEY_new_mac_key(mac_type, NULL, mac_secret, | - | ||||||||||||
| 261 | (int)*mac_secret_size); | - | ||||||||||||
| 262 | if (mac_key == NULL
| 0-2746 | ||||||||||||
| 263 | || EVP_DigestSignInit(mac_ctx, NULL, m, NULL, mac_key) <= 0) {
| 0-2746 | ||||||||||||
| 264 | EVP_PKEY_free(mac_key); | - | ||||||||||||
| 265 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 266 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 267 | goto err; never executed: goto err; | 0 | ||||||||||||
| 268 | } | - | ||||||||||||
| 269 | EVP_PKEY_free(mac_key); | - | ||||||||||||
| 270 | } executed 2746 times by 1 test: end of blockExecuted by:
| 2746 | ||||||||||||
| 271 | #ifdef SSL_DEBUG | - | ||||||||||||
| 272 | printf("which = %04X\nmac key=", which); | - | ||||||||||||
| 273 | { | - | ||||||||||||
| 274 | size_t z; | - | ||||||||||||
| 275 | for (z = 0; z < i; z++) | - | ||||||||||||
| 276 | printf("%02X%c", ms[z], ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 277 | } | - | ||||||||||||
| 278 | #endif | - | ||||||||||||
| 279 | - | |||||||||||||
| 280 | if (EVP_CIPHER_mode(c) == EVP_CIPH_GCM_MODE) {
| 2070-2921 | ||||||||||||
| 281 | if (!EVP_CipherInit_ex(dd, c, NULL, key, NULL, (which & SSL3_CC_WRITE))
| 0-2070 | ||||||||||||
| 282 | || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_GCM_SET_IV_FIXED, (int)k,
| 0-2070 | ||||||||||||
| 283 | iv)) {
| 0-2070 | ||||||||||||
| 284 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 285 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 286 | goto err; never executed: goto err; | 0 | ||||||||||||
| 287 | } | - | ||||||||||||
| 288 | } else if (EVP_CIPHER_mode(c) == EVP_CIPH_CCM_MODE) { executed 2070 times by 1 test: end of blockExecuted by:
| 126-2795 | ||||||||||||
| 289 | int taglen; | - | ||||||||||||
| 290 | if (s->s3->tmp.
| 59-67 | ||||||||||||
| 291 | new_cipher->algorithm_enc & (SSL_AES128CCM8 | SSL_AES256CCM8))
| 59-67 | ||||||||||||
| 292 | taglen = EVP_CCM8_TLS_TAG_LEN; executed 59 times by 1 test: taglen = 8;Executed by:
| 59 | ||||||||||||
| 293 | else | - | ||||||||||||
| 294 | taglen = EVP_CCM_TLS_TAG_LEN; executed 67 times by 1 test: taglen = 16;Executed by:
| 67 | ||||||||||||
| 295 | if (!EVP_CipherInit_ex(dd, c, NULL, NULL, NULL, (which & SSL3_CC_WRITE))
| 0-126 | ||||||||||||
| 296 | || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_AEAD_SET_IVLEN, 12, NULL)
| 0-126 | ||||||||||||
| 297 | || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_AEAD_SET_TAG, taglen, NULL)
| 0-126 | ||||||||||||
| 298 | || !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_CCM_SET_IV_FIXED, (int)k, iv)
| 0-126 | ||||||||||||
| 299 | || !EVP_CipherInit_ex(dd, NULL, NULL, key, NULL, -1)) {
| 0-126 | ||||||||||||
| 300 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 301 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 302 | goto err; never executed: goto err; | 0 | ||||||||||||
| 303 | } | - | ||||||||||||
| 304 | } else { executed 126 times by 1 test: end of blockExecuted by:
| 126 | ||||||||||||
| 305 | if (!EVP_CipherInit_ex(dd, c, NULL, key, iv, (which & SSL3_CC_WRITE))) {
| 0-2795 | ||||||||||||
| 306 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 307 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 308 | goto err; never executed: goto err; | 0 | ||||||||||||
| 309 | } | - | ||||||||||||
| 310 | } executed 2795 times by 1 test: end of blockExecuted by:
| 2795 | ||||||||||||
| 311 | /* Needed for "composite" AEADs, such as RC4-HMAC-MD5 */ | - | ||||||||||||
| 312 | if ((EVP_CIPHER_flags(c) & EVP_CIPH_FLAG_AEAD_CIPHER) && *mac_secret_size
| 0-2746 | ||||||||||||
| 313 | && !EVP_CIPHER_CTX_ctrl(dd, EVP_CTRL_AEAD_SET_MAC_KEY,
| 0 | ||||||||||||
| 314 | (int)*mac_secret_size, mac_secret)) {
| 0 | ||||||||||||
| 315 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_CHANGE_CIPHER_STATE, | - | ||||||||||||
| 316 | ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 317 | goto err; never executed: goto err; | 0 | ||||||||||||
| 318 | } | - | ||||||||||||
| 319 | s->statem.enc_write_state = ENC_WRITE_STATE_VALID; | - | ||||||||||||
| 320 | - | |||||||||||||
| 321 | #ifdef SSL_DEBUG | - | ||||||||||||
| 322 | printf("which = %04X\nkey=", which); | - | ||||||||||||
| 323 | { | - | ||||||||||||
| 324 | int z; | - | ||||||||||||
| 325 | for (z = 0; z < EVP_CIPHER_key_length(c); z++) | - | ||||||||||||
| 326 | printf("%02X%c", key[z], ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 327 | } | - | ||||||||||||
| 328 | printf("\niv="); | - | ||||||||||||
| 329 | { | - | ||||||||||||
| 330 | size_t z; | - | ||||||||||||
| 331 | for (z = 0; z < k; z++) | - | ||||||||||||
| 332 | printf("%02X%c", iv[z], ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 333 | } | - | ||||||||||||
| 334 | printf("\n"); | - | ||||||||||||
| 335 | #endif | - | ||||||||||||
| 336 | - | |||||||||||||
| 337 | OPENSSL_cleanse(tmp1, sizeof(tmp1)); | - | ||||||||||||
| 338 | OPENSSL_cleanse(tmp2, sizeof(tmp1)); | - | ||||||||||||
| 339 | OPENSSL_cleanse(iv1, sizeof(iv1)); | - | ||||||||||||
| 340 | OPENSSL_cleanse(iv2, sizeof(iv2)); | - | ||||||||||||
| 341 | return 1; executed 4991 times by 1 test: return 1;Executed by:
| 4991 | ||||||||||||
| 342 | err: | - | ||||||||||||
| 343 | OPENSSL_cleanse(tmp1, sizeof(tmp1)); | - | ||||||||||||
| 344 | OPENSSL_cleanse(tmp2, sizeof(tmp1)); | - | ||||||||||||
| 345 | OPENSSL_cleanse(iv1, sizeof(iv1)); | - | ||||||||||||
| 346 | OPENSSL_cleanse(iv2, sizeof(iv2)); | - | ||||||||||||
| 347 | return 0; never executed: return 0; | 0 | ||||||||||||
| 348 | } | - | ||||||||||||
| 349 | - | |||||||||||||
| 350 | int tls1_setup_key_block(SSL *s) | - | ||||||||||||
| 351 | { | - | ||||||||||||
| 352 | unsigned char *p; | - | ||||||||||||
| 353 | const EVP_CIPHER *c; | - | ||||||||||||
| 354 | const EVP_MD *hash; | - | ||||||||||||
| 355 | SSL_COMP *comp; | - | ||||||||||||
| 356 | int mac_type = NID_undef; | - | ||||||||||||
| 357 | size_t num, mac_secret_size = 0; | - | ||||||||||||
| 358 | int ret = 0; | - | ||||||||||||
| 359 | - | |||||||||||||
| 360 | if (s->s3->tmp.key_block_length != 0)
| 1047-2685 | ||||||||||||
| 361 | return 1; executed 1047 times by 1 test: return 1;Executed by:
| 1047 | ||||||||||||
| 362 | - | |||||||||||||
| 363 | if (!ssl_cipher_get_evp(s->session, &c, &hash, &mac_type, &mac_secret_size,
| 0-2685 | ||||||||||||
| 364 | &comp, s->ext.use_etm)) {
| 0-2685 | ||||||||||||
| 365 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_SETUP_KEY_BLOCK, | - | ||||||||||||
| 366 | SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | - | ||||||||||||
| 367 | return 0; never executed: return 0; | 0 | ||||||||||||
| 368 | } | - | ||||||||||||
| 369 | - | |||||||||||||
| 370 | s->s3->tmp.new_sym_enc = c; | - | ||||||||||||
| 371 | s->s3->tmp.new_hash = hash; | - | ||||||||||||
| 372 | s->s3->tmp.new_mac_pkey_type = mac_type; | - | ||||||||||||
| 373 | s->s3->tmp.new_mac_secret_size = mac_secret_size; | - | ||||||||||||
| 374 | num = EVP_CIPHER_key_length(c) + mac_secret_size + EVP_CIPHER_iv_length(c); | - | ||||||||||||
| 375 | num *= 2; | - | ||||||||||||
| 376 | - | |||||||||||||
| 377 | ssl3_cleanup_key_block(s); | - | ||||||||||||
| 378 | - | |||||||||||||
| 379 | if ((p = OPENSSL_malloc(num)) == NULL) {
| 0-2685 | ||||||||||||
| 380 | SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_SETUP_KEY_BLOCK, | - | ||||||||||||
| 381 | ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 382 | goto err; never executed: goto err; | 0 | ||||||||||||
| 383 | } | - | ||||||||||||
| 384 | - | |||||||||||||
| 385 | s->s3->tmp.key_block_length = num; | - | ||||||||||||
| 386 | s->s3->tmp.key_block = p; | - | ||||||||||||
| 387 | - | |||||||||||||
| 388 | #ifdef SSL_DEBUG | - | ||||||||||||
| 389 | printf("client random\n"); | - | ||||||||||||
| 390 | { | - | ||||||||||||
| 391 | int z; | - | ||||||||||||
| 392 | for (z = 0; z < SSL3_RANDOM_SIZE; z++) | - | ||||||||||||
| 393 | printf("%02X%c", s->s3->client_random[z], | - | ||||||||||||
| 394 | ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 395 | } | - | ||||||||||||
| 396 | printf("server random\n"); | - | ||||||||||||
| 397 | { | - | ||||||||||||
| 398 | int z; | - | ||||||||||||
| 399 | for (z = 0; z < SSL3_RANDOM_SIZE; z++) | - | ||||||||||||
| 400 | printf("%02X%c", s->s3->server_random[z], | - | ||||||||||||
| 401 | ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 402 | } | - | ||||||||||||
| 403 | printf("master key\n"); | - | ||||||||||||
| 404 | { | - | ||||||||||||
| 405 | size_t z; | - | ||||||||||||
| 406 | for (z = 0; z < s->session->master_key_length; z++) | - | ||||||||||||
| 407 | printf("%02X%c", s->session->master_key[z], | - | ||||||||||||
| 408 | ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 409 | } | - | ||||||||||||
| 410 | #endif | - | ||||||||||||
| 411 | if (!tls1_generate_key_block(s, p, num)) {
| 0-2685 | ||||||||||||
| 412 | /* SSLfatal() already called */ | - | ||||||||||||
| 413 | goto err; never executed: goto err; | 0 | ||||||||||||
| 414 | } | - | ||||||||||||
| 415 | #ifdef SSL_DEBUG | - | ||||||||||||
| 416 | printf("\nkey block\n"); | - | ||||||||||||
| 417 | { | - | ||||||||||||
| 418 | size_t z; | - | ||||||||||||
| 419 | for (z = 0; z < num; z++) | - | ||||||||||||
| 420 | printf("%02X%c", p[z], ((z + 1) % 16) ? ' ' : '\n'); | - | ||||||||||||
| 421 | } | - | ||||||||||||
| 422 | #endif | - | ||||||||||||
| 423 | - | |||||||||||||
| 424 | if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
| 0-2685 | ||||||||||||
| 425 | && s->method->version <= TLS1_VERSION) {
| 477-2208 | ||||||||||||
| 426 | /* | - | ||||||||||||
| 427 | * enable vulnerability countermeasure for CBC ciphers with known-IV | - | ||||||||||||
| 428 | * problem (http://www.openssl.org/~bodo/tls-cbc.txt) | - | ||||||||||||
| 429 | */ | - | ||||||||||||
| 430 | s->s3->need_empty_fragments = 1; | - | ||||||||||||
| 431 | - | |||||||||||||
| 432 | if (s->session->cipher != NULL) {
| 0-477 | ||||||||||||
| 433 | if (s->session->cipher->algorithm_enc == SSL_eNULL)
| 10-467 | ||||||||||||
| 434 | s->s3->need_empty_fragments = 0; executed 10 times by 1 test: s->s3->need_empty_fragments = 0;Executed by:
| 10 | ||||||||||||
| 435 | - | |||||||||||||
| 436 | #ifndef OPENSSL_NO_RC4 | - | ||||||||||||
| 437 | if (s->session->cipher->algorithm_enc == SSL_RC4)
| 0-477 | ||||||||||||
| 438 | s->s3->need_empty_fragments = 0; never executed: s->s3->need_empty_fragments = 0; | 0 | ||||||||||||
| 439 | #endif | - | ||||||||||||
| 440 | } executed 477 times by 1 test: end of blockExecuted by:
| 477 | ||||||||||||
| 441 | } executed 477 times by 1 test: end of blockExecuted by:
| 477 | ||||||||||||
| 442 | - | |||||||||||||
| 443 | ret = 1; | - | ||||||||||||
| 444 | err: code before this statement executed 2685 times by 1 test: err:Executed by:
| 2685 | ||||||||||||
| 445 | return ret; executed 2685 times by 1 test: return ret;Executed by:
| 2685 | ||||||||||||
| 446 | } | - | ||||||||||||
| 447 | - | |||||||||||||
| 448 | size_t tls1_final_finish_mac(SSL *s, const char *str, size_t slen, | - | ||||||||||||
| 449 | unsigned char *out) | - | ||||||||||||
| 450 | { | - | ||||||||||||
| 451 | size_t hashlen; | - | ||||||||||||
| 452 | unsigned char hash[EVP_MAX_MD_SIZE]; | - | ||||||||||||
| 453 | - | |||||||||||||
| 454 | if (!ssl3_digest_cached_records(s, 0)) {
| 0-4618 | ||||||||||||
| 455 | /* SSLfatal() already called */ | - | ||||||||||||
| 456 | return 0; never executed: return 0; | 0 | ||||||||||||
| 457 | } | - | ||||||||||||
| 458 | - | |||||||||||||
| 459 | if (!ssl_handshake_hash(s, hash, sizeof(hash), &hashlen)) {
| 0-4618 | ||||||||||||
| 460 | /* SSLfatal() already called */ | - | ||||||||||||
| 461 | return 0; never executed: return 0; | 0 | ||||||||||||
| 462 | } | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | if (!tls1_PRF(s, str, slen, hash, hashlen, NULL, 0, NULL, 0, NULL, 0,
| 0-4618 | ||||||||||||
| 465 | s->session->master_key, s->session->master_key_length,
| 0-4618 | ||||||||||||
| 466 | out, TLS1_FINISH_MAC_LENGTH, 1)) {
| 0-4618 | ||||||||||||
| 467 | /* SSLfatal() already called */ | - | ||||||||||||
| 468 | return 0; never executed: return 0; | 0 | ||||||||||||
| 469 | } | - | ||||||||||||
| 470 | OPENSSL_cleanse(hash, hashlen); | - | ||||||||||||
| 471 | return TLS1_FINISH_MAC_LENGTH; executed 4618 times by 1 test: return 12;Executed by:
| 4618 | ||||||||||||
| 472 | } | - | ||||||||||||
| 473 | - | |||||||||||||
| 474 | int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | - | ||||||||||||
| 475 | size_t len, size_t *secret_size) | - | ||||||||||||
| 476 | { | - | ||||||||||||
| 477 | if (s->session->flags & SSL_SESS_FLAG_EXTMS) {
| 389-2193 | ||||||||||||
| 478 | unsigned char hash[EVP_MAX_MD_SIZE * 2]; | - | ||||||||||||
| 479 | size_t hashlen; | - | ||||||||||||
| 480 | /* | - | ||||||||||||
| 481 | * Digest cached records keeping record buffer (if present): this wont | - | ||||||||||||
| 482 | * affect client auth because we're freezing the buffer at the same | - | ||||||||||||
| 483 | * point (after client key exchange and before certificate verify) | - | ||||||||||||
| 484 | */ | - | ||||||||||||
| 485 | if (!ssl3_digest_cached_records(s, 1)
| 0-2193 | ||||||||||||
| 486 | || !ssl_handshake_hash(s, hash, sizeof(hash), &hashlen)) {
| 0-2193 | ||||||||||||
| 487 | /* SSLfatal() already called */ | - | ||||||||||||
| 488 | return 0; never executed: return 0; | 0 | ||||||||||||
| 489 | } | - | ||||||||||||
| 490 | #ifdef SSL_DEBUG | - | ||||||||||||
| 491 | fprintf(stderr, "Handshake hashes:\n"); | - | ||||||||||||
| 492 | BIO_dump_fp(stderr, (char *)hash, hashlen); | - | ||||||||||||
| 493 | #endif | - | ||||||||||||
| 494 | if (!tls1_PRF(s,
| 0-2193 | ||||||||||||
| 495 | TLS_MD_EXTENDED_MASTER_SECRET_CONST,
| 0-2193 | ||||||||||||
| 496 | TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE,
| 0-2193 | ||||||||||||
| 497 | hash, hashlen,
| 0-2193 | ||||||||||||
| 498 | NULL, 0,
| 0-2193 | ||||||||||||
| 499 | NULL, 0,
| 0-2193 | ||||||||||||
| 500 | NULL, 0, p, len, out,
| 0-2193 | ||||||||||||
| 501 | SSL3_MASTER_SECRET_SIZE, 1)) {
| 0-2193 | ||||||||||||
| 502 | /* SSLfatal() already called */ | - | ||||||||||||
| 503 | return 0; never executed: return 0; | 0 | ||||||||||||
| 504 | } | - | ||||||||||||
| 505 | OPENSSL_cleanse(hash, hashlen); | - | ||||||||||||
| 506 | } else { executed 2193 times by 1 test: end of blockExecuted by:
| 2193 | ||||||||||||
| 507 | if (!tls1_PRF(s,
| 0-389 | ||||||||||||
| 508 | TLS_MD_MASTER_SECRET_CONST,
| 0-389 | ||||||||||||
| 509 | TLS_MD_MASTER_SECRET_CONST_SIZE,
| 0-389 | ||||||||||||
| 510 | s->s3->client_random, SSL3_RANDOM_SIZE,
| 0-389 | ||||||||||||
| 511 | NULL, 0,
| 0-389 | ||||||||||||
| 512 | s->s3->server_random, SSL3_RANDOM_SIZE,
| 0-389 | ||||||||||||
| 513 | NULL, 0, p, len, out,
| 0-389 | ||||||||||||
| 514 | SSL3_MASTER_SECRET_SIZE, 1)) {
| 0-389 | ||||||||||||
| 515 | /* SSLfatal() already called */ | - | ||||||||||||
| 516 | return 0; never executed: return 0; | 0 | ||||||||||||
| 517 | } | - | ||||||||||||
| 518 | } executed 389 times by 1 test: end of blockExecuted by:
| 389 | ||||||||||||
| 519 | #ifdef SSL_DEBUG | - | ||||||||||||
| 520 | fprintf(stderr, "Premaster Secret:\n"); | - | ||||||||||||
| 521 | BIO_dump_fp(stderr, (char *)p, len); | - | ||||||||||||
| 522 | fprintf(stderr, "Client Random:\n"); | - | ||||||||||||
| 523 | BIO_dump_fp(stderr, (char *)s->s3->client_random, SSL3_RANDOM_SIZE); | - | ||||||||||||
| 524 | fprintf(stderr, "Server Random:\n"); | - | ||||||||||||
| 525 | BIO_dump_fp(stderr, (char *)s->s3->server_random, SSL3_RANDOM_SIZE); | - | ||||||||||||
| 526 | fprintf(stderr, "Master Secret:\n"); | - | ||||||||||||
| 527 | BIO_dump_fp(stderr, (char *)s->session->master_key, | - | ||||||||||||
| 528 | SSL3_MASTER_SECRET_SIZE); | - | ||||||||||||
| 529 | #endif | - | ||||||||||||
| 530 | - | |||||||||||||
| 531 | *secret_size = SSL3_MASTER_SECRET_SIZE; | - | ||||||||||||
| 532 | return 1; executed 2582 times by 1 test: return 1;Executed by:
| 2582 | ||||||||||||
| 533 | } | - | ||||||||||||
| 534 | - | |||||||||||||
| 535 | int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen, | - | ||||||||||||
| 536 | const char *label, size_t llen, | - | ||||||||||||
| 537 | const unsigned char *context, | - | ||||||||||||
| 538 | size_t contextlen, int use_context) | - | ||||||||||||
| 539 | { | - | ||||||||||||
| 540 | unsigned char *val = NULL; | - | ||||||||||||
| 541 | size_t vallen = 0, currentvalpos; | - | ||||||||||||
| 542 | int rv; | - | ||||||||||||
| 543 | - | |||||||||||||
| 544 | /* | - | ||||||||||||
| 545 | * construct PRF arguments we construct the PRF argument ourself rather | - | ||||||||||||
| 546 | * than passing separate values into the TLS PRF to ensure that the | - | ||||||||||||
| 547 | * concatenation of values does not create a prohibited label. | - | ||||||||||||
| 548 | */ | - | ||||||||||||
| 549 | vallen = llen + SSL3_RANDOM_SIZE * 2; | - | ||||||||||||
| 550 | if (use_context) {
| 6-12 | ||||||||||||
| 551 | vallen += 2 + contextlen; | - | ||||||||||||
| 552 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 553 | - | |||||||||||||
| 554 | val = OPENSSL_malloc(vallen); | - | ||||||||||||
| 555 | if (val == NULL)
| 0-18 | ||||||||||||
| 556 | goto err2; never executed: goto err2; | 0 | ||||||||||||
| 557 | currentvalpos = 0; | - | ||||||||||||
| 558 | memcpy(val + currentvalpos, (unsigned char *)label, llen); | - | ||||||||||||
| 559 | currentvalpos += llen; | - | ||||||||||||
| 560 | memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE); | - | ||||||||||||
| 561 | currentvalpos += SSL3_RANDOM_SIZE; | - | ||||||||||||
| 562 | memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE); | - | ||||||||||||
| 563 | currentvalpos += SSL3_RANDOM_SIZE; | - | ||||||||||||
| 564 | - | |||||||||||||
| 565 | if (use_context) {
| 6-12 | ||||||||||||
| 566 | val[currentvalpos] = (contextlen >> 8) & 0xff; | - | ||||||||||||
| 567 | currentvalpos++; | - | ||||||||||||
| 568 | val[currentvalpos] = contextlen & 0xff; | - | ||||||||||||
| 569 | currentvalpos++; | - | ||||||||||||
| 570 | if ((contextlen > 0) || (context != NULL)) {
| 0-6 | ||||||||||||
| 571 | memcpy(val + currentvalpos, context, contextlen); | - | ||||||||||||
| 572 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 573 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||
| 574 | - | |||||||||||||
| 575 | /* | - | ||||||||||||
| 576 | * disallow prohibited labels note that SSL3_RANDOM_SIZE > max(prohibited | - | ||||||||||||
| 577 | * label len) = 15, so size of val > max(prohibited label len) = 15 and | - | ||||||||||||
| 578 | * the comparisons won't have buffer overflow | - | ||||||||||||
| 579 | */ | - | ||||||||||||
| 580 | if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
| 0-18 | ||||||||||||
| 581 | TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
| 0-18 | ||||||||||||
| 582 | goto err1; never executed: goto err1; | 0 | ||||||||||||
| 583 | if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
| 0-18 | ||||||||||||
| 584 | TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
| 0-18 | ||||||||||||
| 585 | goto err1; never executed: goto err1; | 0 | ||||||||||||
| 586 | if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
| 0-18 | ||||||||||||
| 587 | TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
| 0-18 | ||||||||||||
| 588 | goto err1; never executed: goto err1; | 0 | ||||||||||||
| 589 | if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
| 0-18 | ||||||||||||
| 590 | TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)
| 0-18 | ||||||||||||
| 591 | goto err1; never executed: goto err1; | 0 | ||||||||||||
| 592 | if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
| 0-18 | ||||||||||||
| 593 | TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
| 0-18 | ||||||||||||
| 594 | goto err1; never executed: goto err1; | 0 | ||||||||||||
| 595 | - | |||||||||||||
| 596 | rv = tls1_PRF(s, | - | ||||||||||||
| 597 | val, vallen, | - | ||||||||||||
| 598 | NULL, 0, | - | ||||||||||||
| 599 | NULL, 0, | - | ||||||||||||
| 600 | NULL, 0, | - | ||||||||||||
| 601 | NULL, 0, | - | ||||||||||||
| 602 | s->session->master_key, s->session->master_key_length, | - | ||||||||||||
| 603 | out, olen, 0); | - | ||||||||||||
| 604 | - | |||||||||||||
| 605 | goto ret; executed 18 times by 1 test: goto ret;Executed by:
| 18 | ||||||||||||
| 606 | err1: | - | ||||||||||||
| 607 | SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL); | - | ||||||||||||
| 608 | rv = 0; | - | ||||||||||||
| 609 | goto ret; never executed: goto ret; | 0 | ||||||||||||
| 610 | err2: | - | ||||||||||||
| 611 | SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 612 | rv = 0; | - | ||||||||||||
| 613 | ret: code before this statement never executed: ret: | 0 | ||||||||||||
| 614 | OPENSSL_clear_free(val, vallen); | - | ||||||||||||
| 615 | return rv; executed 18 times by 1 test: return rv;Executed by:
| 18 | ||||||||||||
| 616 | } | - | ||||||||||||
| 617 | - | |||||||||||||
| 618 | int tls1_alert_code(int code) | - | ||||||||||||
| 619 | { | - | ||||||||||||
| 620 | switch (code) { | - | ||||||||||||
| 621 | case SSL_AD_CLOSE_NOTIFY: executed 2587 times by 1 test: case 0:Executed by:
| 2587 | ||||||||||||
| 622 | return SSL3_AD_CLOSE_NOTIFY; executed 2587 times by 1 test: return 0;Executed by:
| 2587 | ||||||||||||
| 623 | case SSL_AD_UNEXPECTED_MESSAGE: executed 131 times by 1 test: case 10:Executed by:
| 131 | ||||||||||||
| 624 | return SSL3_AD_UNEXPECTED_MESSAGE; executed 131 times by 1 test: return 10;Executed by:
| 131 | ||||||||||||
| 625 | case SSL_AD_BAD_RECORD_MAC: executed 334 times by 1 test: case 20:Executed by:
| 334 | ||||||||||||
| 626 | return SSL3_AD_BAD_RECORD_MAC; executed 334 times by 1 test: return 20;Executed by:
| 334 | ||||||||||||
| 627 | case SSL_AD_DECRYPTION_FAILED: executed 41 times by 1 test: case 21:Executed by:
| 41 | ||||||||||||
| 628 | return TLS1_AD_DECRYPTION_FAILED; executed 41 times by 1 test: return 21;Executed by:
| 41 | ||||||||||||
| 629 | case SSL_AD_RECORD_OVERFLOW: executed 13 times by 1 test: case 22:Executed by:
| 13 | ||||||||||||
| 630 | return TLS1_AD_RECORD_OVERFLOW; executed 13 times by 1 test: return 22;Executed by:
| 13 | ||||||||||||
| 631 | case SSL_AD_DECOMPRESSION_FAILURE: never executed: case 30: | 0 | ||||||||||||
| 632 | return SSL3_AD_DECOMPRESSION_FAILURE; never executed: return 30; | 0 | ||||||||||||
| 633 | case SSL_AD_HANDSHAKE_FAILURE: executed 257 times by 1 test: case 40:Executed by:
| 257 | ||||||||||||
| 634 | return SSL3_AD_HANDSHAKE_FAILURE; executed 257 times by 1 test: return 40;Executed by:
| 257 | ||||||||||||
| 635 | case SSL_AD_NO_CERTIFICATE: never executed: case 41: | 0 | ||||||||||||
| 636 | return -1; never executed: return -1; | 0 | ||||||||||||
| 637 | case SSL_AD_BAD_CERTIFICATE: executed 437 times by 1 test: case 42:Executed by:
| 437 | ||||||||||||
| 638 | return SSL3_AD_BAD_CERTIFICATE; executed 437 times by 1 test: return 42;Executed by:
| 437 | ||||||||||||
| 639 | case SSL_AD_UNSUPPORTED_CERTIFICATE: never executed: case 43: | 0 | ||||||||||||
| 640 | return SSL3_AD_UNSUPPORTED_CERTIFICATE; never executed: return 43; | 0 | ||||||||||||
| 641 | case SSL_AD_CERTIFICATE_REVOKED: never executed: case 44: | 0 | ||||||||||||
| 642 | return SSL3_AD_CERTIFICATE_REVOKED; never executed: return 44; | 0 | ||||||||||||
| 643 | case SSL_AD_CERTIFICATE_EXPIRED: never executed: case 45: | 0 | ||||||||||||
| 644 | return SSL3_AD_CERTIFICATE_EXPIRED; never executed: return 45; | 0 | ||||||||||||
| 645 | case SSL_AD_CERTIFICATE_UNKNOWN: never executed: case 46: | 0 | ||||||||||||
| 646 | return SSL3_AD_CERTIFICATE_UNKNOWN; never executed: return 46; | 0 | ||||||||||||
| 647 | case SSL_AD_ILLEGAL_PARAMETER: executed 265 times by 1 test: case 47:Executed by:
| 265 | ||||||||||||
| 648 | return SSL3_AD_ILLEGAL_PARAMETER; executed 265 times by 1 test: return 47;Executed by:
| 265 | ||||||||||||
| 649 | case SSL_AD_UNKNOWN_CA: executed 10 times by 1 test: case 48:Executed by:
| 10 | ||||||||||||
| 650 | return TLS1_AD_UNKNOWN_CA; executed 10 times by 1 test: return 48;Executed by:
| 10 | ||||||||||||
| 651 | case SSL_AD_ACCESS_DENIED: never executed: case 49: | 0 | ||||||||||||
| 652 | return TLS1_AD_ACCESS_DENIED; never executed: return 49; | 0 | ||||||||||||
| 653 | case SSL_AD_DECODE_ERROR: executed 523 times by 1 test: case 50:Executed by:
| 523 | ||||||||||||
| 654 | return TLS1_AD_DECODE_ERROR; executed 523 times by 1 test: return 50;Executed by:
| 523 | ||||||||||||
| 655 | case SSL_AD_DECRYPT_ERROR: executed 400 times by 1 test: case 51:Executed by:
| 400 | ||||||||||||
| 656 | return TLS1_AD_DECRYPT_ERROR; executed 400 times by 1 test: return 51;Executed by:
| 400 | ||||||||||||
| 657 | case SSL_AD_EXPORT_RESTRICTION: never executed: case 60: | 0 | ||||||||||||
| 658 | return TLS1_AD_EXPORT_RESTRICTION; never executed: return 60; | 0 | ||||||||||||
| 659 | case SSL_AD_PROTOCOL_VERSION: executed 958 times by 1 test: case 70:Executed by:
| 958 | ||||||||||||
| 660 | return TLS1_AD_PROTOCOL_VERSION; executed 958 times by 1 test: return 70;Executed by:
| 958 | ||||||||||||
| 661 | case SSL_AD_INSUFFICIENT_SECURITY: never executed: case 71: | 0 | ||||||||||||
| 662 | return TLS1_AD_INSUFFICIENT_SECURITY; never executed: return 71; | 0 | ||||||||||||
| 663 | case SSL_AD_INTERNAL_ERROR: executed 369 times by 1 test: case 80:Executed by:
| 369 | ||||||||||||
| 664 | return TLS1_AD_INTERNAL_ERROR; executed 369 times by 1 test: return 80;Executed by:
| 369 | ||||||||||||
| 665 | case SSL_AD_USER_CANCELLED: never executed: case 90: | 0 | ||||||||||||
| 666 | return TLS1_AD_USER_CANCELLED; never executed: return 90; | 0 | ||||||||||||
| 667 | case SSL_AD_NO_RENEGOTIATION: executed 3 times by 1 test: case 100:Executed by:
| 3 | ||||||||||||
| 668 | return TLS1_AD_NO_RENEGOTIATION; executed 3 times by 1 test: return 100;Executed by:
| 3 | ||||||||||||
| 669 | case SSL_AD_UNSUPPORTED_EXTENSION: executed 11 times by 1 test: case 110:Executed by:
| 11 | ||||||||||||
| 670 | return TLS1_AD_UNSUPPORTED_EXTENSION; executed 11 times by 1 test: return 110;Executed by:
| 11 | ||||||||||||
| 671 | case SSL_AD_CERTIFICATE_UNOBTAINABLE: never executed: case 111: | 0 | ||||||||||||
| 672 | return TLS1_AD_CERTIFICATE_UNOBTAINABLE; never executed: return 111; | 0 | ||||||||||||
| 673 | case SSL_AD_UNRECOGNIZED_NAME: executed 4 times by 1 test: case 112:Executed by:
| 4 | ||||||||||||
| 674 | return TLS1_AD_UNRECOGNIZED_NAME; executed 4 times by 1 test: return 112;Executed by:
| 4 | ||||||||||||
| 675 | case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE: executed 2 times by 1 test: case 113:Executed by:
| 2 | ||||||||||||
| 676 | return TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE; executed 2 times by 1 test: return 113;Executed by:
| 2 | ||||||||||||
| 677 | case SSL_AD_BAD_CERTIFICATE_HASH_VALUE: never executed: case 114: | 0 | ||||||||||||
| 678 | return TLS1_AD_BAD_CERTIFICATE_HASH_VALUE; never executed: return 114; | 0 | ||||||||||||
| 679 | case SSL_AD_UNKNOWN_PSK_IDENTITY: never executed: case 115: | 0 | ||||||||||||
| 680 | return TLS1_AD_UNKNOWN_PSK_IDENTITY; never executed: return 115; | 0 | ||||||||||||
| 681 | case SSL_AD_INAPPROPRIATE_FALLBACK: executed 1 time by 1 test: case 86:Executed by:
| 1 | ||||||||||||
| 682 | return TLS1_AD_INAPPROPRIATE_FALLBACK; executed 1 time by 1 test: return 86;Executed by:
| 1 | ||||||||||||
| 683 | case SSL_AD_NO_APPLICATION_PROTOCOL: executed 2 times by 1 test: case 120:Executed by:
| 2 | ||||||||||||
| 684 | return TLS1_AD_NO_APPLICATION_PROTOCOL; executed 2 times by 1 test: return 120;Executed by:
| 2 | ||||||||||||
| 685 | case SSL_AD_CERTIFICATE_REQUIRED: executed 5 times by 1 test: case 116:Executed by:
| 5 | ||||||||||||
| 686 | return SSL_AD_HANDSHAKE_FAILURE; executed 5 times by 1 test: return 40;Executed by:
| 5 | ||||||||||||
| 687 | default: never executed: default: | 0 | ||||||||||||
| 688 | return -1; never executed: return -1; | 0 | ||||||||||||
| 689 | } | - | ||||||||||||
| 690 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |