Add psktool to @direntry. Alphasort @direntry.
[gnutls.git] / doc / gnutls.texi
blob198e6b6c603a42b2409db11bc4927ace20d9b538
1 \input texinfo   @c -*-texinfo-*-
2 @comment $Id$
3 @comment %**start of header
4 @setfilename gnutls.info
5 @include version.texi
6 @settitle GNU TLS @value{VERSION}
8 @c don't indent the paragraphs.
9 @paragraphindent 0
11 @c Unify some of the indices.
12 @syncodeindex tp fn
13 @syncodeindex pg cp
15 @comment %**end of header
16 @finalout
17 @copying
18 This manual is last updated @value{UPDATED} for version
19 @value{VERSION} of GNU TLS.
21 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
23 @quotation
24 Permission is granted to copy, distribute and/or modify this document
25 under the terms of the GNU Free Documentation License, Version 1.2 or
26 any later version published by the Free Software Foundation; with no
27 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
28 copy of the license is included in the section entitled ``GNU Free
29 Documentation License''.
30 @end quotation
31 @end copying
33 @dircategory GNU Libraries
34 @direntry
35 * libgnutls: (gnutls).          A Transport Layer Security Library.
36 @end direntry
38 @dircategory Network Applications
39 @direntry
40 * GnuTLS: (gnutls).                     Package for Transport Layer Security.
41 * certtool: (gnutls)Invoking certtool.  Manipulate certificates and keys.
42 * gnutls-serv: (gnutls)Invoking gnutls-serv.    GNU TLS test server.
43 * gnutls-cli: (gnutls)Invoking gnutls-cli.      GNU TLS test client.
44 * gnutls-cli-debug: (gnutls)Invoking gnutls-cli-debug.  GNU TLS debug client.
45 * psktool: (gnutls)Invoking psktool.    Simple TLS-Pre-Shared-Keys manager.
46 * srptool: (gnutls)Invoking srptool.    Simple SRP password tool.
47 @end direntry
49 @titlepage
50 @title GNU TLS
51 @subtitle Transport Layer Security Library for the GNU system
52 @subtitle for version @value{VERSION}, @value{UPDATED}
53 @sp 7
54 @image{gnutls-logo,6cm,6cm}
55 @author Nikos Mavrogiannopoulos
56 @author Simon Josefsson (@email{bug-gnutls@@gnu.org})
57 @page
58 @vskip 0pt plus 1filll
59 @insertcopying
60 @end titlepage
62 @macro xcite{ref}
63 [\ref\] (@pxref{Bibliography})
64 @end macro
66 @contents
68 @ifnottex
69 @node Top
70 @top GNU TLS
72 @insertcopying
73 @end ifnottex
75 @menu
76 * Preface::
77 * The Library::
78 * Introduction to TLS::
79 * Authentication methods::
80 * More on certificate authentication::
81 * How to use TLS in application protocols::
82 * How to use GnuTLS in applications::
83 * Included programs::
84 * Function reference::
85 * All the supported ciphersuites in GnuTLS::
86 * Guile Bindings::
87 * Internal architecture of GnuTLS::
88 * Copying Information::
89 * Concept Index::
90 * Function and Data Index::
91 @c * @mybibnode{}::
92 * Bibliography::
93 @end menu
96 @node Preface
97 @chapter Preface
99 This document tries to demonstrate and explain the @acronym{GnuTLS}
100 library API.  A brief introduction to the protocols and the technology
101 involved, is also included so that an application programmer can
102 better understand the @acronym{GnuTLS} purpose and actual offerings.
103 Even if @acronym{GnuTLS} is a typical library software, it operates
104 over several security and cryptographic protocols, which require the
105 programmer to make careful and correct usage of them, otherwise he
106 risks to offer just a false sense of security. Security and the
107 network security terms are very general terms even for computer
108 software thus cannot be easily restricted to a single cryptographic
109 library.  For that reason, do not consider a program secure just
110 because it uses @acronym{GnuTLS}; there are several ways to compromise
111 a program or a communication line and @acronym{GnuTLS} only helps with
112 some of them.
114 Although this document tries to be self contained, basic network
115 programming and PKI knowlegde is assumed in most of it. A good
116 introduction to networking can be found in @xcite{STEVENS} and for
117 Public Key Infrastructure in @xcite{GUTPKI}.
119 @anchor{Availability}
121 Updated versions of the @acronym{GnuTLS} software and this document
122 will be available from @url{http://www.gnutls.org/} and
123 @url{http://www.gnu.org/software/gnutls/}.
125 @menu
126 * Getting help::
127 * Commercial Support::
128 * Downloading and Installing::
129 * Bug Reports::
130 * Contributing::
131 @end menu
133 @node Getting help
134 @section Getting Help
136 A mailing list where users may help each other exists, and you can
137 reach it by sending e-mail to @email{help-gnutls@@gnu.org}.  Archives
138 of the mailing list discussions, and an interface to manage
139 subscriptions, is available through the World Wide Web at
140 @url{http://lists.gnu.org/mailman/listinfo/help-gnutls}.
142 A mailing list for developers are also available, see
143 @url{http://www.gnu.org/software/gnutls/lists.html}.
145 Bug reports should be sent to @email{bug-gnutls@@gnu.org}, see
146 @xref{Bug Reports}.
148 @node Commercial Support
149 @section Commercial Support
151 Commercial support is available for users of GnuTLS.  The kind of
152 support that can be purchased may include:
154 @itemize
156 @item Implement new features.
157 Such as a new TLS extension.
159 @item Port GnuTLS to new platforms.
160 This could include porting to an embedded platforms that may need
161 memory or size optimization.
163 @item Integrating TLS as a security environment in your existing project.
165 @item System design of components related to TLS.
167 @end itemize
169 If you are interested, please write to:
171 @verbatim
172 Simon Josefsson Datakonsult
173 Hagagatan 24
174 113 47 Stockholm
175 Sweden
177 E-mail: simon@josefsson.org
178 @end verbatim
180 If your company provide support related to GnuTLS and would like to be
181 mentioned here, contact the author (@pxref{Bug Reports}).
183 @node Downloading and Installing
184 @section Downloading and Installing
185 @cindex Installation
186 @cindex Download
188 GnuTLS is available for download from the following URL:
190 @url{http://www.gnutls.org/download.html}
192 The latest version is stored in a file, e.g.,
193 @samp{gnutls-@value{VERSION}.tar.gz} where the @samp{@value{VERSION}}
194 value is the highest version number in the directory.
196 GnuTLS uses a Linux-like development cycle: even minor version numbers
197 indicate a stable release and a odd minor version number indicates a
198 development release.  For example, GnuTLS 1.6.3 denote a stable
199 release since 6 is even, and GnuTLS 1.7.11 denote a development
200 release since 7 is odd.
202 GnuTLS depends on Libgcrypt, and you will need to install Libgcrypt
203 before installing GnuTLS.  Libgcrypt is available from
204 @url{ftp://ftp.gnupg.org/gcrypt/libgcrypt}.  Libgcrypt needs another
205 library, libgpg-error, and you need to install libgpg-error before
206 installing Libgcrypt.  Libgpg-error is available from
207 @url{ftp://ftp.gnupg.org/gcrypt/libgpg-error}.
209 Don't forget to verify the cryptographic signature after downloading
210 source code packages.
212 The package is then extracted, configured and built like many other
213 packages that use Autoconf.  For detailed information on configuring
214 and building it, refer to the @file{INSTALL} file that is part of the
215 distribution archive.  Typically you invoke @code{./configure} and
216 then @code{make check install}.  There are a number of compile-time
217 parameters, as discussed below.
219 The compression libraries (libz and lzo) are optional dependencies.
220 You can get libz from @url{http://www.zlib.net/}.  You can get lzo
221 from @url{http://www.oberhumer.com/opensource/lzo/}.
223 The X.509 part of GnuTLS needs ASN.1 functionality, from a library
224 called libtasn1.  A copy of libtasn1 is included in GnuTLS.  If you
225 want to install it separately (e.g., to make it possibly to use
226 libtasn1 in other programs), you can get it from
227 @url{http://www.gnu.org/software/gnutls/download.html}.
229 The OpenPGP part of GnuTLS uses a stripped down version of OpenCDK for
230 parsing OpenPGP packets.  It is included GnuTLS.  Use parameter
231 @code{--disable-openpgp-authentication} to disable the OpenPGP
232 functionality in GnuTLS.  Unfortunately, we didn't have resources to
233 maintain the code in a separate library.
235 Regarding the Guile bindings, there are additional installation
236 considerations, see @xref{Guile Preparations}.
238 A few @code{configure} options may be relevant, summarized in the
239 table.
241 @table @code
243 @item --disable-srp-authentication
244 @itemx --disable-psk-authentication
245 @itemx --disable-anon-authentication
246 @itemx --disable-extra-pki
247 @itemx --disable-openpgp-authentication
248 @itemx --disable-openssl-compatibility
249 Disable or enable particular features.  Generally not recommended.
251 @end table
253 For the complete list, refer to the output from @code{configure
254 --help}.
256 @node Bug Reports
257 @section Bug Reports
258 @cindex Reporting Bugs
260 If you think you have found a bug in GnuTLS, please investigate it and
261 report it.
263 @itemize @bullet
265 @item Please make sure that the bug is really in GnuTLS, and
266 preferably also check that it hasn't already been fixed in the latest
267 version.
269 @item You have to send us a test case that makes it possible for us to
270 reproduce the bug.
272 @item You also have to explain what is wrong; if you get a crash, or
273 if the results printed are not good and in that case, in what way.
274 Make sure that the bug report includes all information you would need
275 to fix this kind of bug for someone else.
277 @end itemize
279 Please make an effort to produce a self-contained report, with
280 something definite that can be tested or debugged.  Vague queries or
281 piecemeal messages are difficult to act on and don't help the
282 development effort.
284 If your bug report is good, we will do our best to help you to get a
285 corrected version of the software; if the bug report is poor, we won't
286 do anything about it (apart from asking you to send better bug
287 reports).
289 If you think something in this manual is unclear, or downright
290 incorrect, or if the language needs to be improved, please also send a
291 note.
293 Send your bug report to:
295 @center @samp{bug-gnutls@@gnu.org}
297 @node Contributing
298 @section Contributing
299 @cindex Contributing
300 @cindex Hacking
302 If you want to submit a patch for inclusion -- from solve a typo you
303 discovered, up to adding support for a new feature -- you should
304 submit it as a bug report (@pxref{Bug Reports}).  There are some
305 things that you can do to increase the chances for it to be included
306 in the official package.
308 Unless your patch is very small (say, under 10 lines) we require that
309 you assign the copyright of your work to the Free Software Foundation.
310 This is to protect the freedom of the project.  If you have not
311 already signed papers, we will send you the necessary information when
312 you submit your contribution.
314 For contributions that doesn't consist of actual programming code, the
315 only guidelines are common sense.  Use it.
317 For code contributions, a number of style guides will help you:
319 @itemize @bullet
321 @item Coding Style.
322 Follow the GNU Standards document (@pxref{top, GNU Coding Standards,,
323 standards}).
325 If you normally code using another coding standard, there is no
326 problem, but you should use @samp{indent} to reformat the code
327 (@pxref{top, GNU Indent,, indent}) before submitting your work.
329 @item Use the unified diff format @samp{diff -u}.
331 @item Return errors.
332 No reason whatsoever should abort the execution of the library.  Even
333 memory allocation errors, e.g. when malloc return NULL, should work
334 although result in an error code.
336 @item Design with thread safety in mind.
337 Don't use global variables.  Don't even write to per-handle global
338 variables unless the documented behaviour of the function you write is
339 to write to the per-handle global variable.
341 @item Avoid using the C math library.
342 It causes problems for embedded implementations, and in most
343 situations it is very easy to avoid using it.
345 @item Document your functions.
346 Use comments before each function headers, that, if properly
347 formatted, are extracted into Texinfo manuals and GTK-DOC web pages.
349 @item Supply a ChangeLog and NEWS entries, where appropriate.
351 @end itemize
352 @node The Library
353 @chapter The Library
355 In brief @acronym{GnuTLS} can be described as a library which offers an API
356 to access secure communication protocols. These protocols provide
357 privacy over insecure lines, and were designed to prevent
358 eavesdropping, tampering, or message forgery.
360 Technically @acronym{GnuTLS} is a portable ANSI C based library which
361 implements the TLS 1.1 and SSL 3.0 protocols (@xref{Introduction to
362 TLS}, for a more detailed description of the protocols), accompanied
363 with the required framework for authentication and public key
364 infrastructure.  The library is available under the GNU Lesser GPL
365 license@footnote{A copy of the license is included in the
366 distribution}.  Important features of the @acronym{GnuTLS} library
367 include:
369 @itemize
371 @item Support for TLS 1.0, TLS 1.1, and SSL 3.0 protocols.
373 @item Support for both @acronym{X.509} and @acronym{OpenPGP} certificates.
375 @item Support for handling and verification of certificates.
377 @item Support for @acronym{SRP} for TLS authentication.
379 @item Support for @acronym{PSK} for TLS authentication.
381 @item Support for TLS Extension mechanism.
383 @item Support for TLS Compression Methods.
385 @end itemize
387 Additionally @acronym{GnuTLS} provides a limited emulation API for the
388 widely used OpenSSL@footnote{@url{http://www.openssl.org/}} library,
389 to ease integration with existing applications.
391 @acronym{GnuTLS} consists of three independent parts, namely the ``TLS
392 protocol part'', the ``Certificate part'', and the ``Crypto backend''
393 part.  The `TLS protocol part' is the actual protocol implementation,
394 and is entirely implemented within the @acronym{GnuTLS} library.  The
395 `Certificate part' consists of the certificate parsing, and
396 verification functions which is partially implemented in the
397 @acronym{GnuTLS} library.  The
398 @acronym{Libtasn1}@footnote{@url{ftp://ftp.gnupg.org/gcrypt/alpha/gnutls/libtasn1/}},
399 a library which offers @acronym{ASN.1} parsing capabilities, is used
400 for the @acronym{X.509} certificate parsing functions.  A smaller
401 version of
402 @acronym{OpenCDK}@footnote{@url{ftp://ftp.gnupg.org/gcrypt/alpha/gnutls/opencdk/}}
403 is used for the @acronym{OpenPGP} key support in @acronym{GnuTLS}.
404 The ``Crypto backend'' is provided by the
405 @acronym{Libgcrypt}@footnote{@url{ftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/}}
406 library.
408 In order to ease integration in embedded systems, parts of the
409 @acronym{GnuTLS} library can be disabled at compile time. That way a
410 small library, with the required features, can be generated.
412 @menu
413 * General Idea::
414 * Error handling::
415 * Memory handling::
416 * Callback functions::
417 @end menu
419 @node General Idea
420 @section General Idea
422 A brief description of how @acronym{GnuTLS} works internally is shown
423 at the figure below. This section may be easier to understand after
424 having seen the examples (@pxref{examples}).
426 @image{gnutls-internals,12cm,8cm}
428 As shown in the figure, there is a read-only global state that is
429 initialized once by the global initialization function.  This global
430 structure, among others, contains the memory allocation functions
431 used, and some structures needed for the @acronym{ASN.1} parser.  This structure
432 is never modified by any @acronym{GnuTLS} function, except for the
433 deinitialization function which frees all memory allocated in the
434 global structure and is called after the program has permanently
435 finished using @acronym{GnuTLS}.
437 The credentials structure is used by some authentication methods, such
438 as certificate authentication (@pxref{Certificate Authentication}).  A
439 credentials structure may contain certificates, private keys,
440 temporary parameters for diffie hellman or RSA key exchange, and other
441 stuff that may be shared between several TLS sessions.
443 This structure should be initialized using the appropriate
444 initialization functions. For example an application which uses
445 certificate authentication would probably initialize the credentials,
446 using the appropriate functions, and put its trusted certificates in
447 this structure. The next step is to associate the credentials
448 structure with each @acronym{TLS} session.
450 A @acronym{GnuTLS} session contains all the required stuff for a
451 session to handle one secure connection. This session calls directly
452 to the transport layer functions, in order to communicate with the
453 peer.  Every session has a unique session ID shared with the peer.
455 Since TLS sessions can be resumed, servers would probably need a
456 database backend to hold the session's parameters.  Every
457 @acronym{GnuTLS} session after a successful handshake calls the
458 appropriate backend function (@xref{resume}, for information on
459 initialization) to store the newly negotiated session. The session
460 database is examined by the server just after having received the
461 client hello@footnote{The first message in a @acronym{TLS} handshake},
462 and if the session ID sent by the client, matches a stored session,
463 the stored session will be retrieved, and the new session will be a
464 resumed one, and will share the same session ID with the previous one.
466 @node Error handling
467 @section Error Handling
469 In @acronym{GnuTLS} most functions return an integer type as a result.  In
470 almost all cases a zero or a positive number means success, and a
471 negative number indicates failure, or a situation that some action has
472 to be taken. Thus negative error codes may be fatal or not.
474 Fatal errors terminate the connection immediately and further sends
475 and receives will be disallowed. An example of a fatal error code is
476 @code{GNUTLS_E_DECRYPTION_FAILED}. Non-fatal errors may warn about
477 something, i.e., a warning alert was received, or indicate the some
478 action has to be taken. This is the case with the error code
479 @code{GNUTLS_E_REHANDSHAKE} returned by @ref{gnutls_record_recv}.
480 This error code indicates that the server requests a re-handshake. The
481 client may ignore this request, or may reply with an alert.  You can
482 test if an error code is a fatal one by using the
483 @ref{gnutls_error_is_fatal}.
485 If any non fatal errors, that require an action, are to be returned by
486 a function, these error codes will be documented in the function's
487 reference.  @xref{Error Codes}, for all the error codes.
489 @node Memory handling
490 @section Memory Handling
492 @acronym{GnuTLS} internally handles heap allocated objects
493 differently, depending on the sensitivity of the data they
494 contain. However for performance reasons, the default memory functions
495 do not overwrite sensitive data from memory, nor protect such objects
496 from being written to the swap.  In order to change the default
497 behavior the @ref{gnutls_global_set_mem_functions} function is
498 available which can be used to set other memory handlers than the
499 defaults.
501 The @acronym{Libgcrypt} library on which @acronym{GnuTLS} depends, has such
502 secure memory allocation functions available. These should be used in
503 cases where even the system's swap memory is not considered
504 secure. See the documentation of @acronym{Libgcrypt} for more
505 information.
507 @node Callback functions
508 @section Callback Functions
509 @cindex Callback functions
511 There are several cases where @acronym{GnuTLS} may need some out of
512 band input from your program. This is now implemented using some
513 callback functions, which your program is expected to register.
515 An example of this type of functions are the push and pull callbacks
516 which are used to specify the functions that will retrieve and send
517 data to the transport layer.
519 @itemize
521 @item @ref{gnutls_transport_set_push_function}
523 @item @ref{gnutls_transport_set_pull_function}
525 @end itemize
527 Other callback functions such as the one set by
528 @ref{gnutls_srp_set_server_credentials_function}, may require more
529 complicated input, including data to be allocated.  These callbacks
530 should allocate and free memory using the functions shown below.
532 @itemize
534 @item @ref{gnutls_malloc}
536 @item @ref{gnutls_free}
538 @end itemize
540 @node Introduction to TLS
541 @chapter Introduction to @acronym{TLS}
543 @acronym{TLS} stands for ``Transport Layer Security'' and is the
544 successor of SSL, the Secure Sockets Layer protocol @xcite{SSL3}
545 designed by Netscape.  @acronym{TLS} is an Internet protocol, defined
546 by @acronym{IETF}@footnote{IETF, or Internet Engineering Task Force,
547 is a large open international community of network designers,
548 operators, vendors, and researchers concerned with the evolution of
549 the Internet architecture and the smooth operation of the Internet.
550 It is open to any interested individual.}, described in @acronym{RFC}
551 4346 and also in @xcite{RESCORLA}.  The protocol provides
552 confidentiality, and authentication layers over any reliable transport
553 layer.  The description, below, refers to @acronym{TLS} 1.0 but also
554 applies to @acronym{TLS} 1.1 @xcite{RFC4346} and @acronym{SSL} 3.0,
555 since the differences of these protocols are minor.  Older protocols
556 such as @acronym{SSL} 2.0 are not discussed nor implemented in
557 @acronym{GnuTLS} since they are not considered secure today.  GnuTLS
558 also supports @acronym{X.509} and @acronym{OpenPGP} @xcite{RFC4880}.
560 @menu
561 * TLS layers::
562 * The transport layer::
563 * The TLS record protocol::
564 * The TLS Alert Protocol::
565 * The TLS Handshake Protocol::
566 * TLS Extensions::
567 * Selecting cryptographic key sizes::
568 * On SSL 2 and older protocols::
569 * On Record Padding::
570 @end menu
572 @node TLS layers
573 @section TLS Layers
574 @cindex TLS Layers
576 @acronym{TLS} is a layered protocol, and consists of the Record
577 Protocol, the Handshake Protocol and the Alert Protocol. The Record
578 Protocol is to serve all other protocols and is above the transport
579 layer.  The Record protocol offers symmetric encryption, data
580 authenticity, and optionally compression.
582 The Alert protocol offers some signaling to the other protocols. It
583 can help informing the peer for the cause of failures and other error
584 conditions.  @xref{The Alert Protocol}, for more information.  The
585 alert protocol is above the record protocol.
587 The Handshake protocol is responsible for the security parameters'
588 negotiation, the initial key exchange and authentication.  @xref{The
589 Handshake Protocol}, for more information about the handshake
590 protocol.  The protocol layering in TLS is shown in the figure below.
592 @image{gnutls-layers,12cm,8cm}
594 @node The transport layer
595 @section The Transport Layer
596 @cindex Transport protocol
598 @acronym{TLS} is not limited to one transport layer, it can be used
599 above any transport layer, as long as it is a reliable one.  A set of
600 functions is provided and their purpose is to load to @acronym{GnuTLS} the
601 required callbacks to access the transport layer.
603 @itemize
604 @item @ref{gnutls_transport_set_push_function}
605 @item @ref{gnutls_transport_set_pull_function}
606 @item @ref{gnutls_transport_set_ptr}
607 @item @ref{gnutls_transport_set_lowat}
608 @item @ref{gnutls_transport_set_errno}
609 @end itemize
611 These functions accept a callback function as a parameter.  The
612 callback functions should return the number of bytes written, or -1 on
613 error and should set @code{errno} appropriately.
615 In some environments, setting @code{errno} is unreliable, for example
616 Windows have several errno variables in different CRTs, or it may be
617 that errno is not a thread-local variable.  If this is a concern to
618 you, call @code{gnutls_transport_set_errno} with the intended errno
619 value instead of setting @code{errno} directly.
621 @acronym{GnuTLS} currently only interprets the EINTR and EAGAIN errno
622 values and returns the corresponding @acronym{GnuTLS} error codes
623 @code{GNUTLS_E_INTERRUPTED} and @code{GNUTLS_E_AGAIN}.  These values
624 are usually returned by interrupted system calls, or when non blocking
625 IO is used.  All @acronym{GnuTLS} functions can be resumed (called
626 again), if any of these error codes is returned.  The error codes
627 above refer to the system call, not the @acronym{GnuTLS} function,
628 since signals do not interrupt @acronym{GnuTLS}' functions.
630 For non blocking sockets or other custom made pull/push functions
631 the @ref{gnutls_transport_set_lowat} must be called, with a zero
632 low water mark value.
634 By default, if the transport functions are not set, @acronym{GnuTLS}
635 will use the Berkeley Sockets functions.  In this case
636 @acronym{GnuTLS} will use some hacks in order for @code{select} to
637 work, thus making it easy to add @acronym{TLS} support to existing
638 TCP/IP servers.
640 @node The TLS record protocol
641 @section The TLS Record Protocol
642 @cindex Record protocol
644 The Record protocol is the secure communications provider. Its purpose
645 is to encrypt, authenticate and ---optionally--- compress packets.
646 The following functions are available:
648 @table @asis
650 @item @ref{gnutls_record_send}:
651 To send a record packet (with application data).
653 @item @ref{gnutls_record_recv}:
654 To receive a record packet (with application data).
656 @item @ref{gnutls_record_get_direction}:
657 To get the direction of the last interrupted function call.
658 @end table
660 As you may have already noticed, the functions which access the Record
661 protocol, are quite limited, given the importance of this protocol in
662 @acronym{TLS}.  This is because the Record protocol's parameters are
663 all set by the Handshake protocol.
665 The Record protocol initially starts with NULL parameters, which means
666 no encryption, and no MAC is used. Encryption and authentication begin
667 just after the handshake protocol has finished.
669 @menu
670 * Encryption algorithms used in the record layer::
671 * Compression algorithms used in the record layer::
672 * Weaknesses and countermeasures::
673 @end menu
675 @node Encryption algorithms used in the record layer
676 @subsection Encryption Algorithms Used in the Record Layer
677 @cindex Symmetric encryption algorithms
679 Confidentiality in the record layer is achieved by using symmetric
680 block encryption algorithms like @code{3DES}, @code{AES}@footnote{AES,
681 or Advanced Encryption Standard, is actually the RIJNDAEL algorithm.
682 This is the algorithm that replaced DES.}, or stream algorithms like
683 @code{ARCFOUR_128}@footnote{@code{ARCFOUR_128} is a compatible
684 algorithm with RSA's RC4 algorithm, which is considered to be a trade
685 secret.}. Ciphers are encryption algorithms that use a single, secret,
686 key to encrypt and decrypt data. Block algorithms in TLS also provide
687 protection against statistical analysis of the data.  Thus, if you're
688 using the @acronym{TLS} protocol, a random number of blocks will be
689 appended to data, to prevent eavesdroppers from guessing the actual
690 data size.
692 Supported cipher algorithms:
694 @table @code
695 @item 3DES_CBC
696 @code{3DES_CBC} is the DES block cipher algorithm used with triple
697 encryption (EDE). Has 64 bits block size and is used in CBC mode.
699 @item ARCFOUR_128
700 ARCFOUR is a fast stream cipher.
702 @item ARCFOUR_40
703 This is the ARCFOUR cipher that is fed with a 40 bit key,
704 which is considered weak.
706 @item AES_CBC
707 AES or RIJNDAEL is the block cipher algorithm that replaces the old
708 DES algorithm.  Has 128 bits block size and is used in CBC mode. This
709 is not officially supported in TLS.
710 @end table
712 Supported MAC algorithms:
714 @table @code
715 @item MAC_MD5
716 MD5 is a cryptographic hash algorithm designed by Ron Rivest. Outputs
717 128 bits of data.
719 @item MAC_SHA
720 SHA is a cryptographic hash algorithm designed by NSA. Outputs 160
721 bits of data.
723 @end table
725 @node Compression algorithms used in the record layer
726 @subsection Compression Algorithms Used in the Record Layer
727 @cindex Compression algorithms
729 The TLS record layer also supports compression.  The algorithms
730 implemented in @acronym{GnuTLS} can be found in the table below.
731 All the algorithms except for DEFLATE which is
732 referenced in @xcite{RFC3749}, should be considered as
733 @acronym{GnuTLS}' extensions@footnote{You should use
734 @ref{gnutls_handshake_set_private_extensions} to enable private
735 extensions.}, and should be advertised only when the peer is known to
736 have a compliant client, to avoid interoperability problems.
738 The included algorithms perform really good when text, or other
739 compressible data are to be transfered, but offer nothing on already
740 compressed data, such as compressed images, zipped archives etc.
741 These compression algorithms, may be useful in high bandwidth TLS
742 tunnels, and in cases where network usage has to be minimized. As a
743 drawback, compression increases latency.
745 The record layer compression in @acronym{GnuTLS} is implemented based
746 on the proposal @xcite{RFC3749}.
747 The supported compression algorithms are:
749 @table @code
750 @item DEFLATE
751 Zlib compression, using the deflate algorithm.
753 @item LZO
754 LZO is a very fast compression algorithm.  This algorithm is only
755 available if the @acronym{GnuTLS-extra} library has been initialized
756 and the private extensions are enabled, and if GnuTLS was built with
757 LZO support.
759 @end table
761 @node Weaknesses and countermeasures
762 @subsection Weaknesses and Countermeasures
764 Some weaknesses that may affect the security of the Record layer have
765 been found in @acronym{TLS} 1.0 protocol. These weaknesses can be
766 exploited by active attackers, and exploit the facts that
768 @enumerate
770 @item
771 @acronym{TLS} has separate alerts for ``decryption_failed'' and
772 ``bad_record_mac''
774 @item
775 The decryption failure reason can be detected by timing the response
776 time.
778 @item
779 The IV for CBC encrypted packets is the last block of the previous
780 encrypted packet.
782 @end enumerate
784 Those weaknesses were solved in @acronym{TLS} 1.1 @xcite{RFC4346} which is implemented
785 in @acronym{GnuTLS}. For a detailed discussion see the archives of the
786 TLS Working Group mailing list and the paper @xcite{CBCATT}.
788 @node The TLS Alert Protocol
789 @section The TLS Alert Protocol
790 @anchor{The Alert Protocol}
791 @cindex Alert protocol
793 The Alert protocol is there to allow signals to be sent between peers.
794 These signals are mostly used to inform the peer about the cause of a
795 protocol failure. Some of these signals are used internally by the
796 protocol and the application protocol does not have to cope with them
797 (see @code{GNUTLS_A_CLOSE_NOTIFY}), and others refer to the
798 application protocol solely (see @code{GNUTLS_A_USER_CANCELLED}).  An
799 alert signal includes a level indication which may be either fatal or
800 warning. Fatal alerts always terminate the current connection, and
801 prevent future renegotiations using the current session ID.
803 The alert messages are protected by the record protocol, thus the
804 information that is included does not leak. You must take extreme care
805 for the alert information not to leak to a possible attacker, via
806 public log files etc.
808 @table @asis
809 @item @ref{gnutls_alert_send}:
810 To send an alert signal.
812 @item @ref{gnutls_error_to_alert}:
813 To map a gnutls error number to an alert signal.
815 @item @ref{gnutls_alert_get}:
816 Returns the last received alert.
818 @item @ref{gnutls_alert_get_name}:
819 Returns the name, in a character array, of the given alert.
821 @end table
823 @node The TLS Handshake Protocol
824 @section The TLS Handshake Protocol
825 @anchor{The Handshake Protocol}
826 @cindex Handshake protocol
828 The Handshake protocol is responsible for the ciphersuite negotiation,
829 the initial key exchange, and the authentication of the two peers.
830 This is fully controlled by the application layer, thus your program
831 has to set up the required parameters. Available functions to control
832 the handshake protocol include:
834 @table @asis
835 @item @ref{gnutls_priority_init}:
836 To initialize a priority set of ciphers.
838 @item @ref{gnutls_priority_deinit}:
839 To deinitialize a priority set of ciphers.
841 @item @ref{gnutls_priority_set}:
842 To associate a priority set with a @acronym{TLS} session.
844 @item @ref{gnutls_priority_set_direct}:
845 To directly associate a session with a given priority string.
847 @item @ref{gnutls_credentials_set}:
848 To set the appropriate credentials structures.
850 @item @ref{gnutls_certificate_server_set_request}:
851 To set whether client certificate is required or not.
853 @item @ref{gnutls_handshake}:
854 To initiate the handshake.
855 @end table
857 @subsection TLS Cipher Suites
859 The Handshake Protocol of @acronym{TLS} negotiates cipher suites of
860 the form @code{TLS_DHE_RSA_WITH_3DES_CBC_SHA}.  The usual cipher
861 suites contain these parameters:
863 @itemize
865 @item The key exchange algorithm.
866 @code{DHE_RSA} in the example.
868 @item The Symmetric encryption algorithm and mode
869 @code{3DES_CBC} in this example.
871 @item The MAC@footnote{MAC stands for Message Authentication Code. It can be described as a keyed hash algorithm. See RFC2104.} algorithm used for authentication.
872 @code{MAC_SHA} is used in the above example.
874 @end itemize
876 The cipher suite negotiated in the handshake protocol will affect the
877 Record Protocol, by enabling encryption and data authentication.  Note
878 that you should not over rely on @acronym{TLS} to negotiate the
879 strongest available cipher suite. Do not enable ciphers and algorithms
880 that you consider weak.
882 The priority functions, dicussed above, allow the application layer to
883 enable and set priorities on the individual ciphers. It may imply that
884 all combinations of ciphersuites are allowed, but this is not
885 true. For several reasons, not discussed here, some combinations were
886 not defined in the @acronym{TLS} protocol.  The supported ciphersuites
887 are shown in @ref{ciphersuites}.
889 @subsection Client Authentication
890 @cindex Client Certificate authentication
892 In the case of ciphersuites that use certificate authentication, the
893 authentication of the client is optional in @acronym{TLS}.  A server
894 may request a certificate from the client --- using the
895 @ref{gnutls_certificate_server_set_request} function. If a
896 certificate is to be requested from the client during the handshake,
897 the server will send a certificate request message that contains a
898 list of acceptable certificate signers. In @acronym{GnuTLS} the certificate
899 signers list is constructed using the trusted Certificate Authorities by the 
900 server. That is the ones set using
901 @itemize
902 @item @ref{gnutls_certificate_set_x509_trust_file}
903 @item @ref{gnutls_certificate_set_x509_trust_mem}
904 @end itemize
906 Sending of the names of the CAs can be controlled using 
907 @ref{gnutls_certificate_send_x509_rdn_sequence}. The client, then, 
908 may send a certificate, signed by one of the server's acceptable 
909 signers. 
911 @subsection Resuming Sessions
912 @anchor{resume}
913 @cindex Resuming sessions
915 The @ref{gnutls_handshake} function, is expensive since a lot of
916 calculations are performed. In order to support many fast connections
917 to the same server a client may use session resuming. @strong{Session
918 resuming} is a feature of the @acronym{TLS} protocol which allows a
919 client to connect to a server, after a successful handshake, without
920 the expensive calculations.  This is achieved by using the previously
921 established keys. @acronym{GnuTLS} supports this feature, and the
922 example (@pxref{ex:resume-client}) illustrates a typical use of it.
924 Keep in mind that sessions are expired after some time, for security
925 reasons, thus it may be normal for a server not to resume a session
926 even if you requested that.  Also note that you must enable, using the
927 priority functions, at least the algorithms used in the last session.
929 @subsection Resuming Internals
931 The resuming capability, mostly in the server side, is one of the
932 problems of a thread-safe TLS implementations. The problem is that all
933 threads must share information in order to be able to resume
934 sessions. The gnutls approach is, in case of a client, to leave all
935 the burden of resuming to the client. I.e., copy and keep the necessary
936 parameters. See the functions:
938 @itemize
940 @item @ref{gnutls_session_get_data}
942 @item @ref{gnutls_session_get_id}
944 @item @ref{gnutls_session_set_data}
946 @end itemize
948 The server side is different. A server has to specify some callback
949 functions which store, retrieve and delete session data. These can be
950 registered with:
952 @itemize
954 @item @ref{gnutls_db_set_remove_function}
956 @item @ref{gnutls_db_set_store_function}
958 @item @ref{gnutls_db_set_retrieve_function}
960 @item @ref{gnutls_db_set_ptr}
962 @end itemize
964 It might also be useful to be able to check for expired sessions in
965 order to remove them, and save space. The function
966 @ref{gnutls_db_check_entry} is provided for that reason.
968 @node TLS Extensions
969 @section TLS Extensions
970 @cindex TLS Extensions
972 A number of extensions to the @acronym{TLS} protocol have been
973 proposed mainly in @xcite{TLSEXT}. The extensions supported
974 in @acronym{GnuTLS} are:
976 @itemize
977 @item Maximum fragment length negotiation
978 @item Server name indication
979 @end itemize
981 and they will be discussed in the subsections that follow.
983 @subsection Maximum Fragment Length Negotiation
984 @cindex TLS Extensions
985 @cindex Maximum fragment length
987 This extension allows a @acronym{TLS} implementation to negotiate a
988 smaller value for record packet maximum length. This extension may be
989 useful to clients with constrained capabilities. See the
990 @ref{gnutls_record_set_max_size} and the
991 @ref{gnutls_record_get_max_size} functions.
993 @subsection Server Name Indication
994 @anchor{serverind}
995 @cindex TLS Extensions
996 @cindex Server name indication
998 A common problem in @acronym{HTTPS} servers is the fact that the
999 @acronym{TLS} protocol is not aware of the hostname that a client
1000 connects to, when the handshake procedure begins. For that reason the
1001 @acronym{TLS} server has no way to know which certificate to send.
1003 This extension solves that problem within the @acronym{TLS} protocol,
1004 and allows a client to send the HTTP hostname before the handshake
1005 begins within the first handshake packet.  The functions
1006 @ref{gnutls_server_name_set} and @ref{gnutls_server_name_get} can be
1007 used to enable this extension, or to retrieve the name sent by a
1008 client.
1010 @node Selecting cryptographic key sizes
1011 @section Selecting Cryptographic Key Sizes
1012 @cindex key sizes
1014 In TLS, since a lot of algorithms are involved, it is not easy to set a consistent security level.
1015 For this reason this section will present some correspondance between key sizes of symmetric algorithms
1016 and public key algorithms based on the most conservative values of @xcite{SELKEY}. 
1017 Those can be used to generate certificates with appropriate key sizes as well
1018 as parameters for Diffie Hellman and SRP authentication.
1020 @multitable @columnfractions .15 .20 .20 .20
1022 @item Year
1023 @tab Symmetric key size
1024 @tab RSA key size, DH and SRP prime size
1025 @tab ECC key size
1027 @item 1982
1028 @tab 56
1029 @tab 417
1030 @tab 105
1032 @item 1988
1033 @tab 61
1034 @tab 566
1035 @tab 114
1037 @item 2002
1038 @tab 72
1039 @tab 1028
1040 @tab 139
1042 @item 2015
1043 @tab 82
1044 @tab 1613
1045 @tab 173
1047 @item 2028
1048 @tab 92
1049 @tab 2362
1050 @tab 210
1052 @item 2040
1053 @tab 101
1054 @tab 3214
1055 @tab 244
1057 @item 2050 
1058 @tab 109
1059 @tab 4047
1060 @tab 272
1062 @end multitable
1064 The first column provides an estimation of the year until these parameters
1065 are considered safe and the rest of the columns list the parameters for the
1066 various algorithms.
1068 Note however that the values suggested here are nothing more than an educated
1069 guess that is valid today. There are no guarrantees that an algorithm will remain unbreakable or that these values will remain constant in time. There could be scientific breakthroughs that cannot be predicted or total failure of the current public key systems by quantum computers. On the other hand though the cryptosystems
1070 used in TLS are selected in a conservative way and such catastrophic breakthroughs or failures are believed to be unlikely.
1072 @node On SSL 2 and older protocols
1073 @section On SSL 2 and Older Protocols
1074 @cindex SSL 2
1076 One of the initial decisions in the @acronym{GnuTLS} development was
1077 to implement the known security protocols for the transport layer.
1078 Initially @acronym{TLS} 1.0 was implemented since it was the latest at
1079 that time, and was considered to be the most advanced in security
1080 properties.  Later the @acronym{SSL} 3.0 protocol was implemented
1081 since it is still the only protocol supported by several servers and
1082 there are no serious security vulnerabilities known.
1084 One question that may arise is why we didn't implement @acronym{SSL}
1085 2.0 in the library.  There are several reasons, most important being
1086 that it has serious security flaws, unacceptable for a modern security
1087 library.  Other than that, this protocol is barely used by anyone
1088 these days since it has been deprecated since 1996.  The security
1089 problems in @acronym{SSL} 2.0 include:
1091 @itemize
1093 @item Message integrity compromised.
1094 The @acronym{SSLv2} message authentication uses the MD5 function, and
1095 is insecure.
1097 @item Man-in-the-middle attack.
1098 There is no protection of the handshake in @acronym{SSLv2}, which
1099 permits a man-in-the-middle attack.
1101 @item Truncation attack.
1102 @acronym{SSLv2} relies on TCP FIN to close the session, so the
1103 attacker can forge a TCP FIN, and the peer cannot tell if it was a
1104 legitimate end of data or not.
1106 @item Weak message integrity for export ciphers.
1107 The cryptographic keys in @acronym{SSLv2} are used for both message
1108 authentication and encryption, so if weak encryption schemes are
1109 negotiated (say 40-bit keys) the message authentication code use the
1110 same weak key, which isn't necessary.
1112 @end itemize
1114 @cindex PCT
1115 Other protocols such as Microsoft's @acronym{PCT} 1 and @acronym{PCT}
1116 2 were not implemented because they were also abandoned and deprecated
1117 by @acronym{SSL} 3.0 and later @acronym{TLS} 1.0.
1119 @node On Record Padding
1120 @section On Record Padding
1121 @cindex Record padding
1122 @cindex Bad record MAC
1124 The TLS protocol allows for random padding of records, to make it more
1125 difficult to perform analysis on the length of exchanged messages.
1126 (In RFC 4346 this is specified in section 6.2.3.2.)  GnuTLS appears to
1127 be one of few implementation that take advantage of this text, and pad
1128 records by a random length.
1130 The TLS implementation in the Symbian operating system, frequently
1131 used by Nokia and Sony-Ericsson mobile phones, cannot handle
1132 non-minimal record padding.  What happens when one of these clients
1133 handshake with a GnuTLS server is that the client will fail to compute
1134 the correct MAC for the record.  The client sends a TLS alert
1135 (@code{bad_record_mac}) and disconnects.  Typically this will result
1136 in error messages such as 'A TLS fatal alert has been received', 'Bad
1137 record MAC', or both, on the GnuTLS server side.
1139 GnuTLS implements a work around for this problem.  However, it has to
1140 be enabled specifically.  It can be enabled by using
1141 @ref{gnutls_record_disable_padding}, or @ref{gnutls_priority_set} with
1142 the @code{%COMPAT} priority string.
1144 If you implement an application that have a configuration file, we
1145 recommend that you make it possible for users or administrators to
1146 specify a GnuTLS protocol priority string, which is used by your
1147 application via @ref{gnutls_priority_set}.  To allow the best
1148 flexibility, make it possible to have a different priority string for
1149 different incoming IP addresses.
1151 To enable the workaround in the @code{gnutls-cli} client or the
1152 @code{gnutls-serv} server, for testing of other implementations, use
1153 the following parameter: @code{--priority "%COMPAT"}.
1155 This problem has been discussed on mailing lists and in bug reports.
1156 This section tries to collect all pieces of information that we know
1157 about the problem.  If you wish to go back to the old discussions,
1158 here are some links:
1160 @url{http://bugs.debian.org/390712}
1162 @url{http://bugs.debian.org/402861}
1164 @url{http://bugs.debian.org/438137}
1166 @url{http://thread.gmane.org/gmane.ietf.tls/3079}
1168 @node Authentication methods
1169 @chapter Authentication Methods
1171 The @acronym{TLS} protocol provides confidentiality and encryption,
1172 but also offers authentication, which is a prerequisite for a secure
1173 connection. The available authentication methods in @acronym{GnuTLS}
1174 are:
1176 @itemize
1178 @item Certificate authentication
1180 @item Anonymous authentication
1182 @item @acronym{SRP} authentication
1184 @item @acronym{PSK} authentication
1186 @end itemize
1188 @menu
1189 * Certificate authentication::
1190 * Anonymous authentication::
1191 * Authentication using SRP::
1192 * Authentication using PSK::
1193 * Authentication and credentials::
1194 * Parameters stored in credentials::
1195 @end menu
1197 @node Certificate authentication
1198 @section Certificate Authentication
1200 @subsection Authentication Using @acronym{X.509} Certificates
1201 @cindex @acronym{X.509} certificates
1203 @acronym{X.509} certificates contain the public parameters, of a
1204 public key algorithm, and an authority's signature, which proves the
1205 authenticity of the parameters.  @xref{The X.509 trust model}, for
1206 more information on @acronym{X.509} protocols.
1208 @subsection Authentication Using @acronym{OpenPGP} Keys
1209 @cindex @acronym{OpenPGP} Keys
1211 @acronym{OpenPGP} keys also contain public parameters of a public key
1212 algorithm, and signatures from several other parties. Depending on
1213 whether a signer is trusted the key is considered trusted or not.
1214 @acronym{GnuTLS}'s @acronym{OpenPGP} authentication implementation is
1215 based on the @xcite{TLSPGP} proposal.
1217 @xref{The OpenPGP trust model}, for more information about the
1218 @acronym{OpenPGP} trust model.  For a more detailed introduction to
1219 @acronym{OpenPGP} and @acronym{GnuPG} see @xcite{GPGH}.
1221 @subsection Using Certificate Authentication
1223 In @acronym{GnuTLS} both the @acronym{OpenPGP} and @acronym{X.509}
1224 certificates are part of the certificate authentication and thus are
1225 handled using a common API.
1227 When using certificates the server is required to have at least one
1228 certificate and private key pair. A client may or may not have such a
1229 pair. The certificate and key pair should be loaded, before any
1230 @acronym{TLS} session is initialized, in a certificate credentials
1231 structure. This should be done by using
1232 @ref{gnutls_certificate_set_x509_key_file} or
1233 @ref{gnutls_certificate_set_openpgp_key_file} depending on the
1234 certificate type.  In the @acronym{X.509} case, the functions will
1235 also accept and use a certificate list that leads to a trusted
1236 authority. The certificate list must be ordered in such way that every
1237 certificate certifies the one before it. The trusted authority's
1238 certificate need not to be included, since the peer should possess it
1239 already.
1241 As an alternative, a callback may be used so the server or the client
1242 specify the certificate and the key at the handshake time.  That
1243 callback can be set using the functions:
1245 @itemize
1247 @item @ref{gnutls_certificate_server_set_retrieve_function}
1249 @item @ref{gnutls_certificate_client_set_retrieve_function}
1251 @end itemize
1253 Certificate verification is possible by loading the trusted
1254 authorities into the credentials structure by using
1255 @ref{gnutls_certificate_set_x509_trust_file} or
1256 @ref{gnutls_certificate_set_openpgp_keyring_file} for openpgp
1257 keys. Note however that the peer's certificate is not automatically
1258 verified, you should call @ref{gnutls_certificate_verify_peers2},
1259 after a successful handshake, to verify the signatures of the
1260 certificate.  An alternative way, which reports a more detailed
1261 verification output, is to use @ref{gnutls_certificate_get_peers} to
1262 obtain the raw certificate of the peer and verify it using the
1263 functions discussed in @ref{The X.509 trust model}.
1265 In a handshake, the negotiated cipher suite depends on the
1266 certificate's parameters, so not all key exchange methods will be
1267 available with some certificates. @acronym{GnuTLS} will disable
1268 ciphersuites that are not compatible with the key, or the enabled
1269 authentication methods.  For example keys marked as sign-only, will
1270 not be able to access the plain RSA ciphersuites, but only the
1271 @code{DHE_RSA} ones. It is recommended not to use RSA keys for both
1272 signing and encryption. If possible use the same key for the
1273 @code{DHE_RSA} and @code{RSA_EXPORT} ciphersuites, which use signing,
1274 and a different key for the plain RSA ciphersuites, which use
1275 encryption.  All the key exchange methods shown below are available in
1276 certificate authentication.
1278 Note that the DHE key exchange methods are generally
1279 slower@footnote{It really depends on the group used.  Primes with
1280 lesser bits are always faster, but also easier to break.  Values less
1281 than 768 should not be used today} than plain RSA and require Diffie
1282 Hellman parameters to be generated and associated with a credentials
1283 structure, by the server.  The @code{RSA-EXPORT} method also requires 512 bit RSA
1284 parameters, that should also be generated and associated with the
1285 credentials structure.  See the functions:
1287 @itemize
1289 @item @ref{gnutls_dh_params_generate2}
1291 @item @ref{gnutls_certificate_set_dh_params}
1293 @item @ref{gnutls_rsa_params_generate2}
1295 @item @ref{gnutls_certificate_set_rsa_export_params}
1297 @end itemize
1299 Sometimes in order to avoid bottlenecks in programs it is usefull to store
1300 and read parameters from formats that can be generated by external programs such
1301 as @code{certtool}. This is possible with @acronym{GnuTLS} by using the following
1302 functions:
1304 @itemize
1306 @item @ref{gnutls_dh_params_import_pkcs3}
1308 @item @ref{gnutls_rsa_params_import_pkcs1}
1310 @item @ref{gnutls_dh_params_export_pkcs3}
1312 @item @ref{gnutls_rsa_params_export_pkcs1}
1314 @end itemize
1316 Key exchange algorithms for @acronym{OpenPGP} and @acronym{X.509}
1317 certificates:
1319 @table @code
1321 @item RSA:
1322 The RSA algorithm is used to encrypt a key and send it to the peer.
1323 The certificate must allow the key to be used for encryption.
1325 @item RSA_EXPORT:
1326 The RSA algorithm is used to encrypt a key and send it to the peer.
1327 In the EXPORT algorithm, the server signs temporary RSA parameters of
1328 512 bits --- which are considered weak --- and sends them to the client.
1330 @item DHE_RSA:
1331 The RSA algorithm is used to sign Ephemeral Diffie Hellman parameters
1332 which are sent to the peer. The key in the certificate must allow the
1333 key to be used for signing. Note that key exchange algorithms which
1334 use Ephemeral Diffie Hellman parameters, offer perfect forward
1335 secrecy. That means that even if the private key used for signing is
1336 compromised, it cannot be used to reveal past session data.
1338 @item DHE_DSS:
1339 The DSS algorithm is used to sign Ephemeral Diffie Hellman parameters
1340 which are sent to the peer. The certificate must contain DSA
1341 parameters to use this key exchange algorithm. DSS stands for Digital
1342 Signature Standard.
1344 @end table
1346 @node Anonymous authentication
1347 @section Anonymous Authentication
1348 @cindex Anonymous authentication
1350 The anonymous key exchange performs encryption but there is no
1351 indication of the identity of the peer.  This kind of authentication
1352 is vulnerable to a man in the middle attack, but this protocol can be
1353 used even if there is no prior communication and trusted parties with
1354 the peer, or when full anonymity is required.  Unless really required,
1355 do not use anonymous authentication.  Available key exchange methods
1356 are shown below.
1358 Note that the key exchange methods for anonymous authentication
1359 require Diffie Hellman parameters to be generated by the server and associated with
1360 an anonymous credentials structure.
1362 Supported anonymous key exchange algorithms:
1364 @table @code
1366 @item ANON_DH:
1367 This algorithm exchanges Diffie Hellman parameters.
1369 @end table
1371 @node Authentication using SRP
1372 @section Authentication using @acronym{SRP}
1373 @cindex @acronym{SRP} authentication
1375 Authentication via the Secure Remote Password protocol,
1376 @acronym{SRP}@footnote{@acronym{SRP} is described in @xcite{RFC2945}},
1377 is supported.  The @acronym{SRP} key exchange is an extension to the
1378 @acronym{TLS} protocol, and it is a password based authentication
1379 (unlike @acronym{X.509} or @acronym{OpenPGP} that use certificates).
1380 The two peers can be identified using a single password, or there can
1381 be combinations where the client is authenticated using @acronym{SRP}
1382 and the server using a certificate.
1384 The advantage of @acronym{SRP} authentication, over other proposed
1385 secure password authentication schemes, is that @acronym{SRP} does not
1386 require the server to hold the user's password.  This kind of
1387 protection is similar to the one used traditionally in the @emph{UNIX}
1388 @file{/etc/passwd} file, where the contents of this file did not cause
1389 harm to the system security if they were revealed.  The @acronym{SRP}
1390 needs instead of the plain password something called a verifier, which
1391 is calculated using the user's password, and if stolen cannot be used
1392 to impersonate the user. Check @xcite{TOMSRP} for a detailed description
1393 of the @acronym{SRP} protocol and the Stanford @acronym{SRP}
1394 libraries, which includes a PAM module that synchronizes the system's
1395 users passwords with the @acronym{SRP} password files. That way
1396 @acronym{SRP} authentication could be used for all the system's users.
1398 The implementation in @acronym{GnuTLS} is based on paper
1399 @xcite{TLSSRP}.  The supported @acronym{SRP} key exchange methods are:
1401 @table @code
1403 @item SRP:
1404 Authentication using the @acronym{SRP} protocol.
1406 @item SRP_DSS:
1407 Client authentication using the @acronym{SRP} protocol. Server is
1408 authenticated using a certificate with DSA parameters.
1410 @item SRP_RSA:
1411 Client authentication using the @acronym{SRP} protocol. Server is
1412 authenticated using a certificate with RSA parameters.
1414 @end table
1416 If clients supporting @acronym{SRP} know the username and password
1417 before the connection, should initialize the client credentials and
1418 call the function @ref{gnutls_srp_set_client_credentials}.
1419 Alternatively they could specify a callback function by using the
1420 function @ref{gnutls_srp_set_client_credentials_function}.  This has
1421 the advantage that allows probing the server for @acronym{SRP}
1422 support.  In that case the callback function will be called twice per
1423 handshake.  The first time is before the ciphersuite is negotiated,
1424 and if the callback returns a negative error code, the callback will
1425 be called again if @acronym{SRP} has been negotiated.  This uses a
1426 special @acronym{TLS}-@acronym{SRP} handshake idiom in order to avoid,
1427 in interactive applications, to ask the user for @acronym{SRP}
1428 password and username if the server does not negotiate an
1429 @acronym{SRP} ciphersuite.
1431 In server side the default behaviour of @acronym{GnuTLS} is to read
1432 the usernames and @acronym{SRP} verifiers from password files. These
1433 password files are the ones used by the @emph{Stanford srp libraries}
1434 and can be specified using the
1435 @ref{gnutls_srp_set_server_credentials_file}.  If a different
1436 password file format is to be used, then the function
1437 @ref{gnutls_srp_set_server_credentials_function}, should be called,
1438 in order to set an appropriate callback.
1440 Some helper functions such as
1442 @itemize
1444 @item @ref{gnutls_srp_verifier}
1446 @item @ref{gnutls_srp_base64_encode}
1448 @item @ref{gnutls_srp_base64_decode}
1450 @end itemize
1452 are included in @acronym{GnuTLS}, and can be used to generate and
1453 maintain @acronym{SRP} verifiers and password files.  A program to
1454 manipulate the required parameters for @acronym{SRP} authentication is
1455 also included.  @xref{srptool}, for more information.
1458 @node Authentication using PSK
1459 @section Authentication using @acronym{PSK}
1460 @cindex @acronym{PSK} authentication
1462 Authentication using Pre-shared keys is a method to authenticate using
1463 usernames and binary keys. This protocol avoids making use of public key infrastructure
1464 and expensive calculations, thus it is suitable for constraint clients.
1466 The implementation in @acronym{GnuTLS} is based on paper
1467 @xcite{TLSPSK}.  The supported @acronym{PSK} key exchange methods are:
1469 @table @code
1471 @item PSK:
1472 Authentication using the @acronym{PSK} protocol.
1474 @item DHE-PSK:
1475 Authentication using the @acronym{PSK} protocol and Diffie Hellman key exchange.
1476 This method offers perfect forward secrecy.
1478 @end table
1480 Clients supporting @acronym{PSK} should supply the username and key
1481 before the connection to the client credentials by calling
1482 the function @ref{gnutls_psk_set_client_credentials}.
1483 Alternatively they could specify a callback function by using the
1484 function @ref{gnutls_psk_set_client_credentials_function}.
1485 This has the advantage that the callback will be called only if @acronym{PSK}
1486 has been negotiated.
1488 In server side the default behaviour of @acronym{GnuTLS} is to read
1489 the usernames and @acronym{PSK} keys from a password file. The password file
1490 should contain usernames and keys in hexadecimal format. The name of the password
1491 file can be stored to the credentials structure by calling
1492 @ref{gnutls_psk_set_server_credentials_file}.  If a different
1493 password file format is to be used, then the function
1494 @ref{gnutls_psk_set_server_credentials_function}, should be used instead.
1496 The server can help the client chose a suitable username and password,
1497 by sending a hint.  In the server, specify the hint by calling
1498 @ref{gnutls_psk_set_server_credentials_hint}.  The client can retrieve
1499 the hint, for example in the callback function, using
1500 @ref{gnutls_psk_client_get_hint}.
1502 There is no standard mechanism to derive a PSK key from a password
1503 specified by the TLS PSK document.  However, GnuTLS provides
1504 @ref{gnutls_psk_netconf_derive_key} which follows the algorithm
1505 specified in @file{draft-ietf-netconf-tls-02.txt}.
1507 Some helper functions such as:
1509 @itemize
1511 @item @ref{gnutls_hex_encode}
1513 @item @ref{gnutls_hex_decode}
1515 @end itemize
1517 are included in @acronym{GnuTLS}, and may be used to generate and
1518 maintain @acronym{PSK} keys.
1521 @node Authentication and credentials
1522 @section Authentication and Credentials
1524 In @acronym{GnuTLS} every key exchange method is associated with a
1525 credentials type. So in order to enable to enable a specific method,
1526 the corresponding credentials type should be initialized and set using
1527 @ref{gnutls_credentials_set}.  A mapping is shown below.
1529 Key exchange algorithms and the corresponding credential types:
1531 @multitable @columnfractions .3 .3 .3
1533 @headitem Key exchange @tab Client credentials @tab Server credentials
1535 @item @code{KX_RSA}
1536 @item @code{KX_DHE_RSA}
1537 @item @code{KX_DHE_DSS}
1538 @item @code{KX_RSA_EXPORT}
1539 @tab @code{CRD_CERTIFICATE}
1540 @tab @code{CRD_CERTIFICATE}
1542 @item @code{KX_SRP_RSA}
1543 @tab @code{CRD_SRP}
1544 @tab @code{CRD_SRP}
1545 @item @code{KX_SRP_DSS}
1546 @tab
1547 @tab @code{CRD_CERTIFICATE}
1549 @item @code{KX_SRP}
1550 @tab @code{CRD_SRP}
1551 @tab @code{CRD_SRP}
1553 @item @code{KX_ANON_DH}
1554 @tab @code{CRD_ANON}
1555 @tab @code{CRD_ANON}
1557 @item @code{KX_PSK}
1558 @tab @code{CRD_PSK}
1559 @tab @code{CRD_PSK}
1561 @end multitable
1563 @node Parameters stored in credentials
1564 @section Parameters Stored in Credentials
1566 Several parameters such as the ones used for Diffie-Hellman
1567 authentication are stored within the credentials structures, so all
1568 sessions can access them. Those parameters are stored in structures
1569 such as @code{gnutls_dh_params_t} and @code{gnutls_rsa_params_t}, and
1570 functions like @ref{gnutls_certificate_set_dh_params} and
1571 @ref{gnutls_certificate_set_rsa_export_params} can be used to
1572 associate those parameters with the given credentials structure.
1574 Since those parameters need to be renewed from time to time and a
1575 global structure such as the credentials, may not be easy to modify
1576 since it is accessible by all sessions, an alternative interface is
1577 available using a callback function.  This can be set using the
1578 @ref{gnutls_certificate_set_params_function}.  An example is shown
1579 below.
1581 @example
1582 #include <gnutls.h>
1584 gnutls_rsa_params_t rsa_params;
1585 gnutls_dh_params_t dh_params;
1587 /* This function will be called once a session requests DH
1588  * or RSA parameters. The parameters returned (if any) will
1589  * be used for the first handshake only.
1590  */
1591 static int get_params( gnutls_session_t session,
1592         gnutls_params_type_t type,
1593         gnutls_params_st *st)
1595    if (type == GNUTLS_PARAMS_RSA_EXPORT)
1596       st->params.rsa_export = rsa_params;
1597    else if (type == GNUTLS_PARAMS_DH)
1598       st->params.dh = dh_params;
1599    else return -1;
1601    st->type = type;
1602    /* do not deinitialize those parameters.
1603     */
1604    st->deinit = 0;
1606    return 0;
1609 int main()
1611    gnutls_certificate_credentials_t cert_cred;
1613    initialize_params();
1615    /* ...
1616     */
1618    gnutls_certificate_set_params_function( cert_cred, get_params);
1620 @end example
1622 @node More on certificate authentication
1623 @chapter More on Certificate Authentication
1624 @anchor{Certificate Authentication}
1625 @cindex Certificate authentication
1627 @menu
1628 * The X.509 trust model::
1629 * The OpenPGP trust model::
1630 * Digital signatures::
1631 @end menu
1633 @node The X.509 trust model
1634 @section The @acronym{X.509} Trust Model
1635 @cindex @acronym{X.509} certificates
1637 The @acronym{X.509} protocols rely on a hierarchical trust model. In
1638 this trust model Certification Authorities (CAs) are used to certify
1639 entities.  Usually more than one certification authorities exist, and
1640 certification authorities may certify other authorities to issue
1641 certificates as well, following a hierarchical model.
1643 @image{gnutls-x509,7cm,9.5cm}
1645 One needs to trust one or more CAs for his secure communications. In
1646 that case only the certificates issued by the trusted authorities are
1647 acceptable.  See the figure above for a typical example.  The API for
1648 handling @acronym{X.509} certificates is described at section
1649 @ref{sec:x509api}.  Some examples are listed below.
1651 @menu
1652 * X.509 certificates::
1653 * Verifying X.509 certificate paths::
1654 * PKCS #10 certificate requests::
1655 * PKCS #12 structures::
1656 @end menu
1658 @node X.509 certificates
1659 @subsection @acronym{X.509} Certificates
1661 An @acronym{X.509} certificate usually contains information about the
1662 certificate holder, the signer, a unique serial number, expiration
1663 dates and some other fields @xcite{RFC3280} as shown in the table
1664 below.
1666 @table @code
1668 @item version:
1669 The field that indicates the version of the certificate.
1671 @item serialNumber:
1672 This field holds a unique serial number per certificate.
1674 @item issuer:
1675 Holds the issuer's distinguished name.
1677 @item validity:
1678 The activation and expiration dates.
1680 @item subject:
1681 The subject's distinguished name of the certificate.
1683 @item extensions:
1684 The extensions are fields only present in version 3 certificates.
1686 @end table
1688 The certificate's @emph{subject or issuer name} is not just a single
1689 string.  It is a Distinguished name and in the @acronym{ASN.1}
1690 notation is a sequence of several object IDs with their corresponding
1691 values. Some of available OIDs to be used in an @acronym{X.509}
1692 distinguished name are defined in @file{gnutls/x509.h}.
1694 The @emph{Version} field in a certificate has values either 1 or 3 for
1695 version 3 certificates.  Version 1 certificates do not support the
1696 extensions field so it is not possible to distinguish a CA from a
1697 person, thus their usage should be avoided.
1699 The @emph{validity} dates are there to indicate the date that the
1700 specific certificate was activated and the date the certificate's key
1701 would be considered invalid.
1703 Certificate @emph{extensions} are there to include information about
1704 the certificate's subject that did not fit in the typical certificate
1705 fields. Those may be e-mail addresses, flags that indicate whether the
1706 belongs to a CA etc.  All the supported @acronym{X.509} version 3
1707 extensions are shown in the table below.
1709 @table @code
1711 @item subject key id (2.5.29.14):
1712 An identifier of the key of the subject.
1714 @item authority key id (2.5.29.35):
1715 An identifier of the authority's key used to sign the certificate.
1717 @item subject alternative name (2.5.29.17):
1718 Alternative names to subject's distinguished name.
1720 @item key usage (2.5.29.15):
1721 Constraints the key's usage of the certificate.
1723 @item extended key usage (2.5.29.37):
1724 Constraints the purpose of the certificate.
1726 @item basic constraints (2.5.29.19):
1727 Indicates whether this is a CA certificate or not, and specify the
1728 maximum path lengths of certificate chains.
1730 @item CRL distribution points (2.5.29.31):
1731 This extension is set by the CA, in order to inform about the issued CRLs.
1733 @item Proxy Certification Information (1.3.6.1.5.5.7.1.14):
1734 Proxy Certificates includes this extension that contains the OID of
1735 the proxy policy language used, and can specify limits on the maximum
1736 lengths of proxy chains.  Proxy Certificates are specified in
1737 @xcite{RFC3820}.
1739 @end table
1741 In @acronym{GnuTLS} the @acronym{X.509} certificate structures are handled using
1742 the @code{gnutls_x509_crt_t} type and the corresponding private keys
1743 with the @code{gnutls_x509_privkey_t} type.  All the available
1744 functions for @acronym{X.509} certificate handling have their prototypes in
1745 @file{gnutls/x509.h}. An example program to demonstrate the @acronym{X.509}
1746 parsing capabilities can be found at section @ref{ex:x509-info}.
1748 @node Verifying X.509 certificate paths
1749 @subsection Verifying @acronym{X.509} Certificate Paths
1750 @cindex Verifying certificate paths
1752 Verifying certificate paths is important in @acronym{X.509} authentication. For
1753 this purpose the function @ref{gnutls_x509_crt_verify} is
1754 provided. The output of this function is the bitwise OR of the
1755 elements of the @code{gnutls_certificate_status_t} enumeration.  A
1756 detailed description of these elements can be found in figure below.
1757 The function @ref{gnutls_certificate_verify_peers2} is equivalent to
1758 the previous one, and will verify the peer's certificate in a TLS
1759 session.
1761 @table @code
1763 @item CERT_INVALID:
1764 The certificate is not signed by one of the known authorities, or
1765 the signature is invalid.
1767 @item CERT_REVOKED:
1768 The certificate has been revoked by its CA.
1770 @item CERT_SIGNER_NOT_FOUND:
1771 The certificate's issuer is not known. This is the case when the
1772 issuer is not in the trusted certificates list.
1774 @item GNUTLS_CERT_SIGNER_NOT_CA:
1775 The certificate's signer was not a CA. This may happen if
1776 this was a version 1 certificate, which is common with some CAs, or
1777 a version 3 certificate without the basic constrains extension.
1779 @anchor{GNUTLS_CERT_INSECURE_ALGORITHM}
1780 @item GNUTLS_CERT_INSECURE_ALGORITHM:
1781 The certificate was signed using an insecure algorithm such as MD2 or
1782 MD5.  These algorithms have been broken and should not be trusted.
1784 @end table
1786 There is also to possibility to pass some input to the verification
1787 functions in the form of flags. For @ref{gnutls_x509_crt_verify} the
1788 flags are passed straightforward, but
1789 @ref{gnutls_certificate_verify_peers2} depends on the flags set by
1790 calling @ref{gnutls_certificate_set_verify_flags}.  All the available
1791 flags are part of the enumeration
1792 @ref{gnutls_certificate_verify_flags} and are explained in the table
1793 below.
1795 @anchor{gnutls_certificate_verify_flags}
1796 @tindex gnutls_certificate_verify_flags
1797 @table @code
1798 @item GNUTLS_VERIFY_DISABLE_CA_SIGN:
1799 If set a signer does not have to be a certificate authority. This
1800 flag should normaly be disabled, unless you know what this means.
1802 @item GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT:
1803 Allow only trusted CA certificates that have version 1.  This is
1804 safer than GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT, and should be
1805 used instead. That way only signers in your trusted list will be
1806 allowed to have certificates of version 1.
1808 @item GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT:
1809 Allow CA certificates that have version 1 (both root and
1810 intermediate). This is dangerous since those haven't the
1811 basicConstraints extension. Must be used in combination with
1812 GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT.
1814 @item GNUTLS_VERIFY_DO_NOT_ALLOW_SAME:
1815 If a certificate is not signed by anyone trusted but exists in
1816 the trusted CA list do not treat it as trusted.
1818 @item GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2:
1819 Allow certificates to be signed using the old MD2 algorithm.
1821 @item GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5:
1822 Allow certificates to be signed using the broken MD5 algorithm.
1823 @end table
1825 Although the verification of a certificate path indicates that the
1826 certificate is signed by trusted authority, does not reveal anything
1827 about the peer's identity. It is required to verify if the
1828 certificate's owner is the one you expect. For more information consult @xcite{RFC2818} 
1829 and section @ref{ex:verify} for an example.
1831 @node PKCS #10 certificate requests
1832 @subsection @acronym{PKCS} #10 Certificate Requests
1833 @cindex Certificate requests
1834 @cindex @acronym{PKCS} #10
1836 A certificate request is a structure, which contain information about
1837 an applicant of a certificate service.  It usually contains a private
1838 key, a distinguished name and secondary data such as a challenge
1839 password. @acronym{GnuTLS} supports the requests defined in
1840 @acronym{PKCS} #10 @xcite{RFC2986}. Other certificate request's format
1841 such as PKIX's @xcite{RFC4211} are not currently supported.
1843 In @acronym{GnuTLS} the @acronym{PKCS} #10 structures are handled
1844 using the @code{gnutls_x509_crq_t} type.  An example of a certificate
1845 request generation can be found at section @ref{ex:crq}.
1847 @node PKCS #12 structures
1848 @subsection @acronym{PKCS} #12 Structures
1849 @cindex @acronym{PKCS} #12
1851 A @acronym{PKCS} #12 structure @xcite{PKCS12} usually contains a user's
1852 private keys and certificates. It is commonly used in browsers to
1853 export and import the user's identities.
1855 In @acronym{GnuTLS} the @acronym{PKCS} #12 structures are handled
1856 using the @code{gnutls_pkcs12_t} type. This is an abstract type that
1857 may hold several @code{gnutls_pkcs12_bag_t} types.  The Bag types are
1858 the holders of the actual data, which may be certificates, private
1859 keys or encrypted data.  An Bag of type encrypted should be decrypted
1860 in order for its data to be accessed.
1862 An example of a @acronym{PKCS} #12 structure generation can be found
1863 at section @ref{ex:pkcs12}.
1865 @node The OpenPGP trust model
1866 @section The @acronym{OpenPGP} Trust Model
1867 @cindex @acronym{OpenPGP} Keys
1869 The @acronym{OpenPGP} key authentication relies on a distributed trust
1870 model, called the ``web of trust''. The ``web of trust'' uses a
1871 decentralized system of trusted introducers, which are the same as a
1872 CA. @acronym{OpenPGP} allows anyone to sign anyone's else public
1873 key. When Alice signs Bob's key, she is introducing Bob's key to
1874 anyone who trusts Alice. If someone trusts Alice to introduce keys,
1875 then Alice is a trusted introducer in the mind of that observer.
1877 @image{gnutls-pgp,11cm,9cm}
1879 For example: If David trusts Alice to be an introducer, and Alice
1880 signed Bob's key, Dave also trusts Bob's key to be the real one.
1882 There are some key points that are important in that model. In the
1883 example Alice has to sign Bob's key, only if she is sure that the key
1884 belongs to Bob. Otherwise she may also make Dave falsely believe that
1885 this is Bob's key. Dave has also the responsibility to know who to
1886 trust.  This model is similar to real life relations.
1888 Just see how Charlie behaves in the previous example. Although he has
1889 signed Bob's key - because he knows, somehow, that it belongs to Bob -
1890 he does not trust Bob to be an introducer. Charlie decided to trust
1891 only Kevin, for some reason. A reason could be that Bob is lazy
1892 enough, and signs other people's keys without being sure that they
1893 belong to the actual owner.
1895 @subsection @acronym{OpenPGP} Keys
1897 In @acronym{GnuTLS} the @acronym{OpenPGP} key structures
1898 @xcite{RFC2440} are handled using the @code{gnutls_openpgp_crt_t} type
1899 and the corresponding private keys with the
1900 @code{gnutls_openpgp_privkey_t} type. All the prototypes for the key
1901 handling functions can be found at @file{gnutls/openpgp.h}.
1903 @subsection Verifying an @acronym{OpenPGP} Key
1905 The verification functions of @acronym{OpenPGP} keys, included in
1906 @acronym{GnuTLS}, are simple ones, and do not use the features of the
1907 ``web of trust''.  For that reason, if the verification needs are
1908 complex, the assistance of external tools like @acronym{GnuPG} and
1909 GPGME (@url{http://www.gnupg.org/related_software/gpgme/}) is
1910 recommended.
1912 There is one verification function in @acronym{GnuTLS}, the
1913 @ref{gnutls_openpgp_crt_verify_ring}.
1914 This checks an @acronym{OpenPGP} key against a given set of public keys (keyring) and
1915 returns the key status. The key verification status is the same as in
1916 @acronym{X.509} certificates, although the meaning and interpretation are
1917 different. For example an @acronym{OpenPGP} key may be valid, if the
1918 self signature is ok, even if no signers were found.  The meaning of
1919 verification status is shown in the figure below.  
1921 @table @code
1923 @item CERT_INVALID:
1924 A signature on the key is invalid. That means that the key was
1925 modified by somebody, or corrupted during transport.
1927 @item CERT_REVOKED:
1928 The key has been revoked by its owner.
1930 @item CERT_SIGNER_NOT_FOUND:
1931 The key was not signed by a known signer.
1933 @item GNUTLS_CERT_INSECURE_ALGORITHM:
1934 The certificate was signed using an insecure algorithm such as MD2 or MD5.
1935 These algorithms have been broken and should not be trusted.
1937 @end table
1939 @node Digital signatures
1940 @section Digital Signatures
1941 @cindex Digital signatures
1942 @include signatures.texi
1945 @node How to use TLS in application protocols
1946 @chapter How To Use @acronym{TLS} in Application Protocols
1948 This chapter is intended to provide some hints on how to use the
1949 @acronym{TLS} over simple custom made application protocols.  The
1950 discussion below mainly refers to the @emph{TCP/IP} transport layer
1951 but may be extended to other ones too.
1953 @menu
1954 * Separate ports::
1955 * Upward negotiation::
1956 @end menu
1958 @node Separate ports
1959 @section Separate Ports
1961 Traditionally @acronym{SSL} was used in application protocols by
1962 assigning a new port number for the secure services. That way two
1963 separate ports were assigned, one for the non secure sessions, and one
1964 for the secured ones. This has the benefit that if a user requests a
1965 secure session then the client will try to connect to the secure port
1966 and fail otherwise. The only possible attack with this method is a
1967 denial of service one. The most famous example of this method is the
1968 famous ``HTTP over TLS'' or @acronym{HTTPS} protocol @xcite{RFC2818}.
1970 Despite its wide use, this method is not as good as it seems.  This
1971 approach starts the @acronym{TLS} Handshake procedure just after the
1972 client connects on the ---so called--- secure port.  That way the
1973 @acronym{TLS} protocol does not know anything about the client, and
1974 popular methods like the host advertising in HTTP do not
1975 work@footnote{See also the Server Name Indication extension on
1976 @ref{serverind}.}.  There is no way for the client to say ``I
1977 connected to YYY server'' before the Handshake starts, so the server
1978 cannot possibly know which certificate to use.
1980 Other than that it requires two separate ports to run a single
1981 service, which is unnecessary complication. Due to the fact that there
1982 is a limitation on the available privileged ports, this approach was
1983 soon obsoleted.
1985 @node Upward negotiation
1986 @section Upward Negotiation
1988 Other application protocols@footnote{See LDAP, IMAP etc.}  use a
1989 different approach to enable the secure layer.  They use something
1990 called the ``TLS upgrade'' method. This method is quite tricky but it
1991 is more flexible. The idea is to extend the application protocol to
1992 have a ``STARTTLS'' request, whose purpose it to start the TLS
1993 protocols just after the client requests it.  This is a really neat
1994 idea and does not require an extra port.
1996 This method is used by almost all modern protocols and there is even
1997 the @xcite{RFC2817} paper which proposes extensions to HTTP to support
2000 The tricky part, in this method, is that the ``STARTTLS'' request is
2001 sent in the clear, thus is vulnerable to modifications.  A typical
2002 attack is to modify the messages in a way that the client is fooled
2003 and thinks that the server does not have the ``STARTTLS'' capability.
2004 See a typical conversation of a hypothetical protocol:
2006 @quotation
2007 (client connects to the server)
2009 CLIENT: HELLO I'M MR. XXX
2011 SERVER: NICE TO MEET YOU XXX
2013 CLIENT: PLEASE START TLS
2015 SERVER: OK
2017 *** TLS STARTS
2019 CLIENT: HERE ARE SOME CONFIDENTIAL DATA
2020 @end quotation
2022 And see an example of a conversation where someone is acting
2023 in between:
2025 @quotation
2026 (client connects to the server)
2028 CLIENT: HELLO I'M MR. XXX
2030 SERVER: NICE TO MEET YOU XXX
2032 CLIENT: PLEASE START TLS
2034 (here someone inserts this message)
2036 SERVER: SORRY I DON'T HAVE THIS CAPABILITY
2038 CLIENT: HERE ARE SOME CONFIDENTIAL DATA
2039 @end quotation
2041 As you can see above the client was fooled, and was dummy enough to
2042 send the confidential data in the clear.
2044 How to avoid the above attack? As you may have already thought this
2045 one is easy to avoid. The client has to ask the user before it
2046 connects whether the user requests @acronym{TLS} or not. If the user
2047 answered that he certainly wants the secure layer the last
2048 conversation should be:
2050 @quotation
2051 (client connects to the server)
2053 CLIENT: HELLO I'M MR. XXX
2055 SERVER: NICE TO MEET YOU XXX
2057 CLIENT: PLEASE START TLS
2059 (here someone inserts this message)
2061 SERVER: SORRY I DON'T HAVE THIS CAPABILITY
2063 CLIENT: BYE
2065 (the client notifies the user that the secure connection was not possible)
2066 @end quotation
2068 This method, if implemented properly, is far better than the
2069 traditional method, and the security properties remain the same, since
2070 only denial of service is possible. The benefit is that the server may
2071 request additional data before the @acronym{TLS} Handshake protocol
2072 starts, in order to send the correct certificate, use the correct
2073 password file@footnote{in @acronym{SRP} authentication}, or anything
2074 else!
2076 @node How to use GnuTLS in applications
2077 @chapter How To Use @acronym{GnuTLS} in Applications
2078 @anchor{examples}
2079 @cindex Example programs
2081 @menu
2082 * Preparation::
2083 * Multi-threaded applications::
2084 * Client examples::
2085 * Server examples::
2086 * Miscellaneous examples::
2087 * Compatibility with the OpenSSL library::
2088 * Opaque PRF Input TLS Extension::
2089 @end menu
2091 @node Preparation
2092 @section Preparation
2094 To use @acronym{GnuTLS}, you have to perform some changes to your
2095 sources and your build system. The necessary changes are explained in
2096 the following subsections.
2098 @menu
2099 * Headers::
2100 * Version check::
2101 * Debugging::
2102 * Building the source::
2103 @end menu
2105 @node Headers
2106 @subsection Headers
2108 All the data types and functions of the @acronym{GnuTLS} library are
2109 defined in the header file @file{gnutls/gnutls.h}.  This must be
2110 included in all programs that make use of the @acronym{GnuTLS}
2111 library.
2113 The extra functionality of the @acronym{GnuTLS-extra} library is
2114 available by including the header file @file{gnutls/extra.h} in your
2115 programs.
2117 @node Version check
2118 @subsection Version Check
2120 It is often desirable to check that the version of `gnutls' used is
2121 indeed one which fits all requirements.  Even with binary
2122 compatibility new features may have been introduced but due to problem
2123 with the dynamic linker an old version is actually used.  So you may
2124 want to check that the version is okay right after program startup.
2125 See the function @ref{gnutls_check_version}.
2127 @node Debugging
2128 @subsection Debugging
2130 In many cases things may not go as expected and further information,
2131 to assist debugging, from @acronym{GnuTLS} is desired. Those are the
2132 case where the @ref{gnutls_global_set_log_level} and
2133 @ref{gnutls_global_set_log_function} are to be used. Those will print
2134 verbose information on the @acronym{GnuTLS} functions internal flow.
2136 @node Building the source
2137 @subsection Building the Source
2139 If you want to compile a source file including the `gnutls/gnutls.h'
2140 header file, you must make sure that the compiler can find it in the
2141 directory hierarchy.  This is accomplished by adding the path to the
2142 directory in which the header file is located to the compilers include
2143 file search path (via the -I option).
2145 However, the path to the include file is determined at the time the
2146 source is configured.  To solve this problem, @acronym{GnuTLS} ships
2147 with two small helper programs @command{libgnutls-config} and
2148 @command{libgnutls-extra-config} that knows about the path to the
2149 include file and other configuration options.  The options that need
2150 to be added to the compiler invocation at compile time are output by
2151 the @code{--cflags} option to @command{libgnutls-config}.  The
2152 following example shows how it can be used at the command line:
2154 @example
2155 gcc -c foo.c `libgnutls-config --cflags`
2156 @end example
2158 Adding the output of @command{libgnutls-config --cflags} to the
2159 compilers command line will ensure that the compiler can find the
2160 @acronym{GnuTLS} header file.
2162 A similar problem occurs when linking the program with the library.
2163 Again, the compiler has to find the library files.  For this to work,
2164 the path to the library files has to be added to the library search
2165 path (via the -L option).  For this, the option @code{--libs} to
2166 @command{libgnutls-config} can be used.  For convenience, this option
2167 also outputs all other options that are required to link the program
2168 with the @acronym{GnuTLS} libararies.  The example shows how to link
2169 `foo.o' with the @acronym{GnuTLS} libraries to a program @emph{foo}.
2171 @example
2172 gcc -o foo foo.o `libgnutls-config --libs`
2173 @end example
2175 Of course you can also combine both examples to a single command by
2176 specifying both options to `libgnutls-config':
2178 @example
2179 gcc -o foo foo.c `libgnutls-config --cflags --libs`
2180 @end example
2182 @node Multi-threaded applications
2183 @section Multi-Threaded Applications
2185 Although the @acronym{GnuTLS} library is thread safe by design, some
2186 parts of the crypto backend, such as the random generator, are
2187 not. Since @emph{libgcrypt 1.1.92} there was an automatic detection of
2188 the thread library used by the application, so most applications
2189 wouldn't need to do any changes to ensure thread-safety. Due to the
2190 unportability of the automatic thread detection, this was removed from
2191 later releases of @emph{libgcrypt}, so applications have now to
2192 register callback functions to ensure proper locking in sensitive
2193 parts of @emph{libgcrypt}.
2195 There are helper macros to help you properly initialize the libraries.
2196 Examples are shown below.
2198 @itemize
2200 @item POSIX threads
2201 @example
2202 #include <gnutls.h>
2203 #include <gcrypt.h>
2204 #include <errno.h>
2205 #include <pthread.h>
2206 GCRY_THREAD_OPTION_PTHREAD_IMPL;
2208 int main() 
2210    /* The order matters.
2211     */
2212    gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
2213    gnutls_global_init();
2215 @end example
2217 @item GNU PTH threads
2218 @example
2219 #include <gnutls.h>
2220 #include <gcrypt.h>
2221 #include <errno.h>
2222 #include <pth.h>
2223 GCRY_THREAD_OPTION_PTH_IMPL;
2225 int main() 
2227    gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pth);
2228    gnutls_global_init();
2230 @end example
2232 @item Other thread packages
2233 @example
2234 /* The gcry_thread_cbs structure must have been
2235  * initialized.
2236  */
2237 static struct gcry_thread_cbs gcry_threads_other = @{ ... @};
2239 int main()
2241    gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_other);
2243 @end example
2244 @end itemize
2246 @node Client examples
2247 @section Client Examples
2249 This section contains examples of @acronym{TLS} and @acronym{SSL}
2250 clients, using @acronym{GnuTLS}.  Note that these examples contain
2251 little or no error checking.  Some of the examples require functions
2252 implemented by another example.
2254 @menu
2255 * Simple client example with anonymous authentication::
2256 * Simple client example with X.509 certificate support::
2257 * Obtaining session information::
2258 * Verifying peer's certificate::
2259 * Using a callback to select the certificate to use::
2260 * Client with Resume capability example::
2261 * Simple client example with SRP authentication::
2262 * Simple client example with TLS/IA support::
2263 * Simple client example in @acronym{C++}::
2264 * Helper function for TCP connections::
2265 @end menu
2267 @node Simple client example with anonymous authentication
2268 @subsection Simple Client Example with Anonymous Authentication
2270 The simplest client using TLS is the one that doesn't do any
2271 authentication.  This means no external certificates or passwords are
2272 needed to set up the connection.  As could be expected, the connection
2273 is vulnerable to man-in-the-middle (active or redirection) attacks.
2274 However, the data is integrity and privacy protected.
2276 @verbatiminclude examples/ex-client1.c
2278 @node Simple client example with X.509 certificate support
2279 @subsection Simple Client Example with @acronym{X.509} Certificate Support
2281 Let's assume now that we want to create a TCP client which
2282 communicates with servers that use @acronym{X.509} or
2283 @acronym{OpenPGP} certificate authentication. The following client is
2284 a very simple @acronym{TLS} client, it does not support session
2285 resuming, not even certificate verification. The TCP functions defined
2286 in this example are used in most of the other examples below, without
2287 redefining them.
2289 @verbatiminclude examples/ex-client2.c
2291 @node Obtaining session information
2292 @subsection Obtaining Session Information
2294 Most of the times it is desirable to know the security properties of
2295 the current established session.  This includes the underlying ciphers
2296 and the protocols involved.  That is the purpose of the following
2297 function.  Note that this function will print meaningful values only
2298 if called after a successful @ref{gnutls_handshake}.
2300 @verbatiminclude examples/ex-session-info.c
2302 @node Verifying peer's certificate
2303 @subsection Verifying Peer's Certificate
2304 @anchor{ex:verify}
2306 A @acronym{TLS} session is not secure just after the handshake
2307 procedure has finished.  It must be considered secure, only after the
2308 peer's certificate and identity have been verified. That is, you have
2309 to verify the signature in peer's certificate, the hostname in the
2310 certificate, and expiration dates.  Just after this step you should
2311 treat the connection as being a secure one.
2313 @verbatiminclude examples/ex-rfc2818.c
2315 An other example is listed below which provides a more detailed
2316 verification output.
2318 @verbatiminclude examples/ex-verify.c
2320 @node Using a callback to select the certificate to use
2321 @subsection Using a Callback to Select the Certificate to Use
2323 There are cases where a client holds several certificate and key
2324 pairs, and may not want to load all of them in the credentials
2325 structure.  The following example demonstrates the use of the
2326 certificate selection callback.
2328 @verbatiminclude examples/ex-cert-select.c
2330 @node Client with Resume capability example
2331 @subsection Client with Resume Capability Example
2332 @anchor{ex:resume-client}
2334 This is a modification of the simple client example. Here we
2335 demonstrate the use of session resumption. The client tries to connect
2336 once using @acronym{TLS}, close the connection and then try to
2337 establish a new connection using the previously negotiated data.
2339 @verbatiminclude examples/ex-client-resume.c
2341 @node Simple client example with SRP authentication
2342 @subsection Simple Client Example with @acronym{SRP} Authentication
2344 The following client is a very simple @acronym{SRP} @acronym{TLS}
2345 client which connects to a server and authenticates using a
2346 @emph{username} and a @emph{password}. The server may authenticate
2347 itself using a certificate, and in that case it has to be verified.
2349 @verbatiminclude examples/ex-client-srp.c
2351 @node Simple client example with TLS/IA support
2352 @subsection Simple Client Example with @acronym{TLS/IA} Support
2354 The following client is a simple client which uses the
2355 @acronym{TLS/IA} extension to authenticate with the server.
2357 @verbatiminclude examples/ex-client-tlsia.c
2359 @node Simple client example in @acronym{C++}
2360 @subsection Simple Client Example using the @acronym{C++} API
2362 The following client is a simple example of a client
2363 client utilizing the GnuTLS @acronym{C++} API. 
2365 @verbatiminclude examples/ex-cxx.cpp
2367 @node Helper function for TCP connections
2368 @subsection Helper Function for TCP Connections
2370 This helper function abstracts away TCP connection handling from the
2371 other examples.  It is required to build some examples.
2373 @verbatiminclude examples/tcp.c
2375 @node Server examples
2376 @section Server Examples
2378 This section contains examples of @acronym{TLS} and @acronym{SSL}
2379 servers, using @acronym{GnuTLS}.
2381 @menu
2382 * Echo Server with X.509 authentication::
2383 * Echo Server with X.509 authentication II::
2384 * Echo Server with OpenPGP authentication::
2385 * Echo Server with SRP authentication::
2386 * Echo Server with anonymous authentication::
2387 @end menu
2389 @node Echo Server with X.509 authentication
2390 @subsection Echo Server with @acronym{X.509} Authentication
2392 This example is a very simple echo server which supports
2393 @acronym{X.509} authentication, using the RSA ciphersuites.
2395 @verbatiminclude examples/ex-serv1.c
2397 @node Echo Server with X.509 authentication II
2398 @subsection Echo Server with @acronym{X.509} Authentication II
2400 The following example is a server which supports @acronym{X.509}
2401 authentication.  This server supports the export-grade cipher suites,
2402 the DHE ciphersuites and session resuming.
2404 @verbatiminclude examples/ex-serv-export.c
2406 @node Echo Server with OpenPGP authentication
2407 @subsection Echo Server with @acronym{OpenPGP} Authentication
2408 @cindex @acronym{OpenPGP} Server
2410 The following example is an echo server which supports
2411 @acronym{@acronym{OpenPGP}} key authentication. You can easily combine
2412 this functionality ---that is have a server that supports both
2413 @acronym{X.509} and @acronym{OpenPGP} certificates--- but we separated
2414 them to keep these examples as simple as possible.
2416 @verbatiminclude examples/ex-serv-pgp.c
2418 @node Echo Server with SRP authentication
2419 @subsection Echo Server with @acronym{SRP} Authentication
2421 This is a server which supports @acronym{SRP} authentication. It is
2422 also possible to combine this functionality with a certificate
2423 server. Here it is separate for simplicity.
2425 @verbatiminclude examples/ex-serv-srp.c
2427 @node Echo Server with anonymous authentication
2428 @subsection Echo Server with Anonymous Authentication
2430 This example server support anonymous authentication, and could be
2431 used to serve the example client for anonymous authentication.
2433 @verbatiminclude examples/ex-serv-anon.c
2435 @node Miscellaneous examples
2436 @section Miscellaneous Examples
2438 @menu
2439 * Checking for an alert::
2440 * X.509 certificate parsing example::
2441 * Certificate request generation::
2442 * PKCS #12 structure generation::
2443 @end menu
2445 @node Checking for an alert
2446 @subsection Checking for an Alert
2448 This is a function that checks if an alert has been received in the
2449 current session.
2451 @verbatiminclude examples/ex-alert.c
2453 @node X.509 certificate parsing example
2454 @subsection @acronym{X.509} Certificate Parsing Example
2455 @anchor{ex:x509-info}
2457 To demonstrate the @acronym{X.509} parsing capabilities an example program is
2458 listed below.  That program reads the peer's certificate, and prints
2459 information about it.
2461 @verbatiminclude examples/ex-x509-info.c
2463 @node Certificate request generation
2464 @subsection Certificate Request Generation
2465 @anchor{ex:crq}
2467 The following example is about generating a certificate request, and a
2468 private key. A certificate request can be later be processed by a CA,
2469 which should return a signed certificate.
2471 @verbatiminclude examples/ex-crq.c
2473 @node PKCS #12 structure generation
2474 @subsection @acronym{PKCS} #12 Structure Generation
2475 @anchor{ex:pkcs12}
2477 The following example is about generating a @acronym{PKCS} #12
2478 structure.
2480 @verbatiminclude examples/ex-pkcs12.c
2482 @node Compatibility with the OpenSSL library
2483 @section Compatibility with the OpenSSL Library
2484 @cindex OpenSSL
2486 To ease @acronym{GnuTLS}' integration with existing applications, a
2487 compatibility layer with the widely used OpenSSL library is included
2488 in the @code{gnutls-openssl} library. This compatibility layer is not
2489 complete and it is not intended to completely reimplement the OpenSSL
2490 API with @acronym{GnuTLS}.  It only provides source-level
2491 compatibility. There is currently no attempt to make it
2492 binary-compatible with OpenSSL.
2494 The prototypes for the compatibility functions are in the
2495 @file{gnutls/openssl.h} header file.
2497 Current limitations imposed by the compatibility layer include:
2499 @itemize
2501 @item Error handling is not thread safe.
2503 @end itemize
2505 @node Opaque PRF Input TLS Extension
2506 @section Opaque PRF Input TLS Extension
2507 @cindex Opaque PRF Input
2509 GnuTLS supports the Opaque PRF Input TLS extension
2510 (@code{draft-rescorla-tls-opaque-prf-input-00.txt}).  The API consists
2511 of one API for use in the client, @ref{gnutls_oprfi_enable_client},
2512 and one API for use in the server, @ref{gnutls_oprfi_enable_server}.
2513 You must invoke both functions before calling @ref{gnutls_handshake}.
2514 The server utilizes a callback function into the application.  The
2515 callback can look at the random string provided by the client, and
2516 also set the server string.  The string lengths must be equal
2517 according to the protocol.
2519 @node Included programs
2520 @chapter Included Programs
2522 Included with @acronym{GnuTLS} are also a few command line tools that
2523 let you use the library for common tasks without writing an
2524 application.  The applications are discussed in this chapter.
2526 @menu
2527 * Invoking srptool::
2528 * Invoking gnutls-cli::
2529 * Invoking gnutls-cli-debug::
2530 * Invoking gnutls-serv::
2531 * Invoking certtool::
2532 * Invoking psktool::
2533 @end menu
2535 @node Invoking srptool
2536 @section Invoking srptool
2537 @anchor{srptool}
2538 @cindex srptool
2540 The @file{srptool} is a very simple program that emulates the programs
2541 in the @emph{Stanford SRP libraries}.  It is intended for use in
2542 places where you don't expect @acronym{SRP} authentication to be the
2543 used for system users.  Traditionally @emph{libsrp} used two
2544 files. One called 'tpasswd' which holds usernames and verifiers, and
2545 'tpasswd.conf' which holds generators and primes.
2547 How to use srptool:
2549 @itemize
2551 @item
2552 To create tpasswd.conf which holds the g and n values for
2553 @acronym{SRP} protocol (generator and a large prime), run:
2555 @example
2556 $ srptool --create-conf /etc/tpasswd.conf
2557 @end example
2559 @item
2560 This command will create /etc/tpasswd and will add user 'test' (you
2561 will also be prompted for a password). Verifiers are stored by default
2562 in the way libsrp expects.
2564 @example
2565 $ srptool --passwd /etc/tpasswd \
2566     --passwd-conf /etc/tpasswd.conf -u test
2567 @end example
2569 @item
2570 This command will check against a password. If the password matches
2571 the one in /etc/tpasswd you will get an ok.
2573 @example
2574 $ srptool --passwd /etc/tpasswd \
2575     --passwd-conf /etc/tpasswd.conf --verify -u test
2576 @end example
2578 @end itemize
2580 @node Invoking gnutls-cli
2581 @section Invoking gnutls-cli
2582 @cindex gnutls-cli
2584 Simple client program to set up a TLS connection to some other
2585 computer.  It sets up a TLS connection and forwards data from the
2586 standard input to the secured socket and vice versa.
2588 @verbatim
2589 GNU TLS test client
2590 Usage:  gnutls-cli [options] hostname
2592      -d, --debug integer      Enable debugging
2593      -r, --resume             Connect, establish a session. Connect
2594                               again and resume this session.
2595      -s, --starttls           Connect, establish a plain session and
2596                               start TLS when EOF or a SIGALRM is
2597                               received.
2598      --crlf                   Send CR LF instead of LF.
2599      --x509fmtder             Use DER format for certificates to read
2600                               from.
2601      -f, --fingerprint        Send the openpgp fingerprint, instead
2602                               of the key.
2603      --disable-extensions     Disable all the TLS extensions.
2604      --print-cert             Print the certificate in PEM format.
2605      -p, --port integer       The port to connect to.
2606      --recordsize integer     The maximum record size to advertize.
2607      -V, --verbose            More verbose output.
2608      --ciphers cipher1 cipher2...
2609                               Ciphers to enable.
2610      --protocols protocol1 protocol2...
2611                               Protocols to enable.
2612      --comp comp1 comp2...    Compression methods to enable.
2613      --macs mac1 mac2...      MACs to enable.
2614      --kx kx1 kx2...          Key exchange methods to enable.
2615      --ctypes certType1 certType2...
2616                               Certificate types to enable.
2617      --x509cafile FILE        Certificate file to use.
2618      --x509crlfile FILE       CRL file to use.
2619      --pgpkeyfile FILE        PGP Key file to use.
2620      --pgpkeyring FILE        PGP Key ring file to use.
2621      --pgptrustdb FILE        PGP trustdb file to use.
2622      --pgpcertfile FILE       PGP Public Key (certificate) file to
2623                               use.
2624      --x509keyfile FILE       X.509 key file to use.
2625      --x509certfile FILE      X.509 Certificate file to use.
2626      --srpusername NAME       SRP username to use.
2627      --srppasswd PASSWD       SRP password to use.
2628      --insecure               Don't abort program if server
2629                               certificate can't be validated.
2630      -l, --list               Print a list of the supported
2631                               algorithms  and modes.
2632      -h, --help               prints this help
2633      -v, --version            prints the program's version number
2634      --copyright              prints the program's license
2635 @end verbatim
2637 To connect to a server using PSK authentication, you may use something
2638 like:
2640 @smallexample
2641 $ gnutls-cli -p 5556 test.gnutls.org --pskusername jas --pskkey 9e32cf7786321a828ef7668f09fb35db --priority NORMAL:+PSK:-RSA:-DHE-RSA -d 4711
2642 @end smallexample
2644 @menu
2645 * Example client PSK connection::
2646 @end menu
2648 @node Example client PSK connection
2649 @subsection Example client PSK connection
2650 @cindex PSK client
2652 If your server only supports the PSK ciphersuite, connecting to it
2653 should be as simple as connecting to the server:
2655 @smallexample
2656 $ ./gnutls-cli -p 5556 localhost
2657 Resolving 'localhost'...
2658 Connecting to '127.0.0.1:5556'...
2659 - PSK client callback. PSK hint 'psk_identity_hint'
2660 Enter PSK identity: psk_identity
2661 Enter password: 
2662 - PSK authentication. PSK hint 'psk_identity_hint'
2663 - Version: TLS1.1
2664 - Key Exchange: PSK
2665 - Cipher: AES-128-CBC
2666 - MAC: SHA1
2667 - Compression: NULL
2668 - Handshake was completed
2670 - Simple Client Mode:
2671 @end smallexample
2673 If the server supports several cipher suites, you may need to force it
2674 to chose PSK by using a cipher priority parameter such as
2675 @code{--priority NORMAL:+PSK:-RSA:-DHE-RSA:-DHE-PSK}.
2677 @cindex Netconf
2678 Instead of using the Netconf-way to derive the PSK key from a
2679 password, you can also give the PSK username and key directly on the
2680 command line:
2682 @smallexample
2683 $ ./gnutls-cli -p 5556 localhost --pskusername psk_identity --pskkey 88f3824b3e5659f52d00e959bacab954b6540344 
2684 Resolving 'localhost'...
2685 Connecting to '127.0.0.1:5556'...
2686 - PSK authentication. PSK hint 'psk_identity_hint'
2687 - Version: TLS1.1
2688 - Key Exchange: PSK
2689 - Cipher: AES-128-CBC
2690 - MAC: SHA1
2691 - Compression: NULL
2692 - Handshake was completed
2694 - Simple Client Mode:
2695 @end smallexample
2697 By keeping the @code{--pskusername} parameter and removing the
2698 @code{--pskkey} parameter, it will query only for the password during
2699 the handshake.
2701 @node Invoking gnutls-cli-debug
2702 @section Invoking gnutls-cli-debug
2703 @cindex gnutls-cli-debug
2705 This program was created to assist in debugging @acronym{GnuTLS}, but
2706 it might be useful to extract a @acronym{TLS} server's capabilities.
2707 It's purpose is to connect onto a @acronym{TLS} server, perform some
2708 tests and print the server's capabilities. If called with the `-v'
2709 parameter a more checks will be performed. An example output is:
2711 @smallexample
2712 crystal:/cvs/gnutls/src$ ./gnutls-cli-debug localhost -p 5556
2713 Resolving 'localhost'...
2714 Connecting to '127.0.0.1:5556'...
2715 Checking for TLS 1.1 support... yes
2716 Checking fallback from TLS 1.1 to... N/A
2717 Checking for TLS 1.0 support... yes
2718 Checking for SSL 3.0 support... yes
2719 Checking for version rollback bug in RSA PMS... no
2720 Checking for version rollback bug in Client Hello... no
2721 Checking whether we need to disable TLS 1.0... N/A
2722 Checking whether the server ignores the RSA PMS version... no
2723 Checking whether the server can accept Hello Extensions... yes
2724 Checking whether the server can accept cipher suites not in SSL 3.0 spec... yes
2725 Checking whether the server can accept a bogus TLS record version in the client hello... yes
2726 Checking for certificate information... N/A
2727 Checking for trusted CAs... N/A
2728 Checking whether the server understands TLS closure alerts... yes
2729 Checking whether the server supports session resumption... yes
2730 Checking for export-grade ciphersuite support... no
2731 Checking RSA-export ciphersuite info... N/A
2732 Checking for anonymous authentication support... no
2733 Checking anonymous Diffie Hellman group info... N/A
2734 Checking for ephemeral Diffie Hellman support... no
2735 Checking ephemeral Diffie Hellman group info... N/A
2736 Checking for AES cipher support (TLS extension)... yes
2737 Checking for 3DES cipher support... yes
2738 Checking for ARCFOUR 128 cipher support... yes
2739 Checking for ARCFOUR 40 cipher support... no
2740 Checking for MD5 MAC support... yes
2741 Checking for SHA1 MAC support... yes
2742 Checking for ZLIB compression support (TLS extension)... yes
2743 Checking for LZO compression support (GnuTLS extension)... yes
2744 Checking for max record size (TLS extension)... yes
2745 Checking for SRP authentication support (TLS extension)... yes
2746 Checking for OpenPGP authentication support (TLS extension)... no
2747 @end smallexample
2749 @node Invoking gnutls-serv
2750 @section Invoking gnutls-serv
2751 @cindex gnutls-serv
2753 Simple server program that listens to incoming TLS connections.
2755 @verbatim
2756 GNU TLS test server
2757 Usage: gnutls-serv [options]
2759      -d, --debug integer      Enable debugging
2760      -g, --generate           Generate Diffie Hellman Parameters.
2761      -p, --port integer       The port to connect to.
2762      -q, --quiet              Suppress some messages.
2763      --nodb                   Does not use the resume database.
2764      --http                   Act as an HTTP Server.
2765      --echo                   Act as an Echo Server.
2766      --dhparams FILE          DH params file to use.
2767      --x509fmtder             Use DER format for certificates
2768      --x509cafile FILE        Certificate file to use.
2769      --x509crlfile FILE       CRL file to use.
2770      --pgpkeyring FILE        PGP Key ring file to use.
2771      --pgptrustdb FILE        PGP trustdb file to use.
2772      --pgpkeyfile FILE        PGP Key file to use.
2773      --pgpcertfile FILE       PGP Public Key (certificate) file to
2774                               use.
2775      --x509keyfile FILE       X.509 key file to use.
2776      --x509certfile FILE      X.509 Certificate file to use.
2777      --x509dsakeyfile FILE    Alternative X.509 key file to use.
2778      --x509dsacertfile FILE   Alternative X.509 certificate file to
2779                               use.
2780      --srppasswd FILE         SRP password file to use.
2781      --srppasswdconf FILE     SRP password conf file to use.
2782      --ciphers cipher1 cipher2...
2783                               Ciphers to enable.
2784      --protocols protocol1 protocol2...
2785                               Protocols to enable.
2786      --comp comp1 comp2...    Compression methods to enable.
2787      --macs mac1 mac2...      MACs to enable.
2788      --kx kx1 kx2...          Key exchange methods to enable.
2789      --ctypes certType1 certType2...
2790                               Certificate types to enable.
2791      -l, --list               Print a list of the supported
2792                               algorithms  and modes.
2793      -h, --help               prints this help
2794      -v, --version            prints the program's version number
2795      --copyright              prints the program's license
2796 @end verbatim
2798 @subsection Setting Up a Test HTTPS Server
2799 @cindex HTTPS server
2800 @cindex debug server
2802 Running your own TLS server based on GnuTLS can be useful when
2803 debugging clients and/or GnuTLS itself.  This section describes how to
2804 use @code{gnutls-serv} as a simple HTTPS server.
2806 The most basic server can be started as:
2808 @example
2809 gnutls-serv --http
2810 @end example
2812 It will only support anonymous ciphersuites, which many TLS clients
2813 refuse to use.
2815 The next step is to add support for X.509.  First we generate a CA:
2817 @example
2818 certtool --generate-privkey > x509-ca-key.pem
2819 echo 'cn = GnuTLS test CA' > ca.tmpl
2820 echo 'ca' >> ca.tmpl
2821 echo 'cert_signing_key' >> ca.tmpl
2822 certtool --generate-self-signed --load-privkey x509-ca-key.pem \
2823   --template ca.tmpl --outfile x509-ca.pem
2825 @end example
2827 Then generate a server certificate.  Remember to change the dns_name
2828 value to the name of your server host, or skip that command to avoid
2829 the field.
2831 @example
2832 certtool --generate-privkey > x509-server-key.pem
2833 echo 'organization = GnuTLS test server' > server.tmpl
2834 echo 'cn = test.gnutls.org' >> server.tmpl
2835 echo 'tls_www_server' >> server.tmpl
2836 echo 'encryption_key' >> server.tmpl
2837 echo 'signing_key' >> server.tmpl
2838 echo 'dns_name = test.gnutls.org' >> server.tmpl
2839 certtool --generate-certificate --load-privkey x509-server-key.pem \
2840   --load-ca-certificate x509-ca.pem --load-ca-privkey x509-ca-key.pem \
2841   --template server.tmpl --outfile x509-server.pem
2843 @end example
2845 For use in the client, you may want to generate a client certificate
2846 as well.
2848 @example
2849 certtool --generate-privkey > x509-client-key.pem
2850 echo 'cn = GnuTLS test client' > client.tmpl
2851 echo 'tls_www_client' >> client.tmpl
2852 echo 'encryption_key' >> client.tmpl
2853 echo 'signing_key' >> client.tmpl
2854 certtool --generate-certificate --load-privkey x509-client-key.pem \
2855   --load-ca-certificate x509-ca.pem --load-ca-privkey x509-ca-key.pem \
2856   --template client.tmpl --outfile x509-client.pem
2858 @end example
2860 To be able to import the client key/certificate into some
2861 applications, you will need to convert them into a PKCS#12 structure.
2862 This also encrypts the security sensitive key with a password.
2864 @example
2865 certtool --to-p12 --load-privkey x509-client-key.pem --load-certificate x509-client.pem --outder --outfile x509-client.p12
2866 @end example
2868 For icing, we'll create a proxy certificate for the client too.
2870 @example
2871 certtool --generate-privkey > x509-proxy-key.pem
2872 echo 'cn = GnuTLS test client proxy' > proxy.tmpl
2873 certtool --generate-proxy --load-privkey x509-proxy-key.pem \
2874   --load-ca-certificate x509-client.pem --load-ca-privkey x509-client-key.pem \
2875   --load-certificate x509-client.pem --template proxy.tmpl \
2876   --outfile x509-proxy.pem
2878 @end example
2880 Then start the server again:
2882 @example
2883 gnutls-serv --http \
2884             --x509cafile x509-ca.pem \
2885             --x509keyfile x509-server-key.pem \
2886             --x509certfile x509-server.pem
2887 @end example
2889 Try connecting to the server using your web browser.  Note that the
2890 server listens to port 5556 by default.
2892 While you are at it, to allow connections using DSA, you can also
2893 create a DSA key and certificate for the server.  These credentials
2894 will be used in the final example below.
2896 @example
2897 certtool --generate-privkey --dsa > x509-server-key-dsa.pem
2898 certtool --generate-certificate --load-privkey x509-server-key-dsa.pem \
2899   --load-ca-certificate x509-ca.pem --load-ca-privkey x509-ca-key.pem \
2900   --template server.tmpl --outfile x509-server-dsa.pem
2902 @end example
2904 The next step is to create OpenPGP credentials for the server.
2906 @example
2907 gpg --gen-key
2908 ...enter whatever details you want, use 'test.gnutls.org' as name...
2909 @end example
2911 Make a note of the OpenPGP key identifier of the newly generated key,
2912 here it was @code{5D1D14D8}.  You will need to export the key for
2913 GnuTLS to be able to use it.
2915 @example
2916 gpg -a --export 5D1D14D8 > openpgp-server.txt
2917 gpg --export 5D1D14D8 > openpgp-server.bin
2918 gpg --export-secret-keys 5D1D14D8 > openpgp-server-key.bin
2919 gpg -a --export-secret-keys 5D1D14D8 > openpgp-server-key.txt
2920 @end example
2922 Let's start the server with support for OpenPGP credentials:
2924 @example
2925 gnutls-serv --http \
2926             --pgpkeyfile openpgp-server-key.txt \
2927             --pgpcertfile openpgp-server.txt
2928 @end example
2930 The next step is to add support for SRP authentication.
2932 @example
2933 srptool --create-conf srp-tpasswd.conf
2934 srptool --passwd-conf srp-tpasswd.conf --username jas --passwd srp-passwd.txt
2935 Enter password: [TYPE "foo"]
2936 @end example
2938 Start the server with SRP support:
2940 @example
2941 gnutls-serv --http \
2942             --srppasswdconf srp-tpasswd.conf \
2943             --srppasswd srp-passwd.txt
2944 @end example
2946 Let's also add support for PSK.
2948 @example
2949 $ psktool --passwd psk-passwd.txt
2950 @end example
2952 Start the server with PSK support:
2954 @example
2955 gnutls-serv --http \
2956             --pskpasswd psk-passwd.txt
2957 @end example
2959 Finally, we start the server with all the earlier parameters and you
2960 get this command:
2962 @example
2963 gnutls-serv --http \
2964             --x509cafile x509-ca.pem \
2965             --x509keyfile x509-server-key.pem \
2966             --x509certfile x509-server.pem \
2967             --x509dsakeyfile x509-server-key-dsa.pem \
2968             --x509dsacertfile x509-server-dsa.pem \
2969             --pgpkeyfile openpgp-server-key.txt \
2970             --pgpcertfile openpgp-server.txt \
2971             --srppasswdconf srp-tpasswd.conf \
2972             --srppasswd srp-passwd.txt \
2973             --pskpasswd psk-passwd.txt
2974 @end example
2976 @menu
2977 * Example server PSK connection::
2978 @end menu
2980 @node Example server PSK connection
2981 @subsection Example server PSK connection
2982 @cindex PSK server
2984 To set up a PSK server with @code{gnutls-serv} you need to create PSK
2985 password file (@pxref{Invoking psktool}).  In the example below, I
2986 type @code{password} at the prompt.
2988 @smallexample
2989 $ ./psktool -u psk_identity -p psks.txt -n psk_identity_hint
2990 Enter password:
2991 Key stored to psks.txt
2992 $ cat psks.txt
2993 psk_identity:88f3824b3e5659f52d00e959bacab954b6540344
2995 @end smallexample
2997 After this, start the server pointing to the password file.  We
2998 disable DHE-PSK.
3000 @smallexample
3001 $ ./gnutls-serv --pskpasswd psks.txt  --pskhint psk_identity_hint --priority NORMAL:-DHE-PSK
3002 Set static Diffie Hellman parameters, consider --dhparams.
3003 Echo Server ready. Listening to port '5556'.
3004 @end smallexample
3006 You can now connect to the server using a PSK client (@pxref{Example
3007 client PSK connection}).
3009 @node Invoking certtool
3010 @section Invoking certtool
3011 @cindex certtool
3013 This is a program to generate @acronym{X.509} certificates, certificate
3014 requests, CRLs and private keys.
3016 @verbatim
3017 Certtool help
3018 Usage: certtool [options]
3019      -s, --generate-self-signed
3020                               Generate a self-signed certificate.
3021      -c, --generate-certificate
3022                               Generate a signed certificate.
3023      --generate-proxy         Generate a proxy certificate.
3024      --generate-crl           Generate a CRL.
3025      -u, --update-certificate
3026                               Update a signed certificate.
3027      -p, --generate-privkey   Generate a private key.
3028      -q, --generate-request   Generate a PKCS #10 certificate
3029                               request.
3030      -e, --verify-chain       Verify a PEM encoded certificate chain.
3031                               The last certificate in the chain must
3032                               be a self signed one.
3033      --verify-crl             Verify a CRL.
3034      --generate-dh-params     Generate PKCS #3 encoded Diffie Hellman
3035                               parameters.
3036      --get-dh-params          Get the included PKCS #3 encoded Diffie
3037                               Hellman parameters.
3038      --load-privkey FILE      Private key file to use.
3039      --load-request FILE      Certificate request file to use.
3040      --load-certificate FILE
3041                               Certificate file to use.
3042      --load-ca-privkey FILE   Certificate authority's private key
3043                               file to use.
3044      --load-ca-certificate FILE
3045                               Certificate authority's certificate
3046                               file to use.
3047      --password PASSWORD      Password to use.
3048      -i, --certificate-info   Print information on a certificate.
3049      -l, --crl-info           Print information on a CRL.
3050      --p12-info               Print information on a PKCS #12
3051                               structure.
3052      --p7-info                Print information on a PKCS #7
3053                               structure.
3054      --smime-to-p7            Convert S/MIME to PKCS #7 structure.
3055      -k, --key-info           Print information on a private key.
3056      --fix-key                Regenerate the parameters in a private
3057                               key.
3058      --to-p12                 Generate a PKCS #12 structure.
3059      -8, --pkcs8              Use PKCS #8 format for private keys.
3060      --dsa                    Use DSA keys.
3061      --hash STR               Hash algorithm to use for signing
3062                               (MD5,SHA1,RMD160).
3063      --export-ciphers         Use weak encryption algorithms.
3064      --inder                  Use DER format for input certificates
3065                               and private keys.
3066      --outder                 Use DER format for output certificates
3067                               and private keys.
3068      --bits BITS              specify the number of bits for key
3069                               generation.
3070      --outfile FILE           Output file.
3071      --infile FILE            Input file.
3072      --template FILE          Template file to use for non
3073                               interactive operation.
3074      -d, --debug LEVEL        specify the debug level. Default is 1.
3075      -h, --help               shows this help text
3076      -v, --version            shows the program's version
3077      --copyright              shows the program's license
3078 @end verbatim
3080 The program can be used interactively or non interactively by
3081 specifying the @code{--template} command line option. See below for an
3082 example of a template file.
3084 How to use certtool interactively:
3086 @itemize
3087 @item
3088 To generate parameters for Diffie Hellman key exchange, use the command:
3089 @example
3090 $ certtool --generate-dh-params --outfile dh.pem
3091 @end example
3093 @item
3094 To generate parameters for the RSA-EXPORT key exchange, use the command:
3095 @example
3096 $ certtool --generate-privkey --bits 512 --outfile rsa.pem
3097 @end example
3099 @end itemize
3101 @itemize
3103 @item
3104 To create a self signed certificate, use the command:
3105 @example
3106 $ certtool --generate-privkey --outfile ca-key.pem
3107 $ certtool --generate-self-signed --load-privkey ca-key.pem \
3108    --outfile ca-cert.pem
3109 @end example
3111 Note that a self-signed certificate usually belongs to a certificate
3112 authority, that signs other certificates.
3114 @item
3115 To create a private key, run:
3117 @example
3118 $ certtool --generate-privkey --outfile key.pem
3119 @end example
3121 @item
3122 To generate a certificate using the private key, use the command:
3124 @example
3125 $ certtool --generate-certificate --load-privkey key.pem \
3126    --outfile cert.pem --load-ca-certificate ca-cert.pem \
3127    --load-ca-privkey ca-key.pem
3128 @end example
3130 @item
3131 To create a certificate request (needed when the certificate is issued by
3132 another party), run:
3134 @example
3135 $ certtool --generate-request --load-privkey key.pem \
3136   --outfile request.pem
3137 @end example
3139 @item
3140 To generate a certificate using the previous request, use the command:
3142 @example
3143 $ certtool --generate-certificate --load-request request.pem \
3144    --outfile cert.pem \
3145    --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
3146 @end example
3148 @item
3149 To view the certificate information, use:
3151 @example
3152 $ certtool --certificate-info --infile cert.pem
3153 @end example
3155 @item
3156 To generate a @acronym{PKCS} #12 structure using the previous key and
3157 certificate, use the command:
3159 @example
3160 $ certtool --load-certificate cert.pem --load-privkey key.pem \
3161   --to-p12 --outder --outfile key.p12
3162 @end example
3164 @item
3165 Proxy certificate can be used to delegate your credential to a
3166 temporary, typically short-lived, certificate.  To create one from the
3167 previously created certificate, first create a temporary key and then
3168 generate a proxy certificate for it, using the commands:
3170 @example
3171 $ certtool --generate-privkey > proxy-key.pem
3172 $ certtool --generate-proxy --load-ca-privkey key.pem \
3173   --load-privkey proxy-key.pem --load-certificate cert.pem \
3174   --outfile proxy-cert.pem
3175 @end example
3177 @item
3178 To create an empty Certificate Revocation List (CRL) do:
3180 @example
3181 $ certtool --generate-crl --load-ca-privkey x509-ca-key.pem --load-ca-certificate x509-ca.pem
3182 @end example
3184 To create a CRL that contains some revoked certificates, place the
3185 certificates in a file and use @code{--load-certificate} as follows:
3187 @example
3188 $ certtool --generate-crl --load-ca-privkey x509-ca-key.pem --load-ca-certificate x509-ca.pem --load-certificate revoked-certs.pem
3189 @end example
3191 @item
3192 To verify a Certificate Revocation List (CRL) do:
3194 @example
3195 $ certtool --verify-crl --load-ca-certificate x509-ca.pem < crl.pem
3196 @end example
3198 @end itemize
3200 Certtool's template file format:
3202 @itemize
3204 @item
3205 Firstly create a file named 'cert.cfg' that contains the information
3206 about the certificate. An example file is listed below.
3208 @item
3209 Then execute:
3211 @example
3212 $ certtool --generate-certificate cert.pem --load-privkey key.pem  \
3213    --template cert.cfg \
3214    --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
3215 @end example
3217 @end itemize
3219 An example certtool template file:
3221 @example
3222 # X.509 Certificate options
3224 # DN options
3226 # The organization of the subject.
3227 organization = "Koko inc."
3229 # The organizational unit of the subject.
3230 unit = "sleeping dept."
3232 # The locality of the subject.
3233 # locality =
3235 # The state of the certificate owner.
3236 state = "Attiki"
3238 # The country of the subject. Two letter code.
3239 country = GR
3241 # The common name of the certificate owner.
3242 cn = "Cindy Lauper"
3244 # A user id of the certificate owner.
3245 #uid = "clauper"
3247 # If the supported DN OIDs are not adequate you can set
3248 # any OID here.
3249 # For example set the X.520 Title and the X.520 Pseudonym
3250 # by using OID and string pairs.
3251 #dn_oid = "2.5.4.12" "Dr." "2.5.4.65" "jackal"
3253 # This is deprecated and should not be used in new
3254 # certificates.
3255 # pkcs9_email = "none@@none.org"
3257 # The serial number of the certificate
3258 serial = 007
3260 # In how many days, counting from today, this certificate will expire.
3261 expiration_days = 700
3263 # X.509 v3 extensions
3265 # A dnsname in case of a WWW server.
3266 #dns_name = "www.none.org"
3268 # An IP address in case of a server.
3269 #ip_address = "192.168.1.1"
3271 # An email in case of a person
3272 email = "none@@none.org"
3274 # An URL that has CRLs (certificate revocation lists)
3275 # available. Needed in CA certificates.
3276 #crl_dist_points = "http://www.getcrl.crl/getcrl/"
3278 # Whether this is a CA certificate or not
3281 # Whether this certificate will be used for a TLS client
3282 #tls_www_client
3284 # Whether this certificate will be used for a TLS server
3285 #tls_www_server
3287 # Whether this certificate will be used to sign data (needed
3288 # in TLS DHE ciphersuites).
3289 signing_key
3291 # Whether this certificate will be used to encrypt data (needed
3292 # in TLS RSA ciphersuites). Note that it is prefered to use different
3293 # keys for encryption and signing.
3294 #encryption_key
3296 # Whether this key will be used to sign other certificates.
3297 #cert_signing_key
3299 # Whether this key will be used to sign CRLs.
3300 #crl_signing_key
3302 # Whether this key will be used to sign code.
3303 #code_signing_key
3305 # Whether this key will be used to sign OCSP data.
3306 #ocsp_signing_key
3308 # Whether this key will be used for time stamping.
3309 #time_stamping_key
3310 @end example
3312 @node Invoking psktool
3313 @section Invoking psktool
3314 @cindex psktool
3316 This is a program to manage @acronym{PSK} username and keys.
3318 @verbatim
3319 PSKtool help
3320 Usage : psktool [options]
3321      -u, --username username
3322                               specify username.
3323      -p, --passwd FILE        specify a password file.
3324      -n, --netconf-hint HINT
3325                               derive key from Netconf password, using 
3326                               HINT as the psk_identity_hint.
3327      -s, --keysize SIZE       specify the key size in bytes.
3328      -v, --version            prints the program's version number
3329      -h, --help               shows this help text
3330 @end verbatim
3332 Normally the file will generate random keys for the indicate username.
3333 You may also derive PSK keys from passwords, using the algorithm
3334 specified in @file{draft-ietf-netconf-tls-02.txt}.  The algorithm
3335 needs a PSK identity hint, which you specify using
3336 @code{--netconf-hint}.  To derive a PSK key from a password with an
3337 empty PSK identity hint, using @code{--netconf-hint ""}.
3339 @node Function reference
3340 @chapter Function Reference
3341 @cindex Function reference
3343 @menu
3344 * Core functions::
3345 * X.509 certificate functions::
3346 * GnuTLS-extra functions::
3347 * OpenPGP functions::
3348 * TLS Inner Application (TLS/IA) functions::
3349 * Error codes and descriptions::
3350 @end menu
3352 @node Core functions
3353 @section Core Functions
3355 The prototypes for the following functions lie in
3356 @file{gnutls/gnutls.h}.
3358 @include gnutls-api.texi
3360 @node X.509 certificate functions
3361 @section @acronym{X.509} Certificate Functions
3362 @anchor{sec:x509api}
3363 @cindex @acronym{X.509} Functions
3365 The following functions are to be used for @acronym{X.509} certificate handling.
3366 Their prototypes lie in @file{gnutls/x509.h}.
3368 @include x509-api.texi
3370 @node GnuTLS-extra functions
3371 @section @acronym{GnuTLS-extra} Functions
3372 @cindex @acronym{GnuTLS-extra} functions
3374 These functions are only available in the GPL version of the library
3375 called @code{gnutls-extra}. The prototypes for this library lie in
3376 @file{gnutls/extra.h}.
3378 @include gnutls-extra-api.texi
3380 @node OpenPGP functions
3381 @section @acronym{OpenPGP} Functions
3382 @cindex @acronym{OpenPGP} functions
3383 @anchor{sec:openpgpapi}
3385 The following functions are to be used for @acronym{OpenPGP}
3386 certificate handling.  Their prototypes lie in
3387 @file{gnutls/openpgp.h}.  You need to link with @file{libgnutls-extra}
3388 to be able to use these functions (@pxref{GnuTLS-extra functions}).
3390 @include pgp-api.texi
3392 @node TLS Inner Application (TLS/IA) functions
3393 @section @acronym{TLS} Inner Application (@acronym{TLS/IA}) Functions
3394 @cindex @acronym{TLS} Inner Application (@acronym{TLS/IA}) functions
3395 @cindex Inner Application (@acronym{TLS/IA}) functions
3397 The following functions are used for @acronym{TLS} Inner Application
3398 (@acronym{TLS/IA}).  Their prototypes lie in @file{gnutls/extra.h}.
3399 You need to link with @file{libgnutls-extra} to be able to use these
3400 functions (@pxref{GnuTLS-extra functions}).
3402 The typical control flow in an TLS/IA client (that would not require
3403 an Application Phase for resumed sessions) would be similar to the
3404 following:
3406 @example
3407 int client_avp (gnuls_session_t *session, void *ptr,
3408                 const char *last, size_t lastlen,
3409                 char **new, size_t *newlen)
3414 int main ()
3416   gnutls_ia_client_credentials_t iacred;
3418   gnutls_init (&session, GNUTLS_CLIENT);
3420   /* Enable TLS/IA. */
3421   gnutls_ia_allocate_client_credentials(&iacred);
3422   gnutls_ia_set_client_avp_function(iacred, client_avp);
3423   gnutls_credentials_set (session, GNUTLS_CRD_IA, iacred);
3425   ret = gnutls_handshake (session);
3426   // Error handling...
3428   if (gnutls_ia_handshake_p (session))
3429     @{
3430       ret = gnutls_ia_handshake (session);
3431       // Error handling...
3433 @end example
3435 See below for detailed descriptions of all the functions used above.
3437 The function @code{client_avp} would have to be implemented by your
3438 application.  The function is responsible for handling the AVP data.
3439 See @code{gnutls_ia_set_client_avp_function} below for more
3440 information on how that function should be implemented.
3442 The control flow in a typical server is similar to the above, use
3443 @code{gnutls_ia_server_credentials_t} instead of
3444 @code{gnutls_ia_client_credentials_t}, and replace the call to the
3445 client functions with the corresponding server functions.
3447 @include ia-api.texi
3449 @node Error codes and descriptions
3450 @section Error Codes and Descriptions
3451 @anchor{Error Codes}
3452 @cindex Error codes
3454 The error codes used throughout the library are described below.  The
3455 return code @code{GNUTLS_E_SUCCESS} indicate successful operation, and
3456 is guaranteed to have the value 0, so you can use it in logical
3457 expressions.
3459 @include error_codes.texi
3461 @node All the supported ciphersuites in GnuTLS
3462 @chapter All the Supported Ciphersuites in @acronym{GnuTLS}
3463 @anchor{ciphersuites}
3464 @cindex Ciphersuites
3466 @multitable @columnfractions .45 .20 .35
3468 @item @code{TLS_RSA_NULL_MD5} 
3469 @tab 0x00 0x01
3470 @tab RFC 2246
3472 @item @code{TLS_ANON_DH_3DES_EDE_CBC_SHA} 
3473 @tab 0x00 0x1B
3474 @tab RFC 2246
3476 @item @code{TLS_ANON_DH_ARCFOUR_MD5}
3477 @tab 0x00 0x18
3478 @tab RFC 2246
3480 @item @code{TLS_ANON_DH_AES_128_CBC_SHA}
3481 @tab 0x00 0x34
3482 @tab RFC 2246
3484 @item @code{TLS_ANON_DH_AES_256_CBC_SHA}
3485 @tab 0x00 0x3A
3486 @tab RFC 2246
3488 @item @code{TLS_RSA_ARCFOUR_SHA}
3489 @tab 0x00 0x05
3490 @tab  RFC 2246
3492 @item @code{TLS_RSA_ARCFOUR_MD5}
3493 @tab 0x00 0x04
3494 @tab RFC 2246
3496 @item @code{TLS_RSA_3DES_EDE_CBC_SHA}
3497 @tab 0x00 0x0A
3498 @tab RFC 2246
3500 @item @code{TLS_RSA_EXPORT_ARCFOUR_40_MD5}
3501 @tab 0x00 0x03
3502 @tab RFC 2246
3504 @item @code{TLS_DHE_DSS_3DES_EDE_CBC_SHA}
3505 @tab 0x00 0x13
3506 @tab RFC 2246
3508 @item @code{TLS_DHE_RSA_3DES_EDE_CBC_SHA}
3509 @tab 0x00 0x16
3510 @tab RFC 2246
3512 @item @code{TLS_RSA_AES_128_CBC_SHA}
3513 @tab 0x00 0x2F
3514 @tab RFC 3268
3516 @item @code{TLS_RSA_AES_256_CBC_SHA}
3517 @tab 0x00 0x35
3518 @tab RFC 3268
3520 @item @code{TLS_DHE_DSS_AES_256_CBC_SHA}
3521 @tab 0x00 0x38
3522 @tab RFC 3268
3524 @item @code{TLS_DHE_DSS_AES_128_CBC_SHA}
3525 @tab 0x00 0x32
3526 @tab RFC 3268
3528 @item @code{TLS_DHE_RSA_AES_256_CBC_SHA}
3529 @tab 0x00 0x39
3530 @tab RFC 3268
3532 @item @code{TLS_DHE_RSA_AES_128_CBC_SHA}
3533 @tab 0x00 0x33
3534 @tab RFC 3268
3536 @item @code{TLS_SRP_SHA_3DES_EDE_CBC_SHA}
3537 @tab 0x00 0x50
3538 @tab RFC 5054
3540 @item @code{TLS_SRP_SHA_AES_128_CBC_SHA}
3541 @tab 0x00 0x53
3542 @tab RFC 5054
3544 @item @code{TLS_SRP_SHA_AES_256_CBC_SHA}
3545 @tab 0x00 0x56
3546 @tab RFC 5054
3548 @item @code{TLS_SRP_SHA_RSA_3DES_EDE_CBC_SHA}
3549 @tab 0x00 0x51
3550 @tab RFC 5054
3552 @item @code{TLS_SRP_SHA_DSS_3DES_EDE_CBC_SHA}
3553 @tab 0x00 0x52
3554 @tab RFC 5054
3556 @item @code{TLS_SRP_SHA_RSA_AES_128_CBC_SHA}
3557 @tab 0x00 0x54
3558 @tab RFC 5054
3560 @item @code{TLS_SRP_SHA_DSS_AES_128_CBC_SHA}
3561 @tab 0x00 0x55
3562 @tab RFC 5054
3564 @item @code{TLS_SRP_SHA_RSA_AES_256_CBC_SHA}
3565 @tab 0x00 0x57
3566 @tab RFC 5054
3568 @item @code{TLS_SRP_SHA_DSS_AES_256_CBC_SHA}
3569 @tab 0x00 0x58
3570 @tab RFC 5054
3572 @item @code{TLS_DHE_DSS_ARCFOUR_SHA}
3573 @tab 0x00 0x66
3574 @tab draft-ietf-tls-56-bit-ciphersuites
3576 @item @code{TLS_PSK_ARCFOUR_SHA}
3577 @tab 0x00 0x8A
3578 @tab draft-ietf-tls-psk
3580 @item @code{TLS_PSK_3DES_EDE_CBC_SHA}
3581 @tab 0x00 0x8B
3582 @tab draft-ietf-tls-psk
3584 @item @code{TLS_PSK_AES_128_CBC_SHA}
3585 @tab 0x00 0x8C
3586 @tab draft-ietf-tls-psk
3588 @item @code{TLS_PSK_AES_256_CBC_SHA}
3589 @tab 0x00 0x8D
3590 @tab draft-ietf-tls-psk
3592 @end multitable
3595 @c Guile Bindings
3598 @include guile.texi
3600 @node Internal architecture of GnuTLS
3601 @chapter Internal Architecture of GnuTLS
3602 @cindex Internal architecture
3604 This chapter is to give a brief description of the
3605 way @acronym{GnuTLS} works. The focus is to give an idea
3606 to potential developers and those who want to know what
3607 happens inside the black box.
3609 @section The TLS Protocol
3610 The main needs for the TLS protocol to be used are
3611 shown in the image below.
3613 @image{gnutls-client-server-use-case,9cm}
3615 This is being accomplished by the following object diagram.
3616 Note that since @acronym{GnuTLS} is being developed in C
3617 object are just structures with attributes. The operations listed
3618 are functions that require the first parameter to be that object.
3619 @image{gnutls-objects,15cm}
3621 @section TLS Handshake Protocol
3622 The @acronym{GnuTLS} handshake protocol is implemented as a state
3623 machine that waits for input or returns immediately when the non-blocking
3624 transport layer functions are used. The main idea is shown in the following
3625 figure.
3627 @image{gnutls-handshake-state,9cm}
3629 Also the way the input is processed varies per ciphersuite. Several 
3630 implementations of the internal handlers are available and 
3631 @ref{gnutls_handshake} only multiplexes the input to the appropriate 
3632 handler. For example a @acronym{PSK} ciphersuite has a different 
3633 implementation of the @code{process_client_key_exchange} than a
3634 certificate ciphersuite.
3636 @image{gnutls-handshake-sequence,12cm}
3638 @section TLS Authentication Methods
3639 In @acronym{GnuTLS} authentication methods can be implemented quite easily.
3640 Since the required changes to add a new authentication method affect only the
3641 handshake protocol, a simple interface is used. An authentication method needs
3642 only to implement the functions as seen in the figure below.
3644 @image{gnutls-mod_auth_st,12cm}
3646 The functions that need to be implemented are the ones responsible for interpreting
3647 the handshake protocol messages. It is common for such functions to read data from
3648 one or more @code{credentials_t} structures@footnote{such as the @code{gnutls_certificate_credentials_t} structures} and write data, such as certificates, usernames etc. to @code{auth_info_t} structures.
3650 Simple examples of existing authentication methods can be seen in @code{auth_psk.c}
3651 for PSK ciphersuites and @code{auth_srp.c} for SRP ciphersuites. After implementing these functions
3652 the structure holding its pointers has to be registered in @code{gnutls_algorithms.c}
3653 in the @code{_gnutls_kx_algorithms} structure.
3655 @section TLS Extension Handling
3656 As with authentication methods, the TLS extensions handlers can be implemented
3657 using the following interface.
3659 @image{gnutls-extensions_st,12cm}
3661 Here there are two functions, one for receiving the extension data
3662 and one for sending. These functions have to check internally whether
3663 they operate in client or server side. 
3665 A simple example of an extension handler can be seen in @code{ext_srp.c}
3666 After implementing these functions, together with the extension number they
3667 handle, they have to be registered in @code{gnutls_extensions.c} in the 
3668 @code{_gnutls_extensions} structure.
3670 @subsection Adding a New TLS Extension
3672 Adding support for a new TLS extension is done from time to time, and
3673 the process to do so is not difficult.  Here are the steps you need to
3674 follow if you wish to do this yourself.  For sake of discussion, let's
3675 consider adding support for the hypothetical TLS extension
3676 @code{foobar}.
3678 @enumerate
3680 @item Modify @code{configure.in} to add @code{--enable-foobar} or @code{--disable-foobar}.
3682 Which to chose depends on whether you intend to make the extension be
3683 enabled by default.  Look at existing checks (i.e., SRP, authz) for
3684 how to model the code.  For example:
3686 @example
3687 AC_MSG_CHECKING([whether to disable foobar support])
3688 AC_ARG_ENABLE(foobar,
3689         AS_HELP_STRING([--disable-foobar],
3690                 [disable foobar support]),
3691         ac_enable_foobar=no)
3692 if test x$ac_enable_foobar != xno; then
3693  AC_MSG_RESULT(no)
3694  AC_DEFINE(ENABLE_FOOBAR, 1, [enable foobar])
3695 else
3696  ac_full=0
3697  AC_MSG_RESULT(yes)
3699 AM_CONDITIONAL(ENABLE_FOOBAR, test "$ac_enable_foobar" != "no")
3700 @end example
3702 @item Add IANA extension value to @code{extensions_t} in @code{gnutls_int.h}.
3704 A good name for the value would be GNUTLS_EXTENSION_FOOBAR.  Check
3705 with @url{http://www.iana.org/assignments/tls-extensiontype-values}
3706 for allocated values.  For experiments, you could pick a number but
3707 remember that some consider it a bad idea to deploy such modified
3708 version since it will lead to interoperability problems in the future
3709 when the IANA allocates that number to someone else, or when the
3710 foobar protocol is allocated another number.
3712 @item Add an entry to @code{_gnutls_extensions} in @code{gnutls_extensions.c}.
3714 A typical entry would be:
3716 @example
3717 #if ENABLE_FOOBAR
3718   GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_FOOBAR,
3719                           _gnutls_foobar_recv_params,
3720                           _gnutls_foobar_send_params),
3721 #endif
3722 @end example
3724 The GNUTLS_EXTENSION_FOOBAR is the integer value you added to
3725 @code{gnutls_int.h} earlier.  The two functions are new functions that
3726 you will need to implement, most likely you'll need to add an
3727 @code{#include "ext_foobar.h"} as well.
3729 @item Add new files @code{ext_foobar.c} and @code{ext_foobar.h} that implements the extension.
3731 The functions you are responsible to add are those mentioned in the
3732 previous step.  As a starter, you could add this:
3734 @example
3736 _gnutls_foobar_recv_params (gnutls_session_t session,
3737                             const opaque * data,
3738                             size_t data_size)
3740   return 0;
3744 _gnutls_foobar_send_params (gnutls_session_t session,
3745                             opaque * data,
3746                             size_t _data_size)
3748   return 0;
3750 @end example
3752 The @code{_gnutls_foobar_recv_params} function is responsible for
3753 parsing incoming extension data (both in the client and server).
3755 The @code{_gnutls_foobar_send_params} function is responsible for
3756 sending extension data (both in the client and server).
3758 If you receive length fields that doesn't match, return
3759 @code{GNUTLS_E_UNEXPECTED_PACKET_LENGTH}.  If you receive invalid
3760 data, return @code{GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER}.  You can use
3761 other error codes too.  Return 0 on success.
3763 The function typically store some information in the @code{session}
3764 variable for later usage.  If you need to add new fields there, check
3765 @code{tls_ext_st} in @code{gnutls_int.h} and compare with existing TLS
3766 extension specific variables.
3768 Recall that both the client and server both send and receives
3769 parameters, and your code most likely will need to do different things
3770 depending on which mode it is in.  It may be useful to make this
3771 distinction explicit in the code.  Thus, for example, a better
3772 template than above would be:
3774 @example
3776 _gnutls_foobar_recv_params (gnutls_session_t session,
3777                             const opaque * data,
3778                             size_t data_size)
3780   if (session->security_parameters.entity == GNUTLS_CLIENT)
3781     return foobar_recv_client (session, data, data_size);
3782   else
3783     return foobar_recv_server (session, data, data_size);
3787 _gnutls_foobar_send_params (gnutls_session_t session,
3788                             opaque * data,
3789                             size_t data_size)
3791   if (session->security_parameters.entity == GNUTLS_CLIENT)
3792     return foobar_send_client (session, data, data_size);
3793   else
3794     return foobar_send_server (session, data, data_size);
3796 @end example
3798 The functions used would be declared as @code{static} functions, of
3799 the appropriate prototype, in the same file.
3801 When adding the files, you'll need to add them to @code{Makefile.am}
3802 as well, for example:
3804 @example
3805 if ENABLE_FOOBAR
3806 COBJECTS += ext_foobar.c
3807 HFILES += ext_foobar.h
3808 endif
3809 @end example
3811 @item Add API functions to enable/disable the extension.
3813 Normally the client will have one API to request use of the extension,
3814 and setting some extension specific data.  The server will have one
3815 API to let the library know that it is willing to accept the
3816 extension, often this is implemented through a callback but it doesn't
3817 have to.
3819 The APIs need to be added to @code{includes/gnutls/gnutls.h} or
3820 @code{includes/gnutls/extra.h} as appropriate.  It is recommended that
3821 if you don't have a requirement to use the LGPL license for your
3822 extension, that you place your work under the GPL license and thus in
3823 the libgnutls-extra library.
3825 You can implement the API function in the @code{ext_foobar.c} file, or
3826 if that file ends up becoming rather larger, add a
3827 @code{gnutls_foobar.c} file.
3829 @end enumerate
3831 @section Certificate Handling
3832 What is provided by the certificate handling functions
3833 is summarized in the following diagram.
3835 @image{gnutls-certificate-user-use-case,12cm}
3838 @node Copying Information
3839 @appendix Copying Information
3841 @menu
3842 * GNU Free Documentation License::   License for copying this manual.
3843 * GNU LGPL::                     License for copying the core GnuTLS library.
3844 * GNU GPL::                      License for copying GNUTLS extra and tools.
3845 @end menu
3847 @node GNU Free Documentation License
3848 @appendixsec GNU Free Documentation License
3850 @cindex FDL, GNU Free Documentation License
3852 @include fdl.texi
3854 @node GNU LGPL
3855 @appendixsec GNU Lesser General Public License
3856 @cindex LGPL, GNU Lesser General Public License
3857 @cindex License, GNU LGPL
3859 @include lgpl-2.1.texi
3861 @node GNU GPL
3862 @appendixsec GNU General Public License
3863 @cindex GPL, GNU General Public License
3864 @cindex License, GNU GPL
3866 @include gpl-3.0.texi
3868 @node Bibliography
3869 @unnumbered Bibliography
3871 @table @asis
3873 @item @anchor{CBCATT}[CBCATT]
3874 Bodo Moeller, "Security of CBC Ciphersuites in SSL/TLS: Problems and
3875 Countermeasures", 2002, available from
3876 @url{http://www.openssl.org/~bodo/tls-cbc.txt}.
3878 @item @anchor{GPGH}[GPGH]
3879 Mike Ashley, "The GNU Privacy Handbook", 2002, available from
3880 @url{http://www.gnupg.org/gph/en/manual.pdf}.
3882 @item @anchor{GUTPKI}[GUTPKI]
3883 Peter Gutmann, "Everything you never wanted to know about PKI but were
3884 forced to find out", Available from
3885 @url{http://www.cs.auckland.ac.nz/~pgut001/}.
3887 @item @anchor{RFC2246}[RFC2246]
3888 Tim Dierks and Christopher Allen, "The TLS Protocol Version 1.0",
3889 January 1999, Available from
3890 @url{http://www.ietf.org/rfc/rfc2246.txt}.
3892 @item @anchor{RFC4346}[RFC4346]
3893 Tim Dierks and Eric Rescorla, "The TLS Protocol Version 1.1", Match
3894 2006, Available from @url{http://www.ietf.org/rfc/rfc4346.txt}.
3896 @item @anchor{RFC2440}[RFC2440]
3897 Jon Callas, Lutz Donnerhacke, Hal Finney and Rodney Thayer, "OpenPGP
3898 Message Format", November 1998, Available from
3899 @url{http://www.ietf.org/rfc/rfc2440.txt}.
3901 @item @anchor{RFC4880}[RFC4880]
3902 Jon Callas, Lutz Donnerhacke, Hal Finney, David Shaw and Rodney
3903 Thayer, "OpenPGP Message Format", November 2007, Available from
3904 @url{http://www.ietf.org/rfc/rfc4880.txt}.
3906 @item @anchor{RFC4211}[RFC4211]
3907 J. Schaad, "Internet X.509 Public Key Infrastructure Certificate
3908 Request Message Format (CRMF)", September 2005, Available from
3909 @url{http://www.ietf.org/rfc/rfc4211.txt}.
3911 @item @anchor{RFC2817}[RFC2817]
3912 Rohit Khare and Scott Lawrence, "Upgrading to TLS Within HTTP/1.1",
3913 May 2000, Available from @url{http://www.ietf.org/rfc/rfc2817.txt}
3915 @item @anchor{RFC2818}[RFC2818]
3916 Eric Rescorla, "HTTP Over TLS", May 2000, Available from
3917 @url{http://www.ietf/rfc/rfc2818.txt}.
3919 @item @anchor{RFC2945}[RFC2945]
3920 Tom Wu, "The SRP Authentication and Key Exchange System", September
3921 2000, Available from @url{http://www.ietf.org/rfc/rfc2945.txt}.
3923 @item @anchor{RFC2986}[RFC2986]
3924 Magnus Nystrom and Burt Kaliski, "PKCS 10 v1.7: Certification Request
3925 Syntax Specification", November 2000, Available from
3926 @url{http://www.ietf.org/rfc/rfc2986.txt}.
3928 @item @anchor{RFC3280}[RFC3280]
3929 Russell Housley, Tim Polk, Warwick Ford and David Solo, "Internet
3930 X.509 Public Key Infrastructure Certificate and Certificate Revocation
3931 List (CRL) Profile", April 2002, Available from
3932 @url{http://www.ietf.org/rfc/rfc3280.txt}.
3934 @item @anchor{RFC3749}[RFC3749]
3935 Scott Hollenbeck, "Transport Layer Security Protocol Compression
3936 Methods", May 2004, Available from
3937 @url{http://www.ietf.org/rfc/rfc3749.txt}.
3939 @item @anchor{RFC3820}[RFC3820]
3940 Steven Tuecke, Von Welch, Doug Engert, Laura Pearlman, and Mary
3941 Thompson, "Internet X.509 Public Key Infrastructure (PKI) Proxy
3942 Certificate Profile", June 2004, available from
3943 @url{http://www.ietf.org/rfc3820}.
3945 @item @anchor{PKCS12}[PKCS12]
3946 RSA Laboratories, "PKCS 12 v1.0: Personal Information Exchange
3947 Syntax", June 1999, Available from @url{http://www.rsa.com}.
3949 @item @anchor{RESCORLA}[RESCORLA]
3950 Eric Rescorla, "SSL and TLS: Designing and Building Secure Systems",
3951 2001
3953 @item @anchor{SELKEY}[SELKEY]
3954 Arjen Lenstra and Eric Verheul, "Selecting Cryptographic Key Sizes",
3955 2003, available from @url{http://www.win.tue.nl/~klenstra/key.pdf}.
3957 @item @anchor{SSL3}[SSL3]
3958 Alan Freier, Philip Karlton and Paul Kocher, "The SSL Protocol Version
3959 3.0", November 1996, Available from
3960 @url{http://wp.netscape.com/eng/ssl3/draft302.txt}.
3962 @item @anchor{STEVENS}[STEVENS]
3963 Richard Stevens, "UNIX Network Programming, Volume 1", Prentice Hall
3964 PTR, January 1998
3966 @item @anchor{TLSEXT}[TLSEXT]
3967 Simon Blake-Wilson, Magnus Nystrom, David Hopwood, Jan Mikkelsen and
3968 Tim Wright, "Transport Layer Security (TLS) Extensions", June 2003,
3969 Available from @url{http://www.ietf.org/rfc/rfc3546.txt}.
3971 @item @anchor{TLSPGP}[TLSPGP]
3972 Nikos Mavrogiannopoulos, "Using OpenPGP keys for TLS authentication",
3973 April 2004, November 2007. Available from
3974 @url{http://www.ietf.org/rfc/rfc5081.txt}.
3976 @item @anchor{TLSSRP}[TLSSRP]
3977 David Taylor, Trevor Perrin, Tom Wu and Nikos Mavrogiannopoulos,
3978 "Using SRP for TLS Authentication", November 2007. Available from
3979 @url{http://www.ietf.org/rfc/rfc5054.txt}.
3981 @item @anchor{TLSPSK}[TLSPSK]
3982 Pasi Eronen and Hannes Tschofenig, "Pre-shared key Ciphersuites for
3983 TLS", December 2005, Available from
3984 @url{http://www.ietf.org/rfc/rfc4279.txt}.
3986 @item @anchor{TOMSRP}[TOMSRP]
3987 Tom Wu, "The Stanford SRP Authentication Project", Available at
3988 @url{http://srp.stanford.edu/}.
3990 @item @anchor{WEGER}[WEGER]
3991 Arjen Lenstra and Xiaoyun Wang and Benne de Weger, "Colliding X.509
3992 Certificates", Cryptology ePrint Archive, Report 2005/067, Available
3993 at @url{http://eprint.iacr.org/}.
3995 @end table
3997 @node Function and Data Index
3998 @unnumbered Function and Data Index
4000 @printindex fn
4002 @node Concept Index
4003 @unnumbered Concept Index
4005 @printindex cp
4007 @bye