corrected function name
[gnutls.git] / doc / cha-cert-auth2.texi
blob9f983a43d8f5105c61c2960578c9172fbdf62e61
1 @node More on certificate authentication
2 @chapter More on certificate authentication
3 @cindex certificate authentication
5 Certificates are not the only structures involved in a public key
6 infrastructure. Several other structures that are used for certificate
7 requests, encrypted private keys, revocation lists, GnuTLS abstract key
8 structures, etc., are discussed in this chapter.
10 @menu
11 * PKCS 10 certificate requests::
12 * PKIX certificate revocation lists::
13 * OCSP certificate status checking::
14 * Managing encrypted keys::
15 * certtool Invocation::            Invoking certtool
16 * ocsptool Invocation::            Invoking ocsptool
17 * Smart cards and HSMs::
18 * Abstract key types::
19 @end menu
21 @node PKCS 10 certificate requests
22 @section @acronym{PKCS} #10 certificate requests
23 @cindex certificate requests
24 @cindex PKCS #10
26 A certificate request is a structure, which contain information about
27 an applicant of a certificate service.  It usually contains a private
28 key, a distinguished name and secondary data such as a challenge
29 password. @acronym{GnuTLS} supports the requests defined in
30 @acronym{PKCS} #10 @xcite{RFC2986}. Other formats of certificate requests
31 are not currently supported.
33 A certificate request can be generated by
34 associating it with a private key, setting the
35 subject's information and finally self signing it.
36 The last step ensures that the requester is in
37 possession of the private key.
39 @showfuncE{gnutls_x509_crq_set_version,gnutls_x509_crq_set_dn_by_oid,gnutls_x509_crq_set_key_usage,gnutls_x509_crq_set_key_purpose_oid,gnutls_x509_crq_set_basic_constraints}
41 The @funcref{gnutls_x509_crq_set_key} and @funcref{gnutls_x509_crq_sign2} 
42 functions associate the request with a private key and sign it. If a 
43 request is to be signed with a key residing in a PKCS #11 token it is recommended to use
44 the signing functions shown in @ref{Abstract key types}.
46 @showfuncdesc{gnutls_x509_crq_set_key}
47 @showfuncdesc{gnutls_x509_crq_sign2}
49 The following example is about generating a certificate request, and a
50 private key. A certificate request can be later be processed by a CA
51 which should return a signed certificate.
53 @anchor{ex:crq}
54 @verbatiminclude examples/ex-crq.c
56 @node PKIX certificate revocation lists
57 @section PKIX certificate revocation lists
58 @cindex certificate revocation lists
59 @cindex CRL
61 A certificate revocation list (CRL) is a structure issued by an authority
62 periodically containing a list of revoked certificates serial numbers. 
63 The CRL structure is signed with the issuing authorities' keys. A typical
64 CRL contains the fields as shown in @ref{tab:crl}.
65 Certificate revocation lists are used to complement the expiration date of a certificate,
66 in order to account for other reasons of revocation, such as compromised keys, etc.
68 A certificate request can be generated by
69 associating it with a private key, setting the
70 subject's information and finally self signing it.
71 The last step ensures that the requester is in
72 possession of the private key. Each CRL is valid for limited amount of
73 time and is required to provide, except for the current issuing time, also 
74 the issuing time of the next update.
76 @float Table,tab:crl
77 @multitable @columnfractions .2 .7
79 @headitem Field @tab Description
81 @item version @tab
82 The field that indicates the version of the CRL structure.
84 @item signature @tab
85 A signature by the issuing authority.
87 @item issuer @tab
88 Holds the issuer's distinguished name.
90 @item thisUpdate @tab
91 The issuing time of the revocation list.
93 @item nextUpdate @tab
94 The issuing time of the revocation list that will update that one.
96 @item revokedCertificates @tab
97 List of revoked certificates serial numbers.
99 @item extensions @tab
100 Optional CRL structure extensions.
102 @end multitable
103 @caption{Certificate revocation list fields.}
104 @end float
107 @showfuncE{gnutls_x509_crl_set_version,gnutls_x509_crl_set_crt_serial,gnutls_x509_crl_set_crt,gnutls_x509_crl_set_next_update,gnutls_x509_crl_set_this_update}
109 The @funcref{gnutls_x509_crl_sign2} and @funcref{gnutls_x509_crl_privkey_sign} 
110 functions sign the revocation list with a private key. The latter function
111 can be used to sign with a key residing in a PKCS #11 token.
113 @showfuncdesc{gnutls_x509_crl_sign2}
114 @showfuncdesc{gnutls_x509_crl_privkey_sign}
116 Few extensions on the CRL structure are supported, including the
117 CRL number extension and the authority key identifier.
119 @showfuncB{gnutls_x509_crl_set_number,gnutls_x509_crl_set_authority_key_id}
121 @node OCSP certificate status checking
122 @section @acronym{OCSP} certificate status checking
123 @cindex certificate status
124 @cindex Online Certificate Status Protocol
125 @cindex OCSP
127 Certificates may be revoked before their expiration time has been
128 reached.  There are several reasons for revoking certificates, but a
129 typical situation is when the private key associated with a
130 certificate has been compromised.  Traditionally, Certificate
131 Revocation Lists (CRLs) have been used by application to implement
132 revocation checking, however, several problems with CRLs have been
133 identified @xcite{RIVESTCRL}.
135 The Online Certificate Status Protocol, or @acronym{OCSP} @xcite{RFC2560}, 
136 is a widely implemented protocol to perform certificate revocation status
137 checking.  An application that wish to verify the
138 identity of a peer will verify the certificate against a set of
139 trusted certificates and then check whether the certificate is listed
140 in a CRL and/or perform an OCSP check for the certificate.
142 Before performing the OCSP query, the application will need to figure
143 out the address of the OCSP server.  The OCSP server address can be
144 provided by the local user in manual configuration or may be stored
145 in the certificate that is being checked.  The latter is due to
146 an extension field called the Authority Information Access (AIA) which
147 may hold the location of the OCSP responder in 
148 the access method called @code{id-ad-ocsp}. The following function
149 extracts this information from a certificate.
151 @showfuncA{gnutls_x509_crt_get_authority_info_access}
153 There are several functions in GnuTLS for creating and manipulating
154 OCSP requests and responses.  The general idea is that a client
155 application create an OCSP request object, store some information
156 about the certificate to check in the request, and then export the
157 request in DER format.  The request will then need to be sent to the
158 OCSP responder, which needs to be done by the application (GnuTLS does
159 not send and receive OCSP packets).  Normally an OCSP response is
160 received that the application will need to import into an OCSP
161 response object.  The digital signature in the OCSP response needs to
162 be verified against a set of trust anchors before the information in
163 the response can be trusted.
165 The ASN.1 structure of OCSP requests are briefly as follows.  It is
166 useful to review the structures to get an understanding of which
167 fields are modified by GnuTLS functions.
169 @example
170 OCSPRequest     ::=     SEQUENCE @{
171     tbsRequest                  TBSRequest,
172     optionalSignature   [0]     EXPLICIT Signature OPTIONAL @}
174 TBSRequest      ::=     SEQUENCE @{
175     version             [0]     EXPLICIT Version DEFAULT v1,
176     requestorName       [1]     EXPLICIT GeneralName OPTIONAL,
177     requestList                 SEQUENCE OF Request,
178     requestExtensions   [2]     EXPLICIT Extensions OPTIONAL @}
180 Request         ::=     SEQUENCE @{
181     reqCert                     CertID,
182     singleRequestExtensions     [0] EXPLICIT Extensions OPTIONAL @}
184 CertID          ::=     SEQUENCE @{
185     hashAlgorithm       AlgorithmIdentifier,
186     issuerNameHash      OCTET STRING, -- Hash of Issuer's DN
187     issuerKeyHash       OCTET STRING, -- Hash of Issuers public key
188     serialNumber        CertificateSerialNumber @}
189 @end example
191 The basic functions to initialize, import, export and deallocate OCSP
192 requests are the following.
194 @showfuncE{gnutls_ocsp_req_init,gnutls_ocsp_req_deinit,gnutls_ocsp_req_import,gnutls_ocsp_req_export,gnutls_ocsp_req_print}
196 There are two interfaces for setting the identity of a certificate in
197 a OCSP request, the first being a low-level function when you have the
198 issuer name hash, issuer key hash, and certificate serial number in
199 binary form.  The second is usually more useful if you have the
200 certificate (and its issuer) in a @code{gnutls_x509_crt_t} type.
201 There is also a function to extract this information from an OCSP
202 request.
204 @showfuncC{gnutls_ocsp_req_add_cert_id,gnutls_ocsp_req_add_cert,gnutls_ocsp_req_get_cert_id}
206 Each OCSP request may contain a number of extensions.  Extensions are
207 identified by an Object Identifier (OID) and an opaque data buffer
208 whose syntax and semantics is implied by the OID.
210 @showfuncB{gnutls_ocsp_req_get_extension,gnutls_ocsp_req_set_extension}
212 A common OCSP Request extension is the nonce extension (OID
213 1.3.6.1.5.5.7.48.1.2), which is used to avoid replay attacks of
214 earlier recorded OCSP responses.  The nonce extension carries a value
215 that is intended to be sufficiently random and unique so that an
216 attacker will not be able to give a stale response for the same nonce.
218 @showfuncC{gnutls_ocsp_req_get_nonce,gnutls_ocsp_req_set_nonce,gnutls_ocsp_req_randomize_nonce}
220 The OCSP response structures is a bit more complex than the request.
221 The important ASN.1 structure is as follows.  In practice, all OCSP
222 responses contain a Basic OCSP response sub-structure.
224 @example
225 OCSPResponse ::= SEQUENCE @{
226    responseStatus         OCSPResponseStatus,
227    responseBytes          [0] EXPLICIT ResponseBytes OPTIONAL @}
229 OCSPResponseStatus ::= ENUMERATED @{
230     successful            (0),  --Response has valid confirmations
231     malformedRequest      (1),  --Illegal confirmation request
232     internalError         (2),  --Internal error in issuer
233     tryLater              (3),  --Try again later
234                                 --(4) is not used
235     sigRequired           (5),  --Must sign the request
236     unauthorized          (6)   --Request unauthorized @}
238 ResponseBytes ::=       SEQUENCE @{
239     responseType   OBJECT IDENTIFIER,
240     response       OCTET STRING @}
242 id-pkix-ocsp-basic     OBJECT IDENTIFIER ::= @{ id-pkix-ocsp 1 @}
244 BasicOCSPResponse       ::= SEQUENCE @{
245    tbsResponseData      ResponseData,
246    signatureAlgorithm   AlgorithmIdentifier,
247    signature            BIT STRING,
248    certs                [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL @}
250 ResponseData ::= SEQUENCE @{
251    version              [0] EXPLICIT Version DEFAULT v1,
252    responderID              ResponderID,
253    producedAt               GeneralizedTime,
254    responses                SEQUENCE OF SingleResponse,
255    responseExtensions   [1] EXPLICIT Extensions OPTIONAL @}
257 ResponderID ::= CHOICE @{
258    byName               [1] Name,
259    byKey                [2] KeyHash @}
261 KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key
262 (excluding the tag and length fields)
264 SingleResponse ::= SEQUENCE @{
265    certID                       CertID,
266    certStatus                   CertStatus,
267    thisUpdate                   GeneralizedTime,
268    nextUpdate         [0]       EXPLICIT GeneralizedTime OPTIONAL,
269    singleExtensions   [1]       EXPLICIT Extensions OPTIONAL @}
271 CertStatus ::= CHOICE @{
272     good        [0]     IMPLICIT NULL,
273     revoked     [1]     IMPLICIT RevokedInfo,
274     unknown     [2]     IMPLICIT UnknownInfo @}
276 RevokedInfo ::= SEQUENCE @{
277     revocationTime              GeneralizedTime,
278     revocationReason    [0]     EXPLICIT CRLReason OPTIONAL @}
279 @end example
281 We provide basic functions for initialization, importing, exporting
282 and deallocating OCSP responses.  The Basic OCSP Response structure is
283 automatically parsed when an OCSP Response is imported.
285 @showfuncE{gnutls_ocsp_resp_init,gnutls_ocsp_resp_deinit,gnutls_ocsp_resp_import,gnutls_ocsp_resp_export,gnutls_ocsp_resp_print}
287 The OCSP response needs to be verified against some set of trust
288 anchors before it can be relied upon.
290 @showfuncB{gnutls_ocsp_resp_verify,gnutls_ocsp_resp_verify_direct}
292 @node Managing encrypted keys
293 @section Managing encrypted keys
294 @cindex Encrypted keys
296 Transferring or storing private keys in plain might not be a
297 good idea. Any access on the keys becomes a fatal compromise.
298 Storing the keys in hardware security modules (see @ref{Smart cards and HSMs})
299 could solve the storage problem but it is not always practical
300 or efficient enough. This section describes alternative ways
301 that involve encryption of the private keys to store and
302 transfer.
304 There are two alternatives to use for key encryption, 
305 PKCS #8 and #12 methods of private key encryption. The PKCS #8
306 method only allows encryption of the private key, whilst the
307 PKCS #12 method allows in addition the bundling of other
308 data into the structure. That could be bundling together the
309 certificate as well as the trusted CA certificate.
311 @subheading @acronym{PKCS} #8 structures
312 @cindex PKCS #8
314 PKCS #8 keys can be imported and exported as normal private keys using
315 the functions below. An addition to the normal import functions, are
316 a password and a flags argument. The flags can be any element of the @code{gnutls_pkcs_encrypt_flags_t}
317 enumeration. Note however, that GnuTLS only supports the PKCS #5 PBES2
318 encryption scheme. Keys encrypted with the obsolete PBES1 scheme cannot 
319 be decrypted.
321 @showfuncB{gnutls_x509_privkey_import_pkcs8,gnutls_x509_privkey_export_pkcs8}
323 @showenumdesc{gnutls_pkcs_encrypt_flags_t,Encryption flags}
325 @subheading @acronym{PKCS} #12 structures
326 @cindex PKCS #12
328 A @acronym{PKCS} #12 structure @xcite{PKCS12} usually contains a user's
329 private keys and certificates. It is commonly used in browsers to
330 export and import the user's identities.
332 In @acronym{GnuTLS} the @acronym{PKCS} #12 structures are handled
333 using the @code{gnutls_pkcs12_t} type. This is an abstract type that
334 may hold several @code{gnutls_pkcs12_bag_t} types.  The bag types are
335 the holders of the actual data, which may be certificates, private
336 keys or encrypted data.  A bag of type encrypted should be decrypted
337 in order for its data to be accessed.
339 @showfuncC{gnutls_pkcs12_get_bag,gnutls_pkcs12_verify_mac,gnutls_pkcs12_bag_decrypt}
341 @showfuncD{gnutls_pkcs12_bag_get_count,gnutls_pkcs12_bag_get_data,gnutls_pkcs12_bag_get_key_id,gnutls_pkcs12_bag_get_friendly_name}
343 The functions below are used to generate a PKCS #12 structure. An example
344 of their usage is also shown.
346 @showfuncC{gnutls_pkcs12_set_bag,gnutls_pkcs12_bag_encrypt,gnutls_pkcs12_generate_mac}
347 @showfuncE{gnutls_pkcs12_bag_set_data,gnutls_pkcs12_bag_set_crl,gnutls_pkcs12_bag_set_crt,gnutls_pkcs12_bag_set_key_id,gnutls_pkcs12_bag_set_friendly_name}
349 @verbatiminclude examples/ex-pkcs12.c
351 @include invoke-certtool.texi
353 @include invoke-ocsptool.texi
355 @node Smart cards and HSMs
356 @section Smart cards and HSMs
357 @cindex PKCS #11 tokens
358 @cindex hardware tokens
359 @cindex hardware security modules
360 @cindex smart cards
362 In this section we present the smart-card and hardware security module (HSM) support 
363 in @acronym{GnuTLS} using @acronym{PKCS} #11 @xcite{PKCS11}. Hardware security
364 modules and smart cards provide a way to store private keys and perform
365 operations on them without exposing them. This decouples cryptographic
366 keys from the applications that use them and provide an additional 
367 security layer against cryptographic key extraction.
368 Since this can also be achieved in software components such as in Gnome keyring,
369 we will use the term security module to describe any cryptographic key 
370 separation subsystem.
372 @acronym{PKCS} #11 is plugin API allowing applications to access cryptographic
373 operations on a security module, as well as to objects residing on it. PKCS
374 #11 modules exist for hardware tokens such as smart cards@footnote{@url{http://www.opensc-project.org}},
375 the trusted 
376 platform module (TPM)@footnote{@url{http://trousers.sourceforge.net/}}
377 as well as for software modules like @acronym{Gnome Keyring}. 
378 The objects residing on a security module may be certificates, public keys, 
379 private keys or secret keys. Of those certificates and public/private key 
380 pairs can be used with @acronym{GnuTLS}. PKCS #11's main advantage is that 
381 it allows operations on private key objects such as decryption
382 and signing without exposing the key.
384 Moreover @acronym{PKCS} #11 can be (ab)used to allow all applications in the same operating system to access
385 shared cryptographic keys and certificates in a uniform way, as in @ref{fig:pkcs11-vision}.
386 That way applications could load their trusted certificate list, as well as user
387 certificates from a common PKCS #11 module. Such a provider exists in the @acronym{Gnome} 
388 system, being the @acronym{Gnome Keyring}.
390 @float Figure,fig:pkcs11-vision
391 @image{pkcs11-vision,9cm}
392 @caption{PKCS #11 module usage.}
393 @end float
395 @menu
396 * PKCS11 Initialization::
397 * Reading objects::
398 * Writing objects::
399 * Using a PKCS11 token with TLS::
400 * p11tool Invocation::             Invoking p11tool
401 @end menu
403 @node PKCS11 Initialization
404 @subsection Initialization
405 To allow all the  @acronym{GnuTLS} applications to access @acronym{PKCS} #11 tokens
406 you can use a configuration per module, stored in @code{/etc/pkcs11/modules/}. 
407 These are the configuration files of @acronym{p11-kit}@footnote{@url{http://p11-glue.freedesktop.org/}}.
408 For example a file that will load the @acronym{OpenSC} module, could be named
409 @code{/etc/pkcs11/modules/opensc} and contain the following:
411 @example
412 module: /usr/lib/opensc-pkcs11.so
413 @end example
415 If you use this file, then there is no need for other initialization in
416 @acronym{GnuTLS}, except for the PIN and token functions. Those allow retrieving a PIN
417 when accessing a protected object, such as a private key, as well as probe
418 the user to insert the token. All the initialization functions are below.
420 @showfuncdesc{gnutls_pkcs11_init}
421 @showfuncC{gnutls_pkcs11_set_token_function,gnutls_pkcs11_set_pin_function,gnutls_pkcs11_add_provider}
423 Note that due to limitations of @acronym{PKCS} #11 there are issues when multiple libraries 
424 are sharing a module. To avoid this problem GnuTLS uses @acronym{p11-kit}
425 that provides a middleware to control access to resources over the
426 multiple users.
428 Moreover PKCS #11 modules must be reinitialized on the child processes
429 after a @funcintref{fork}. @acronym{GnuTLS} provides @funcref{gnutls_pkcs11_reinit}
430 to be called for this purpose.
432 @showfuncdesc{gnutls_pkcs11_reinit}
434 @node Reading objects
435 @subsection Reading objects
437 All @acronym{PKCS} #11 objects are referenced by @acronym{GnuTLS} functions by
438 URLs as described in @xcite{PKCS11URI}. 
439 This allows for a consistent naming of objects across systems and applications
440 in the same system. For example a public
441 key on a smart card may be referenced as:
443 @example
444 pkcs11:token=Nikos;serial=307521161601031;model=PKCS%2315; \
445 manufacturer=EnterSafe;object=test1;objecttype=public;\
446 id=32f153f3e37990b08624141077ca5dec2d15faed
447 @end example
449 while the smart card itself can be referenced as:
450 @example
451 pkcs11:token=Nikos;serial=307521161601031;model=PKCS%2315;manufacturer=EnterSafe
452 @end example
454 Objects stored in a @acronym{PKCS} #11 token can be extracted
455 if they are not marked as sensitive. Usually only private keys are marked as
456 sensitive and cannot be extracted, while certificates and other data can
457 be retrieved. The functions that can be used to access objects
458 are shown below.
460 @showfuncB{gnutls_pkcs11_obj_import_url,gnutls_pkcs11_obj_export_url}
462 @showfuncdesc{gnutls_pkcs11_obj_get_info}
464 @showfuncC{gnutls_x509_crt_import_pkcs11,gnutls_x509_crt_import_pkcs11_url,gnutls_x509_crt_list_import_pkcs11}
466 Properties of the physical token can also be accessed and altered with @acronym{GnuTLS}.
467 For example data in a token can be erased (initialized), PIN can be altered, etc.
469 @showfuncE{gnutls_pkcs11_token_init,gnutls_pkcs11_token_get_url,gnutls_pkcs11_token_get_info,gnutls_pkcs11_token_get_flags,gnutls_pkcs11_token_set_pin}
471 The following examples demonstrate the usage of the API. The first example
472 will list all available PKCS #11 tokens in a system and the latter will
473 list all certificates in a token that have a corresponding private key.
475 @example
476 int i;
477 char* url;
479 gnutls_global_init();
481 for (i=0;;i++) 
482   @{
483     ret = gnutls_pkcs11_token_get_url(i, &url);
484     if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
485       break;
487     if (ret < 0)
488       exit(1);
489                 
490     fprintf(stdout, "Token[%d]: URL: %s\n", i, url);
491     gnutls_free(url);
492   @}
493 gnutls_global_deinit();
494 @end example
496 @verbatiminclude examples/ex-pkcs11-list.c
498 @node Writing objects
499 @subsection Writing objects
501 With @acronym{GnuTLS} you can copy existing private keys and certificates
502 to a token. Note that when copying private keys it is recommended to mark
503 them as sensitive using the @code{GNUTLS_@-PKCS11_OBJ_@-FLAG_@-MARK_@-SENSITIVE}
504 to prevent its extraction. An object can be marked as private using the flag 
505 @code{GNUTLS_@-PKCS11_OBJ_@-FLAG_@-MARK_@-PRIVATE}, to require PIN to be
506 entered before accessing the object (for operations or otherwise).
508 @showfuncdesc{gnutls_pkcs11_copy_x509_privkey}
510 @showfuncdesc{gnutls_pkcs11_copy_x509_crt}
511 @showfuncdesc{gnutls_pkcs11_delete_url}
514 @node Using a PKCS11 token with TLS
515 @subsection Using a @acronym{PKCS} #11 token with TLS
517 It is possible to use a @acronym{PKCS} #11 token to a TLS
518 session, as shown in @ref{ex:pkcs11-client}. In addition
519 the following functions can be used to load PKCS #11 key and
520 certificates by specifying a PKCS #11 URL instead of a filename.
522 @showfuncB{gnutls_certificate_set_x509_trust_file,gnutls_certificate_set_x509_key_file}
523 @showfuncdesc{gnutls_certificate_set_x509_system_trust}
525 @include invoke-p11tool.texi
527 @node Abstract key types
528 @section Abstract key types
529 @cindex abstract types
531 Since there are many forms of a public or private keys supported by @acronym{GnuTLS} such as
532 @acronym{X.509}, @acronym{OpenPGP}, or @acronym{PKCS} #11 it is desirable to allow common operations
533 on them. For these reasons the abstract @code{gnutls_privkey_t} and @code{gnutls_pubkey_t} were
534 introduced in @code{gnutls/abstract.h} header. Those types are initialized using a specific type of 
535 key and then can be used to perform operations in an abstract way. For example in order
536 to sign an X.509 certificate with a key that resides in a token the following steps must be
537 used.
539 @example
540 #inlude <gnutls/abstract.h>
541 #inlude <gnutls/pkcs11.h>
543 void sign_cert( gnutls_x509_crt_t to_be_signed)
545 gnutls_pkcs11_privkey_t ca_key;
546 gnutls_x509_crt_t ca_cert;
547 gnutls_privkey_t abs_key;
549   /* load the PKCS #11 key and certificates */
550   gnutls_pkcs11_privkey_init(&ca_key);
551   gnutls_pkcs11_privkey_import_url(ca_key, key_url);
553   gnutls_x509_crt_init(&ca_cert);
554   gnutls_x509_crt_import_pkcs11_url(&ca_cert, cert_url);
556   /* initialize the abstract key */
557   gnutls_privkey_init(&abs_key);
558   gnutls_privkey_import_pkcs11(abs_key, ca_key);
560   /* sign the certificate to be signed */
561   gnutls_x509_crt_privkey_sign(to_be_signed, ca_cert, ca_key, 
562                                GNUTLS_DIG_SHA256, 0);
564 @end example
566 @menu
567 * Abstract public keys::
568 * Abstract private keys::
569 * Operations::
570 @end menu
573 @node Abstract public keys
574 @subsection Public keys
575 An abstract @code{gnutls_pubkey_t} can be initialized
576 using the functions below. It can be imported through
577 an existing structure like @code{gnutls_x509_crt_t},
578 or through an ASN.1 encoding of the X.509 @code{SubjectPublicKeyInfo}
579 sequence.
581 @showfuncdesc{gnutls_pubkey_import_x509}
582 @showfuncE{gnutls_pubkey_import_openpgp,gnutls_pubkey_import_pkcs11,gnutls_pubkey_import_pkcs11_url,gnutls_pubkey_import_privkey,gnutls_pubkey_import}
583 @showfuncdesc{gnutls_pubkey_export}
585 Additional functions are available that will return
586 information over a public key.
588 @showfuncC{gnutls_pubkey_get_pk_algorithm,gnutls_pubkey_get_preferred_hash_algorithm,gnutls_pubkey_get_key_id}
590 @node Abstract private keys
591 @subsection Private keys
592 An abstract @code{gnutls_privkey_t} can be initialized
593 using the functions below. It can be imported through
594 an existing structure like @code{gnutls_x509_privkey_t},
595 but unlike public keys it cannot be exported. That is
596 to allow abstraction over @acronym{PKCS} #11 keys that
597 are not extractable.
599 @showfuncC{gnutls_privkey_import_x509,gnutls_privkey_import_openpgp,gnutls_privkey_import_pkcs11}
601 @showfuncB{gnutls_privkey_get_pk_algorithm,gnutls_privkey_get_type}
603 In order to support cryptographic operations using 
604 an external API, the following function is provided.
605 This allows for a simple extensibility API without
606 resorting to @acronym{PKCS} #11.
608 @showfuncdesc{gnutls_privkey_import_ext}
610 @node Operations
611 @subsection Operations
612 The abstract key types can be used to access signing and
613 signature verification operations with the underlying keys.
615 @showfuncdesc{gnutls_pubkey_verify_data2}
616 @showfuncdesc{gnutls_pubkey_verify_hash2}
617 @showfuncdesc{gnutls_pubkey_encrypt_data}
619 @showfuncdesc{gnutls_privkey_sign_data}
620 @showfuncdesc{gnutls_privkey_sign_hash}
621 @showfuncdesc{gnutls_privkey_decrypt_data}
623 Signing existing structures, such as certificates, CRLs,
624 or certificate requests, as well as associating public
625 keys with structures is also possible using the 
626 key abstractions.
628 @showfuncdesc{gnutls_x509_crq_set_pubkey}
629 @showfuncdesc{gnutls_x509_crt_set_pubkey}
630 @showfuncC{gnutls_x509_crt_privkey_sign,gnutls_x509_crl_privkey_sign,gnutls_x509_crq_privkey_sign}