OLD | NEW |
1 /* pk7_attr.c */ | 1 /* pk7_attr.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 2001. | 3 * project 2001. |
4 */ | 4 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2001-2004 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 * This product includes cryptographic software written by Eric Young | 53 * This product includes cryptographic software written by Eric Young |
54 * (eay@cryptsoft.com). This product includes software written by Tim | 54 * (eay@cryptsoft.com). This product includes software written by Tim |
55 * Hudson (tjh@cryptsoft.com). | 55 * Hudson (tjh@cryptsoft.com). |
56 * | 56 * |
57 */ | 57 */ |
58 | 58 |
59 #include <stdio.h> | 59 #include <stdio.h> |
60 #include <stdlib.h> | 60 #include <stdlib.h> |
61 #include <openssl/bio.h> | 61 #include <openssl/bio.h> |
62 #include <openssl/asn1.h> | 62 #include <openssl/asn1.h> |
| 63 #include <openssl/asn1t.h> |
63 #include <openssl/pem.h> | 64 #include <openssl/pem.h> |
64 #include <openssl/pkcs7.h> | 65 #include <openssl/pkcs7.h> |
65 #include <openssl/x509.h> | 66 #include <openssl/x509.h> |
66 #include <openssl/err.h> | 67 #include <openssl/err.h> |
67 | 68 |
68 int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) | 69 int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) |
69 { | 70 { |
70 ASN1_STRING *seq; | 71 ASN1_STRING *seq; |
71 unsigned char *p, *pp; | |
72 int len; | |
73 len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR, | |
74 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, | |
75 IS_SEQUENCE); | |
76 if(!(pp=(unsigned char *)OPENSSL_malloc(len))) { | |
77 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE)
; | |
78 return 0; | |
79 } | |
80 p=pp; | |
81 i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE, | |
82 V_ASN1_UNIVERSAL, IS_SEQUENCE); | |
83 if(!(seq = ASN1_STRING_new())) { | 72 if(!(seq = ASN1_STRING_new())) { |
84 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE)
; | 73 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE)
; |
85 return 0; | 74 return 0; |
86 } | 75 } |
87 » if(!ASN1_STRING_set (seq, pp, len)) { | 76 » seq->length = ASN1_item_i2d((ASN1_VALUE *)cap,&seq->data, |
88 » » PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE)
; | 77 » » » » ASN1_ITEM_rptr(X509_ALGORS)); |
89 » » return 0; | |
90 » } | |
91 » OPENSSL_free (pp); | |
92 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, | 78 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, |
93 V_ASN1_SEQUENCE, seq); | 79 V_ASN1_SEQUENCE, seq); |
94 } | 80 } |
95 | 81 |
96 STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) | 82 STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) |
97 { | 83 { |
98 ASN1_TYPE *cap; | 84 ASN1_TYPE *cap; |
99 const unsigned char *p; | 85 const unsigned char *p; |
100 | 86 |
101 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); | 87 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); |
102 if (!cap || (cap->type != V_ASN1_SEQUENCE)) | 88 if (!cap || (cap->type != V_ASN1_SEQUENCE)) |
103 return NULL; | 89 return NULL; |
104 p = cap->value.sequence->data; | 90 p = cap->value.sequence->data; |
105 » return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p, | 91 » return (STACK_OF(X509_ALGOR) *) |
106 » » » » » cap->value.sequence->length, | 92 » » ASN1_item_d2i(NULL, &p, cap->value.sequence->length, |
107 » » » » » d2i_X509_ALGOR, X509_ALGOR_free, | 93 » » » » ASN1_ITEM_rptr(X509_ALGORS)); |
108 » » » » » V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | |
109 } | 94 } |
110 | 95 |
111 /* Basic smime-capabilities OID and optional integer arg */ | 96 /* Basic smime-capabilities OID and optional integer arg */ |
112 int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) | 97 int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) |
113 { | 98 { |
114 X509_ALGOR *alg; | 99 X509_ALGOR *alg; |
115 | 100 |
116 if(!(alg = X509_ALGOR_new())) { | 101 if(!(alg = X509_ALGOR_new())) { |
117 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); | 102 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); |
118 return 0; | 103 return 0; |
(...skipping 13 matching lines...) Expand all Loading... |
132 if(!ASN1_INTEGER_set (nbit, arg)) { | 117 if(!ASN1_INTEGER_set (nbit, arg)) { |
133 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAIL
URE); | 118 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAIL
URE); |
134 return 0; | 119 return 0; |
135 } | 120 } |
136 alg->parameter->value.integer = nbit; | 121 alg->parameter->value.integer = nbit; |
137 alg->parameter->type = V_ASN1_INTEGER; | 122 alg->parameter->type = V_ASN1_INTEGER; |
138 } | 123 } |
139 sk_X509_ALGOR_push (sk, alg); | 124 sk_X509_ALGOR_push (sk, alg); |
140 return 1; | 125 return 1; |
141 } | 126 } |
| 127 |
| 128 int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid) |
| 129 { |
| 130 if (PKCS7_get_signed_attribute(si, NID_pkcs9_contentType)) |
| 131 return 0; |
| 132 if (!coid) |
| 133 coid = OBJ_nid2obj(NID_pkcs7_data); |
| 134 return PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, |
| 135 V_ASN1_OBJECT, coid); |
| 136 } |
| 137 |
| 138 int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t) |
| 139 { |
| 140 if (!t && !(t=X509_gmtime_adj(NULL,0))) |
| 141 { |
| 142 PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME, |
| 143 ERR_R_MALLOC_FAILURE); |
| 144 return 0; |
| 145 } |
| 146 return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime, |
| 147 V_ASN1_UTCTIME, t); |
| 148 } |
| 149 |
| 150 int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, |
| 151 const unsigned char *md, int mdlen) |
| 152 { |
| 153 ASN1_OCTET_STRING *os; |
| 154 os = ASN1_OCTET_STRING_new(); |
| 155 if (!os) |
| 156 return 0; |
| 157 if (!ASN1_STRING_set(os, md, mdlen) |
| 158 || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest, |
| 159 V_ASN1_OCTET_STRING, os)) |
| 160 { |
| 161 ASN1_OCTET_STRING_free(os); |
| 162 return 0; |
| 163 } |
| 164 return 1; |
| 165 } |
OLD | NEW |