/src/openssl111/crypto/ts/ts_req_utils.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the OpenSSL license (the "License").  You may not use | 
| 5 |  |  * this file except in compliance with the License.  You can obtain a copy | 
| 6 |  |  * in the file LICENSE in the source distribution or at | 
| 7 |  |  * https://www.openssl.org/source/license.html | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | #include <stdio.h> | 
| 11 |  | #include "internal/cryptlib.h" | 
| 12 |  | #include <openssl/objects.h> | 
| 13 |  | #include <openssl/x509v3.h> | 
| 14 |  | #include <openssl/ts.h> | 
| 15 |  | #include "ts_local.h" | 
| 16 |  |  | 
| 17 |  | int TS_REQ_set_version(TS_REQ *a, long version) | 
| 18 | 0 | { | 
| 19 | 0 |     return ASN1_INTEGER_set(a->version, version); | 
| 20 | 0 | } | 
| 21 |  |  | 
| 22 |  | long TS_REQ_get_version(const TS_REQ *a) | 
| 23 | 2.34k | { | 
| 24 | 2.34k |     return ASN1_INTEGER_get(a->version); | 
| 25 | 2.34k | } | 
| 26 |  |  | 
| 27 |  | int TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint) | 
| 28 | 0 | { | 
| 29 | 0 |     TS_MSG_IMPRINT *new_msg_imprint; | 
| 30 |  | 
 | 
| 31 | 0 |     if (a->msg_imprint == msg_imprint) | 
| 32 | 0 |         return 1; | 
| 33 | 0 |     new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint); | 
| 34 | 0 |     if (new_msg_imprint == NULL) { | 
| 35 | 0 |         TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE); | 
| 36 | 0 |         return 0; | 
| 37 | 0 |     } | 
| 38 | 0 |     TS_MSG_IMPRINT_free(a->msg_imprint); | 
| 39 | 0 |     a->msg_imprint = new_msg_imprint; | 
| 40 | 0 |     return 1; | 
| 41 | 0 | } | 
| 42 |  |  | 
| 43 |  | TS_MSG_IMPRINT *TS_REQ_get_msg_imprint(TS_REQ *a) | 
| 44 | 0 | { | 
| 45 | 0 |     return a->msg_imprint; | 
| 46 | 0 | } | 
| 47 |  |  | 
| 48 |  | int TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg) | 
| 49 | 0 | { | 
| 50 | 0 |     X509_ALGOR *new_alg; | 
| 51 |  | 
 | 
| 52 | 0 |     if (a->hash_algo == alg) | 
| 53 | 0 |         return 1; | 
| 54 | 0 |     new_alg = X509_ALGOR_dup(alg); | 
| 55 | 0 |     if (new_alg == NULL) { | 
| 56 | 0 |         TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE); | 
| 57 | 0 |         return 0; | 
| 58 | 0 |     } | 
| 59 | 0 |     X509_ALGOR_free(a->hash_algo); | 
| 60 | 0 |     a->hash_algo = new_alg; | 
| 61 | 0 |     return 1; | 
| 62 | 0 | } | 
| 63 |  |  | 
| 64 |  | X509_ALGOR *TS_MSG_IMPRINT_get_algo(TS_MSG_IMPRINT *a) | 
| 65 | 0 | { | 
| 66 | 0 |     return a->hash_algo; | 
| 67 | 0 | } | 
| 68 |  |  | 
| 69 |  | int TS_MSG_IMPRINT_set_msg(TS_MSG_IMPRINT *a, unsigned char *d, int len) | 
| 70 | 0 | { | 
| 71 | 0 |     return ASN1_OCTET_STRING_set(a->hashed_msg, d, len); | 
| 72 | 0 | } | 
| 73 |  |  | 
| 74 |  | ASN1_OCTET_STRING *TS_MSG_IMPRINT_get_msg(TS_MSG_IMPRINT *a) | 
| 75 | 0 | { | 
| 76 | 0 |     return a->hashed_msg; | 
| 77 | 0 | } | 
| 78 |  |  | 
| 79 |  | int TS_REQ_set_policy_id(TS_REQ *a, const ASN1_OBJECT *policy) | 
| 80 | 0 | { | 
| 81 | 0 |     ASN1_OBJECT *new_policy; | 
| 82 |  | 
 | 
| 83 | 0 |     if (a->policy_id == policy) | 
| 84 | 0 |         return 1; | 
| 85 | 0 |     new_policy = OBJ_dup(policy); | 
| 86 | 0 |     if (new_policy == NULL) { | 
| 87 | 0 |         TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE); | 
| 88 | 0 |         return 0; | 
| 89 | 0 |     } | 
| 90 | 0 |     ASN1_OBJECT_free(a->policy_id); | 
| 91 | 0 |     a->policy_id = new_policy; | 
| 92 | 0 |     return 1; | 
| 93 | 0 | } | 
| 94 |  |  | 
| 95 |  | ASN1_OBJECT *TS_REQ_get_policy_id(TS_REQ *a) | 
| 96 | 2.34k | { | 
| 97 | 2.34k |     return a->policy_id; | 
| 98 | 2.34k | } | 
| 99 |  |  | 
| 100 |  | int TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce) | 
| 101 | 0 | { | 
| 102 | 0 |     ASN1_INTEGER *new_nonce; | 
| 103 |  | 
 | 
| 104 | 0 |     if (a->nonce == nonce) | 
| 105 | 0 |         return 1; | 
| 106 | 0 |     new_nonce = ASN1_INTEGER_dup(nonce); | 
| 107 | 0 |     if (new_nonce == NULL) { | 
| 108 | 0 |         TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE); | 
| 109 | 0 |         return 0; | 
| 110 | 0 |     } | 
| 111 | 0 |     ASN1_INTEGER_free(a->nonce); | 
| 112 | 0 |     a->nonce = new_nonce; | 
| 113 | 0 |     return 1; | 
| 114 | 0 | } | 
| 115 |  |  | 
| 116 |  | const ASN1_INTEGER *TS_REQ_get_nonce(const TS_REQ *a) | 
| 117 | 0 | { | 
| 118 | 0 |     return a->nonce; | 
| 119 | 0 | } | 
| 120 |  |  | 
| 121 |  | int TS_REQ_set_cert_req(TS_REQ *a, int cert_req) | 
| 122 | 0 | { | 
| 123 | 0 |     a->cert_req = cert_req ? 0xFF : 0x00; | 
| 124 | 0 |     return 1; | 
| 125 | 0 | } | 
| 126 |  |  | 
| 127 |  | int TS_REQ_get_cert_req(const TS_REQ *a) | 
| 128 | 0 | { | 
| 129 | 0 |     return a->cert_req ? 1 : 0; | 
| 130 | 0 | } | 
| 131 |  |  | 
| 132 |  | STACK_OF(X509_EXTENSION) *TS_REQ_get_exts(TS_REQ *a) | 
| 133 | 0 | { | 
| 134 | 0 |     return a->extensions; | 
| 135 | 0 | } | 
| 136 |  |  | 
| 137 |  | void TS_REQ_ext_free(TS_REQ *a) | 
| 138 | 0 | { | 
| 139 | 0 |     if (!a) | 
| 140 | 0 |         return; | 
| 141 | 0 |     sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free); | 
| 142 | 0 |     a->extensions = NULL; | 
| 143 | 0 | } | 
| 144 |  |  | 
| 145 |  | int TS_REQ_get_ext_count(TS_REQ *a) | 
| 146 | 0 | { | 
| 147 | 0 |     return X509v3_get_ext_count(a->extensions); | 
| 148 | 0 | } | 
| 149 |  |  | 
| 150 |  | int TS_REQ_get_ext_by_NID(TS_REQ *a, int nid, int lastpos) | 
| 151 | 0 | { | 
| 152 | 0 |     return X509v3_get_ext_by_NID(a->extensions, nid, lastpos); | 
| 153 | 0 | } | 
| 154 |  |  | 
| 155 |  | int TS_REQ_get_ext_by_OBJ(TS_REQ *a, const ASN1_OBJECT *obj, int lastpos) | 
| 156 | 0 | { | 
| 157 | 0 |     return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos); | 
| 158 | 0 | } | 
| 159 |  |  | 
| 160 |  | int TS_REQ_get_ext_by_critical(TS_REQ *a, int crit, int lastpos) | 
| 161 | 0 | { | 
| 162 | 0 |     return X509v3_get_ext_by_critical(a->extensions, crit, lastpos); | 
| 163 | 0 | } | 
| 164 |  |  | 
| 165 |  | X509_EXTENSION *TS_REQ_get_ext(TS_REQ *a, int loc) | 
| 166 | 0 | { | 
| 167 | 0 |     return X509v3_get_ext(a->extensions, loc); | 
| 168 | 0 | } | 
| 169 |  |  | 
| 170 |  | X509_EXTENSION *TS_REQ_delete_ext(TS_REQ *a, int loc) | 
| 171 | 0 | { | 
| 172 | 0 |     return X509v3_delete_ext(a->extensions, loc); | 
| 173 | 0 | } | 
| 174 |  |  | 
| 175 |  | int TS_REQ_add_ext(TS_REQ *a, X509_EXTENSION *ex, int loc) | 
| 176 | 0 | { | 
| 177 | 0 |     return X509v3_add_ext(&a->extensions, ex, loc) != NULL; | 
| 178 | 0 | } | 
| 179 |  |  | 
| 180 |  | void *TS_REQ_get_ext_d2i(TS_REQ *a, int nid, int *crit, int *idx) | 
| 181 | 0 | { | 
| 182 | 0 |     return X509V3_get_d2i(a->extensions, nid, crit, idx); | 
| 183 | 0 | } |