6 int add_signed_time(si)
9 ASN1_UTCTIME *sign_time;
11 /* The last parameter is the amount to add/subtract from the current
12 * time (in seconds) */
13 sign_time=X509_gmtime_adj(NULL,0);
14 PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime,
15 V_ASN1_UTCTIME,(char *)sign_time);
19 ASN1_UTCTIME *get_signed_time(si)
20 PKCS7_SIGNER_INFO *si;
25 so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime);
26 if (so->type == V_ASN1_UTCTIME)
33 static int signed_string_nid= -1;
35 int add_signed_string(si,str)
36 PKCS7_SIGNER_INFO *si;
39 ASN1_OCTET_STRING *os;
41 /* To a an object of OID 1.2.3.4.5, which is an octet string */
42 if (signed_string_nid == -1)
44 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
45 os=ASN1_OCTET_STRING_new();
46 ASN1_OCTET_STRING_set(os,str,strlen(str));
47 /* When we add, we do not free */
48 PKCS7_add_signed_attribute(si,signed_string_nid,
49 V_ASN1_OCTET_STRING,(char *)os);
52 int get_signed_string(si,buf,len)
53 PKCS7_SIGNER_INFO *si;
58 ASN1_OCTET_STRING *os;
61 if (signed_string_nid == -1)
63 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
65 so=PKCS7_get_signed_attribute(si,signed_string_nid);
68 if (so->type == V_ASN1_OCTET_STRING)
70 os=so->value.octet_string;
74 memcpy(buf,os->data,i);
81 static signed_seq2string_nid= -1;
82 /* ########################################### */
83 int add_signed_seq2string(si,str1,str2)
84 PKCS7_SIGNER_INFO *si;
87 /* To add an object of OID 1.9.999, which is a sequence containing
91 ASN1_OCTET_STRING *os1,*os2;
96 if (signed_seq2string_nid == -1)
97 signed_seq2string_nid=
98 OBJ_create("1.9.9999","OID_example","Our example OID");
100 os1=ASN1_OCTET_STRING_new();
101 os2=ASN1_OCTET_STRING_new();
102 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
103 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
104 i =i2d_ASN1_OCTET_STRING(os1,NULL);
105 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
106 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
110 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
111 i2d_ASN1_OCTET_STRING(os1,&p);
112 i2d_ASN1_OCTET_STRING(os2,&p);
114 seq=ASN1_STRING_new();
115 ASN1_STRING_set(seq,data,total);
117 ASN1_OCTET_STRING_free(os1);
118 ASN1_OCTET_STRING_free(os2);
120 PKCS7_add_signed_attribute(si,signed_seq2string_nid,
121 V_ASN1_SEQUENCE,(char *)seq);
125 /* For this case, I will malloc the return strings */
126 int get_signed_seq2string(si,str1,str2)
127 PKCS7_SIGNER_INFO *si;
133 if (signed_seq2string_nid == -1)
134 signed_seq2string_nid=
135 OBJ_create("1.9.9999","OID_example","Our example OID");
137 so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
138 if (so && (so->type == V_ASN1_SEQUENCE))
143 ASN1_OCTET_STRING *os1,*os2;
145 s=so->value.sequence;
146 c.p=ASN1_STRING_data(s);
147 c.max=c.p+ASN1_STRING_length(s);
148 if (!asn1_GetSequence(&c,&length)) goto err;
149 /* Length is the length of the seqence */
152 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
157 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
161 if (!asn1_Finish(&c)) goto err;
162 *str1=malloc(os1->length+1);
163 *str2=malloc(os2->length+1);
164 memcpy(*str1,os1->data,os1->length);
165 memcpy(*str2,os2->data,os2->length);
166 (*str1)[os1->length]='\0';
167 (*str2)[os2->length]='\0';
168 ASN1_OCTET_STRING_free(os1);
169 ASN1_OCTET_STRING_free(os2);
177 /* #######################################
178 * THE OTHER WAY TO DO THINGS
179 * #######################################
181 X509_ATTRIBUTE *create_time()
183 ASN1_UTCTIME *sign_time;
186 /* The last parameter is the amount to add/subtract from the current
187 * time (in seconds) */
188 sign_time=X509_gmtime_adj(NULL,0);
189 ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime,
190 V_ASN1_UTCTIME,(char *)sign_time);
194 ASN1_UTCTIME *sk_get_time(sk)
199 PKCS7_SIGNER_INFO si;
202 so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime);
203 if (so->type == V_ASN1_UTCTIME)
205 ut=so->value.utctime;
210 X509_ATTRIBUTE *create_string(si,str)
213 ASN1_OCTET_STRING *os;
216 /* To a an object of OID 1.2.3.4.5, which is an octet string */
217 if (signed_string_nid == -1)
219 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
220 os=ASN1_OCTET_STRING_new();
221 ASN1_OCTET_STRING_set(os,str,strlen(str));
222 /* When we add, we do not free */
223 ret=X509_ATTRIBUTE_create(signed_string_nid,
224 V_ASN1_OCTET_STRING,(char *)os);
228 int sk_get_string(sk,buf,len)
234 ASN1_OCTET_STRING *os;
236 PKCS7_SIGNER_INFO si;
240 if (signed_string_nid == -1)
242 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
244 so=PKCS7_get_signed_attribute(&si,signed_string_nid);
247 if (so->type == V_ASN1_OCTET_STRING)
249 os=so->value.octet_string;
253 memcpy(buf,os->data,i);
260 X509_ATTRIBUTE *add_seq2string(si,str1,str2)
261 PKCS7_SIGNER_INFO *si;
264 /* To add an object of OID 1.9.999, which is a sequence containing
268 ASN1_OCTET_STRING *os1,*os2;
274 if (signed_seq2string_nid == -1)
275 signed_seq2string_nid=
276 OBJ_create("1.9.9999","OID_example","Our example OID");
278 os1=ASN1_OCTET_STRING_new();
279 os2=ASN1_OCTET_STRING_new();
280 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
281 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
282 i =i2d_ASN1_OCTET_STRING(os1,NULL);
283 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
284 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
288 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
289 i2d_ASN1_OCTET_STRING(os1,&p);
290 i2d_ASN1_OCTET_STRING(os2,&p);
292 seq=ASN1_STRING_new();
293 ASN1_STRING_set(seq,data,total);
295 ASN1_OCTET_STRING_free(os1);
296 ASN1_OCTET_STRING_free(os2);
298 ret=X509_ATTRIBUTE_create(signed_seq2string_nid,
299 V_ASN1_SEQUENCE,(char *)seq);
303 /* For this case, I will malloc the return strings */
304 int sk_get_seq2string(sk,str1,str2)
310 PKCS7_SIGNER_INFO si;
312 if (signed_seq2string_nid == -1)
313 signed_seq2string_nid=
314 OBJ_create("1.9.9999","OID_example","Our example OID");
318 so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
319 if (so->type == V_ASN1_SEQUENCE)
324 ASN1_OCTET_STRING *os1,*os2;
326 s=so->value.sequence;
327 c.p=ASN1_STRING_data(s);
328 c.max=c.p+ASN1_STRING_length(s);
329 if (!asn1_GetSequence(&c,&length)) goto err;
330 /* Length is the length of the seqence */
333 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
338 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
342 if (!asn1_Finish(&c)) goto err;
343 *str1=malloc(os1->length+1);
344 *str2=malloc(os2->length+1);
345 memcpy(*str1,os1->data,os1->length);
346 memcpy(*str2,os2->data,os2->length);
347 (*str1)[os1->length]='\0';
348 (*str2)[os2->length]='\0';
349 ASN1_OCTET_STRING_free(os1);
350 ASN1_OCTET_STRING_free(os2);