| Top |
int
gnutls_x509_crt_init (gnutls_x509_crt_t *cert);
This function will initialize an X.509 certificate structure.
void
gnutls_x509_crt_deinit (gnutls_x509_crt_t cert);
This function will deinitialize a certificate structure.
void gnutls_x509_crt_set_flags (gnutls_x509_crt_t cert,unsigned flags);
This function will set flags for the specified certificate.
Currently this is useful for the GNUTLS_X509_CRT_FLAG_IGNORE_SANITY
which allows importing certificates even if they have known issues.
Since: 3.6.0
unsigned gnutls_x509_crt_equals (gnutls_x509_crt_t cert1,gnutls_x509_crt_t cert2);
unsigned gnutls_x509_crt_equals2 (gnutls_x509_crt_t cert1,const gnutls_datum_t *der);
int gnutls_x509_crt_import (gnutls_x509_crt_t cert,const gnutls_datum_t *data,gnutls_x509_crt_fmt_t format);
This function will convert the given DER or PEM encoded Certificate
to the native gnutls_x509_crt_t format. The output will be stored
in cert
.
If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or "CERTIFICATE".
int gnutls_x509_crt_list_import2 (gnutls_x509_crt_t **certs,unsigned int *size,const gnutls_datum_t *data,gnutls_x509_crt_fmt_t format,unsigned int flags);
This function will convert the given PEM encoded certificate list
to the native gnutls_x509_crt_t format. The output will be stored
in certs
which will be allocated and initialized.
If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or "CERTIFICATE".
To deinitialize certs
, you need to deinitialize each crt structure
independently, and use gnutls_free() at certs
.
certs |
Will hold the parsed certificate list. |
|
size |
It will contain the size of the list. |
|
data |
The PEM encoded certificate. |
|
format |
One of DER or PEM. |
|
flags |
must be (0) or an OR'd sequence of gnutls_certificate_import_flags. |
Since: 3.0
int gnutls_x509_crt_list_import (gnutls_x509_crt_t *certs,unsigned int *cert_max,const gnutls_datum_t *data,gnutls_x509_crt_fmt_t format,unsigned int flags);
This function will convert the given PEM encoded certificate list
to the native gnutls_x509_crt_t format. The output will be stored
in certs
. They will be automatically initialized.
The flag GNUTLS_X509_CRT_LIST_IMPORT_FAIL_IF_EXCEED will cause
import to fail if the certificates in the provided buffer are more
than the available structures. The GNUTLS_X509_CRT_LIST_FAIL_IF_UNSORTED
flag will cause the function to fail if the provided list is not
sorted from subject to issuer.
If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or "CERTIFICATE".
certs |
Indicates where the parsed list will be copied to. Must not be initialized. |
|
cert_max |
Initially must hold the maximum number of certs. It will be updated with the number of certs available. |
|
data |
The PEM encoded certificate. |
|
format |
One of DER or PEM. |
|
flags |
must be (0) or an OR'd sequence of gnutls_certificate_import_flags. |
int gnutls_x509_crt_import_url (gnutls_x509_crt_t crt,const char *url,unsigned int flags);
This function will import a certificate present in a PKCS11 token or any type of back-end that supports URLs.
In previous versions of gnutls this function was named gnutls_x509_crt_import_pkcs11_url, and the old name is an alias to this one.
crt |
A certificate of type gnutls_x509_crt_t |
|
url |
A PKCS 11 url |
|
flags |
One of GNUTLS_PKCS11_OBJ_* flags for PKCS11 URLs or zero otherwise |
Since: 3.4.0
int gnutls_x509_crt_list_import_url (gnutls_x509_crt_t **certs,unsigned int *size,const char *url,gnutls_pin_callback_t pin_fn,void *pin_fn_userdata,unsigned int flags);
This function will import a certificate chain present in a PKCS11 token
or any type of back-end that supports URLs. The certificates
must be deinitialized afterwards using gnutls_x509_crt_deinit()
and the returned pointer must be freed using gnutls_free().
The URI provided must be the first certificate in the chain; subsequent
certificates will be retrieved using gnutls_pkcs11_get_raw_issuer() or
equivalent functionality for the supported URI.
certs |
Will hold the allocated certificate list. |
|
size |
It will contain the size of the list. |
|
url |
A PKCS 11 url |
|
pin_fn |
a PIN callback if not globally set |
|
pin_fn_userdata |
parameter for the PIN callback |
|
flags |
One of GNUTLS_PKCS11_OBJ_* flags for PKCS11 URLs or zero otherwise |
Since: 3.6.3
int gnutls_x509_crt_export (gnutls_x509_crt_t cert,gnutls_x509_crt_fmt_t format,void *output_data,size_t *output_data_size);
This function will export the certificate to DER or PEM format.
If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.
If the structure is PEM encoded, it will have a header of "BEGIN CERTIFICATE".
int gnutls_x509_crt_export2 (gnutls_x509_crt_t cert,gnutls_x509_crt_fmt_t format,gnutls_datum_t *out);
This function will export the certificate to DER or PEM format.
The output buffer is allocated using gnutls_malloc().
If the structure is PEM encoded, it will have a header of "BEGIN CERTIFICATE".
cert |
Holds the certificate |
|
format |
the format of output params. One of PEM or DER. |
|
out |
will contain a certificate PEM or DER encoded |
Since: 3.1.3
int gnutls_x509_crt_get_private_key_usage_period (gnutls_x509_crt_t cert,time_t *activation,time_t *expiration,unsigned int *critical);
This function will return the expiration and activation times of the private key of the certificate. It relies on the PKIX extension 2.5.29.16 being present.
cert |
should contain a gnutls_x509_crt_t type |
|
activation |
The activation time |
|
expiration |
The expiration time |
|
critical |
the extension status |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
int gnutls_x509_crt_get_issuer_dn (gnutls_x509_crt_t cert,char *buf,size_t *buf_size);
This function will copy the name of the Certificate issuer in the provided buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
If buf
is null then only the size will be filled.
This function does not output a fully RFC4514 compliant string, if
that is required see gnutls_x509_crt_get_issuer_dn3().
cert |
should contain a gnutls_x509_crt_t type |
|
buf |
a pointer to a structure to hold the name (may be null) |
|
buf_size |
initially holds the size of |
GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not
long enough, and in that case the buf_size
will be updated
with the required size. GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE if
the DN does not exist, or another error value on error. On success 0 is returned.
int gnutls_x509_crt_get_issuer_dn2 (gnutls_x509_crt_t cert,gnutls_datum_t *dn);
This function will allocate buffer and copy the name of issuer of the Certificate. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
This function does not output a fully RFC4514 compliant string, if
that is required see gnutls_x509_crt_get_issuer_dn3().
cert |
should contain a gnutls_x509_crt_t type |
|
dn |
a pointer to a structure to hold the name; must be freed using |
Since: 3.1.10
int gnutls_x509_crt_get_issuer_dn3 (gnutls_x509_crt_t cert,gnutls_datum_t *dn,unsigned flags);
This function will allocate buffer and copy the name of issuer of the Certificate. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
When the flag GNUTLS_X509_DN_FLAG_COMPAT is specified, the output
format will match the format output by previous to 3.5.6 versions of GnuTLS
which was not not fully RFC4514-compliant.
cert |
should contain a gnutls_x509_crt_t type |
|
dn |
a pointer to a structure to hold the name; must be freed using |
|
flags |
zero or |
Since: 3.5.7
int gnutls_x509_crt_get_issuer_dn_oid (gnutls_x509_crt_t cert,unsigned indx,void *oid,size_t *oid_size);
This function will extract the OIDs of the name of the Certificate issuer specified by the given index.
If oid
is null then only the size will be filled. The oid
returned will be null terminated, although oid_size
will not
account for the trailing null.
cert |
should contain a gnutls_x509_crt_t type |
|
indx |
This specifies which OID to return. Use (0) to get the first one. |
|
oid |
a pointer to a buffer to hold the OID (may be null) |
|
oid_size |
initially holds the size of |
GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not
long enough, and in that case the buf_size
will be updated with
the required size. GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE if there
are no data in the current index. On success 0 is returned.
int gnutls_x509_crt_get_issuer_dn_by_oid (gnutls_x509_crt_t cert,const char *oid,unsigned indx,unsigned int raw_flag,void *buf,size_t *buf_size);
This function will extract the part of the name of the Certificate issuer specified by the given OID. The output, if the raw flag is not used, will be encoded as described in RFC4514. Thus a string that is ASCII or UTF-8 encoded, depending on the certificate data.
Some helper macros with popular OIDs can be found in gnutls/x509.h
If raw flag is (0), this function will only return known OIDs as
text. Other OIDs will be DER encoded, as described in RFC4514 --
in hex format with a '#' prefix. You can check about known OIDs
using gnutls_x509_dn_oid_known().
If buf
is null then only the size will be filled. If the raw_flag
is not specified the output is always null terminated, although the
buf_size
will not include the null character.
cert |
should contain a gnutls_x509_crt_t type |
|
oid |
holds an Object Identified in null terminated string |
|
indx |
In case multiple same OIDs exist in the RDN, this specifies which to send. Use (0) to get the first one. |
|
raw_flag |
If non-zero returns the raw DER data of the DN part. |
|
buf |
a pointer to a structure to hold the name (may be null) |
|
buf_size |
initially holds the size of |
GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not
long enough, and in that case the buf_size
will be updated with
the required size. GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE if there
are no data in the current index. On success 0 is returned.
int gnutls_x509_crt_get_dn (gnutls_x509_crt_t cert,char *buf,size_t *buf_size);
This function will copy the name of the Certificate in the provided buffer. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
The buf
returned will be null terminated and the buf_size
will account
for the trailing null. If buf
is null then only the size will be filled.
This function does not output a fully RFC4514 compliant string, if
that is required see gnutls_x509_crt_get_dn3().
cert |
should contain a gnutls_x509_crt_t type |
|
buf |
a pointer to a structure to hold the name (may be null) |
|
buf_size |
initially holds the size of |
GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not
long enough, and in that case the buf_size
will be updated
with the required size. GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE if
the DN does not exist, or another error value on error. On success 0 is returned.
int gnutls_x509_crt_get_dn2 (gnutls_x509_crt_t cert,gnutls_datum_t *dn);
This function will allocate buffer and copy the name of the Certificate. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
This function does not output a fully RFC4514 compliant string, if
that is required see gnutls_x509_crt_get_dn3().
cert |
should contain a gnutls_x509_crt_t type |
|
dn |
a pointer to a structure to hold the name; must be freed using |
Since: 3.1.10
int gnutls_x509_crt_get_dn3 (gnutls_x509_crt_t cert,gnutls_datum_t *dn,unsigned flags);
This function will allocate buffer and copy the name of the Certificate. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
When the flag GNUTLS_X509_DN_FLAG_COMPAT is specified, the output
format will match the format output by previous to 3.5.6 versions of GnuTLS
which was not not fully RFC4514-compliant.
cert |
should contain a gnutls_x509_crt_t type |
|
dn |
a pointer to a structure to hold the name; must be freed using |
|
flags |
zero or |
Since: 3.5.7
int gnutls_x509_crt_get_dn_oid (gnutls_x509_crt_t cert,unsigned indx,void *oid,size_t *oid_size);
This function will extract the OIDs of the name of the Certificate subject specified by the given index.
If oid
is null then only the size will be filled. The oid
returned will be null terminated, although oid_size
will not
account for the trailing null.
cert |
should contain a gnutls_x509_crt_t type |
|
indx |
This specifies which OID to return. Use (0) to get the first one. |
|
oid |
a pointer to a buffer to hold the OID (may be null) |
|
oid_size |
initially holds the size of |
GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not
long enough, and in that case the buf_size
will be updated with
the required size. GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE if there
are no data in the current index. On success 0 is returned.
int gnutls_x509_crt_get_dn_by_oid (gnutls_x509_crt_t cert,const char *oid,unsigned indx,unsigned int raw_flag,void *buf,size_t *buf_size);
This function will extract the part of the name of the Certificate subject specified by the given OID. The output, if the raw flag is not used, will be encoded as described in RFC4514. Thus a string that is ASCII or UTF-8 encoded, depending on the certificate data.
Some helper macros with popular OIDs can be found in gnutls/x509.h
If raw flag is (0), this function will only return known OIDs as
text. Other OIDs will be DER encoded, as described in RFC4514 --
in hex format with a '#' prefix. You can check about known OIDs
using gnutls_x509_dn_oid_known().
If buf
is null then only the size will be filled. If the raw_flag
is not specified the output is always null terminated, although the
buf_size
will not include the null character.
cert |
should contain a gnutls_x509_crt_t type |
|
oid |
holds an Object Identified in null terminated string |
|
indx |
In case multiple same OIDs exist in the RDN, this specifies which to send. Use (0) to get the first one. |
|
raw_flag |
If non-zero returns the raw DER data of the DN part. |
|
buf |
a pointer where the DN part will be copied (may be null). |
|
buf_size |
initially holds the size of |
GNUTLS_E_SHORT_MEMORY_BUFFER if the provided buffer is not
long enough, and in that case the buf_size
will be updated with
the required size. GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE if there
are no data in the current index. On success 0 is returned.
unsigned gnutls_x509_crt_check_hostname (gnutls_x509_crt_t cert,const char *hostname);
This function will check if the given certificate's subject matches the given hostname. This is a basic implementation of the matching described in RFC6125, and takes into account wildcards, and the DNSName/IPAddress subject alternative name PKIX extension.
For details see also gnutls_x509_crt_check_hostname2().
unsigned gnutls_x509_crt_check_hostname2 (gnutls_x509_crt_t cert,const char *hostname,unsigned int flags);
This function will check if the given certificate's subject matches the given hostname. This is a basic implementation of the matching described in RFC6125, and takes into account wildcards, and the DNSName/IPAddress subject alternative name PKIX extension.
IPv4 addresses are accepted by this function in the dotted-decimal format (e.g, ddd.ddd.ddd.ddd), and IPv6 addresses in the hexadecimal x:x:x:x:x:x:x:x format. For them the IPAddress subject alternative name extension is consulted. Previous versions to 3.6.0 of GnuTLS in case of a non-match would consult (in a non-standard extension) the DNSname and CN fields. This is no longer the case.
When the flag GNUTLS_VERIFY_DO_NOT_ALLOW_WILDCARDS is specified no
wildcards are considered. Otherwise they are only considered if the
domain name consists of three components or more, and the wildcard
starts at the leftmost position.
When the flag GNUTLS_VERIFY_DO_NOT_ALLOW_IP_MATCHES is specified,
the input will be treated as a DNS name, and matching of textual IP addresses
against the IPAddress part of the alternative name will not be allowed.
The function gnutls_x509_crt_check_ip() is available for matching
IP addresses.
cert |
should contain an gnutls_x509_crt_t type |
|
hostname |
A null terminated string that contains a DNS name |
|
flags |
gnutls_certificate_verify_flags |
Since: 3.3.0
unsigned gnutls_x509_crt_check_email (gnutls_x509_crt_t cert,const char *email,unsigned int flags);
This function will check if the given certificate's subject matches the given email address.
unsigned gnutls_x509_crt_check_ip (gnutls_x509_crt_t cert,const unsigned char *ip,unsigned int ip_size,unsigned int flags);
This function will check if the IP allowed IP addresses in the certificate's subject alternative name match the provided IP address.
int
gnutls_x509_crt_get_signature_algorithm
(gnutls_x509_crt_t cert);
This function will return a value of the gnutls_sign_algorithm_t enumeration that is the signature algorithm that has been used to sign this certificate.
Since 3.6.0 this function never returns a negative error code.
Error cases and unknown/unsupported signature algorithms are
mapped to GNUTLS_SIGN_UNKNOWN.
int gnutls_x509_crt_get_signature (gnutls_x509_crt_t cert,char *sig,size_t *sizeof_sig);
This function will extract the signature field of a certificate.
cert |
should contain a gnutls_x509_crt_t type |
|
sig |
a pointer where the signature part will be copied (may be null). |
|
sig_size |
initially holds the size of |
int
gnutls_x509_crt_get_version (gnutls_x509_crt_t cert);
This function will return the version of the specified Certificate.
int gnutls_x509_crt_get_pk_oid (gnutls_x509_crt_t cert,char *oid,size_t *oid_size);
This function will return the OID of the public key algorithm
on that certificate. This is function
is useful in the case gnutls_x509_crt_get_pk_algorithm()
returned GNUTLS_PK_UNKNOWN.
cert |
should contain a gnutls_x509_crt_t type |
|
oid |
a pointer to a buffer to hold the OID (may be null) |
|
oid_size |
initially holds the size of |
Since: 3.5.0
int gnutls_x509_crt_get_signature_oid (gnutls_x509_crt_t cert,char *oid,size_t *oid_size);
This function will return the OID of the signature algorithm
that has been used to sign this certificate. This is function
is useful in the case gnutls_x509_crt_get_signature_algorithm()
returned GNUTLS_SIGN_UNKNOWN.
cert |
should contain a gnutls_x509_crt_t type |
|
oid |
a pointer to a buffer to hold the OID (may be null) |
|
oid_size |
initially holds the size of |
Since: 3.5.0
int gnutls_x509_crt_get_key_id (gnutls_x509_crt_t crt,unsigned int flags,unsigned char *output_data,size_t *output_data_size);
This function will return a unique ID that depends on the public key parameters. This ID can be used in checking whether a certificate corresponds to the given private key.
If the buffer provided is not long enough to hold the output, then *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be returned. The output will normally be a SHA-1 hash output, which is 20 bytes.
crt |
Holds the certificate |
|
flags |
should be one of the flags from |
|
output_data |
will contain the key ID |
|
output_data_size |
holds the size of output_data (and will be replaced by the actual size of parameters) |
int gnutls_x509_crt_set_private_key_usage_period (gnutls_x509_crt_t crt,time_t activation,time_t expiration);
This function will set the private key usage period extension (2.5.29.16).
crt |
a certificate of type gnutls_x509_crt_t |
|
activation |
The activation time |
|
expiration |
The expiration time |
int gnutls_x509_crt_set_authority_key_id (gnutls_x509_crt_t cert,const void *id,size_t id_size);
This function will set the X.509 certificate's authority key ID extension. Only the keyIdentifier field can be set with this function.
cert |
a certificate of type gnutls_x509_crt_t |
|
id |
The key ID |
|
id_size |
Holds the size of the key ID field. |
int gnutls_x509_crt_get_authority_key_id (gnutls_x509_crt_t cert,void *id,size_t *id_size,unsigned int *critical);
This function will return the X.509v3 certificate authority's key
identifier. This is obtained by the X.509 Authority Key
identifier extension field (2.5.29.35). Note that this function
only returns the keyIdentifier field of the extension and
GNUTLS_E_X509_UNSUPPORTED_EXTENSION, if the extension contains
the name and serial number of the certificate. In that case
gnutls_x509_crt_get_authority_key_gn_serial() may be used.
cert |
should contain a gnutls_x509_crt_t type |
|
id |
The place where the identifier will be copied |
|
id_size |
Holds the size of the id field. |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
int gnutls_x509_crt_get_authority_key_gn_serial (gnutls_x509_crt_t cert,unsigned int seq,void *alt,size_t *alt_size,unsigned int *alt_type,void *serial,size_t *serial_size,unsigned int *critical);
This function will return the X.509 authority key identifier when stored as a general name (authorityCertIssuer) and serial number.
Because more than one general names might be stored
seq
can be used as a counter to request them all until
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
alt |
is the place where the alternative name will be copied to |
|
alt_size |
holds the size of alt. |
|
alt_type |
holds the type of the alternative name (one of gnutls_x509_subject_alt_name_t). |
|
serial |
buffer to store the serial number (may be null) |
|
serial_size |
Holds the size of the serial field (may be null) |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
Since: 3.0
int gnutls_x509_crt_get_subject_key_id (gnutls_x509_crt_t cert,void *ret,size_t *ret_size,unsigned int *critical);
This function will return the X.509v3 certificate's subject key identifier. This is obtained by the X.509 Subject Key identifier extension field (2.5.29.14).
cert |
should contain a gnutls_x509_crt_t type |
|
ret |
The place where the identifier will be copied |
|
ret_size |
Holds the size of the result field. |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
int gnutls_x509_crt_get_subject_unique_id (gnutls_x509_crt_t crt,char *buf,size_t *buf_size);
This function will extract the subjectUniqueID value (if present) for the given certificate.
If the user allocated memory buffer is not large enough to hold the full subjectUniqueID, then a GNUTLS_E_SHORT_MEMORY_BUFFER error will be returned, and buf_size will be set to the actual length.
This function had a bug prior to 3.4.8 that prevented the setting
of NULL buf
to discover the buf_size
. To use this function safely
with the older versions the buf
must be a valid buffer that can hold
at least a single byte if buf_size
is zero.
int gnutls_x509_crt_get_issuer_unique_id (gnutls_x509_crt_t crt,char *buf,size_t *buf_size);
This function will extract the issuerUniqueID value (if present) for the given certificate.
If the user allocated memory buffer is not large enough to hold the full subjectUniqueID, then a GNUTLS_E_SHORT_MEMORY_BUFFER error will be returned, and buf_size will be set to the actual length.
This function had a bug prior to 3.4.8 that prevented the setting
of NULL buf
to discover the buf_size
. To use this function safely
with the older versions the buf
must be a valid buffer that can hold
at least a single byte if buf_size
is zero.
crt |
Holds the certificate |
|
buf |
user allocated memory buffer, will hold the unique id |
|
buf_size |
size of user allocated memory buffer (on input), will hold actual size of the unique ID on return. |
Since: 2.12.0
void gnutls_x509_crt_set_pin_function (gnutls_x509_crt_t crt,gnutls_pin_callback_t fn,void *userdata);
This function will set a callback function to be used when
it is required to access a protected object. This function overrides
the global function set using gnutls_pkcs11_set_pin_function().
Note that this callback is currently used only during the import
of a PKCS 11 certificate with gnutls_x509_crt_import_url().
Since: 3.1.0
int gnutls_x509_crt_get_authority_info_access (gnutls_x509_crt_t crt,unsigned int seq,int what,gnutls_datum_t *data,unsigned int *critical);
Note that a simpler API to access the authority info data is provided
by gnutls_x509_aia_get() and gnutls_x509_ext_import_aia().
This function extracts the Authority Information Access (AIA) extension, see RFC 5280 section 4.2.2.1 for more information. The AIA extension holds a sequence of AccessDescription (AD) data.
The seq
input parameter is used to indicate which member of the
sequence the caller is interested in. The first member is 0, the
second member 1 and so on. When the seq
value is out of bounds,
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
The type of data returned in data
is specified via what
which
should be gnutls_info_access_what_t values.
If what
is GNUTLS_IA_ACCESSMETHOD_OID then data
will hold the
accessMethod OID (e.g., "1.3.6.1.5.5.7.48.1").
If what
is GNUTLS_IA_ACCESSLOCATION_GENERALNAME_TYPE, data
will
hold the accessLocation GeneralName type (e.g.,
"uniformResourceIdentifier").
If what
is GNUTLS_IA_URI, data
will hold the accessLocation URI
data. Requesting this what
value leads to an error if the
accessLocation is not of the "uniformResourceIdentifier" type.
If what
is GNUTLS_IA_OCSP_URI, data
will hold the OCSP URI.
Requesting this what
value leads to an error if the accessMethod
is not 1.3.6.1.5.5.7.48.1 aka OCSP, or if accessLocation is not of
the "uniformResourceIdentifier" type. In that case GNUTLS_E_UNKNOWN_ALGORITHM
will be returned, and seq
should be increased and this function
called again.
If what
is GNUTLS_IA_CAISSUERS_URI, data
will hold the caIssuers
URI. Requesting this what
value leads to an error if the
accessMethod is not 1.3.6.1.5.5.7.48.2 aka caIssuers, or if
accessLocation is not of the "uniformResourceIdentifier" type.
In that case handle as in GNUTLS_IA_OCSP_URI.
More what
values may be allocated in the future as needed.
If data
is NULL, the function does the same without storing the
output data, that is, it will set critical
and do error checking
as usual.
The value of the critical flag is returned in *critical
. Supply a
NULL critical
if you want the function to make sure the extension
is non-critical, as required by RFC 5280.
crt |
Holds the certificate |
|
seq |
specifies the sequence number of the access descriptor (0 for the first one, 1 for the second etc.) |
|
what |
what data to get, a gnutls_info_access_what_t type. |
|
data |
output data to be freed with |
|
critical |
pointer to output integer that is set to non-zero if the extension is marked as critical (may be |
GNUTLS_E_SUCCESS on success, GNUTLS_E_INVALID_REQUEST on
invalid crt
, GNUTLS_E_CONSTRAINT_ERROR if the extension is
incorrectly marked as critical (use a non-NULL critical
to
override), GNUTLS_E_UNKNOWN_ALGORITHM if the requested OID does
not match (e.g., when using GNUTLS_IA_OCSP_URI), otherwise a
negative error code.
Since: 3.0
unsigned gnutls_x509_name_constraints_check (gnutls_x509_name_constraints_t nc,gnutls_x509_subject_alt_name_t type,const gnutls_datum_t *name);
This function will check the provided name against the constraints in
nc
using the RFC5280 rules. Currently this function is limited to DNS
names, emails and IP addresses (of type GNUTLS_SAN_DNSNAME,
GNUTLS_SAN_RFC822NAME and GNUTLS_SAN_IPADDRESS).
nc |
the extracted name constraints |
|
type |
the type of the constraint to check (of type gnutls_x509_subject_alt_name_t) |
|
name |
the name to be checked |
Since: 3.3.0
unsigned gnutls_x509_name_constraints_check_crt (gnutls_x509_name_constraints_t nc,gnutls_x509_subject_alt_name_t type,gnutls_x509_crt_t crt);
This function will check the provided certificate names against the constraints in
nc
using the RFC5280 rules. It will traverse all the certificate's names and
alternative names.
Currently this function is limited to DNS
names and emails (of type GNUTLS_SAN_DNSNAME and GNUTLS_SAN_RFC822NAME).
nc |
the extracted name constraints |
|
type |
the type of the constraint to check (of type gnutls_x509_subject_alt_name_t) |
|
cert |
the certificate to be checked |
Since: 3.3.0
int
gnutls_x509_name_constraints_init (gnutls_x509_name_constraints_t *nc);
This function will initialize a name constraints type.
Since: 3.3.0
void
gnutls_x509_name_constraints_deinit (gnutls_x509_name_constraints_t nc);
This function will deinitialize a name constraints type.
Since: 3.3.0
int gnutls_x509_crt_get_name_constraints (gnutls_x509_crt_t crt,gnutls_x509_name_constraints_t nc,unsigned int flags,unsigned int *critical);
This function will return an intermediate type containing
the name constraints of the provided CA certificate. That
structure can be used in combination with gnutls_x509_name_constraints_check()
to verify whether a server's name is in accordance with the constraints.
When the flags
is set to GNUTLS_EXT_FLAG_APPEND,
then if the nc
structure is empty this function will behave
identically as if the flag was not set.
Otherwise if there are elements in the nc
structure then the
constraints will be merged with the existing constraints following
RFC5280 p6.1.4 (excluded constraints will be appended, permitted
will be intersected).
Note that nc
must be initialized prior to calling this function.
crt |
should contain a gnutls_x509_crt_t type |
|
nc |
The nameconstraints intermediate type |
|
flags |
zero or |
|
critical |
the extension status |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
Since: 3.3.0
int gnutls_x509_name_constraints_add_permitted (gnutls_x509_name_constraints_t nc,gnutls_x509_subject_alt_name_t type,const gnutls_datum_t *name);
This function will add a name constraint to the list of permitted
constraints. The constraints type
can be any of the following types:
GNUTLS_SAN_DNSNAME, GNUTLS_SAN_RFC822NAME, GNUTLS_SAN_DN,
GNUTLS_SAN_URI, GNUTLS_SAN_IPADDRESS. For the latter, an IP address
in network byte order is expected, followed by its network mask.
Since: 3.3.0
int gnutls_x509_name_constraints_add_excluded (gnutls_x509_name_constraints_t nc,gnutls_x509_subject_alt_name_t type,const gnutls_datum_t *name);
This function will add a name constraint to the list of excluded
constraints. The constraints type
can be any of the following types:
GNUTLS_SAN_DNSNAME, GNUTLS_SAN_RFC822NAME, GNUTLS_SAN_DN,
GNUTLS_SAN_URI, GNUTLS_SAN_IPADDRESS. For the latter, an IP address
in network byte order is expected, followed by its network mask (which is
4 bytes in IPv4 or 16-bytes in IPv6).
Since: 3.3.0
int gnutls_x509_crt_set_name_constraints (gnutls_x509_crt_t crt,gnutls_x509_name_constraints_t nc,unsigned int critical);
This function will set the provided name constraints to the certificate extension list. This extension is always marked as critical.
crt |
The certificate |
|
nc |
The nameconstraints structure |
|
critical |
whether this extension will be critical |
Since: 3.3.0
int gnutls_x509_name_constraints_get_permitted (gnutls_x509_name_constraints_t nc,unsigned idx,unsigned *type,gnutls_datum_t *name);
This function will return an intermediate type containing
the name constraints of the provided CA certificate. That
structure can be used in combination with gnutls_x509_name_constraints_check()
to verify whether a server's name is in accordance with the constraints.
The name should be treated as constant and valid for the lifetime of nc
.
nc |
the extracted name constraints |
|
idx |
the index of the constraint |
|
type |
the type of the constraint (of type gnutls_x509_subject_alt_name_t) |
|
name |
the name in the constraint (of the specific type) |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
Since: 3.3.0
int gnutls_x509_name_constraints_get_excluded (gnutls_x509_name_constraints_t nc,unsigned idx,unsigned *type,gnutls_datum_t *name);
This function will return an intermediate type containing
the name constraints of the provided CA certificate. That
structure can be used in combination with gnutls_x509_name_constraints_check()
to verify whether a server's name is in accordance with the constraints.
The name should be treated as constant and valid for the lifetime of nc
.
nc |
the extracted name constraints |
|
idx |
the index of the constraint |
|
type |
the type of the constraint (of type gnutls_x509_subject_alt_name_t) |
|
name |
the name in the constraint (of the specific type) |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
Since: 3.3.0
int gnutls_x509_cidr_to_rfc5280 (const char *cidr,gnutls_datum_t *cidr_rfc5280);
This function will convert text CIDR range with prefix (such as '10.0.0.0/8') to RFC5280 (IP address in network byte order followed by its network mask). Works for both IPv4 and IPv6.
The resulting object is directly usable for IP name constraints usage,
for example in functions gnutls_x509_name_constraints_add_permitted
or gnutls_x509_name_constraints_add_excluded.
The data in datum needs to be deallocated using gnutls_free().
cidr |
CIDR in RFC4632 format (IP/prefix), null-terminated |
|
cidr_rfc5280 |
CIDR range converted to RFC5280 format |
Since: 3.5.4
int gnutls_x509_crt_get_crl_dist_points (gnutls_x509_crt_t cert,unsigned int seq,void *ret,size_t *ret_size,unsigned int *reason_flags,unsigned int *critical);
This function retrieves the CRL distribution points (2.5.29.31), contained in the given certificate in the X509v3 Certificate Extensions.
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the distribution point (0 for the first one, 1 for the second etc.) |
|
san |
is the place where the distribution point will be copied to |
|
san_size |
holds the size of ret. |
|
reason_flags |
Revocation reasons. An ORed sequence of flags from |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
GNUTLS_E_SHORT_MEMORY_BUFFER and updates ret_size
if
ret_size
is not enough to hold the distribution point, or the
type of the distribution point if everything was ok. The type is
one of the enumerated gnutls_x509_subject_alt_name_t. If the
certificate does not have an Alternative name with the specified
sequence number then GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is
returned.
int gnutls_x509_crt_set_crl_dist_points2 (gnutls_x509_crt_t crt,gnutls_x509_subject_alt_name_t type,const void *data,unsigned int data_size,unsigned int reason_flags);
This function will set the CRL distribution points certificate extension.
crt |
a certificate of type gnutls_x509_crt_t |
|
type |
is one of the gnutls_x509_subject_alt_name_t enumerations |
|
data |
The data to be set |
|
data_size |
The data size |
|
reason_flags |
revocation reasons |
Since: 2.6.0
int gnutls_x509_crt_set_crl_dist_points (gnutls_x509_crt_t crt,gnutls_x509_subject_alt_name_t type,const void *data_string,unsigned int reason_flags);
This function will set the CRL distribution points certificate extension.
crt |
a certificate of type gnutls_x509_crt_t |
|
type |
is one of the gnutls_x509_subject_alt_name_t enumerations |
|
data_string |
The data to be set |
|
reason_flags |
revocation reasons |
int gnutls_x509_crt_cpy_crl_dist_points (gnutls_x509_crt_t dst,gnutls_x509_crt_t src);
This function will copy the CRL distribution points certificate extension, from the source to the destination certificate. This may be useful to copy from a CA certificate to issued ones.
dst |
a certificate of type gnutls_x509_crt_t |
|
src |
the certificate where the dist points will be copied from |
int gnutls_x509_crl_sign (gnutls_x509_crl_t crl,gnutls_x509_crt_t issuer,gnutls_x509_privkey_t issuer_key);
This function is the same a gnutls_x509_crl_sign2() with no flags,
and an appropriate hash algorithm. The hash algorithm used may
vary between versions of GnuTLS, and it is tied to the security
level of the issuer's public key.
int gnutls_x509_crl_sign2 (gnutls_x509_crl_t crl,gnutls_x509_crt_t issuer,gnutls_x509_privkey_t issuer_key,gnutls_digest_algorithm_t dig,unsigned int flags);
This function will sign the CRL with the issuer's private key, and will copy the issuer's information into the CRL.
This must be the last step in a certificate CRL since all the previously set parameters are now signed.
A known limitation of this function is, that a newly-signed CRL will not be fully functional (e.g., for signature verification), until it is exported an re-imported.
After GnuTLS 3.6.1 the value of dig
may be GNUTLS_DIG_UNKNOWN,
and in that case, a suitable but reasonable for the key algorithm will be selected.
time_t
gnutls_x509_crt_get_activation_time (gnutls_x509_crt_t cert);
This function will return the time this Certificate was or will be activated.
time_t
gnutls_x509_crt_get_expiration_time (gnutls_x509_crt_t cert);
This function will return the time this certificate was or will be expired.
int gnutls_x509_crt_get_serial (gnutls_x509_crt_t cert,void *result,size_t *result_size);
This function will return the X.509 certificate's serial number. This is obtained by the X509 Certificate serialNumber field. Serial is not always a 32 or 64bit number. Some CAs use large serial numbers, thus it may be wise to handle it as something uint8_t.
cert |
should contain a gnutls_x509_crt_t type |
|
result |
The place where the serial number will be copied |
|
result_size |
Holds the size of the result field. |
int
gnutls_x509_spki_init (gnutls_x509_spki_t *spki);
This function will initialize a SubjectPublicKeyInfo structure used in PKIX. The structure is used to set additional parameters in the public key information field of a certificate.
Since: 3.6.0
void
gnutls_x509_spki_deinit (gnutls_x509_spki_t spki);
This function will deinitialize a SubjectPublicKeyInfo structure.
Since: 3.6.0
int gnutls_x509_spki_get_rsa_pss_params (gnutls_x509_spki_t spki,gnutls_digest_algorithm_t *dig,unsigned int *salt_size);
This function will get the public key algorithm parameters of RSA-PSS type.
spki |
the SubjectPublicKeyInfo structure |
|
dig |
if non-NULL, it will hold the digest algorithm |
|
salt_size |
if non-NULL, it will hold the salt size |
Since: 3.6.0
void gnutls_x509_spki_set_rsa_pss_params (gnutls_x509_spki_t spki,gnutls_digest_algorithm_t dig,unsigned int salt_size);
This function will set the public key parameters for an RSA-PSS algorithm, in the SubjectPublicKeyInfo structure.
spki |
the SubjectPublicKeyInfo structure |
|
dig |
a digest algorithm of type gnutls_digest_algorithm_t |
|
salt_size |
the size of salt string |
Since: 3.6.0
int gnutls_x509_spki_set_rsa_oaep_params (gnutls_x509_spki_t spki,gnutls_digest_algorithm_t dig,const gnutls_datum_t *label);
This function will set the public key parameters for an RSA-OAEP algorithm, in the SubjectPublicKeyInfo structure.
spki |
the SubjectPublicKeyInfo structure |
|
dig |
a digest algorithm of type gnutls_digest_algorithm_t |
|
label |
optional label |
Since: 3.8.4
int gnutls_x509_spki_get_rsa_oaep_params (gnutls_x509_spki_t spki,gnutls_digest_algorithm_t *dig,gnutls_datum_t *label);
This function will get the public key algorithm parameters of RSA-OAEP type.
spki |
the SubjectPublicKeyInfo structure |
|
dig |
if non-NULL, it will hold the digest algorithm |
|
label |
if non-NULL, it will hold the pointer to label |
Since: 3.8.4
int gnutls_x509_crt_get_pk_algorithm (gnutls_x509_crt_t cert,unsigned int *bits);
This function will return the public key algorithm of an X.509 certificate.
If bits is non null, it should have enough size to hold the parameters size in bits. For RSA the bits returned is the modulus. For DSA the bits returned are of the public exponent.
Unknown/unsupported algorithms are mapped to GNUTLS_PK_UNKNOWN.
cert |
should contain a gnutls_x509_crt_t type |
|
bits |
if bits is non null it will hold the size of the parameters' in bits |
a member of the gnutls_pk_algorithm_t enumeration on success, or a negative error code on error.
int gnutls_x509_crt_set_spki (gnutls_x509_crt_t crt,const gnutls_x509_spki_t spki,unsigned int flags);
This function will set the certificate's subject public key information explicitly. This is intended to be used in the cases where a single public key (e.g., RSA) can be used for multiple signature algorithms (RSA PKCS1-1.5, and RSA-PSS).
To export the public key (i.e., the SubjectPublicKeyInfo part), check
gnutls_pubkey_import_x509().
crt |
a certificate of type gnutls_x509_crt_t |
|
spki |
a SubjectPublicKeyInfo structure of type gnutls_x509_spki_t |
|
flags |
must be zero |
Since: 3.6.0
int gnutls_x509_crt_get_spki (gnutls_x509_crt_t cert,gnutls_x509_spki_t spki,unsigned int flags);
This function will return the public key information of an X.509
certificate. The provided spki
must be initialized.
cert |
a certificate of type gnutls_x509_crt_t |
|
spki |
a SubjectPublicKeyInfo structure of type gnutls_x509_spki_t |
|
flags |
must be zero |
Since: 3.6.0
int gnutls_x509_crt_get_pk_rsa_raw (gnutls_x509_crt_t crt,gnutls_datum_t *m,gnutls_datum_t *e);
This function will export the RSA public key's parameters found in
the given structure. The new parameters will be allocated using
gnutls_malloc() and will be stored in the appropriate datum.
int gnutls_x509_crt_get_pk_dsa_raw (gnutls_x509_crt_t crt,gnutls_datum_t *p,gnutls_datum_t *q,gnutls_datum_t *g,gnutls_datum_t *y);
This function will export the DSA public key's parameters found in
the given certificate. The new parameters will be allocated using
gnutls_malloc() and will be stored in the appropriate datum.
int gnutls_x509_crt_get_pk_ecc_raw (gnutls_x509_crt_t crt,gnutls_ecc_curve_t *curve,gnutls_datum_t *x,gnutls_datum_t *y);
This function will export the ECC public key's parameters found in
the given certificate. The new parameters will be allocated using
gnutls_malloc() and will be stored in the appropriate datum.
In EdDSA curves the y
parameter will be NULL and the other parameters
will be in the native format for the curve.
crt |
Holds the certificate |
|
curve |
will hold the curve |
|
x |
will hold the x-coordinate |
|
y |
will hold the y-coordinate |
Since: 3.4.1
int gnutls_x509_crt_get_pk_gost_raw (gnutls_x509_crt_t crt,gnutls_ecc_curve_t *curve,gnutls_digest_algorithm_t *digest,gnutls_gost_paramset_t *paramset,gnutls_datum_t *x,gnutls_datum_t *y);
This function will export the GOST public key's parameters found in
the given certificate. The new parameters will be allocated using
gnutls_malloc() and will be stored in the appropriate datum.
crt |
Holds the certificate |
|
curve |
will hold the curve |
|
digest |
will hold the digest |
|
paramset |
will hold the GOST parameter set ID |
|
x |
will hold the x-coordinate |
|
y |
will hold the y-coordinate |
Since: 3.6.3
int gnutls_x509_crt_get_subject_alt_name (gnutls_x509_crt_t cert,unsigned int seq,void *san,size_t *san_size,unsigned int *critical);
This function retrieves the Alternative Name (2.5.29.17), contained in the given certificate in the X509v3 Certificate Extensions.
When the SAN type is otherName, it will extract the data in the
otherName's value field, and GNUTLS_SAN_OTHERNAME is returned.
You may use gnutls_x509_crt_get_subject_alt_othername_oid() to get
the corresponding OID and the "virtual" SAN types (e.g.,
GNUTLS_SAN_OTHERNAME_XMPP).
If an otherName OID is known, the data will be decoded. Otherwise the returned data will be DER encoded, and you will have to decode it yourself. Currently, only the RFC 3920 id-on-xmppAddr SAN is recognized.
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
san |
is the place where the alternative name will be copied to |
|
san_size |
holds the size of san. |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
the alternative subject name type on success, one of the
enumerated gnutls_x509_subject_alt_name_t. It will return
GNUTLS_E_SHORT_MEMORY_BUFFER if san_size
is not large enough to
hold the value. In that case san_size
will be updated with the
required size. If the certificate does not have an Alternative
name with the specified sequence number then
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
int gnutls_x509_crt_get_subject_alt_name2 (gnutls_x509_crt_t cert,unsigned int seq,void *san,size_t *san_size,unsigned int *san_type,unsigned int *critical);
This function will return the alternative names, contained in the
given certificate. It is the same as
gnutls_x509_crt_get_subject_alt_name() except for the fact that it
will return the type of the alternative name in san_type
even if
the function fails for some reason (i.e. the buffer provided is
not enough).
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
san |
is the place where the alternative name will be copied to |
|
san_size |
holds the size of ret. |
|
san_type |
holds the type of the alternative name (one of gnutls_x509_subject_alt_name_t). |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
the alternative subject name type on success, one of the
enumerated gnutls_x509_subject_alt_name_t. It will return
GNUTLS_E_SHORT_MEMORY_BUFFER if san_size
is not large enough
to hold the value. In that case san_size
will be updated with
the required size. If the certificate does not have an
Alternative name with the specified sequence number then
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
int gnutls_x509_crt_get_subject_alt_othername_oid (gnutls_x509_crt_t cert,unsigned int seq,void *oid,size_t *oid_size);
This function will extract the type OID of an otherName Subject Alternative Name, contained in the given certificate, and return the type as an enumerated element.
This function is only useful if
gnutls_x509_crt_get_subject_alt_name() returned
GNUTLS_SAN_OTHERNAME.
If oid
is null then only the size will be filled. The oid
returned will be null terminated, although oid_size
will not
account for the trailing null.
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
oid |
is the place where the otherName OID will be copied to |
|
oid_size |
holds the size of ret. |
the alternative subject name type on success, one of the
enumerated gnutls_x509_subject_alt_name_t. For supported OIDs, it
will return one of the virtual (GNUTLS_SAN_OTHERNAME_*) types,
e.g. GNUTLS_SAN_OTHERNAME_XMPP, and GNUTLS_SAN_OTHERNAME for
unknown OIDs. It will return GNUTLS_E_SHORT_MEMORY_BUFFER if
ian_size
is not large enough to hold the value. In that case
ian_size
will be updated with the required size. If the
certificate does not have an Alternative name with the specified
sequence number and with the otherName type then
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
int gnutls_x509_crt_get_issuer_alt_name (gnutls_x509_crt_t cert,unsigned int seq,void *ian,size_t *ian_size,unsigned int *critical);
This function retrieves the Issuer Alternative Name (2.5.29.18), contained in the given certificate in the X509v3 Certificate Extensions.
When the SAN type is otherName, it will extract the data in the
otherName's value field, and GNUTLS_SAN_OTHERNAME is returned.
You may use gnutls_x509_crt_get_subject_alt_othername_oid() to get
the corresponding OID and the "virtual" SAN types (e.g.,
GNUTLS_SAN_OTHERNAME_XMPP).
If an otherName OID is known, the data will be decoded. Otherwise the returned data will be DER encoded, and you will have to decode it yourself. Currently, only the RFC 3920 id-on-xmppAddr Issuer AltName is recognized.
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
ian |
is the place where the alternative name will be copied to |
|
ian_size |
holds the size of ian. |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
the alternative issuer name type on success, one of the
enumerated gnutls_x509_subject_alt_name_t. It will return
GNUTLS_E_SHORT_MEMORY_BUFFER if ian_size
is not large enough
to hold the value. In that case ian_size
will be updated with
the required size. If the certificate does not have an
Alternative name with the specified sequence number then
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
Since: 2.10.0
int gnutls_x509_crt_get_issuer_alt_name2 (gnutls_x509_crt_t cert,unsigned int seq,void *ian,size_t *ian_size,unsigned int *ian_type,unsigned int *critical);
This function will return the alternative names, contained in the
given certificate. It is the same as
gnutls_x509_crt_get_issuer_alt_name() except for the fact that it
will return the type of the alternative name in ian_type
even if
the function fails for some reason (i.e. the buffer provided is
not enough).
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
ian |
is the place where the alternative name will be copied to |
|
ian_size |
holds the size of ret. |
|
ian_type |
holds the type of the alternative name (one of gnutls_x509_subject_alt_name_t). |
|
critical |
will be non-zero if the extension is marked as critical (may be null) |
the alternative issuer name type on success, one of the
enumerated gnutls_x509_subject_alt_name_t. It will return
GNUTLS_E_SHORT_MEMORY_BUFFER if ian_size
is not large enough
to hold the value. In that case ian_size
will be updated with
the required size. If the certificate does not have an
Alternative name with the specified sequence number then
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
Since: 2.10.0
int gnutls_x509_crt_get_issuer_alt_othername_oid (gnutls_x509_crt_t cert,unsigned int seq,void *ret,size_t *ret_size);
This function will extract the type OID of an otherName Subject Alternative Name, contained in the given certificate, and return the type as an enumerated element.
If oid
is null then only the size will be filled. The oid
returned will be null terminated, although oid_size
will not
account for the trailing null.
This function is only useful if
gnutls_x509_crt_get_issuer_alt_name() returned
GNUTLS_SAN_OTHERNAME.
cert |
should contain a gnutls_x509_crt_t type |
|
seq |
specifies the sequence number of the alt name (0 for the first one, 1 for the second etc.) |
|
ret |
is the place where the otherName OID will be copied to |
|
ret_size |
holds the size of ret. |
the alternative issuer name type on success, one of the
enumerated gnutls_x509_subject_alt_name_t. For supported OIDs, it
will return one of the virtual (GNUTLS_SAN_OTHERNAME_*) types,
e.g. GNUTLS_SAN_OTHERNAME_XMPP, and GNUTLS_SAN_OTHERNAME for
unknown OIDs. It will return GNUTLS_E_SHORT_MEMORY_BUFFER if
ret_size
is not large enough to hold the value. In that case
ret_size
will be updated with the required size. If the
certificate does not have an Alternative name with the specified
sequence number and with the otherName type then
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
Since: 2.10.0
int gnutls_x509_crt_get_ca_status (gnutls_x509_crt_t cert,unsigned int *critical);
This function will return certificates CA status, by reading the basicConstraints X.509 extension (2.5.29.19). If the certificate is a CA a positive value will be returned, or (0) if the certificate does not have CA flag set.
Use gnutls_x509_crt_get_basic_constraints() if you want to read the
pathLenConstraint field too.
cert |
should contain a gnutls_x509_crt_t type |
|
critical |
will be non-zero if the extension is marked as critical |
If the certificate is a CA a positive value will be returned, or (0) if the certificate does not have CA flag set. A negative error code may be returned in case of errors. If the certificate does not contain the basicConstraints extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.
int gnutls_x509_crt_get_basic_constraints (gnutls_x509_crt_t cert,unsigned int *critical,unsigned int *ca,int *pathlen);
This function will read the certificate's basic constraints, and return the certificates CA status. It reads the basicConstraints X.509 extension (2.5.29.19).
cert |
should contain a gnutls_x509_crt_t type |
|
critical |
will be non-zero if the extension is marked as critical |
|
ca |
pointer to output integer indicating CA status, may be NULL, value is 1 if the certificate CA flag is set, 0 otherwise. |
|
pathlen |
pointer to output integer indicating path length (may be NULL), non-negative error codes indicate a present pathLenConstraint field and the actual value, -1 indicate that the field is absent. |
If the certificate is a CA a positive value will be returned, or (0) if the certificate does not have CA flag set. A negative error code may be returned in case of errors. If the certificate does not contain the basicConstraints extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.
int gnutls_x509_crt_get_key_usage (gnutls_x509_crt_t cert,unsigned int *key_usage,unsigned int *critical);
This function will return certificate's key usage, by reading the
keyUsage X.509 extension (2.5.29.15). The key usage value will ORed
values of the: GNUTLS_KEY_DIGITAL_SIGNATURE,
GNUTLS_KEY_NON_REPUDIATION, GNUTLS_KEY_KEY_ENCIPHERMENT,
GNUTLS_KEY_DATA_ENCIPHERMENT, GNUTLS_KEY_KEY_AGREEMENT,
GNUTLS_KEY_KEY_CERT_SIGN, GNUTLS_KEY_CRL_SIGN,
GNUTLS_KEY_ENCIPHER_ONLY, GNUTLS_KEY_DECIPHER_ONLY.
cert |
should contain a gnutls_x509_crt_t type |
|
key_usage |
where the key usage bits will be stored |
|
critical |
will be non-zero if the extension is marked as critical |
zero on success, or a negative error code in case of
parsing error. If the certificate does not contain the keyUsage
extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be
returned.
int gnutls_x509_crt_set_key_usage (gnutls_x509_crt_t crt,unsigned int usage);
This function will set the keyUsage certificate extension.
crt |
a certificate of type gnutls_x509_crt_t |
|
usage |
an ORed sequence of the GNUTLS_KEY_* elements. |
int gnutls_x509_crt_set_authority_info_access (gnutls_x509_crt_t crt,int what,gnutls_datum_t *data);
This function sets the Authority Information Access (AIA) extension, see RFC 5280 section 4.2.2.1 for more information.
The type of data stored in data
is specified via what
which
should be gnutls_info_access_what_t values.
If what
is GNUTLS_IA_OCSP_URI, data
will hold the OCSP URI.
If what
is GNUTLS_IA_CAISSUERS_URI, data
will hold the caIssuers
URI.
crt |
Holds the certificate |
|
what |
what data to get, a gnutls_info_access_what_t type. |
|
data |
output data to be freed with |
Since: 3.0
int gnutls_x509_crt_get_inhibit_anypolicy (gnutls_x509_crt_t cert,unsigned int *skipcerts,unsigned int *critical);
This function will return certificate's value of the SkipCerts, i.e., the Inhibit anyPolicy X.509 extension (2.5.29.54).
The returned value is the number of additional certificates that may appear in the path before the anyPolicy is no longer acceptable.
cert |
should contain a gnutls_x509_crt_t type |
|
skipcerts |
will hold the number of certificates after which anypolicy is no longer acceptable. |
|
critical |
will be non-zero if the extension is marked as critical |
zero on success, or a negative error code in case of
parsing error. If the certificate does not contain the Inhibit anyPolicy
extension GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be
returned.
Since: 3.6.0
int gnutls_x509_crt_set_inhibit_anypolicy (gnutls_x509_crt_t crt,unsigned int skipcerts);
This function will set the Inhibit anyPolicy certificate extension.
crt |
a certificate of type gnutls_x509_crt_t |
|
skipcerts |
number of certificates after which anypolicy is no longer acceptable. |
int gnutls_x509_crt_get_proxy (gnutls_x509_crt_t cert,unsigned int *critical,int *pathlen,char **policyLanguage,char **policy,size_t *sizeof_policy);
This function will get information from a proxy certificate. It reads the ProxyCertInfo X.509 extension (1.3.6.1.5.5.7.1.14).
cert |
should contain a gnutls_x509_crt_t type |
|
critical |
will be non-zero if the extension is marked as critical |
|
pathlen |
pointer to output integer indicating path length (may be NULL), non-negative error codes indicate a present pCPathLenConstraint field and the actual value, -1 indicate that the field is absent. |
|
policyLanguage |
output variable with OID of policy language |
|
policy |
output variable with policy data |
|
sizeof_policy |
output variable size of policy data |
int
gnutls_x509_tlsfeatures_init (gnutls_x509_tlsfeatures_t *features);
This function will initialize a X.509 TLS features extension structure
Since: 3.5.1
void
gnutls_x509_tlsfeatures_deinit (gnutls_x509_tlsfeatures_t Param1);
This function will deinitialize a X.509 TLS features extension structure
Since: 3.5.1
int gnutls_x509_tlsfeatures_get (gnutls_x509_tlsfeatures_t f,unsigned idx,unsigned int *feature);
This function will get a feature from the X.509 TLS features extension structure.
f |
The TLS features |
|
idx |
The index of the feature to get |
|
feature |
If the function succeeds, the feature will be stored in this variable |
Since: 3.5.1
int gnutls_x509_crt_set_tlsfeatures (gnutls_x509_crt_t crt,gnutls_x509_tlsfeatures_t features);
This function will set the certificates X.509 TLS extension from the given structure.
crt |
A X.509 certificate |
|
features |
If the function succeeds, the features will be added to the certificate. |
Since: 3.5.1
int gnutls_x509_crt_get_tlsfeatures (gnutls_x509_crt_t cert,gnutls_x509_tlsfeatures_t features,unsigned int flags,unsigned int *critical);
This function will get the X.509 TLS features
extension structure from the certificate. The
returned structure needs to be freed using
gnutls_x509_tlsfeatures_deinit().
When the flags
is set to GNUTLS_EXT_FLAG_APPEND,
then if the features
structure is empty this function will behave
identically as if the flag was not set. Otherwise if there are elements
in the features
structure then they will be merged with.
Note that features
must be initialized prior to calling this function.
crt |
A X.509 certificate |
|
features |
If the function succeeds, the features will be stored in this variable. |
|
flags |
zero or |
|
critical |
the extension status |
Since: 3.5.1
unsigned gnutls_x509_tlsfeatures_check_crt (gnutls_x509_tlsfeatures_t feat,gnutls_x509_crt_t crt);
void
gnutls_x509_policy_release (struct gnutls_x509_policy_st *policy);
This function will deinitialize all memory associated with the provided
policy
. The policy is allocated using gnutls_x509_crt_get_policy().
Since: 3.1.5
int gnutls_x509_crt_get_policy (gnutls_x509_crt_t crt,unsigned indx,struct gnutls_x509_policy_st *policy,unsigned int *critical);
This function will extract the certificate policy (extension 2.5.29.32) specified by the given index.
The policy returned by this function must be deinitialized by using
gnutls_x509_policy_release().
crt |
should contain a gnutls_x509_crt_t type |
|
indx |
This specifies which policy to return. Use (0) to get the first one. |
|
policy |
A pointer to a policy structure. |
|
critical |
will be non-zero if the extension is marked as critical |
On success, GNUTLS_E_SUCCESS (0) is returned, GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
if the extension is not present, otherwise a negative error value.
Since: 3.1.5
int gnutls_x509_crt_set_policy (gnutls_x509_crt_t crt,const struct gnutls_x509_policy_st *policy,unsigned int critical);
This function will set the certificate policy extension (2.5.29.32). Multiple calls to this function append a new policy.
Note the maximum text size for the qualifier GNUTLS_X509_QUALIFIER_NOTICE
is 200 characters. This function will fail with GNUTLS_E_INVALID_REQUEST
if this is exceeded.
crt |
should contain a gnutls_x509_crt_t type |
|
policy |
A pointer to a policy |
|
critical |
use non-zero if the extension is marked as critical |
Since: 3.1.5
int
gnutls_x509_dn_oid_known (const char *oid);
This function will inform about known DN OIDs. This is useful since
functions like gnutls_x509_crt_set_dn_by_oid() use the information
on known OIDs to properly encode their input. Object Identifiers
that are not known are not encoded by these functions, and their
input is stored directly into the ASN.1 structure. In that case of
unknown OIDs, you have the responsibility of DER encoding your
data.
const char * gnutls_x509_dn_oid_name (const char *oid,unsigned int flags);
This function will return the name of a known DN OID. If
GNUTLS_X509_DN_OID_RETURN_OID is specified this function
will return the given OID if no descriptive name has been
found.
oid |
holds an Object Identifier in a null terminated string |
|
flags |
0 or GNUTLS_X509_DN_OID_* |
Since: 3.0
int gnutls_x509_crt_get_extension_oid (gnutls_x509_crt_t cert,unsigned indx,void *oid,size_t *oid_size);
This function will return the requested extension OID in the certificate. The extension OID will be stored as a string in the provided buffer.
The oid
returned will be null terminated, although oid_size
will not
account for the trailing null.
cert |
should contain a gnutls_x509_crt_t type |
|
indx |
Specifies which extension OID to send. Use (0) to get the first one. |
|
oid |
a pointer to a structure to hold the OID (may be null) |
|
oid_size |
initially holds the size of |
On success, GNUTLS_E_SUCCESS (0) is returned,
otherwise a negative error code is returned. If you have reached the
last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
will be returned.
int gnutls_x509_crt_get_extension_by_oid (gnutls_x509_crt_t cert,const char *oid,unsigned indx,void *buf,size_t *buf_size,unsigned int *critical);
This function will return the extension specified by the OID in the certificate. The extensions will be returned as binary data DER encoded, in the provided buffer.
cert |
should contain a gnutls_x509_crt_t type |
|
oid |
holds an Object Identified in null terminated string |
|
indx |
In case multiple same OIDs exist in the extensions, this specifies which to send. Use (0) to get the first one. |
|
buf |
a pointer to a structure to hold the name (may be null) |
|
buf_size |
initially holds the size of |
|
critical |
will be non-zero if the extension is marked as critical |
On success, GNUTLS_E_SUCCESS (0) is returned,
otherwise a negative error code is returned. If the certificate does not
contain the specified extension
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.
int
gnutls_x509_crq_get_signature_algorithm
(gnutls_x509_crq_t crq);
This function will return a value of the gnutls_sign_algorithm_t enumeration that is the signature algorithm that has been used to sign this certificate request.
Since 3.6.0 this function never returns a negative error code.
Error cases and unknown/unsupported signature algorithms are
mapped to GNUTLS_SIGN_UNKNOWN.
Since: 3.4.0
int gnutls_x509_crq_get_extension_by_oid2 (gnutls_x509_crq_t crq,const char *oid,unsigned indx,gnutls_datum_t *output,unsigned int *critical);
This function will return the extension specified by the OID in the certificate. The extensions will be returned as binary data DER encoded, in the provided buffer.
crq |
should contain a gnutls_x509_crq_t type |
|
oid |
holds an Object Identifier in a null terminated string |
|
indx |
In case multiple same OIDs exist in the extensions, this specifies which to get. Use (0) to get the first one. |
|
output |
will hold the allocated extension data |
|
critical |
will be non-zero if the extension is marked as critical |
On success, GNUTLS_E_SUCCESS (0) is returned, otherwise a
negative error code in case of an error. If the certificate does not
contain the specified extension
GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE will be returned.
Since: 3.3.8
int gnutls_x509_crt_get_extension_info (gnutls_x509_crt_t cert,unsigned indx,void *oid,size_t *oid_size,unsigned int *critical);
This function will return the requested extension OID in the
certificate, and the critical flag for it. The extension OID will
be stored as a string in the provided buffer. Use
gnutls_x509_crt_get_extension() to extract the data.
If the buffer provided is not long enough to hold the output, then
oid_size
is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will be
returned. The oid
returned will be null terminated, although
oid_size
will not account for the trailing null (the latter is not
true for GnuTLS prior to 3.6.0).
cert |
should contain a gnutls_x509_crt_t type |
|
indx |
Specifies which extension OID to send. Use (0) to get the first one. |
|
oid |
a pointer to a structure to hold the OID |
|
oid_size |
initially holds the maximum size of |
|
critical |
output variable with critical flag, may be NULL. |
On success, GNUTLS_E_SUCCESS (0) is returned,
otherwise a negative error code is returned. If you have reached the
last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
will be returned.
int gnutls_x509_crt_get_extension_data (gnutls_x509_crt_t cert,unsigned indx,void *data,size_t *sizeof_data);
This function will return the requested extension data in the certificate. The extension data will be stored in the provided buffer.
Use gnutls_x509_crt_get_extension_info() to extract the OID and
critical flag. Use gnutls_x509_crt_get_extension_by_oid() instead,
if you want to get data indexed by the extension OID rather than
sequence.
cert |
should contain a gnutls_x509_crt_t type |
|
indx |
Specifies which extension OID to send. Use (0) to get the first one. |
|
data |
a pointer to a structure to hold the data (may be null) |
|
sizeof_data |
initially holds the size of |
On success, GNUTLS_E_SUCCESS (0) is returned,
otherwise a negative error code is returned. If you have reached the
last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
will be returned.
int gnutls_x509_crt_get_extension_data2 (gnutls_x509_crt_t cert,unsigned indx,gnutls_datum_t *data);
This function will return the requested by the index extension data in the
certificate. The extension data will be allocated using
gnutls_malloc().
Use gnutls_x509_crt_get_extension_info() to extract the OID.
cert |
should contain a gnutls_x509_crt_t type |
|
indx |
Specifies which extension OID to read. Use (0) to get the first one. |
|
data |
will contain the extension DER-encoded data |
On success, GNUTLS_E_SUCCESS (0) is returned,
otherwise a negative error code is returned. If you have reached the
last extension available GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
will be returned.
int gnutls_x509_crt_set_extension_by_oid (gnutls_x509_crt_t crt,const char *oid,const void *buf,size_t sizeof_buf,unsigned int critical);
This function will set an the extension, by the specified OID, in the certificate. The extension data should be binary data DER encoded.
crt |
a certificate of type gnutls_x509_crt_t |
|
oid |
holds an Object Identifier in null terminated string |
|
buf |
a pointer to a DER encoded data |
|
sizeof_buf |
holds the size of |
|
critical |
should be non-zero if the extension is to be marked as critical |
int gnutls_x509_crt_set_dn (gnutls_x509_crt_t crt,const char *dn,const char **err);
This function will set the DN on the provided certificate.
The input string should be plain ASCII or UTF-8 encoded. On
DN parsing error GNUTLS_E_PARSING_ERROR is returned.
Note that DNs are not expected to hold DNS information, and thus
no automatic IDNA conversions are attempted when using this function.
If that is required (e.g., store a domain in CN), process the corresponding
input with gnutls_idna_map().
crt |
a certificate of type gnutls_x509_crt_t |
|
dn |
a comma separated DN string (RFC4514) |
|
err |
indicates the error position (if any) |
int gnutls_x509_crt_set_dn_by_oid (gnutls_x509_crt_t crt,const char *oid,unsigned int raw_flag,const void *name,unsigned int sizeof_name);
This function will set the part of the name of the Certificate subject, specified by the given OID. The input string should be ASCII or UTF-8 encoded.
Some helper macros with popular OIDs can be found in gnutls/x509.h
With this function you can only set the known OIDs. You can test
for known OIDs using gnutls_x509_dn_oid_known(). For OIDs that are
not known (by gnutls) you should properly DER encode your data,
and call this function with raw_flag
set.
crt |
a certificate of type gnutls_x509_crt_t |
|
oid |
holds an Object Identifier in a null terminated string |
|
raw_flag |
must be 0, or 1 if the data are DER encoded |
|
name |
a pointer to the name |
|
sizeof_name |
holds the size of |
int gnutls_x509_crt_set_issuer_dn_by_oid (gnutls_x509_crt_t crt,const char *oid,unsigned int raw_flag,const void *name,unsigned int sizeof_name);
This function will set the part of the name of the Certificate issuer, specified by the given OID. The input string should be ASCII or UTF-8 encoded.
Some helper macros with popular OIDs can be found in gnutls/x509.h
With this function you can only set the known OIDs. You can test
for known OIDs using gnutls_x509_dn_oid_known(). For OIDs that are
not known (by gnutls) you should properly DER encode your data,
and call this function with raw_flag
set.
Normally you do not need to call this function, since the signing operation will copy the signer's name as the issuer of the certificate.
crt |
a certificate of type gnutls_x509_crt_t |
|
oid |
holds an Object Identifier in a null terminated string |
|
raw_flag |
must be 0, or 1 if the data are DER encoded |
|
name |
a pointer to the name |
|
sizeof_name |
holds the size of |
int gnutls_x509_crt_set_issuer_dn (gnutls_x509_crt_t crt,const char *dn,const char **err);
This function will set the DN on the provided certificate.
The input string should be plain ASCII or UTF-8 encoded. On
DN parsing error GNUTLS_E_PARSING_ERROR is returned.
crt |
a certificate of type gnutls_x509_crt_t |
|
dn |
a comma separated DN string (RFC4514) |
|
err |
indicates the error position (if any) |
int gnutls_x509_crt_set_version (gnutls_x509_crt_t crt,unsigned int version);
This function will set the version of the certificate. This must be one for X.509 version 1, and so on. Plain certificates without extensions must have version set to one.
To create well-formed certificates, you must specify version 3 if
you use any certificate extensions. Extensions are created by
functions such as gnutls_x509_crt_set_subject_alt_name()
or gnutls_x509_crt_set_key_usage().
crt |
a certificate of type gnutls_x509_crt_t |
|
version |
holds the version number. For X.509v1 certificates must be 1. |
int gnutls_x509_crt_set_key (gnutls_x509_crt_t crt,gnutls_x509_privkey_t key);
This function will set the public parameters from the given private key to the certificate.
To export the public key (i.e., the SubjectPublicKeyInfo part), check
gnutls_pubkey_import_x509().
int gnutls_x509_crt_set_ca_status (gnutls_x509_crt_t crt,unsigned int ca);
This function will set the basicConstraints certificate extension.
Use gnutls_x509_crt_set_basic_constraints() if you want to control
the pathLenConstraint field too.
crt |
a certificate of type gnutls_x509_crt_t |
|
ca |
true(1) or false(0). Depending on the Certificate authority status. |
int gnutls_x509_crt_set_basic_constraints (gnutls_x509_crt_t crt,unsigned int ca,int pathLenConstraint);
This function will set the basicConstraints certificate extension.
crt |
a certificate of type gnutls_x509_crt_t |
|
ca |
true(1) or false(0). Depending on the Certificate authority status. |
|
pathLenConstraint |
non-negative error codes indicate maximum length of path, and negative error codes indicate that the pathLenConstraints field should not be present. |
int gnutls_x509_crt_set_subject_unique_id (gnutls_x509_crt_t cert,const void *id,size_t id_size);
This function will set the X.509 certificate's subject unique ID field.
cert |
a certificate of type gnutls_x509_crt_t |
|
id |
The unique ID |
|
id_size |
Holds the size of the unique ID. |
Since: 3.4.7
int gnutls_x509_crt_set_issuer_unique_id (gnutls_x509_crt_t cert,const void *id,size_t id_size);
This function will set the X.509 certificate's issuer unique ID field.
cert |
a certificate of type gnutls_x509_crt_t |
|
id |
The unique ID |
|
id_size |
Holds the size of the unique ID. |
Since: 3.4.7
int gnutls_x509_crt_set_subject_alternative_name (gnutls_x509_crt_t crt,gnutls_x509_subject_alt_name_t type,const char *data_string);
This function will set the subject alternative name certificate extension. This function assumes that data can be expressed as a null terminated string.
The name of the function is unfortunate since it is inconsistent with
gnutls_x509_crt_get_subject_alt_name().
See gnutls_x509_crt_set_subject_alt_name() for more information.
crt |
a certificate of type gnutls_x509_crt_t |
|
type |
is one of the gnutls_x509_subject_alt_name_t enumerations |
|
data_string |
The data to be set, a (0) terminated string |
int gnutls_x509_crt_set_subject_alt_name (gnutls_x509_crt_t crt,gnutls_x509_subject_alt_name_t type,const void *data,unsigned int data_size,unsigned int flags);
This function will set the subject alternative name certificate
extension. It can set the following types: GNUTLS_SAN_DNSNAME as a text string,
GNUTLS_SAN_RFC822NAME as a text string, GNUTLS_SAN_URI as a text string,
GNUTLS_SAN_IPADDRESS as a binary IP address (4 or 16 bytes),
GNUTLS_SAN_OTHERNAME_XMPP as a UTF8 string (since 3.5.0).
Since version 3.5.7 the GNUTLS_SAN_RFC822NAME, GNUTLS_SAN_DNSNAME, and
GNUTLS_SAN_OTHERNAME_XMPP are converted to ACE format when necessary.
crt |
a certificate of type gnutls_x509_crt_t |
|
type |
is one of the gnutls_x509_subject_alt_name_t enumerations |
|
data |
The data to be set |
|
data_size |
The size of data to be set |
|
flags |
GNUTLS_FSAN_SET to clear previous data or GNUTLS_FSAN_APPEND to append. |
Since: 2.6.0
int gnutls_x509_crt_set_subject_alt_othername (gnutls_x509_crt_t crt,const char *oid,const void *data,unsigned int data_size,unsigned int flags);
This function will set an "othername" to the subject alternative name certificate extension.
The values set are set as binary values and are expected to have the proper DER encoding.
For convenience the flags GNUTLS_FSAN_ENCODE_OCTET_STRING and GNUTLS_FSAN_ENCODE_UTF8_STRING
can be used to encode the provided data.
crt |
a certificate of type gnutls_x509_crt_t |
|
oid |
The other name OID |
|
data |
The data to be set |
|
data_size |
The size of data to be set |
|
flags |
GNUTLS_FSAN_SET to clear previous data or GNUTLS_FSAN_APPEND to append. |
Since: 3.5.0
int gnutls_x509_crt_set_issuer_alt_name (gnutls_x509_crt_t crt,gnutls_x509_subject_alt_name_t type,const void *data,unsigned int data_size,unsigned int flags);
This function will set the issuer alternative name certificate
extension. It can set the same types as gnutls_x509_crt_set_subject_alt_name().
Since version 3.5.7 the GNUTLS_SAN_RFC822NAME, GNUTLS_SAN_DNSNAME, and
GNUTLS_SAN_OTHERNAME_XMPP are converted to ACE format when necessary.
crt |
a certificate of type gnutls_x509_crt_t |
|
type |
is one of the gnutls_x509_subject_alt_name_t enumerations |
|
data |
The data to be set |
|
data_size |
The size of data to be set |
|
flags |
GNUTLS_FSAN_SET to clear previous data or GNUTLS_FSAN_APPEND to append. |
Since: 3.3.0
int gnutls_x509_crt_set_issuer_alt_othername (gnutls_x509_crt_t crt,const char *oid,const void *data,unsigned int data_size,unsigned int flags);
This function will set an "othername" to the issuer alternative name certificate extension.
The values set are set as binary values and are expected to have the proper DER encoding.
For convenience the flags GNUTLS_FSAN_ENCODE_OCTET_STRING and GNUTLS_FSAN_ENCODE_UTF8_STRING
can be used to encode the provided data.
crt |
a certificate of type gnutls_x509_crt_t |
|
oid |
The other name OID |
|
data |
The data to be set |
|
data_size |
The size of data to be set |
|
flags |
GNUTLS_FSAN_SET to clear previous data or GNUTLS_FSAN_APPEND to append. |
Since: 3.5.0
int gnutls_x509_crt_sign (gnutls_x509_crt_t crt,gnutls_x509_crt_t issuer,gnutls_x509_privkey_t issuer_key);
This function is the same a gnutls_x509_crt_sign2() with no flags,
and an appropriate hash algorithm. The hash algorithm used may
vary between versions of GnuTLS, and it is tied to the security
level of the issuer's public key.
crt |
a certificate of type gnutls_x509_crt_t |
|
issuer |
is the certificate of the certificate issuer |
|
issuer_key |
holds the issuer's private key |
int gnutls_x509_crt_sign2 (gnutls_x509_crt_t crt,gnutls_x509_crt_t issuer,gnutls_x509_privkey_t issuer_key,gnutls_digest_algorithm_t dig,unsigned int flags);
This function will sign the certificate with the issuer's private key, and will copy the issuer's information into the certificate.
This must be the last step in a certificate generation since all the previously set parameters are now signed.
A known limitation of this function is, that a newly-signed certificate will not be fully functional (e.g., for signature verification), until it is exported an re-imported.
After GnuTLS 3.6.1 the value of dig
may be GNUTLS_DIG_UNKNOWN,
and in that case, a suitable but reasonable for the key algorithm will be selected.
crt |
a certificate of type gnutls_x509_crt_t |
|
issuer |
is the certificate of the certificate issuer |
|
issuer_key |
holds the issuer's private key |
|
dig |
The message digest to use, |
|
flags |
must be 0 |
int gnutls_x509_crt_set_activation_time (gnutls_x509_crt_t cert,time_t act_time);
This function will set the time this certificate was or will be activated.
int gnutls_x509_crt_set_expiration_time (gnutls_x509_crt_t cert,time_t exp_time);
This function will set the time this Certificate will expire. Setting an expiration time to (time_t)-1 will set to the no well-defined expiration date value.
int gnutls_x509_crt_set_serial (gnutls_x509_crt_t cert,const void *serial,size_t serial_size);
This function will set the X.509 certificate's serial number.
While the serial number is an integer, it is often handled
as an opaque field by several CAs. For this reason this function
accepts any kind of data as a serial number. To be consistent
with the X.509/PKIX specifications the provided serial
should be
a big-endian positive number (i.e. its leftmost bit should be zero).
The size of the serial is restricted to 20 bytes maximum by RFC5280. This function allows writing more than 20 bytes but the generated certificates in that case may be rejected by other implementations.
cert |
a certificate of type gnutls_x509_crt_t |
|
serial |
The serial number |
|
serial_size |
Holds the size of the serial field. |
int gnutls_x509_crt_set_subject_key_id (gnutls_x509_crt_t cert,const void *id,size_t id_size);
This function will set the X.509 certificate's subject key ID extension.
cert |
a certificate of type gnutls_x509_crt_t |
|
id |
The key ID |
|
id_size |
Holds the size of the subject key ID field. |
int gnutls_x509_crt_set_proxy_dn (gnutls_x509_crt_t crt,gnutls_x509_crt_t eecrt,unsigned int raw_flag,const void *name,unsigned int sizeof_name);
This function will set the subject in crt
to the end entity's
eecrt
subject name, and add a single Common Name component name
of size sizeof_name
. This corresponds to the required proxy
certificate naming style. Note that if name
is NULL, you MUST
set it later by using gnutls_x509_crt_set_dn_by_oid() or similar.
int gnutls_x509_crt_set_proxy (gnutls_x509_crt_t crt,int pathLenConstraint,const char *policyLanguage,const char *policy,size_t sizeof_policy);
This function will set the proxyCertInfo extension.
crt |
a certificate of type gnutls_x509_crt_t |
|
pathLenConstraint |
non-negative error codes indicate maximum length of path, and negative error codes indicate that the pathLenConstraints field should not be present. |
|
policyLanguage |
OID describing the language of |
|
policy |
uint8_t byte array with policy language, can be |
|
sizeof_policy |
size of |
int gnutls_x509_crt_print (gnutls_x509_crt_t cert,gnutls_certificate_print_formats_t format,gnutls_datum_t *out);
This function will pretty print a X.509 certificate, suitable for display to a human.
If the format is GNUTLS_CRT_PRINT_FULL then all fields of the
certificate will be output, on multiple lines. The
GNUTLS_CRT_PRINT_ONELINE format will generate one line with some
selected fields, which is useful for logging purposes.
The output out
needs to be deallocated using gnutls_free().
int gnutls_x509_crl_print (gnutls_x509_crl_t crl,gnutls_certificate_print_formats_t format,gnutls_datum_t *out);
This function will pretty print a X.509 certificate revocation list, suitable for display to a human.
The output out
needs to be deallocated using gnutls_free().
int gnutls_x509_crt_get_raw_issuer_dn (gnutls_x509_crt_t cert,gnutls_datum_t *start);
This function will return a pointer to the DER encoded DN structure
and the length. This points to allocated data that must be free'd using gnutls_free().
On success, GNUTLS_E_SUCCESS (0) is returned, otherwise a
negative error value.or a negative error code on error.
int gnutls_x509_crt_get_raw_dn (gnutls_x509_crt_t cert,gnutls_datum_t *start);
This function will return a pointer to the DER encoded DN structure and
the length. This points to allocated data that must be free'd using gnutls_free().
On success, GNUTLS_E_SUCCESS (0) is returned, otherwise a
negative error value. or a negative error code on error.
int gnutls_x509_rdn_get (const gnutls_datum_t *idn,char *buf,size_t *sizeof_buf);
This function will return the name of the given RDN sequence. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514.
This function does not output a fully RFC4514 compliant string, if
that is required see gnutls_x509_rdn_get2().
idn |
should contain a DER encoded RDN sequence |
|
buf |
a pointer to a structure to hold the peer's name |
|
buf_size |
holds the size of |
On success, GNUTLS_E_SUCCESS (0) is returned, or
GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *buf_size
is
updated if the provided buffer is not long enough, otherwise a
negative error value.
int gnutls_x509_rdn_get2 (const gnutls_datum_t *idn,gnutls_datum_t *str,unsigned flags);
This function will return the name of the given RDN sequence. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514.
When the flag GNUTLS_X509_DN_FLAG_COMPAT is specified, the output
format will match the format output by previous to 3.5.6 versions of GnuTLS
which was not not fully RFC4514-compliant.
idn |
should contain a DER encoded RDN sequence |
|
str |
a datum that will hold the name |
|
flags |
zero of |
On success, GNUTLS_E_SUCCESS (0) is returned, or
GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *buf_size
is
updated if the provided buffer is not long enough, otherwise a
negative error value.
int gnutls_x509_rdn_get_oid (const gnutls_datum_t *idn,unsigned indx,void *buf,size_t *sizeof_buf);
This function will return the specified Object identifier, of the RDN sequence.
idn |
should contain a DER encoded RDN sequence |
|
indx |
Indicates which OID to return. Use 0 for the first one. |
|
buf |
a pointer to a structure to hold the peer's name OID |
|
buf_size |
holds the size of |
On success, GNUTLS_E_SUCCESS (0) is returned, or
GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *buf_size
is
updated if the provided buffer is not long enough, otherwise a
negative error value.
Since: 2.4.0
int gnutls_x509_rdn_get_by_oid (const gnutls_datum_t *idn,const char *oid,unsigned indx,unsigned int raw_flag,void *buf,size_t *sizeof_buf);
This function will return the name of the given Object identifier, of the RDN sequence. The name will be encoded using the rules from RFC4514.
idn |
should contain a DER encoded RDN sequence |
|
oid |
an Object Identifier |
|
indx |
In case multiple same OIDs exist in the RDN indicates which to send. Use 0 for the first one. |
|
raw_flag |
If non-zero then the raw DER data are returned. |
|
buf |
a pointer to a structure to hold the peer's name |
|
buf_size |
holds the size of |
On success, GNUTLS_E_SUCCESS (0) is returned, or
GNUTLS_E_SHORT_MEMORY_BUFFER is returned and *buf_size
is
updated if the provided buffer is not long enough, otherwise a
negative error value.
int gnutls_x509_crt_get_subject (gnutls_x509_crt_t cert,gnutls_x509_dn_t *dn);
Return the Certificate's Subject DN as a gnutls_x509_dn_t data type,
that can be decoded using gnutls_x509_dn_get_rdn_ava().
Note that dn
should be treated as constant. Because it points
into the cert
object, you should not use dn
after cert
is
deallocated.
cert |
should contain a gnutls_x509_crt_t type |
|
dn |
output variable with pointer to uint8_t DN. |
int gnutls_x509_crt_get_issuer (gnutls_x509_crt_t cert,gnutls_x509_dn_t *dn);
Return the Certificate's Issuer DN as a gnutls_x509_dn_t data type,
that can be decoded using gnutls_x509_dn_get_rdn_ava().
Note that dn
should be treated as constant. Because it points
into the cert
object, you should not use dn
after cert
is
deallocated.
cert |
should contain a gnutls_x509_crt_t type |
|
dn |
output variable with pointer to uint8_t DN |
int gnutls_x509_dn_get_rdn_ava (gnutls_x509_dn_t dn,int irdn,int iava,gnutls_x509_ava_st *ava);
Get pointers to data within the DN. The format of the ava
structure
is shown below.
struct gnutls_x509_ava_st { gnutls_datum_t oid; gnutls_datum_t value; unsigned long value_tag; };
The X.509 distinguished name is a sequence of sequences of strings
and this is what the irdn
and iava
indexes model.
Note that ava
will contain pointers into the dn
structure which
in turns points to the original certificate. Thus you should not
modify any data or deallocate any of those.
This is a low-level function that requires the caller to do the value conversions when necessary (e.g. from UCS-2).
int gnutls_x509_dn_get_str (gnutls_x509_dn_t dn,gnutls_datum_t *str);
This function will allocate buffer and copy the name in the provided DN. The name will be in the form "C=xxxx,O=yyyy,CN=zzzz" as described in RFC4514. The output string will be ASCII or UTF-8 encoded, depending on the certificate data.
When the flag GNUTLS_X509_DN_FLAG_COMPAT is specified, the output
format will match the format output by previous to 3.5.6 versions of GnuTLS
which was not not fully RFC4514-compliant.