diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_ess.c')
| -rw-r--r-- | src/lib/libcrypto/cms/cms_ess.c | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/src/lib/libcrypto/cms/cms_ess.c b/src/lib/libcrypto/cms/cms_ess.c index bcc3e58368..abfd170bb4 100644 --- a/src/lib/libcrypto/cms/cms_ess.c +++ b/src/lib/libcrypto/cms/cms_ess.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: cms_ess.c,v 1.13 2019/08/10 16:42:20 jsing Exp $ */ | 1 | /* $OpenBSD: cms_ess.c,v 1.14 2019/08/10 18:15:52 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 4 | * project. | 4 | * project. |
| @@ -65,16 +65,16 @@ IMPLEMENT_ASN1_FUNCTIONS(CMS_ReceiptRequest) | |||
| 65 | 65 | ||
| 66 | /* ESS services: for now just Signed Receipt related */ | 66 | /* ESS services: for now just Signed Receipt related */ |
| 67 | 67 | ||
| 68 | int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr) | 68 | int |
| 69 | CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr) | ||
| 69 | { | 70 | { |
| 70 | ASN1_STRING *str; | 71 | ASN1_STRING *str; |
| 71 | CMS_ReceiptRequest *rr = NULL; | 72 | CMS_ReceiptRequest *rr = NULL; |
| 73 | |||
| 72 | if (prr) | 74 | if (prr) |
| 73 | *prr = NULL; | 75 | *prr = NULL; |
| 74 | str = CMS_signed_get0_data_by_OBJ(si, | 76 | str = CMS_signed_get0_data_by_OBJ(si, |
| 75 | OBJ_nid2obj | 77 | OBJ_nid2obj(NID_id_smime_aa_receiptRequest), -3, V_ASN1_SEQUENCE); |
| 76 | (NID_id_smime_aa_receiptRequest), -3, | ||
| 77 | V_ASN1_SEQUENCE); | ||
| 78 | if (!str) | 78 | if (!str) |
| 79 | return 0; | 79 | return 0; |
| 80 | 80 | ||
| @@ -85,14 +85,13 @@ int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr) | |||
| 85 | *prr = rr; | 85 | *prr = rr; |
| 86 | else | 86 | else |
| 87 | CMS_ReceiptRequest_free(rr); | 87 | CMS_ReceiptRequest_free(rr); |
| 88 | |||
| 88 | return 1; | 89 | return 1; |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, | 92 | CMS_ReceiptRequest * |
| 92 | int allorfirst, | 93 | CMS_ReceiptRequest_create0(unsigned char *id, int idlen, int allorfirst, |
| 93 | STACK_OF(GENERAL_NAMES) | 94 | STACK_OF(GENERAL_NAMES) *receiptList, STACK_OF(GENERAL_NAMES) *receiptsTo) |
| 94 | *receiptList, STACK_OF(GENERAL_NAMES) | ||
| 95 | *receiptsTo) | ||
| 96 | { | 95 | { |
| 97 | CMS_ReceiptRequest *rr = NULL; | 96 | CMS_ReceiptRequest *rr = NULL; |
| 98 | 97 | ||
| @@ -127,10 +126,10 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen, | |||
| 127 | err: | 126 | err: |
| 128 | CMS_ReceiptRequest_free(rr); | 127 | CMS_ReceiptRequest_free(rr); |
| 129 | return NULL; | 128 | return NULL; |
| 130 | |||
| 131 | } | 129 | } |
| 132 | 130 | ||
| 133 | int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) | 131 | int |
| 132 | CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) | ||
| 134 | { | 133 | { |
| 135 | unsigned char *rrder = NULL; | 134 | unsigned char *rrder = NULL; |
| 136 | int rrderlen, r = 0; | 135 | int rrderlen, r = 0; |
| @@ -140,7 +139,7 @@ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) | |||
| 140 | goto merr; | 139 | goto merr; |
| 141 | 140 | ||
| 142 | if (!CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_receiptRequest, | 141 | if (!CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_receiptRequest, |
| 143 | V_ASN1_SEQUENCE, rrder, rrderlen)) | 142 | V_ASN1_SEQUENCE, rrder, rrderlen)) |
| 144 | goto merr; | 143 | goto merr; |
| 145 | 144 | ||
| 146 | r = 1; | 145 | r = 1; |
| @@ -152,14 +151,12 @@ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr) | |||
| 152 | OPENSSL_free(rrder); | 151 | OPENSSL_free(rrder); |
| 153 | 152 | ||
| 154 | return r; | 153 | return r; |
| 155 | |||
| 156 | } | 154 | } |
| 157 | 155 | ||
| 158 | void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, | 156 | void |
| 159 | ASN1_STRING **pcid, | 157 | CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, ASN1_STRING **pcid, |
| 160 | int *pallorfirst, | 158 | int *pallorfirst, STACK_OF(GENERAL_NAMES) **plist, |
| 161 | STACK_OF(GENERAL_NAMES) **plist, | 159 | STACK_OF(GENERAL_NAMES) **prto) |
| 162 | STACK_OF(GENERAL_NAMES) **prto) | ||
| 163 | { | 160 | { |
| 164 | if (pcid) | 161 | if (pcid) |
| 165 | *pcid = rr->signedContentIdentifier; | 162 | *pcid = rr->signedContentIdentifier; |
| @@ -180,40 +177,46 @@ void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr, | |||
| 180 | 177 | ||
| 181 | /* Digest a SignerInfo structure for msgSigDigest attribute processing */ | 178 | /* Digest a SignerInfo structure for msgSigDigest attribute processing */ |
| 182 | 179 | ||
| 183 | static int cms_msgSigDigest(CMS_SignerInfo *si, | 180 | static int |
| 184 | unsigned char *dig, unsigned int *diglen) | 181 | cms_msgSigDigest(CMS_SignerInfo *si, unsigned char *dig, unsigned int *diglen) |
| 185 | { | 182 | { |
| 186 | const EVP_MD *md; | 183 | const EVP_MD *md; |
| 184 | |||
| 187 | md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm); | 185 | md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm); |
| 188 | if (md == NULL) | 186 | if (md == NULL) |
| 189 | return 0; | 187 | return 0; |
| 190 | if (!ASN1_item_digest(ASN1_ITEM_rptr(CMS_Attributes_Verify), md, | 188 | if (!ASN1_item_digest(ASN1_ITEM_rptr(CMS_Attributes_Verify), md, |
| 191 | si->signedAttrs, dig, diglen)) | 189 | si->signedAttrs, dig, diglen)) |
| 192 | return 0; | 190 | return 0; |
| 191 | |||
| 193 | return 1; | 192 | return 1; |
| 194 | } | 193 | } |
| 195 | 194 | ||
| 196 | /* Add a msgSigDigest attribute to a SignerInfo */ | 195 | /* Add a msgSigDigest attribute to a SignerInfo */ |
| 197 | 196 | ||
| 198 | int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src) | 197 | int |
| 198 | cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src) | ||
| 199 | { | 199 | { |
| 200 | unsigned char dig[EVP_MAX_MD_SIZE]; | 200 | unsigned char dig[EVP_MAX_MD_SIZE]; |
| 201 | unsigned int diglen; | 201 | unsigned int diglen; |
| 202 | |||
| 202 | if (!cms_msgSigDigest(src, dig, &diglen)) { | 203 | if (!cms_msgSigDigest(src, dig, &diglen)) { |
| 203 | CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, CMS_R_MSGSIGDIGEST_ERROR); | 204 | CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, CMS_R_MSGSIGDIGEST_ERROR); |
| 204 | return 0; | 205 | return 0; |
| 205 | } | 206 | } |
| 206 | if (!CMS_signed_add1_attr_by_NID(dest, NID_id_smime_aa_msgSigDigest, | 207 | if (!CMS_signed_add1_attr_by_NID(dest, NID_id_smime_aa_msgSigDigest, |
| 207 | V_ASN1_OCTET_STRING, dig, diglen)) { | 208 | V_ASN1_OCTET_STRING, dig, diglen)) { |
| 208 | CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, ERR_R_MALLOC_FAILURE); | 209 | CMSerr(CMS_F_CMS_MSGSIGDIGEST_ADD1, ERR_R_MALLOC_FAILURE); |
| 209 | return 0; | 210 | return 0; |
| 210 | } | 211 | } |
| 212 | |||
| 211 | return 1; | 213 | return 1; |
| 212 | } | 214 | } |
| 213 | 215 | ||
| 214 | /* Verify signed receipt after it has already passed normal CMS verify */ | 216 | /* Verify signed receipt after it has already passed normal CMS verify */ |
| 215 | 217 | ||
| 216 | int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | 218 | int |
| 219 | cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | ||
| 217 | { | 220 | { |
| 218 | int r = 0, i; | 221 | int r = 0, i; |
| 219 | CMS_ReceiptRequest *rr = NULL; | 222 | CMS_ReceiptRequest *rr = NULL; |
| @@ -274,9 +277,7 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | |||
| 274 | /* Get msgSigDigest value and compare */ | 277 | /* Get msgSigDigest value and compare */ |
| 275 | 278 | ||
| 276 | msig = CMS_signed_get0_data_by_OBJ(si, | 279 | msig = CMS_signed_get0_data_by_OBJ(si, |
| 277 | OBJ_nid2obj | 280 | OBJ_nid2obj(NID_id_smime_aa_msgSigDigest), -3, V_ASN1_OCTET_STRING); |
| 278 | (NID_id_smime_aa_msgSigDigest), -3, | ||
| 279 | V_ASN1_OCTET_STRING); | ||
| 280 | 281 | ||
| 281 | if (!msig) { | 282 | if (!msig) { |
| 282 | CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_MSGSIGDIGEST); | 283 | CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_MSGSIGDIGEST); |
| @@ -302,8 +303,7 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | |||
| 302 | /* Compare content types */ | 303 | /* Compare content types */ |
| 303 | 304 | ||
| 304 | octype = CMS_signed_get0_data_by_OBJ(osi, | 305 | octype = CMS_signed_get0_data_by_OBJ(osi, |
| 305 | OBJ_nid2obj(NID_pkcs9_contentType), | 306 | OBJ_nid2obj(NID_pkcs9_contentType), -3, V_ASN1_OBJECT); |
| 306 | -3, V_ASN1_OBJECT); | ||
| 307 | if (!octype) { | 307 | if (!octype) { |
| 308 | CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_CONTENT_TYPE); | 308 | CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_NO_CONTENT_TYPE); |
| 309 | goto err; | 309 | goto err; |
| @@ -324,7 +324,7 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | |||
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | if (ASN1_STRING_cmp(rr->signedContentIdentifier, | 326 | if (ASN1_STRING_cmp(rr->signedContentIdentifier, |
| 327 | rct->signedContentIdentifier)) { | 327 | rct->signedContentIdentifier)) { |
| 328 | CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_CONTENTIDENTIFIER_MISMATCH); | 328 | CMSerr(CMS_F_CMS_RECEIPT_VERIFY, CMS_R_CONTENTIDENTIFIER_MISMATCH); |
| 329 | goto err; | 329 | goto err; |
| 330 | } | 330 | } |
| @@ -335,7 +335,6 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | |||
| 335 | CMS_ReceiptRequest_free(rr); | 335 | CMS_ReceiptRequest_free(rr); |
| 336 | M_ASN1_free_of(rct, CMS_Receipt); | 336 | M_ASN1_free_of(rct, CMS_Receipt); |
| 337 | return r; | 337 | return r; |
| 338 | |||
| 339 | } | 338 | } |
| 340 | 339 | ||
| 341 | /* | 340 | /* |
| @@ -343,7 +342,8 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms) | |||
| 343 | * SignedData ContentInfo. | 342 | * SignedData ContentInfo. |
| 344 | */ | 343 | */ |
| 345 | 344 | ||
| 346 | ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si) | 345 | ASN1_OCTET_STRING * |
| 346 | cms_encode_Receipt(CMS_SignerInfo *si) | ||
| 347 | { | 347 | { |
| 348 | CMS_Receipt rct; | 348 | CMS_Receipt rct; |
| 349 | CMS_ReceiptRequest *rr = NULL; | 349 | CMS_ReceiptRequest *rr = NULL; |
| @@ -362,8 +362,7 @@ ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si) | |||
| 362 | /* Get original content type */ | 362 | /* Get original content type */ |
| 363 | 363 | ||
| 364 | ctype = CMS_signed_get0_data_by_OBJ(si, | 364 | ctype = CMS_signed_get0_data_by_OBJ(si, |
| 365 | OBJ_nid2obj(NID_pkcs9_contentType), | 365 | OBJ_nid2obj(NID_pkcs9_contentType), -3, V_ASN1_OBJECT); |
| 366 | -3, V_ASN1_OBJECT); | ||
| 367 | if (!ctype) { | 366 | if (!ctype) { |
| 368 | CMSerr(CMS_F_CMS_ENCODE_RECEIPT, CMS_R_NO_CONTENT_TYPE); | 367 | CMSerr(CMS_F_CMS_ENCODE_RECEIPT, CMS_R_NO_CONTENT_TYPE); |
| 369 | goto err; | 368 | goto err; |
