Add `gnutls/dtls.h' to the distribution.
[gnutls.git] / doc / cha-cert-auth.texi
blob08f1e1c602f90aab311f88b8caf9c491813374bd
1 @node More on certificate authentication
2 @chapter More on Certificate Authentication
3 @anchor{Certificate Authentication}
4 @cindex Certificate authentication
6 @menu
7 * The X.509 trust model::
8 * The OpenPGP trust model::
9 * PKCS #11 tokens::
10 * Abstract data types::
11 * Digital signatures::
12 @end menu
14 @node The X.509 trust model
15 @section The @acronym{X.509} Trust Model
16 @cindex @acronym{X.509} certificates
18 The @acronym{X.509} protocols rely on a hierarchical trust model. In
19 this trust model Certification Authorities (CAs) are used to certify
20 entities.  Usually more than one certification authorities exist, and
21 certification authorities may certify other authorities to issue
22 certificates as well, following a hierarchical model.
24 @image{gnutls-x509,7cm,9.5cm}
26 One needs to trust one or more CAs for his secure communications. In
27 that case only the certificates issued by the trusted authorities are
28 acceptable.  See the figure above for a typical example.  The API for
29 handling @acronym{X.509} certificates is described at section
30 @ref{sec:x509api}.  Some examples are listed below.
32 @menu
33 * X.509 certificates::
34 * Verifying X.509 certificate paths::
35 * PKCS #10 certificate requests::
36 * PKCS #12 structures::
37 @end menu
39 @node X.509 certificates
40 @subsection @acronym{X.509} Certificates
42 An @acronym{X.509} certificate usually contains information about the
43 certificate holder, the signer, a unique serial number, expiration
44 dates and some other fields @xcite{PKIX} as shown in the table below.
46 @table @code
48 @item version:
49 The field that indicates the version of the certificate.
51 @item serialNumber:
52 This field holds a unique serial number per certificate.
54 @item issuer:
55 Holds the issuer's distinguished name.
57 @item validity:
58 The activation and expiration dates.
60 @item subject:
61 The subject's distinguished name of the certificate.
63 @item extensions:
64 The extensions are fields only present in version 3 certificates.
66 @end table
68 The certificate's @emph{subject or issuer name} is not just a single
69 string.  It is a Distinguished name and in the @acronym{ASN.1}
70 notation is a sequence of several object IDs with their corresponding
71 values. Some of available OIDs to be used in an @acronym{X.509}
72 distinguished name are defined in @file{gnutls/x509.h}.
74 The @emph{Version} field in a certificate has values either 1 or 3 for
75 version 3 certificates.  Version 1 certificates do not support the
76 extensions field so it is not possible to distinguish a CA from a
77 person, thus their usage should be avoided.
79 The @emph{validity} dates are there to indicate the date that the
80 specific certificate was activated and the date the certificate's key
81 would be considered invalid.
83 Certificate @emph{extensions} are there to include information about
84 the certificate's subject that did not fit in the typical certificate
85 fields. Those may be e-mail addresses, flags that indicate whether the
86 belongs to a CA etc.  All the supported @acronym{X.509} version 3
87 extensions are shown in the table below.
89 @table @code
91 @item subject key id (2.5.29.14):
92 An identifier of the key of the subject.
94 @item authority key id (2.5.29.35):
95 An identifier of the authority's key used to sign the certificate.
97 @item subject alternative name (2.5.29.17):
98 Alternative names to subject's distinguished name.
100 @item key usage (2.5.29.15):
101 Constraints the key's usage of the certificate.
103 @item extended key usage (2.5.29.37):
104 Constraints the purpose of the certificate.
106 @item basic constraints (2.5.29.19):
107 Indicates whether this is a CA certificate or not, and specify the
108 maximum path lengths of certificate chains.
110 @item CRL distribution points (2.5.29.31):
111 This extension is set by the CA, in order to inform about the issued
112 CRLs.
114 @item Proxy Certification Information (1.3.6.1.5.5.7.1.14):
115 Proxy Certificates includes this extension that contains the OID of
116 the proxy policy language used, and can specify limits on the maximum
117 lengths of proxy chains.  Proxy Certificates are specified in
118 @xcite{RFC3820}.
120 @end table
122 In @acronym{GnuTLS} the @acronym{X.509} certificate structures are
123 handled using the @code{gnutls_x509_crt_t} type and the corresponding
124 private keys with the @code{gnutls_x509_privkey_t} type.  All the
125 available functions for @acronym{X.509} certificate handling have
126 their prototypes in @file{gnutls/x509.h}. An example program to
127 demonstrate the @acronym{X.509} parsing capabilities can be found at
128 section @ref{ex:x509-info}.
130 @node Verifying X.509 certificate paths
131 @subsection Verifying @acronym{X.509} Certificate Paths
132 @cindex Verifying certificate paths
134 Verifying certificate paths is important in @acronym{X.509}
135 authentication. For this purpose the following functions are
136 provided.
138 @table @code
140 @item @ref{gnutls_x509_trust_list_init}:
141 A function to initialize a list that will hold trusted
142 certificate authorities and certificate revocation lists.
144 @item @ref{gnutls_x509_trust_list_deinit}:
145 Deinitializes the list.
147 @item @ref{gnutls_x509_trust_list_add_cas}:
148 Adds certificate authorities to the list.
150 @item @ref{gnutls_x509_trust_list_add_crls}:
151 Adds certificate revocation lists.
153 @item @ref{gnutls_x509_trust_list_verify_crt}:
154 Verifies a certificate chain using the previously setup trusted
155 list. A callback can be specified that will provide information
156 about the verification procedure (and detailed reasons of failure).
158 @end table
160 The verification function will verify a given certificate chain against a list of certificate
161 authorities and certificate revocation lists, and output
162 a bitwise OR of elements of the @code{gnutls_certificate_status_t} 
163 enumeration.  A detailed description of these elements can be found 
164 in figure below.  An example of these functions in use can be found
165 in @ref{ex:verify2}.
167 When operating in the context of a TLS session, the trusted certificate
168 authority list has been set via the
169 @ref{gnutls_certificate_set_x509_trust_file} and @ref{gnutls_certificate_set_x509_crl_file},
170 thus it is not required to setup a trusted list as above.
171 Convenience functions such as @ref{gnutls_certificate_verify_peers2} 
172 are equivalent and will verify the peer's certificate chain
173 in a TLS session.
175 @table @code
177 @item GNUTLS_CERT_INVALID:
178 The certificate is not signed by one of the known authorities, or
179 the signature is invalid.
181 @item GNUTLS_CERT_REVOKED:
182 The certificate has been revoked by its CA.
184 @item GNUTLS_CERT_SIGNER_NOT_FOUND:
185 The certificate's issuer is not known. This is the case when the
186 issuer is not in the trusted certificates list.
188 @item GNUTLS_CERT_SIGNER_NOT_CA:
189 The certificate's signer was not a CA. This may happen if
190 this was a version 1 certificate, which is common with some CAs, or
191 a version 3 certificate without the basic constrains extension.
193 @anchor{GNUTLS_CERT_INSECURE_ALGORITHM}
194 @item GNUTLS_CERT_INSECURE_ALGORITHM:
195 The certificate was signed using an insecure algorithm such as MD2 or
196 MD5.  These algorithms have been broken and should not be trusted.
198 @end table
200 There is also to possibility to pass some input to the verification
201 functions in the form of flags. For @ref{gnutls_x509_trust_list_verify_crt} the
202 flags are passed straightforward, but
203 @ref{gnutls_certificate_verify_peers2} depends on the flags set by
204 calling @ref{gnutls_certificate_set_verify_flags}.  All the available
205 flags are part of the enumeration
206 @ref{gnutls_certificate_verify_flags} and are explained in the table
207 below.
209 @anchor{gnutls_certificate_verify_flags}
210 @tindex gnutls_certificate_verify_flags
211 @table @code
212 @item GNUTLS_VERIFY_DISABLE_CA_SIGN:
213 If set a signer does not have to be a certificate authority. This
214 flag should normaly be disabled, unless you know what this means.
216 @item GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT:
217 Allow only trusted CA certificates that have version 1.  This is
218 safer than GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT, and should be
219 used instead. That way only signers in your trusted list will be
220 allowed to have certificates of version 1.
222 @item GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT:
223 Allow CA certificates that have version 1 (both root and
224 intermediate). This is dangerous since those haven't the
225 basicConstraints extension. Must be used in combination with
226 GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT.
228 @item GNUTLS_VERIFY_DO_NOT_ALLOW_SAME:
229 If a certificate is not signed by anyone trusted but exists in
230 the trusted CA list do not treat it as trusted.
232 @item GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2:
233 Allow certificates to be signed using the old MD2 algorithm.
235 @item GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5:
236 Allow certificates to be signed using the broken MD5 algorithm.
237 @end table
239 Although the verification of a certificate path indicates that the
240 certificate is signed by trusted authority, does not reveal anything
241 about the peer's identity. It is required to verify if the
242 certificate's owner is the one you expect. For more information
243 consult @xcite{RFC2818} and section @ref{ex:verify} for an example.
245 @node PKCS #10 certificate requests
246 @subsection @acronym{PKCS} #10 Certificate Requests
247 @cindex Certificate requests
248 @cindex @acronym{PKCS} #10
250 A certificate request is a structure, which contain information about
251 an applicant of a certificate service.  It usually contains a private
252 key, a distinguished name and secondary data such as a challenge
253 password. @acronym{GnuTLS} supports the requests defined in
254 @acronym{PKCS} #10 @xcite{RFC2986}. Other certificate request's format
255 such as PKIX's @xcite{RFC4211} are not currently supported.
257 In @acronym{GnuTLS} the @acronym{PKCS} #10 structures are handled
258 using the @code{gnutls_x509_crq_t} type.  An example of a certificate
259 request generation can be found at section @ref{ex:crq}.
261 @node PKCS #12 structures
262 @subsection @acronym{PKCS} #12 Structures
263 @cindex @acronym{PKCS} #12
265 A @acronym{PKCS} #12 structure @xcite{PKCS12} usually contains a user's
266 private keys and certificates. It is commonly used in browsers to
267 export and import the user's identities.
269 In @acronym{GnuTLS} the @acronym{PKCS} #12 structures are handled
270 using the @code{gnutls_pkcs12_t} type. This is an abstract type that
271 may hold several @code{gnutls_pkcs12_bag_t} types.  The Bag types are
272 the holders of the actual data, which may be certificates, private
273 keys or encrypted data.  An Bag of type encrypted should be decrypted
274 in order for its data to be accessed.
276 An example of a @acronym{PKCS} #12 structure generation can be found
277 at section @ref{ex:pkcs12}.
279 @node The OpenPGP trust model
280 @section The @acronym{OpenPGP} Trust Model
281 @cindex @acronym{OpenPGP} Keys
283 The @acronym{OpenPGP} key authentication relies on a distributed trust
284 model, called the ``web of trust''. The ``web of trust'' uses a
285 decentralized system of trusted introducers, which are the same as a
286 CA. @acronym{OpenPGP} allows anyone to sign anyone's else public
287 key. When Alice signs Bob's key, she is introducing Bob's key to
288 anyone who trusts Alice. If someone trusts Alice to introduce keys,
289 then Alice is a trusted introducer in the mind of that observer.
291 @image{gnutls-pgp,11cm,9cm}
293 For example: If David trusts Alice to be an introducer, and Alice
294 signed Bob's key, Dave also trusts Bob's key to be the real one.
296 There are some key points that are important in that model. In the
297 example Alice has to sign Bob's key, only if she is sure that the key
298 belongs to Bob. Otherwise she may also make Dave falsely believe that
299 this is Bob's key. Dave has also the responsibility to know who to
300 trust.  This model is similar to real life relations.
302 Just see how Charlie behaves in the previous example. Although he has
303 signed Bob's key - because he knows, somehow, that it belongs to Bob -
304 he does not trust Bob to be an introducer. Charlie decided to trust
305 only Kevin, for some reason. A reason could be that Bob is lazy
306 enough, and signs other people's keys without being sure that they
307 belong to the actual owner.
309 @subsection @acronym{OpenPGP} Keys
311 In @acronym{GnuTLS} the @acronym{OpenPGP} key structures
312 @xcite{RFC2440} are handled using the @code{gnutls_openpgp_crt_t} type
313 and the corresponding private keys with the
314 @code{gnutls_openpgp_privkey_t} type. All the prototypes for the key
315 handling functions can be found at @file{gnutls/openpgp.h}.
317 @subsection Verifying an @acronym{OpenPGP} Key
319 The verification functions of @acronym{OpenPGP} keys, included in
320 @acronym{GnuTLS}, are simple ones, and do not use the features of the
321 ``web of trust''.  For that reason, if the verification needs are
322 complex, the assistance of external tools like @acronym{GnuPG} and
323 GPGME (@url{http://www.gnupg.org/related_software/gpgme/}) is
324 recommended.
326 There is one verification function in @acronym{GnuTLS}, the
327 @ref{gnutls_openpgp_crt_verify_ring}.  This checks an
328 @acronym{OpenPGP} key against a given set of public keys (keyring) and
329 returns the key status. The key verification status is the same as in
330 @acronym{X.509} certificates, although the meaning and interpretation
331 are different. For example an @acronym{OpenPGP} key may be valid, if
332 the self signature is ok, even if no signers were found.  The meaning
333 of verification status is shown in the figure below.
335 @table @code
337 @item CERT_INVALID:
338 A signature on the key is invalid. That means that the key was
339 modified by somebody, or corrupted during transport.
341 @item CERT_REVOKED:
342 The key has been revoked by its owner.
344 @item CERT_SIGNER_NOT_FOUND:
345 The key was not signed by a known signer.
347 @item GNUTLS_CERT_INSECURE_ALGORITHM:
348 The certificate was signed using an insecure algorithm such as MD2 or
349 MD5.  These algorithms have been broken and should not be trusted.
351 @end table
354 @node PKCS #11 tokens
355 @section @acronym{PKCS #11} tokens
356 @anchor{sec:pkcs11}
357 @cindex @acronym{PKCS #11} tokens
359 @subsection Introduction
360 This section copes with the @acronym{PKCS #11} @xcite{PKCS11} support in @acronym{GnuTLS}.
361 @acronym{PKCS #11} is plugin API allowing applications to access cryptographic
362 operations on a token, as well as to objects residing on the token. A token can 
363 be a real hardware token such as a smart card, or it can be a software component
364 such as @acronym{Gnome Keyring}. The objects residing on such token can be
365 certificates, public keys, private keys or even plain data or  secret keys. Of those
366 certificates and public/private key pairs can be used with @acronym{GnuTLS}. Its
367 main advantage is that it allows operations on private key objects such as decryption
368 and signing without accessing the key itself.
370 Moreover it can be used to allow all applications in the same operating system to access
371 shared cryptographic keys and certificates in a uniform way, as in the following picture.
373 @image{pkcs11-vision}
375 @subsection Initialization
376 To allow all the  @acronym{GnuTLS} applications to access @acronym{PKCS #11} tokens
377 it is adviceable to use @code{/etc/gnutls/pkcs11.conf}. This file has the following
378 format:
380 @verbatim
381 load=/usr/lib/opensc-pkcs11.so
382 load=/usr/lib/gnome-keyring/gnome-keyring-pkcs11.so
383 @end verbatim
385 If you use this file, then there is no need for other initialization in
386 @acronym{GnuTLS}, except for the PIN and token functions. Those allow retrieving a PIN
387 when accessing a protected object, such as a private key, as well as probe
388 the user to insert the token. All the initialization functions are below.
390 @itemize
392 @item @ref{gnutls_pkcs11_init}: Global initialization
394 @item @ref{gnutls_pkcs11_deinit}: Global deinitialization
396 @item @ref{gnutls_pkcs11_set_token_function}: Sets the token insertion function
398 @item @ref{gnutls_pkcs11_set_pin_function}: Sets the PIN request function
400 @item @ref{gnutls_pkcs11_add_provider}: Adds an additional @acronym{PKCS #11} provider
402 @end itemize
404 @subsection Reading Objects
406 All @acronym{PKCS #11} objects are referenced by @acronym{GnuTLS} functions by
407 URLs as described in @code{draft-pechanec-pkcs11uri-03}. For example a public
408 key on a smart card may be referenced as:
410 @example
411 pkcs11:token=Nikos;serial=307521161601031;model=PKCS%2315; \
412 manufacturer=EnterSafe;object=test1;objecttype=public;\
413 id=32:f1:53:f3:e3:79:90:b0:86:24:14:10:77:ca:5d:ec:2d:15:fa:ed
414 @end example
416 while the smart card itself can be referenced as:
417 @example
418 pkcs11:token=Nikos;serial=307521161601031;model=PKCS%2315;manufacturer=EnterSafe
419 @end example
422 Objects can be accessed with the following functions
423 @itemize
425 @item @ref{gnutls_pkcs11_obj_init}: Initializes an object
427 @item @ref{gnutls_pkcs11_obj_import_url}: To import an object from a url
429 @item @ref{gnutls_pkcs11_obj_export_url}: To export the URL of the object
431 @item @ref{gnutls_pkcs11_obj_deinit}: To deinitialize an object
433 @item @ref{gnutls_pkcs11_obj_export}: To export data associated with object
435 @item @ref{gnutls_pkcs11_obj_get_info}: To obtain information about an object
437 @item @ref{gnutls_pkcs11_obj_list_import_url}: To mass load of objects
439 @item @ref{gnutls_x509_crt_import_pkcs11}: Import a certificate object
441 @item @ref{gnutls_x509_crt_import_pkcs11_url}: Helper function to directly import a URL into a certificate
443 @item @ref{gnutls_x509_crt_list_import_pkcs11}: Mass import of certificates
445 @end itemize
448 Functions that relate to token handling are shown below
449 @itemize
451 @item @ref{gnutls_pkcs11_token_init}: Initializes a token
453 @item @ref{gnutls_pkcs11_token_set_pin}: Sets the token user's PIN
455 @item @ref{gnutls_pkcs11_token_get_url}: Returns the URL of a token
457 @item @ref{gnutls_pkcs11_token_get_info}: Obtain information about a token
459 @item @ref{gnutls_pkcs11_token_get_flags}: Returns flags about a token (i.e. hardware or software)
461 @end itemize
463 The following example will list all tokens.
464 @verbatim
465 int i;
466 char* url;
468 gnutls_global_init();
470 for (i=0;;i++) {
471         ret = gnutls_pkcs11_token_get_url(i, &url);
472         if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
473                 break;
475         if (ret < 0)
476                 exit(1);
477                 
478         fprintf(stdout, "Token[%d]: URL: %s\n", i, url);
479         gnutls_free(url);
481 gnutls_global_deinit();
482 @end verbatim
485 The next one will list all certificates in a token, that have a corresponding
486 private key:
487 @verbatim
488 gnutls_pkcs11_obj_t *obj_list;
489 unsigned int obj_list_size = 0;
490 gnutls_datum_t cinfo;
491 int i;
493 obj_list_size = 0;
494 ret = gnutls_pkcs11_obj_list_import_url( obj_list, NULL, url, \
495                         GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY);
496 if (ret < 0 && ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
497         exit(1);
499 /* no error checking from now on */
500 obj_list = malloc(sizeof(*obj_list)*obj_list_size);
502 gnutls_pkcs11_obj_list_import_url( obj_list, &obj_list_size, url, flags);
504 /* now all certificates are in obj_list */
505 for (i=0;i<obj_list_size;i++) {
507         gnutls_x509_crt_init(&xcrt);
509         gnutls_x509_crt_import_pkcs11(xcrt, obj_list[i]);
510                 
511         gnutls_x509_crt_print (xcrt, GNUTLS_CRT_PRINT_FULL, &cinfo);
513         fprintf(stdout, "cert[%d]:\n %s\n\n", cinfo.data);
515         gnutls_free(cinfo.data);
516         gnutls_x509_crt_deinit(&xcrt);
518 @end verbatim
521 @subsection Writing Objects
523 With @acronym{GnuTLS} you can copy existing private keys and certificates
524 to a token. This can be achieved with the following functions
526 @itemize
528 @item @ref{gnutls_pkcs11_delete_url}: To delete an object
530 @item @ref{gnutls_pkcs11_copy_x509_privkey}: To copy a private key to a token
532 @item @ref{gnutls_pkcs11_copy_x509_crt}: To copy a certificate to a token
534 @end itemize
537 @subsection Using a @acronym{PKCS #11} token with TLS
539 It is possible to use a @acronym{PKCS #11} token to a TLS
540 session, as shown in @ref{ex:pkcs11-client}. In addition
541 the following functions can be used to load PKCS #11 key and
542 certificates.
544 @itemize
546 @item @ref{gnutls_certificate_set_x509_trust_file}: If given a PKCS #11 URL will load the trusted certificates from it.
548 @item @ref{gnutls_certificate_set_x509_key_file}: Will also load PKCS #11 URLs for keys and certificates.
550 @end itemize
553 @node Abstract data types
554 @section Abstract data types
555 @anchor{sec:abstract}
556 @cindex Abstract types
558 Since there are many forms of a public or private keys supported by @acronym{GnuTLS} such as
559 @acronym{X.509}, @acronym{OpenPGP}, or @acronym{PKCS #11} it is desirable to allow common operations
560 on them. For these reasons the abstract @code{gnutls_privkey_t} and @code{gnutls_pubkey_t} were
561 introduced in @code{gnutls/abstract.h} header. Those types are initialized using a specific type of key and then can be used to
562 perform operations in an abstract way. For example in order for someone to sign an X.509 certificate
563 with a key that resides in a smart he has to follow the steps below:
565 @verbatim
566 #inlude <gnutls/abstract.h>
567 #inlude <gnutls/pkcs11.h>
569 void sign_cert( gnutls_x509_crt_t to_be_signed)
571 gnutls_pkcs11_privkey_t ca_key;
572 gnutls_x509_crt_t ca_cert;
573 gnutls_privkey_t abs_key;
575         /* load the PKCS #11 key and certificates */
576         gnutls_pkcs11_privkey_init(&ca_key);
577         gnutls_pkcs11_privkey_import_url(ca_key, key_url);
579         gnutls_x509_crt_init(&ca_cert);
580         gnutls_x509_crt_import_pkcs11_url(&ca_cert, cert_url);
582         /* initialize the abstract key */
583         gnutls_privkey_init(&abs_key);
584         gnutls_privkey_import_pkcs11(abs_key, ca_key);
586         /* sign the certificate to be signed */
587         gnutls_x509_crt_privkey_sign(to_be_signed, ca_cert, ca_key, GNUTLS_DIG_SHA1, 0);
589 @end verbatim
592 @node Digital signatures
593 @section Digital Signatures
594 @cindex Digital signatures
596 In this section we will provide some information about digital
597 signatures, how they work, and give the rationale for disabling some
598 of the algorithms used.
600 Digital signatures work by using somebody's secret key to sign some
601 arbitrary data.  Then anybody else could use the public key of that
602 person to verify the signature.  Since the data may be arbitrary it is
603 not suitable input to a cryptographic digital signature algorithm. For
604 this reason and also for performance cryptographic hash algorithms are
605 used to preprocess the input to the signature algorithm. This works as
606 long as it is difficult enough to generate two different messages with
607 the same hash algorithm output. In that case the same signature could
608 be used as a proof for both messages. Nobody wants to sign an innocent
609 message of donating 1 @euro{} to Greenpeace and find out that he
610 donated 1.000.000 @euro{} to Bad Inc.
612 For a hash algorithm to be called cryptographic the following three
613 requirements must hold:
615 @enumerate
616 @item Preimage resistance.
617 That means the algorithm must be one way and given the output of the
618 hash function @math{H(x)}, it is impossible to calculate @math{x}.
620 @item 2nd preimage resistance.
621 That means that given a pair @math{x,y} with @math{y=H(x)} it is
622 impossible to calculate an @math{x'} such that @math{y=H(x')}.
624 @item Collision resistance.
625 That means that it is impossible to calculate random @math{x} and
626 @math{x'} such @math{H(x')=H(x)}.
627 @end enumerate
629 The last two requirements in the list are the most important in
630 digital signatures. These protect against somebody who would like to
631 generate two messages with the same hash output. When an algorithm is
632 considered broken usually it means that the Collision resistance of
633 the algorithm is less than brute force. Using the birthday paradox the
634 brute force attack takes
635 @iftex
636 @math{2^{(\rm{hash\ size}) / 2}}
637 @end iftex
638 @ifnottex
639 @math{2^{((hash size) / 2)}}
640 @end ifnottex
641 operations. Today colliding certificates using the MD5 hash algorithm
642 have been generated as shown in @xcite{WEGER}.
644 There has been cryptographic results for the SHA-1 hash algorithms as
645 well, although they are not yet critical.  Before 2004, MD5 had a
646 presumed collision strength of @math{2^{64}}, but it has been showed
647 to have a collision strength well under @math{2^{50}}.  As of November
648 2005, it is believed that SHA-1's collision strength is around
649 @math{2^{63}}.  We consider this sufficiently hard so that we still
650 support SHA-1.  We anticipate that SHA-256/386/512 will be used in
651 publicly-distributed certificates in the future.  When @math{2^{63}}
652 can be considered too weak compared to the computer power available
653 sometime in the future, SHA-1 will be disabled as well.  The collision
654 attacks on SHA-1 may also get better, given the new interest in tools
655 for creating them.
657 @subsection Trading Security for Interoperability
659 If you connect to a server and use GnuTLS' functions to verify the
660 certificate chain, and get a @ref{GNUTLS_CERT_INSECURE_ALGORITHM}
661 validation error (@pxref{Verifying X.509 certificate paths}), it means
662 that somewhere in the certificate chain there is a certificate signed
663 using @code{RSA-MD2} or @code{RSA-MD5}.  These two digital signature
664 algorithms are considered broken, so GnuTLS fail when attempting to
665 verify the certificate.  In some situations, it may be useful to be
666 able to verify the certificate chain anyway, assuming an attacker did
667 not utilize the fact that these signatures algorithms are broken.
668 This section will give help on how to achieve that.
670 First, it is important to know that you do not have to enable any of
671 the flags discussed here to be able to use trusted root CA
672 certificates signed using @code{RSA-MD2} or @code{RSA-MD5}.  The only
673 attack today is that it is possible to generate certificates with
674 colliding signatures (collision resistance); you cannot generate a
675 certificate that has the same signature as an already existing
676 signature (2nd preimage resistance).
678 If you are using @ref{gnutls_certificate_verify_peers2} to verify the
679 certificate chain, you can call
680 @ref{gnutls_certificate_set_verify_flags} with the
681 @code{GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2} or
682 @code{GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5} flag, as in:
684 @example
685   gnutls_certificate_set_verify_flags (x509cred,
686                                        GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5);
687 @end example
689 This will tell the verifier algorithm to enable @code{RSA-MD5} when
690 verifying the certificates.
692 If you are using @ref{gnutls_x509_crt_verify} or
693 @ref{gnutls_x509_crt_list_verify}, you can pass the
694 @code{GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5} parameter directly in the
695 @code{flags} parameter.
697 If you are using these flags, it may also be a good idea to warn the
698 user when verification failure occur for this reason.  The simplest is
699 to not use the flags by default, and only fall back to using them
700 after warning the user.  If you wish to inspect the certificate chain
701 yourself, you can use @ref{gnutls_certificate_get_peers} to extract
702 the raw server's certificate chain, then use
703 @ref{gnutls_x509_crt_import} to parse each of the certificates, and
704 then use @ref{gnutls_x509_crt_get_signature_algorithm} to find out the
705 signing algorithm used for each certificate.  If any of the
706 intermediary certificates are using @code{GNUTLS_SIGN_RSA_MD2} or
707 @code{GNUTLS_SIGN_RSA_MD5}, you could present a warning.