This is gnutls.info, produced by makeinfo version 6.3 from gnutls.texi.
This manual is last updated 23 March 2015 for version 3.3.27 of GnuTLS.
Copyright (C) 2001-2013 Free Software Foundation, Inc.\\ Copyright (C)
2001-2013 Nikos Mavrogiannopoulos
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts, and
no Back-Cover Texts. A copy of the license is included in the
section entitled "GNU Free Documentation License".
INFO-DIR-SECTION Software libraries
START-INFO-DIR-ENTRY
* GnuTLS: (gnutls). GNU Transport Layer Security Library.
END-INFO-DIR-ENTRY
INFO-DIR-SECTION System Administration
START-INFO-DIR-ENTRY
* certtool: (gnutls)Invoking certtool. Manipulate certificates and keys.
* gnutls-serv: (gnutls)Invoking gnutls-serv. GnuTLS test server.
* gnutls-cli: (gnutls)Invoking gnutls-cli. GnuTLS test client.
* gnutls-cli-debug: (gnutls)Invoking gnutls-cli-debug. GnuTLS debug client.
* psktool: (gnutls)Invoking psktool. Simple TLS-Pre-Shared-Keys manager.
* srptool: (gnutls)Invoking srptool. Simple SRP password tool.
END-INFO-DIR-ENTRY
File: gnutls.info, Node: OCSP API, Next: OpenPGP API, Prev: X509 certificate API, Up: API reference
E.4 OCSP API
============
The following functions are for OCSP certificate status checking. Their
prototypes lie in 'gnutls/ocsp.h'.
gnutls_ocsp_req_add_cert
------------------------
-- Function: int gnutls_ocsp_req_add_cert (gnutls_ocsp_req_t REQ,
gnutls_digest_algorithm_t DIGEST, gnutls_x509_crt_t ISSUER,
gnutls_x509_crt_t CERT)
REQ: should contain a 'gnutls_ocsp_req_t' structure
DIGEST: hash algorithm, a 'gnutls_digest_algorithm_t' value
ISSUER: issuer of 'subject' certificate
CERT: certificate to request status for
This function will add another request to the OCSP request for a
particular certificate. The issuer name hash, issuer key hash, and
serial number fields is populated as follows. The issuer name and
the serial number is taken from 'cert' . The issuer key is taken
from 'issuer' . The hashed values will be hashed using the
'digest' algorithm, normally 'GNUTLS_DIG_SHA1' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_req_add_cert_id
---------------------------
-- Function: int gnutls_ocsp_req_add_cert_id (gnutls_ocsp_req_t REQ,
gnutls_digest_algorithm_t DIGEST, const gnutls_datum_t *
ISSUER_NAME_HASH, const gnutls_datum_t * ISSUER_KEY_HASH,
const gnutls_datum_t * SERIAL_NUMBER)
REQ: should contain a 'gnutls_ocsp_req_t' structure
DIGEST: hash algorithm, a 'gnutls_digest_algorithm_t' value
ISSUER_NAME_HASH: hash of issuer's DN
ISSUER_KEY_HASH: hash of issuer's public key
SERIAL_NUMBER: serial number of certificate to check
This function will add another request to the OCSP request for a
particular certificate having the issuer name hash of
'issuer_name_hash' and issuer key hash of 'issuer_key_hash' (both
hashed using 'digest' ) and serial number 'serial_number' .
The information needed corresponds to the CertID structure:
CertID ::= SEQUENCE {
hashAlgorithm AlgorithmIdentifier, issuerNameHash OCTET STRING, -
Hash of Issuer's DN issuerKeyHash OCTET STRING, - Hash of Issuers
public key serialNumber CertificateSerialNumber }
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_req_deinit
----------------------
-- Function: void gnutls_ocsp_req_deinit (gnutls_ocsp_req_t REQ)
REQ: The structure to be deinitialized
This function will deinitialize a OCSP request structure.
gnutls_ocsp_req_export
----------------------
-- Function: int gnutls_ocsp_req_export (gnutls_ocsp_req_t REQ,
gnutls_datum_t * DATA)
REQ: Holds the OCSP request
DATA: newly allocate buffer holding DER encoded OCSP request
This function will export the OCSP request to DER format.
*Returns:* In case of failure a negative error code will be
returned, and 0 on success.
gnutls_ocsp_req_get_cert_id
---------------------------
-- Function: int gnutls_ocsp_req_get_cert_id (gnutls_ocsp_req_t REQ,
unsigned INDX, gnutls_digest_algorithm_t * DIGEST,
gnutls_datum_t * ISSUER_NAME_HASH, gnutls_datum_t *
ISSUER_KEY_HASH, gnutls_datum_t * SERIAL_NUMBER)
REQ: should contain a 'gnutls_ocsp_req_t' structure
INDX: Specifies which extension OID to get. Use (0) to get the
first one.
DIGEST: output variable with 'gnutls_digest_algorithm_t' hash
algorithm
ISSUER_NAME_HASH: output buffer with hash of issuer's DN
ISSUER_KEY_HASH: output buffer with hash of issuer's public key
SERIAL_NUMBER: output buffer with serial number of certificate to
check
This function will return the certificate information of the 'indx'
'ed request in the OCSP request. The information returned
corresponds to the CertID structure:
CertID ::= SEQUENCE {
hashAlgorithm AlgorithmIdentifier, issuerNameHash OCTET STRING, -
Hash of Issuer's DN issuerKeyHash OCTET STRING, - Hash of Issuers
public key serialNumber CertificateSerialNumber }
Each of the pointers to output variables may be NULL to indicate
that the caller is not interested in that value.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned. If you have reached
the last CertID available 'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE'
will be returned.
gnutls_ocsp_req_get_extension
-----------------------------
-- Function: int gnutls_ocsp_req_get_extension (gnutls_ocsp_req_t REQ,
unsigned INDX, gnutls_datum_t * OID, unsigned int * CRITICAL,
gnutls_datum_t * DATA)
REQ: should contain a 'gnutls_ocsp_req_t' structure
INDX: Specifies which extension OID to get. Use (0) to get the
first one.
OID: will hold newly allocated buffer with OID of extension, may be
NULL
CRITICAL: output variable with critical flag, may be NULL.
DATA: will hold newly allocated buffer with extension data, may be
NULL
This function will return all information about the requested
extension in the OCSP request. The information returned is the
OID, the critical flag, and the data itself. The extension OID
will be stored as a string. Any of 'oid' , 'critical' , and 'data'
may be NULL which means that the caller is not interested in
getting that information back.
The caller needs to deallocate memory by calling 'gnutls_free()' on
'oid' ->data and 'data' ->data.
*Returns:* 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.
gnutls_ocsp_req_get_nonce
-------------------------
-- Function: int gnutls_ocsp_req_get_nonce (gnutls_ocsp_req_t REQ,
unsigned int * CRITICAL, gnutls_datum_t * NONCE)
REQ: should contain a 'gnutls_ocsp_req_t' structure
CRITICAL: whether nonce extension is marked critical, or NULL
NONCE: will hold newly allocated buffer with nonce data
This function will return the OCSP request nonce extension data.
The caller needs to deallocate memory by calling 'gnutls_free()' on
'nonce' ->data.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_req_get_version
---------------------------
-- Function: int gnutls_ocsp_req_get_version (gnutls_ocsp_req_t REQ)
REQ: should contain a 'gnutls_ocsp_req_t' structure
This function will return the version of the OCSP request.
Typically this is always 1 indicating version 1.
*Returns:* version of OCSP request, or a negative error code on
error.
gnutls_ocsp_req_import
----------------------
-- Function: int gnutls_ocsp_req_import (gnutls_ocsp_req_t REQ, const
gnutls_datum_t * DATA)
REQ: The structure to store the parsed request.
DATA: DER encoded OCSP request.
This function will convert the given DER encoded OCSP request to
the native 'gnutls_ocsp_req_t' format. The output will be stored
in 'req' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_req_init
--------------------
-- Function: int gnutls_ocsp_req_init (gnutls_ocsp_req_t * REQ)
REQ: The structure to be initialized
This function will initialize an OCSP request structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_req_print
---------------------
-- Function: int gnutls_ocsp_req_print (gnutls_ocsp_req_t REQ,
gnutls_ocsp_print_formats_t FORMAT, gnutls_datum_t * OUT)
REQ: The structure to be printed
FORMAT: Indicate the format to use
OUT: Newly allocated datum with (0) terminated string.
This function will pretty print a OCSP request, suitable for
display to a human.
If the format is 'GNUTLS_OCSP_PRINT_FULL' then all fields of the
request will be output, on multiple lines.
The output 'out' ->data needs to be deallocate using
'gnutls_free()' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_req_randomize_nonce
-------------------------------
-- Function: int gnutls_ocsp_req_randomize_nonce (gnutls_ocsp_req_t
REQ)
REQ: should contain a 'gnutls_ocsp_req_t' structure
This function will add or update an nonce extension to the OCSP
request with a newly generated random value.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_req_set_extension
-----------------------------
-- Function: int gnutls_ocsp_req_set_extension (gnutls_ocsp_req_t REQ,
const char * OID, unsigned int CRITICAL, const gnutls_datum_t
* DATA)
REQ: should contain a 'gnutls_ocsp_req_t' structure
OID: buffer with OID of extension as a string.
CRITICAL: critical flag, normally false.
DATA: the extension data
This function will add an extension to the OCSP request. Calling
this function multiple times for the same OID will overwrite values
from earlier calls.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_req_set_nonce
-------------------------
-- Function: int gnutls_ocsp_req_set_nonce (gnutls_ocsp_req_t REQ,
unsigned int CRITICAL, const gnutls_datum_t * NONCE)
REQ: should contain a 'gnutls_ocsp_req_t' structure
CRITICAL: critical flag, normally false.
NONCE: the nonce data
This function will add an nonce extension to the OCSP request.
Calling this function multiple times will overwrite values from
earlier calls.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_resp_check_crt
--------------------------
-- Function: int gnutls_ocsp_resp_check_crt (gnutls_ocsp_resp_t RESP,
unsigned int INDX, gnutls_x509_crt_t CRT)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
INDX: Specifies response number to get. Use (0) to get the first
one.
CRT: The certificate to check
This function will check whether the OCSP response is about the
provided certificate.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
*Since:* 3.1.3
gnutls_ocsp_resp_deinit
-----------------------
-- Function: void gnutls_ocsp_resp_deinit (gnutls_ocsp_resp_t RESP)
RESP: The structure to be deinitialized
This function will deinitialize a OCSP response structure.
gnutls_ocsp_resp_export
-----------------------
-- Function: int gnutls_ocsp_resp_export (gnutls_ocsp_resp_t RESP,
gnutls_datum_t * DATA)
RESP: Holds the OCSP response
DATA: newly allocate buffer holding DER encoded OCSP response
This function will export the OCSP response to DER format.
*Returns:* In case of failure a negative error code will be
returned, and 0 on success.
gnutls_ocsp_resp_get_certs
--------------------------
-- Function: int gnutls_ocsp_resp_get_certs (gnutls_ocsp_resp_t RESP,
gnutls_x509_crt_t ** CERTS, size_t * NCERTS)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
CERTS: newly allocated array with 'gnutls_x509_crt_t' certificates
NCERTS: output variable with number of allocated certs.
This function will extract the X.509 certificates found in the
Basic OCSP Response. The 'certs' output variable will hold a newly
allocated zero-terminated array with X.509 certificates.
Every certificate in the array needs to be de-allocated with
'gnutls_x509_crt_deinit()' and the array itself must be freed using
'gnutls_free()' .
Both the 'certs' and 'ncerts' variables may be NULL. Then the
function will work as normal but will not return the NULL:d
information. This can be used to get the number of certificates
only, or to just get the certificate array without its size.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_get_extension
------------------------------
-- Function: int gnutls_ocsp_resp_get_extension (gnutls_ocsp_resp_t
RESP, unsigned INDX, gnutls_datum_t * OID, unsigned int *
CRITICAL, gnutls_datum_t * DATA)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
INDX: Specifies which extension OID to get. Use (0) to get the
first one.
OID: will hold newly allocated buffer with OID of extension, may be
NULL
CRITICAL: output variable with critical flag, may be NULL.
DATA: will hold newly allocated buffer with extension data, may be
NULL
This function will return all information about the requested
extension in the OCSP response. The information returned is the
OID, the critical flag, and the data itself. The extension OID
will be stored as a string. Any of 'oid' , 'critical' , and 'data'
may be NULL which means that the caller is not interested in
getting that information back.
The caller needs to deallocate memory by calling 'gnutls_free()' on
'oid' ->data and 'data' ->data.
*Returns:* 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.
gnutls_ocsp_resp_get_nonce
--------------------------
-- Function: int gnutls_ocsp_resp_get_nonce (gnutls_ocsp_resp_t RESP,
unsigned int * CRITICAL, gnutls_datum_t * NONCE)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
CRITICAL: whether nonce extension is marked critical
NONCE: will hold newly allocated buffer with nonce data
This function will return the Basic OCSP Response nonce extension
data.
The caller needs to deallocate memory by calling 'gnutls_free()' on
'nonce' ->data.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_resp_get_produced
-----------------------------
-- Function: time_t gnutls_ocsp_resp_get_produced (gnutls_ocsp_resp_t
RESP)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
This function will return the time when the OCSP response was
signed.
*Returns:* signing time, or (time_t)-1 on error.
gnutls_ocsp_resp_get_responder
------------------------------
-- Function: int gnutls_ocsp_resp_get_responder (gnutls_ocsp_resp_t
RESP, gnutls_datum_t * DN)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
DN: newly allocated buffer with name
This function will extract the name of the Basic OCSP Response in
the provided buffer. The name will be in the form
"C=xxxx,O=yyyy,CN=zzzz" as described in RFC2253. The output string
will be ASCII or UTF-8 encoded, depending on the certificate data.
The caller needs to deallocate memory by calling 'gnutls_free()' on
'dn' ->data.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_ocsp_resp_get_response
-----------------------------
-- Function: int gnutls_ocsp_resp_get_response (gnutls_ocsp_resp_t
RESP, gnutls_datum_t * RESPONSE_TYPE_OID, gnutls_datum_t *
RESPONSE)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
RESPONSE_TYPE_OID: newly allocated output buffer with response type
OID
RESPONSE: newly allocated output buffer with DER encoded response
This function will extract the response type OID in and the
response data from an OCSP response. Normally the
'response_type_oid' is always "1.3.6.1.5.5.7.48.1.1" which means
the 'response' should be decoded as a Basic OCSP Response, but
technically other response types could be used.
This function is typically only useful when you want to extract the
response type OID of an response for diagnostic purposes.
Otherwise 'gnutls_ocsp_resp_import()' will decode the basic OCSP
response part and the caller need not worry about that aspect.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_get_signature
------------------------------
-- Function: int gnutls_ocsp_resp_get_signature (gnutls_ocsp_resp_t
RESP, gnutls_datum_t * SIG)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
SIG: newly allocated output buffer with signature data
This function will extract the signature field of a OCSP response.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_get_signature_algorithm
----------------------------------------
-- Function: int gnutls_ocsp_resp_get_signature_algorithm
(gnutls_ocsp_resp_t RESP)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
This function will return a value of the 'gnutls_sign_algorithm_t'
enumeration that is the signature algorithm that has been used to
sign the OCSP response.
*Returns:* a 'gnutls_sign_algorithm_t' value, or a negative error
code on error.
gnutls_ocsp_resp_get_single
---------------------------
-- Function: int gnutls_ocsp_resp_get_single (gnutls_ocsp_resp_t RESP,
unsigned INDX, gnutls_digest_algorithm_t * DIGEST,
gnutls_datum_t * ISSUER_NAME_HASH, gnutls_datum_t *
ISSUER_KEY_HASH, gnutls_datum_t * SERIAL_NUMBER, unsigned int
* CERT_STATUS, time_t * THIS_UPDATE, time_t * NEXT_UPDATE,
time_t * REVOCATION_TIME, unsigned int * REVOCATION_REASON)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
INDX: Specifies response number to get. Use (0) to get the first
one.
DIGEST: output variable with 'gnutls_digest_algorithm_t' hash
algorithm
ISSUER_NAME_HASH: output buffer with hash of issuer's DN
ISSUER_KEY_HASH: output buffer with hash of issuer's public key
SERIAL_NUMBER: output buffer with serial number of certificate to
check
CERT_STATUS: a certificate status, a 'gnutls_ocsp_cert_status_t'
enum.
THIS_UPDATE: time at which the status is known to be correct.
NEXT_UPDATE: when newer information will be available, or
(time_t)-1 if unspecified
REVOCATION_TIME: when 'cert_status' is 'GNUTLS_OCSP_CERT_REVOKED' ,
holds time of revocation.
REVOCATION_REASON: revocation reason, a 'gnutls_x509_crl_reason_t'
enum.
This function will return the certificate information of the 'indx'
'ed response in the Basic OCSP Response 'resp' . The information
returned corresponds to the OCSP SingleResponse structure except
the final singleExtensions.
Each of the pointers to output variables may be NULL to indicate
that the caller is not interested in that value.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned. If you have reached
the last CertID available 'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE'
will be returned.
gnutls_ocsp_resp_get_status
---------------------------
-- Function: int gnutls_ocsp_resp_get_status (gnutls_ocsp_resp_t RESP)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
This function will return the status of a OCSP response, an
'gnutls_ocsp_resp_status_t' enumeration.
*Returns:* status of OCSP request as a 'gnutls_ocsp_resp_status_t'
, or a negative error code on error.
gnutls_ocsp_resp_get_version
----------------------------
-- Function: int gnutls_ocsp_resp_get_version (gnutls_ocsp_resp_t RESP)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
This function will return the version of the Basic OCSP Response.
Typically this is always 1 indicating version 1.
*Returns:* version of Basic OCSP response, or a negative error code
on error.
gnutls_ocsp_resp_import
-----------------------
-- Function: int gnutls_ocsp_resp_import (gnutls_ocsp_resp_t RESP,
const gnutls_datum_t * DATA)
RESP: The structure to store the parsed response.
DATA: DER encoded OCSP response.
This function will convert the given DER encoded OCSP response to
the native 'gnutls_ocsp_resp_t' format. It also decodes the Basic
OCSP Response part, if any. The output will be stored in 'resp' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_init
---------------------
-- Function: int gnutls_ocsp_resp_init (gnutls_ocsp_resp_t * RESP)
RESP: The structure to be initialized
This function will initialize an OCSP response structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_print
----------------------
-- Function: int gnutls_ocsp_resp_print (gnutls_ocsp_resp_t RESP,
gnutls_ocsp_print_formats_t FORMAT, gnutls_datum_t * OUT)
RESP: The structure to be printed
FORMAT: Indicate the format to use
OUT: Newly allocated datum with (0) terminated string.
This function will pretty print a OCSP response, suitable for
display to a human.
If the format is 'GNUTLS_OCSP_PRINT_FULL' then all fields of the
response will be output, on multiple lines.
The output 'out' ->data needs to be deallocate using
'gnutls_free()' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_verify
-----------------------
-- Function: int gnutls_ocsp_resp_verify (gnutls_ocsp_resp_t RESP,
gnutls_x509_trust_list_t TRUSTLIST, unsigned int * VERIFY,
unsigned int FLAGS)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
TRUSTLIST: trust anchors as a 'gnutls_x509_trust_list_t' structure
VERIFY: output variable with verification status, an
'gnutls_ocsp_cert_status_t'
FLAGS: verification flags, 0 for now.
Verify signature of the Basic OCSP Response against the public key
in the certificate of a trusted signer. The 'trustlist' should be
populated with trust anchors. The function will extract the signer
certificate from the Basic OCSP Response and will verify it against
the 'trustlist' . A trusted signer is a certificate that is either
in 'trustlist' , or it is signed directly by a certificate in
'trustlist' and has the id-ad-ocspSigning Extended Key Usage bit
set.
The output 'verify' variable will hold verification status codes
(e.g., 'GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND' ,
'GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM' ) which are only valid if
the function returned 'GNUTLS_E_SUCCESS' .
Note that the function returns 'GNUTLS_E_SUCCESS' even when
verification failed. The caller must always inspect the 'verify'
variable to find out the verification status.
The 'flags' variable should be 0 for now.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_ocsp_resp_verify_direct
------------------------------
-- Function: int gnutls_ocsp_resp_verify_direct (gnutls_ocsp_resp_t
RESP, gnutls_x509_crt_t ISSUER, unsigned int * VERIFY,
unsigned int FLAGS)
RESP: should contain a 'gnutls_ocsp_resp_t' structure
ISSUER: certificate believed to have signed the response
VERIFY: output variable with verification status, an
'gnutls_ocsp_cert_status_t'
FLAGS: verification flags, 0 for now.
Verify signature of the Basic OCSP Response against the public key
in the 'issuer' certificate.
The output 'verify' variable will hold verification status codes
(e.g., 'GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND' ,
'GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM' ) which are only valid if
the function returned 'GNUTLS_E_SUCCESS' .
Note that the function returns 'GNUTLS_E_SUCCESS' even when
verification failed. The caller must always inspect the 'verify'
variable to find out the verification status.
The 'flags' variable should be 0 for now.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
File: gnutls.info, Node: OpenPGP API, Next: PKCS 12 API, Prev: OCSP API, Up: API reference
E.5 OpenPGP API
===============
The following functions are to be used for OpenPGP certificate handling.
Their prototypes lie in 'gnutls/openpgp.h'.
gnutls_certificate_set_openpgp_key
----------------------------------
-- Function: int gnutls_certificate_set_openpgp_key
(gnutls_certificate_credentials_t RES, gnutls_openpgp_crt_t
CRT, gnutls_openpgp_privkey_t PKEY)
RES: is a 'gnutls_certificate_credentials_t' structure.
CRT: contains an openpgp public key
PKEY: is an openpgp private key
This function sets a certificate/private key pair in the
gnutls_certificate_credentials_t structure. This function may be
called more than once (in case multiple keys/certificates exist for
the server).
Note that this function requires that the preferred key ids have
been set and be used. See
'gnutls_openpgp_crt_set_preferred_key_id()' . Otherwise the master
key will be used.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_certificate_set_openpgp_key_file
---------------------------------------
-- Function: int gnutls_certificate_set_openpgp_key_file
(gnutls_certificate_credentials_t RES, const char * CERTFILE,
const char * KEYFILE, gnutls_openpgp_crt_fmt_t FORMAT)
RES: the destination context to save the data.
CERTFILE: the file that contains the public key.
KEYFILE: the file that contains the secret key.
FORMAT: the format of the keys
This funtion is used to load OpenPGP keys into the GnuTLS
credentials structure. The file should contain at least one valid
non encrypted subkey.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_certificate_set_openpgp_key_file2
----------------------------------------
-- Function: int gnutls_certificate_set_openpgp_key_file2
(gnutls_certificate_credentials_t RES, const char * CERTFILE,
const char * KEYFILE, const char * SUBKEY_ID,
gnutls_openpgp_crt_fmt_t FORMAT)
RES: the destination context to save the data.
CERTFILE: the file that contains the public key.
KEYFILE: the file that contains the secret key.
SUBKEY_ID: a hex encoded subkey id
FORMAT: the format of the keys
This funtion is used to load OpenPGP keys into the GnuTLS
credential structure. The file should contain at least one valid
non encrypted subkey.
The special keyword "auto" is also accepted as 'subkey_id' . In
that case the 'gnutls_openpgp_crt_get_auth_subkey()' will be used
to retrieve the subkey.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.4.0
gnutls_certificate_set_openpgp_key_mem
--------------------------------------
-- Function: int gnutls_certificate_set_openpgp_key_mem
(gnutls_certificate_credentials_t RES, const gnutls_datum_t *
CERT, const gnutls_datum_t * KEY, gnutls_openpgp_crt_fmt_t
FORMAT)
RES: the destination context to save the data.
CERT: the datum that contains the public key.
KEY: the datum that contains the secret key.
FORMAT: the format of the keys
This funtion is used to load OpenPGP keys into the GnuTLS
credential structure. The datum should contain at least one valid
non encrypted subkey.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_certificate_set_openpgp_key_mem2
---------------------------------------
-- Function: int gnutls_certificate_set_openpgp_key_mem2
(gnutls_certificate_credentials_t RES, const gnutls_datum_t *
CERT, const gnutls_datum_t * KEY, const char * SUBKEY_ID,
gnutls_openpgp_crt_fmt_t FORMAT)
RES: the destination context to save the data.
CERT: the datum that contains the public key.
KEY: the datum that contains the secret key.
SUBKEY_ID: a hex encoded subkey id
FORMAT: the format of the keys
This funtion is used to load OpenPGP keys into the GnuTLS
credentials structure. The datum should contain at least one valid
non encrypted subkey.
The special keyword "auto" is also accepted as 'subkey_id' . In
that case the 'gnutls_openpgp_crt_get_auth_subkey()' will be used
to retrieve the subkey.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.4.0
gnutls_certificate_set_openpgp_keyring_file
-------------------------------------------
-- Function: int gnutls_certificate_set_openpgp_keyring_file
(gnutls_certificate_credentials_t C, const char * FILE,
gnutls_openpgp_crt_fmt_t FORMAT)
C: A certificate credentials structure
FILE: filename of the keyring.
FORMAT: format of keyring.
The function is used to set keyrings that will be used internally
by various OpenPGP functions. For example to find a key when it is
needed for an operations. The keyring will also be used at the
verification functions.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_certificate_set_openpgp_keyring_mem
------------------------------------------
-- Function: int gnutls_certificate_set_openpgp_keyring_mem
(gnutls_certificate_credentials_t C, const uint8_t * DATA,
size_t DLEN, gnutls_openpgp_crt_fmt_t FORMAT)
C: A certificate credentials structure
DATA: buffer with keyring data.
DLEN: length of data buffer.
FORMAT: the format of the keyring
The function is used to set keyrings that will be used internally
by various OpenPGP functions. For example to find a key when it is
needed for an operations. The keyring will also be used at the
verification functions.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_openpgp_crt_check_hostname
---------------------------------
-- Function: int gnutls_openpgp_crt_check_hostname
(gnutls_openpgp_crt_t KEY, const char * HOSTNAME)
KEY: should contain a 'gnutls_openpgp_crt_t' structure
HOSTNAME: A null terminated string that contains a DNS name
This function will check if the given key's owner matches the given
hostname. This is a basic implementation of the matching described
in RFC2818 (HTTPS), which takes into account wildcards.
*Returns:* non-zero for a successful match, and zero on failure.
gnutls_openpgp_crt_check_hostname2
----------------------------------
-- Function: int gnutls_openpgp_crt_check_hostname2
(gnutls_openpgp_crt_t KEY, const char * HOSTNAME, unsigned
FLAGS)
KEY: should contain a 'gnutls_openpgp_crt_t' structure
HOSTNAME: A null terminated string that contains a DNS name
FLAGS: gnutls_certificate_verify_flags
This function will check if the given key's owner matches the given
hostname.
Unless, the flag 'GNUTLS_VERIFY_DO_NOT_ALLOW_WILDCARDS' is
specified, wildcards are only considered if the domain name
consists of three components or more, and the wildcard starts at
the leftmost position.
*Returns:* non-zero for a successful match, and zero on failure.
gnutls_openpgp_crt_deinit
-------------------------
-- Function: void gnutls_openpgp_crt_deinit (gnutls_openpgp_crt_t KEY)
KEY: The structure to be initialized
This function will deinitialize a key structure.
gnutls_openpgp_crt_export
-------------------------
-- Function: int gnutls_openpgp_crt_export (gnutls_openpgp_crt_t KEY,
gnutls_openpgp_crt_fmt_t FORMAT, void * OUTPUT_DATA, size_t *
OUTPUT_DATA_SIZE)
KEY: Holds the key.
FORMAT: One of gnutls_openpgp_crt_fmt_t elements.
OUTPUT_DATA: will contain the raw or base64 encoded key
OUTPUT_DATA_SIZE: holds the size of output_data (and will be
replaced by the actual size of parameters)
This function will convert the given key to RAW or Base64 format.
If the buffer provided is not long enough to hold the output, then
'GNUTLS_E_SHORT_MEMORY_BUFFER' will be returned.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_export2
--------------------------
-- Function: int gnutls_openpgp_crt_export2 (gnutls_openpgp_crt_t KEY,
gnutls_openpgp_crt_fmt_t FORMAT, gnutls_datum_t * OUT)
KEY: Holds the key.
FORMAT: One of gnutls_openpgp_crt_fmt_t elements.
OUT: will contain the raw or base64 encoded key
This function will convert the given key to RAW or Base64 format.
The output buffer is allocated using 'gnutls_malloc()' .
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
*Since:* 3.1.3
gnutls_openpgp_crt_get_auth_subkey
----------------------------------
-- Function: int gnutls_openpgp_crt_get_auth_subkey
(gnutls_openpgp_crt_t CRT, gnutls_openpgp_keyid_t KEYID,
unsigned int FLAG)
CRT: the structure that contains the OpenPGP public key.
KEYID: the struct to save the keyid.
FLAG: Non-zero indicates that a valid subkey is always returned.
Returns the 64-bit keyID of the first valid OpenPGP subkey marked
for authentication. If flag is non-zero and no authentication
subkey exists, then a valid subkey will be returned even if it is
not marked for authentication.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_get_creation_time
------------------------------------
-- Function: time_t gnutls_openpgp_crt_get_creation_time
(gnutls_openpgp_crt_t KEY)
KEY: the structure that contains the OpenPGP public key.
Get key creation time.
*Returns:* the timestamp when the OpenPGP key was created.
gnutls_openpgp_crt_get_expiration_time
--------------------------------------
-- Function: time_t gnutls_openpgp_crt_get_expiration_time
(gnutls_openpgp_crt_t KEY)
KEY: the structure that contains the OpenPGP public key.
Get key expiration time. A value of '0' means that the key doesn't
expire at all.
*Returns:* the time when the OpenPGP key expires.
gnutls_openpgp_crt_get_fingerprint
----------------------------------
-- Function: int gnutls_openpgp_crt_get_fingerprint
(gnutls_openpgp_crt_t KEY, void * FPR, size_t * FPRLEN)
KEY: the raw data that contains the OpenPGP public key.
FPR: the buffer to save the fingerprint, must hold at least 20
bytes.
FPRLEN: the integer to save the length of the fingerprint.
Get key fingerprint. Depending on the algorithm, the fingerprint
can be 16 or 20 bytes.
*Returns:* On success, 0 is returned. Otherwise, an error code.
gnutls_openpgp_crt_get_key_id
-----------------------------
-- Function: int gnutls_openpgp_crt_get_key_id (gnutls_openpgp_crt_t
KEY, gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP public key.
KEYID: the buffer to save the keyid.
Get key id string.
*Returns:* the 64-bit keyID of the OpenPGP key.
*Since:* 2.4.0
gnutls_openpgp_crt_get_key_usage
--------------------------------
-- Function: int gnutls_openpgp_crt_get_key_usage (gnutls_openpgp_crt_t
KEY, unsigned int * KEY_USAGE)
KEY: should contain a gnutls_openpgp_crt_t structure
KEY_USAGE: where the key usage bits will be stored
This function will return certificate's key usage, by checking the
key algorithm. The key usage value will ORed values of the:
'GNUTLS_KEY_DIGITAL_SIGNATURE' , 'GNUTLS_KEY_KEY_ENCIPHERMENT' .
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_get_name
---------------------------
-- Function: int gnutls_openpgp_crt_get_name (gnutls_openpgp_crt_t KEY,
int IDX, char * BUF, size_t * SIZEOF_BUF)
KEY: the structure that contains the OpenPGP public key.
IDX: the index of the ID to extract
BUF: a pointer to a structure to hold the name, may be 'NULL' to
only get the 'sizeof_buf' .
SIZEOF_BUF: holds the maximum size of 'buf' , on return hold the
actual/required size of 'buf' .
Extracts the userID from the parsed OpenPGP key.
*Returns:* 'GNUTLS_E_SUCCESS' on success, and if the index of the
ID does not exist 'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE' , or an
error code.
gnutls_openpgp_crt_get_pk_algorithm
-----------------------------------
-- Function: gnutls_pk_algorithm_t gnutls_openpgp_crt_get_pk_algorithm
(gnutls_openpgp_crt_t KEY, unsigned int * BITS)
KEY: is an OpenPGP key
BITS: if bits is non null it will hold the size of the parameters'
in bits
This function will return the public key algorithm of an OpenPGP
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.
*Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
success, or GNUTLS_PK_UNKNOWN on error.
gnutls_openpgp_crt_get_pk_dsa_raw
---------------------------------
-- Function: int gnutls_openpgp_crt_get_pk_dsa_raw
(gnutls_openpgp_crt_t CRT, gnutls_datum_t * P, gnutls_datum_t
* Q, gnutls_datum_t * G, gnutls_datum_t * Y)
CRT: Holds the certificate
P: will hold the p
Q: will hold the q
G: will hold the g
Y: will hold the 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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_crt_get_pk_rsa_raw
---------------------------------
-- Function: int gnutls_openpgp_crt_get_pk_rsa_raw
(gnutls_openpgp_crt_t CRT, gnutls_datum_t * M, gnutls_datum_t
* E)
CRT: Holds the certificate
M: will hold the modulus
E: will hold the public exponent
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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_crt_get_preferred_key_id
---------------------------------------
-- Function: int gnutls_openpgp_crt_get_preferred_key_id
(gnutls_openpgp_crt_t KEY, gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP public key.
KEYID: the struct to save the keyid.
Get preferred key id. If it hasn't been set it returns
'GNUTLS_E_INVALID_REQUEST' .
*Returns:* the 64-bit preferred keyID of the OpenPGP key.
gnutls_openpgp_crt_get_revoked_status
-------------------------------------
-- Function: int gnutls_openpgp_crt_get_revoked_status
(gnutls_openpgp_crt_t KEY)
KEY: the structure that contains the OpenPGP public key.
Get revocation status of key.
*Returns:* true (1) if the key has been revoked, or false (0) if it
has not.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_count
-----------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_count
(gnutls_openpgp_crt_t KEY)
KEY: is an OpenPGP key
This function will return the number of subkeys present in the
given OpenPGP certificate.
*Returns:* the number of subkeys, or a negative error code on
error.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_creation_time
-------------------------------------------
-- Function: time_t gnutls_openpgp_crt_get_subkey_creation_time
(gnutls_openpgp_crt_t KEY, unsigned int IDX)
KEY: the structure that contains the OpenPGP public key.
IDX: the subkey index
Get subkey creation time.
*Returns:* the timestamp when the OpenPGP sub-key was created.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_expiration_time
---------------------------------------------
-- Function: time_t gnutls_openpgp_crt_get_subkey_expiration_time
(gnutls_openpgp_crt_t KEY, unsigned int IDX)
KEY: the structure that contains the OpenPGP public key.
IDX: the subkey index
Get subkey expiration time. A value of '0' means that the key
doesn't expire at all.
*Returns:* the time when the OpenPGP key expires.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_fingerprint
-----------------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_fingerprint
(gnutls_openpgp_crt_t KEY, unsigned int IDX, void * FPR,
size_t * FPRLEN)
KEY: the raw data that contains the OpenPGP public key.
IDX: the subkey index
FPR: the buffer to save the fingerprint, must hold at least 20
bytes.
FPRLEN: the integer to save the length of the fingerprint.
Get key fingerprint of a subkey. Depending on the algorithm, the
fingerprint can be 16 or 20 bytes.
*Returns:* On success, 0 is returned. Otherwise, an error code.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_id
--------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_id (gnutls_openpgp_crt_t
KEY, unsigned int IDX, gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP public key.
IDX: the subkey index
KEYID: the buffer to save the keyid.
Get the subkey's key-id.
*Returns:* the 64-bit keyID of the OpenPGP key.
gnutls_openpgp_crt_get_subkey_idx
---------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_idx
(gnutls_openpgp_crt_t KEY, const gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP public key.
KEYID: the keyid.
Get subkey's index.
*Returns:* the index of the subkey or a negative error value.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_pk_algorithm
------------------------------------------
-- Function: gnutls_pk_algorithm_t
gnutls_openpgp_crt_get_subkey_pk_algorithm
(gnutls_openpgp_crt_t KEY, unsigned int IDX, unsigned int *
BITS)
KEY: is an OpenPGP key
IDX: is the subkey index
BITS: if bits is non null it will hold the size of the parameters'
in bits
This function will return the public key algorithm of a subkey of
an OpenPGP 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.
*Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
success, or GNUTLS_PK_UNKNOWN on error.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_pk_dsa_raw
----------------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_pk_dsa_raw
(gnutls_openpgp_crt_t CRT, unsigned int IDX, gnutls_datum_t *
P, gnutls_datum_t * Q, gnutls_datum_t * G, gnutls_datum_t * Y)
CRT: Holds the certificate
IDX: Is the subkey index
P: will hold the p
Q: will hold the q
G: will hold the g
Y: will hold the 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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_pk_rsa_raw
----------------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_pk_rsa_raw
(gnutls_openpgp_crt_t CRT, unsigned int IDX, gnutls_datum_t *
M, gnutls_datum_t * E)
CRT: Holds the certificate
IDX: Is the subkey index
M: will hold the modulus
E: will hold the public exponent
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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_revoked_status
--------------------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_revoked_status
(gnutls_openpgp_crt_t KEY, unsigned int IDX)
KEY: the structure that contains the OpenPGP public key.
IDX: is the subkey index
Get subkey revocation status. A negative error code indicates an
error.
*Returns:* true (1) if the key has been revoked, or false (0) if it
has not.
*Since:* 2.4.0
gnutls_openpgp_crt_get_subkey_usage
-----------------------------------
-- Function: int gnutls_openpgp_crt_get_subkey_usage
(gnutls_openpgp_crt_t KEY, unsigned int IDX, unsigned int *
KEY_USAGE)
KEY: should contain a gnutls_openpgp_crt_t structure
IDX: the subkey index
KEY_USAGE: where the key usage bits will be stored
This function will return certificate's key usage, by checking the
key algorithm. The key usage value will ORed values of
'GNUTLS_KEY_DIGITAL_SIGNATURE' or 'GNUTLS_KEY_KEY_ENCIPHERMENT' .
A negative error code may be returned in case of parsing error.
*Returns:* key usage value.
*Since:* 2.4.0
gnutls_openpgp_crt_get_version
------------------------------
-- Function: int gnutls_openpgp_crt_get_version (gnutls_openpgp_crt_t
KEY)
KEY: the structure that contains the OpenPGP public key.
Extract the version of the OpenPGP key.
*Returns:* the version number is returned, or a negative error code
on errors.
gnutls_openpgp_crt_import
-------------------------
-- Function: int gnutls_openpgp_crt_import (gnutls_openpgp_crt_t KEY,
const gnutls_datum_t * DATA, gnutls_openpgp_crt_fmt_t FORMAT)
KEY: The structure to store the parsed key.
DATA: The RAW or BASE64 encoded key.
FORMAT: One of gnutls_openpgp_crt_fmt_t elements.
This function will convert the given RAW or Base64 encoded key to
the native 'gnutls_openpgp_crt_t' format. The output will be
stored in 'key'.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_init
-----------------------
-- Function: int gnutls_openpgp_crt_init (gnutls_openpgp_crt_t * KEY)
KEY: The structure to be initialized
This function will initialize an OpenPGP key structure.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_print
------------------------
-- Function: int gnutls_openpgp_crt_print (gnutls_openpgp_crt_t CERT,
gnutls_certificate_print_formats_t FORMAT, gnutls_datum_t *
OUT)
CERT: The structure to be printed
FORMAT: Indicate the format to use
OUT: Newly allocated datum with (0) terminated string.
This function will pretty print an OpenPGP certificate, suitable
for display to a human.
The format should be (0) for future compatibility.
The output 'out' needs to be deallocate using 'gnutls_free()' .
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_set_preferred_key_id
---------------------------------------
-- Function: int gnutls_openpgp_crt_set_preferred_key_id
(gnutls_openpgp_crt_t KEY, const gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP public key.
KEYID: the selected keyid
This allows setting a preferred key id for the given certificate.
This key will be used by functions that involve key handling.
If the provided 'keyid' is 'NULL' then the master key is set as
preferred.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_openpgp_crt_verify_ring
------------------------------
-- Function: int gnutls_openpgp_crt_verify_ring (gnutls_openpgp_crt_t
KEY, gnutls_openpgp_keyring_t KEYRING, unsigned int FLAGS,
unsigned int * VERIFY)
KEY: the structure that holds the key.
KEYRING: holds the keyring to check against
FLAGS: unused (should be 0)
VERIFY: will hold the certificate verification output.
Verify all signatures in the key, using the given set of keys
(keyring).
The key verification output will be put in 'verify' and will be one
or more of the 'gnutls_certificate_status_t' enumerated elements
bitwise or'd.
Note that this function does not verify using any "web of trust".
You may use GnuPG for that purpose, or any other external PGP
application.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_crt_verify_self
------------------------------
-- Function: int gnutls_openpgp_crt_verify_self (gnutls_openpgp_crt_t
KEY, unsigned int FLAGS, unsigned int * VERIFY)
KEY: the structure that holds the key.
FLAGS: unused (should be 0)
VERIFY: will hold the key verification output.
Verifies the self signature in the key. The key verification
output will be put in 'verify' and will be one or more of the
gnutls_certificate_status_t enumerated elements bitwise or'd.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_keyring_check_id
-------------------------------
-- Function: int gnutls_openpgp_keyring_check_id
(gnutls_openpgp_keyring_t RING, const gnutls_openpgp_keyid_t
KEYID, unsigned int FLAGS)
RING: holds the keyring to check against
KEYID: will hold the keyid to check for.
FLAGS: unused (should be 0)
Check if a given key ID exists in the keyring.
*Returns:* 'GNUTLS_E_SUCCESS' on success (if keyid exists) and a
negative error code on failure.
gnutls_openpgp_keyring_deinit
-----------------------------
-- Function: void gnutls_openpgp_keyring_deinit
(gnutls_openpgp_keyring_t KEYRING)
KEYRING: A pointer to the type to be initialized
This function will deinitialize a keyring structure.
gnutls_openpgp_keyring_get_crt
------------------------------
-- Function: int gnutls_openpgp_keyring_get_crt
(gnutls_openpgp_keyring_t RING, unsigned int IDX,
gnutls_openpgp_crt_t * CERT)
RING: Holds the keyring.
IDX: the index of the certificate to export
CERT: An uninitialized 'gnutls_openpgp_crt_t' type
This function will extract an OpenPGP certificate from the given
keyring. If the index given is out of range
'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE' will be returned. The
returned structure needs to be deinited.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_keyring_get_crt_count
------------------------------------
-- Function: int gnutls_openpgp_keyring_get_crt_count
(gnutls_openpgp_keyring_t RING)
RING: is an OpenPGP key ring
This function will return the number of OpenPGP certificates
present in the given keyring.
*Returns:* the number of subkeys, or a negative error code on
error.
gnutls_openpgp_keyring_import
-----------------------------
-- Function: int gnutls_openpgp_keyring_import
(gnutls_openpgp_keyring_t KEYRING, const gnutls_datum_t *
DATA, gnutls_openpgp_crt_fmt_t FORMAT)
KEYRING: The structure to store the parsed key.
DATA: The RAW or BASE64 encoded keyring.
FORMAT: One of 'gnutls_openpgp_keyring_fmt' elements.
This function will convert the given RAW or Base64 encoded keyring
to the native 'gnutls_openpgp_keyring_t' format. The output will
be stored in 'keyring'.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_keyring_init
---------------------------
-- Function: int gnutls_openpgp_keyring_init (gnutls_openpgp_keyring_t
* KEYRING)
KEYRING: A pointer to the type to be initialized
This function will initialize an keyring structure.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_privkey_deinit
-----------------------------
-- Function: void gnutls_openpgp_privkey_deinit
(gnutls_openpgp_privkey_t KEY)
KEY: The structure to be initialized
This function will deinitialize a key structure.
gnutls_openpgp_privkey_export
-----------------------------
-- Function: int gnutls_openpgp_privkey_export
(gnutls_openpgp_privkey_t KEY, gnutls_openpgp_crt_fmt_t
FORMAT, const char * PASSWORD, unsigned int FLAGS, void *
OUTPUT_DATA, size_t * OUTPUT_DATA_SIZE)
KEY: Holds the key.
FORMAT: One of gnutls_openpgp_crt_fmt_t elements.
PASSWORD: the password that will be used to encrypt the key.
(unused for now)
FLAGS: (0) for future compatibility
OUTPUT_DATA: will contain the key base64 encoded or raw
OUTPUT_DATA_SIZE: holds the size of output_data (and will be
replaced by the actual size of parameters)
This function will convert the given key to RAW or Base64 format.
If the buffer provided is not long enough to hold the output, then
GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_export2
------------------------------
-- Function: int gnutls_openpgp_privkey_export2
(gnutls_openpgp_privkey_t KEY, gnutls_openpgp_crt_fmt_t
FORMAT, const char * PASSWORD, unsigned int FLAGS,
gnutls_datum_t * OUT)
KEY: Holds the key.
FORMAT: One of gnutls_openpgp_crt_fmt_t elements.
PASSWORD: the password that will be used to encrypt the key.
(unused for now)
FLAGS: (0) for future compatibility
OUT: will contain the raw or based64 encoded key
This function will convert the given key to RAW or Base64 format.
The output buffer is allocated using 'gnutls_malloc()' .
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
*Since:* 3.1.3
gnutls_openpgp_privkey_export_dsa_raw
-------------------------------------
-- Function: int gnutls_openpgp_privkey_export_dsa_raw
(gnutls_openpgp_privkey_t PKEY, gnutls_datum_t * P,
gnutls_datum_t * Q, gnutls_datum_t * G, gnutls_datum_t * Y,
gnutls_datum_t * X)
PKEY: Holds the certificate
P: will hold the p
Q: will hold the q
G: will hold the g
Y: will hold the y
X: will hold the x
This function will export the DSA private 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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_export_rsa_raw
-------------------------------------
-- Function: int gnutls_openpgp_privkey_export_rsa_raw
(gnutls_openpgp_privkey_t PKEY, gnutls_datum_t * M,
gnutls_datum_t * E, gnutls_datum_t * D, gnutls_datum_t * P,
gnutls_datum_t * Q, gnutls_datum_t * U)
PKEY: Holds the certificate
M: will hold the modulus
E: will hold the public exponent
D: will hold the private exponent
P: will hold the first prime (p)
Q: will hold the second prime (q)
U: will hold the coefficient
This function will export the RSA private 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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_export_subkey_dsa_raw
--------------------------------------------
-- Function: int gnutls_openpgp_privkey_export_subkey_dsa_raw
(gnutls_openpgp_privkey_t PKEY, unsigned int IDX,
gnutls_datum_t * P, gnutls_datum_t * Q, gnutls_datum_t * G,
gnutls_datum_t * Y, gnutls_datum_t * X)
PKEY: Holds the certificate
IDX: Is the subkey index
P: will hold the p
Q: will hold the q
G: will hold the g
Y: will hold the y
X: will hold the x
This function will export the DSA private 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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_export_subkey_rsa_raw
--------------------------------------------
-- Function: int gnutls_openpgp_privkey_export_subkey_rsa_raw
(gnutls_openpgp_privkey_t PKEY, unsigned int IDX,
gnutls_datum_t * M, gnutls_datum_t * E, gnutls_datum_t * D,
gnutls_datum_t * P, gnutls_datum_t * Q, gnutls_datum_t * U)
PKEY: Holds the certificate
IDX: Is the subkey index
M: will hold the modulus
E: will hold the public exponent
D: will hold the private exponent
P: will hold the first prime (p)
Q: will hold the second prime (q)
U: will hold the coefficient
This function will export the RSA private 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.
*Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise a negative
error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_fingerprint
--------------------------------------
-- Function: int gnutls_openpgp_privkey_get_fingerprint
(gnutls_openpgp_privkey_t KEY, void * FPR, size_t * FPRLEN)
KEY: the raw data that contains the OpenPGP secret key.
FPR: the buffer to save the fingerprint, must hold at least 20
bytes.
FPRLEN: the integer to save the length of the fingerprint.
Get the fingerprint of the OpenPGP key. Depends on the algorithm,
the fingerprint can be 16 or 20 bytes.
*Returns:* On success, 0 is returned, or an error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_key_id
---------------------------------
-- Function: int gnutls_openpgp_privkey_get_key_id
(gnutls_openpgp_privkey_t KEY, gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP secret key.
KEYID: the buffer to save the keyid.
Get key-id.
*Returns:* the 64-bit keyID of the OpenPGP key.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_pk_algorithm
---------------------------------------
-- Function: gnutls_pk_algorithm_t
gnutls_openpgp_privkey_get_pk_algorithm
(gnutls_openpgp_privkey_t KEY, unsigned int * BITS)
KEY: is an OpenPGP key
BITS: if bits is non null it will hold the size of the parameters'
in bits
This function will return the public key algorithm of an OpenPGP
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.
*Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
success, or a negative error code on error.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_preferred_key_id
-------------------------------------------
-- Function: int gnutls_openpgp_privkey_get_preferred_key_id
(gnutls_openpgp_privkey_t KEY, gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP public key.
KEYID: the struct to save the keyid.
Get the preferred key-id for the key.
*Returns:* the 64-bit preferred keyID of the OpenPGP key, or if it
hasn't been set it returns 'GNUTLS_E_INVALID_REQUEST' .
gnutls_openpgp_privkey_get_revoked_status
-----------------------------------------
-- Function: int gnutls_openpgp_privkey_get_revoked_status
(gnutls_openpgp_privkey_t KEY)
KEY: the structure that contains the OpenPGP private key.
Get revocation status of key.
*Returns:* true (1) if the key has been revoked, or false (0) if it
has not, or a negative error code indicates an error.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_count
---------------------------------------
-- Function: int gnutls_openpgp_privkey_get_subkey_count
(gnutls_openpgp_privkey_t KEY)
KEY: is an OpenPGP key
This function will return the number of subkeys present in the
given OpenPGP certificate.
*Returns:* the number of subkeys, or a negative error code on
error.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_creation_time
-----------------------------------------------
-- Function: time_t gnutls_openpgp_privkey_get_subkey_creation_time
(gnutls_openpgp_privkey_t KEY, unsigned int IDX)
KEY: the structure that contains the OpenPGP private key.
IDX: the subkey index
Get subkey creation time.
*Returns:* the timestamp when the OpenPGP key was created.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_expiration_time
-------------------------------------------------
-- Function: time_t gnutls_openpgp_privkey_get_subkey_expiration_time
(gnutls_openpgp_privkey_t KEY, unsigned int IDX)
KEY: the structure that contains the OpenPGP private key.
IDX: the subkey index
Get subkey expiration time. A value of '0' means that the key
doesn't expire at all.
*Returns:* the time when the OpenPGP key expires.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_fingerprint
---------------------------------------------
-- Function: int gnutls_openpgp_privkey_get_subkey_fingerprint
(gnutls_openpgp_privkey_t KEY, unsigned int IDX, void * FPR,
size_t * FPRLEN)
KEY: the raw data that contains the OpenPGP secret key.
IDX: the subkey index
FPR: the buffer to save the fingerprint, must hold at least 20
bytes.
FPRLEN: the integer to save the length of the fingerprint.
Get the fingerprint of an OpenPGP subkey. Depends on the
algorithm, the fingerprint can be 16 or 20 bytes.
*Returns:* On success, 0 is returned, or an error code.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_id
------------------------------------
-- Function: int gnutls_openpgp_privkey_get_subkey_id
(gnutls_openpgp_privkey_t KEY, unsigned int IDX,
gnutls_openpgp_keyid_t KEYID)
KEY: the structure that contains the OpenPGP secret key.
IDX: the subkey index
KEYID: the buffer to save the keyid.
Get the key-id for the subkey.
*Returns:* the 64-bit keyID of the OpenPGP key.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_idx
-------------------------------------
-- Function: int gnutls_openpgp_privkey_get_subkey_idx
(gnutls_openpgp_privkey_t KEY, const gnutls_openpgp_keyid_t
KEYID)
KEY: the structure that contains the OpenPGP private key.
KEYID: the keyid.
Get index of subkey.
*Returns:* the index of the subkey or a negative error value.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_pk_algorithm
----------------------------------------------
-- Function: gnutls_pk_algorithm_t
gnutls_openpgp_privkey_get_subkey_pk_algorithm
(gnutls_openpgp_privkey_t KEY, unsigned int IDX, unsigned int
* BITS)
KEY: is an OpenPGP key
IDX: is the subkey index
BITS: if bits is non null it will hold the size of the parameters'
in bits
This function will return the public key algorithm of a subkey of
an OpenPGP 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.
*Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
success, or a negative error code on error.
*Since:* 2.4.0
gnutls_openpgp_privkey_get_subkey_revoked_status
------------------------------------------------
-- Function: int gnutls_openpgp_privkey_get_subkey_revoked_status
(gnutls_openpgp_privkey_t KEY, unsigned int IDX)
KEY: the structure that contains the OpenPGP private key.
IDX: is the subkey index
Get revocation status of key.
*Returns:* true (1) if the key has been revoked, or false (0) if it
has not, or a negative error code indicates an error.
*Since:* 2.4.0
gnutls_openpgp_privkey_import
-----------------------------
-- Function: int gnutls_openpgp_privkey_import
(gnutls_openpgp_privkey_t KEY, const gnutls_datum_t * DATA,
gnutls_openpgp_crt_fmt_t FORMAT, const char * PASSWORD,
unsigned int FLAGS)
KEY: The structure to store the parsed key.
DATA: The RAW or BASE64 encoded key.
FORMAT: One of 'gnutls_openpgp_crt_fmt_t' elements.
PASSWORD: not used for now
FLAGS: should be (0)
This function will convert the given RAW or Base64 encoded key to
the native gnutls_openpgp_privkey_t format. The output will be
stored in 'key'.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_privkey_init
---------------------------
-- Function: int gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t
* KEY)
KEY: The structure to be initialized
This function will initialize an OpenPGP key structure.
*Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
gnutls_openpgp_privkey_sec_param
--------------------------------
-- Function: gnutls_sec_param_t gnutls_openpgp_privkey_sec_param
(gnutls_openpgp_privkey_t KEY)
KEY: a key structure
This function will return the security parameter appropriate with
this private key.
*Returns:* On success, a valid security parameter is returned
otherwise 'GNUTLS_SEC_PARAM_UNKNOWN' is returned.
*Since:* 2.12.0
gnutls_openpgp_privkey_set_preferred_key_id
-------------------------------------------
-- Function: int gnutls_openpgp_privkey_set_preferred_key_id
(gnutls_openpgp_privkey_t KEY, const gnutls_openpgp_keyid_t
KEYID)
KEY: the structure that contains the OpenPGP public key.
KEYID: the selected keyid
This allows setting a preferred key id for the given certificate.
This key will be used by functions that involve key handling.
If the provided 'keyid' is 'NULL' then the master key is set as
preferred.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_openpgp_set_recv_key_function
------------------------------------
-- Function: void gnutls_openpgp_set_recv_key_function
(gnutls_session_t SESSION, gnutls_openpgp_recv_key_func FUNC)
SESSION: a TLS session
FUNC: the callback
This funtion will set a key retrieval function for OpenPGP keys.
This callback is only useful in server side, and will be used if
the peer sent a key fingerprint instead of a full key.
The retrieved key must be allocated using 'gnutls_malloc()' .
File: gnutls.info, Node: PKCS 12 API, Next: PKCS 11 API, Prev: OpenPGP API, Up: API reference
E.6 PKCS 12 API
===============
The following functions are to be used for PKCS 12 handling. Their
prototypes lie in 'gnutls/pkcs12.h'.
gnutls_pkcs12_bag_decrypt
-------------------------
-- Function: int gnutls_pkcs12_bag_decrypt (gnutls_pkcs12_bag_t BAG,
const char * PASS)
BAG: The bag
PASS: The password used for encryption, must be ASCII.
This function will decrypt the given encrypted bag and return 0 on
success.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_pkcs12_bag_deinit
------------------------
-- Function: void gnutls_pkcs12_bag_deinit (gnutls_pkcs12_bag_t BAG)
BAG: The structure to be initialized
This function will deinitialize a PKCS12 Bag structure.
gnutls_pkcs12_bag_encrypt
-------------------------
-- Function: int gnutls_pkcs12_bag_encrypt (gnutls_pkcs12_bag_t BAG,
const char * PASS, unsigned int FLAGS)
BAG: The bag
PASS: The password used for encryption, must be ASCII
FLAGS: should be one of 'gnutls_pkcs_encrypt_flags_t' elements
bitwise or'd
This function will encrypt the given bag.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error code is returned.
gnutls_pkcs12_bag_get_count
---------------------------
-- Function: int gnutls_pkcs12_bag_get_count (gnutls_pkcs12_bag_t BAG)
BAG: The bag
This function will return the number of the elements withing the
bag.
*Returns:* Number of elements in bag, or an negative error code on
error.
gnutls_pkcs12_bag_get_data
--------------------------
-- Function: int gnutls_pkcs12_bag_get_data (gnutls_pkcs12_bag_t BAG,
int INDX, gnutls_datum_t * DATA)
BAG: The bag
INDX: The element of the bag to get the data from
DATA: where the bag's data will be. Should be treated as constant.
This function will return the bag's data. The data is a constant
that is stored into the bag. Should not be accessed after the bag
is deleted.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_bag_get_friendly_name
-----------------------------------
-- Function: int gnutls_pkcs12_bag_get_friendly_name
(gnutls_pkcs12_bag_t BAG, int INDX, char ** NAME)
BAG: The bag
INDX: The bag's element to add the id
NAME: will hold a pointer to the name (to be treated as const)
This function will return the friendly name, of the specified bag
element. The key ID is usually used to distinguish the local
private key and the certificate pair.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value. or a negative error code on
error.
gnutls_pkcs12_bag_get_key_id
----------------------------
-- Function: int gnutls_pkcs12_bag_get_key_id (gnutls_pkcs12_bag_t BAG,
int INDX, gnutls_datum_t * ID)
BAG: The bag
INDX: The bag's element to add the id
ID: where the ID will be copied (to be treated as const)
This function will return the key ID, of the specified bag element.
The key ID is usually used to distinguish the local private key and
the certificate pair.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value. or a negative error code on
error.
gnutls_pkcs12_bag_get_type
--------------------------
-- Function: gnutls_pkcs12_bag_type_t gnutls_pkcs12_bag_get_type
(gnutls_pkcs12_bag_t BAG, int INDX)
BAG: The bag
INDX: The element of the bag to get the type
This function will return the bag's type.
*Returns:* One of the 'gnutls_pkcs12_bag_type_t' enumerations.
gnutls_pkcs12_bag_init
----------------------
-- Function: int gnutls_pkcs12_bag_init (gnutls_pkcs12_bag_t * BAG)
BAG: The structure to be initialized
This function will initialize a PKCS12 bag structure. PKCS12 Bags
usually contain private keys, lists of X.509 Certificates and X.509
Certificate revocation lists.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_bag_set_crl
-------------------------
-- Function: int gnutls_pkcs12_bag_set_crl (gnutls_pkcs12_bag_t BAG,
gnutls_x509_crl_t CRL)
BAG: The bag
CRL: the CRL to be copied.
This function will insert the given CRL into the bag. This is just
a wrapper over 'gnutls_pkcs12_bag_set_data()' .
*Returns:* the index of the added bag on success, or a negative
error code on failure.
gnutls_pkcs12_bag_set_crt
-------------------------
-- Function: int gnutls_pkcs12_bag_set_crt (gnutls_pkcs12_bag_t BAG,
gnutls_x509_crt_t CRT)
BAG: The bag
CRT: the certificate to be copied.
This function will insert the given certificate into the bag. This
is just a wrapper over 'gnutls_pkcs12_bag_set_data()' .
*Returns:* the index of the added bag on success, or a negative
value on failure.
gnutls_pkcs12_bag_set_data
--------------------------
-- Function: int gnutls_pkcs12_bag_set_data (gnutls_pkcs12_bag_t BAG,
gnutls_pkcs12_bag_type_t TYPE, const gnutls_datum_t * DATA)
BAG: The bag
TYPE: The data's type
DATA: the data to be copied.
This function will insert the given data of the given type into the
bag.
*Returns:* the index of the added bag on success, or a negative
value on error.
gnutls_pkcs12_bag_set_friendly_name
-----------------------------------
-- Function: int gnutls_pkcs12_bag_set_friendly_name
(gnutls_pkcs12_bag_t BAG, int INDX, const char * NAME)
BAG: The bag
INDX: The bag's element to add the id
NAME: the name
This function will add the given key friendly name, to the
specified, by the index, bag element. The name will be encoded as
a 'Friendly name' bag attribute, which is usually used to set a
user name to the local private key and the certificate pair.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value. or a negative error code on
error.
gnutls_pkcs12_bag_set_key_id
----------------------------
-- Function: int gnutls_pkcs12_bag_set_key_id (gnutls_pkcs12_bag_t BAG,
int INDX, const gnutls_datum_t * ID)
BAG: The bag
INDX: The bag's element to add the id
ID: the ID
This function will add the given key ID, to the specified, by the
index, bag element. The key ID will be encoded as a 'Local key
identifier' bag attribute, which is usually used to distinguish the
local private key and the certificate pair.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value. or a negative error code on
error.
gnutls_pkcs12_deinit
--------------------
-- Function: void gnutls_pkcs12_deinit (gnutls_pkcs12_t PKCS12)
PKCS12: The structure to be initialized
This function will deinitialize a PKCS12 structure.
gnutls_pkcs12_export
--------------------
-- Function: int gnutls_pkcs12_export (gnutls_pkcs12_t PKCS12,
gnutls_x509_crt_fmt_t FORMAT, void * OUTPUT_DATA, size_t *
OUTPUT_DATA_SIZE)
PKCS12: Holds the pkcs12 structure
FORMAT: the format of output params. One of PEM or DER.
OUTPUT_DATA: will contain a structure PEM or DER encoded
OUTPUT_DATA_SIZE: holds the size of output_data (and will be
replaced by the actual size of parameters)
This function will export the pkcs12 structure to DER or PEM
format.
If the buffer provided is not long enough to hold the output, then
*output_data_size will be updated and GNUTLS_E_SHORT_MEMORY_BUFFER
will be returned.
If the structure is PEM encoded, it will have a header of "BEGIN
PKCS12".
*Returns:* In case of failure a negative error code will be
returned, and 0 on success.
gnutls_pkcs12_export2
---------------------
-- Function: int gnutls_pkcs12_export2 (gnutls_pkcs12_t PKCS12,
gnutls_x509_crt_fmt_t FORMAT, gnutls_datum_t * OUT)
PKCS12: Holds the pkcs12 structure
FORMAT: the format of output params. One of PEM or DER.
OUT: will contain a structure PEM or DER encoded
This function will export the pkcs12 structure 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
PKCS12".
*Returns:* In case of failure a negative error code will be
returned, and 0 on success.
*Since:* 3.1.3
gnutls_pkcs12_generate_mac
--------------------------
-- Function: int gnutls_pkcs12_generate_mac (gnutls_pkcs12_t PKCS12,
const char * PASS)
PKCS12: should contain a gnutls_pkcs12_t structure
PASS: The password for the MAC
This function will generate a MAC for the PKCS12 structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_get_bag
---------------------
-- Function: int gnutls_pkcs12_get_bag (gnutls_pkcs12_t PKCS12, int
INDX, gnutls_pkcs12_bag_t BAG)
PKCS12: should contain a gnutls_pkcs12_t structure
INDX: contains the index of the bag to extract
BAG: An initialized bag, where the contents of the bag will be
copied
This function will return a Bag from the PKCS12 structure.
After the last Bag has been read
'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE' will be returned.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_import
--------------------
-- Function: int gnutls_pkcs12_import (gnutls_pkcs12_t PKCS12, const
gnutls_datum_t * DATA, gnutls_x509_crt_fmt_t FORMAT, unsigned
int FLAGS)
PKCS12: The structure to store the parsed PKCS12.
DATA: The DER or PEM encoded PKCS12.
FORMAT: One of DER or PEM
FLAGS: an ORed sequence of gnutls_privkey_pkcs8_flags
This function will convert the given DER or PEM encoded PKCS12 to
the native gnutls_pkcs12_t format. The output will be stored in
'pkcs12'.
If the PKCS12 is PEM encoded it should have a header of "PKCS12".
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_init
------------------
-- Function: int gnutls_pkcs12_init (gnutls_pkcs12_t * PKCS12)
PKCS12: The structure to be initialized
This function will initialize a PKCS12 structure. PKCS12
structures usually contain lists of X.509 Certificates and X.509
Certificate revocation lists.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_set_bag
---------------------
-- Function: int gnutls_pkcs12_set_bag (gnutls_pkcs12_t PKCS12,
gnutls_pkcs12_bag_t BAG)
PKCS12: should contain a gnutls_pkcs12_t structure
BAG: An initialized bag
This function will insert a Bag into the PKCS12 structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs12_simple_parse
--------------------------
-- Function: int gnutls_pkcs12_simple_parse (gnutls_pkcs12_t P12, const
char * PASSWORD, gnutls_x509_privkey_t * KEY,
gnutls_x509_crt_t ** CHAIN, unsigned int * CHAIN_LEN,
gnutls_x509_crt_t ** EXTRA_CERTS, unsigned int *
EXTRA_CERTS_LEN, gnutls_x509_crl_t * CRL, unsigned int FLAGS)
P12: should contain a gnutls_pkcs12_t structure
PASSWORD: optional password used to decrypt the structure, bags and
keys.
KEY: a structure to store the parsed private key.
CHAIN: the corresponding to key certificate chain (may be 'NULL' )
CHAIN_LEN: will be updated with the number of additional (may be
'NULL' )
EXTRA_CERTS: optional pointer to receive an array of additional
certificates found in the PKCS12 structure (may be 'NULL' ).
EXTRA_CERTS_LEN: will be updated with the number of additional
certs (may be 'NULL' ).
CRL: an optional structure to store the parsed CRL (may be 'NULL'
).
FLAGS: should be zero or one of GNUTLS_PKCS12_SP_*
This function parses a PKCS12 structure in 'pkcs12' and extracts
the private key, the corresponding certificate chain, any
additional certificates and a CRL.
The 'extra_certs' and 'extra_certs_len' parameters are optional and
both may be set to 'NULL' . If either is non-'NULL' , then both
must be set. The value for 'extra_certs' is allocated using
'gnutls_malloc()' .
Encrypted PKCS12 bags and PKCS8 private keys are supported, but
only with password based security and the same password for all
operations.
Note that a PKCS12 structure may contain many keys and/or
certificates, and there is no way to identify which key/certificate
pair you want. For this reason this function is useful for PKCS12
files that contain only one key/certificate pair and/or one CRL.
If the provided structure has encrypted fields but no password is
provided then this function returns 'GNUTLS_E_DECRYPTION_FAILED' .
Note that normally the chain constructed does not include self
signed certificates, to comply with TLS' requirements. If,
however, the flag 'GNUTLS_PKCS12_SP_INCLUDE_SELF_SIGNED' is
specified then self signed certificates will be included in the
chain.
Prior to using this function the PKCS '12' structure integrity must
be verified using 'gnutls_pkcs12_verify_mac()' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.1.0
gnutls_pkcs12_verify_mac
------------------------
-- Function: int gnutls_pkcs12_verify_mac (gnutls_pkcs12_t PKCS12,
const char * PASS)
PKCS12: should contain a gnutls_pkcs12_t structure
PASS: The password for the MAC
This function will verify the MAC for the PKCS12 structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
File: gnutls.info, Node: PKCS 11 API, Next: TPM API, Prev: PKCS 12 API, Up: API reference
E.7 Hardware token via PKCS 11 API
==================================
The following functions are to be used for PKCS 11 handling. Their
prototypes lie in 'gnutls/pkcs11.h'.
gnutls_pkcs11_add_provider
--------------------------
-- Function: int gnutls_pkcs11_add_provider (const char * NAME, const
char * PARAMS)
NAME: The filename of the module
PARAMS: should be NULL
This function will load and add a PKCS 11 module to the module list
used in gnutls. After this function is called the module will be
used for PKCS 11 operations.
When loading a module to be used for certificate verification, use
the string 'trusted' as 'params' .
Note that this function is not thread safe.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_copy_secret_key
-----------------------------
-- Function: int gnutls_pkcs11_copy_secret_key (const char * TOKEN_URL,
gnutls_datum_t * KEY, const char * LABEL, unsigned int
KEY_USAGE, unsigned int FLAGS)
TOKEN_URL: A PKCS '11' URL specifying a token
KEY: The raw key
LABEL: A name to be used for the stored data
KEY_USAGE: One of GNUTLS_KEY_*
FLAGS: One of GNUTLS_PKCS11_OBJ_FLAG_*
This function will copy a raw secret (symmetric) key into a PKCS
'11' token specified by a URL. The key can be marked as sensitive
or not.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_copy_x509_crt
---------------------------
-- Function: int gnutls_pkcs11_copy_x509_crt (const char * TOKEN_URL,
gnutls_x509_crt_t CRT, const char * LABEL, unsigned int FLAGS)
TOKEN_URL: A PKCS '11' URL specifying a token
CRT: The certificate to copy
LABEL: The name to be used for the stored data
FLAGS: One of GNUTLS_PKCS11_OBJ_FLAG_*
This function will copy a certificate into a PKCS '11' token
specified by a URL. The certificate can be marked as trusted or
not.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_copy_x509_crt2
----------------------------
-- Function: int gnutls_pkcs11_copy_x509_crt2 (const char * TOKEN_URL,
gnutls_x509_crt_t CRT, const char * LABEL, const
gnutls_datum_t * CID, unsigned int FLAGS)
TOKEN_URL: A PKCS '11' URL specifying a token
CRT: The certificate to copy
LABEL: The name to be used for the stored data
CID: The CKA_ID to set for the object -if NULL, the ID will be
derived from the public key
FLAGS: One of GNUTLS_PKCS11_OBJ_FLAG_*
This function will copy a certificate into a PKCS '11' token
specified by a URL. The certificate can be marked as trusted or
not.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.3.26
gnutls_pkcs11_copy_x509_privkey
-------------------------------
-- Function: int gnutls_pkcs11_copy_x509_privkey (const char *
TOKEN_URL, gnutls_x509_privkey_t KEY, const char * LABEL,
unsigned int KEY_USAGE, unsigned int FLAGS)
TOKEN_URL: A PKCS '11' URL specifying a token
KEY: A private key
LABEL: A name to be used for the stored data
KEY_USAGE: One of GNUTLS_KEY_*
FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
This function will copy a private key into a PKCS '11' token
specified by a URL. It is highly recommended flags to contain
'GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE' unless there is a strong
reason not to.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_copy_x509_privkey2
--------------------------------
-- Function: int gnutls_pkcs11_copy_x509_privkey2 (const char *
TOKEN_URL, gnutls_x509_privkey_t KEY, const char * LABEL,
const gnutls_datum_t * CID, unsigned int KEY_USAGE, unsigned
int FLAGS)
TOKEN_URL: A PKCS '11' URL specifying a token
KEY: A private key
LABEL: A name to be used for the stored data
CID: The CKA_ID to set for the object -if NULL, the ID will be
derived from the public key
KEY_USAGE: One of GNUTLS_KEY_*
FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
This function will copy a private key into a PKCS '11' token
specified by a URL. It is highly recommended flags to contain
'GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE' unless there is a strong
reason not to.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.3.26
gnutls_pkcs11_crt_is_known
--------------------------
-- Function: int gnutls_pkcs11_crt_is_known (const char * URL,
gnutls_x509_crt_t CERT, unsigned int FLAGS)
URL: A PKCS 11 url identifying a token
CERT: is the certificate to find issuer for
FLAGS: Use zero or flags from 'GNUTLS_PKCS11_OBJ_FLAG' .
This function will check whether the provided certificate is stored
in the specified token. This is useful in combination with
'GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_TRUSTED' or
'GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_DISTRUSTED' , to check whether a
CA is present or a certificate is blacklisted in a trust PKCS '11'
module.
This function can be used with a 'url' of "pkcs11:", and in that
case all modules will be searched. To restrict the modules to the
marked as trusted in p11-kit use the
'GNUTLS_PKCS11_OBJ_FLAG_PRESENT_IN_TRUSTED_MODULE' flag.
Note that the flag 'GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_DISTRUSTED' is
specific to p11-kit trust modules.
*Returns:* If the certificate exists non-zero is returned,
otherwise zero.
*Since:* 3.3.0
gnutls_pkcs11_deinit
--------------------
-- Function: void gnutls_pkcs11_deinit ( VOID)
This function will deinitialize the PKCS 11 subsystem in gnutls.
This function is only needed if you need to deinitialize the
subsystem without calling 'gnutls_global_deinit()' .
*Since:* 2.12.0
gnutls_pkcs11_delete_url
------------------------
-- Function: int gnutls_pkcs11_delete_url (const char * OBJECT_URL,
unsigned int FLAGS)
OBJECT_URL: The URL of the object to delete.
FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
This function will delete objects matching the given URL. Note that
not all tokens support the delete operation.
*Returns:* On success, the number of objects deleted is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_get_pin_function
------------------------------
-- Function: gnutls_pin_callback_t gnutls_pkcs11_get_pin_function (void
** USERDATA)
USERDATA: data to be supplied to callback
This function will return the callback function set using
'gnutls_pkcs11_set_pin_function()' .
*Returns:* The function set or NULL otherwise.
*Since:* 3.1.0
gnutls_pkcs11_get_raw_issuer
----------------------------
-- Function: int gnutls_pkcs11_get_raw_issuer (const char * URL,
gnutls_x509_crt_t CERT, gnutls_datum_t * ISSUER,
gnutls_x509_crt_fmt_t FMT, unsigned int FLAGS)
URL: A PKCS 11 url identifying a token
CERT: is the certificate to find issuer for
ISSUER: Will hold the issuer if any in an allocated buffer.
FMT: The format of the exported issuer.
FLAGS: Use zero or flags from 'GNUTLS_PKCS11_OBJ_FLAG' .
This function will return the issuer of a given certificate, if it
is stored in the token. By default only marked as trusted issuers
are retuned. If any issuer should be returned specify
'GNUTLS_PKCS11_OBJ_FLAG_RETRIEVE_ANY' in 'flags' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.2.7
gnutls_pkcs11_init
------------------
-- Function: int gnutls_pkcs11_init (unsigned int FLAGS, const char *
DEPRECATED_CONFIG_FILE)
FLAGS: An ORed sequence of 'GNUTLS_PKCS11_FLAG_' *
DEPRECATED_CONFIG_FILE: either NULL or the location of a deprecated
configuration file
This function will initialize the PKCS 11 subsystem in gnutls. It
will read configuration files if 'GNUTLS_PKCS11_FLAG_AUTO' is used
or allow you to independently load PKCS 11 modules using
'gnutls_pkcs11_add_provider()' if 'GNUTLS_PKCS11_FLAG_MANUAL' is
specified.
Normally you don't need to call this function since it is being
called when the first PKCS 11 operation is requested using the
'GNUTLS_PKCS11_FLAG_AUTO' flag. If another flags are required then
it must be called independently prior to any PKCS 11 operation.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_obj_deinit
------------------------
-- Function: void gnutls_pkcs11_obj_deinit (gnutls_pkcs11_obj_t OBJ)
OBJ: The structure to be initialized
This function will deinitialize a certificate structure.
*Since:* 2.12.0
gnutls_pkcs11_obj_export
------------------------
-- Function: int gnutls_pkcs11_obj_export (gnutls_pkcs11_obj_t OBJ,
void * OUTPUT_DATA, size_t * OUTPUT_DATA_SIZE)
OBJ: Holds the object
OUTPUT_DATA: will contain the object data
OUTPUT_DATA_SIZE: holds the size of output_data (and will be
replaced by the actual size of parameters)
This function will export the PKCS11 object data. It is normal for
data to be inaccesible and in that case 'GNUTLS_E_INVALID_REQUEST'
will be returned.
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.
*Returns:* In case of failure a negative error code will be
returned, and 'GNUTLS_E_SUCCESS' (0) on success.
*Since:* 2.12.0
gnutls_pkcs11_obj_export2
-------------------------
-- Function: int gnutls_pkcs11_obj_export2 (gnutls_pkcs11_obj_t OBJ,
gnutls_datum_t * OUT)
OBJ: Holds the object
OUT: will contain the object data
This function will export the PKCS11 object data. It is normal for
data to be inaccesible and in that case 'GNUTLS_E_INVALID_REQUEST'
will be returned.
The output buffer is allocated using 'gnutls_malloc()' .
*Returns:* In case of failure a negative error code will be
returned, and 'GNUTLS_E_SUCCESS' (0) on success.
*Since:* 3.1.3
gnutls_pkcs11_obj_export3
-------------------------
-- Function: int gnutls_pkcs11_obj_export3 (gnutls_pkcs11_obj_t OBJ,
gnutls_x509_crt_fmt_t FMT, gnutls_datum_t * OUT)
OBJ: Holds the object
FMT: The format of the exported data
OUT: will contain the object data
This function will export the PKCS11 object data. It is normal for
data to be inaccesible and in that case 'GNUTLS_E_INVALID_REQUEST'
will be returned.
The output buffer is allocated using 'gnutls_malloc()' .
*Returns:* In case of failure a negative error code will be
returned, and 'GNUTLS_E_SUCCESS' (0) on success.
*Since:* 3.2.7
gnutls_pkcs11_obj_export_url
----------------------------
-- Function: int gnutls_pkcs11_obj_export_url (gnutls_pkcs11_obj_t OBJ,
gnutls_pkcs11_url_type_t DETAILED, char ** URL)
OBJ: Holds the PKCS 11 certificate
DETAILED: non zero if a detailed URL is required
URL: will contain an allocated url
This function will export a URL identifying the given certificate.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_obj_flags_get_str
-------------------------------
-- Function: char * gnutls_pkcs11_obj_flags_get_str (unsigned int
FLAGS)
FLAGS: holds the flags
This function given an or-sequence of 'GNUTLS_PKCS11_OBJ_FLAG_MARK'
, will return an allocated string with its description. The string
needs to be deallocated using 'gnutls_free()' .
*Returns:* If flags is zero 'NULL' is returned, otherwise an
allocated string.
*Since:* 3.3.7
gnutls_pkcs11_obj_get_exts
--------------------------
-- Function: int gnutls_pkcs11_obj_get_exts (gnutls_pkcs11_obj_t OBJ,
gnutls_x509_ext_st ** EXTS, unsigned int * EXTS_SIZE, unsigned
int FLAGS)
OBJ: should contain a 'gnutls_pkcs11_obj_t' type
EXTS: a pointer to a 'gnutls_x509_ext_st' pointer
EXTS_SIZE: will be updated with the number of 'exts'
FLAGS: Or sequence of 'GNUTLS_PKCS11_OBJ_' * flags
This function will return information about attached extensions
that associate to the provided object (which should be a
certificate). The extensions are the attached p11-kit trust module
extensions.
Each element of 'exts' must be deinitialized using
'gnutls_x509_ext_deinit()' while 'exts' should be deallocated using
'gnutls_free()' .
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
*Since:* 3.3.8
gnutls_pkcs11_obj_get_flags
---------------------------
-- Function: int gnutls_pkcs11_obj_get_flags (gnutls_pkcs11_obj_t OBJ,
unsigned int * OFLAGS)
OBJ: The structure that holds the object
OFLAGS: Will hold the output flags
This function will return the flags of the object being stored in
the structure. The 'oflags' are the 'GNUTLS_PKCS11_OBJ_FLAG_MARK'
flags.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.3.7
gnutls_pkcs11_obj_get_info
--------------------------
-- Function: int gnutls_pkcs11_obj_get_info (gnutls_pkcs11_obj_t OBJ,
gnutls_pkcs11_obj_info_t ITYPE, void * OUTPUT, size_t *
OUTPUT_SIZE)
OBJ: should contain a 'gnutls_pkcs11_obj_t' structure
ITYPE: Denotes the type of information requested
OUTPUT: where output will be stored
OUTPUT_SIZE: contains the maximum size of the output and will be
overwritten with actual
This function will return information about the PKCS11 certificate
such as the label, id as well as token information where the key is
stored. When output is text it returns null terminated string
although 'output_size' contains the size of the actual data only.
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
*Since:* 2.12.0
gnutls_pkcs11_obj_get_type
--------------------------
-- Function: gnutls_pkcs11_obj_type_t gnutls_pkcs11_obj_get_type
(gnutls_pkcs11_obj_t OBJ)
OBJ: Holds the PKCS 11 object
This function will return the type of the object being stored in
the structure.
*Returns:* The type of the object
*Since:* 2.12.0
gnutls_pkcs11_obj_import_url
----------------------------
-- Function: int gnutls_pkcs11_obj_import_url (gnutls_pkcs11_obj_t OBJ,
const char * URL, unsigned int FLAGS)
OBJ: The structure to store the object
URL: a PKCS 11 url identifying the key
FLAGS: Or sequence of GNUTLS_PKCS11_OBJ_* flags
This function will "import" a PKCS 11 URL identifying an object
(e.g. certificate) to the 'gnutls_pkcs11_obj_t' structure. This
does not involve any parsing (such as X.509 or OpenPGP) since the
'gnutls_pkcs11_obj_t' is format agnostic. Only data are
transferred.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_obj_init
----------------------
-- Function: int gnutls_pkcs11_obj_init (gnutls_pkcs11_obj_t * OBJ)
OBJ: The structure to be initialized
This function will initialize a pkcs11 certificate structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_obj_list_import_url
---------------------------------
-- Function: int gnutls_pkcs11_obj_list_import_url (gnutls_pkcs11_obj_t
* P_LIST, unsigned int * N_LIST, const char * URL,
gnutls_pkcs11_obj_attr_t ATTRS, unsigned int FLAGS)
P_LIST: An uninitialized object list (may be NULL)
N_LIST: initially should hold the maximum size of the list. Will
contain the actual size.
URL: A PKCS 11 url identifying a set of objects
ATTRS: Attributes of type 'gnutls_pkcs11_obj_attr_t' that can be
used to limit output
FLAGS: Or sequence of GNUTLS_PKCS11_OBJ_* flags
This function will initialize and set values to an object list by
using all objects identified by a PKCS 11 URL.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_obj_list_import_url2
----------------------------------
-- Function: int gnutls_pkcs11_obj_list_import_url2
(gnutls_pkcs11_obj_t ** P_LIST, unsigned int * N_LIST, const
char * URL, gnutls_pkcs11_obj_attr_t ATTRS, unsigned int
FLAGS)
P_LIST: An uninitialized object list (may be NULL)
N_LIST: It will contain the size of the list.
URL: A PKCS 11 url identifying a set of objects
ATTRS: Attributes of type 'gnutls_pkcs11_obj_attr_t' that can be
used to limit output
FLAGS: Or sequence of GNUTLS_PKCS11_OBJ_* flags
This function will initialize and set values to an object list by
using all objects identified by the PKCS 11 URL. The output is
stored in 'p_list' , which will be initialized.
All returned objects must be deinitialized using
'gnutls_pkcs11_obj_deinit()' , and 'p_list' must be free'd using
'gnutls_free()' .
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.1.0
gnutls_pkcs11_obj_set_info
--------------------------
-- Function: int gnutls_pkcs11_obj_set_info (gnutls_pkcs11_obj_t OBJ,
gnutls_pkcs11_obj_info_t ITYPE, const void * DATA, size_t
DATA_SIZE, unsigned FLAGS)
OBJ: should contain a 'gnutls_pkcs11_obj_t' structure
ITYPE: Denotes the type of information to be set
DATA: the data to set
DATA_SIZE: the size of data
FLAGS: Or sequence of GNUTLS_PKCS11_OBJ_* flags
This function will set attributes on the provided object.
Available options for 'itype' are 'GNUTLS_PKCS11_OBJ_LABEL' ,
'GNUTLS_PKCS11_OBJ_ID_HEX' , and 'GNUTLS_PKCS11_OBJ_ID' .
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
*Since:* 3.3.26
gnutls_pkcs11_obj_set_pin_function
----------------------------------
-- Function: void gnutls_pkcs11_obj_set_pin_function
(gnutls_pkcs11_obj_t OBJ, gnutls_pin_callback_t FN, void *
USERDATA)
OBJ: The object structure
FN: the callback
USERDATA: data associated with the callback
This function will set a callback function to be used when required
to access the object. This function overrides the global set using
'gnutls_pkcs11_set_pin_function()' .
*Since:* 3.1.0
gnutls_pkcs11_privkey_deinit
----------------------------
-- Function: void gnutls_pkcs11_privkey_deinit (gnutls_pkcs11_privkey_t
KEY)
KEY: The structure to be initialized
This function will deinitialize a private key structure.
gnutls_pkcs11_privkey_export_pubkey
-----------------------------------
-- Function: int gnutls_pkcs11_privkey_export_pubkey
(gnutls_pkcs11_privkey_t PKEY, gnutls_x509_crt_fmt_t FMT,
gnutls_datum_t * DATA, unsigned int FLAGS)
PKEY: The private key
FMT: the format of output params. PEM or DER.
DATA: will hold the public key
FLAGS: should be zero
This function will extract the public key (modulus and public
exponent) from the private key specified by the 'url' private key.
This public key will be stored in 'pubkey' in the format specified
by 'fmt' . 'pubkey' should be deinitialized using 'gnutls_free()'
.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.3.7
gnutls_pkcs11_privkey_export_url
--------------------------------
-- Function: int gnutls_pkcs11_privkey_export_url
(gnutls_pkcs11_privkey_t KEY, gnutls_pkcs11_url_type_t
DETAILED, char ** URL)
KEY: Holds the PKCS 11 key
DETAILED: non zero if a detailed URL is required
URL: will contain an allocated url
This function will export a URL identifying the given key.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs11_privkey_generate
------------------------------
-- Function: int gnutls_pkcs11_privkey_generate (const char * URL,
gnutls_pk_algorithm_t PK, unsigned int BITS, const char *
LABEL, unsigned int FLAGS)
URL: a token URL
PK: the public key algorithm
BITS: the security bits
LABEL: a label
FLAGS: should be zero
This function will generate a private key in the specified by the
'url' token. The private key will be generate within the token and
will not be exportable.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.0
gnutls_pkcs11_privkey_generate2
-------------------------------
-- Function: int gnutls_pkcs11_privkey_generate2 (const char * URL,
gnutls_pk_algorithm_t PK, unsigned int BITS, const char *
LABEL, gnutls_x509_crt_fmt_t FMT, gnutls_datum_t * PUBKEY,
unsigned int FLAGS)
URL: a token URL
PK: the public key algorithm
BITS: the security bits
LABEL: a label
FMT: the format of output params. PEM or DER
PUBKEY: will hold the public key (may be 'NULL' )
FLAGS: zero or an OR'ed sequence of 'GNUTLS_PKCS11_OBJ_FLAGs'
This function will generate a private key in the specified by the
'url' token. The private key will be generate within the token and
will not be exportable. This function will store the DER-encoded
public key in the SubjectPublicKeyInfo format in 'pubkey' . The
'pubkey' should be deinitialized using 'gnutls_free()' .
Note that when generating an elliptic curve key, the curve can be
substituted in the place of the bits parameter using the
'GNUTLS_CURVE_TO_BITS()' macro.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.1.5
gnutls_pkcs11_privkey_generate3
-------------------------------
-- Function: int gnutls_pkcs11_privkey_generate3 (const char * URL,
gnutls_pk_algorithm_t PK, unsigned int BITS, const char *
LABEL, const gnutls_datum_t * CID, gnutls_x509_crt_fmt_t FMT,
gnutls_datum_t * PUBKEY, unsigned int FLAGS)
URL: a token URL
PK: the public key algorithm
BITS: the security bits
LABEL: a label
CID: The CKA_ID to use for the new object
FMT: the format of output params. PEM or DER
PUBKEY: will hold the public key (may be 'NULL' )
FLAGS: zero or an OR'ed sequence of 'GNUTLS_PKCS11_OBJ_FLAGs'
This function will generate a private key in the specified by the
'url' token. The private key will be generate within the token and
will not be exportable. This function will store the DER-encoded
public key in the SubjectPublicKeyInfo format in 'pubkey' . The
'pubkey' should be deinitialized using 'gnutls_free()' .
Note that when generating an elliptic curve key, the curve can be
substituted in the place of the bits parameter using the
'GNUTLS_CURVE_TO_BITS()' macro.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.3.26
gnutls_pkcs11_privkey_get_info
------------------------------
-- Function: int gnutls_pkcs11_privkey_get_info
(gnutls_pkcs11_privkey_t PKEY, gnutls_pkcs11_obj_info_t ITYPE,
void * OUTPUT, size_t * OUTPUT_SIZE)
PKEY: should contain a 'gnutls_pkcs11_privkey_t' structure
ITYPE: Denotes the type of information requested
OUTPUT: where output will be stored
OUTPUT_SIZE: contains the maximum size of the output and will be
overwritten with actual
This function will return information about the PKCS 11 private key
such as the label, id as well as token information where the key is
stored. When output is text it returns null terminated string
although 'output_size' contains the size of the actual data only.
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
gnutls_pkcs11_privkey_get_pk_algorithm
--------------------------------------
-- Function: int gnutls_pkcs11_privkey_get_pk_algorithm
(gnutls_pkcs11_privkey_t KEY, unsigned int * BITS)
KEY: should contain a 'gnutls_pkcs11_privkey_t' structure
BITS: if bits is non null it will hold the size of the parameters'
in bits
This function will return the public key algorithm of a private
key.
*Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
success, or a negative error code on error.
gnutls_pkcs11_privkey_import_url
--------------------------------
-- Function: int gnutls_pkcs11_privkey_import_url
(gnutls_pkcs11_privkey_t PKEY, const char * URL, unsigned int
FLAGS)
PKEY: The structure to store the parsed key
URL: a PKCS 11 url identifying the key
FLAGS: Or sequence of GNUTLS_PKCS11_OBJ_* flags
This function will "import" a PKCS 11 URL identifying a private key
to the 'gnutls_pkcs11_privkey_t' structure. In reality since in
most cases keys cannot be exported, the private key structure is
being associated with the available operations on the token.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs11_privkey_init
--------------------------
-- Function: int gnutls_pkcs11_privkey_init (gnutls_pkcs11_privkey_t *
KEY)
KEY: The structure to be initialized
This function will initialize an private key structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs11_privkey_set_pin_function
--------------------------------------
-- Function: void gnutls_pkcs11_privkey_set_pin_function
(gnutls_pkcs11_privkey_t KEY, gnutls_pin_callback_t FN, void *
USERDATA)
KEY: The private key
FN: the callback
USERDATA: data associated with the callback
This function will set a callback function to be used when required
to access the object. This function overrides the global set using
'gnutls_pkcs11_set_pin_function()' .
*Since:* 3.1.0
gnutls_pkcs11_privkey_status
----------------------------
-- Function: int gnutls_pkcs11_privkey_status (gnutls_pkcs11_privkey_t
KEY)
KEY: Holds the key
Checks the status of the private key token.
*Returns:* this function will return non-zero if the token holding
the private key is still available (inserted), and zero otherwise.
*Since:* 3.1.9
gnutls_pkcs11_reinit
--------------------
-- Function: int gnutls_pkcs11_reinit ( VOID)
This function will reinitialize the PKCS 11 subsystem in gnutls.
This is required by PKCS 11 when an application uses 'fork()' .
The reinitialization function must be called on the child.
Note that since GnuTLS 3.3.0, the reinitialization of the PKCS '11'
subsystem occurs automatically after fork.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 3.0
gnutls_pkcs11_set_pin_function
------------------------------
-- Function: void gnutls_pkcs11_set_pin_function (gnutls_pin_callback_t
FN, void * USERDATA)
FN: The PIN callback, a 'gnutls_pin_callback_t()' function.
USERDATA: data to be supplied to callback
This function will set a callback function to be used when a PIN is
required for PKCS 11 operations. See 'gnutls_pin_callback_t()' on
how the callback should behave.
*Since:* 2.12.0
gnutls_pkcs11_set_token_function
--------------------------------
-- Function: void gnutls_pkcs11_set_token_function
(gnutls_pkcs11_token_callback_t FN, void * USERDATA)
FN: The token callback
USERDATA: data to be supplied to callback
This function will set a callback function to be used when a token
needs to be inserted to continue PKCS 11 operations.
*Since:* 2.12.0
gnutls_pkcs11_token_get_flags
-----------------------------
-- Function: int gnutls_pkcs11_token_get_flags (const char * URL,
unsigned int * FLAGS)
URL: should contain a PKCS 11 URL
FLAGS: The output flags (GNUTLS_PKCS11_TOKEN_*)
This function will return information about the PKCS 11 token
flags.
The supported flags are: 'GNUTLS_PKCS11_TOKEN_HW' and
'GNUTLS_PKCS11_TOKEN_TRUSTED' .
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
*Since:* 2.12.0
gnutls_pkcs11_token_get_info
----------------------------
-- Function: int gnutls_pkcs11_token_get_info (const char * URL,
gnutls_pkcs11_token_info_t TTYPE, void * OUTPUT, size_t *
OUTPUT_SIZE)
URL: should contain a PKCS 11 URL
TTYPE: Denotes the type of information requested
OUTPUT: where output will be stored
OUTPUT_SIZE: contains the maximum size of the output and will be
overwritten with actual
This function will return information about the PKCS 11 token such
as the label, id, etc.
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
*Since:* 2.12.0
gnutls_pkcs11_token_get_mechanism
---------------------------------
-- Function: int gnutls_pkcs11_token_get_mechanism (const char * URL,
unsigned int IDX, unsigned long * MECHANISM)
URL: should contain a PKCS 11 URL
IDX: The index of the mechanism
MECHANISM: The PKCS '11' mechanism ID
This function will return the names of the supported mechanisms by
the token. It should be called with an increasing index until it
return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE.
*Returns:* 'GNUTLS_E_SUCCESS' (0) on success or a negative error
code on error.
*Since:* 2.12.0
gnutls_pkcs11_token_get_random
------------------------------
-- Function: int gnutls_pkcs11_token_get_random (const char *
TOKEN_URL, void * RNDDATA, size_t LEN)
TOKEN_URL: A PKCS '11' URL specifying a token
RNDDATA: A pointer to the memory area to be filled with random data
LEN: The number of bytes of randomness to request
This function will get random data from the given token. It will
store rnddata and fill the memory pointed to by rnddata with len
random bytes from the token.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs11_token_get_url
---------------------------
-- Function: int gnutls_pkcs11_token_get_url (unsigned int SEQ,
gnutls_pkcs11_url_type_t DETAILED, char ** URL)
SEQ: sequence number starting from 0
DETAILED: non zero if a detailed URL is required
URL: will contain an allocated url
This function will return the URL for each token available in
system. The url has to be released using 'gnutls_free()'
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE' if the sequence number
exceeds the available tokens, otherwise a negative error value.
*Since:* 2.12.0
gnutls_pkcs11_token_init
------------------------
-- Function: int gnutls_pkcs11_token_init (const char * TOKEN_URL,
const char * SO_PIN, const char * LABEL)
TOKEN_URL: A PKCS '11' URL specifying a token
SO_PIN: Security Officer's PIN
LABEL: A name to be used for the token
This function will initialize (format) a token. If the token is at
a factory defaults state the security officer's PIN given will be
set to be the default. Otherwise it should match the officer's
PIN.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs11_token_set_pin
---------------------------
-- Function: int gnutls_pkcs11_token_set_pin (const char * TOKEN_URL,
const char * OLDPIN, const char * NEWPIN, unsigned int FLAGS)
TOKEN_URL: A PKCS '11' URL specifying a token
OLDPIN: old user's PIN
NEWPIN: new user's PIN
FLAGS: one of 'gnutls_pin_flag_t' .
This function will modify or set a user's PIN for the given token.
If it is called to set a user pin for first time the oldpin must be
NULL.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
gnutls_pkcs11_type_get_name
---------------------------
-- Function: const char * gnutls_pkcs11_type_get_name
(gnutls_pkcs11_obj_type_t TYPE)
TYPE: Holds the PKCS 11 object type, a 'gnutls_pkcs11_obj_type_t' .
This function will return a human readable description of the
PKCS11 object type 'obj' . It will return "Unknown" for unknown
types.
*Returns:* human readable string labeling the PKCS11 object type
'type' .
*Since:* 2.12.0
gnutls_x509_crt_import_pkcs11
-----------------------------
-- Function: int gnutls_x509_crt_import_pkcs11 (gnutls_x509_crt_t CRT,
gnutls_pkcs11_obj_t PKCS11_CRT)
CRT: A certificate of type 'gnutls_x509_crt_t'
PKCS11_CRT: A PKCS 11 object that contains a certificate
This function will import a PKCS 11 certificate to a
'gnutls_x509_crt_t' structure.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_x509_crt_import_pkcs11_url
---------------------------------
-- Function: int gnutls_x509_crt_import_pkcs11_url (gnutls_x509_crt_t
CRT, const char * URL, unsigned int FLAGS)
CRT: A certificate of type 'gnutls_x509_crt_t'
URL: A PKCS 11 url
FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
This function will import a PKCS 11 certificate directly from a
token without involving the 'gnutls_pkcs11_obj_t' structure. This
function will fail if the certificate stored is not of X.509 type.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0
gnutls_x509_crt_list_import_pkcs11
----------------------------------
-- Function: int gnutls_x509_crt_list_import_pkcs11 (gnutls_x509_crt_t
* CERTS, unsigned int CERT_MAX, gnutls_pkcs11_obj_t * const
OBJS, unsigned int FLAGS)
CERTS: A list of certificates of type 'gnutls_x509_crt_t'
CERT_MAX: The maximum size of the list
OBJS: A list of PKCS 11 objects
FLAGS: 0 for now
This function will import a PKCS 11 certificate list to a list of
'gnutls_x509_crt_t' structure. These must not be initialized.
*Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
otherwise a negative error value.
*Since:* 2.12.0