2 * Copyright (C) 2003-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #include <gnutls_int.h>
26 #include <gnutls_datum.h>
27 #include <gnutls_global.h>
28 #include <gnutls_errors.h>
32 #include <gnutls_x509.h>
35 * gnutls_x509_crl_init:
36 * @crl: The structure to be initialized
38 * This function will initialize a CRL structure. CRL stands for
39 * Certificate Revocation List. A revocation list usually contains
40 * lists of certificate serial numbers that have been revoked by an
41 * Authority. The revocation lists are always signed with the
42 * authority's private key.
44 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
45 * negative error value.
48 gnutls_x509_crl_init (gnutls_x509_crl_t
* crl
)
50 *crl
= gnutls_calloc (1, sizeof (gnutls_x509_crl_int
));
54 int result
= asn1_create_element (_gnutls_get_pkix (),
55 "PKIX1.CertificateList",
57 if (result
!= ASN1_SUCCESS
)
61 return _gnutls_asn2err (result
);
63 return 0; /* success */
65 return GNUTLS_E_MEMORY_ERROR
;
69 * gnutls_x509_crl_deinit:
70 * @crl: The structure to be initialized
72 * This function will deinitialize a CRL structure.
75 gnutls_x509_crl_deinit (gnutls_x509_crl_t crl
)
81 asn1_delete_structure (&crl
->crl
);
87 * gnutls_x509_crl_import:
88 * @crl: The structure to store the parsed CRL.
89 * @data: The DER or PEM encoded CRL.
90 * @format: One of DER or PEM
92 * This function will convert the given DER or PEM encoded CRL
93 * to the native #gnutls_x509_crl_t format. The output will be stored in 'crl'.
95 * If the CRL is PEM encoded it should have a header of "X509 CRL".
97 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
98 * negative error value.
101 gnutls_x509_crl_import (gnutls_x509_crl_t crl
,
102 const gnutls_datum_t
* data
,
103 gnutls_x509_crt_fmt_t format
)
105 int result
= 0, need_free
= 0;
106 gnutls_datum_t _data
;
108 _data
.data
= data
->data
;
109 _data
.size
= data
->size
;
114 return GNUTLS_E_INVALID_REQUEST
;
117 /* If the CRL is in PEM format then decode it
119 if (format
== GNUTLS_X509_FMT_PEM
)
121 result
= _gnutls_fbase64_decode (PEM_CRL
, data
->data
, data
->size
, &_data
);
133 result
= asn1_der_decoding (&crl
->crl
, _data
.data
, _data
.size
, NULL
);
134 if (result
!= ASN1_SUCCESS
)
136 result
= _gnutls_asn2err (result
);
142 _gnutls_free_datum (&_data
);
148 _gnutls_free_datum (&_data
);
154 * gnutls_x509_crl_get_issuer_dn:
155 * @crl: should contain a gnutls_x509_crl_t structure
156 * @buf: a pointer to a structure to hold the peer's name (may be null)
157 * @sizeof_buf: initially holds the size of @buf
159 * This function will copy the name of the CRL issuer in the provided
160 * buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as
161 * described in RFC4514. The output string will be ASCII or UTF-8
162 * encoded, depending on the certificate data.
164 * If buf is %NULL then only the size will be filled.
166 * Returns: %GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is
167 * not long enough, and in that case the sizeof_buf will be updated
168 * with the required size, and 0 on success.
172 gnutls_x509_crl_get_issuer_dn (const gnutls_x509_crl_t crl
, char *buf
,
178 return GNUTLS_E_INVALID_REQUEST
;
181 return _gnutls_x509_parse_dn (crl
->crl
,
182 "tbsCertList.issuer.rdnSequence",
187 * gnutls_x509_crl_get_issuer_dn_by_oid:
188 * @crl: should contain a gnutls_x509_crl_t structure
189 * @oid: holds an Object Identified in null terminated string
190 * @indx: In case multiple same OIDs exist in the RDN, this specifies which to send. Use (0) to get the first one.
191 * @raw_flag: If non-zero returns the raw DER data of the DN part.
192 * @buf: a pointer to a structure to hold the peer's name (may be null)
193 * @sizeof_buf: initially holds the size of @buf
195 * This function will extract the part of the name of the CRL issuer
196 * specified by the given OID. The output will be encoded as described
197 * in RFC4514. The output string will be ASCII or UTF-8 encoded,
198 * depending on the certificate data.
200 * Some helper macros with popular OIDs can be found in gnutls/x509.h
201 * If raw flag is (0), this function will only return known OIDs as
202 * text. Other OIDs will be DER encoded, as described in RFC4514 -- in
203 * hex format with a '#' prefix. You can check about known OIDs
204 * using gnutls_x509_dn_oid_known().
206 * If buf is null then only the size will be filled.
208 * Returns: %GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is
209 * not long enough, and in that case the sizeof_buf will be updated
210 * with the required size, and 0 on success.
213 gnutls_x509_crl_get_issuer_dn_by_oid (gnutls_x509_crl_t crl
,
214 const char *oid
, int indx
,
215 unsigned int raw_flag
, void *buf
,
221 return GNUTLS_E_INVALID_REQUEST
;
224 return _gnutls_x509_parse_dn_oid (crl
->crl
,
225 "tbsCertList.issuer.rdnSequence",
226 oid
, indx
, raw_flag
, buf
, sizeof_buf
);
230 * gnutls_x509_crl_get_dn_oid:
231 * @crl: should contain a gnutls_x509_crl_t structure
232 * @indx: Specifies which DN OID to send. Use (0) to get the first one.
233 * @oid: a pointer to a structure to hold the name (may be null)
234 * @sizeof_oid: initially holds the size of 'oid'
236 * This function will extract the requested OID of the name of the CRL
237 * issuer, specified by the given index.
239 * If oid is null then only the size will be filled.
241 * Returns: %GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is
242 * not long enough, and in that case the sizeof_oid will be updated
243 * with the required size. On success 0 is returned.
246 gnutls_x509_crl_get_dn_oid (gnutls_x509_crl_t crl
,
247 int indx
, void *oid
, size_t * sizeof_oid
)
252 return GNUTLS_E_INVALID_REQUEST
;
255 return _gnutls_x509_get_dn_oid (crl
->crl
,
256 "tbsCertList.issuer.rdnSequence", indx
,
262 * gnutls_x509_crl_get_signature_algorithm:
263 * @crl: should contain a #gnutls_x509_crl_t structure
265 * This function will return a value of the #gnutls_sign_algorithm_t
266 * enumeration that is the signature algorithm.
268 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
269 * negative error value.
272 gnutls_x509_crl_get_signature_algorithm (gnutls_x509_crl_t crl
)
280 return GNUTLS_E_INVALID_REQUEST
;
283 /* Read the signature algorithm. Note that parameters are not
284 * read. They will be read from the issuer's certificate if needed.
288 _gnutls_x509_read_value (crl
->crl
, "signatureAlgorithm.algorithm",
297 result
= _gnutls_x509_oid2sign_algorithm ((const char *) sa
.data
);
299 _gnutls_free_datum (&sa
);
305 * gnutls_x509_crl_get_signature:
306 * @crl: should contain a gnutls_x509_crl_t structure
307 * @sig: a pointer where the signature part will be copied (may be null).
308 * @sizeof_sig: initially holds the size of @sig
310 * This function will extract the signature field of a CRL.
312 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
313 * negative error value. and a negative error code on error.
316 gnutls_x509_crl_get_signature (gnutls_x509_crl_t crl
,
317 char *sig
, size_t * sizeof_sig
)
326 return GNUTLS_E_INVALID_REQUEST
;
330 result
= asn1_read_value (crl
->crl
, "signature", NULL
, &len
);
332 if (result
!= ASN1_MEM_ERROR
)
335 return _gnutls_asn2err (result
);
342 return GNUTLS_E_CERTIFICATE_ERROR
;
347 if (*sizeof_sig
< (unsigned)len
)
349 *sizeof_sig
= bits
/ 8;
350 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
353 result
= asn1_read_value (crl
->crl
, "signature", sig
, &len
);
354 if (result
!= ASN1_SUCCESS
)
357 return _gnutls_asn2err (result
);
364 * gnutls_x509_crl_get_version:
365 * @crl: should contain a #gnutls_x509_crl_t structure
367 * This function will return the version of the specified CRL.
369 * Returns: The version number, or a negative error code on error.
372 gnutls_x509_crl_get_version (gnutls_x509_crl_t crl
)
380 return GNUTLS_E_INVALID_REQUEST
;
383 len
= sizeof (version
);
385 asn1_read_value (crl
->crl
, "tbsCertList.version", version
,
386 &len
)) != ASN1_SUCCESS
)
389 return _gnutls_asn2err (result
);
392 return (int) version
[0] + 1;
396 * gnutls_x509_crl_get_this_update:
397 * @crl: should contain a #gnutls_x509_crl_t structure
399 * This function will return the time this CRL was issued.
401 * Returns: when the CRL was issued, or (time_t)-1 on error.
404 gnutls_x509_crl_get_this_update (gnutls_x509_crl_t crl
)
412 return _gnutls_x509_get_time (crl
->crl
, "tbsCertList.thisUpdate", 0);
416 * gnutls_x509_crl_get_next_update:
417 * @crl: should contain a #gnutls_x509_crl_t structure
419 * This function will return the time the next CRL will be issued.
420 * This field is optional in a CRL so it might be normal to get an
423 * Returns: when the next CRL will be issued, or (time_t)-1 on error.
426 gnutls_x509_crl_get_next_update (gnutls_x509_crl_t crl
)
434 return _gnutls_x509_get_time (crl
->crl
, "tbsCertList.nextUpdate", 0);
438 * gnutls_x509_crl_get_crt_count:
439 * @crl: should contain a #gnutls_x509_crl_t structure
441 * This function will return the number of revoked certificates in the
444 * Returns: number of certificates, a negative error code on failure.
447 gnutls_x509_crl_get_crt_count (gnutls_x509_crl_t crl
)
455 return GNUTLS_E_INVALID_REQUEST
;
459 asn1_number_of_elements (crl
->crl
,
460 "tbsCertList.revokedCertificates", &count
);
462 if (result
!= ASN1_SUCCESS
)
465 return 0; /* no certificates */
472 * gnutls_x509_crl_get_crt_serial:
473 * @crl: should contain a #gnutls_x509_crl_t structure
474 * @indx: the index of the certificate to extract (starting from 0)
475 * @serial: where the serial number will be copied
476 * @serial_size: initially holds the size of serial
477 * @t: if non null, will hold the time this certificate was revoked
479 * This function will retrieve the serial number of the specified, by
480 * the index, revoked certificate.
482 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
483 * negative error value. and a negative error code on error.
486 gnutls_x509_crl_get_crt_serial (gnutls_x509_crl_t crl
, int indx
,
487 unsigned char *serial
,
488 size_t * serial_size
, time_t * t
)
491 int result
, _serial_size
;
492 char serial_name
[ASN1_MAX_NAME_SIZE
];
493 char date_name
[ASN1_MAX_NAME_SIZE
];
498 return GNUTLS_E_INVALID_REQUEST
;
501 snprintf (serial_name
, sizeof (serial_name
),
502 "tbsCertList.revokedCertificates.?%u.userCertificate", indx
+ 1);
503 snprintf (date_name
, sizeof (date_name
),
504 "tbsCertList.revokedCertificates.?%u.revocationDate", indx
+ 1);
506 _serial_size
= *serial_size
;
507 result
= asn1_read_value (crl
->crl
, serial_name
, serial
, &_serial_size
);
509 *serial_size
= _serial_size
;
510 if (result
!= ASN1_SUCCESS
)
513 if (result
== ASN1_ELEMENT_NOT_FOUND
)
514 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
;
515 return _gnutls_asn2err (result
);
520 *t
= _gnutls_x509_get_time (crl
->crl
, date_name
, 0);
527 * gnutls_x509_crl_get_raw_issuer_dn:
528 * @crl: should contain a gnutls_x509_crl_t structure
529 * @dn: will hold the starting point of the DN
531 * This function will return a pointer to the DER encoded DN structure
534 * Returns: a negative error code on error, and (0) on success.
539 gnutls_x509_crl_get_raw_issuer_dn (gnutls_x509_crl_t crl
,
542 ASN1_TYPE c2
= ASN1_TYPE_EMPTY
;
545 gnutls_datum_t crl_signed_data
;
550 return GNUTLS_E_INVALID_REQUEST
;
553 /* get the issuer of 'crl'
556 asn1_create_element (_gnutls_get_pkix (), "PKIX1.TBSCertList",
557 &c2
)) != ASN1_SUCCESS
)
560 return _gnutls_asn2err (result
);
564 _gnutls_x509_get_signed_data (crl
->crl
, "tbsCertList", &crl_signed_data
);
572 asn1_der_decoding (&c2
, crl_signed_data
.data
, crl_signed_data
.size
, NULL
);
573 if (result
!= ASN1_SUCCESS
)
575 /* couldn't decode DER */
577 asn1_delete_structure (&c2
);
578 result
= _gnutls_asn2err (result
);
583 asn1_der_decoding_startEnd (c2
, crl_signed_data
.data
,
584 crl_signed_data
.size
, "issuer",
587 if (result
!= ASN1_SUCCESS
)
590 result
= _gnutls_asn2err (result
);
594 len1
= end1
- start1
+ 1;
596 _gnutls_set_datum (dn
, &crl_signed_data
.data
[start1
], len1
);
601 asn1_delete_structure (&c2
);
602 _gnutls_free_datum (&crl_signed_data
);
607 * gnutls_x509_crl_export:
608 * @crl: Holds the revocation list
609 * @format: the format of output params. One of PEM or DER.
610 * @output_data: will contain a private key PEM or DER encoded
611 * @output_data_size: holds the size of output_data (and will
612 * be replaced by the actual size of parameters)
614 * This function will export the revocation list to DER or PEM format.
616 * If the buffer provided is not long enough to hold the output, then
617 * %GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.
619 * If the structure is PEM encoded, it will have a header
620 * of "BEGIN X509 CRL".
622 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
623 * negative error value. and a negative error code on failure.
626 gnutls_x509_crl_export (gnutls_x509_crl_t crl
,
627 gnutls_x509_crt_fmt_t format
, void *output_data
,
628 size_t * output_data_size
)
633 return GNUTLS_E_INVALID_REQUEST
;
636 return _gnutls_x509_export_int (crl
->crl
, format
, PEM_CRL
,
637 output_data
, output_data_size
);
641 * gnutls_x509_crl_export2:
642 * @crl: Holds the revocation list
643 * @format: the format of output params. One of PEM or DER.
644 * @out: will contain a private key PEM or DER encoded
646 * This function will export the revocation list to DER or PEM format.
648 * The output buffer is allocated using gnutls_malloc().
650 * If the structure is PEM encoded, it will have a header
651 * of "BEGIN X509 CRL".
653 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
654 * negative error value. and a negative error code on failure.
659 gnutls_x509_crl_export2 (gnutls_x509_crl_t crl
,
660 gnutls_x509_crt_fmt_t format
, gnutls_datum_t
*out
)
665 return GNUTLS_E_INVALID_REQUEST
;
668 return _gnutls_x509_export_int2 (crl
->crl
, format
, PEM_CRL
, out
);
672 * _gnutls_x509_crl_cpy - This function copies a gnutls_x509_crl_t structure
673 * @dest: The structure where to copy
674 * @src: The structure to be copied
676 * This function will copy an X.509 certificate structure.
678 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
679 * negative error value.
682 _gnutls_x509_crl_cpy (gnutls_x509_crl_t dest
, gnutls_x509_crl_t src
)
687 ret
= gnutls_x509_crl_export2 (src
, GNUTLS_X509_FMT_DER
, &tmp
);
689 return gnutls_assert_val(ret
);
691 ret
= gnutls_x509_crl_import (dest
, &tmp
, GNUTLS_X509_FMT_DER
);
693 gnutls_free (tmp
.data
);
706 _get_authority_key_id (gnutls_x509_crl_t cert
, ASN1_TYPE
*c2
,
707 unsigned int *critical
)
712 *c2
= ASN1_TYPE_EMPTY
;
717 return GNUTLS_E_INVALID_REQUEST
;
721 _gnutls_x509_crl_get_extension (cert
, "2.5.29.35", 0, &id
,
724 return gnutls_assert_val(ret
);
727 if (id
.size
== 0 || id
.data
== NULL
)
730 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
;
733 ret
= asn1_create_element
734 (_gnutls_get_pkix (), "PKIX1.AuthorityKeyIdentifier", c2
);
735 if (ret
!= ASN1_SUCCESS
)
738 _gnutls_free_datum (&id
);
739 return _gnutls_asn2err (ret
);
742 ret
= asn1_der_decoding (c2
, id
.data
, id
.size
, NULL
);
743 _gnutls_free_datum (&id
);
745 if (ret
!= ASN1_SUCCESS
)
748 asn1_delete_structure (c2
);
749 return _gnutls_asn2err (ret
);
756 * gnutls_x509_crl_get_authority_key_gn_serial:
757 * @crl: should contain a #gnutls_x509_crl_t structure
758 * @seq: specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.)
759 * @alt: is the place where the alternative name will be copied to
760 * @alt_size: holds the size of alt.
761 * @alt_type: holds the type of the alternative name (one of gnutls_x509_subject_alt_name_t).
762 * @serial: buffer to store the serial number (may be null)
763 * @serial_size: Holds the size of the serial field (may be null)
764 * @critical: will be non-zero if the extension is marked as critical (may be null)
766 * This function will return the X.509 authority key
767 * identifier when stored as a general name (authorityCertIssuer)
770 * Because more than one general names might be stored
771 * @seq can be used as a counter to request them all until
772 * %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
774 * Returns: Returns 0 on success, or an error code.
779 gnutls_x509_crl_get_authority_key_gn_serial (gnutls_x509_crl_t crl
,
783 unsigned int *alt_type
,
786 unsigned int *critical
)
788 int ret
, result
, len
;
791 ret
= _get_authority_key_id(crl
, &c2
, critical
);
793 return gnutls_assert_val(ret
);
796 _gnutls_parse_general_name (c2
, "authorityCertIssuer", seq
, alt
, alt_size
, alt_type
,
800 ret
= gnutls_assert_val(ret
);
807 result
= asn1_read_value (c2
, "authorityCertSerialNumber", serial
, &len
);
813 ret
= _gnutls_asn2err(result
);
822 asn1_delete_structure (&c2
);
829 * gnutls_x509_crl_get_authority_key_id:
830 * @crl: should contain a #gnutls_x509_crl_t structure
831 * @id: The place where the identifier will be copied
832 * @id_size: Holds the size of the result field.
833 * @critical: will be non-zero if the extension is marked as critical
836 * This function will return the CRL authority's key identifier. This
837 * is obtained by the X.509 Authority Key identifier extension field
838 * (2.5.29.35). Note that this function
839 * only returns the keyIdentifier field of the extension and
840 * %GNUTLS_E_X509_UNSUPPORTED_EXTENSION, if the extension contains
841 * the name and serial number of the certificate. In that case
842 * gnutls_x509_crl_get_authority_key_gn_serial() may be used.
844 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
845 * negative error code in case of an error.
850 gnutls_x509_crl_get_authority_key_id (gnutls_x509_crl_t crl
, void *id
,
852 unsigned int *critical
)
854 int result
, len
, ret
;
857 ret
= _get_authority_key_id(crl
, &c2
, critical
);
859 return gnutls_assert_val(ret
);
862 result
= asn1_read_value (c2
, "keyIdentifier", id
, &len
);
865 asn1_delete_structure (&c2
);
867 if (result
== ASN1_VALUE_NOT_FOUND
|| result
== ASN1_ELEMENT_NOT_FOUND
)
868 return gnutls_assert_val(GNUTLS_E_X509_UNSUPPORTED_EXTENSION
);
870 if (result
!= ASN1_SUCCESS
)
873 return _gnutls_asn2err (result
);
880 * gnutls_x509_crl_get_number:
881 * @crl: should contain a #gnutls_x509_crl_t structure
882 * @ret: The place where the number will be copied
883 * @ret_size: Holds the size of the result field.
884 * @critical: will be non-zero if the extension is marked as critical
887 * This function will return the CRL number extension. This is
888 * obtained by the CRL Number extension field (2.5.29.20).
890 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
891 * negative error code in case of an error.
896 gnutls_x509_crl_get_number (gnutls_x509_crl_t crl
, void *ret
,
897 size_t * ret_size
, unsigned int *critical
)
905 return GNUTLS_E_INVALID_REQUEST
;
910 memset (ret
, 0, *ret_size
);
915 _gnutls_x509_crl_get_extension (crl
, "2.5.29.20", 0, &id
,
921 if (id
.size
== 0 || id
.data
== NULL
)
924 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
;
927 result
= _gnutls_x509_ext_extract_number (ret
, ret_size
, id
.data
, id
.size
);
929 _gnutls_free_datum (&id
);
941 * gnutls_x509_crl_get_extension_oid:
942 * @crl: should contain a #gnutls_x509_crl_t structure
943 * @indx: Specifies which extension OID to send, use (0) to get the first one.
944 * @oid: a pointer to a structure to hold the OID (may be null)
945 * @sizeof_oid: initially holds the size of @oid
947 * This function will return the requested extension OID in the CRL.
948 * The extension OID will be stored as a string in the provided
951 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
952 * negative error code in case of an error. If your have reached the
953 * last extension available %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
959 gnutls_x509_crl_get_extension_oid (gnutls_x509_crl_t crl
, int indx
,
960 void *oid
, size_t * sizeof_oid
)
967 return GNUTLS_E_INVALID_REQUEST
;
970 result
= _gnutls_x509_crl_get_extension_oid (crl
, indx
, oid
, sizeof_oid
);
981 * gnutls_x509_crl_get_extension_info:
982 * @crl: should contain a #gnutls_x509_crl_t structure
983 * @indx: Specifies which extension OID to send, use (0) to get the first one.
984 * @oid: a pointer to a structure to hold the OID
985 * @sizeof_oid: initially holds the maximum size of @oid, on return
986 * holds actual size of @oid.
987 * @critical: output variable with critical flag, may be NULL.
989 * This function will return the requested extension OID in the CRL,
990 * and the critical flag for it. The extension OID will be stored as
991 * a string in the provided buffer. Use
992 * gnutls_x509_crl_get_extension_data() to extract the data.
994 * If the buffer provided is not long enough to hold the output, then
995 * *@sizeof_oid is updated and %GNUTLS_E_SHORT_MEMORY_BUFFER will be
998 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
999 * negative error code in case of an error. If your have reached the
1000 * last extension available %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
1006 gnutls_x509_crl_get_extension_info (gnutls_x509_crl_t crl
, int indx
,
1007 void *oid
, size_t * sizeof_oid
,
1008 unsigned int *critical
)
1011 char str_critical
[10];
1012 char name
[ASN1_MAX_NAME_SIZE
];
1018 return GNUTLS_E_INVALID_REQUEST
;
1021 snprintf (name
, sizeof (name
), "tbsCertList.crlExtensions.?%u.extnID",
1025 result
= asn1_read_value (crl
->crl
, name
, oid
, &len
);
1028 if (result
== ASN1_ELEMENT_NOT_FOUND
)
1029 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
;
1030 else if (result
!= ASN1_SUCCESS
)
1033 return _gnutls_asn2err (result
);
1036 snprintf (name
, sizeof (name
), "tbsCertList.crlExtensions.?%u.critical",
1038 len
= sizeof (str_critical
);
1039 result
= asn1_read_value (crl
->crl
, name
, str_critical
, &len
);
1040 if (result
!= ASN1_SUCCESS
)
1043 return _gnutls_asn2err (result
);
1048 if (str_critical
[0] == 'T')
1059 * gnutls_x509_crl_get_extension_data:
1060 * @crl: should contain a #gnutls_x509_crl_t structure
1061 * @indx: Specifies which extension OID to send. Use (0) to get the first one.
1062 * @data: a pointer to a structure to hold the data (may be null)
1063 * @sizeof_data: initially holds the size of @oid
1065 * This function will return the requested extension data in the CRL.
1066 * The extension data will be stored as a string in the provided
1069 * Use gnutls_x509_crl_get_extension_info() to extract the OID and
1070 * critical flag. Use gnutls_x509_crl_get_extension_info() instead,
1071 * if you want to get data indexed by the extension OID rather than
1074 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
1075 * negative error code in case of an error. If your have reached the
1076 * last extension available %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
1082 gnutls_x509_crl_get_extension_data (gnutls_x509_crl_t crl
, int indx
,
1083 void *data
, size_t * sizeof_data
)
1086 char name
[ASN1_MAX_NAME_SIZE
];
1091 return GNUTLS_E_INVALID_REQUEST
;
1094 snprintf (name
, sizeof (name
), "tbsCertList.crlExtensions.?%u.extnValue",
1098 result
= asn1_read_value (crl
->crl
, name
, data
, &len
);
1101 if (result
== ASN1_ELEMENT_NOT_FOUND
)
1102 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
;
1103 else if (result
< 0)
1106 return _gnutls_asn2err (result
);
1113 * gnutls_x509_crl_list_import2:
1114 * @crls: The structures to store the parsed crl list. Must not be initialized.
1115 * @size: It will contain the size of the list.
1116 * @data: The PEM encoded CRL.
1117 * @format: One of DER or PEM.
1118 * @flags: must be (0) or an OR'd sequence of gnutls_certificate_import_flags.
1120 * This function will convert the given PEM encoded CRL list
1121 * to the native gnutls_x509_crl_t format. The output will be stored
1122 * in @crls. They will be automatically initialized.
1124 * If the Certificate is PEM encoded it should have a header of "X509
1127 * Returns: the number of certificates read or a negative error value.
1132 gnutls_x509_crl_list_import2 (gnutls_x509_crl_t
** crls
,
1133 unsigned int * size
,
1134 const gnutls_datum_t
* data
,
1135 gnutls_x509_crt_fmt_t format
, unsigned int flags
)
1137 unsigned int init
= 1024;
1140 *crls
= gnutls_malloc(sizeof(gnutls_x509_crl_t
)*init
);
1144 return GNUTLS_E_MEMORY_ERROR
;
1147 ret
= gnutls_x509_crl_list_import(*crls
, &init
, data
, format
, GNUTLS_X509_CRT_LIST_IMPORT_FAIL_IF_EXCEED
);
1148 if (ret
== GNUTLS_E_SHORT_MEMORY_BUFFER
)
1150 *crls
= gnutls_realloc_fast(*crls
, sizeof(gnutls_x509_crl_t
)*init
);
1154 return GNUTLS_E_MEMORY_ERROR
;
1157 ret
= gnutls_x509_crl_list_import(*crls
, &init
, data
, format
, flags
);
1172 * gnutls_x509_crl_list_import:
1173 * @crls: The structures to store the parsed CRLs. Must not be initialized.
1174 * @crl_max: Initially must hold the maximum number of crls. It will be updated with the number of crls available.
1175 * @data: The PEM encoded CRLs
1176 * @format: One of DER or PEM.
1177 * @flags: must be (0) or an OR'd sequence of gnutls_certificate_import_flags.
1179 * This function will convert the given PEM encoded CRL list
1180 * to the native gnutls_x509_crl_t format. The output will be stored
1181 * in @crls. They will be automatically initialized.
1183 * If the Certificate is PEM encoded it should have a header of "X509 CRL".
1185 * Returns: the number of certificates read or a negative error value.
1190 gnutls_x509_crl_list_import (gnutls_x509_crl_t
* crls
,
1191 unsigned int *crl_max
,
1192 const gnutls_datum_t
* data
,
1193 gnutls_x509_crt_fmt_t format
, unsigned int flags
)
1198 int ret
, nocopy
= 0;
1199 unsigned int count
= 0, j
;
1201 if (format
== GNUTLS_X509_FMT_DER
)
1206 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
1209 count
= 1; /* import only the first one */
1211 ret
= gnutls_x509_crl_init (&crls
[0]);
1218 ret
= gnutls_x509_crl_import (crls
[0], data
, format
);
1229 /* move to the certificate
1231 ptr
= memmem (data
->data
, data
->size
,
1232 PEM_CRL_SEP
, sizeof (PEM_CRL_SEP
) - 1);
1236 return GNUTLS_E_BASE64_DECODING_ERROR
;
1243 if (count
>= *crl_max
)
1245 if (!(flags
& GNUTLS_X509_CRT_LIST_IMPORT_FAIL_IF_EXCEED
))
1253 ret
= gnutls_x509_crl_init (&crls
[count
]);
1260 tmp
.data
= (void *) ptr
;
1261 tmp
.size
= data
->size
- (ptr
- (char *) data
->data
);
1264 gnutls_x509_crl_import (crls
[count
], &tmp
, GNUTLS_X509_FMT_PEM
);
1272 /* now we move ptr after the pem header
1275 /* find the next certificate (if any)
1277 size
= data
->size
- (ptr
- (char *) data
->data
);
1281 ptr
= memmem (ptr
, size
, PEM_CRL_SEP
, sizeof (PEM_CRL_SEP
) - 1);
1288 while (ptr
!= NULL
);
1295 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
1298 for (j
= 0; j
< count
; j
++)
1299 gnutls_x509_crl_deinit (crls
[j
]);