diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_io.c')
| -rw-r--r-- | src/lib/libcrypto/cms/cms_io.c | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/src/lib/libcrypto/cms/cms_io.c b/src/lib/libcrypto/cms/cms_io.c index 1cb0264cc5..f8c1d45152 100644 --- a/src/lib/libcrypto/cms/cms_io.c +++ b/src/lib/libcrypto/cms/cms_io.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -58,76 +58,82 @@ | |||
| 58 | #include "cms.h" | 58 | #include "cms.h" |
| 59 | #include "cms_lcl.h" | 59 | #include "cms_lcl.h" |
| 60 | 60 | ||
| 61 | int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) | 61 | int |
| 62 | { | 62 | CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) |
| 63 | { | ||
| 63 | ASN1_OCTET_STRING **pos; | 64 | ASN1_OCTET_STRING **pos; |
| 65 | |||
| 64 | pos = CMS_get0_content(cms); | 66 | pos = CMS_get0_content(cms); |
| 65 | if (!pos) | 67 | if (!pos) |
| 66 | return 0; | 68 | return 0; |
| 67 | if (!*pos) | 69 | if (!*pos) |
| 68 | *pos = ASN1_OCTET_STRING_new(); | 70 | *pos = ASN1_OCTET_STRING_new(); |
| 69 | if (*pos) | 71 | if (*pos) { |
| 70 | { | ||
| 71 | (*pos)->flags |= ASN1_STRING_FLAG_NDEF; | 72 | (*pos)->flags |= ASN1_STRING_FLAG_NDEF; |
| 72 | (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; | 73 | (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; |
| 73 | *boundary = &(*pos)->data; | 74 | *boundary = &(*pos)->data; |
| 74 | return 1; | 75 | return 1; |
| 75 | } | 76 | } |
| 76 | CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE); | 77 | CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE); |
| 77 | return 0; | 78 | return 0; |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) | 81 | CMS_ContentInfo * |
| 81 | { | 82 | d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) |
| 83 | { | ||
| 82 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 84 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); |
| 83 | } | 85 | } |
| 84 | 86 | ||
| 85 | int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms) | 87 | int |
| 86 | { | 88 | i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms) |
| 89 | { | ||
| 87 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 90 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); |
| 88 | } | 91 | } |
| 89 | 92 | ||
| 90 | IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) | 93 | IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) |
| 91 | 94 | ||
| 92 | BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) | 95 | BIO * |
| 93 | { | 96 | BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) |
| 97 | { | ||
| 94 | return BIO_new_NDEF(out, (ASN1_VALUE *)cms, | 98 | return BIO_new_NDEF(out, (ASN1_VALUE *)cms, |
| 95 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 99 | ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 96 | } | 100 | } |
| 97 | 101 | ||
| 98 | /* CMS wrappers round generalised stream and MIME routines */ | 102 | /* CMS wrappers round generalised stream and MIME routines */ |
| 99 | 103 | ||
| 100 | int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) | 104 | int |
| 101 | { | 105 | i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) |
| 106 | { | ||
| 102 | return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags, | 107 | return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags, |
| 103 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 108 | ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 104 | } | 109 | } |
| 105 | 110 | ||
| 106 | int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) | 111 | int |
| 107 | { | 112 | PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) |
| 113 | { | ||
| 108 | return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) cms, in, flags, | 114 | return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) cms, in, flags, |
| 109 | "CMS", | 115 | "CMS", ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 110 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 116 | } |
| 111 | } | ||
| 112 | 117 | ||
| 113 | int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) | 118 | int |
| 114 | { | 119 | SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) |
| 120 | { | ||
| 115 | STACK_OF(X509_ALGOR) *mdalgs; | 121 | STACK_OF(X509_ALGOR) *mdalgs; |
| 116 | int ctype_nid = OBJ_obj2nid(cms->contentType); | 122 | int ctype_nid = OBJ_obj2nid(cms->contentType); |
| 117 | int econt_nid = OBJ_obj2nid(CMS_get0_eContentType(cms)); | 123 | int econt_nid = OBJ_obj2nid(CMS_get0_eContentType(cms)); |
| 124 | |||
| 118 | if (ctype_nid == NID_pkcs7_signed) | 125 | if (ctype_nid == NID_pkcs7_signed) |
| 119 | mdalgs = cms->d.signedData->digestAlgorithms; | 126 | mdalgs = cms->d.signedData->digestAlgorithms; |
| 120 | else | 127 | else |
| 121 | mdalgs = NULL; | 128 | mdalgs = NULL; |
| 122 | 129 | ||
| 123 | return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, | 130 | return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, |
| 124 | ctype_nid, econt_nid, mdalgs, | 131 | ctype_nid, econt_nid, mdalgs, ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 125 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 132 | } |
| 126 | } | ||
| 127 | 133 | ||
| 128 | CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont) | 134 | CMS_ContentInfo * |
| 129 | { | 135 | SMIME_read_CMS(BIO *bio, BIO **bcont) |
| 136 | { | ||
| 130 | return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, | 137 | return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, |
| 131 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 138 | ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 132 | } | 139 | } |
| 133 | |||
