OLD | NEW |
1 /* crypto/cms/cms_io.c */ | 1 /* crypto/cms/cms_io.c */ |
2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 * project. | 3 * project. |
4 */ | 4 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 * ==================================================================== | 51 * ==================================================================== |
52 */ | 52 */ |
53 | 53 |
54 #include <openssl/asn1t.h> | 54 #include <openssl/asn1t.h> |
55 #include <openssl/x509.h> | 55 #include <openssl/x509.h> |
56 #include <openssl/err.h> | 56 #include <openssl/err.h> |
57 #include <openssl/pem.h> | 57 #include <openssl/pem.h> |
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) |
| 62 { |
| 63 ASN1_OCTET_STRING **pos; |
| 64 pos = CMS_get0_content(cms); |
| 65 if (!pos) |
| 66 return 0; |
| 67 if (!*pos) |
| 68 *pos = ASN1_OCTET_STRING_new(); |
| 69 if (*pos) |
| 70 { |
| 71 (*pos)->flags |= ASN1_STRING_FLAG_NDEF; |
| 72 (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; |
| 73 *boundary = &(*pos)->data; |
| 74 return 1; |
| 75 } |
| 76 CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE); |
| 77 return 0; |
| 78 } |
| 79 |
61 CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) | 80 CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) |
62 { | 81 { |
63 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 82 return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); |
64 } | 83 } |
65 | 84 |
66 int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms) | 85 int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms) |
67 { | 86 { |
68 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 87 return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); |
69 } | 88 } |
70 | 89 |
71 IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) | 90 IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) |
72 | 91 |
73 /* Callback for int_smime_write_ASN1 */ | 92 BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) |
74 | |
75 static int cms_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |
76 » » » » » const ASN1_ITEM *it) | |
77 { | 93 { |
78 » CMS_ContentInfo *cms = (CMS_ContentInfo *)val; | 94 » return BIO_new_NDEF(out, (ASN1_VALUE *)cms, |
79 » BIO *tmpbio, *cmsbio; | 95 » » » » ASN1_ITEM_rptr(CMS_ContentInfo)); |
80 » int r = 0; | |
81 | |
82 » if (!(flags & SMIME_DETACHED)) | |
83 » » { | |
84 » » SMIME_crlf_copy(data, out, flags); | |
85 » » return 1; | |
86 » » } | |
87 | |
88 » /* Let CMS code prepend any needed BIOs */ | |
89 | |
90 » cmsbio = CMS_dataInit(cms, out); | |
91 | |
92 » if (!cmsbio) | |
93 » » return 0; | |
94 | |
95 » /* Copy data across, passing through filter BIOs for processing */ | |
96 » SMIME_crlf_copy(data, cmsbio, flags); | |
97 | |
98 » /* Finalize structure */ | |
99 » if (CMS_dataFinal(cms, cmsbio) <= 0) | |
100 » » goto err; | |
101 | |
102 » r = 1; | |
103 | |
104 » err: | |
105 | |
106 » /* Now remove any digests prepended to the BIO */ | |
107 | |
108 » while (cmsbio != out) | |
109 » » { | |
110 » » tmpbio = BIO_pop(cmsbio); | |
111 » » BIO_free(cmsbio); | |
112 » » cmsbio = tmpbio; | |
113 » » } | |
114 | |
115 » return 1; | |
116 | |
117 } | 96 } |
118 | 97 |
| 98 /* CMS wrappers round generalised stream and MIME routines */ |
| 99 |
| 100 int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) |
| 101 { |
| 102 return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags, |
| 103 ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 104 } |
| 105 |
| 106 int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) |
| 107 { |
| 108 return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) cms, in, flags, |
| 109 "CMS", |
| 110 ASN1_ITEM_rptr(CMS_ContentInfo)); |
| 111 } |
119 | 112 |
120 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) | 113 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) |
121 { | 114 { |
122 STACK_OF(X509_ALGOR) *mdalgs; | 115 STACK_OF(X509_ALGOR) *mdalgs; |
123 int ctype_nid = OBJ_obj2nid(cms->contentType); | 116 int ctype_nid = OBJ_obj2nid(cms->contentType); |
124 int econt_nid = OBJ_obj2nid(CMS_get0_eContentType(cms)); | 117 int econt_nid = OBJ_obj2nid(CMS_get0_eContentType(cms)); |
125 if (ctype_nid == NID_pkcs7_signed) | 118 if (ctype_nid == NID_pkcs7_signed) |
126 mdalgs = cms->d.signedData->digestAlgorithms; | 119 mdalgs = cms->d.signedData->digestAlgorithms; |
127 else | 120 else |
128 mdalgs = NULL; | 121 mdalgs = NULL; |
129 | 122 |
130 » return int_smime_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, | 123 » return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, |
131 ctype_nid, econt_nid, mdalgs, | 124 ctype_nid, econt_nid, mdalgs, |
132 cms_output_data, | |
133 ASN1_ITEM_rptr(CMS_ContentInfo)); | 125 ASN1_ITEM_rptr(CMS_ContentInfo)); |
134 } | 126 } |
135 | 127 |
136 CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont) | 128 CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont) |
137 { | 129 { |
138 return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, | 130 return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, |
139 ASN1_ITEM_rptr(CMS_ContentInfo)); | 131 ASN1_ITEM_rptr(CMS_ContentInfo)); |
140 } | 132 } |
| 133 |
OLD | NEW |