| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ct/ct_sct_ctx.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | SCT_CTX *SCT_CTX_new(void) | - | ||||||||||||
| 5 | { | - | ||||||||||||
| 6 | SCT_CTX *sctx = CRYPTO_zalloc(sizeof(*sctx), __FILE__, 25); | - | ||||||||||||
| 7 | - | |||||||||||||
| 8 | if (sctx ==
| 0-9 | ||||||||||||
| 9 | ((void *)0)
| 0-9 | ||||||||||||
| 10 | ) | - | ||||||||||||
| 11 | ERR_put_error(50,(126),((1|64)),__FILE__,28); never executed: ERR_put_error(50,(126),((1|64)),__FILE__,28); | 0 | ||||||||||||
| 12 | - | |||||||||||||
| 13 | return executed 9 times by 1 test: sctx;return sctx;Executed by:
executed 9 times by 1 test: return sctx;Executed by:
| 9 | ||||||||||||
| 14 | } | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | void SCT_CTX_free(SCT_CTX *sctx) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | if (sctx ==
| 0-9 | ||||||||||||
| 19 | ((void *)0)
| 0-9 | ||||||||||||
| 20 | ) | - | ||||||||||||
| 21 | return; never executed: return; | 0 | ||||||||||||
| 22 | EVP_PKEY_free(sctx->pkey); | - | ||||||||||||
| 23 | CRYPTO_free(sctx->pkeyhash, __FILE__, 38); | - | ||||||||||||
| 24 | CRYPTO_free(sctx->ihash, __FILE__, 39); | - | ||||||||||||
| 25 | CRYPTO_free(sctx->certder, __FILE__, 40); | - | ||||||||||||
| 26 | CRYPTO_free(sctx->preder, __FILE__, 41); | - | ||||||||||||
| 27 | CRYPTO_free(sctx, __FILE__, 42); | - | ||||||||||||
| 28 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| 29 | - | |||||||||||||
| 30 | - | |||||||||||||
| 31 | - | |||||||||||||
| 32 | - | |||||||||||||
| 33 | - | |||||||||||||
| 34 | - | |||||||||||||
| 35 | static int ct_x509_get_ext(X509 *cert, int nid, int *is_duplicated) | - | ||||||||||||
| 36 | { | - | ||||||||||||
| 37 | int ret = X509_get_ext_by_NID(cert, nid, -1); | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | if (is_duplicated !=
| 0-18 | ||||||||||||
| 40 | ((void *)0)
| 0-18 | ||||||||||||
| 41 | ) | - | ||||||||||||
| 42 | * executed 18 times by 1 test: is_duplicated = ret >= 0*is_duplicated = ret >= 0 && X509_get_ext_by_NID(cert, nid, ret) >= 0;Executed by:
executed 18 times by 1 test: *is_duplicated = ret >= 0 && X509_get_ext_by_NID(cert, nid, ret) >= 0;Executed by:
| 0-18 | ||||||||||||
| 43 | - | |||||||||||||
| 44 | return executed 18 times by 1 test: ret;return ret;Executed by:
executed 18 times by 1 test: return ret;Executed by:
| 18 | ||||||||||||
| 45 | } | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | - | |||||||||||||
| 48 | - | |||||||||||||
| 49 | - | |||||||||||||
| 50 | - | |||||||||||||
| 51 | - | |||||||||||||
| 52 | static int ct_x509_cert_fixup(X509 *cert, X509 *presigner) | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | int preidx, certidx; | - | ||||||||||||
| 55 | int pre_akid_ext_is_dup, cert_akid_ext_is_dup; | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | if (presigner ==
| 0-9 | ||||||||||||
| 58 | ((void *)0)
| 0-9 | ||||||||||||
| 59 | ) | - | ||||||||||||
| 60 | return executed 9 times by 1 test: 1;return 1;Executed by:
executed 9 times by 1 test: return 1;Executed by:
| 9 | ||||||||||||
| 61 | - | |||||||||||||
| 62 | preidx = ct_x509_get_ext(presigner, 90, | - | ||||||||||||
| 63 | &pre_akid_ext_is_dup); | - | ||||||||||||
| 64 | certidx = ct_x509_get_ext(cert, 90, | - | ||||||||||||
| 65 | &cert_akid_ext_is_dup); | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | - | |||||||||||||
| 68 | if (preidx < -1
| 0 | ||||||||||||
| 69 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 70 | - | |||||||||||||
| 71 | if (pre_akid_ext_is_dup
| 0 | ||||||||||||
| 72 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 73 | - | |||||||||||||
| 74 | if (preidx >= 0
| 0 | ||||||||||||
| 75 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 76 | if (preidx == -1
| 0 | ||||||||||||
| 77 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 78 | - | |||||||||||||
| 79 | if (!X509_set_issuer_name(cert, X509_get_issuer_name(presigner))
| 0 | ||||||||||||
| 80 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 81 | if (preidx != -1
| 0 | ||||||||||||
| 82 | - | |||||||||||||
| 83 | X509_EXTENSION *preext = X509_get_ext(presigner, preidx); | - | ||||||||||||
| 84 | X509_EXTENSION *certext = X509_get_ext(cert, certidx); | - | ||||||||||||
| 85 | ASN1_OCTET_STRING *preextdata; | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | - | |||||||||||||
| 88 | if (preext ==
| 0 | ||||||||||||
| 89 | ((void *)0)
| 0 | ||||||||||||
| 90 | || certext ==
| 0 | ||||||||||||
| 91 | ((void *)0)
| 0 | ||||||||||||
| 92 | ) | - | ||||||||||||
| 93 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 94 | preextdata = X509_EXTENSION_get_data(preext); | - | ||||||||||||
| 95 | if (preextdata ==
| 0 | ||||||||||||
| 96 | ((void *)0)
| 0 | ||||||||||||
| 97 | || | - | ||||||||||||
| 98 | !X509_EXTENSION_set_data(certext, preextdata)
| 0 | ||||||||||||
| 99 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 100 | } never executed: end of block | 0 | ||||||||||||
| 101 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||
| 102 | } | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | int SCT_CTX_set1_cert(SCT_CTX *sctx, X509 *cert, X509 *presigner) | - | ||||||||||||
| 105 | { | - | ||||||||||||
| 106 | unsigned char *certder = | - | ||||||||||||
| 107 | ((void *)0) | - | ||||||||||||
| 108 | , *preder = | - | ||||||||||||
| 109 | ((void *)0) | - | ||||||||||||
| 110 | ; | - | ||||||||||||
| 111 | X509 *pretmp = | - | ||||||||||||
| 112 | ((void *)0) | - | ||||||||||||
| 113 | ; | - | ||||||||||||
| 114 | int certderlen = 0, prederlen = 0; | - | ||||||||||||
| 115 | int idx = -1; | - | ||||||||||||
| 116 | int poison_ext_is_dup, sct_ext_is_dup; | - | ||||||||||||
| 117 | int poison_idx = ct_x509_get_ext(cert, 952, &poison_ext_is_dup); | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | - | |||||||||||||
| 120 | if (poison_ext_is_dup
| 0-9 | ||||||||||||
| 121 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 122 | - | |||||||||||||
| 123 | - | |||||||||||||
| 124 | if (poison_idx == -1
| 0-9 | ||||||||||||
| 125 | - | |||||||||||||
| 126 | if (presigner !=
| 0-9 | ||||||||||||
| 127 | ((void *)0)
| 0-9 | ||||||||||||
| 128 | ) | - | ||||||||||||
| 129 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 130 | - | |||||||||||||
| 131 | certderlen = i2d_X509(cert, &certder); | - | ||||||||||||
| 132 | if (certderlen < 0
| 0-9 | ||||||||||||
| 133 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 134 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | - | |||||||||||||
| 137 | idx = ct_x509_get_ext(cert, 951, &sct_ext_is_dup); | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | if (sct_ext_is_dup
| 0-9 | ||||||||||||
| 140 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | if (idx >= 0
| 0-9 | ||||||||||||
| 143 | - | |||||||||||||
| 144 | - | |||||||||||||
| 145 | - | |||||||||||||
| 146 | - | |||||||||||||
| 147 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 148 | } | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | if (idx == -1
| 0-9 | ||||||||||||
| 151 | idx = poison_idx; | - | ||||||||||||
| 152 | } never executed: end of block | 0 | ||||||||||||
| 153 | - | |||||||||||||
| 154 | - | |||||||||||||
| 155 | - | |||||||||||||
| 156 | - | |||||||||||||
| 157 | - | |||||||||||||
| 158 | - | |||||||||||||
| 159 | - | |||||||||||||
| 160 | if (idx >= 0
| 0-9 | ||||||||||||
| 161 | X509_EXTENSION *ext; | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | - | |||||||||||||
| 164 | pretmp = X509_dup(cert); | - | ||||||||||||
| 165 | if (pretmp ==
| 0-9 | ||||||||||||
| 166 | ((void *)0)
| 0-9 | ||||||||||||
| 167 | ) | - | ||||||||||||
| 168 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 169 | - | |||||||||||||
| 170 | ext = X509_delete_ext(pretmp, idx); | - | ||||||||||||
| 171 | X509_EXTENSION_free(ext); | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | if (!ct_x509_cert_fixup(pretmp, presigner)
| 0-9 | ||||||||||||
| 174 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | prederlen = i2d_re_X509_tbs(pretmp, &preder); | - | ||||||||||||
| 177 | if (prederlen <= 0
| 0-9 | ||||||||||||
| 178 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 179 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| 180 | - | |||||||||||||
| 181 | X509_free(pretmp); | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | CRYPTO_free(sctx->certder, __FILE__, 178); | - | ||||||||||||
| 184 | sctx->certder = certder; | - | ||||||||||||
| 185 | sctx->certderlen = certderlen; | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | CRYPTO_free(sctx->preder, __FILE__, 182); | - | ||||||||||||
| 188 | sctx->preder = preder; | - | ||||||||||||
| 189 | sctx->prederlen = prederlen; | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | return executed 9 times by 1 test: 1;return 1;Executed by:
executed 9 times by 1 test: return 1;Executed by:
| 9 | ||||||||||||
| 192 | err: | - | ||||||||||||
| 193 | CRYPTO_free(certder, __FILE__, 188); | - | ||||||||||||
| 194 | CRYPTO_free(preder, __FILE__, 189); | - | ||||||||||||
| 195 | X509_free(pretmp); | - | ||||||||||||
| 196 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | static int ct_public_key_hash(X509_PUBKEY *pkey, unsigned char **hash, | - | ||||||||||||
| 200 | size_t *hash_len) | - | ||||||||||||
| 201 | { | - | ||||||||||||
| 202 | int ret = 0; | - | ||||||||||||
| 203 | unsigned char *md = | - | ||||||||||||
| 204 | ((void *)0) | - | ||||||||||||
| 205 | , *der = | - | ||||||||||||
| 206 | ((void *)0) | - | ||||||||||||
| 207 | ; | - | ||||||||||||
| 208 | int der_len; | - | ||||||||||||
| 209 | unsigned int md_len; | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | - | |||||||||||||
| 212 | if (*
| 0-18 | ||||||||||||
| 213 | ((void *)0)
| 0-18 | ||||||||||||
| 214 | && *
| 0 | ||||||||||||
| 215 | md = *hash; | - | ||||||||||||
| 216 | } never executed: else {end of block | 0 | ||||||||||||
| 217 | md = CRYPTO_malloc(32, __FILE__, 206); | - | ||||||||||||
| 218 | if (md ==
| 0-18 | ||||||||||||
| 219 | ((void *)0)
| 0-18 | ||||||||||||
| 220 | ) | - | ||||||||||||
| 221 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 222 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 223 | - | |||||||||||||
| 224 | - | |||||||||||||
| 225 | der_len = i2d_X509_PUBKEY(pkey, &der); | - | ||||||||||||
| 226 | if (der_len <= 0
| 0-18 | ||||||||||||
| 227 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 228 | - | |||||||||||||
| 229 | if (!EVP_Digest(der, der_len, md, &md_len, EVP_sha256(),
| 0-18 | ||||||||||||
| 230 | ((void *)0)
| 0-18 | ||||||||||||
| 231 | )
| 0-18 | ||||||||||||
| 232 | goto never executed: err;goto err;never executed: goto err; | 0 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | if (md != *hash
| 0-18 | ||||||||||||
| 235 | CRYPTO_free(*hash, __FILE__, 220); | - | ||||||||||||
| 236 | *hash = md; | - | ||||||||||||
| 237 | *hash_len = 32; | - | ||||||||||||
| 238 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 239 | - | |||||||||||||
| 240 | md = | - | ||||||||||||
| 241 | ((void *)0) | - | ||||||||||||
| 242 | ; | - | ||||||||||||
| 243 | ret = 1; | - | ||||||||||||
| 244 | err: code before this statement executed 18 times by 1 test: err:Executed by:
| 18 | ||||||||||||
| 245 | CRYPTO_free(md, __FILE__, 228); | - | ||||||||||||
| 246 | CRYPTO_free(der, __FILE__, 229); | - | ||||||||||||
| 247 | return executed 18 times by 1 test: ret;return ret;Executed by:
executed 18 times by 1 test: return ret;Executed by:
| 18 | ||||||||||||
| 248 | } | - | ||||||||||||
| 249 | - | |||||||||||||
| 250 | int SCT_CTX_set1_issuer(SCT_CTX *sctx, const X509 *issuer) | - | ||||||||||||
| 251 | { | - | ||||||||||||
| 252 | return never executed: SCT_CTX_set1_issuer_pubkey(sctx, X509_get_X509_PUBKEY(issuer));return SCT_CTX_set1_issuer_pubkey(sctx, X509_get_X509_PUBKEY(issuer));never executed: return SCT_CTX_set1_issuer_pubkey(sctx, X509_get_X509_PUBKEY(issuer)); | 0 | ||||||||||||
| 253 | } | - | ||||||||||||
| 254 | - | |||||||||||||
| 255 | int SCT_CTX_set1_issuer_pubkey(SCT_CTX *sctx, X509_PUBKEY *pubkey) | - | ||||||||||||
| 256 | { | - | ||||||||||||
| 257 | return executed 9 times by 1 test: ct_public_key_hash(pubkey, &sctx->ihash, &sctx->ihashlen);return ct_public_key_hash(pubkey, &sctx->ihash, &sctx->ihashlen);Executed by:
executed 9 times by 1 test: return ct_public_key_hash(pubkey, &sctx->ihash, &sctx->ihashlen);Executed by:
| 9 | ||||||||||||
| 258 | } | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | int SCT_CTX_set1_pubkey(SCT_CTX *sctx, X509_PUBKEY *pubkey) | - | ||||||||||||
| 261 | { | - | ||||||||||||
| 262 | EVP_PKEY *pkey = X509_PUBKEY_get(pubkey); | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | if (pkey ==
| 0-9 | ||||||||||||
| 265 | ((void *)0)
| 0-9 | ||||||||||||
| 266 | ) | - | ||||||||||||
| 267 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 268 | - | |||||||||||||
| 269 | if (!ct_public_key_hash(pubkey, &sctx->pkeyhash, &sctx->pkeyhashlen)
| 0-9 | ||||||||||||
| 270 | EVP_PKEY_free(pkey); | - | ||||||||||||
| 271 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||
| 272 | } | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | EVP_PKEY_free(sctx->pkey); | - | ||||||||||||
| 275 | sctx->pkey = pkey; | - | ||||||||||||
| 276 | return executed 9 times by 1 test: 1;return 1;Executed by:
executed 9 times by 1 test: return 1;Executed by:
| 9 | ||||||||||||
| 277 | } | - | ||||||||||||
| 278 | - | |||||||||||||
| 279 | void SCT_CTX_set_time(SCT_CTX *sctx, uint64_t time_in_ms) | - | ||||||||||||
| 280 | { | - | ||||||||||||
| 281 | sctx->epoch_time_in_ms = time_in_ms; | - | ||||||||||||
| 282 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| Switch to Source code | Preprocessed file |