1 This is gnutls.info, produced by makeinfo version 4.13.90 from
4 This manual is last updated 6 January 2012 for version 2.12.20 of
7 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
8 Free Software Foundation, Inc.
10 Permission is granted to copy, distribute and/or modify this
11 document under the terms of the GNU Free Documentation License,
12 Version 1.3 or any later version published by the Free Software
13 Foundation; with no Invariant Sections, no Front-Cover Texts, and
14 no Back-Cover Texts. A copy of the license is included in the
15 section entitled "GNU Free Documentation License".
16 INFO-DIR-SECTION Software libraries
18 * GnuTLS: (gnutls). GNU Transport Layer Security Library.
21 INFO-DIR-SECTION System Administration
23 * certtool: (gnutls)Invoking certtool. Manipulate certificates and keys.
24 * gnutls-serv: (gnutls)Invoking gnutls-serv. GnuTLS test server.
25 * gnutls-cli: (gnutls)Invoking gnutls-cli. GnuTLS test client.
26 * gnutls-cli-debug: (gnutls)Invoking gnutls-cli-debug. GnuTLS debug client.
27 * psktool: (gnutls)Invoking psktool. Simple TLS-Pre-Shared-Keys manager.
28 * srptool: (gnutls)Invoking srptool. Simple SRP password tool.
32 File: gnutls.info, Node: Top, Next: Preface, Up: (dir)
37 This manual is last updated 6 January 2012 for version 2.12.20 of
40 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
41 Free Software Foundation, Inc.
43 Permission is granted to copy, distribute and/or modify this
44 document under the terms of the GNU Free Documentation License,
45 Version 1.3 or any later version published by the Free Software
46 Foundation; with no Invariant Sections, no Front-Cover Texts, and
47 no Back-Cover Texts. A copy of the license is included in the
48 section entitled "GNU Free Documentation License".
54 * Introduction to TLS::
55 * Authentication methods::
56 * More on certificate authentication::
57 * How to use TLS in application protocols::
58 * How to use GnuTLS in applications::
60 * Function reference::
61 * All the supported ciphersuites in GnuTLS::
63 * Internal architecture of GnuTLS::
64 * Copying Information::
66 * Function and Data Index::
70 File: gnutls.info, Node: Preface, Next: The Library, Prev: Top, Up: Top
75 This document tries to demonstrate and explain the GnuTLS library API. A
76 brief introduction to the protocols and the technology involved, is also
77 included so that an application programmer can better understand the
78 GnuTLS purpose and actual offerings. Even if GnuTLS is a typical
79 library software, it operates over several security and cryptographic
80 protocols, which require the programmer to make careful and correct
81 usage of them, otherwise he risks to offer just a false sense of
82 security. Security and the network security terms are very general
83 terms even for computer software thus cannot be easily restricted to a
84 single cryptographic library. For that reason, do not consider a
85 program secure just because it uses GnuTLS; there are several ways to
86 compromise a program or a communication line and GnuTLS only helps with
89 Although this document tries to be self contained, basic network
90 programming and PKI knowlegde is assumed in most of it. A good
91 introduction to networking can be found in [STEVENS] (*note
92 Bibliography::) and for Public Key Infrastructure in [GUTPKI] (*note
95 Updated versions of the GnuTLS software and this document will be
96 available from 'http://www.gnutls.org/' and
97 'http://www.gnu.org/software/gnutls/'.
102 * Commercial Support::
103 * Downloading and Installing::
108 File: gnutls.info, Node: Getting help, Next: Commercial Support, Up: Preface
113 A mailing list where users may help each other exists, and you can reach
114 it by sending e-mail to <help-gnutls@gnu.org>. Archives of the mailing
115 list discussions, and an interface to manage subscriptions, is available
116 through the World Wide Web at
117 'http://lists.gnu.org/mailman/listinfo/help-gnutls'.
119 A mailing list for developers are also available, see
120 'http://www.gnu.org/software/gnutls/lists.html'.
122 Bug reports should be sent to <bug-gnutls@gnu.org>, see *Note Bug
126 File: gnutls.info, Node: Commercial Support, Next: Downloading and Installing, Prev: Getting help, Up: Preface
128 1.2 Commercial Support
129 ======================
131 Commercial support is available for users of GnuTLS. The kind of support
132 that can be purchased may include:
134 * Implement new features. Such as a new TLS extension.
136 * Port GnuTLS to new platforms. This could include porting to an
137 embedded platforms that may need memory or size optimization.
139 * Integrating TLS as a security environment in your existing project.
141 * System design of components related to TLS.
143 If you are interested, please write to:
145 Simon Josefsson Datakonsult
150 E-mail: simon@josefsson.org
152 If your company provides support related to GnuTLS and would like to be
153 mentioned here, contact the author (*note Bug Reports::).
156 File: gnutls.info, Node: Downloading and Installing, Next: Bug Reports, Prev: Commercial Support, Up: Preface
158 1.3 Downloading and Installing
159 ==============================
161 GnuTLS is available for download from the following URL:
163 'http://www.gnutls.org/download.html'
165 The latest version is stored in a file, e.g., 'gnutls-2.12.20.tar.gz'
166 where the '2.12.20' value is the highest version number in the
169 GnuTLS uses a Linux-like development cycle: even minor version numbers
170 indicate a stable release and a odd minor version number indicates a
171 development release. For example, GnuTLS 1.6.3 denote a stable release
172 since 6 is even, and GnuTLS 1.7.11 denote a development release since 7
175 GnuTLS depends on Libgcrypt, and you will need to install Libgcrypt
176 before installing GnuTLS. Libgcrypt is available from
177 'ftp://ftp.gnupg.org/gcrypt/libgcrypt'. Libgcrypt needs another
178 library, libgpg-error, and you need to install libgpg-error before
179 installing Libgcrypt. Libgpg-error is available from
180 'ftp://ftp.gnupg.org/gcrypt/libgpg-error'.
182 Don't forget to verify the cryptographic signature after downloading
183 source code packages.
185 The package is then extracted, configured and built like many other
186 packages that use Autoconf. For detailed information on configuring and
187 building it, refer to the 'INSTALL' file that is part of the
188 distribution archive. Typically you invoke './configure' and then 'make
189 check install'. There are a number of compile-time parameters, as
192 The compression libraries (libz and lzo) are optional dependencies. You
193 can get libz from 'http://www.zlib.net/'. You can get lzo from
194 'http://www.oberhumer.com/opensource/lzo/'.
196 The X.509 part of GnuTLS needs ASN.1 functionality, from a library
197 called libtasn1. A copy of libtasn1 is included in GnuTLS. If you want
198 to install it separately (e.g., to make it possibly to use libtasn1 in
199 other programs), you can get it from
200 'http://www.gnu.org/software/gnutls/download.html'.
202 The OpenPGP part of GnuTLS uses a stripped down version of OpenCDK for
203 parsing OpenPGP packets. It is included GnuTLS. Use parameter
204 '--disable-openpgp-authentication' to disable the OpenPGP functionality
205 in GnuTLS. Unfortunately, we didn't have resources to maintain the code
206 in a separate library.
208 Regarding the Guile bindings, there are additional installation
209 considerations, see *Note Guile Preparations::.
211 A few 'configure' options may be relevant, summarized in the table.
213 '--disable-srp-authentication'
214 '--disable-psk-authentication'
215 '--disable-anon-authentication'
216 '--disable-extra-pki'
217 '--disable-openpgp-authentication'
218 '--disable-openssl-compatibility'
219 Disable or enable particular features. Generally not recommended.
221 For the complete list, refer to the output from 'configure --help'.
224 File: gnutls.info, Node: Bug Reports, Next: Contributing, Prev: Downloading and Installing, Up: Preface
229 If you think you have found a bug in GnuTLS, please investigate it and
232 * Please make sure that the bug is really in GnuTLS, and preferably
233 also check that it hasn't already been fixed in the latest version.
235 * You have to send us a test case that makes it possible for us to
238 * You also have to explain what is wrong; if you get a crash, or if
239 the results printed are not good and in that case, in what way.
240 Make sure that the bug report includes all information you would
241 need to fix this kind of bug for someone else.
243 Please make an effort to produce a self-contained report, with something
244 definite that can be tested or debugged. Vague queries or piecemeal
245 messages are difficult to act on and don't help the development effort.
247 If your bug report is good, we will do our best to help you to get a
248 corrected version of the software; if the bug report is poor, we won't
249 do anything about it (apart from asking you to send better bug reports).
251 If you think something in this manual is unclear, or downright
252 incorrect, or if the language needs to be improved, please also send a
255 Send your bug report to:
260 File: gnutls.info, Node: Contributing, Prev: Bug Reports, Up: Preface
265 If you want to submit a patch for inclusion - from solve a typo you
266 discovered, up to adding support for a new feature - you should submit
267 it as a bug report (*note Bug Reports::). There are some things that
268 you can do to increase the chances for it to be included in the official
271 Unless your patch is very small (say, under 10 lines) we require that
272 you assign the copyright of your work to the Free Software Foundation.
273 This is to protect the freedom of the project. If you have not already
274 signed papers, we will send you the necessary information when you
275 submit your contribution.
277 For contributions that doesn't consist of actual programming code, the
278 only guidelines are common sense. Use it.
280 For code contributions, a number of style guides will help you:
282 * Coding Style. Follow the GNU Standards document.
284 If you normally code using another coding standard, there is no
285 problem, but you should use 'indent' to reformat the code before
286 submitting your work.
288 * Use the unified diff format 'diff -u'.
290 * Return errors. No reason whatsoever should abort the execution of
291 the library. Even memory allocation errors, e.g. when malloc
292 return NULL, should work although result in an error code.
294 * Design with thread safety in mind. Don't use global variables.
295 Don't even write to per-handle global variables unless the
296 documented behaviour of the function you write is to write to the
297 per-handle global variable.
299 * Avoid using the C math library. It causes problems for embedded
300 implementations, and in most situations it is very easy to avoid
303 * Document your functions. Use comments before each function
304 headers, that, if properly formatted, are extracted into Texinfo
305 manuals and GTK-DOC web pages.
307 * Supply a ChangeLog and NEWS entries, where appropriate.
310 File: gnutls.info, Node: The Library, Next: Introduction to TLS, Prev: Preface, Up: Top
315 In brief GnuTLS can be described as a library which offers an API to
316 access secure communication protocols. These protocols provide privacy
317 over insecure lines, and were designed to prevent eavesdropping,
318 tampering, or message forgery.
320 Technically GnuTLS is a portable ANSI C based library which implements
321 the protocols ranging from SSL 3.0 to TLS 1.2 (*Note Introduction to
322 TLS::, for a more detailed description of the protocols), accompanied
323 with the required framework for authentication and public key
324 infrastructure. Important features of the GnuTLS library include:
326 * Support for TLS 1.2, TLS 1.1, TLS 1.0 and SSL 3.0 protocols.
328 * Support for both X.509 and OpenPGP certificates.
330 * Support for handling and verification of certificates.
332 * Support for SRP for TLS authentication.
334 * Support for PSK for TLS authentication.
336 * Support for TLS Extension mechanism.
338 * Support for TLS Compression Methods.
340 Additionally GnuTLS provides a limited emulation API for the widely used
341 OpenSSL(1) library, to ease integration with existing applications.
343 GnuTLS consists of three independent parts, namely the "TLS protocol
344 part", the "Certificate part", and the "Cryptographic backend" part.
345 The 'TLS protocol part' is the actual protocol implementation, and is
346 entirely implemented within the GnuTLS library. The 'Certificate part'
347 consists of the certificate parsing, and verification functions which is
348 partially implemented in the GnuTLS library. The Libtasn1(2), a library
349 which offers ASN.1 parsing capabilities, is used for the X.509
350 certificate parsing functions. A smaller version of OpenCDK(3) is used
351 for the OpenPGP key support in GnuTLS. The "Cryptographic backend" is
352 provided by the Libgcrypt(4) library(5).
354 In order to ease integration in embedded systems, parts of the GnuTLS
355 library can be disabled at compile time. That way a small library, with
356 the required features, can be generated.
363 * Callback functions::
365 ---------- Footnotes ----------
367 (1) 'http://www.openssl.org/'
369 (2) 'ftp://ftp.gnupg.org/gcrypt/alpha/gnutls/libtasn1/'
371 (3) 'ftp://ftp.gnupg.org/gcrypt/alpha/gnutls/opencdk/'
373 (4) 'ftp://ftp.gnupg.org/gcrypt/alpha/libgcrypt/'
375 (5) On current versions of GnuTLS it is possible to override the
376 default crypto backend. Check *note Cryptographic Backend:: for details
379 File: gnutls.info, Node: General Idea, Next: Error handling, Up: The Library
384 A brief description of how GnuTLS works internally is shown at the
385 figure below. This section may be easier to understand after having
386 seen the examples (*note examples::).
388 \0\b[image src="gnutls-internals.png"
\0\b]
390 As shown in the figure, there is a read-only global state that is
391 initialized once by the global initialization function. This global
392 structure, among others, contains the memory allocation functions used,
393 and some structures needed for the ASN.1 parser. This structure is
394 never modified by any GnuTLS function, except for the deinitialization
395 function which frees all memory allocated in the global structure and is
396 called after the program has permanently finished using GnuTLS.
398 The credentials structure is used by some authentication methods, such
399 as certificate authentication (*note Certificate Authentication::). A
400 credentials structure may contain certificates, private keys, temporary
401 parameters for Diffie-Hellman or RSA key exchange, and other stuff that
402 may be shared between several TLS sessions.
404 This structure should be initialized using the appropriate
405 initialization functions. For example an application which uses
406 certificate authentication would probably initialize the credentials,
407 using the appropriate functions, and put its trusted certificates in
408 this structure. The next step is to associate the credentials structure
409 with each TLS session.
411 A GnuTLS session contains all the required stuff for a session to handle
412 one secure connection. This session calls directly to the transport
413 layer functions, in order to communicate with the peer. Every session
414 has a unique session ID shared with the peer.
416 Since TLS sessions can be resumed, servers would probably need a
417 database backend to hold the session's parameters. Every GnuTLS session
418 after a successful handshake calls the appropriate backend function
419 (*Note resume::, for information on initialization) to store the newly
420 negotiated session. The session database is examined by the server just
421 after having received the client hello(1), and if the session ID sent by
422 the client, matches a stored session, the stored session will be
423 retrieved, and the new session will be a resumed one, and will share the
424 same session ID with the previous one.
426 ---------- Footnotes ----------
428 (1) The first message in a TLS handshake
431 File: gnutls.info, Node: Error handling, Next: Memory handling, Prev: General Idea, Up: The Library
436 In GnuTLS most functions return an integer type as a result. In almost
437 all cases a zero or a positive number means success, and a negative
438 number indicates failure, or a situation that some action has to be
439 taken. Thus negative error codes may be fatal or not.
441 Fatal errors terminate the connection immediately and further sends and
442 receives will be disallowed. An example of a fatal error code is
443 'GNUTLS_E_DECRYPTION_FAILED'. Non-fatal errors may warn about
444 something, i.e., a warning alert was received, or indicate the some
445 action has to be taken. This is the case with the error code
446 'GNUTLS_E_REHANDSHAKE' returned by *note gnutls_record_recv::. This
447 error code indicates that the server requests a re-handshake. The
448 client may ignore this request, or may reply with an alert. You can
449 test if an error code is a fatal one by using the *note
450 gnutls_error_is_fatal::.
452 If any non fatal errors, that require an action, are to be returned by a
453 function, these error codes will be documented in the function's
454 reference. *Note Error Codes::, for all the error codes.
457 File: gnutls.info, Node: Memory handling, Next: Callback functions, Prev: Error handling, Up: The Library
462 GnuTLS internally handles heap allocated objects differently, depending
463 on the sensitivity of the data they contain. However for performance
464 reasons, the default memory functions do not overwrite sensitive data
465 from memory, nor protect such objects from being written to the swap.
466 In order to change the default behavior the *note
467 gnutls_global_set_mem_functions:: function is available which can be
468 used to set other memory handlers than the defaults.
470 The Libgcrypt library on which GnuTLS depends, has such secure memory
471 allocation functions available. These should be used in cases where
472 even the system's swap memory is not considered secure. See the
473 documentation of Libgcrypt for more information.
476 File: gnutls.info, Node: Callback functions, Prev: Memory handling, Up: The Library
478 2.4 Callback Functions
479 ======================
481 There are several cases where GnuTLS may need some out of band input
482 from your program. This is now implemented using some callback
483 functions, which your program is expected to register.
485 An example of this type of functions are the push and pull callbacks
486 which are used to specify the functions that will retrieve and send data
487 to the transport layer.
489 * *note gnutls_transport_set_push_function::
491 * *note gnutls_transport_set_pull_function::
493 Other callback functions such as the one set by *note
494 gnutls_srp_set_server_credentials_function::, may require more
495 complicated input, including data to be allocated. These callbacks
496 should allocate and free memory using the functions shown below.
498 * *note gnutls_malloc::
500 * *note gnutls_free::
503 File: gnutls.info, Node: Introduction to TLS, Next: Authentication methods, Prev: The Library, Up: Top
505 3 Introduction to TLS
506 *********************
508 TLS stands for "Transport Layer Security" and is the successor of SSL,
509 the Secure Sockets Layer protocol [SSL3] (*note Bibliography::) designed
510 by Netscape. TLS is an Internet protocol, defined by IETF(1), described
511 in RFC 4346 and also in [RESCORLA] (*note Bibliography::). The protocol
512 provides confidentiality, and authentication layers over any reliable
513 transport layer. The description, below, refers to TLS 1.0 but also
514 applies to TLS 1.1 [RFC4346] (*note Bibliography::) and SSL 3.0, since
515 the differences of these protocols are minor. Older protocols such as
516 SSL 2.0 are not discussed nor implemented in GnuTLS since they are not
517 considered secure today. GnuTLS also supports X.509 and OpenPGP
518 [RFC4880] (*note Bibliography::).
523 * The transport layer::
524 * The TLS record protocol::
525 * The TLS Alert Protocol::
526 * The TLS Handshake Protocol::
528 * Selecting cryptographic key sizes::
529 * On SSL 2 and older protocols::
531 ---------- Footnotes ----------
533 (1) IETF, or Internet Engineering Task Force, is a large open
534 international community of network designers, operators, vendors, and
535 researchers concerned with the evolution of the Internet architecture
536 and the smooth operation of the Internet. It is open to any interested
540 File: gnutls.info, Node: TLS layers, Next: The transport layer, Up: Introduction to TLS
545 TLS is a layered protocol, and consists of the Record Protocol, the
546 Handshake Protocol and the Alert Protocol. The Record Protocol is to
547 serve all other protocols and is above the transport layer. The Record
548 protocol offers symmetric encryption, data authenticity, and optionally
551 The Alert protocol offers some signaling to the other protocols. It can
552 help informing the peer for the cause of failures and other error
553 conditions. *Note The Alert Protocol::, for more information. The
554 alert protocol is above the record protocol.
556 The Handshake protocol is responsible for the security parameters'
557 negotiation, the initial key exchange and authentication. *Note The
558 Handshake Protocol::, for more information about the handshake protocol.
559 The protocol layering in TLS is shown in the figure below.
561 \0\b[image src="gnutls-layers.png"
\0\b]
564 File: gnutls.info, Node: The transport layer, Next: The TLS record protocol, Prev: TLS layers, Up: Introduction to TLS
566 3.2 The Transport Layer
567 =======================
569 TLS is not limited to one transport layer, it can be used above any
570 transport layer, as long as it is a reliable one. A set of functions is
571 provided and their purpose is to load to GnuTLS the required callbacks
572 to access the transport layer.
574 * *note gnutls_transport_set_push_function::
575 * *note gnutls_transport_set_vec_push_function::
576 * *note gnutls_transport_set_pull_function::
577 * *note gnutls_transport_set_ptr::
578 * *note gnutls_transport_set_lowat::
579 * *note gnutls_transport_set_errno::
581 These functions accept a callback function as a parameter. The callback
582 functions should return the number of bytes written, or -1 on error and
583 should set 'errno' appropriately.
585 In some environments, setting 'errno' is unreliable, for example Windows
586 have several errno variables in different CRTs, or it may be that errno
587 is not a thread-local variable. If this is a concern to you, call
588 'gnutls_transport_set_errno' with the intended errno value instead of
589 setting 'errno' directly.
591 GnuTLS currently only interprets the EINTR and EAGAIN errno values and
592 returns the corresponding GnuTLS error codes 'GNUTLS_E_INTERRUPTED' and
593 'GNUTLS_E_AGAIN'. These values are usually returned by interrupted
594 system calls, or when non blocking IO is used. All GnuTLS functions can
595 be resumed (called again), if any of these error codes is returned. The
596 error codes above refer to the system call, not the GnuTLS function,
597 since signals do not interrupt GnuTLS' functions.
599 For non blocking sockets or other custom made pull/push functions the
600 *note gnutls_transport_set_lowat:: must be called, with a zero low water
603 By default, if the transport functions are not set, GnuTLS will use the
604 Berkeley Sockets functions.
607 File: gnutls.info, Node: The TLS record protocol, Next: The TLS Alert Protocol, Prev: The transport layer, Up: Introduction to TLS
609 3.3 The TLS Record Protocol
610 ===========================
612 The Record protocol is the secure communications provider. Its purpose
613 is to encrypt, authenticate and --optionally-- compress packets. The
614 following functions are available:
616 *note gnutls_record_send:::
617 To send a record packet (with application data).
619 *note gnutls_record_recv:::
620 To receive a record packet (with application data).
622 *note gnutls_record_get_direction:::
623 To get the direction of the last interrupted function call.
625 As you may have already noticed, the functions which access the Record
626 protocol, are quite limited, given the importance of this protocol in
627 TLS. This is because the Record protocol's parameters are all set by
628 the Handshake protocol.
630 The Record protocol initially starts with NULL parameters, which means
631 no encryption, and no MAC is used. Encryption and authentication begin
632 just after the handshake protocol has finished.
636 * Encryption algorithms used in the record layer::
637 * Compression algorithms used in the record layer::
638 * Weaknesses and countermeasures::
639 * On Record Padding::
642 File: gnutls.info, Node: Encryption algorithms used in the record layer, Next: Compression algorithms used in the record layer, Up: The TLS record protocol
644 3.3.1 Encryption Algorithms Used in the Record Layer
645 ----------------------------------------------------
647 Confidentiality in the record layer is achieved by using symmetric block
648 encryption algorithms like '3DES', 'AES'(1), or stream algorithms like
649 'ARCFOUR_128'(2). Ciphers are encryption algorithms that use a single,
650 secret, key to encrypt and decrypt data. Block algorithms in TLS also
651 provide protection against statistical analysis of the data. Thus, if
652 you're using the TLS protocol, a random number of blocks will be
653 appended to data, to prevent eavesdroppers from guessing the actual data
656 Supported cipher algorithms:
659 '3DES_CBC' is the DES block cipher algorithm used with triple
660 encryption (EDE). Has 64 bits block size and is used in CBC mode.
663 ARCFOUR is a fast stream cipher.
666 This is the ARCFOUR cipher that is fed with a 40 bit key, which is
670 AES or RIJNDAEL is the block cipher algorithm that replaces the old
671 DES algorithm. Has 128 bits block size and is used in CBC mode.
673 Supported MAC algorithms:
676 MD5 is a cryptographic hash algorithm designed by Ron Rivest.
677 Outputs 128 bits of data.
680 SHA is a cryptographic hash algorithm designed by NSA. Outputs 160
683 ---------- Footnotes ----------
685 (1) AES, or Advanced Encryption Standard, is actually the RIJNDAEL
686 algorithm. This is the algorithm that replaced DES.
688 (2) 'ARCFOUR_128' is a compatible algorithm with RSA's RC4 algorithm,
689 which is considered to be a trade secret.
692 File: gnutls.info, Node: Compression algorithms used in the record layer, Next: Weaknesses and countermeasures, Prev: Encryption algorithms used in the record layer, Up: The TLS record protocol
694 3.3.2 Compression Algorithms Used in the Record Layer
695 -----------------------------------------------------
697 The TLS record layer also supports compression. The algorithms
698 implemented in GnuTLS can be found in the table below. All the
699 algorithms except for DEFLATE which is referenced in [RFC3749] (*note
700 Bibliography::), should be considered as GnuTLS' extensions(1), and
701 should be advertised only when the peer is known to have a compliant
702 client, to avoid interoperability problems.
704 The included algorithms perform really good when text, or other
705 compressible data are to be transfered, but offer nothing on already
706 compressed data, such as compressed images, zipped archives etc. These
707 compression algorithms, may be useful in high bandwidth TLS tunnels, and
708 in cases where network usage has to be minimized. As a drawback,
709 compression increases latency.
711 The record layer compression in GnuTLS is implemented based on the
712 proposal [RFC3749] (*note Bibliography::). The supported compression
716 Zlib compression, using the deflate algorithm.
719 LZO is a very fast compression algorithm. This algorithm is only
720 available if the GnuTLS-extra library has been initialized and the
721 private extensions are enabled, and if GnuTLS was built with LZO
724 ---------- Footnotes ----------
726 (1) You should use *note gnutls_handshake_set_private_extensions:: to
727 enable private extensions.
730 File: gnutls.info, Node: Weaknesses and countermeasures, Next: On Record Padding, Prev: Compression algorithms used in the record layer, Up: The TLS record protocol
732 3.3.3 Weaknesses and Countermeasures
733 ------------------------------------
735 Some weaknesses that may affect the security of the Record layer have
736 been found in TLS 1.0 protocol. These weaknesses can be exploited by
737 active attackers, and exploit the facts that
739 1. TLS has separate alerts for "decryption_failed" and
742 2. The decryption failure reason can be detected by timing the
745 3. The IV for CBC encrypted packets is the last block of the previous
748 Those weaknesses were solved in TLS 1.1 [RFC4346] (*note Bibliography::)
749 which is implemented in GnuTLS. For a detailed discussion see the
750 archives of the TLS Working Group mailing list and the paper [CBCATT]
751 (*note Bibliography::).
754 File: gnutls.info, Node: On Record Padding, Prev: Weaknesses and countermeasures, Up: The TLS record protocol
756 3.3.4 On Record Padding
757 -----------------------
759 The TLS protocol allows for random padding of records, to make it more
760 difficult to perform analysis on the length of exchanged messages (RFC
761 5246 6.2.3.2). GnuTLS appears to be one of few implementation that take
762 advantage of this text, and pad records by a random length.
764 The TLS implementation in the Symbian operating system, frequently used
765 by Nokia and Sony-Ericsson mobile phones, cannot handle non-minimal
766 record padding. What happens when one of these clients handshake with a
767 GnuTLS server is that the client will fail to compute the correct MAC
768 for the record. The client sends a TLS alert ('bad_record_mac') and
769 disconnects. Typically this will result in error messages such as 'A
770 TLS fatal alert has been received', 'Bad record MAC', or both, on the
773 GnuTLS implements a work around for this problem. However, it has to be
774 enabled specifically. It can be enabled by using *note
775 gnutls_record_disable_padding::, or *note gnutls_priority_set:: with the
776 '%COMPAT' priority string.
778 If you implement an application that have a configuration file, we
779 recommend that you make it possible for users or administrators to
780 specify a GnuTLS protocol priority string, which is used by your
781 application via *note gnutls_priority_set::. To allow the best
782 flexibility, make it possible to have a different priority string for
783 different incoming IP addresses.
785 To enable the workaround in the 'gnutls-cli' client or the 'gnutls-serv'
786 server, for testing of other implementations, use the following
787 parameter: '--priority "NORMAL:%COMPAT"'.
790 File: gnutls.info, Node: The TLS Alert Protocol, Next: The TLS Handshake Protocol, Prev: The TLS record protocol, Up: Introduction to TLS
792 3.4 The TLS Alert Protocol
793 ==========================
795 The Alert protocol is there to allow signals to be sent between peers.
796 These signals are mostly used to inform the peer about the cause of a
797 protocol failure. Some of these signals are used internally by the
798 protocol and the application protocol does not have to cope with them
799 (see 'GNUTLS_A_CLOSE_NOTIFY'), and others refer to the application
800 protocol solely (see 'GNUTLS_A_USER_CANCELLED'). An alert signal
801 includes a level indication which may be either fatal or warning. Fatal
802 alerts always terminate the current connection, and prevent future
803 renegotiations using the current session ID.
805 The alert messages are protected by the record protocol, thus the
806 information that is included does not leak. You must take extreme care
807 for the alert information not to leak to a possible attacker, via public
810 *note gnutls_alert_send:::
811 To send an alert signal.
813 *note gnutls_error_to_alert:::
814 To map a gnutls error number to an alert signal.
816 *note gnutls_alert_get:::
817 Returns the last received alert.
819 *note gnutls_alert_get_name:::
820 Returns the name, in a character array, of the given alert.
823 File: gnutls.info, Node: The TLS Handshake Protocol, Next: TLS Extensions, Prev: The TLS Alert Protocol, Up: Introduction to TLS
825 3.5 The TLS Handshake Protocol
826 ==============================
828 The Handshake protocol is responsible for the ciphersuite negotiation,
829 the initial key exchange, and the authentication of the two peers. This
830 is fully controlled by the application layer, thus your program has to
831 set up the required parameters. Available functions to control the
832 handshake protocol include:
834 *note gnutls_priority_init:::
835 To initialize a priority set of ciphers.
837 *note gnutls_priority_deinit:::
838 To deinitialize a priority set of ciphers.
840 *note gnutls_priority_set:::
841 To associate a priority set with a TLS session.
843 *note gnutls_priority_set_direct:::
844 To directly associate a session with a given priority string.
846 *note gnutls_credentials_set:::
847 To set the appropriate credentials structures.
849 *note gnutls_certificate_server_set_request:::
850 To set whether client certificate is required or not.
852 *note gnutls_handshake:::
853 To initiate the handshake.
857 * TLS Cipher Suites:: TLS session parameters.
858 * Priority Strings:: Defining how parameters are negotiated.
859 * Client Authentication:: Requesting a certificate from the client.
860 * Resuming Sessions:: Reusing previously established keys.
861 * Resuming Internals:: More information on reusing previously established keys.
862 * Interoperability:: About interoperability with other implementations.
865 File: gnutls.info, Node: TLS Cipher Suites, Next: Priority Strings, Up: The TLS Handshake Protocol
867 3.5.1 TLS Cipher Suites
868 -----------------------
870 The Handshake Protocol of TLS negotiates cipher suites of the form
871 'TLS_DHE_RSA_WITH_3DES_CBC_SHA'. The usual cipher suites contain these
874 * The key exchange algorithm. 'DHE_RSA' in the example.
876 * The Symmetric encryption algorithm and mode '3DES_CBC' in this
879 * The MAC(1) algorithm used for authentication. 'MAC_SHA' is used in
882 The cipher suite negotiated in the handshake protocol will affect the
883 Record Protocol, by enabling encryption and data authentication. Note
884 that you should not over rely on TLS to negotiate the strongest
885 available cipher suite. Do not enable ciphers and algorithms that you
888 All the supported ciphersuites are shown in *note ciphersuites::.
890 ---------- Footnotes ----------
892 (1) MAC stands for Message Authentication Code. It can be described
893 as a keyed hash algorithm. See RFC2104.
896 File: gnutls.info, Node: Priority Strings, Next: Client Authentication, Prev: TLS Cipher Suites, Up: The TLS Handshake Protocol
898 3.5.2 Priority Strings
899 ----------------------
901 In order to specify cipher suite preferences, the previously shown
902 priority functions accept a string that specifies the algorithms to be
903 enabled in a TLS handshake. That string may contain some high level
907 All the "secure" ciphersuites are enabled, limited to 128 bit
908 ciphers and sorted by terms of speed performance.
911 Means all "secure" ciphersuites. The 256-bit ciphers are included
912 as a fallback only. The ciphers are sorted by security margin.
915 Means all "secure" ciphersuites with ciphers up to 128 bits, sorted
919 Means all "secure" ciphersuites including the 256 bit ciphers,
920 sorted by security margin.
923 Means all ciphersuites are enabled, including the low-security 40
927 Means nothing is enabled. This disables even protocols and
928 compression methods. It should be followed by the algorithms to be
931 or it might contain special keywords, that will be explained later on.
933 Unless the first keyword is "NONE" the defaults (in preference order)
934 are for TLS protocols TLS 1.2, TLS1.1, TLS1.0, SSL3.0; for compression
935 NULL; for certificate types X.509, OpenPGP. For key exchange algorithms
936 when in NORMAL or SECURE levels the perfect forward secrecy algorithms
937 take precedence of the other protocols. In all cases all the supported
938 key exchange algorithms are enabled (except for the RSA-EXPORT which is
939 only enabled in EXPORT level).
941 The NONE keyword is followed by the algorithms to be enabled, and is
942 used to provide the exact list of requested algorithms(1). The order
943 with which every algorithm is specified is significant. Similar
944 algorithms specified before others will take precedence.
946 Keywords prepended to individual algorithms:
949 appended with an algorithm will remove this algorithm.
952 appended with an algorithm will add this algorithm.
954 Individual algorithms:
956 AES-128-CBC, AES-256-CBC, CAMELLIA-128-CBC, CAMELLIA-256-CBC,
957 ARCFOUR-128, 3DES-CBC ARCFOUR-40. Catch all name is CIPHER-ALL
958 which will add all the algorithms from NORMAL priority.
961 RSA, DHE-RSA, DHE-DSS, SRP, SRP-RSA, SRP-DSS, PSK, DHE-PSK,
962 ANON-DH, RSA-EXPORT. The key exchange methods do not have a catch
966 MD5, SHA1, SHA256. All algorithms from NORMAL priority can be
967 accessed with MAC-ALL.
969 Compression algorithms:
970 COMP-NULL, COMP-DEFLATE. Catch all is COMP-ALL.
973 VERS-SSL3.0, VERS-TLS1.0, VERS-TLS1.1, VERS-TLS1.2. Catch all is
976 Signature algorithms:
977 SIGN-RSA-SHA1, SIGN-RSA-SHA224, SIGN-RSA-SHA256, SIGN-RSA-SHA384,
978 SIGN-RSA-SHA512, SIGN-DSA-SHA1, SIGN-DSA-SHA224, SIGN-DSA-SHA256,
979 SIGN-RSA-MD5. Catch all is SIGN-ALL. This is only valid for TLS
985 will enable compatibility mode. It might mean that violations of
986 the protocols are allowed as long as maximum compatibility with
987 problematic clients and servers is achieved.
989 %DISABLE_SAFE_RENEGOTIATION:
990 will disable safe renegotiation completely. Do not use unless you
991 know what you are doing. Testing purposes only.
993 %UNSAFE_RENEGOTIATION:
994 will allow handshakes and rehandshakes without the safe
995 renegotiation extension. Note that for clients this mode is
996 insecure (you may be under attack), and for servers it will allow
997 insecure clients to connect (which could be fooled by an attacker).
998 Do not use unless you know what you are doing and want maximum
1001 %PARTIAL_RENEGOTIATION:
1002 will allow initial handshakes to proceed, but not rehandshakes.
1003 This leaves the client vulnerable to attack, and servers will be
1004 compatible with non-upgraded clients for initial handshakes. This
1005 is currently the default for clients and servers, for compatibility
1008 %SAFE_RENEGOTIATION:
1009 will enforce safe renegotiation. Clients and servers will refuse
1010 to talk to an insecure peer. Currently this causes operability
1011 problems, but is required for full protection.
1013 %SSL3_RECORD_VERSION:
1014 will use SSL3.0 record version in client hello. This is the
1017 %LATEST_RECORD_VERSION:
1018 will use the latest TLS version record version in client hello.
1020 %VERIFY_ALLOW_SIGN_RSA_MD5:
1021 will allow RSA-MD5 signatures in certificate chains.
1023 %VERIFY_ALLOW_X509_V1_CA_CRT:
1024 will allow V1 CAs in chains.
1026 ---------- Footnotes ----------
1028 (1) To avoid collisions in order to specify a compression algorithm
1029 in this string you have to prefix it with "COMP-", protocol versions
1030 with "VERS-", signature algorithms with "SIGN-" and certificate types
1031 with "CTYPE-". All other algorithms don't need a prefix.
1034 File: gnutls.info, Node: Client Authentication, Next: Resuming Sessions, Prev: Priority Strings, Up: The TLS Handshake Protocol
1036 3.5.3 Client Authentication
1037 ---------------------------
1039 In the case of ciphersuites that use certificate authentication, the
1040 authentication of the client is optional in TLS. A server may request a
1041 certificate from the client -- using the *note
1042 gnutls_certificate_server_set_request:: function. If a certificate is
1043 to be requested from the client during the handshake, the server will
1044 send a certificate request message that contains a list of acceptable
1045 certificate signers. In GnuTLS the certificate signers list is
1046 constructed using the trusted Certificate Authorities by the server.
1047 That is the ones set using
1048 * *note gnutls_certificate_set_x509_trust_file::
1049 * *note gnutls_certificate_set_x509_trust_mem::
1051 Sending of the names of the CAs can be controlled using *note
1052 gnutls_certificate_send_x509_rdn_sequence::. The client, then, may send
1053 a certificate, signed by one of the server's acceptable signers.
1056 File: gnutls.info, Node: Resuming Sessions, Next: Resuming Internals, Prev: Client Authentication, Up: The TLS Handshake Protocol
1058 3.5.4 Resuming Sessions
1059 -----------------------
1061 The *note gnutls_handshake:: function, is expensive since a lot of
1062 calculations are performed. In order to support many fast connections
1063 to the same server a client may use session resuming. *Session
1064 resuming* is a feature of the TLS protocol which allows a client to
1065 connect to a server, after a successful handshake, without the expensive
1066 calculations. This is achieved by using the previously established
1067 keys. GnuTLS supports this feature, and the example (*note
1068 ex:resume-client::) illustrates a typical use of it.
1070 Keep in mind that sessions are expired after some time, for security
1071 reasons, thus it may be normal for a server not to resume a session even
1072 if you requested that. Also note that you must enable, using the
1073 priority functions, at least the algorithms used in the last session.
1076 File: gnutls.info, Node: Resuming Internals, Next: Interoperability, Prev: Resuming Sessions, Up: The TLS Handshake Protocol
1078 3.5.5 Resuming Internals
1079 ------------------------
1081 The resuming capability, mostly in the server side, is one of the
1082 problems of a thread-safe TLS implementations. The problem is that all
1083 threads must share information in order to be able to resume sessions.
1084 The gnutls approach is, in case of a client, to leave all the burden of
1085 resuming to the client. I.e., copy and keep the necessary parameters.
1088 * *note gnutls_session_get_data::
1090 * *note gnutls_session_get_id::
1092 * *note gnutls_session_set_data::
1094 The server side is different. A server has to specify some callback
1095 functions which store, retrieve and delete session data. These can be
1098 * *note gnutls_db_set_remove_function::
1100 * *note gnutls_db_set_store_function::
1102 * *note gnutls_db_set_retrieve_function::
1104 * *note gnutls_db_set_ptr::
1106 It might also be useful to be able to check for expired sessions in
1107 order to remove them, and save space. The function *note
1108 gnutls_db_check_entry:: is provided for that reason.
1111 File: gnutls.info, Node: Interoperability, Prev: Resuming Internals, Up: The TLS Handshake Protocol
1113 3.5.6 Interoperability
1114 ----------------------
1116 The TLS handshake is a complex procedure that negotiates all required
1117 parameters for a secure session. GnuTLS supports several TLS
1118 extensions, as well as the latest TLS protocol version 1.2. However few
1119 implementations are not able to properly interoperate once faced with
1120 extensions or version protocols they do not support and understand. The
1121 TLS protocol allows for a graceful downgrade to the commonly supported
1122 options, but practice shows it is not always implemented correctly.
1124 Because there is no way to achieve maximum interoperability with broken
1125 peers without sacrificing security, GnuTLS ignores such peers by
1126 default. This might not be acceptable in cases where maximum
1127 compatibility is required. Thus we allow enabling compatibility with
1128 broken peers using priority strings (see *note Priority Strings::). An
1129 example priority string that is known to provide wide compatibility even
1130 with broken peers is shown below:
1131 NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0:+VERS-SSL3.0:%COMPAT
1132 This priority string will only enable SSL 3.0 and TLS 1.0 as protocols
1133 and will disable, via the '%COMPAT' keyword, several TLS protocol
1134 options that are known to cause compatibility problems. We suggest
1135 however only to use this mode if compatibility issues occur.
1138 File: gnutls.info, Node: TLS Extensions, Next: Selecting cryptographic key sizes, Prev: The TLS Handshake Protocol, Up: Introduction to TLS
1143 A number of extensions to the TLS protocol have been proposed mainly in
1144 [TLSEXT] (*note Bibliography::). The extensions supported in GnuTLS
1147 * Maximum fragment length negotiation
1148 * Server name indication
1150 * Safe Renegotiation
1152 and they will be discussed in the subsections that follow.
1154 3.6.1 Maximum Fragment Length Negotiation
1155 -----------------------------------------
1157 This extension allows a TLS implementation to negotiate a smaller value
1158 for record packet maximum length. This extension may be useful to
1159 clients with constrained capabilities. See the *note
1160 gnutls_record_set_max_size:: and the *note gnutls_record_get_max_size::
1163 3.6.2 Server Name Indication
1164 ----------------------------
1166 A common problem in HTTPS servers is the fact that the TLS protocol is
1167 not aware of the hostname that a client connects to, when the handshake
1168 procedure begins. For that reason the TLS server has no way to know
1169 which certificate to send.
1171 This extension solves that problem within the TLS protocol, and allows a
1172 client to send the HTTP hostname before the handshake begins within the
1173 first handshake packet. The functions *note gnutls_server_name_set::
1174 and *note gnutls_server_name_get:: can be used to enable this extension,
1175 or to retrieve the name sent by a client.
1177 3.6.3 Session Tickets
1178 ---------------------
1180 To resume a TLS session the server normally store some state. This
1181 complicates deployment, and typical situations the client can cache
1182 information and send it to the server instead. The Session Ticket
1183 extension implements this idea, and it is documented in RFC 5077
1184 [TLSTKT] (*note Bibliography::).
1186 Clients can enable support for TLS tickets with *note
1187 gnutls_session_ticket_enable_client:: and servers use *note
1188 gnutls_session_ticket_key_generate:: to generate a key and *note
1189 gnutls_session_ticket_enable_server:: to enable the extension. Clients
1190 resume sessions using the ticket using the normal session resume
1191 functions, *note resume::.
1193 3.6.4 Safe Renegotiation
1194 ------------------------
1196 TLS gives the option to two communicating parties to renegotiate and
1197 update their security parameters. One useful example of this feature
1198 was for a client to initially connect using anonymous negotiation to a
1199 server, and the renegotiate using some authenticated ciphersuite. This
1200 occured to avoid having the client sending its credentials in the clear.
1202 However this renegotiation, as initially designed would not ensure that
1203 the party one is renegotiating is the same as the one in the initial
1204 negotiation. For example one server could forward all renegotiation
1205 traffic to an other server who will see this traffic as an initial
1206 negotiation attempt.
1208 This might be seen as a valid design decision, but it seems it was not
1209 widely known or understood, thus today some application protocols the
1210 TLS renegotiation feature in a manner that enables a malicious server to
1211 insert content of his choice in the beginning of a TLS session.
1213 The most prominent vulnerability was with HTTPS. There servers request a
1214 renegotiation to enforce an anonymous user to use a certificate in order
1215 to access certain parts of a web site. The attack works by having the
1216 attacker simulate a client and connect to a server, with server-only
1217 authentication, and send some data intended to cause harm. The server
1218 will then require renegotiation from him in order to perform the
1219 request. When the proper client attempts to contact the server, the
1220 attacker hijacks that connection and forwards traffic to the initial
1221 server that requested renegotiation. The attacker will not be able to
1222 read the data exchanged between the client and the server. However, the
1223 server will (incorrectly) assume that the initial request sent by the
1224 attacker was sent by the now authenticated client. The result is a
1225 prefix plain-text injection attack.
1227 The above is just one example. Other vulnerabilities exists that do not
1228 rely on the TLS renegotiation to change the client's authenticated
1229 status (either TLS or application layer).
1231 While fixing these application protocols and implementations would be
1232 one natural reaction, an extension to TLS has been designed that
1233 cryptographically binds together any renegotiated handshakes with the
1234 initial negotiation. When the extension is used, the attack is detected
1235 and the session can be terminated. The extension is specified in
1236 [RFC5746] (*note Bibliography::).
1238 GnuTLS supports the safe renegotiation extension. The default behavior
1239 is as follows. Clients will attempt to negotiate the safe renegotiation
1240 extension when talking to servers. Servers will accept the extension
1241 when presented by clients. Clients and servers will permit an initial
1242 handshake to complete even when the other side does not support the safe
1243 renegotiation extension. Clients and servers will refuse renegotiation
1244 attempts when the extension has not been negotiated.
1246 Note that permitting clients to connect to servers when the safe
1247 renegotiation extension is not enabled, is open up for attacks.
1248 Changing this default behaviour would prevent interoperability against
1249 the majority of deployed servers out there. We will reconsider this
1250 default behaviour in the future when more servers have been upgraded.
1251 Note that it is easy to configure clients to always require the safe
1252 renegotiation extension from servers (see below on the
1253 '%SAFE_RENEGOTIATION' priority string).
1255 To modify the default behaviour, we have introduced some new priority
1256 strings. The priority strings can be used by applications (*note
1257 gnutls_priority_set::) and end users (e.g., '--priority' parameter to
1258 'gnutls-cli' and 'gnutls-serv').
1260 The '%UNSAFE_RENEGOTIATION' priority string permits (re-)handshakes even
1261 when the safe renegotiation extension was not negotiated. The default
1262 behavior is '%PARTIAL_RENEGOTIATION' that will prevent renegotiation
1263 with clients and servers not supporting the extension. This is secure
1264 for servers but leaves clients vulnerable to some attacks, but this is a
1265 tradeoff between security and compatibility with old servers. The
1266 '%SAFE_RENEGOTIATION' priority string makes clients and servers require
1267 the extension for every handshake. The latter is the most secure option
1268 for clients, at the cost of not being able to connect to legacy servers.
1269 Servers will also deny clients that do not support the extension from
1272 It is possible to disable use of the extension completely, in both
1273 clients and servers, by using the '%DISABLE_SAFE_RENEGOTIATION' priority
1274 string however we strongly recommend you to only do this for debugging
1277 The default values if the flags above are not specified are:
1280 %PARTIAL_RENEGOTIATION
1283 %PARTIAL_RENEGOTIATION
1285 For applications we have introduced a new API related to safe
1286 renegotiation. The *note gnutls_safe_renegotiation_status:: function is
1287 used to check if the extension has been negotiated on a session, and can
1288 be used both by clients and servers.
1291 File: gnutls.info, Node: Selecting cryptographic key sizes, Next: On SSL 2 and older protocols, Prev: TLS Extensions, Up: Introduction to TLS
1293 3.7 Selecting Cryptographic Key Sizes
1294 =====================================
1296 In TLS, since a lot of algorithms are involved, it is not easy to set a
1297 consistent security level. For this reason this section will present
1298 some correspondance between key sizes of symmetric algorithms and public
1299 key algorithms based on the "ECRYPT II Yearly Report on Algorithms and
1300 Keysizes (2009-2010)" in [ECRYPT] (*note Bibliography::). Those can be
1301 used to generate certificates with appropriate key sizes as well as
1302 parameters for Diffie-Hellman and SRP authentication.
1304 SecurityRSA, DH ECC 'gnutls_sec_param_t'Description
1308 64 816 128 'WEAK' Very short term
1312 80 1248 160 'LOW' Very short term
1316 112 2432 224 'NORMAL' Medium-term protection
1318 128 3248 256 'HIGH' Long term protection
1320 256 15424 512 'ULTRA' Foreseeable future
1323 The first column provides a security parameter in a number of bits.
1324 This gives an indication of the number of combinations to be tried by an
1325 adversary to brute force a key. For example to test all possible keys
1326 in a 112 bit security parameter 2^{112} combinations have to be tried.
1327 For today's technology this is infeasible. The next two columns
1328 correlate the security parameter with actual bit sizes of parameters for
1329 DH, RSA, SRP and ECC algorithms. A mapping to 'gnutls_sec_param_t'
1330 value is given for each security parameter, on the next column, and
1331 finally a brief description of the level.
1333 Note however that the values suggested here are nothing more than an
1334 educated guess that is valid today. There are no guarrantees that an
1335 algorithm will remain unbreakable or that these values will remain
1336 constant in time. There could be scientific breakthroughs that cannot
1337 be predicted or total failure of the current public key systems by
1338 quantum computers. On the other hand though the cryptosystems used in
1339 TLS are selected in a conservative way and such catastrophic
1340 breakthroughs or failures are believed to be unlikely.
1342 NIST publication SP 800-57 [NISTSP80057] (*note Bibliography::) contains
1345 When using GnuTLS and a decision on bit sizes for a public key algorithm
1346 is required, use of the following functions is recommended:
1348 * *note gnutls_pk_bits_to_sec_param::
1350 * *note gnutls_sec_param_to_pk_bits::
1352 Those functions will convert a human understandable security parameter
1353 of 'gnutls_sec_param_t' type, to a number of bits suitable for a public
1357 File: gnutls.info, Node: On SSL 2 and older protocols, Prev: Selecting cryptographic key sizes, Up: Introduction to TLS
1359 3.8 On SSL 2 and Older Protocols
1360 ================================
1362 One of the initial decisions in the GnuTLS development was to implement
1363 the known security protocols for the transport layer. Initially TLS 1.0
1364 was implemented since it was the latest at that time, and was considered
1365 to be the most advanced in security properties. Later the SSL 3.0
1366 protocol was implemented since it is still the only protocol supported
1367 by several servers and there are no serious security vulnerabilities
1370 One question that may arise is why we didn't implement SSL 2.0 in the
1371 library. There are several reasons, most important being that it has
1372 serious security flaws, unacceptable for a modern security library.
1373 Other than that, this protocol is barely used by anyone these days since
1374 it has been deprecated since 1996. The security problems in SSL 2.0
1377 * Message integrity compromised. The SSLv2 message authentication
1378 uses the MD5 function, and is insecure.
1380 * Man-in-the-middle attack. There is no protection of the handshake
1381 in SSLv2, which permits a man-in-the-middle attack.
1383 * Truncation attack. SSLv2 relies on TCP FIN to close the session,
1384 so the attacker can forge a TCP FIN, and the peer cannot tell if it
1385 was a legitimate end of data or not.
1387 * Weak message integrity for export ciphers. The cryptographic keys
1388 in SSLv2 are used for both message authentication and encryption,
1389 so if weak encryption schemes are negotiated (say 40-bit keys) the
1390 message authentication code use the same weak key, which isn't
1393 Other protocols such as Microsoft's PCT 1 and PCT 2 were not implemented
1394 because they were also abandoned and deprecated by SSL 3.0 and later TLS
1398 File: gnutls.info, Node: Authentication methods, Next: More on certificate authentication, Prev: Introduction to TLS, Up: Top
1400 4 Authentication Methods
1401 ************************
1403 The TLS protocol provides confidentiality and encryption, but also
1404 offers authentication, which is a prerequisite for a secure connection.
1405 The available authentication methods in GnuTLS are:
1407 * Certificate authentication
1409 * Anonymous authentication
1411 * SRP authentication
1413 * PSK authentication
1417 * Certificate authentication::
1418 * Anonymous authentication::
1419 * Authentication using SRP::
1420 * Authentication using PSK::
1421 * Authentication and credentials::
1422 * Parameters stored in credentials::
1425 File: gnutls.info, Node: Certificate authentication, Next: Anonymous authentication, Up: Authentication methods
1427 4.1 Certificate Authentication
1428 ==============================
1430 4.1.1 Authentication Using X.509 Certificates
1431 ---------------------------------------------
1433 X.509 certificates contain the public parameters, of a public key
1434 algorithm, and an authority's signature, which proves the authenticity
1435 of the parameters. *Note The X.509 trust model::, for more information
1438 4.1.2 Authentication Using OpenPGP Keys
1439 ---------------------------------------
1441 OpenPGP keys also contain public parameters of a public key algorithm,
1442 and signatures from several other parties. Depending on whether a
1443 signer is trusted the key is considered trusted or not. GnuTLS's
1444 OpenPGP authentication implementation is based on the [TLSPGP] (*note
1445 Bibliography::) proposal.
1447 *Note The OpenPGP trust model::, for more information about the OpenPGP
1448 trust model. For a more detailed introduction to OpenPGP and GnuPG see
1449 [GPGH] (*note Bibliography::).
1451 4.1.3 Using Certificate Authentication
1452 --------------------------------------
1454 In GnuTLS both the OpenPGP and X.509 certificates are part of the
1455 certificate authentication and thus are handled using a common API.
1457 When using certificates the server is required to have at least one
1458 certificate and private key pair. A client may or may not have such a
1459 pair. The certificate and key pair should be loaded, before any TLS
1460 session is initialized, in a certificate credentials structure. This
1461 should be done by using *note gnutls_certificate_set_x509_key_file:: or
1462 *note gnutls_certificate_set_openpgp_key_file:: depending on the
1463 certificate type. In the X.509 case, the functions will also accept and
1464 use a certificate list that leads to a trusted authority. The
1465 certificate list must be ordered in such way that every certificate
1466 certifies the one before it. The trusted authority's certificate need
1467 not to be included, since the peer should possess it already.
1469 As an alternative, a callback may be used so the server or the client
1470 specify the certificate and the key at the handshake time. That
1471 callback can be set using the functions:
1473 * *note gnutls_certificate_server_set_retrieve_function::
1475 * *note gnutls_certificate_client_set_retrieve_function::
1477 Clients and servers that will select certificates using callback
1478 functions should select a certificate according the peer's signature
1479 algorithm preferences. To get those preferences use *note
1480 gnutls_sign_algorithm_get_requested::.
1482 Certificate verification is possible by loading the trusted authorities
1483 into the credentials structure by using *note
1484 gnutls_certificate_set_x509_trust_file:: or *note
1485 gnutls_certificate_set_openpgp_keyring_file:: for openpgp keys. Note
1486 however that the peer's certificate is not automatically verified, you
1487 should call *note gnutls_certificate_verify_peers2::, after a successful
1488 handshake, to verify the signatures of the certificate. An alternative
1489 way, which reports a more detailed verification output, is to use *note
1490 gnutls_certificate_get_peers:: to obtain the raw certificate of the peer
1491 and verify it using the functions discussed in *note The X.509 trust
1494 In a handshake, the negotiated cipher suite depends on the certificate's
1495 parameters, so not all key exchange methods will be available with some
1496 certificates. GnuTLS will disable ciphersuites that are not compatible
1497 with the key, or the enabled authentication methods. For example keys
1498 marked as sign-only, will not be able to access the plain RSA
1499 ciphersuites, but only the 'DHE_RSA' ones. It is recommended not to use
1500 RSA keys for both signing and encryption. If possible use the same key
1501 for the 'DHE_RSA' and 'RSA_EXPORT' ciphersuites, which use signing, and
1502 a different key for the plain RSA ciphersuites, which use encryption.
1503 All the key exchange methods shown below are available in certificate
1506 Note that the DHE key exchange methods are generally slower(1) than
1507 plain RSA and require Diffie Hellman parameters to be generated and
1508 associated with a credentials structure, by the server. The
1509 'RSA-EXPORT' method also requires 512 bit RSA parameters, that should
1510 also be generated and associated with the credentials structure. See
1513 * *note gnutls_dh_params_generate2::
1515 * *note gnutls_certificate_set_dh_params::
1517 * *note gnutls_rsa_params_generate2::
1519 * *note gnutls_certificate_set_rsa_export_params::
1521 Sometimes in order to avoid bottlenecks in programs it is useful to
1522 store and read parameters from formats that can be generated by external
1523 programs such as 'certtool'. This is possible with GnuTLS by using the
1524 following functions:
1526 * *note gnutls_dh_params_import_pkcs3::
1528 * *note gnutls_rsa_params_import_pkcs1::
1530 * *note gnutls_dh_params_export_pkcs3::
1532 * *note gnutls_rsa_params_export_pkcs1::
1534 Key exchange algorithms for OpenPGP and X.509 certificates:
1537 The RSA algorithm is used to encrypt a key and send it to the peer.
1538 The certificate must allow the key to be used for encryption.
1541 The RSA algorithm is used to encrypt a key and send it to the peer.
1542 In the EXPORT algorithm, the server signs temporary RSA parameters
1543 of 512 bits -- which are considered weak -- and sends them to the
1547 The RSA algorithm is used to sign Ephemeral Diffie-Hellman
1548 parameters which are sent to the peer. The key in the certificate
1549 must allow the key to be used for signing. Note that key exchange
1550 algorithms which use Ephemeral Diffie-Hellman parameters, offer
1551 perfect forward secrecy. That means that even if the private key
1552 used for signing is compromised, it cannot be used to reveal past
1556 The DSS algorithm is used to sign Ephemeral Diffie-Hellman
1557 parameters which are sent to the peer. The certificate must
1558 contain DSA parameters to use this key exchange algorithm. DSS
1559 stands for Digital Signature Standard.
1561 ---------- Footnotes ----------
1563 (1) It really depends on the group used. Primes with lesser bits are
1564 always faster, but also easier to break. Values less than 768 should
1568 File: gnutls.info, Node: Anonymous authentication, Next: Authentication using SRP, Prev: Certificate authentication, Up: Authentication methods
1570 4.2 Anonymous Authentication
1571 ============================
1573 The anonymous key exchange performs encryption but there is no
1574 indication of the identity of the peer. This kind of authentication is
1575 vulnerable to a man in the middle attack, but this protocol can be used
1576 even if there is no prior communication and trusted parties with the
1577 peer, or when full anonymity is required. Unless really required, do
1578 not use anonymous authentication. Available key exchange methods are
1581 Note that the key exchange methods for anonymous authentication require
1582 Diffie-Hellman parameters to be generated by the server and associated
1583 with an anonymous credentials structure.
1585 Supported anonymous key exchange algorithms:
1588 This algorithm exchanges Diffie-Hellman parameters.
1591 File: gnutls.info, Node: Authentication using SRP, Next: Authentication using PSK, Prev: Anonymous authentication, Up: Authentication methods
1593 4.3 Authentication using SRP
1594 ============================
1596 Authentication via the Secure Remote Password protocol, SRP(1), is
1597 supported. The SRP key exchange is an extension to the TLS protocol,
1598 and it is a password based authentication (unlike X.509 or OpenPGP that
1599 use certificates). The two peers can be identified using a single
1600 password, or there can be combinations where the client is authenticated
1601 using SRP and the server using a certificate.
1603 The advantage of SRP authentication, over other proposed secure password
1604 authentication schemes, is that SRP does not require the server to hold
1605 the user's password. This kind of protection is similar to the one used
1606 traditionally in the _UNIX_ '/etc/passwd' file, where the contents of
1607 this file did not cause harm to the system security if they were
1608 revealed. The SRP needs instead of the plain password something called
1609 a verifier, which is calculated using the user's password, and if stolen
1610 cannot be used to impersonate the user. Check [TOMSRP] (*note
1611 Bibliography::) for a detailed description of the SRP protocol and the
1612 Stanford SRP libraries, which includes a PAM module that synchronizes
1613 the system's users passwords with the SRP password files. That way SRP
1614 authentication could be used for all the system's users.
1616 The implementation in GnuTLS is based on paper [TLSSRP] (*note
1617 Bibliography::). The supported SRP key exchange methods are:
1620 Authentication using the SRP protocol.
1623 Client authentication using the SRP protocol. Server is
1624 authenticated using a certificate with DSA parameters.
1627 Client authentication using the SRP protocol. Server is
1628 authenticated using a certificate with RSA parameters.
1630 If clients supporting SRP know the username and password before the
1631 connection, should initialize the client credentials and call the
1632 function *note gnutls_srp_set_client_credentials::. Alternatively they
1633 could specify a callback function by using the function *note
1634 gnutls_srp_set_client_credentials_function::. This has the advantage
1635 that allows probing the server for SRP support. In that case the
1636 callback function will be called twice per handshake. The first time is
1637 before the ciphersuite is negotiated, and if the callback returns a
1638 negative error code, the callback will be called again if SRP has been
1639 negotiated. This uses a special TLS-SRP handshake idiom in order to
1640 avoid, in interactive applications, to ask the user for SRP password and
1641 username if the server does not negotiate an SRP ciphersuite.
1643 In server side the default behaviour of GnuTLS is to read the usernames
1644 and SRP verifiers from password files. These password files are the
1645 ones used by the _Stanford srp libraries_ and can be specified using the
1646 *note gnutls_srp_set_server_credentials_file::. If a different password
1647 file format is to be used, then the function *note
1648 gnutls_srp_set_server_credentials_function::, should be called, in order
1649 to set an appropriate callback.
1651 Some helper functions such as
1653 * *note gnutls_srp_verifier::
1655 * *note gnutls_srp_base64_encode::
1657 * *note gnutls_srp_base64_decode::
1659 are included in GnuTLS, and can be used to generate and maintain SRP
1660 verifiers and password files. A program to manipulate the required
1661 parameters for SRP authentication is also included. *Note srptool::,
1662 for more information.
1664 ---------- Footnotes ----------
1666 (1) SRP is described in [RFC2945] (*note Bibliography::)
1669 File: gnutls.info, Node: Authentication using PSK, Next: Authentication and credentials, Prev: Authentication using SRP, Up: Authentication methods
1671 4.4 Authentication using PSK
1672 ============================
1674 Authentication using Pre-shared keys is a method to authenticate using
1675 usernames and binary keys. This protocol avoids making use of public
1676 key infrastructure and expensive calculations, thus it is suitable for
1679 The implementation in GnuTLS is based on paper [TLSPSK] (*note
1680 Bibliography::). The supported PSK key exchange methods are:
1683 Authentication using the PSK protocol.
1686 Authentication using the PSK protocol and Diffie-Hellman key
1687 exchange. This method offers perfect forward secrecy.
1689 Clients supporting PSK should supply the username and key before the
1690 connection to the client credentials by calling the function *note
1691 gnutls_psk_set_client_credentials::. Alternatively they could specify a
1692 callback function by using the function *note
1693 gnutls_psk_set_client_credentials_function::. This has the advantage
1694 that the callback will be called only if PSK has been negotiated.
1696 In server side the default behaviour of GnuTLS is to read the usernames
1697 and PSK keys from a password file. The password file should contain
1698 usernames and keys in hexadecimal format. The name of the password file
1699 can be stored to the credentials structure by calling *note
1700 gnutls_psk_set_server_credentials_file::. If a different password file
1701 format is to be used, then the function *note
1702 gnutls_psk_set_server_credentials_function::, should be used instead.
1704 The server can help the client chose a suitable username and password,
1705 by sending a hint. In the server, specify the hint by calling *note
1706 gnutls_psk_set_server_credentials_hint::. The client can retrieve the
1707 hint, for example in the callback function, using *note
1708 gnutls_psk_client_get_hint::.
1710 There is no mechanism to derive a PSK key from a password specified by
1711 the TLS PSK document(1). For password-based authentication check *note
1712 Authentication using SRP::.
1714 Some helper functions such as:
1716 * *note gnutls_hex_encode::
1718 * *note gnutls_hex_decode::
1720 are included in GnuTLS, and may be used to generate and maintain PSK
1723 ---------- Footnotes ----------
1725 (1) GnuTLS used to provide 'gnutls_psk_netconf_derive_key' which
1726 follows the algorithm specified in 'draft-ietf-netconf-tls-02.txt'.
1727 This method is deprecated and might be removed in later versions of
1731 File: gnutls.info, Node: Authentication and credentials, Next: Parameters stored in credentials, Prev: Authentication using PSK, Up: Authentication methods
1733 4.5 Authentication and Credentials
1734 ==================================
1736 In GnuTLS every key exchange method is associated with a credentials
1737 type. So in order to enable to enable a specific method, the
1738 corresponding credentials type should be initialized and set using *note
1739 gnutls_credentials_set::. A mapping is shown below.
1741 Key exchange algorithms and the corresponding credential types:
1743 Key exchange Client credentials Server credentials
1745 ---------------------------------------------------------------------
1749 'KX_RSA_EXPORT' 'CRD_CERTIFICATE' 'CRD_CERTIFICATE'
1751 'KX_SRP_RSA' 'CRD_SRP' 'CRD_SRP'
1752 'KX_SRP_DSS' 'CRD_CERTIFICATE'
1754 'KX_SRP' 'CRD_SRP' 'CRD_SRP'
1756 'KX_ANON_DH' 'CRD_ANON' 'CRD_ANON'
1758 'KX_PSK' 'CRD_PSK' 'CRD_PSK'
1762 File: gnutls.info, Node: Parameters stored in credentials, Prev: Authentication and credentials, Up: Authentication methods
1764 4.6 Parameters Stored in Credentials
1765 ====================================
1767 Several parameters such as the ones used for Diffie-Hellman
1768 authentication are stored within the credentials structures, so all
1769 sessions can access them. Those parameters are stored in structures
1770 such as 'gnutls_dh_params_t' and 'gnutls_rsa_params_t', and functions
1771 like *note gnutls_certificate_set_dh_params:: and *note
1772 gnutls_certificate_set_rsa_export_params:: can be used to associate
1773 those parameters with the given credentials structure.
1775 Since those parameters need to be renewed from time to time and a global
1776 structure such as the credentials, may not be easy to modify since it is
1777 accessible by all sessions, an alternative interface is available using
1778 a callback function. This can be set using the *note
1779 gnutls_certificate_set_params_function::. An example is shown below.
1783 gnutls_rsa_params_t rsa_params;
1784 gnutls_dh_params_t dh_params;
1786 /* This function will be called once a session requests DH
1787 * or RSA parameters. The parameters returned (if any) will
1788 * be used for the first handshake only.
1790 static int get_params( gnutls_session_t session,
1791 gnutls_params_type_t type,
1792 gnutls_params_st *st)
1794 if (type == GNUTLS_PARAMS_RSA_EXPORT)
1795 st->params.rsa_export = rsa_params;
1796 else if (type == GNUTLS_PARAMS_DH)
1797 st->params.dh = dh_params;
1801 /* do not deinitialize those parameters.
1810 gnutls_certificate_credentials_t cert_cred;
1812 initialize_params();
1817 gnutls_certificate_set_params_function( cert_cred, get_params);
1821 File: gnutls.info, Node: More on certificate authentication, Next: How to use TLS in application protocols, Prev: Authentication methods, Up: Top
1823 5 More on Certificate Authentication
1824 ************************************
1828 * The X.509 trust model::
1829 * The OpenPGP trust model::
1831 * Abstract data types::
1832 * Digital signatures::
1835 File: gnutls.info, Node: The X.509 trust model, Next: The OpenPGP trust model, Up: More on certificate authentication
1837 5.1 The X.509 Trust Model
1838 =========================
1840 The X.509 protocols rely on a hierarchical trust model. In this trust
1841 model Certification Authorities (CAs) are used to certify entities.
1842 Usually more than one certification authorities exist, and certification
1843 authorities may certify other authorities to issue certificates as well,
1844 following a hierarchical model.
1846 \0\b[image src="gnutls-x509.png"
\0\b]
1848 One needs to trust one or more CAs for his secure communications. In
1849 that case only the certificates issued by the trusted authorities are
1850 acceptable. See the figure above for a typical example. The API for
1851 handling X.509 certificates is described at section *note sec:x509api::.
1852 Some examples are listed below.
1856 * X.509 certificates::
1857 * Verifying X.509 certificate paths::
1858 * PKCS #10 certificate requests::
1859 * PKCS #12 structures::
1862 File: gnutls.info, Node: X.509 certificates, Next: Verifying X.509 certificate paths, Up: The X.509 trust model
1864 5.1.1 X.509 Certificates
1865 ------------------------
1867 An X.509 certificate usually contains information about the certificate
1868 holder, the signer, a unique serial number, expiration dates and some
1869 other fields [PKIX] (*note Bibliography::) as shown in the table below.
1872 The field that indicates the version of the certificate.
1875 This field holds a unique serial number per certificate.
1878 Holds the issuer's distinguished name.
1881 The activation and expiration dates.
1884 The subject's distinguished name of the certificate.
1887 The extensions are fields only present in version 3 certificates.
1889 The certificate's _subject or issuer name_ is not just a single string.
1890 It is a Distinguished name and in the ASN.1 notation is a sequence of
1891 several object IDs with their corresponding values. Some of available
1892 OIDs to be used in an X.509 distinguished name are defined in
1895 The _Version_ field in a certificate has values either 1 or 3 for
1896 version 3 certificates. Version 1 certificates do not support the
1897 extensions field so it is not possible to distinguish a CA from a
1898 person, thus their usage should be avoided.
1900 The _validity_ dates are there to indicate the date that the specific
1901 certificate was activated and the date the certificate's key would be
1904 Certificate _extensions_ are there to include information about the
1905 certificate's subject that did not fit in the typical certificate
1906 fields. Those may be e-mail addresses, flags that indicate whether the
1907 belongs to a CA etc. All the supported X.509 version 3 extensions are
1908 shown in the table below.
1910 'subject key id (2.5.29.14):'
1911 An identifier of the key of the subject.
1913 'authority key id (2.5.29.35):'
1914 An identifier of the authority's key used to sign the certificate.
1916 'subject alternative name (2.5.29.17):'
1917 Alternative names to subject's distinguished name.
1919 'key usage (2.5.29.15):'
1920 Constraints the key's usage of the certificate.
1922 'extended key usage (2.5.29.37):'
1923 Constraints the purpose of the certificate.
1925 'basic constraints (2.5.29.19):'
1926 Indicates whether this is a CA certificate or not, and specify the
1927 maximum path lengths of certificate chains.
1929 'CRL distribution points (2.5.29.31):'
1930 This extension is set by the CA, in order to inform about the
1933 'Proxy Certification Information (1.3.6.1.5.5.7.1.14):'
1934 Proxy Certificates includes this extension that contains the OID of
1935 the proxy policy language used, and can specify limits on the
1936 maximum lengths of proxy chains. Proxy Certificates are specified
1937 in [RFC3820] (*note Bibliography::).
1939 In GnuTLS the X.509 certificate structures are handled using the
1940 'gnutls_x509_crt_t' type and the corresponding private keys with the
1941 'gnutls_x509_privkey_t' type. All the available functions for X.509
1942 certificate handling have their prototypes in 'gnutls/x509.h'. An
1943 example program to demonstrate the X.509 parsing capabilities can be
1944 found at section *note ex:x509-info::.
1947 File: gnutls.info, Node: Verifying X.509 certificate paths, Next: PKCS #10 certificate requests, Prev: X.509 certificates, Up: The X.509 trust model
1949 5.1.2 Verifying X.509 Certificate Paths
1950 ---------------------------------------
1952 Verifying certificate paths is important in X.509 authentication. For
1953 this purpose the function *note gnutls_x509_crt_verify:: is provided.
1954 The output of this function is the bitwise OR of the elements of the
1955 'gnutls_certificate_status_t' enumeration. A detailed description of
1956 these elements can be found in figure below. The function *note
1957 gnutls_certificate_verify_peers2:: is equivalent to the previous one,
1958 and will verify the peer's certificate in a TLS session.
1960 'GNUTLS_CERT_INVALID:'
1961 The certificate is not signed by one of the known authorities, or
1962 the signature is invalid.
1964 'GNUTLS_CERT_REVOKED:'
1965 The certificate has been revoked by its CA.
1967 'GNUTLS_CERT_SIGNER_NOT_FOUND:'
1968 The certificate's issuer is not known. This is the case when the
1969 issuer is not in the trusted certificates list.
1971 'GNUTLS_CERT_SIGNER_NOT_CA:'
1972 The certificate's signer was not a CA. This may happen if this was
1973 a version 1 certificate, which is common with some CAs, or a
1974 version 3 certificate without the basic constrains extension.
1976 'GNUTLS_CERT_INSECURE_ALGORITHM:'
1977 The certificate was signed using an insecure algorithm such as MD2
1978 or MD5. These algorithms have been broken and should not be
1981 There is also to possibility to pass some input to the verification
1982 functions in the form of flags. For *note gnutls_x509_crt_verify:: the
1983 flags are passed straightforward, but *note
1984 gnutls_certificate_verify_peers2:: depends on the flags set by calling
1985 *note gnutls_certificate_set_verify_flags::. All the available flags
1986 are part of the enumeration *note gnutls_certificate_verify_flags:: and
1987 are explained in the table below.
1989 'GNUTLS_VERIFY_DISABLE_CA_SIGN:'
1990 If set a signer does not have to be a certificate authority. This
1991 flag should normaly be disabled, unless you know what this means.
1993 'GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT:'
1994 Allow only trusted CA certificates that have version 1. This is
1995 safer than GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT, and should be
1996 used instead. That way only signers in your trusted list will be
1997 allowed to have certificates of version 1.
1999 'GNUTLS_VERIFY_ALLOW_ANY_X509_V1_CA_CRT:'
2000 Allow CA certificates that have version 1 (both root and
2001 intermediate). This is dangerous since those haven't the
2002 basicConstraints extension. Must be used in combination with
2003 GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT.
2005 'GNUTLS_VERIFY_DO_NOT_ALLOW_SAME:'
2006 If a certificate is not signed by anyone trusted but exists in the
2007 trusted CA list do not treat it as trusted.
2009 'GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2:'
2010 Allow certificates to be signed using the old MD2 algorithm.
2012 'GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5:'
2013 Allow certificates to be signed using the broken MD5 algorithm.
2015 Although the verification of a certificate path indicates that the
2016 certificate is signed by trusted authority, does not reveal anything
2017 about the peer's identity. It is required to verify if the
2018 certificate's owner is the one you expect. For more information consult
2019 [RFC2818] (*note Bibliography::) and section *note ex:verify:: for an
2023 File: gnutls.info, Node: PKCS #10 certificate requests, Next: PKCS #12 structures, Prev: Verifying X.509 certificate paths, Up: The X.509 trust model
2025 5.1.3 PKCS #10 Certificate Requests
2026 -----------------------------------
2028 A certificate request is a structure, which contain information about an
2029 applicant of a certificate service. It usually contains a private key,
2030 a distinguished name and secondary data such as a challenge password.
2031 GnuTLS supports the requests defined in PKCS #10 [RFC2986] (*note
2032 Bibliography::). Other certificate request's format such as PKIX's
2033 [RFC4211] (*note Bibliography::) are not currently supported.
2035 In GnuTLS the PKCS #10 structures are handled using the
2036 'gnutls_x509_crq_t' type. An example of a certificate request
2037 generation can be found at section *note ex:crq::.
2040 File: gnutls.info, Node: PKCS #12 structures, Prev: PKCS #10 certificate requests, Up: The X.509 trust model
2042 5.1.4 PKCS #12 Structures
2043 -------------------------
2045 A PKCS #12 structure [PKCS12] (*note Bibliography::) usually contains a
2046 user's private keys and certificates. It is commonly used in browsers
2047 to export and import the user's identities.
2049 In GnuTLS the PKCS #12 structures are handled using the
2050 'gnutls_pkcs12_t' type. This is an abstract type that may hold several
2051 'gnutls_pkcs12_bag_t' types. The Bag types are the holders of the
2052 actual data, which may be certificates, private keys or encrypted data.
2053 An Bag of type encrypted should be decrypted in order for its data to be
2056 An example of a PKCS #12 structure generation can be found at section
2060 File: gnutls.info, Node: The OpenPGP trust model, Next: PKCS #11 tokens, Prev: The X.509 trust model, Up: More on certificate authentication
2062 5.2 The OpenPGP Trust Model
2063 ===========================
2065 The OpenPGP key authentication relies on a distributed trust model,
2066 called the "web of trust". The "web of trust" uses a decentralized
2067 system of trusted introducers, which are the same as a CA. OpenPGP
2068 allows anyone to sign anyone's else public key. When Alice signs Bob's
2069 key, she is introducing Bob's key to anyone who trusts Alice. If
2070 someone trusts Alice to introduce keys, then Alice is a trusted
2071 introducer in the mind of that observer.
2073 \0\b[image src="gnutls-pgp.png"
\0\b]
2075 For example: If David trusts Alice to be an introducer, and Alice signed
2076 Bob's key, Dave also trusts Bob's key to be the real one.
2078 There are some key points that are important in that model. In the
2079 example Alice has to sign Bob's key, only if she is sure that the key
2080 belongs to Bob. Otherwise she may also make Dave falsely believe that
2081 this is Bob's key. Dave has also the responsibility to know who to
2082 trust. This model is similar to real life relations.
2084 Just see how Charlie behaves in the previous example. Although he has
2085 signed Bob's key - because he knows, somehow, that it belongs to Bob -
2086 he does not trust Bob to be an introducer. Charlie decided to trust
2087 only Kevin, for some reason. A reason could be that Bob is lazy enough,
2088 and signs other people's keys without being sure that they belong to the
2094 In GnuTLS the OpenPGP key structures [RFC2440] (*note Bibliography::)
2095 are handled using the 'gnutls_openpgp_crt_t' type and the corresponding
2096 private keys with the 'gnutls_openpgp_privkey_t' type. All the
2097 prototypes for the key handling functions can be found at
2100 5.2.2 Verifying an OpenPGP Key
2101 ------------------------------
2103 The verification functions of OpenPGP keys, included in GnuTLS, are
2104 simple ones, and do not use the features of the "web of trust". For
2105 that reason, if the verification needs are complex, the assistance of
2106 external tools like GnuPG and GPGME
2107 ('http://www.gnupg.org/related_software/gpgme/') is recommended.
2109 There is one verification function in GnuTLS, the *note
2110 gnutls_openpgp_crt_verify_ring::. This checks an OpenPGP key against a
2111 given set of public keys (keyring) and returns the key status. The key
2112 verification status is the same as in X.509 certificates, although the
2113 meaning and interpretation are different. For example an OpenPGP key
2114 may be valid, if the self signature is ok, even if no signers were
2115 found. The meaning of verification status is shown in the figure below.
2118 A signature on the key is invalid. That means that the key was
2119 modified by somebody, or corrupted during transport.
2122 The key has been revoked by its owner.
2124 'CERT_SIGNER_NOT_FOUND:'
2125 The key was not signed by a known signer.
2127 'GNUTLS_CERT_INSECURE_ALGORITHM:'
2128 The certificate was signed using an insecure algorithm such as MD2
2129 or MD5. These algorithms have been broken and should not be
2133 File: gnutls.info, Node: PKCS #11 tokens, Next: Abstract data types, Prev: The OpenPGP trust model, Up: More on certificate authentication
2141 This section copes with the PKCS #11 [PKCS11] (*note Bibliography::)
2142 support in GnuTLS. PKCS #11 is plugin API allowing applications to
2143 access cryptographic operations on a token, as well as to objects
2144 residing on the token. A token can be a real hardware token such as a
2145 smart card, or it can be a software component such as Gnome Keyring.
2146 The objects residing on such token can be certificates, public keys,
2147 private keys or even plain data or secret keys. Of those certificates
2148 and public/private key pairs can be used with GnuTLS. Its main
2149 advantage is that it allows operations on private key objects such as
2150 decryption and signing without accessing the key itself.
2152 Moreover it can be used to allow all applications in the same operating
2153 system to access shared cryptographic keys and certificates in a uniform
2154 way, as in the following picture.
2156 \0\b[image src="pkcs11-vision.png"
\0\b]
2158 5.3.2 Initialization
2159 --------------------
2161 To allow all the GnuTLS applications to access PKCS #11 tokens you can
2162 use a configuration per module, such as
2163 '/etc/pkcs11/modules/mymodule.conf'. This file has the following
2166 module: /usr/lib/opensc-pkcs11.so
2168 If you use this file, then there is no need for other initialization in
2169 GnuTLS, except for the PIN and token functions. Those allow retrieving
2170 a PIN when accessing a protected object, such as a private key, as well
2171 as probe the user to insert the token. All the initialization functions
2174 * *note gnutls_pkcs11_init::: Global initialization
2176 * *note gnutls_pkcs11_deinit::: Global deinitialization
2178 * *note gnutls_pkcs11_set_token_function::: Sets the token insertion
2181 * *note gnutls_pkcs11_set_pin_function::: Sets the PIN request
2184 * *note gnutls_pkcs11_add_provider::: Adds an additional PKCS #11
2187 Note that due to limitations of PKCS #11 there might be issues when
2188 multiple libraries are sharing a module. If this is the case we suggest
2189 to use p11-kit(1) that provides an intermediate module to control access
2190 to resources over the multiple users.
2192 5.3.3 Reading Objects
2193 ---------------------
2195 All PKCS #11 objects are referenced by GnuTLS functions by URLs as
2196 described in 'draft-pechanec-pkcs11uri-03'. For example a public key on
2197 a smart card may be referenced as:
2199 pkcs11:token=Nikos;serial=307521161601031;model=PKCS%2315; \
2200 manufacturer=EnterSafe;object=test1;objecttype=public;\
2201 id=32:f1:53:f3:e3:79:90:b0:86:24:14:10:77:ca:5d:ec:2d:15:fa:ed
2203 while the smart card itself can be referenced as:
2204 pkcs11:token=Nikos;serial=307521161601031;model=PKCS%2315;manufacturer=EnterSafe
2206 Objects can be accessed with the following functions
2208 * *note gnutls_pkcs11_obj_init::: Initializes an object
2210 * *note gnutls_pkcs11_obj_import_url::: To import an object from a
2213 * *note gnutls_pkcs11_obj_export_url::: To export the URL of the
2216 * *note gnutls_pkcs11_obj_deinit::: To deinitialize an object
2218 * *note gnutls_pkcs11_obj_export::: To export data associated with
2221 * *note gnutls_pkcs11_obj_get_info::: To obtain information about an
2224 * *note gnutls_pkcs11_obj_list_import_url::: To mass load of objects
2226 * *note gnutls_x509_crt_import_pkcs11::: Import a certificate object
2228 * *note gnutls_x509_crt_import_pkcs11_url::: Helper function to
2229 directly import a URL into a certificate
2231 * *note gnutls_x509_crt_list_import_pkcs11::: Mass import of
2234 Functions that relate to token handling are shown below
2236 * *note gnutls_pkcs11_token_init::: Initializes a token
2238 * *note gnutls_pkcs11_token_set_pin::: Sets the token user's PIN
2240 * *note gnutls_pkcs11_token_get_url::: Returns the URL of a token
2242 * *note gnutls_pkcs11_token_get_info::: Obtain information about a
2245 * *note gnutls_pkcs11_token_get_flags::: Returns flags about a token
2246 (i.e. hardware or software)
2248 The following example will list all tokens.
2252 gnutls_global_init();
2255 ret = gnutls_pkcs11_token_get_url(i, &url);
2256 if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
2262 fprintf(stdout, "Token[%d]: URL: %s\n", i, url);
2265 gnutls_global_deinit();
2267 The next one will list all certificates in a token, that have a
2268 corresponding private key:
2269 gnutls_pkcs11_obj_t *obj_list;
2270 unsigned int obj_list_size = 0;
2271 gnutls_datum_t cinfo;
2275 ret = gnutls_pkcs11_obj_list_import_url( obj_list, NULL, url, \
2276 GNUTLS_PKCS11_OBJ_ATTR_CRT_WITH_PRIVKEY);
2277 if (ret < 0 && ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
2280 /* no error checking from now on */
2281 obj_list = malloc(sizeof(*obj_list)*obj_list_size);
2283 gnutls_pkcs11_obj_list_import_url( obj_list, &obj_list_size, url, flags);
2285 /* now all certificates are in obj_list */
2286 for (i=0;i<obj_list_size;i++) {
2288 gnutls_x509_crt_init(&xcrt);
2290 gnutls_x509_crt_import_pkcs11(xcrt, obj_list[i]);
2292 gnutls_x509_crt_print (xcrt, GNUTLS_CRT_PRINT_FULL, &cinfo);
2294 fprintf(stdout, "cert[%d]:\n %s\n\n", cinfo.data);
2296 gnutls_free(cinfo.data);
2297 gnutls_x509_crt_deinit(&xcrt);
2300 5.3.4 Writing Objects
2301 ---------------------
2303 With GnuTLS you can copy existing private keys and certificates to a
2304 token. This can be achieved with the following functions
2306 * *note gnutls_pkcs11_delete_url::: To delete an object
2308 * *note gnutls_pkcs11_copy_x509_privkey::: To copy a private key to a
2311 * *note gnutls_pkcs11_copy_x509_crt::: To copy a certificate to a
2314 5.3.5 Using a PKCS #11 token with TLS
2315 -------------------------------------
2317 It is possible to use a PKCS #11 token to a TLS session, as shown in
2318 *note ex:pkcs11-client::. In addition the following functions can be
2319 used to load PKCS #11 key and certificates.
2321 * *note gnutls_certificate_set_x509_trust_file::: If given a PKCS #11
2322 URL will load the trusted certificates from it.
2324 * *note gnutls_certificate_set_x509_key_file::: Will also load PKCS
2325 #11 URLs for keys and certificates.
2327 ---------- Footnotes ----------
2329 (1) http://p11-glue.freedesktop.org/
2332 File: gnutls.info, Node: Abstract data types, Next: Digital signatures, Prev: PKCS #11 tokens, Up: More on certificate authentication
2334 5.4 Abstract data types
2335 =======================
2337 Since there are many forms of a public or private keys supported by
2338 GnuTLS such as X.509, OpenPGP, or PKCS #11 it is desirable to allow
2339 common operations on them. For these reasons the abstract
2340 'gnutls_privkey_t' and 'gnutls_pubkey_t' were introduced in
2341 'gnutls/abstract.h' header. Those types are initialized using a
2342 specific type of key and then can be used to perform operations in an
2343 abstract way. For example in order for someone to sign an X.509
2344 certificate with a key that resides in a smart he has to follow the
2347 #inlude <gnutls/abstract.h>
2348 #inlude <gnutls/pkcs11.h>
2350 void sign_cert( gnutls_x509_crt_t to_be_signed)
2352 gnutls_pkcs11_privkey_t ca_key;
2353 gnutls_x509_crt_t ca_cert;
2354 gnutls_privkey_t abs_key;
2356 /* load the PKCS #11 key and certificates */
2357 gnutls_pkcs11_privkey_init(&ca_key);
2358 gnutls_pkcs11_privkey_import_url(ca_key, key_url);
2360 gnutls_x509_crt_init(&ca_cert);
2361 gnutls_x509_crt_import_pkcs11_url(&ca_cert, cert_url);
2363 /* initialize the abstract key */
2364 gnutls_privkey_init(&abs_key);
2365 gnutls_privkey_import_pkcs11(abs_key, ca_key);
2367 /* sign the certificate to be signed */
2368 gnutls_x509_crt_privkey_sign(to_be_signed, ca_cert, ca_key, GNUTLS_DIG_SHA1, 0);
2372 File: gnutls.info, Node: Digital signatures, Prev: Abstract data types, Up: More on certificate authentication
2374 5.5 Digital Signatures
2375 ======================
2377 In this section we will provide some information about digital
2378 signatures, how they work, and give the rationale for disabling some of
2379 the algorithms used.
2381 Digital signatures work by using somebody's secret key to sign some
2382 arbitrary data. Then anybody else could use the public key of that
2383 person to verify the signature. Since the data may be arbitrary it is
2384 not suitable input to a cryptographic digital signature algorithm. For
2385 this reason and also for performance cryptographic hash algorithms are
2386 used to preprocess the input to the signature algorithm. This works as
2387 long as it is difficult enough to generate two different messages with
2388 the same hash algorithm output. In that case the same signature could
2389 be used as a proof for both messages. Nobody wants to sign an innocent
2390 message of donating 1 euro to Greenpeace and find out that he donated
2391 1.000.000 euros to Bad Inc.
2393 For a hash algorithm to be called cryptographic the following three
2394 requirements must hold:
2396 1. Preimage resistance. That means the algorithm must be one way and
2397 given the output of the hash function H(x), it is impossible to
2400 2. 2nd preimage resistance. That means that given a pair x,y with
2401 y=H(x) it is impossible to calculate an x' such that y=H(x').
2403 3. Collision resistance. That means that it is impossible to
2404 calculate random x and x' such H(x')=H(x).
2406 The last two requirements in the list are the most important in digital
2407 signatures. These protect against somebody who would like to generate
2408 two messages with the same hash output. When an algorithm is considered
2409 broken usually it means that the Collision resistance of the algorithm
2410 is less than brute force. Using the birthday paradox the brute force
2411 attack takes 2^{((hash size) / 2)} operations. Today colliding
2412 certificates using the MD5 hash algorithm have been generated as shown
2413 in [WEGER] (*note Bibliography::).
2415 There has been cryptographic results for the SHA-1 hash algorithms as
2416 well, although they are not yet critical. Before 2004, MD5 had a
2417 presumed collision strength of 2^{64}, but it has been showed to have a
2418 collision strength well under 2^{50}. As of November 2005, it is
2419 believed that SHA-1's collision strength is around 2^{63}. We consider
2420 this sufficiently hard so that we still support SHA-1. We anticipate
2421 that SHA-256/386/512 will be used in publicly-distributed certificates
2422 in the future. When 2^{63} can be considered too weak compared to the
2423 computer power available sometime in the future, SHA-1 will be disabled
2424 as well. The collision attacks on SHA-1 may also get better, given the
2425 new interest in tools for creating them.
2427 5.5.1 Trading Security for Interoperability
2428 -------------------------------------------
2430 If you connect to a server and use GnuTLS' functions to verify the
2431 certificate chain, and get a *note GNUTLS_CERT_INSECURE_ALGORITHM::
2432 validation error (*note Verifying X.509 certificate paths::), it means
2433 that somewhere in the certificate chain there is a certificate signed
2434 using 'RSA-MD2' or 'RSA-MD5'. These two digital signature algorithms
2435 are considered broken, so GnuTLS fail when attempting to verify the
2436 certificate. In some situations, it may be useful to be able to verify
2437 the certificate chain anyway, assuming an attacker did not utilize the
2438 fact that these signatures algorithms are broken. This section will
2439 give help on how to achieve that.
2441 First, it is important to know that you do not have to enable any of the
2442 flags discussed here to be able to use trusted root CA certificates
2443 signed using 'RSA-MD2' or 'RSA-MD5'. The only attack today is that it
2444 is possible to generate certificates with colliding signatures
2445 (collision resistance); you cannot generate a certificate that has the
2446 same signature as an already existing signature (2nd preimage
2449 If you are using *note gnutls_certificate_verify_peers2:: to verify the
2450 certificate chain, you can call *note
2451 gnutls_certificate_set_verify_flags:: with the
2452 'GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2' or 'GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5'
2455 gnutls_certificate_set_verify_flags (x509cred,
2456 GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5);
2458 This will tell the verifier algorithm to enable 'RSA-MD5' when verifying
2461 If you are using *note gnutls_x509_crt_verify:: or *note
2462 gnutls_x509_crt_list_verify::, you can pass the
2463 'GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5' parameter directly in the 'flags'
2466 If you are using these flags, it may also be a good idea to warn the
2467 user when verification failure occur for this reason. The simplest is
2468 to not use the flags by default, and only fall back to using them after
2469 warning the user. If you wish to inspect the certificate chain
2470 yourself, you can use *note gnutls_certificate_get_peers:: to extract
2471 the raw server's certificate chain, then use *note
2472 gnutls_x509_crt_import:: to parse each of the certificates, and then use
2473 *note gnutls_x509_crt_get_signature_algorithm:: to find out the signing
2474 algorithm used for each certificate. If any of the intermediary
2475 certificates are using 'GNUTLS_SIGN_RSA_MD2' or 'GNUTLS_SIGN_RSA_MD5',
2476 you could present a warning.
2479 File: gnutls.info, Node: How to use TLS in application protocols, Next: How to use GnuTLS in applications, Prev: More on certificate authentication, Up: Top
2481 6 How To Use TLS in Application Protocols
2482 *****************************************
2484 This chapter is intended to provide some hints on how to use the TLS
2485 over simple custom made application protocols. The discussion below
2486 mainly refers to the _TCP/IP_ transport layer but may be extended to
2492 * Upward negotiation::
2495 File: gnutls.info, Node: Separate ports, Next: Upward negotiation, Up: How to use TLS in application protocols
2500 Traditionally SSL was used in application protocols by assigning a new
2501 port number for the secure services. That way two separate ports were
2502 assigned, one for the non secure sessions, and one for the secured ones.
2503 This has the benefit that if a user requests a secure session then the
2504 client will try to connect to the secure port and fail otherwise. The
2505 only possible attack with this method is a denial of service one. The
2506 most famous example of this method is the famous "HTTP over TLS" or
2507 HTTPS protocol [RFC2818] (*note Bibliography::).
2509 Despite its wide use, this method is not as good as it seems. This
2510 approach starts the TLS Handshake procedure just after the client
2511 connects on the --so called-- secure port. That way the TLS protocol
2512 does not know anything about the client, and popular methods like the
2513 host advertising in HTTP do not work(1). There is no way for the client
2514 to say "I connected to YYY server" before the Handshake starts, so the
2515 server cannot possibly know which certificate to use.
2517 Other than that it requires two separate ports to run a single service,
2518 which is unnecessary complication. Due to the fact that there is a
2519 limitation on the available privileged ports, this approach was soon
2522 ---------- Footnotes ----------
2524 (1) See also the Server Name Indication extension on *note
2528 File: gnutls.info, Node: Upward negotiation, Prev: Separate ports, Up: How to use TLS in application protocols
2530 6.2 Upward Negotiation
2531 ======================
2533 Other application protocols(1) use a different approach to enable the
2534 secure layer. They use something called the "TLS upgrade" method. This
2535 method is quite tricky but it is more flexible. The idea is to extend
2536 the application protocol to have a "STARTTLS" request, whose purpose it
2537 to start the TLS protocols just after the client requests it. This is a
2538 really neat idea and does not require an extra port.
2540 This method is used by almost all modern protocols and there is even the
2541 [RFC2817] (*note Bibliography::) paper which proposes extensions to HTTP
2544 The tricky part, in this method, is that the "STARTTLS" request is sent
2545 in the clear, thus is vulnerable to modifications. A typical attack is
2546 to modify the messages in a way that the client is fooled and thinks
2547 that the server does not have the "STARTTLS" capability. See a typical
2548 conversation of a hypothetical protocol:
2550 (client connects to the server)
2552 CLIENT: HELLO I'M MR. XXX
2554 SERVER: NICE TO MEET YOU XXX
2556 CLIENT: PLEASE START TLS
2562 CLIENT: HERE ARE SOME CONFIDENTIAL DATA
2564 And see an example of a conversation where someone is acting in between:
2566 (client connects to the server)
2568 CLIENT: HELLO I'M MR. XXX
2570 SERVER: NICE TO MEET YOU XXX
2572 CLIENT: PLEASE START TLS
2574 (here someone inserts this message)
2576 SERVER: SORRY I DON'T HAVE THIS CAPABILITY
2578 CLIENT: HERE ARE SOME CONFIDENTIAL DATA
2580 As you can see above the client was fooled, and was dummy enough to send
2581 the confidential data in the clear.
2583 How to avoid the above attack? As you may have already thought this one
2584 is easy to avoid. The client has to ask the user before it connects
2585 whether the user requests TLS or not. If the user answered that he
2586 certainly wants the secure layer the last conversation should be:
2588 (client connects to the server)
2590 CLIENT: HELLO I'M MR. XXX
2592 SERVER: NICE TO MEET YOU XXX
2594 CLIENT: PLEASE START TLS
2596 (here someone inserts this message)
2598 SERVER: SORRY I DON'T HAVE THIS CAPABILITY
2602 (the client notifies the user that the secure connection was not
2605 This method, if implemented properly, is far better than the traditional
2606 method, and the security properties remain the same, since only denial
2607 of service is possible. The benefit is that the server may request
2608 additional data before the TLS Handshake protocol starts, in order to
2609 send the correct certificate, use the correct password file(2), or
2612 ---------- Footnotes ----------
2614 (1) See LDAP, IMAP etc.
2616 (2) in SRP authentication
2619 File: gnutls.info, Node: How to use GnuTLS in applications, Next: Included programs, Prev: How to use TLS in application protocols, Up: Top
2621 7 How To Use GnuTLS in Applications
2622 ***********************************
2627 * Multi-threaded applications::
2630 * Miscellaneous examples::
2631 * Parameter generation::
2632 * Keying Material Exporters::
2633 * Channel Bindings::
2634 * Compatibility with the OpenSSL library::
2637 File: gnutls.info, Node: Preparation, Next: Multi-threaded applications, Up: How to use GnuTLS in applications
2642 To use GnuTLS, you have to perform some changes to your sources and your
2643 build system. The necessary changes are explained in the following
2652 * Building the source::
2655 File: gnutls.info, Node: Headers, Next: Initialization, Up: Preparation
2660 All the data types and functions of the GnuTLS library are defined in
2661 the header file 'gnutls/gnutls.h'. This must be included in all
2662 programs that make use of the GnuTLS library.
2664 The extra functionality of the GnuTLS-extra library is available by
2665 including the header file 'gnutls/extra.h' in your programs.
2668 File: gnutls.info, Node: Initialization, Next: Version check, Prev: Headers, Up: Preparation
2670 7.1.2 Initialization
2671 --------------------
2673 GnuTLS must be initialized before it can be used. The library is
2674 initialized by calling *note gnutls_global_init::. The resources
2675 allocated by the initialization process can be released if the
2676 application no longer has a need to call GnuTLS functions, this is done
2677 by calling *note gnutls_global_deinit::.
2679 The extra functionality of the GnuTLS-extra library is available after
2680 calling *note gnutls_global_init_extra::.
2682 In order to take advantage of the internationalisation features in
2683 GnuTLS, such as translated error messages, the application must set the
2684 current locale using 'setlocale' before initializing GnuTLS.
2687 File: gnutls.info, Node: Version check, Next: Debugging, Prev: Initialization, Up: Preparation
2692 It is often desirable to check that the version of 'gnutls' used is
2693 indeed one which fits all requirements. Even with binary compatibility
2694 new features may have been introduced but due to problem with the
2695 dynamic linker an old version is actually used. So you may want to
2696 check that the version is okay right after program startup. See the
2697 function *note gnutls_check_version::.
2700 File: gnutls.info, Node: Debugging, Next: Building the source, Prev: Version check, Up: Preparation
2705 In many cases things may not go as expected and further information, to
2706 assist debugging, from GnuTLS is desired. Those are the case where the
2707 *note gnutls_global_set_log_level:: and *note
2708 gnutls_global_set_log_function:: are to be used. Those will print
2709 verbose information on the GnuTLS functions internal flow.
2712 File: gnutls.info, Node: Building the source, Prev: Debugging, Up: Preparation
2714 7.1.5 Building the Source
2715 -------------------------
2717 If you want to compile a source file including the 'gnutls/gnutls.h'
2718 header file, you must make sure that the compiler can find it in the
2719 directory hierarchy. This is accomplished by adding the path to the
2720 directory in which the header file is located to the compilers include
2721 file search path (via the '-I' option).
2723 However, the path to the include file is determined at the time the
2724 source is configured. To solve this problem, the library uses the
2725 external package 'pkg-config' that knows the path to the include file
2726 and other configuration options. The options that need to be added to
2727 the compiler invocation at compile time are output by the '--cflags'
2728 option to 'pkg-config gnutls'. The following example shows how it can
2729 be used at the command line:
2731 gcc -c foo.c `pkg-config gnutls --cflags`
2733 Adding the output of 'pkg-config gnutls --cflags' to the compilers
2734 command line will ensure that the compiler can find the
2735 'gnutls/gnutls.h' header file.
2737 A similar problem occurs when linking the program with the library.
2738 Again, the compiler has to find the library files. For this to work,
2739 the path to the library files has to be added to the library search path
2740 (via the '-L' option). For this, the option '--libs' to 'pkg-config
2741 gnutls' can be used. For convenience, this option also outputs all
2742 other options that are required to link the program with the libarary
2743 (for instance, the '-ltasn1' option). The example shows how to link
2744 'foo.o' with the library to a program 'foo'.
2746 gcc -o foo foo.o `pkg-config gnutls --libs`
2748 Of course you can also combine both examples to a single command by
2749 specifying both options to 'pkg-config':
2751 gcc -o foo foo.c `pkg-config gnutls --cflags --libs`
2754 File: gnutls.info, Node: Multi-threaded applications, Next: Client examples, Prev: Preparation, Up: How to use GnuTLS in applications
2756 7.2 Multi-Threaded Applications
2757 ===============================
2759 Although the GnuTLS library is thread safe by design, some parts of the
2760 cryptographic backend, such as the random generator, are not.
2761 Applications can either call *note gnutls_global_init:: and use the
2762 default operating system provided locks (i.e. 'pthreads' on GNU/Linux),
2763 or specify manualy the locking system using the function *note
2764 gnutls_global_set_mutex:: before calling *note gnutls_global_init::.
2765 Setting manually mutexes is recommended only to applications that have
2766 full control of the underlying libraries. If this is not the case, the
2767 use of the operating system defaults is recommended.
2769 There are helper macros to help you properly initialize the libraries.
2770 Examples are shown below.
2772 * POSIX threads in GNU/Linux
2775 #include <pthread.h>
2779 gnutls_global_init();
2782 * Other thread packages
2786 gnutls_global_mutex_set (mutex_init, mutex_deinit, mutex_lock, mutex_unlock);
2787 gnutls_global_init();
2791 File: gnutls.info, Node: Client examples, Next: Server examples, Prev: Multi-threaded applications, Up: How to use GnuTLS in applications
2796 This section contains examples of TLS and SSL clients, using GnuTLS.
2797 Note that these examples contain little or no error checking. Some of
2798 the examples require functions implemented by another example.
2802 * Simple client example with anonymous authentication::
2803 * Simple client example with X.509 certificate support::
2804 * Obtaining session information::
2805 * Verifying peer's certificate::
2806 * Using a callback to select the certificate to use::
2807 * Client using a PKCS #11 token with TLS::
2808 * Client with Resume capability example::
2809 * Simple client example with SRP authentication::
2810 * Simple client example in C++::
2811 * Helper function for TCP connections::
2814 File: gnutls.info, Node: Simple client example with anonymous authentication, Next: Simple client example with X.509 certificate support, Up: Client examples
2816 7.3.1 Simple Client Example with Anonymous Authentication
2817 ---------------------------------------------------------
2819 The simplest client using TLS is the one that doesn't do any
2820 authentication. This means no external certificates or passwords are
2821 needed to set up the connection. As could be expected, the connection
2822 is vulnerable to man-in-the-middle (active or redirection) attacks.
2823 However, the data is integrity and privacy protected.
2825 /* This example code is placed in the public domain. */
2827 #ifdef HAVE_CONFIG_H
2834 #include <sys/types.h>
2835 #include <sys/socket.h>
2836 #include <arpa/inet.h>
2838 #include <gnutls/gnutls.h>
2840 /* A very basic TLS client, with anonymous authentication.
2843 #define MAX_BUF 1024
2844 #define MSG "GET / HTTP/1.0\r\n\r\n"
2846 extern int tcp_connect (void);
2847 extern void tcp_close (int sd);
2853 gnutls_session_t session;
2854 char buffer[MAX_BUF + 1];
2855 gnutls_anon_client_credentials_t anoncred;
2856 /* Need to enable anonymous KX specifically. */
2858 gnutls_global_init ();
2860 gnutls_anon_allocate_client_credentials (&anoncred);
2862 /* Initialize TLS session
2864 gnutls_init (&session, GNUTLS_CLIENT);
2866 /* Use default priorities */
2867 gnutls_priority_set_direct (session, "PERFORMANCE:+ANON-DH:!ARCFOUR-128",
2870 /* put the anonymous credentials to the current session
2872 gnutls_credentials_set (session, GNUTLS_CRD_ANON, anoncred);
2874 /* connect to the peer
2876 sd = tcp_connect ();
2878 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
2880 /* Perform the TLS handshake
2882 ret = gnutls_handshake (session);
2886 fprintf (stderr, "*** Handshake failed\n");
2887 gnutls_perror (ret);
2892 printf ("- Handshake was completed\n");
2895 gnutls_record_send (session, MSG, strlen (MSG));
2897 ret = gnutls_record_recv (session, buffer, MAX_BUF);
2900 printf ("- Peer has closed the TLS connection\n");
2905 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
2909 printf ("- Received %d bytes: ", ret);
2910 for (ii = 0; ii < ret; ii++)
2912 fputc (buffer[ii], stdout);
2914 fputs ("\n", stdout);
2916 gnutls_bye (session, GNUTLS_SHUT_RDWR);
2922 gnutls_deinit (session);
2924 gnutls_anon_free_client_credentials (anoncred);
2926 gnutls_global_deinit ();
2932 File: gnutls.info, Node: Simple client example with X.509 certificate support, Next: Obtaining session information, Prev: Simple client example with anonymous authentication, Up: Client examples
2934 7.3.2 Simple Client Example with X.509 Certificate Support
2935 ----------------------------------------------------------
2937 Let's assume now that we want to create a TCP client which communicates
2938 with servers that use X.509 or OpenPGP certificate authentication. The
2939 following client is a very simple TLS client, it does not support
2940 session resuming, not even certificate verification. The TCP functions
2941 defined in this example are used in most of the other examples below,
2942 without redefining them.
2944 /* This example code is placed in the public domain. */
2946 #ifdef HAVE_CONFIG_H
2953 #include <sys/types.h>
2954 #include <sys/socket.h>
2955 #include <arpa/inet.h>
2957 #include <gnutls/gnutls.h>
2959 /* A very basic TLS client, with X.509 authentication.
2962 #define MAX_BUF 1024
2963 #define CAFILE "ca.pem"
2964 #define MSG "GET / HTTP/1.0\r\n\r\n"
2966 extern int tcp_connect (void);
2967 extern void tcp_close (int sd);
2973 gnutls_session_t session;
2974 char buffer[MAX_BUF + 1];
2976 gnutls_certificate_credentials_t xcred;
2978 gnutls_global_init ();
2981 gnutls_certificate_allocate_credentials (&xcred);
2983 /* sets the trusted cas file
2985 gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
2987 /* Initialize TLS session
2989 gnutls_init (&session, GNUTLS_CLIENT);
2991 /* Use default priorities */
2992 ret = gnutls_priority_set_direct (session, "PERFORMANCE", &err);
2995 if (ret == GNUTLS_E_INVALID_REQUEST)
2997 fprintf (stderr, "Syntax error at: %s\n", err);
3002 /* put the x509 credentials to the current session
3004 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
3006 /* connect to the peer
3008 sd = tcp_connect ();
3010 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
3012 /* Perform the TLS handshake
3014 ret = gnutls_handshake (session);
3018 fprintf (stderr, "*** Handshake failed\n");
3019 gnutls_perror (ret);
3024 printf ("- Handshake was completed\n");
3027 gnutls_record_send (session, MSG, strlen (MSG));
3029 ret = gnutls_record_recv (session, buffer, MAX_BUF);
3032 printf ("- Peer has closed the TLS connection\n");
3037 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
3041 printf ("- Received %d bytes: ", ret);
3042 for (ii = 0; ii < ret; ii++)
3044 fputc (buffer[ii], stdout);
3046 fputs ("\n", stdout);
3048 gnutls_bye (session, GNUTLS_SHUT_RDWR);
3054 gnutls_deinit (session);
3056 gnutls_certificate_free_credentials (xcred);
3058 gnutls_global_deinit ();
3064 File: gnutls.info, Node: Obtaining session information, Next: Verifying peer's certificate, Prev: Simple client example with X.509 certificate support, Up: Client examples
3066 7.3.3 Obtaining Session Information
3067 -----------------------------------
3069 Most of the times it is desirable to know the security properties of the
3070 current established session. This includes the underlying ciphers and
3071 the protocols involved. That is the purpose of the following function.
3072 Note that this function will print meaningful values only if called
3073 after a successful *note gnutls_handshake::.
3075 /* This example code is placed in the public domain. */
3077 #ifdef HAVE_CONFIG_H
3083 #include <gnutls/gnutls.h>
3084 #include <gnutls/x509.h>
3086 #include "examples.h"
3088 /* This function will print some details of the
3092 print_info (gnutls_session_t session)
3095 gnutls_credentials_type_t cred;
3096 gnutls_kx_algorithm_t kx;
3098 /* print the key exchange's algorithm name
3100 kx = gnutls_kx_get (session);
3101 tmp = gnutls_kx_get_name (kx);
3102 printf ("- Key Exchange: %s\n", tmp);
3104 /* Check the authentication type used and switch
3105 * to the appropriate.
3107 cred = gnutls_auth_get_type (session);
3111 printf ("- TLS/IA session\n");
3116 case GNUTLS_CRD_SRP:
3117 printf ("- SRP session with username %s\n",
3118 gnutls_srp_server_get_username (session));
3122 case GNUTLS_CRD_PSK:
3123 /* This returns NULL in server side.
3125 if (gnutls_psk_client_get_hint (session) != NULL)
3126 printf ("- PSK authentication. PSK hint '%s'\n",
3127 gnutls_psk_client_get_hint (session));
3128 /* This returns NULL in client side.
3130 if (gnutls_psk_server_get_username (session) != NULL)
3131 printf ("- PSK authentication. Connected as '%s'\n",
3132 gnutls_psk_server_get_username (session));
3135 case GNUTLS_CRD_ANON: /* anonymous authentication */
3137 printf ("- Anonymous DH using prime of %d bits\n",
3138 gnutls_dh_get_prime_bits (session));
3141 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */
3143 /* Check if we have been using ephemeral Diffie-Hellman.
3145 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
3147 printf ("\n- Ephemeral DH using prime of %d bits\n",
3148 gnutls_dh_get_prime_bits (session));
3151 /* if the certificate list is available, then
3152 * print some information about it.
3154 print_x509_certificate_info (session);
3158 /* print the protocol's name (ie TLS 1.0)
3160 tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session));
3161 printf ("- Protocol: %s\n", tmp);
3163 /* print the certificate type of the peer.
3167 gnutls_certificate_type_get_name (gnutls_certificate_type_get (session));
3169 printf ("- Certificate Type: %s\n", tmp);
3171 /* print the compression algorithm (if any)
3173 tmp = gnutls_compression_get_name (gnutls_compression_get (session));
3174 printf ("- Compression: %s\n", tmp);
3176 /* print the name of the cipher used.
3179 tmp = gnutls_cipher_get_name (gnutls_cipher_get (session));
3180 printf ("- Cipher: %s\n", tmp);
3182 /* Print the MAC algorithms name.
3185 tmp = gnutls_mac_get_name (gnutls_mac_get (session));
3186 printf ("- MAC: %s\n", tmp);
3192 File: gnutls.info, Node: Verifying peer's certificate, Next: Using a callback to select the certificate to use, Prev: Obtaining session information, Up: Client examples
3194 7.3.4 Verifying Peer's Certificate
3195 ----------------------------------
3197 A TLS session is not secure just after the handshake procedure has
3198 finished. It must be considered secure, only after the peer's
3199 certificate and identity have been verified. That is, you have to
3200 verify the signature in peer's certificate, the hostname in the
3201 certificate, and expiration dates. Just after this step you should
3202 treat the connection as being a secure one.
3204 /* This example code is placed in the public domain. */
3206 #ifdef HAVE_CONFIG_H
3213 #include <gnutls/gnutls.h>
3214 #include <gnutls/x509.h>
3215 #include "examples.h"
3217 /* A very basic TLS client, with X.509 authentication and server certificate
3221 #define MAX_BUF 1024
3222 #define CAFILE "ca.pem"
3223 #define MSG "GET / HTTP/1.0\r\n\r\n"
3225 extern int tcp_connect (void);
3226 extern void tcp_close (int sd);
3228 /* This function will try to verify the peer's certificate, and
3229 * also check if the hostname matches, and the activation, expiration dates.
3232 verify_certificate_callback (gnutls_session_t session)
3234 unsigned int status;
3235 const gnutls_datum_t *cert_list;
3236 unsigned int cert_list_size;
3238 gnutls_x509_crt_t cert;
3239 const char *hostname;
3242 hostname = gnutls_session_get_ptr (session);
3244 /* This verification function uses the trusted CAs in the credentials
3245 * structure. So you must have installed one or more CA certificates.
3247 ret = gnutls_certificate_verify_peers2 (session, &status);
3251 return GNUTLS_E_CERTIFICATE_ERROR;
3254 if (status & GNUTLS_CERT_INVALID)
3255 printf ("The certificate is not trusted.\n");
3257 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
3258 printf ("The certificate hasn't got a known issuer.\n");
3260 if (status & GNUTLS_CERT_REVOKED)
3261 printf ("The certificate has been revoked.\n");
3263 if (status & GNUTLS_CERT_EXPIRED)
3264 printf ("The certificate has expired\n");
3266 if (status & GNUTLS_CERT_NOT_ACTIVATED)
3267 printf ("The certificate is not yet activated\n");
3269 /* Up to here the process is the same for X.509 certificates and
3270 * OpenPGP keys. From now on X.509 certificates are assumed. This can
3271 * be easily extended to work with openpgp keys as well.
3273 if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
3274 return GNUTLS_E_CERTIFICATE_ERROR;
3276 if (gnutls_x509_crt_init (&cert) < 0)
3278 printf ("error in initialization\n");
3279 return GNUTLS_E_CERTIFICATE_ERROR;
3282 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
3283 if (cert_list == NULL)
3285 printf ("No certificate was found!\n");
3286 return GNUTLS_E_CERTIFICATE_ERROR;
3289 /* This is not a real world example, since we only check the first
3290 * certificate in the given chain.
3292 if (gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0)
3294 printf ("error parsing certificate\n");
3295 return GNUTLS_E_CERTIFICATE_ERROR;
3299 if (!gnutls_x509_crt_check_hostname (cert, hostname))
3301 printf ("The certificate's owner does not match hostname '%s'\n",
3303 return GNUTLS_E_CERTIFICATE_ERROR;
3306 gnutls_x509_crt_deinit (cert);
3308 /* notify gnutls to continue handshake normally */
3317 gnutls_session_t session;
3318 char buffer[MAX_BUF + 1];
3320 gnutls_certificate_credentials_t xcred;
3322 gnutls_global_init ();
3325 gnutls_certificate_allocate_credentials (&xcred);
3327 /* sets the trusted cas file
3329 gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
3330 gnutls_certificate_set_verify_function (xcred, verify_certificate_callback);
3331 gnutls_certificate_set_verify_flags (xcred,
3332 GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
3334 /* Initialize TLS session
3336 gnutls_init (&session, GNUTLS_CLIENT);
3338 gnutls_session_set_ptr (session, (void *) "my_host_name");
3340 /* Use default priorities */
3341 ret = gnutls_priority_set_direct (session, "PERFORMANCE", &err);
3344 if (ret == GNUTLS_E_INVALID_REQUEST)
3346 fprintf (stderr, "Syntax error at: %s\n", err);
3351 /* put the x509 credentials to the current session
3353 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
3355 /* connect to the peer
3357 sd = tcp_connect ();
3359 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
3361 /* Perform the TLS handshake
3363 ret = gnutls_handshake (session);
3367 fprintf (stderr, "*** Handshake failed\n");
3368 gnutls_perror (ret);
3373 printf ("- Handshake was completed\n");
3376 gnutls_record_send (session, MSG, strlen (MSG));
3378 ret = gnutls_record_recv (session, buffer, MAX_BUF);
3381 printf ("- Peer has closed the TLS connection\n");
3386 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
3390 printf ("- Received %d bytes: ", ret);
3391 for (ii = 0; ii < ret; ii++)
3393 fputc (buffer[ii], stdout);
3395 fputs ("\n", stdout);
3397 gnutls_bye (session, GNUTLS_SHUT_RDWR);
3403 gnutls_deinit (session);
3405 gnutls_certificate_free_credentials (xcred);
3407 gnutls_global_deinit ();
3412 Another example is listed below which provides more detailed
3413 verification output, for applications that need it.
3415 /* This example code is placed in the public domain. */
3417 #ifdef HAVE_CONFIG_H
3423 #include <gnutls/gnutls.h>
3424 #include <gnutls/x509.h>
3426 #include "examples.h"
3428 /* All the available CRLs
3430 gnutls_x509_crl_t *crl_list;
3433 /* All the available trusted CAs
3435 gnutls_x509_crt_t *ca_list;
3438 static void verify_cert2 (gnutls_x509_crt_t crt,
3439 gnutls_x509_crt_t issuer,
3440 gnutls_x509_crl_t * crl_list, int crl_list_size);
3441 static void verify_last_cert (gnutls_x509_crt_t crt,
3442 gnutls_x509_crt_t * ca_list, int ca_list_size,
3443 gnutls_x509_crl_t * crl_list,
3447 /* This function will try to verify the peer's certificate chain, and
3448 * also check if the hostname matches, and the activation, expiration dates.
3451 verify_certificate_chain (gnutls_session_t session,
3452 const char *hostname,
3453 const gnutls_datum_t * cert_chain,
3454 int cert_chain_length)
3457 gnutls_x509_crt_t *cert;
3459 cert = malloc (sizeof (*cert) * cert_chain_length);
3461 /* Import all the certificates in the chain to
3462 * native certificate format.
3464 for (i = 0; i < cert_chain_length; i++)
3466 gnutls_x509_crt_init (&cert[i]);
3467 gnutls_x509_crt_import (cert[i], &cert_chain[i], GNUTLS_X509_FMT_DER);
3470 /* If the last certificate in the chain is self signed ignore it.
3471 * That is because we want to check against our trusted certificate
3474 if (gnutls_x509_crt_check_issuer (cert[cert_chain_length - 1],
3475 cert[cert_chain_length - 1]) > 0
3476 && cert_chain_length > 0)
3478 cert_chain_length--;
3481 /* Now verify the certificates against their issuers
3484 for (i = 1; i < cert_chain_length; i++)
3486 verify_cert2 (cert[i - 1], cert[i], crl_list, crl_list_size);
3489 /* Here we must verify the last certificate in the chain against
3490 * our trusted CA list.
3492 verify_last_cert (cert[cert_chain_length - 1],
3493 ca_list, ca_list_size, crl_list, crl_list_size);
3495 /* Check if the name in the first certificate matches our destination!
3497 if (!gnutls_x509_crt_check_hostname (cert[0], hostname))
3499 printf ("The certificate's owner does not match hostname '%s'\n",
3503 for (i = 0; i < cert_chain_length; i++)
3504 gnutls_x509_crt_deinit (cert[i]);
3510 /* Verifies a certificate against an other certificate
3511 * which is supposed to be it's issuer. Also checks the
3512 * crl_list if the certificate is revoked.
3515 verify_cert2 (gnutls_x509_crt_t crt, gnutls_x509_crt_t issuer,
3516 gnutls_x509_crl_t * crl_list, int crl_list_size)
3518 unsigned int output;
3523 /* Print information about the certificates to
3526 name_size = sizeof (name);
3527 gnutls_x509_crt_get_dn (crt, name, &name_size);
3529 fprintf (stderr, "\nCertificate: %s\n", name);
3531 name_size = sizeof (name);
3532 gnutls_x509_crt_get_issuer_dn (crt, name, &name_size);
3534 fprintf (stderr, "Issued by: %s\n", name);
3536 /* Get the DN of the issuer cert.
3538 name_size = sizeof (name);
3539 gnutls_x509_crt_get_dn (issuer, name, &name_size);
3541 fprintf (stderr, "Checking against: %s\n", name);
3543 /* Do the actual verification.
3545 gnutls_x509_crt_verify (crt, &issuer, 1, 0, &output);
3547 if (output & GNUTLS_CERT_INVALID)
3549 fprintf (stderr, "Not trusted");
3551 if (output & GNUTLS_CERT_SIGNER_NOT_FOUND)
3552 fprintf (stderr, ": no issuer was found");
3553 if (output & GNUTLS_CERT_SIGNER_NOT_CA)
3554 fprintf (stderr, ": issuer is not a CA");
3555 if (output & GNUTLS_CERT_NOT_ACTIVATED)
3556 fprintf (stderr, ": not yet activated\n");
3557 if (output & GNUTLS_CERT_EXPIRED)
3558 fprintf (stderr, ": expired\n");
3560 fprintf (stderr, "\n");
3563 fprintf (stderr, "Trusted\n");
3565 /* Check if the certificate is revoked.
3567 ret = gnutls_x509_crt_check_revocation (crt, crl_list, crl_list_size);
3570 fprintf (stderr, "Revoked\n");
3575 /* Verifies a certificate against our trusted CA list.
3576 * Also checks the crl_list if the certificate is revoked.
3579 verify_last_cert (gnutls_x509_crt_t crt,
3580 gnutls_x509_crt_t * ca_list, int ca_list_size,
3581 gnutls_x509_crl_t * crl_list, int crl_list_size)
3583 unsigned int output;
3588 /* Print information about the certificates to
3591 name_size = sizeof (name);
3592 gnutls_x509_crt_get_dn (crt, name, &name_size);
3594 fprintf (stderr, "\nCertificate: %s\n", name);
3596 name_size = sizeof (name);
3597 gnutls_x509_crt_get_issuer_dn (crt, name, &name_size);
3599 fprintf (stderr, "Issued by: %s\n", name);
3601 /* Do the actual verification.
3603 gnutls_x509_crt_verify (crt, ca_list, ca_list_size,
3604 GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT, &output);
3606 if (output & GNUTLS_CERT_INVALID)
3608 fprintf (stderr, "Not trusted");
3610 if (output & GNUTLS_CERT_SIGNER_NOT_CA)
3611 fprintf (stderr, ": Issuer is not a CA\n");
3612 if (output & GNUTLS_CERT_NOT_ACTIVATED)
3613 fprintf (stderr, ": Not yet activated\n");
3614 if (output & GNUTLS_CERT_EXPIRED)
3615 fprintf (stderr, ": Expired\n");
3616 fprintf (stderr, "\n");
3619 fprintf (stderr, "Trusted\n");
3622 /* Check if the certificate is revoked.
3624 ret = gnutls_x509_crt_check_revocation (crt, crl_list, crl_list_size);
3627 fprintf (stderr, "Revoked\n");
3632 File: gnutls.info, Node: Using a callback to select the certificate to use, Next: Client using a PKCS #11 token with TLS, Prev: Verifying peer's certificate, Up: Client examples
3634 7.3.5 Using a Callback to Select the Certificate to Use
3635 -------------------------------------------------------
3637 There are cases where a client holds several certificate and key pairs,
3638 and may not want to load all of them in the credentials structure. The
3639 following example demonstrates the use of the certificate selection
3642 /* This example code is placed in the public domain. */
3644 #ifdef HAVE_CONFIG_H
3651 #include <sys/types.h>
3652 #include <sys/socket.h>
3653 #include <arpa/inet.h>
3655 #include <gnutls/gnutls.h>
3656 #include <gnutls/x509.h>
3657 #include <sys/types.h>
3658 #include <sys/stat.h>
3661 /* A TLS client that loads the certificate and key.
3664 #define MAX_BUF 1024
3665 #define MSG "GET / HTTP/1.0\r\n\r\n"
3667 #define CERT_FILE "cert.pem"
3668 #define KEY_FILE "key.pem"
3669 #define CAFILE "ca.pem"
3671 extern int tcp_connect (void);
3672 extern void tcp_close (int sd);
3674 static int cert_callback (gnutls_session_t session,
3675 const gnutls_datum_t * req_ca_rdn, int nreqs,
3676 const gnutls_pk_algorithm_t * sign_algos,
3677 int sign_algos_length, gnutls_retr2_st * st);
3679 gnutls_x509_crt_t crt;
3680 gnutls_x509_privkey_t key;
3682 /* Helper functions to load a certificate and key
3683 * files into memory.
3685 static gnutls_datum_t
3686 load_file (const char *file)
3689 gnutls_datum_t loaded_file = { NULL, 0 };
3693 if (!(f = fopen (file, "r"))
3694 || fseek (f, 0, SEEK_END) != 0
3695 || (filelen = ftell (f)) < 0
3696 || fseek (f, 0, SEEK_SET) != 0
3697 || !(ptr = malloc ((size_t) filelen))
3698 || fread (ptr, 1, (size_t) filelen, f) < (size_t) filelen)
3703 loaded_file.data = ptr;
3704 loaded_file.size = (unsigned int) filelen;
3709 unload_file (gnutls_datum_t data)
3714 /* Load the certificate and the private key.
3720 gnutls_datum_t data;
3722 data = load_file (CERT_FILE);
3723 if (data.data == NULL)
3725 fprintf (stderr, "*** Error loading cert file.\n");
3728 gnutls_x509_crt_init (&crt);
3730 ret = gnutls_x509_crt_import (crt, &data, GNUTLS_X509_FMT_PEM);
3733 fprintf (stderr, "*** Error loading key file: %s\n",
3734 gnutls_strerror (ret));
3740 data = load_file (KEY_FILE);
3741 if (data.data == NULL)
3743 fprintf (stderr, "*** Error loading key file.\n");
3747 gnutls_x509_privkey_init (&key);
3749 ret = gnutls_x509_privkey_import (key, &data, GNUTLS_X509_FMT_PEM);
3752 fprintf (stderr, "*** Error loading key file: %s\n",
3753 gnutls_strerror (ret));
3765 gnutls_session_t session;
3766 gnutls_priority_t priorities_cache;
3767 char buffer[MAX_BUF + 1];
3768 gnutls_certificate_credentials_t xcred;
3769 /* Allow connections to servers that have OpenPGP keys as well.
3772 gnutls_global_init ();
3777 gnutls_certificate_allocate_credentials (&xcred);
3780 gnutls_priority_init (&priorities_cache, "NORMAL", NULL);
3783 /* sets the trusted cas file
3785 gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
3787 gnutls_certificate_set_retrieve_function (xcred, cert_callback);
3789 /* Initialize TLS session
3791 gnutls_init (&session, GNUTLS_CLIENT);
3793 /* Use default priorities */
3794 gnutls_priority_set (session, priorities_cache);
3796 /* put the x509 credentials to the current session
3798 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
3800 /* connect to the peer
3802 sd = tcp_connect ();
3804 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
3806 /* Perform the TLS handshake
3808 ret = gnutls_handshake (session);
3812 fprintf (stderr, "*** Handshake failed\n");
3813 gnutls_perror (ret);
3818 printf ("- Handshake was completed\n");
3821 gnutls_record_send (session, MSG, strlen (MSG));
3823 ret = gnutls_record_recv (session, buffer, MAX_BUF);
3826 printf ("- Peer has closed the TLS connection\n");
3831 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
3835 printf ("- Received %d bytes: ", ret);
3836 for (ii = 0; ii < ret; ii++)
3838 fputc (buffer[ii], stdout);
3840 fputs ("\n", stdout);
3842 gnutls_bye (session, GNUTLS_SHUT_RDWR);
3848 gnutls_deinit (session);
3850 gnutls_certificate_free_credentials (xcred);
3851 gnutls_priority_deinit (priorities_cache);
3853 gnutls_global_deinit ();
3860 /* This callback should be associated with a session by calling
3861 * gnutls_certificate_client_set_retrieve_function( session, cert_callback),
3862 * before a handshake.
3866 cert_callback (gnutls_session_t session,
3867 const gnutls_datum_t * req_ca_rdn, int nreqs,
3868 const gnutls_pk_algorithm_t * sign_algos,
3869 int sign_algos_length, gnutls_retr2_st * st)
3871 char issuer_dn[256];
3874 gnutls_certificate_type_t type;
3876 /* Print the server's trusted CAs
3879 printf ("- Server's trusted authorities:\n");
3881 printf ("- Server did not send us any trusted authorities names.\n");
3883 /* print the names (if any) */
3884 for (i = 0; i < nreqs; i++)
3886 len = sizeof (issuer_dn);
3887 ret = gnutls_x509_rdn_get (&req_ca_rdn[i], issuer_dn, &len);
3890 printf (" [%d]: ", i);
3891 printf ("%s\n", issuer_dn);
3895 /* Select a certificate and return it.
3896 * The certificate must be of any of the "sign algorithms"
3897 * supported by the server.
3900 type = gnutls_certificate_type_get (session);
3901 if (type == GNUTLS_CRT_X509)
3903 /* check if the certificate we are sending is signed
3904 * with an algorithm that the server accepts */
3905 gnutls_sign_algorithm_t cert_algo, req_algo;
3908 ret = gnutls_x509_crt_get_signature_algorithm (crt);
3911 /* error reading signature algorithm
3920 ret = gnutls_sign_algorithm_get_requested (session, i, &req_algo);
3921 if (ret >= 0 && cert_algo == req_algo)
3927 /* server has not requested anything specific */
3928 if (i == 0 && ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
3940 ("- Could not find a suitable certificate to send to server\n");
3944 st->cert_type = type;
3947 st->cert.x509 = &crt;
3949 st->key_type = GNUTLS_PRIVKEY_X509;
3963 File: gnutls.info, Node: Client using a PKCS #11 token with TLS, Next: Client with Resume capability example, Prev: Using a callback to select the certificate to use, Up: Client examples
3965 7.3.6 Using a PKCS #11 token with TLS
3966 -------------------------------------
3968 This example will demonstrate how to load keys and certificates from a
3969 PKCS #11 token, and use it with a TLS connection.
3971 /* This example code is placed in the public domain. */
3973 #ifdef HAVE_CONFIG_H
3977 #include <getpass.h>
3982 #include <sys/types.h>
3983 #include <sys/socket.h>
3984 #include <arpa/inet.h>
3986 #include <gnutls/gnutls.h>
3987 #include <gnutls/x509.h>
3988 #include <gnutls/pkcs11.h>
3989 #include <sys/types.h>
3990 #include <sys/stat.h>
3993 /* A TLS client that loads the certificate and key.
3996 #define MAX_BUF 1024
3997 #define MSG "GET / HTTP/1.0\r\n\r\n"
3998 #define MIN(x,y) (((x)<(y))?(x):(y))
4000 #define CAFILE "ca.pem"
4001 #define KEY_URL "pkcs11:manufacturer=SomeManufacturer;object=Private%20Key" \
4002 ";objecttype=private;id=db:5b:3e:b5:72:33"
4003 #define CERT_URL "pkcs11:manufacturer=SomeManufacturer;object=Certificate;" \
4004 "objecttype=cert;id=db:5b:3e:b5:72:33"
4006 extern int tcp_connect (void);
4007 extern void tcp_close (int sd);
4009 static int cert_callback (gnutls_session_t session,
4010 const gnutls_datum_t * req_ca_rdn, int nreqs,
4011 const gnutls_pk_algorithm_t * sign_algos,
4012 int sign_algos_length, gnutls_retr2_st * st);
4014 gnutls_x509_crt_t crt;
4015 gnutls_pkcs11_privkey_t key;
4017 /* Load the certificate and the private key.
4024 gnutls_x509_crt_init (&crt);
4026 ret = gnutls_x509_crt_import_pkcs11_url (crt, CERT_URL, 0);
4028 /* some tokens require login to read data */
4029 if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
4030 ret = gnutls_x509_crt_import_pkcs11_url (crt, CERT_URL,
4031 GNUTLS_PKCS11_OBJ_FLAG_LOGIN);
4035 fprintf (stderr, "*** Error loading key file: %s\n",
4036 gnutls_strerror (ret));
4040 gnutls_pkcs11_privkey_init (&key);
4042 ret = gnutls_pkcs11_privkey_import_url (key, KEY_URL, 0);
4045 fprintf (stderr, "*** Error loading key file: %s\n",
4046 gnutls_strerror (ret));
4053 pin_callback (void *user, int attempt, const char *token_url,
4054 const char *token_label, unsigned int flags, char *pin,
4057 const char *password;
4060 printf ("PIN required for token '%s' with URL '%s'\n", token_label,
4062 if (flags & GNUTLS_PKCS11_PIN_FINAL_TRY)
4063 printf ("*** This is the final try before locking!\n");
4064 if (flags & GNUTLS_PKCS11_PIN_COUNT_LOW)
4065 printf ("*** Only few tries left before locking!\n");
4067 password = getpass ("Enter pin: ");
4068 if (password == NULL || password[0] == 0)
4070 fprintf (stderr, "No password given\n");
4074 len = MIN (pin_max, strlen (password));
4075 memcpy (pin, password, len);
4085 gnutls_session_t session;
4086 gnutls_priority_t priorities_cache;
4087 char buffer[MAX_BUF + 1];
4088 gnutls_certificate_credentials_t xcred;
4089 /* Allow connections to servers that have OpenPGP keys as well.
4092 gnutls_global_init ();
4093 /* PKCS11 private key operations might require PIN.
4094 * Register a callback.
4096 gnutls_pkcs11_set_pin_function (pin_callback, NULL);
4101 gnutls_certificate_allocate_credentials (&xcred);
4104 gnutls_priority_init (&priorities_cache, "NORMAL", NULL);
4107 /* sets the trusted cas file
4109 gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
4111 gnutls_certificate_set_retrieve_function (xcred, cert_callback);
4113 /* Initialize TLS session
4115 gnutls_init (&session, GNUTLS_CLIENT);
4117 /* Use default priorities */
4118 gnutls_priority_set (session, priorities_cache);
4120 /* put the x509 credentials to the current session
4122 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
4124 /* connect to the peer
4126 sd = tcp_connect ();
4128 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
4130 /* Perform the TLS handshake
4132 ret = gnutls_handshake (session);
4136 fprintf (stderr, "*** Handshake failed\n");
4137 gnutls_perror (ret);
4142 printf ("- Handshake was completed\n");
4145 gnutls_record_send (session, MSG, strlen (MSG));
4147 ret = gnutls_record_recv (session, buffer, MAX_BUF);
4150 printf ("- Peer has closed the TLS connection\n");
4155 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
4159 printf ("- Received %d bytes: ", ret);
4160 for (ii = 0; ii < ret; ii++)
4162 fputc (buffer[ii], stdout);
4164 fputs ("\n", stdout);
4166 gnutls_bye (session, GNUTLS_SHUT_RDWR);
4172 gnutls_deinit (session);
4174 gnutls_certificate_free_credentials (xcred);
4175 gnutls_priority_deinit (priorities_cache);
4177 gnutls_global_deinit ();
4184 /* This callback should be associated with a session by calling
4185 * gnutls_certificate_client_set_retrieve_function( session, cert_callback),
4186 * before a handshake.
4190 cert_callback (gnutls_session_t session,
4191 const gnutls_datum_t * req_ca_rdn, int nreqs,
4192 const gnutls_pk_algorithm_t * sign_algos,
4193 int sign_algos_length, gnutls_retr2_st * st)
4195 char issuer_dn[256];
4198 gnutls_certificate_type_t type;
4200 /* Print the server's trusted CAs
4203 printf ("- Server's trusted authorities:\n");
4205 printf ("- Server did not send us any trusted authorities names.\n");
4207 /* print the names (if any) */
4208 for (i = 0; i < nreqs; i++)
4210 len = sizeof (issuer_dn);
4211 ret = gnutls_x509_rdn_get (&req_ca_rdn[i], issuer_dn, &len);
4214 printf (" [%d]: ", i);
4215 printf ("%s\n", issuer_dn);
4219 /* Select a certificate and return it.
4220 * The certificate must be of any of the "sign algorithms"
4221 * supported by the server.
4224 type = gnutls_certificate_type_get (session);
4225 if (type == GNUTLS_CRT_X509)
4227 /* check if the certificate we are sending is signed
4228 * with an algorithm that the server accepts */
4229 gnutls_sign_algorithm_t cert_algo, req_algo;
4232 ret = gnutls_x509_crt_get_signature_algorithm (crt);
4235 /* error reading signature algorithm
4244 ret = gnutls_sign_algorithm_get_requested (session, i, &req_algo);
4245 if (ret >= 0 && cert_algo == req_algo)
4251 /* server has not requested anything specific */
4252 if (i == 0 && ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
4264 ("- Could not find a suitable certificate to send to server\n");
4268 st->cert_type = type;
4271 st->cert.x509 = &crt;
4272 st->key.pkcs11 = key;
4273 st->key_type = GNUTLS_PRIVKEY_PKCS11;
4287 File: gnutls.info, Node: Client with Resume capability example, Next: Simple client example with SRP authentication, Prev: Client using a PKCS #11 token with TLS, Up: Client examples
4289 7.3.7 Client with Resume Capability Example
4290 -------------------------------------------
4292 This is a modification of the simple client example. Here we
4293 demonstrate the use of session resumption. The client tries to connect
4294 once using TLS, close the connection and then try to establish a new
4295 connection using the previously negotiated data.
4297 /* This example code is placed in the public domain. */
4299 #ifdef HAVE_CONFIG_H
4306 #include <gnutls/gnutls.h>
4308 /* Those functions are defined in other examples.
4310 extern void check_alert (gnutls_session_t session, int ret);
4311 extern int tcp_connect (void);
4312 extern void tcp_close (int sd);
4314 #define MAX_BUF 1024
4315 #define CAFILE "ca.pem"
4316 #define MSG "GET / HTTP/1.0\r\n\r\n"
4323 gnutls_session_t session;
4324 char buffer[MAX_BUF + 1];
4325 gnutls_certificate_credentials_t xcred;
4327 /* variables used in session resuming
4330 char *session_data = NULL;
4331 size_t session_data_size = 0;
4333 gnutls_global_init ();
4336 gnutls_certificate_allocate_credentials (&xcred);
4338 gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
4340 for (t = 0; t < 2; t++)
4341 { /* connect 2 times to the server */
4343 sd = tcp_connect ();
4345 gnutls_init (&session, GNUTLS_CLIENT);
4347 gnutls_priority_set_direct (session, "PERFORMANCE:!ARCFOUR-128", NULL);
4349 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
4353 /* if this is not the first time we connect */
4354 gnutls_session_set_data (session, session_data, session_data_size);
4355 free (session_data);
4358 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
4360 /* Perform the TLS handshake
4362 ret = gnutls_handshake (session);
4366 fprintf (stderr, "*** Handshake failed\n");
4367 gnutls_perror (ret);
4372 printf ("- Handshake was completed\n");
4376 { /* the first time we connect */
4377 /* get the session data size */
4378 gnutls_session_get_data (session, NULL, &session_data_size);
4379 session_data = malloc (session_data_size);
4381 /* put session data to the session variable */
4382 gnutls_session_get_data (session, session_data, &session_data_size);
4386 { /* the second time we connect */
4388 /* check if we actually resumed the previous session */
4389 if (gnutls_session_is_resumed (session) != 0)
4391 printf ("- Previous session was resumed\n");
4395 fprintf (stderr, "*** Previous session was NOT resumed\n");
4399 /* This function was defined in a previous example
4401 /* print_info(session); */
4403 gnutls_record_send (session, MSG, strlen (MSG));
4405 ret = gnutls_record_recv (session, buffer, MAX_BUF);
4408 printf ("- Peer has closed the TLS connection\n");
4413 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
4417 printf ("- Received %d bytes: ", ret);
4418 for (ii = 0; ii < ret; ii++)
4420 fputc (buffer[ii], stdout);
4422 fputs ("\n", stdout);
4424 gnutls_bye (session, GNUTLS_SHUT_RDWR);
4430 gnutls_deinit (session);
4434 gnutls_certificate_free_credentials (xcred);
4436 gnutls_global_deinit ();
4442 File: gnutls.info, Node: Simple client example with SRP authentication, Next: Simple client example in C++, Prev: Client with Resume capability example, Up: Client examples
4444 7.3.8 Simple Client Example with SRP Authentication
4445 ---------------------------------------------------
4447 The following client is a very simple SRP TLS client which connects to a
4448 server and authenticates using a _username_ and a _password_. The
4449 server may authenticate itself using a certificate, and in that case it
4452 /* This example code is placed in the public domain. */
4454 #ifdef HAVE_CONFIG_H
4461 #include <gnutls/gnutls.h>
4462 #include <gnutls/extra.h>
4464 /* Those functions are defined in other examples.
4466 extern void check_alert (gnutls_session_t session, int ret);
4467 extern int tcp_connect (void);
4468 extern void tcp_close (int sd);
4470 #define MAX_BUF 1024
4471 #define USERNAME "user"
4472 #define PASSWORD "pass"
4473 #define CAFILE "ca.pem"
4474 #define MSG "GET / HTTP/1.0\r\n\r\n"
4481 gnutls_session_t session;
4482 char buffer[MAX_BUF + 1];
4483 gnutls_srp_client_credentials_t srp_cred;
4484 gnutls_certificate_credentials_t cert_cred;
4486 gnutls_global_init ();
4488 /* now enable the gnutls-extra library which contains the
4491 gnutls_global_init_extra ();
4493 gnutls_srp_allocate_client_credentials (&srp_cred);
4494 gnutls_certificate_allocate_credentials (&cert_cred);
4496 gnutls_certificate_set_x509_trust_file (cert_cred, CAFILE,
4497 GNUTLS_X509_FMT_PEM);
4498 gnutls_srp_set_client_credentials (srp_cred, USERNAME, PASSWORD);
4500 /* connects to server
4502 sd = tcp_connect ();
4504 /* Initialize TLS session
4506 gnutls_init (&session, GNUTLS_CLIENT);
4509 /* Set the priorities.
4511 gnutls_priority_set_direct (session, "NORMAL:+SRP:+SRP-RSA:+SRP-DSS", NULL);
4513 /* put the SRP credentials to the current session
4515 gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred);
4516 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cert_cred);
4518 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
4520 /* Perform the TLS handshake
4522 ret = gnutls_handshake (session);
4526 fprintf (stderr, "*** Handshake failed\n");
4527 gnutls_perror (ret);
4532 printf ("- Handshake was completed\n");
4535 gnutls_record_send (session, MSG, strlen (MSG));
4537 ret = gnutls_record_recv (session, buffer, MAX_BUF);
4538 if (gnutls_error_is_fatal (ret) == 1 || ret == 0)
4542 printf ("- Peer has closed the GnuTLS connection\n");
4547 fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
4552 check_alert (session, ret);
4556 printf ("- Received %d bytes: ", ret);
4557 for (ii = 0; ii < ret; ii++)
4559 fputc (buffer[ii], stdout);
4561 fputs ("\n", stdout);
4563 gnutls_bye (session, GNUTLS_SHUT_RDWR);
4569 gnutls_deinit (session);
4571 gnutls_srp_free_client_credentials (srp_cred);
4572 gnutls_certificate_free_credentials (cert_cred);
4574 gnutls_global_deinit ();
4580 File: gnutls.info, Node: Simple client example in C++, Next: Helper function for TCP connections, Prev: Simple client example with SRP authentication, Up: Client examples
4582 7.3.9 Simple Client Example using the C++ API
4583 ---------------------------------------------
4585 The following client is a simple example of a client client utilizing
4589 #include <stdexcept>
4590 #include <gnutls/gnutls.h>
4591 #include <gnutls/gnutlsxx.h>
4592 #include <cstring> /* for strlen */
4594 /* A very basic TLS client, with anonymous authentication.
4595 * written by Eduardo Villanueva Che.
4598 #define MAX_BUF 1024
4599 #define SA struct sockaddr
4601 #define CAFILE "ca.pem"
4602 #define MSG "GET / HTTP/1.0\r\n\r\n"
4606 int tcp_connect(void);
4607 void tcp_close(int sd);
4614 gnutls_global_init();
4619 /* Allow connections to servers that have OpenPGP keys as well.
4621 gnutls::client_session session;
4624 gnutls::certificate_credentials credentials;
4627 /* sets the trusted cas file
4629 credentials.set_x509_trust_file(CAFILE, GNUTLS_X509_FMT_PEM);
4630 /* put the x509 credentials to the current session
4632 session.set_credentials(credentials);
4634 /* Use default priorities */
4635 session.set_priority ("NORMAL", NULL);
4637 /* connect to the peer
4640 session.set_transport_ptr((gnutls_transport_ptr_t) sd);
4642 /* Perform the TLS handshake
4644 int ret = session.handshake();
4647 throw std::runtime_error("Handshake failed");
4651 std::cout << "- Handshake was completed" << std::endl;
4654 session.send(MSG, strlen(MSG));
4655 char buffer[MAX_BUF + 1];
4656 ret = session.recv(buffer, MAX_BUF);
4659 throw std::runtime_error("Peer has closed the TLS connection");
4663 throw std::runtime_error(gnutls_strerror(ret));
4666 std::cout << "- Received " << ret << " bytes:" << std::endl;
4667 std::cout.write(buffer, ret);
4668 std::cout << std::endl;
4670 session.bye(GNUTLS_SHUT_RDWR);
4672 catch (std::exception &ex)
4674 std::cerr << "Exception caught: " << ex.what() << std::endl;
4680 gnutls_global_deinit();
4686 File: gnutls.info, Node: Helper function for TCP connections, Prev: Simple client example in C++, Up: Client examples
4688 7.3.10 Helper Function for TCP Connections
4689 ------------------------------------------
4691 This helper function abstracts away TCP connection handling from the
4692 other examples. It is required to build some examples.
4694 /* This example code is placed in the public domain. */
4696 #ifdef HAVE_CONFIG_H
4703 #include <sys/types.h>
4704 #include <sys/socket.h>
4705 #include <arpa/inet.h>
4706 #include <netinet/in.h>
4709 #define SA struct sockaddr
4712 int tcp_connect (void);
4713 void tcp_close (int sd);
4715 /* Connects to the peer and returns a socket
4721 const char *PORT = "5556";
4722 const char *SERVER = "127.0.0.1";
4724 struct sockaddr_in sa;
4726 /* connects to server
4728 sd = socket (AF_INET, SOCK_STREAM, 0);
4730 memset (&sa, '\0', sizeof (sa));
4731 sa.sin_family = AF_INET;
4732 sa.sin_port = htons (atoi (PORT));
4733 inet_pton (AF_INET, SERVER, &sa.sin_addr);
4735 err = connect (sd, (SA *) & sa, sizeof (sa));
4738 fprintf (stderr, "Connect error\n");
4745 /* closes the given socket descriptor.
4750 shutdown (sd, SHUT_RDWR); /* no more receptions */
4755 File: gnutls.info, Node: Server examples, Next: Miscellaneous examples, Prev: Client examples, Up: How to use GnuTLS in applications
4760 This section contains examples of TLS and SSL servers, using GnuTLS.
4764 * Echo Server with X.509 authentication::
4765 * Echo Server with OpenPGP authentication::
4766 * Echo Server with SRP authentication::
4767 * Echo Server with anonymous authentication::
4770 File: gnutls.info, Node: Echo Server with X.509 authentication, Next: Echo Server with OpenPGP authentication, Up: Server examples
4772 7.4.1 Echo Server with X.509 Authentication
4773 -------------------------------------------
4775 This example is a very simple echo server which supports X.509
4776 authentication, using the RSA ciphersuites.
4778 /* This example code is placed in the public domain. */
4780 #ifdef HAVE_CONFIG_H
4787 #include <sys/types.h>
4788 #include <sys/socket.h>
4789 #include <arpa/inet.h>
4790 #include <netinet/in.h>
4793 #include <gnutls/gnutls.h>
4795 #define KEYFILE "key.pem"
4796 #define CERTFILE "cert.pem"
4797 #define CAFILE "ca.pem"
4798 #define CRLFILE "crl.pem"
4800 /* This is a sample TLS 1.0 echo server, using X.509 authentication.
4804 #define SA struct sockaddr
4805 #define SOCKET_ERR(err,s) if(err==-1) {perror(s);return(1);}
4806 #define MAX_BUF 1024
4807 #define PORT 5556 /* listen to 5556 port */
4808 #define DH_BITS 1024
4810 /* These are global */
4811 gnutls_certificate_credentials_t x509_cred;
4812 gnutls_priority_t priority_cache;
4814 static gnutls_session_t
4815 initialize_tls_session (void)
4817 gnutls_session_t session;
4819 gnutls_init (&session, GNUTLS_SERVER);
4821 gnutls_priority_set (session, priority_cache);
4823 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, x509_cred);
4825 /* request client certificate if any.
4827 gnutls_certificate_server_set_request (session, GNUTLS_CERT_REQUEST);
4829 /* Set maximum compatibility mode. This is only suggested on public webservers
4830 * that need to trade security for compatibility
4832 gnutls_session_enable_compatibility_mode (session);
4837 static gnutls_dh_params_t dh_params;
4840 generate_dh_params (void)
4843 /* Generate Diffie-Hellman parameters - for use with DHE
4844 * kx algorithms. When short bit length is used, it might
4845 * be wise to regenerate parameters.
4847 * Check the ex-serv-export.c example for using static
4850 gnutls_dh_params_init (&dh_params);
4851 gnutls_dh_params_generate2 (dh_params, DH_BITS);
4861 struct sockaddr_in sa_serv;
4862 struct sockaddr_in sa_cli;
4865 gnutls_session_t session;
4866 char buffer[MAX_BUF + 1];
4869 /* this must be called once in the program
4871 gnutls_global_init ();
4873 gnutls_certificate_allocate_credentials (&x509_cred);
4874 gnutls_certificate_set_x509_trust_file (x509_cred, CAFILE,
4875 GNUTLS_X509_FMT_PEM);
4877 gnutls_certificate_set_x509_crl_file (x509_cred, CRLFILE,
4878 GNUTLS_X509_FMT_PEM);
4880 gnutls_certificate_set_x509_key_file (x509_cred, CERTFILE, KEYFILE,
4881 GNUTLS_X509_FMT_PEM);
4883 generate_dh_params ();
4885 gnutls_priority_init (&priority_cache, "NORMAL", NULL);
4888 gnutls_certificate_set_dh_params (x509_cred, dh_params);
4890 /* Socket operations
4892 listen_sd = socket (AF_INET, SOCK_STREAM, 0);
4893 SOCKET_ERR (listen_sd, "socket");
4895 memset (&sa_serv, '\0', sizeof (sa_serv));
4896 sa_serv.sin_family = AF_INET;
4897 sa_serv.sin_addr.s_addr = INADDR_ANY;
4898 sa_serv.sin_port = htons (PORT); /* Server Port number */
4900 setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval,
4903 err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv));
4904 SOCKET_ERR (err, "bind");
4905 err = listen (listen_sd, 1024);
4906 SOCKET_ERR (err, "listen");
4908 printf ("Server ready. Listening to port '%d'.\n\n", PORT);
4910 client_len = sizeof (sa_cli);
4913 session = initialize_tls_session ();
4915 sd = accept (listen_sd, (SA *) & sa_cli, &client_len);
4917 printf ("- connection from %s, port %d\n",
4918 inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf,
4919 sizeof (topbuf)), ntohs (sa_cli.sin_port));
4921 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
4922 ret = gnutls_handshake (session);
4926 gnutls_deinit (session);
4927 fprintf (stderr, "*** Handshake has failed (%s)\n\n",
4928 gnutls_strerror (ret));
4931 printf ("- Handshake was completed\n");
4933 /* see the Getting peer's information example */
4934 /* print_info(session); */
4938 memset (buffer, 0, MAX_BUF + 1);
4939 ret = gnutls_record_recv (session, buffer, MAX_BUF);
4943 printf ("\n- Peer has closed the GnuTLS connection\n");
4948 fprintf (stderr, "\n*** Received corrupted "
4949 "data(%d). Closing the connection.\n\n", ret);
4954 /* echo data back to the client
4956 gnutls_record_send (session, buffer, strlen (buffer));
4960 /* do not wait for the peer to close the connection.
4962 gnutls_bye (session, GNUTLS_SHUT_WR);
4965 gnutls_deinit (session);
4970 gnutls_certificate_free_credentials (x509_cred);
4971 gnutls_priority_deinit (priority_cache);
4973 gnutls_global_deinit ();
4980 File: gnutls.info, Node: Echo Server with OpenPGP authentication, Next: Echo Server with SRP authentication, Prev: Echo Server with X.509 authentication, Up: Server examples
4982 7.4.2 Echo Server with OpenPGP Authentication
4983 ---------------------------------------------
4985 The following example is an echo server which supports OpenPGP key
4986 authentication. You can easily combine this functionality --that is
4987 have a server that supports both X.509 and OpenPGP certificates-- but we
4988 separated them to keep these examples as simple as possible.
4990 /* This example code is placed in the public domain. */
4992 #ifdef HAVE_CONFIG_H
4999 #include <sys/types.h>
5000 #include <sys/socket.h>
5001 #include <arpa/inet.h>
5002 #include <netinet/in.h>
5005 #include <gnutls/gnutls.h>
5006 #include <gnutls/openpgp.h>
5008 #define KEYFILE "secret.asc"
5009 #define CERTFILE "public.asc"
5010 #define RINGFILE "ring.gpg"
5012 /* This is a sample TLS 1.0-OpenPGP echo server.
5016 #define SA struct sockaddr
5017 #define SOCKET_ERR(err,s) if(err==-1) {perror(s);return(1);}
5018 #define MAX_BUF 1024
5019 #define PORT 5556 /* listen to 5556 port */
5020 #define DH_BITS 1024
5022 /* These are global */
5023 gnutls_certificate_credentials_t cred;
5024 gnutls_dh_params_t dh_params;
5027 generate_dh_params (void)
5030 /* Generate Diffie-Hellman parameters - for use with DHE
5031 * kx algorithms. These should be discarded and regenerated
5032 * once a day, once a week or once a month. Depending on the
5033 * security requirements.
5035 gnutls_dh_params_init (&dh_params);
5036 gnutls_dh_params_generate2 (dh_params, DH_BITS);
5041 static gnutls_session_t
5042 initialize_tls_session (void)
5044 gnutls_session_t session;
5046 gnutls_init (&session, GNUTLS_SERVER);
5048 gnutls_priority_set_direct (session, "NORMAL", NULL);
5050 /* request client certificate if any.
5052 gnutls_certificate_server_set_request (session, GNUTLS_CERT_REQUEST);
5054 gnutls_dh_set_prime_bits (session, DH_BITS);
5064 struct sockaddr_in sa_serv;
5065 struct sockaddr_in sa_cli;
5068 gnutls_session_t session;
5069 char buffer[MAX_BUF + 1];
5073 strcpy (name, "Echo Server");
5075 /* this must be called once in the program
5077 gnutls_global_init ();
5079 gnutls_certificate_allocate_credentials (&cred);
5080 gnutls_certificate_set_openpgp_keyring_file (cred, RINGFILE,
5081 GNUTLS_OPENPGP_FMT_BASE64);
5083 gnutls_certificate_set_openpgp_key_file (cred, CERTFILE, KEYFILE,
5084 GNUTLS_OPENPGP_FMT_BASE64);
5086 generate_dh_params ();
5088 gnutls_certificate_set_dh_params (cred, dh_params);
5090 /* Socket operations
5092 listen_sd = socket (AF_INET, SOCK_STREAM, 0);
5093 SOCKET_ERR (listen_sd, "socket");
5095 memset (&sa_serv, '\0', sizeof (sa_serv));
5096 sa_serv.sin_family = AF_INET;
5097 sa_serv.sin_addr.s_addr = INADDR_ANY;
5098 sa_serv.sin_port = htons (PORT); /* Server Port number */
5100 setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval,
5103 err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv));
5104 SOCKET_ERR (err, "bind");
5105 err = listen (listen_sd, 1024);
5106 SOCKET_ERR (err, "listen");
5108 printf ("%s ready. Listening to port '%d'.\n\n", name, PORT);
5110 client_len = sizeof (sa_cli);
5113 session = initialize_tls_session ();
5115 sd = accept (listen_sd, (SA *) & sa_cli, &client_len);
5117 printf ("- connection from %s, port %d\n",
5118 inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf,
5119 sizeof (topbuf)), ntohs (sa_cli.sin_port));
5121 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
5122 ret = gnutls_handshake (session);
5126 gnutls_deinit (session);
5127 fprintf (stderr, "*** Handshake has failed (%s)\n\n",
5128 gnutls_strerror (ret));
5131 printf ("- Handshake was completed\n");
5133 /* see the Getting peer's information example */
5134 /* print_info(session); */
5138 memset (buffer, 0, MAX_BUF + 1);
5139 ret = gnutls_record_recv (session, buffer, MAX_BUF);
5143 printf ("\n- Peer has closed the GnuTLS connection\n");
5148 fprintf (stderr, "\n*** Received corrupted "
5149 "data(%d). Closing the connection.\n\n", ret);
5154 /* echo data back to the client
5156 gnutls_record_send (session, buffer, strlen (buffer));
5160 /* do not wait for the peer to close the connection.
5162 gnutls_bye (session, GNUTLS_SHUT_WR);
5165 gnutls_deinit (session);
5170 gnutls_certificate_free_credentials (cred);
5172 gnutls_global_deinit ();
5179 File: gnutls.info, Node: Echo Server with SRP authentication, Next: Echo Server with anonymous authentication, Prev: Echo Server with OpenPGP authentication, Up: Server examples
5181 7.4.3 Echo Server with SRP Authentication
5182 -----------------------------------------
5184 This is a server which supports SRP authentication. It is also possible
5185 to combine this functionality with a certificate server. Here it is
5186 separate for simplicity.
5188 /* This example code is placed in the public domain. */
5190 #ifdef HAVE_CONFIG_H
5197 #include <sys/types.h>
5198 #include <sys/socket.h>
5199 #include <arpa/inet.h>
5200 #include <netinet/in.h>
5203 #include <gnutls/gnutls.h>
5204 #include <gnutls/extra.h>
5206 #define SRP_PASSWD "tpasswd"
5207 #define SRP_PASSWD_CONF "tpasswd.conf"
5209 #define KEYFILE "key.pem"
5210 #define CERTFILE "cert.pem"
5211 #define CAFILE "ca.pem"
5213 /* This is a sample TLS-SRP echo server.
5216 #define SA struct sockaddr
5217 #define SOCKET_ERR(err,s) if(err==-1) {perror(s);return(1);}
5218 #define MAX_BUF 1024
5219 #define PORT 5556 /* listen to 5556 port */
5221 /* These are global */
5222 gnutls_srp_server_credentials_t srp_cred;
5223 gnutls_certificate_credentials_t cert_cred;
5225 static gnutls_session_t
5226 initialize_tls_session (void)
5228 gnutls_session_t session;
5230 gnutls_init (&session, GNUTLS_SERVER);
5232 gnutls_priority_set_direct (session, "NORMAL:+SRP:+SRP-DSS:+SRP-RSA", NULL);
5234 gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred);
5235 /* for the certificate authenticated ciphersuites.
5237 gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, cert_cred);
5239 /* request client certificate if any.
5241 gnutls_certificate_server_set_request (session, GNUTLS_CERT_IGNORE);
5251 struct sockaddr_in sa_serv;
5252 struct sockaddr_in sa_cli;
5255 gnutls_session_t session;
5256 char buffer[MAX_BUF + 1];
5260 strcpy (name, "Echo Server");
5262 /* these must be called once in the program
5264 gnutls_global_init ();
5265 gnutls_global_init_extra (); /* for SRP */
5267 /* SRP_PASSWD a password file (created with the included srptool utility)
5269 gnutls_srp_allocate_server_credentials (&srp_cred);
5270 gnutls_srp_set_server_credentials_file (srp_cred, SRP_PASSWD,
5273 gnutls_certificate_allocate_credentials (&cert_cred);
5274 gnutls_certificate_set_x509_trust_file (cert_cred, CAFILE,
5275 GNUTLS_X509_FMT_PEM);
5276 gnutls_certificate_set_x509_key_file (cert_cred, CERTFILE, KEYFILE,
5277 GNUTLS_X509_FMT_PEM);
5279 /* TCP socket operations
5281 listen_sd = socket (AF_INET, SOCK_STREAM, 0);
5282 SOCKET_ERR (listen_sd, "socket");
5284 memset (&sa_serv, '\0', sizeof (sa_serv));
5285 sa_serv.sin_family = AF_INET;
5286 sa_serv.sin_addr.s_addr = INADDR_ANY;
5287 sa_serv.sin_port = htons (PORT); /* Server Port number */
5289 setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval,
5292 err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv));
5293 SOCKET_ERR (err, "bind");
5294 err = listen (listen_sd, 1024);
5295 SOCKET_ERR (err, "listen");
5297 printf ("%s ready. Listening to port '%d'.\n\n", name, PORT);
5299 client_len = sizeof (sa_cli);
5302 session = initialize_tls_session ();
5304 sd = accept (listen_sd, (SA *) & sa_cli, &client_len);
5306 printf ("- connection from %s, port %d\n",
5307 inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf,
5308 sizeof (topbuf)), ntohs (sa_cli.sin_port));
5310 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
5311 ret = gnutls_handshake (session);
5315 gnutls_deinit (session);
5316 fprintf (stderr, "*** Handshake has failed (%s)\n\n",
5317 gnutls_strerror (ret));
5320 printf ("- Handshake was completed\n");
5322 /* print_info(session); */
5326 memset (buffer, 0, MAX_BUF + 1);
5327 ret = gnutls_record_recv (session, buffer, MAX_BUF);
5331 printf ("\n- Peer has closed the GnuTLS connection\n");
5336 fprintf (stderr, "\n*** Received corrupted "
5337 "data(%d). Closing the connection.\n\n", ret);
5342 /* echo data back to the client
5344 gnutls_record_send (session, buffer, strlen (buffer));
5348 /* do not wait for the peer to close the connection. */
5349 gnutls_bye (session, GNUTLS_SHUT_WR);
5352 gnutls_deinit (session);
5357 gnutls_srp_free_server_credentials (srp_cred);
5358 gnutls_certificate_free_credentials (cert_cred);
5360 gnutls_global_deinit ();
5367 File: gnutls.info, Node: Echo Server with anonymous authentication, Prev: Echo Server with SRP authentication, Up: Server examples
5369 7.4.4 Echo Server with Anonymous Authentication
5370 -----------------------------------------------
5372 This example server support anonymous authentication, and could be used
5373 to serve the example client for anonymous authentication.
5375 /* This example code is placed in the public domain. */
5377 #ifdef HAVE_CONFIG_H
5384 #include <sys/types.h>
5385 #include <sys/socket.h>
5386 #include <arpa/inet.h>
5387 #include <netinet/in.h>
5390 #include <gnutls/gnutls.h>
5392 /* This is a sample TLS 1.0 echo server, for anonymous authentication only.
5396 #define SA struct sockaddr
5397 #define SOCKET_ERR(err,s) if(err==-1) {perror(s);return(1);}
5398 #define MAX_BUF 1024
5399 #define PORT 5556 /* listen to 5556 port */
5400 #define DH_BITS 1024
5402 /* These are global */
5403 gnutls_anon_server_credentials_t anoncred;
5405 static gnutls_session_t
5406 initialize_tls_session (void)
5408 gnutls_session_t session;
5410 gnutls_init (&session, GNUTLS_SERVER);
5412 gnutls_priority_set_direct (session, "NORMAL:+ANON-DH", NULL);
5414 gnutls_credentials_set (session, GNUTLS_CRD_ANON, anoncred);
5416 gnutls_dh_set_prime_bits (session, DH_BITS);
5421 static gnutls_dh_params_t dh_params;
5424 generate_dh_params (void)
5427 /* Generate Diffie-Hellman parameters - for use with DHE
5428 * kx algorithms. These should be discarded and regenerated
5429 * once a day, once a week or once a month. Depending on the
5430 * security requirements.
5432 gnutls_dh_params_init (&dh_params);
5433 gnutls_dh_params_generate2 (dh_params, DH_BITS);
5443 struct sockaddr_in sa_serv;
5444 struct sockaddr_in sa_cli;
5447 gnutls_session_t session;
5448 char buffer[MAX_BUF + 1];
5451 /* this must be called once in the program
5453 gnutls_global_init ();
5455 gnutls_anon_allocate_server_credentials (&anoncred);
5457 generate_dh_params ();
5459 gnutls_anon_set_server_dh_params (anoncred, dh_params);
5461 /* Socket operations
5463 listen_sd = socket (AF_INET, SOCK_STREAM, 0);
5464 SOCKET_ERR (listen_sd, "socket");
5466 memset (&sa_serv, '\0', sizeof (sa_serv));
5467 sa_serv.sin_family = AF_INET;
5468 sa_serv.sin_addr.s_addr = INADDR_ANY;
5469 sa_serv.sin_port = htons (PORT); /* Server Port number */
5471 setsockopt (listen_sd, SOL_SOCKET, SO_REUSEADDR, (void *) &optval,
5474 err = bind (listen_sd, (SA *) & sa_serv, sizeof (sa_serv));
5475 SOCKET_ERR (err, "bind");
5476 err = listen (listen_sd, 1024);
5477 SOCKET_ERR (err, "listen");
5479 printf ("Server ready. Listening to port '%d'.\n\n", PORT);
5481 client_len = sizeof (sa_cli);
5484 session = initialize_tls_session ();
5486 sd = accept (listen_sd, (SA *) & sa_cli, &client_len);
5488 printf ("- connection from %s, port %d\n",
5489 inet_ntop (AF_INET, &sa_cli.sin_addr, topbuf,
5490 sizeof (topbuf)), ntohs (sa_cli.sin_port));
5492 gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
5493 ret = gnutls_handshake (session);
5497 gnutls_deinit (session);
5498 fprintf (stderr, "*** Handshake has failed (%s)\n\n",
5499 gnutls_strerror (ret));
5502 printf ("- Handshake was completed\n");
5504 /* see the Getting peer's information example */
5505 /* print_info(session); */
5509 memset (buffer, 0, MAX_BUF + 1);
5510 ret = gnutls_record_recv (session, buffer, MAX_BUF);
5514 printf ("\n- Peer has closed the GnuTLS connection\n");
5519 fprintf (stderr, "\n*** Received corrupted "
5520 "data(%d). Closing the connection.\n\n", ret);
5525 /* echo data back to the client
5527 gnutls_record_send (session, buffer, strlen (buffer));
5531 /* do not wait for the peer to close the connection.
5533 gnutls_bye (session, GNUTLS_SHUT_WR);
5536 gnutls_deinit (session);
5541 gnutls_anon_free_server_credentials (anoncred);
5543 gnutls_global_deinit ();
5550 File: gnutls.info, Node: Miscellaneous examples, Next: Parameter generation, Prev: Server examples, Up: How to use GnuTLS in applications
5552 7.5 Miscellaneous Examples
5553 ==========================
5557 * Checking for an alert::
5558 * X.509 certificate parsing example::
5559 * Certificate request generation::
5560 * PKCS #12 structure generation::
5563 File: gnutls.info, Node: Checking for an alert, Next: X.509 certificate parsing example, Up: Miscellaneous examples
5565 7.5.1 Checking for an Alert
5566 ---------------------------
5568 This is a function that checks if an alert has been received in the
5571 /* This example code is placed in the public domain. */
5573 #ifdef HAVE_CONFIG_H
5579 #include <gnutls/gnutls.h>
5581 #include "examples.h"
5583 /* This function will check whether the given return code from
5584 * a gnutls function (recv/send), is an alert, and will print
5588 check_alert (gnutls_session_t session, int ret)
5592 if (ret == GNUTLS_E_WARNING_ALERT_RECEIVED
5593 || ret == GNUTLS_E_FATAL_ALERT_RECEIVED)
5595 last_alert = gnutls_alert_get (session);
5597 /* The check for renegotiation is only useful if we are
5598 * a server, and we had requested a rehandshake.
5600 if (last_alert == GNUTLS_A_NO_RENEGOTIATION &&
5601 ret == GNUTLS_E_WARNING_ALERT_RECEIVED)
5602 printf ("* Received NO_RENEGOTIATION alert. "
5603 "Client Does not support renegotiation.\n");
5605 printf ("* Received alert '%d': %s.\n", last_alert,
5606 gnutls_alert_get_name (last_alert));
5611 File: gnutls.info, Node: X.509 certificate parsing example, Next: Certificate request generation, Prev: Checking for an alert, Up: Miscellaneous examples
5613 7.5.2 X.509 Certificate Parsing Example
5614 ---------------------------------------
5616 To demonstrate the X.509 parsing capabilities an example program is
5617 listed below. That program reads the peer's certificate, and prints
5618 information about it.
5620 /* This example code is placed in the public domain. */
5622 #ifdef HAVE_CONFIG_H
5628 #include <gnutls/gnutls.h>
5629 #include <gnutls/x509.h>
5631 #include "examples.h"
5634 bin2hex (const void *bin, size_t bin_size)
5636 static char printable[110];
5637 const unsigned char *_bin = bin;
5645 for (i = 0; i < bin_size; i++)
5647 sprintf (print, "%.2x ", _bin[i]);
5654 /* This function will print information about this session's peer
5658 print_x509_certificate_info (gnutls_session_t session)
5663 unsigned int algo, bits;
5664 time_t expiration_time, activation_time;
5665 const gnutls_datum_t *cert_list;
5666 unsigned int cert_list_size = 0;
5667 gnutls_x509_crt_t cert;
5668 gnutls_datum_t cinfo;
5670 /* This function only works for X.509 certificates.
5672 if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
5675 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
5677 printf ("Peer provided %d certificates.\n", cert_list_size);
5679 if (cert_list_size > 0)
5683 /* we only print information about the first certificate.
5685 gnutls_x509_crt_init (&cert);
5687 gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER);
5689 printf ("Certificate info:\n");
5691 /* This is the preferred way of printing short information about
5694 ret = gnutls_x509_crt_print (cert, GNUTLS_CRT_PRINT_ONELINE, &cinfo);
5697 printf ("\t%s\n", cinfo.data);
5698 gnutls_free (cinfo.data);
5701 /* If you want to extract fields manually for some other reason,
5702 below are popular example calls. */
5704 expiration_time = gnutls_x509_crt_get_expiration_time (cert);
5705 activation_time = gnutls_x509_crt_get_activation_time (cert);
5707 printf ("\tCertificate is valid since: %s", ctime (&activation_time));
5708 printf ("\tCertificate expires: %s", ctime (&expiration_time));
5710 /* Print the serial number of the certificate.
5712 size = sizeof (serial);
5713 gnutls_x509_crt_get_serial (cert, serial, &size);
5715 printf ("\tCertificate serial number: %s\n", bin2hex (serial, size));
5717 /* Extract some of the public key algorithm's parameters
5719 algo = gnutls_x509_crt_get_pk_algorithm (cert, &bits);
5721 printf ("Certificate public key: %s",
5722 gnutls_pk_algorithm_get_name (algo));
5724 /* Print the version of the X.509
5727 printf ("\tCertificate version: #%d\n",
5728 gnutls_x509_crt_get_version (cert));
5731 gnutls_x509_crt_get_dn (cert, dn, &size);
5732 printf ("\tDN: %s\n", dn);
5735 gnutls_x509_crt_get_issuer_dn (cert, dn, &size);
5736 printf ("\tIssuer's DN: %s\n", dn);
5738 gnutls_x509_crt_deinit (cert);
5744 File: gnutls.info, Node: Certificate request generation, Next: PKCS #12 structure generation, Prev: X.509 certificate parsing example, Up: Miscellaneous examples
5746 7.5.3 Certificate Request Generation
5747 ------------------------------------
5749 The following example is about generating a certificate request, and a
5750 private key. A certificate request can be later be processed by a CA,
5751 which should return a signed certificate.
5753 /* This example code is placed in the public domain. */
5755 #ifdef HAVE_CONFIG_H
5762 #include <gnutls/gnutls.h>
5763 #include <gnutls/x509.h>
5764 #include <gnutls/abstract.h>
5767 /* This example will generate a private key and a certificate
5774 gnutls_x509_crq_t crq;
5775 gnutls_x509_privkey_t key;
5776 gnutls_privkey_t pkey; /* object used for signing */
5777 unsigned char buffer[10 * 1024];
5778 size_t buffer_size = sizeof (buffer);
5781 gnutls_global_init ();
5783 /* Initialize an empty certificate request, and
5784 * an empty private key.
5786 gnutls_x509_crq_init (&crq);
5788 gnutls_x509_privkey_init (&key);
5789 gnutls_privkey_init (&pkey);
5791 /* Generate an RSA key of moderate security.
5793 bits = gnutls_sec_param_to_pk_bits (GNUTLS_PK_RSA, GNUTLS_SEC_PARAM_NORMAL);
5794 gnutls_x509_privkey_generate (key, GNUTLS_PK_RSA, bits, 0);
5796 /* Add stuff to the distinguished name
5798 gnutls_x509_crq_set_dn_by_oid (crq, GNUTLS_OID_X520_COUNTRY_NAME,
5801 gnutls_x509_crq_set_dn_by_oid (crq, GNUTLS_OID_X520_COMMON_NAME,
5802 0, "Nikos", strlen ("Nikos"));
5804 /* Set the request version.
5806 gnutls_x509_crq_set_version (crq, 1);
5808 /* Set a challenge password.
5810 gnutls_x509_crq_set_challenge_password (crq, "something to remember here");
5812 /* Associate the request with the private key
5814 gnutls_x509_crq_set_key (crq, key);
5816 /* Self sign the certificate request.
5818 gnutls_privkey_import_x509( pkey, key, 0);
5819 gnutls_x509_crq_privkey_sign (crq, pkey, GNUTLS_DIG_SHA1, 0);
5821 /* Export the PEM encoded certificate request, and
5824 gnutls_x509_crq_export (crq, GNUTLS_X509_FMT_PEM, buffer, &buffer_size);
5826 printf ("Certificate Request: \n%s", buffer);
5829 /* Export the PEM encoded private key, and
5832 buffer_size = sizeof (buffer);
5833 gnutls_x509_privkey_export (key, GNUTLS_X509_FMT_PEM, buffer, &buffer_size);
5835 printf ("\n\nPrivate key: \n%s", buffer);
5837 gnutls_x509_crq_deinit (crq);
5838 gnutls_x509_privkey_deinit (key);
5845 File: gnutls.info, Node: PKCS #12 structure generation, Prev: Certificate request generation, Up: Miscellaneous examples
5847 7.5.4 PKCS #12 Structure Generation
5848 -----------------------------------
5850 The following example is about generating a PKCS #12 structure.
5852 /* This example code is placed in the public domain. */
5854 #ifdef HAVE_CONFIG_H
5860 #include <gnutls/gnutls.h>
5861 #include <gnutls/pkcs12.h>
5863 #include "examples.h"
5865 #define OUTFILE "out.p12"
5867 /* This function will write a pkcs12 structure into a file.
5868 * cert: is a DER encoded certificate
5869 * pkcs8_key: is a PKCS #8 encrypted key (note that this must be
5870 * encrypted using a PKCS #12 cipher, or some browsers will crash)
5871 * password: is the password used to encrypt the PKCS #12 packet.
5874 write_pkcs12 (const gnutls_datum_t * cert,
5875 const gnutls_datum_t * pkcs8_key, const char *password)
5877 gnutls_pkcs12_t pkcs12;
5879 gnutls_pkcs12_bag_t bag, key_bag;
5880 char pkcs12_struct[10 * 1024];
5881 size_t pkcs12_struct_size;
5884 /* A good idea might be to use gnutls_x509_privkey_get_key_id()
5885 * to obtain a unique ID.
5887 gnutls_datum_t key_id = { (char *) "\x00\x00\x07", 3 };
5889 gnutls_global_init ();
5891 /* Firstly we create two helper bags, which hold the certificate,
5892 * and the (encrypted) key.
5895 gnutls_pkcs12_bag_init (&bag);
5896 gnutls_pkcs12_bag_init (&key_bag);
5898 ret = gnutls_pkcs12_bag_set_data (bag, GNUTLS_BAG_CERTIFICATE, cert);
5901 fprintf (stderr, "ret: %s\n", gnutls_strerror (ret));
5905 /* ret now holds the bag's index.
5909 /* Associate a friendly name with the given certificate. Used
5912 gnutls_pkcs12_bag_set_friendly_name (bag, bag_index, "My name");
5914 /* Associate the certificate with the key using a unique key
5917 gnutls_pkcs12_bag_set_key_id (bag, bag_index, &key_id);
5919 /* use weak encryption for the certificate.
5921 gnutls_pkcs12_bag_encrypt (bag, password, GNUTLS_PKCS_USE_PKCS12_RC2_40);
5926 ret = gnutls_pkcs12_bag_set_data (key_bag,
5927 GNUTLS_BAG_PKCS8_ENCRYPTED_KEY,
5931 fprintf (stderr, "ret: %s\n", gnutls_strerror (ret));
5935 /* Note that since the PKCS #8 key is already encrypted we don't
5936 * bother encrypting that bag.
5940 gnutls_pkcs12_bag_set_friendly_name (key_bag, bag_index, "My name");
5942 gnutls_pkcs12_bag_set_key_id (key_bag, bag_index, &key_id);
5945 /* The bags were filled. Now create the PKCS #12 structure.
5947 gnutls_pkcs12_init (&pkcs12);
5949 /* Insert the two bags in the PKCS #12 structure.
5952 gnutls_pkcs12_set_bag (pkcs12, bag);
5953 gnutls_pkcs12_set_bag (pkcs12, key_bag);
5956 /* Generate a message authentication code for the PKCS #12
5959 gnutls_pkcs12_generate_mac (pkcs12, password);
5961 pkcs12_struct_size = sizeof (pkcs12_struct);
5963 gnutls_pkcs12_export (pkcs12, GNUTLS_X509_FMT_DER, pkcs12_struct,
5964 &pkcs12_struct_size);
5967 fprintf (stderr, "ret: %s\n", gnutls_strerror (ret));
5971 fd = fopen (OUTFILE, "w");
5974 fprintf (stderr, "cannot open file\n");
5977 fwrite (pkcs12_struct, 1, pkcs12_struct_size, fd);
5980 gnutls_pkcs12_bag_deinit (bag);
5981 gnutls_pkcs12_bag_deinit (key_bag);
5982 gnutls_pkcs12_deinit (pkcs12);
5988 File: gnutls.info, Node: Parameter generation, Next: Keying Material Exporters, Prev: Miscellaneous examples, Up: How to use GnuTLS in applications
5990 7.6 Parameter generation
5991 ========================
5993 Several TLS ciphersuites require additional parameters that need to be
5994 generated or provided by the application. The Diffie-Hellman based
5995 ciphersuites (ANON-DH or DHE), require the group information to be
5996 provided. This information can be either be generated on the fly using
5997 *note gnutls_dh_params_generate2:: or imported from some pregenerated
5998 value using *note gnutls_dh_params_import_pkcs3::. The parameters can
5999 be used in a session by calling *note gnutls_certificate_set_dh_params::
6000 or *note gnutls_anon_set_server_dh_params:: for anonymous sessions.
6002 Due to the time-consuming calculations required for the generation of
6003 Diffie-Hellman parameters we suggest against performing generation of
6004 them within an application. The 'certtool' tool can be used to generate
6005 or export known safe values that can be stored in code or in a
6006 configuration file to provide the ability to replace. We also recommend
6007 the usage of *note gnutls_sec_param_to_pk_bits:: to determine the bit
6008 size of the parameters to be generated.
6010 The ciphersuites that involve the RSA-EXPORT key exchange require
6011 additional parameters. Those ciphersuites are rarely used today because
6012 they are by design insecure, thus if you have no requirement for them,
6013 this section should be skipped. The RSA-EXPORT key exchange requires
6014 512-bit RSA keys to be generated. It is recommended those parameters to
6015 be refreshed (regenerated) in short intervals. The following functions
6016 can be used for these parameters.
6018 * *note gnutls_rsa_params_generate2::
6020 * *note gnutls_certificate_set_rsa_export_params::
6022 * *note gnutls_rsa_params_import_pkcs1::
6024 * *note gnutls_rsa_params_export_pkcs1::
6027 File: gnutls.info, Node: Keying Material Exporters, Next: Channel Bindings, Prev: Parameter generation, Up: How to use GnuTLS in applications
6029 7.7 Keying Material Exporters
6030 =============================
6032 The TLS PRF can be used by other protocols to derive data. The API to
6033 use is *note gnutls_prf::. The function needs to be provided with the
6034 label in the parameter 'label', and the extra data to mix in the 'extra'
6035 parameter. Depending on whether you want to mix in the client or server
6036 random data first, you can set the 'server_random_first' parameter.
6038 For example, after establishing a TLS session using *note
6039 gnutls_handshake::, you can invoke the TLS PRF with this call:
6041 #define MYLABEL "EXPORTER-FOO"
6042 #define MYCONTEXT "some context data"
6044 rc = gnutls_prf (session, strlen (MYLABEL), MYLABEL, 0,
6045 strlen (MYCONTEXT), MYCONTEXT, 32, out);
6047 If you don't want to mix in the client/server random, there is a more
6048 low-level TLS PRF interface called *note gnutls_prf_raw::.
6051 File: gnutls.info, Node: Channel Bindings, Next: Compatibility with the OpenSSL library, Prev: Keying Material Exporters, Up: How to use GnuTLS in applications
6053 7.8 Channel Bindings
6054 ====================
6056 In user authentication protocols (e.g., EAP or SASL mechanisms) it is
6057 useful to have a unique string that identifies the secure channel that
6058 is used, to bind together the user authentication with the secure
6059 channel. This can protect against man-in-the-middle attacks in some
6060 situations. The unique strings is a "channel bindings". For background
6061 and more discussion see [RFC5056] (*note Bibliography::).
6063 You can extract a channel bindings using the *note
6064 gnutls_session_channel_binding:: function. Currently only the
6065 'GNUTLS_CB_TLS_UNIQUE' type is supported, which corresponds to the
6066 'tls-unique' channel bindings for TLS defined in [RFC5929] (*note
6069 The following example describes how to print the channel binding data.
6070 Note that it must be run after a successful TLS handshake.
6076 rc = gnutls_session_channel_binding (session,
6077 GNUTLS_CB_TLS_UNIQUE,
6080 fprintf (stderr, "Channel binding error: %s\n",
6081 gnutls_strerror (rc));
6085 printf ("- Channel binding 'tls-unique': ");
6086 for (i = 0; i < cb.size; i++)
6087 printf ("%02x", cb.data[i]);
6093 File: gnutls.info, Node: Compatibility with the OpenSSL library, Prev: Channel Bindings, Up: How to use GnuTLS in applications
6095 7.9 Compatibility with the OpenSSL Library
6096 ==========================================
6098 To ease GnuTLS' integration with existing applications, a compatibility
6099 layer with the widely used OpenSSL library is included in the
6100 'gnutls-openssl' library. This compatibility layer is not complete and
6101 it is not intended to completely reimplement the OpenSSL API with
6102 GnuTLS. It only provides source-level compatibility. There is
6103 currently no attempt to make it binary-compatible with OpenSSL.
6105 The prototypes for the compatibility functions are in the
6106 'gnutls/openssl.h' header file.
6108 Current limitations imposed by the compatibility layer include:
6110 * Error handling is not thread safe.
6113 File: gnutls.info, Node: Included programs, Next: Function reference, Prev: How to use GnuTLS in applications, Up: Top
6118 Included with GnuTLS are also a few command line tools that let you use
6119 the library for common tasks without writing an application. The
6120 applications are discussed in this chapter.
6124 * Invoking certtool::
6125 * Invoking gnutls-cli::
6126 * Invoking gnutls-cli-debug::
6127 * Invoking gnutls-serv::
6128 * Invoking psktool::
6129 * Invoking srptool::
6130 * Invoking p11tool::
6133 File: gnutls.info, Node: Invoking certtool, Next: Invoking gnutls-cli, Up: Included programs
6135 8.1 Invoking certtool
6136 =====================
6138 This is a program to generate X.509 certificates, certificate requests,
6139 CRLs and private keys.
6142 Usage: certtool [options]
6143 -s, --generate-self-signed
6144 Generate a self-signed certificate.
6145 -c, --generate-certificate
6146 Generate a signed certificate.
6147 --generate-proxy Generate a proxy certificate.
6148 --generate-crl Generate a CRL.
6149 -u, --update-certificate
6150 Update a signed certificate.
6151 -p, --generate-privkey Generate a private key.
6152 -q, --generate-request Generate a PKCS #10 certificate
6154 -e, --verify-chain Verify a PEM encoded certificate chain.
6155 The last certificate in the chain must
6156 be a self signed one.
6157 --verify-crl Verify a CRL.
6158 --generate-dh-params Generate PKCS #3 encoded Diffie-Hellman
6160 --get-dh-params Get the included PKCS #3 encoded Diffie
6162 --load-privkey FILE Private key file to use.
6163 --load-request FILE Certificate request file to use.
6164 --load-certificate FILE
6165 Certificate file to use.
6166 --load-ca-privkey FILE Certificate authority's private key
6168 --load-ca-certificate FILE
6169 Certificate authority's certificate
6171 --password PASSWORD Password to use.
6172 -i, --certificate-info Print information on a certificate.
6173 -l, --crl-info Print information on a CRL.
6174 --p12-info Print information on a PKCS #12
6176 --p7-info Print information on a PKCS #7
6178 --smime-to-p7 Convert S/MIME to PKCS #7 structure.
6179 -k, --key-info Print information on a private key.
6180 --fix-key Regenerate the parameters in a private
6182 --to-p12 Generate a PKCS #12 structure.
6183 -8, --pkcs8 Use PKCS #8 format for private keys.
6185 --hash STR Hash algorithm to use for signing
6187 --export-ciphers Use weak encryption algorithms.
6188 --inder Use DER format for input certificates
6190 --outder Use DER format for output certificates
6192 --bits BITS specify the number of bits for key
6194 --outfile FILE Output file.
6195 --infile FILE Input file.
6196 --template FILE Template file to use for non
6197 interactive operation.
6198 -d, --debug LEVEL specify the debug level. Default is 1.
6199 -h, --help shows this help text
6200 -v, --version shows the program's version
6202 The program can be used interactively or non interactively by specifying
6203 the '--template' command line option. See below for an example of a
6206 How to use certtool interactively:
6208 * To generate parameters for Diffie-Hellman key exchange, use the
6210 $ certtool --generate-dh-params --outfile dh.pem
6212 * To generate parameters for the RSA-EXPORT key exchange, use the
6214 $ certtool --generate-privkey --bits 512 --outfile rsa.pem
6216 * To create a self signed certificate, use the command:
6217 $ certtool --generate-privkey --outfile ca-key.pem
6218 $ certtool --generate-self-signed --load-privkey ca-key.pem \
6219 --outfile ca-cert.pem
6221 Note that a self-signed certificate usually belongs to a
6222 certificate authority, that signs other certificates.
6224 * To create a private key (RSA by default), run:
6226 $ certtool --generate-privkey --outfile key.pem
6228 To create a DSA private key, run:
6230 $ certtool --dsa --generate-privkey --outfile key-dsa.pem
6232 * To generate a certificate using the private key, use the command:
6234 $ certtool --generate-certificate --load-privkey key.pem \
6235 --outfile cert.pem --load-ca-certificate ca-cert.pem \
6236 --load-ca-privkey ca-key.pem
6238 * To create a certificate request (needed when the certificate is
6239 issued by another party), run:
6241 $ certtool --generate-request --load-privkey key.pem \
6242 --outfile request.pem
6244 * To generate a certificate using the previous request, use the
6247 $ certtool --generate-certificate --load-request request.pem \
6248 --outfile cert.pem \
6249 --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
6251 * To view the certificate information, use:
6253 $ certtool --certificate-info --infile cert.pem
6255 * To generate a PKCS #12 structure using the previous key and
6256 certificate, use the command:
6258 $ certtool --load-certificate cert.pem --load-privkey key.pem \
6259 --to-p12 --outder --outfile key.p12
6261 Some tools (reportedly web browsers) have problems with that file
6262 because it does not contain the CA certificate for the certificate.
6263 To work around that problem in the tool, you can use the
6264 '--load-ca-certificate' parameter as follows:
6266 $ certtool --load-ca-certificate ca.pem \
6267 --load-certificate cert.pem --load-privkey key.pem \
6268 --to-p12 --outder --outfile key.p12
6270 * Proxy certificate can be used to delegate your credential to a
6271 temporary, typically short-lived, certificate. To create one from
6272 the previously created certificate, first create a temporary key
6273 and then generate a proxy certificate for it, using the commands:
6275 $ certtool --generate-privkey > proxy-key.pem
6276 $ certtool --generate-proxy --load-ca-privkey key.pem \
6277 --load-privkey proxy-key.pem --load-certificate cert.pem \
6278 --outfile proxy-cert.pem
6280 * To create an empty Certificate Revocation List (CRL) do:
6282 $ certtool --generate-crl --load-ca-privkey x509-ca-key.pem --load-ca-certificate x509-ca.pem
6284 To create a CRL that contains some revoked certificates, place the
6285 certificates in a file and use '--load-certificate' as follows:
6287 $ certtool --generate-crl --load-ca-privkey x509-ca-key.pem --load-ca-certificate x509-ca.pem --load-certificate revoked-certs.pem
6289 * To verify a Certificate Revocation List (CRL) do:
6291 $ certtool --verify-crl --load-ca-certificate x509-ca.pem < crl.pem
6293 Certtool's template file format:
6295 * Firstly create a file named 'cert.cfg' that contains the
6296 information about the certificate. An example file is listed
6301 $ certtool --generate-certificate cert.pem --load-privkey key.pem \
6302 --template cert.cfg \
6303 --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
6305 An example certtool template file:
6307 # X.509 Certificate options
6311 # The organization of the subject.
6312 organization = "Koko inc."
6314 # The organizational unit of the subject.
6315 unit = "sleeping dept."
6317 # The locality of the subject.
6320 # The state of the certificate owner.
6323 # The country of the subject. Two letter code.
6326 # The common name of the certificate owner.
6329 # A user id of the certificate owner.
6332 # If the supported DN OIDs are not adequate you can set
6334 # For example set the X.520 Title and the X.520 Pseudonym
6335 # by using OID and string pairs.
6336 #dn_oid = "2.5.4.12" "Dr." "2.5.4.65" "jackal"
6338 # This is deprecated and should not be used in new
6340 # pkcs9_email = "none@none.org"
6342 # The serial number of the certificate
6345 # In how many days, counting from today, this certificate will expire.
6346 expiration_days = 700
6348 # X.509 v3 extensions
6350 # A dnsname in case of a WWW server.
6351 #dns_name = "www.none.org"
6352 #dns_name = "www.morethanone.org"
6354 # An IP address in case of a server.
6355 #ip_address = "192.168.1.1"
6357 # An email in case of a person
6358 email = "none@none.org"
6360 # An URL that has CRLs (certificate revocation lists)
6361 # available. Needed in CA certificates.
6362 #crl_dist_points = "http://www.getcrl.crl/getcrl/"
6364 # Whether this is a CA certificate or not
6367 # Whether this certificate will be used for a TLS client
6370 # Whether this certificate will be used for a TLS server
6373 # Whether this certificate will be used to sign data (needed
6374 # in TLS DHE ciphersuites).
6377 # Whether this certificate will be used to encrypt data (needed
6378 # in TLS RSA ciphersuites). Note that it is preferred to use different
6379 # keys for encryption and signing.
6382 # Whether this key will be used to sign other certificates.
6385 # Whether this key will be used to sign CRLs.
6388 # Whether this key will be used to sign code.
6391 # Whether this key will be used to sign OCSP data.
6394 # Whether this key will be used for time stamping.
6397 # Whether this key will be used for IPsec IKE operations.
6401 File: gnutls.info, Node: Invoking gnutls-cli, Next: Invoking gnutls-cli-debug, Prev: Invoking certtool, Up: Included programs
6403 8.2 Invoking gnutls-cli
6404 =======================
6406 Simple client program to set up a TLS connection to some other computer.
6407 It sets up a TLS connection and forwards data from the standard input to
6408 the secured socket and vice versa.
6411 Usage: gnutls-cli [options] hostname
6413 -d, --debug integer Enable debugging
6414 -r, --resume Connect, establish a session. Connect
6415 again and resume this session.
6416 -s, --starttls Connect, establish a plain session and
6417 start TLS when EOF or a SIGALRM is
6419 --crlf Send CR LF instead of LF.
6420 --x509fmtder Use DER format for certificates to read
6422 -f, --fingerprint Send the openpgp fingerprint, instead
6424 --disable-extensions Disable all the TLS extensions.
6425 --print-cert Print the certificate in PEM format.
6426 --recordsize integer The maximum record size to advertize.
6427 -V, --verbose More verbose output.
6428 --ciphers cipher1 cipher2...
6430 --protocols protocol1 protocol2...
6431 Protocols to enable.
6432 --comp comp1 comp2... Compression methods to enable.
6433 --macs mac1 mac2... MACs to enable.
6434 --kx kx1 kx2... Key exchange methods to enable.
6435 --ctypes certType1 certType2...
6436 Certificate types to enable.
6437 --priority PRIORITY STRING
6439 --x509cafile FILE Certificate file to use.
6440 --x509crlfile FILE CRL file to use.
6441 --pgpkeyfile FILE PGP Key file to use.
6442 --pgpkeyring FILE PGP Key ring file to use.
6443 --pgpcertfile FILE PGP Public Key (certificate) file to
6445 --pgpsubkey HEX|auto PGP subkey to use.
6446 --x509keyfile FILE X.509 key file to use.
6447 --x509certfile FILE X.509 Certificate file to use.
6448 --srpusername NAME SRP username to use.
6449 --srppasswd PASSWD SRP password to use.
6450 --pskusername NAME PSK username to use.
6451 --pskkey KEY PSK key (in hex) to use.
6452 --opaque-prf-input DATA
6453 Use Opaque PRF Input DATA.
6454 -p, --port PORT The port to connect to.
6455 --insecure Don't abort program if server
6456 certificate can't be validated.
6457 -l, --list Print a list of the supported
6458 algorithms and modes.
6459 -h, --help prints this help
6460 -v, --version prints the program's version number
6462 To connect to a server using PSK authentication, you may use something
6465 $ gnutls-cli -p 5556 test.gnutls.org --pskusername jas --pskkey 9e32cf7786321a828ef7668f09fb35db --priority NORMAL:+DHE-PSK:+PSK:-RSA:-DHE-RSA -d 4711
6469 * Example client PSK connection::
6472 File: gnutls.info, Node: Example client PSK connection, Up: Invoking gnutls-cli
6474 8.2.1 Example client PSK connection
6475 -----------------------------------
6477 If your server only supports the PSK ciphersuite, connecting to it
6478 should be as simple as connecting to the server:
6480 $ ./gnutls-cli -p 5556 localhost
6481 Resolving 'localhost'...
6482 Connecting to '127.0.0.1:5556'...
6483 - PSK client callback.
6484 Enter PSK identity: psk_identity
6486 - PSK authentication.
6489 - Cipher: AES-128-CBC
6492 - Handshake was completed
6494 - Simple Client Mode:
6496 If the server supports several cipher suites, you may need to force it
6497 to chose PSK by using a cipher priority parameter such as '--priority
6498 NORMAL:+PSK:-RSA:-DHE-RSA:-DHE-PSK'.
6500 Instead of using the Netconf-way to derive the PSK key from a password,
6501 you can also give the PSK username and key directly on the command line:
6503 $ ./gnutls-cli -p 5556 localhost --pskusername psk_identity --pskkey 88f3824b3e5659f52d00e959bacab954b6540344 --priority NORMAL:+DHE-PSK:+PSK
6504 Resolving 'localhost'...
6505 Connecting to '127.0.0.1:5556'...
6506 - PSK authentication.
6509 - Cipher: AES-128-CBC
6512 - Handshake was completed
6514 - Simple Client Mode:
6516 By keeping the '--pskusername' parameter and removing the '--pskkey'
6517 parameter, it will query only for the password during the handshake.
6520 File: gnutls.info, Node: Invoking gnutls-cli-debug, Next: Invoking gnutls-serv, Prev: Invoking gnutls-cli, Up: Included programs
6522 8.3 Invoking gnutls-cli-debug
6523 =============================
6525 This program was created to assist in debugging GnuTLS, but it might be
6526 useful to extract a TLS server's capabilities. It's purpose is to
6527 connect onto a TLS server, perform some tests and print the server's
6528 capabilities. If called with the '-v' parameter a more checks will be
6529 performed. An example output is:
6531 crystal:/cvs/gnutls/src$ ./gnutls-cli-debug localhost -p 5556
6532 Resolving 'localhost'...
6533 Connecting to '127.0.0.1:5556'...
6534 Checking for TLS 1.1 support... yes
6535 Checking fallback from TLS 1.1 to... N/A
6536 Checking for TLS 1.0 support... yes
6537 Checking for SSL 3.0 support... yes
6538 Checking for version rollback bug in RSA PMS... no
6539 Checking for version rollback bug in Client Hello... no
6540 Checking whether we need to disable TLS 1.0... N/A
6541 Checking whether the server ignores the RSA PMS version... no
6542 Checking whether the server can accept Hello Extensions... yes
6543 Checking whether the server can accept cipher suites not in SSL 3.0 spec... yes
6544 Checking whether the server can accept a bogus TLS record version in the client hello... yes
6545 Checking for certificate information... N/A
6546 Checking for trusted CAs... N/A
6547 Checking whether the server understands TLS closure alerts... yes
6548 Checking whether the server supports session resumption... yes
6549 Checking for export-grade ciphersuite support... no
6550 Checking RSA-export ciphersuite info... N/A
6551 Checking for anonymous authentication support... no
6552 Checking anonymous Diffie-Hellman group info... N/A
6553 Checking for ephemeral Diffie-Hellman support... no
6554 Checking ephemeral Diffie-Hellman group info... N/A
6555 Checking for AES cipher support (TLS extension)... yes
6556 Checking for 3DES cipher support... yes
6557 Checking for ARCFOUR 128 cipher support... yes
6558 Checking for ARCFOUR 40 cipher support... no
6559 Checking for MD5 MAC support... yes
6560 Checking for SHA1 MAC support... yes
6561 Checking for ZLIB compression support (TLS extension)... yes
6562 Checking for LZO compression support (GnuTLS extension)... yes
6563 Checking for max record size (TLS extension)... yes
6564 Checking for SRP authentication support (TLS extension)... yes
6565 Checking for OpenPGP authentication support (TLS extension)... no
6568 File: gnutls.info, Node: Invoking gnutls-serv, Next: Invoking psktool, Prev: Invoking gnutls-cli-debug, Up: Included programs
6570 8.4 Invoking gnutls-serv
6571 ========================
6573 Simple server program that listens to incoming TLS connections.
6576 Usage: gnutls-serv [options]
6578 -d, --debug integer Enable debugging
6579 -g, --generate Generate Diffie-Hellman Parameters.
6580 -p, --port integer The port to connect to.
6581 -q, --quiet Suppress some messages.
6582 --nodb Does not use the resume database.
6583 --http Act as an HTTP Server.
6584 --echo Act as an Echo Server.
6585 --dhparams FILE DH params file to use.
6586 --x509fmtder Use DER format for certificates
6587 --x509cafile FILE Certificate file to use.
6588 --x509crlfile FILE CRL file to use.
6589 --pgpkeyring FILE PGP Key ring file to use.
6590 --pgpkeyfile FILE PGP Key file to use.
6591 --pgpcertfile FILE PGP Public Key (certificate) file to
6593 --pgpsubkey HEX|auto PGP subkey to use.
6594 --x509keyfile FILE X.509 key file to use.
6595 --x509certfile FILE X.509 Certificate file to use.
6596 --x509dsakeyfile FILE Alternative X.509 key file to use.
6597 --x509dsacertfile FILE Alternative X.509 certificate file to
6599 -r, --require-cert Require a valid certificate.
6600 -a, --disable-client-cert
6601 Disable request for a client
6603 --pskpasswd FILE PSK password file to use.
6604 --pskhint HINT PSK identity hint to use.
6605 --srppasswd FILE SRP password file to use.
6606 --srppasswdconf FILE SRP password conf file to use.
6607 --opaque-prf-input DATA
6608 Use Opaque PRF Input DATA.
6609 --ciphers cipher1 cipher2...
6611 --protocols protocol1 protocol2...
6612 Protocols to enable.
6613 --comp comp1 comp2... Compression methods to enable.
6614 --macs mac1 mac2... MACs to enable.
6615 --kx kx1 kx2... Key exchange methods to enable.
6616 --ctypes certType1 certType2...
6617 Certificate types to enable.
6618 --priority PRIORITY STRING
6620 -l, --list Print a list of the supported
6621 algorithms and modes.
6622 -h, --help prints this help
6623 -v, --version prints the program's version number
6625 8.4.1 Setting Up a Test HTTPS Server
6626 ------------------------------------
6628 Running your own TLS server based on GnuTLS can be useful when debugging
6629 clients and/or GnuTLS itself. This section describes how to use
6630 'gnutls-serv' as a simple HTTPS server.
6632 The most basic server can be started as:
6636 It will only support anonymous ciphersuites, which many TLS clients
6639 The next step is to add support for X.509. First we generate a CA:
6641 certtool --generate-privkey > x509-ca-key.pem
6642 echo 'cn = GnuTLS test CA' > ca.tmpl
6643 echo 'ca' >> ca.tmpl
6644 echo 'cert_signing_key' >> ca.tmpl
6645 certtool --generate-self-signed --load-privkey x509-ca-key.pem \
6646 --template ca.tmpl --outfile x509-ca.pem
6649 Then generate a server certificate. Remember to change the dns_name
6650 value to the name of your server host, or skip that command to avoid the
6653 certtool --generate-privkey > x509-server-key.pem
6654 echo 'organization = GnuTLS test server' > server.tmpl
6655 echo 'cn = test.gnutls.org' >> server.tmpl
6656 echo 'tls_www_server' >> server.tmpl
6657 echo 'encryption_key' >> server.tmpl
6658 echo 'signing_key' >> server.tmpl
6659 echo 'dns_name = test.gnutls.org' >> server.tmpl
6660 certtool --generate-certificate --load-privkey x509-server-key.pem \
6661 --load-ca-certificate x509-ca.pem --load-ca-privkey x509-ca-key.pem \
6662 --template server.tmpl --outfile x509-server.pem
6665 For use in the client, you may want to generate a client certificate as
6668 certtool --generate-privkey > x509-client-key.pem
6669 echo 'cn = GnuTLS test client' > client.tmpl
6670 echo 'tls_www_client' >> client.tmpl
6671 echo 'encryption_key' >> client.tmpl
6672 echo 'signing_key' >> client.tmpl
6673 certtool --generate-certificate --load-privkey x509-client-key.pem \
6674 --load-ca-certificate x509-ca.pem --load-ca-privkey x509-ca-key.pem \
6675 --template client.tmpl --outfile x509-client.pem
6678 To be able to import the client key/certificate into some applications,
6679 you will need to convert them into a PKCS#12 structure. This also
6680 encrypts the security sensitive key with a password.
6682 certtool --to-p12 --load-ca-certificate x509-ca.pem --load-privkey x509-client-key.pem --load-certificate x509-client.pem --outder --outfile x509-client.p12
6684 For icing, we'll create a proxy certificate for the client too.
6686 certtool --generate-privkey > x509-proxy-key.pem
6687 echo 'cn = GnuTLS test client proxy' > proxy.tmpl
6688 certtool --generate-proxy --load-privkey x509-proxy-key.pem \
6689 --load-ca-certificate x509-client.pem --load-ca-privkey x509-client-key.pem \
6690 --load-certificate x509-client.pem --template proxy.tmpl \
6691 --outfile x509-proxy.pem
6694 Then start the server again:
6696 gnutls-serv --http \
6697 --x509cafile x509-ca.pem \
6698 --x509keyfile x509-server-key.pem \
6699 --x509certfile x509-server.pem
6701 Try connecting to the server using your web browser. Note that the
6702 server listens to port 5556 by default.
6704 While you are at it, to allow connections using DSA, you can also create
6705 a DSA key and certificate for the server. These credentials will be
6706 used in the final example below.
6708 certtool --generate-privkey --dsa > x509-server-key-dsa.pem
6709 certtool --generate-certificate --load-privkey x509-server-key-dsa.pem \
6710 --load-ca-certificate x509-ca.pem --load-ca-privkey x509-ca-key.pem \
6711 --template server.tmpl --outfile x509-server-dsa.pem
6714 The next step is to create OpenPGP credentials for the server.
6717 ...enter whatever details you want, use 'test.gnutls.org' as name...
6719 Make a note of the OpenPGP key identifier of the newly generated key,
6720 here it was '5D1D14D8'. You will need to export the key for GnuTLS to
6723 gpg -a --export 5D1D14D8 > openpgp-server.txt
6724 gpg --export 5D1D14D8 > openpgp-server.bin
6725 gpg --export-secret-keys 5D1D14D8 > openpgp-server-key.bin
6726 gpg -a --export-secret-keys 5D1D14D8 > openpgp-server-key.txt
6728 Let's start the server with support for OpenPGP credentials:
6730 gnutls-serv --http \
6731 --pgpkeyfile openpgp-server-key.txt \
6732 --pgpcertfile openpgp-server.txt
6734 The next step is to add support for SRP authentication.
6736 srptool --create-conf srp-tpasswd.conf
6737 srptool --passwd-conf srp-tpasswd.conf --username jas --passwd srp-passwd.txt
6738 Enter password: [TYPE "foo"]
6740 Start the server with SRP support:
6742 gnutls-serv --http \
6743 --srppasswdconf srp-tpasswd.conf \
6744 --srppasswd srp-passwd.txt
6746 Let's also add support for PSK.
6748 $ psktool --passwd psk-passwd.txt
6750 Start the server with PSK support:
6752 gnutls-serv --http \
6753 --pskpasswd psk-passwd.txt
6755 Finally, we start the server with all the earlier parameters and you get
6758 gnutls-serv --http \
6759 --x509cafile x509-ca.pem \
6760 --x509keyfile x509-server-key.pem \
6761 --x509certfile x509-server.pem \
6762 --x509dsakeyfile x509-server-key-dsa.pem \
6763 --x509dsacertfile x509-server-dsa.pem \
6764 --pgpkeyfile openpgp-server-key.txt \
6765 --pgpcertfile openpgp-server.txt \
6766 --srppasswdconf srp-tpasswd.conf \
6767 --srppasswd srp-passwd.txt \
6768 --pskpasswd psk-passwd.txt
6772 * Example server PSK connection::
6775 File: gnutls.info, Node: Example server PSK connection, Up: Invoking gnutls-serv
6777 8.4.2 Example server PSK connection
6778 -----------------------------------
6780 To set up a PSK server with 'gnutls-serv' you need to create PSK
6781 password file (*note Invoking psktool::). In the example below, I type
6782 'password' at the prompt.
6784 $ ./psktool -u psk_identity -p psks.txt
6786 Key stored to psks.txt
6788 psk_identity:88f3824b3e5659f52d00e959bacab954b6540344
6791 After this, start the server pointing to the password file. We disable
6794 $ ./gnutls-serv --pskpasswd psks.txt --pskhint psk_identity_hint --priority NORMAL:-DHE-PSK
6795 Set static Diffie-Hellman parameters, consider --dhparams.
6796 Echo Server ready. Listening to port '5556'.
6798 You can now connect to the server using a PSK client (*note Example
6799 client PSK connection::).
6802 File: gnutls.info, Node: Invoking psktool, Next: Invoking srptool, Prev: Invoking gnutls-serv, Up: Included programs
6804 8.5 Invoking psktool
6805 ====================
6807 This is a program to manage PSK username and keys.
6810 Usage : psktool [options]
6811 -u, --username username
6813 -p, --passwd FILE specify a password file.
6814 -n, --netconf-hint HINT
6815 derive key from Netconf password, using
6816 HINT as the psk_identity_hint.
6817 -s, --keysize SIZE specify the key size in bytes.
6818 -v, --version prints the program's version number
6819 -h, --help shows this help text
6821 Normally the file will generate random keys for the indicate username.
6822 You may also derive PSK keys from passwords, using the algorithm
6823 specified in 'draft-ietf-netconf-tls-02.txt'. The algorithm needs a PSK
6824 identity hint, which you specify using '--netconf-hint'. To derive a
6825 PSK key from a password with an empty PSK identity hint, using
6826 '--netconf-hint ""'.
6829 File: gnutls.info, Node: Invoking srptool, Next: Invoking p11tool, Prev: Invoking psktool, Up: Included programs
6831 8.6 Invoking srptool
6832 ====================
6834 The 'srptool' is a very simple program that emulates the programs in the
6835 _Stanford SRP libraries_, see 'http://srp.stanford.edu/'. It is
6836 intended for use in places where you don't expect SRP authentication to
6837 be the used for system users.
6839 Traditionally _libsrp_ used two files. One called 'tpasswd' which holds
6840 usernames and verifiers, and 'tpasswd.conf' which holds generators and
6845 * To create tpasswd.conf which holds the g and n values for SRP
6846 protocol (generator and a large prime), run:
6848 $ srptool --create-conf /etc/tpasswd.conf
6850 * This command will create /etc/tpasswd and will add user 'test' (you
6851 will also be prompted for a password). Verifiers are stored by
6852 default in the way libsrp expects.
6854 $ srptool --passwd /etc/tpasswd \
6855 --passwd-conf /etc/tpasswd.conf -u test
6857 * This command will check against a password. If the password
6858 matches the one in /etc/tpasswd you will get an ok.
6860 $ srptool --passwd /etc/tpasswd \
6861 --passwd-conf /etc/tpasswd.conf --verify -u test
6864 File: gnutls.info, Node: Invoking p11tool, Prev: Invoking srptool, Up: Included programs
6866 8.7 Invoking p11tool
6867 ====================
6869 The 'p11tool' is a program that helps with accessing tokens and security
6870 modules that support the PKCS #11 API. It requires the individual PKCS
6871 #11 modules to be loaded either with the '--provider' option, or by
6872 setting up the GnuTLS configuration file for PKCS #11 as in *note
6876 Usage: p11tool [options]
6878 --export URL Export an object specified by a pkcs11
6880 --list-tokens List all available tokens
6881 --list-mechanisms URL List all available mechanisms in token.
6882 --list-all List all objects specified by a PKCS#11
6884 --list-all-certs List all certificates specified by a
6886 --list-certs List certificates that have a private
6887 key specified by a PKCS#11 URL
6888 --list-privkeys List private keys specified by a
6890 --list-trusted List certificates marked as trusted,
6891 specified by a PKCS#11 URL
6892 --initialize URL Initializes a PKCS11 token.
6893 --write URL Writes loaded certificates, private or
6894 secret keys to a PKCS11 token.
6895 --delete URL Deletes objects matching the URL.
6896 --label label Sets a label for the write operation.
6897 --trusted Marks the certificate to be imported as
6899 --login Force login to token
6900 --detailed-url Export detailed URLs.
6901 --no-detailed-url Export less detailed URLs.
6902 --secret-key HEX_KEY Provide a hex encoded secret key.
6903 --load-privkey FILE Private key file to use.
6904 --load-pubkey FILE Private key file to use.
6905 --load-certificate FILE
6906 Certificate file to use.
6907 -8, --pkcs8 Use PKCS #8 format for private keys.
6908 --inder Use DER format for input certificates
6910 --inraw Use RAW/DER format for input
6911 certificates and private keys.
6912 --provider Library Specify the pkcs11 provider library
6913 --outfile FILE Output file.
6914 -d, --debug LEVEL specify the debug level. Default is 1.
6915 -h, --help shows this help text
6917 After being provided the available PKCS #11 modules, it can list all
6918 tokens available in your system, the objects on the tokens, and perform
6921 Some examples on how to use p11tool:
6924 $ p11tool --list-tokens
6927 $ p11tool --login --list-all
6929 * To export an object
6930 $ p11tool --login --export pkcs11:(OBJECT URL)
6932 * To copy an object to a token
6933 $ p11tool --login --write pkcs11:(TOKEN URL) --load-certificate (certificate file) --label "my_cert"
6935 Note that typically PKCS #11 private key objects are not allowed to be
6936 extracted from the token.
6939 File: gnutls.info, Node: Function reference, Next: All the supported ciphersuites in GnuTLS, Prev: Included programs, Up: Top
6941 9 Function Reference
6942 ********************
6947 * X.509 certificate functions::
6948 * GnuTLS-extra functions::
6949 * OpenPGP functions::
6950 * TLS Inner Application (TLS/IA) functions::
6951 * Error codes and descriptions::
6954 File: gnutls.info, Node: Core functions, Next: X.509 certificate functions, Up: Function reference
6959 The prototypes for the following functions lie in 'gnutls/gnutls.h'.
6961 gnutls_alert_get_name
6962 ---------------------
6964 -- Function: const char * gnutls_alert_get_name
6965 (gnutls_alert_description_t ALERT)
6966 ALERT: is an alert number 'gnutls_session_t' structure.
6968 This function will return a string that describes the given alert
6969 number, or 'NULL'. See 'gnutls_alert_get()'.
6971 *Returns:* string corresponding to 'gnutls_alert_description_t'
6977 -- Function: gnutls_alert_description_t gnutls_alert_get
6978 (gnutls_session_t SESSION)
6979 SESSION: is a 'gnutls_session_t' structure.
6981 This function will return the last alert number received. This
6982 function should be called if 'GNUTLS_E_WARNING_ALERT_RECEIVED' or
6983 'GNUTLS_E_FATAL_ALERT_RECEIVED' has been returned by a gnutls
6984 function. The peer may send alerts if he thinks some things were
6985 not right. Check gnutls.h for the available alert descriptions.
6987 If no alert has been received the returned value is undefined.
6989 *Returns:* returns the last alert received, a
6990 'gnutls_alert_description_t' value.
6992 gnutls_alert_send_appropriate
6993 -----------------------------
6995 -- Function: int gnutls_alert_send_appropriate (gnutls_session_t
6997 SESSION: is a 'gnutls_session_t' structure.
7001 Sends an alert to the peer depending on the error code returned by
7002 a gnutls function. This function will call
7003 'gnutls_error_to_alert()' to determine the appropriate alert to
7006 This function may also return 'GNUTLS_E_AGAIN', or
7007 'GNUTLS_E_INTERRUPTED'.
7009 If the return value is 'GNUTLS_E_INVALID_REQUEST', then no alert
7010 has been sent to the peer.
7012 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
7013 otherwise an error code is returned.
7018 -- Function: int gnutls_alert_send (gnutls_session_t SESSION,
7019 gnutls_alert_level_t LEVEL, gnutls_alert_description_t DESC)
7020 SESSION: is a 'gnutls_session_t' structure.
7022 LEVEL: is the level of the alert
7024 DESC: is the alert description
7026 This function will send an alert to the peer in order to inform him
7027 of something important (eg. his Certificate could not be
7028 verified). If the alert level is Fatal then the peer is expected
7029 to close the connection, otherwise he may ignore the alert and
7032 The error code of the underlying record send function will be
7033 returned, so you may also receive 'GNUTLS_E_INTERRUPTED' or
7034 'GNUTLS_E_AGAIN' as well.
7036 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
7037 otherwise an error code is returned.
7039 gnutls_anon_allocate_client_credentials
7040 ---------------------------------------
7042 -- Function: int gnutls_anon_allocate_client_credentials
7043 (gnutls_anon_client_credentials_t * SC)
7044 SC: is a pointer to a 'gnutls_anon_client_credentials_t' structure.
7046 This structure is complex enough to manipulate directly thus this
7047 helper function is provided in order to allocate it.
7049 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7051 gnutls_anon_allocate_server_credentials
7052 ---------------------------------------
7054 -- Function: int gnutls_anon_allocate_server_credentials
7055 (gnutls_anon_server_credentials_t * SC)
7056 SC: is a pointer to a 'gnutls_anon_server_credentials_t' structure.
7058 This structure is complex enough to manipulate directly thus this
7059 helper function is provided in order to allocate it.
7061 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7063 gnutls_anon_free_client_credentials
7064 -----------------------------------
7066 -- Function: void gnutls_anon_free_client_credentials
7067 (gnutls_anon_client_credentials_t SC)
7068 SC: is a 'gnutls_anon_client_credentials_t' structure.
7070 This structure is complex enough to manipulate directly thus this
7071 helper function is provided in order to free (deallocate) it.
7073 gnutls_anon_free_server_credentials
7074 -----------------------------------
7076 -- Function: void gnutls_anon_free_server_credentials
7077 (gnutls_anon_server_credentials_t SC)
7078 SC: is a 'gnutls_anon_server_credentials_t' structure.
7080 This structure is complex enough to manipulate directly thus this
7081 helper function is provided in order to free (deallocate) it.
7083 gnutls_anon_set_params_function
7084 -------------------------------
7086 -- Function: void gnutls_anon_set_params_function
7087 (gnutls_anon_server_credentials_t RES, gnutls_params_function
7089 RES: is a gnutls_anon_server_credentials_t structure
7091 FUNC: is the function to be called
7093 This function will set a callback in order for the server to get
7094 the Diffie-Hellman or RSA parameters for anonymous authentication.
7095 The callback should return zero on success.
7097 gnutls_anon_set_server_dh_params
7098 --------------------------------
7100 -- Function: void gnutls_anon_set_server_dh_params
7101 (gnutls_anon_server_credentials_t RES, gnutls_dh_params_t
7103 RES: is a gnutls_anon_server_credentials_t structure
7105 DH_PARAMS: is a structure that holds Diffie-Hellman parameters.
7107 This function will set the Diffie-Hellman parameters for an
7108 anonymous server to use. These parameters will be used in
7109 Anonymous Diffie-Hellman cipher suites.
7111 gnutls_anon_set_server_params_function
7112 --------------------------------------
7114 -- Function: void gnutls_anon_set_server_params_function
7115 (gnutls_anon_server_credentials_t RES, gnutls_params_function
7117 RES: is a gnutls_certificate_credentials_t structure
7119 FUNC: is the function to be called
7121 This function will set a callback in order for the server to get
7122 the Diffie-Hellman parameters for anonymous authentication. The
7123 callback should return zero on success.
7125 gnutls_auth_client_get_type
7126 ---------------------------
7128 -- Function: gnutls_credentials_type_t gnutls_auth_client_get_type
7129 (gnutls_session_t SESSION)
7130 SESSION: is a 'gnutls_session_t' structure.
7132 Returns the type of credentials that were used for client
7133 authentication. The returned information is to be used to
7134 distinguish the function used to access authentication data.
7136 *Returns:* The type of credentials for the client authentication
7137 schema, a 'gnutls_credentials_type_t' type.
7139 gnutls_auth_get_type
7140 --------------------
7142 -- Function: gnutls_credentials_type_t gnutls_auth_get_type
7143 (gnutls_session_t SESSION)
7144 SESSION: is a 'gnutls_session_t' structure.
7146 Returns type of credentials for the current authentication schema.
7147 The returned information is to be used to distinguish the function
7148 used to access authentication data.
7150 Eg. for CERTIFICATE ciphersuites (key exchange algorithms:
7151 'GNUTLS_KX_RSA', 'GNUTLS_KX_DHE_RSA'), the same function are to be
7152 used to access the authentication data.
7154 *Returns:* The type of credentials for the current authentication
7155 schema, a 'gnutls_credentials_type_t' type.
7157 gnutls_auth_server_get_type
7158 ---------------------------
7160 -- Function: gnutls_credentials_type_t gnutls_auth_server_get_type
7161 (gnutls_session_t SESSION)
7162 SESSION: is a 'gnutls_session_t' structure.
7164 Returns the type of credentials that were used for server
7165 authentication. The returned information is to be used to
7166 distinguish the function used to access authentication data.
7168 *Returns:* The type of credentials for the server authentication
7169 schema, a 'gnutls_credentials_type_t' type.
7174 -- Function: int gnutls_bye (gnutls_session_t SESSION,
7175 gnutls_close_request_t HOW)
7176 SESSION: is a 'gnutls_session_t' structure.
7180 Terminates the current TLS/SSL connection. The connection should
7181 have been initiated using 'gnutls_handshake()'. 'how' should be
7182 one of 'GNUTLS_SHUT_RDWR', 'GNUTLS_SHUT_WR'.
7184 In case of 'GNUTLS_SHUT_RDWR' then the TLS connection gets
7185 terminated and further receives and sends will be disallowed. If
7186 the return value is zero you may continue using the connection.
7187 'GNUTLS_SHUT_RDWR' actually sends an alert containing a close
7188 request and waits for the peer to reply with the same message.
7190 In case of 'GNUTLS_SHUT_WR' then the TLS connection gets terminated
7191 and further sends will be disallowed. In order to reuse the
7192 connection you should wait for an EOF from the peer.
7193 'GNUTLS_SHUT_WR' sends an alert containing a close request.
7195 Note that not all implementations will properly terminate a TLS
7196 connection. Some of them, usually for performance reasons, will
7197 terminate only the underlying transport layer, thus causing a
7198 transmission error to the peer. This error cannot be distinguished
7199 from a malicious party prematurely terminating the session, thus
7200 this behavior is not recommended.
7202 This function may also return 'GNUTLS_E_AGAIN' or
7203 'GNUTLS_E_INTERRUPTED'; cf. 'gnutls_record_get_direction()'.
7205 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code, see
7206 function documentation for entire semantics.
7208 gnutls_certificate_activation_time_peers
7209 ----------------------------------------
7211 -- Function: time_t gnutls_certificate_activation_time_peers
7212 (gnutls_session_t SESSION)
7213 SESSION: is a gnutls session
7215 This function will return the peer's certificate activation time.
7216 This is the creation time for openpgp keys.
7218 *Returns:* (time_t)-1 on error.
7220 *Deprecated:* 'gnutls_certificate_verify_peers2()' now verifies
7223 gnutls_certificate_allocate_credentials
7224 ---------------------------------------
7226 -- Function: int gnutls_certificate_allocate_credentials
7227 (gnutls_certificate_credentials_t * RES)
7228 RES: is a pointer to a 'gnutls_certificate_credentials_t'
7231 This structure is complex enough to manipulate directly thus this
7232 helper function is provided in order to allocate it.
7234 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7236 gnutls_certificate_client_get_request_status
7237 --------------------------------------------
7239 -- Function: int gnutls_certificate_client_get_request_status
7240 (gnutls_session_t SESSION)
7241 SESSION: is a gnutls session
7243 Get whether client certificate is requested or not.
7245 *Returns:* 0 if the peer (server) did not request client
7246 authentication or 1 otherwise, or a negative value in case of
7249 gnutls_certificate_client_set_retrieve_function
7250 -----------------------------------------------
7252 -- Function: void gnutls_certificate_client_set_retrieve_function
7253 (gnutls_certificate_credentials_t CRED,
7254 gnutls_certificate_client_retrieve_function * FUNC)
7255 CRED: is a 'gnutls_certificate_credentials_t' structure.
7257 FUNC: is the callback function
7259 This function sets a callback to be called in order to retrieve the
7260 certificate to be used in the handshake.
7262 The callback's function prototype is: int
7263 (*callback)(gnutls_session_t, const gnutls_datum_t* req_ca_dn, int
7264 nreqs, const gnutls_pk_algorithm_t* pk_algos, int pk_algos_length,
7265 gnutls_retr_st* st);
7267 'req_ca_cert' is only used in X.509 certificates. Contains a list
7268 with the CA names that the server considers trusted. Normally we
7269 should send a certificate that is signed by one of these CAs.
7270 These names are DER encoded. To get a more meaningful value use
7271 the function 'gnutls_x509_rdn_get()'.
7273 'pk_algos' contains a list with server's acceptable signature
7274 algorithms. The certificate returned should support the server's
7277 'st' should contain the certificates and private keys.
7279 If the callback function is provided then gnutls will call it, in
7280 the handshake, after the certificate request message has been
7283 The callback function should set the certificate list to be sent,
7284 and return 0 on success. If no certificate was selected then the
7285 number of certificates should be set to zero. The value (-1)
7286 indicates error and the handshake will be terminated.
7288 gnutls_certificate_expiration_time_peers
7289 ----------------------------------------
7291 -- Function: time_t gnutls_certificate_expiration_time_peers
7292 (gnutls_session_t SESSION)
7293 SESSION: is a gnutls session
7295 This function will return the peer's certificate expiration time.
7297 *Returns:* (time_t)-1 on error.
7299 *Deprecated:* 'gnutls_certificate_verify_peers2()' now verifies
7302 gnutls_certificate_free_ca_names
7303 --------------------------------
7305 -- Function: void gnutls_certificate_free_ca_names
7306 (gnutls_certificate_credentials_t SC)
7307 SC: is a 'gnutls_certificate_credentials_t' structure.
7309 This function will delete all the CA name in the given credentials.
7310 Clients may call this to save some memory since in client side the
7311 CA names are not used. Servers might want to use this function if
7312 a large list of trusted CAs is present and sending the names of it
7313 would just consume bandwidth without providing information to
7316 CA names are used by servers to advertize the CAs they support to
7319 gnutls_certificate_free_cas
7320 ---------------------------
7322 -- Function: void gnutls_certificate_free_cas
7323 (gnutls_certificate_credentials_t SC)
7324 SC: is a 'gnutls_certificate_credentials_t' structure.
7326 This function will delete all the CAs associated with the given
7327 credentials. Servers that do not use
7328 'gnutls_certificate_verify_peers2()' may call this to save some
7331 gnutls_certificate_free_credentials
7332 -----------------------------------
7334 -- Function: void gnutls_certificate_free_credentials
7335 (gnutls_certificate_credentials_t SC)
7336 SC: is a 'gnutls_certificate_credentials_t' structure.
7338 This structure is complex enough to manipulate directly thus this
7339 helper function is provided in order to free (deallocate) it.
7341 This function does not free any temporary parameters associated
7342 with this structure (ie RSA and DH parameters are not freed by this
7345 gnutls_certificate_free_crls
7346 ----------------------------
7348 -- Function: void gnutls_certificate_free_crls
7349 (gnutls_certificate_credentials_t SC)
7350 SC: is a 'gnutls_certificate_credentials_t' structure.
7352 This function will delete all the CRLs associated with the given
7355 gnutls_certificate_free_keys
7356 ----------------------------
7358 -- Function: void gnutls_certificate_free_keys
7359 (gnutls_certificate_credentials_t SC)
7360 SC: is a 'gnutls_certificate_credentials_t' structure.
7362 This function will delete all the keys and the certificates
7363 associated with the given credentials. This function must not be
7364 called when a TLS negotiation that uses the credentials is in
7367 gnutls_certificate_get_issuer
7368 -----------------------------
7370 -- Function: int gnutls_certificate_get_issuer
7371 (gnutls_certificate_credentials_t SC, gnutls_x509_crt_t CERT,
7372 gnutls_x509_crt_t* ISSUER, unsigned int FLAGS)
7373 SC: is a 'gnutls_certificate_credentials_t' structure.
7375 CERT: is the certificate to find issuer for
7377 ISSUER: Will hold the issuer if any. Should be treated as
7382 This function will return the issuer of a given certificate.
7384 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
7385 negative error value.
7387 gnutls_certificate_get_openpgp_keyring
7388 --------------------------------------
7390 -- Function: void gnutls_certificate_get_openpgp_keyring
7391 (gnutls_certificate_credentials_t SC, gnutls_openpgp_keyring_t
7393 SC: is a 'gnutls_certificate_credentials_t' structure.
7395 KEYRING: the exported keyring. Should be treated as constant
7397 This function will export the OpenPGP keyring associated with the
7402 gnutls_certificate_get_ours
7403 ---------------------------
7405 -- Function: const gnutls_datum_t * gnutls_certificate_get_ours
7406 (gnutls_session_t SESSION)
7407 SESSION: is a gnutls session
7409 Get the certificate as sent to the peer, in the last handshake.
7410 These certificates are in raw format. In X.509 this is a
7411 certificate list. In OpenPGP this is a single certificate.
7413 *Returns:* return a pointer to a 'gnutls_datum_t' containing our
7414 certificates, or 'NULL' in case of an error or if no certificate
7417 gnutls_certificate_get_peers
7418 ----------------------------
7420 -- Function: const gnutls_datum_t * gnutls_certificate_get_peers
7421 (gnutls_session_t SESSION, unsigned int * LIST_SIZE)
7422 SESSION: is a gnutls session
7424 LIST_SIZE: is the length of the certificate list
7426 Get the peer's raw certificate (chain) as sent by the peer. These
7427 certificates are in raw format (DER encoded for X.509). In case of
7428 a X.509 then a certificate list may be present. The first
7429 certificate in the list is the peer's certificate, following the
7430 issuer's certificate, then the issuer's issuer etc.
7432 In case of OpenPGP keys a single key will be returned in raw
7435 *Returns:* return a pointer to a 'gnutls_datum_t' containing our
7436 certificates, or 'NULL' in case of an error or if no certificate
7439 gnutls_certificate_get_x509_cas
7440 -------------------------------
7442 -- Function: void gnutls_certificate_get_x509_cas
7443 (gnutls_certificate_credentials_t SC, gnutls_x509_crt_t **
7444 X509_CA_LIST, unsigned int * NCAS)
7445 SC: is a 'gnutls_certificate_credentials_t' structure.
7447 X509_CA_LIST: will point to the CA list. Should be treated as
7450 NCAS: the number of CAs
7452 This function will export all the CAs associated with the given
7457 gnutls_certificate_get_x509_crls
7458 --------------------------------
7460 -- Function: void gnutls_certificate_get_x509_crls
7461 (gnutls_certificate_credentials_t SC, gnutls_x509_crl_t **
7462 X509_CRL_LIST, unsigned int * NCRLS)
7463 SC: is a 'gnutls_certificate_credentials_t' structure.
7465 X509_CRL_LIST: the exported CRL list. Should be treated as
7468 NCRLS: the number of exported CRLs
7470 This function will export all the CRLs associated with the given
7475 gnutls_certificate_send_x509_rdn_sequence
7476 -----------------------------------------
7478 -- Function: void gnutls_certificate_send_x509_rdn_sequence
7479 (gnutls_session_t SESSION, int STATUS)
7480 SESSION: is a pointer to a 'gnutls_session_t' structure.
7484 If status is non zero, this function will order gnutls not to send
7485 the rdnSequence in the certificate request message. That is the
7486 server will not advertize it's trusted CAs to the peer. If status
7487 is zero then the default behaviour will take effect, which is to
7488 advertize the server's trusted CAs.
7490 This function has no effect in clients, and in authentication
7491 methods other than certificate with X.509 certificates.
7493 gnutls_certificate_server_set_request
7494 -------------------------------------
7496 -- Function: void gnutls_certificate_server_set_request
7497 (gnutls_session_t SESSION, gnutls_certificate_request_t REQ)
7498 SESSION: is a 'gnutls_session_t' structure.
7500 REQ: is one of GNUTLS_CERT_REQUEST, GNUTLS_CERT_REQUIRE
7502 This function specifies if we (in case of a server) are going to
7503 send a certificate request message to the client. If 'req' is
7504 GNUTLS_CERT_REQUIRE then the server will return an error if the
7505 peer does not provide a certificate. If you do not call this
7506 function then the client will not be asked to send a certificate.
7508 gnutls_certificate_server_set_retrieve_function
7509 -----------------------------------------------
7511 -- Function: void gnutls_certificate_server_set_retrieve_function
7512 (gnutls_certificate_credentials_t CRED,
7513 gnutls_certificate_server_retrieve_function * FUNC)
7514 CRED: is a 'gnutls_certificate_credentials_t' structure.
7516 FUNC: is the callback function
7518 This function sets a callback to be called in order to retrieve the
7519 certificate to be used in the handshake.
7521 The callback's function prototype is: int
7522 (*callback)(gnutls_session_t, gnutls_retr_st* st);
7524 'st' should contain the certificates and private keys.
7526 If the callback function is provided then gnutls will call it, in
7527 the handshake, after the certificate request message has been
7530 The callback function should set the certificate list to be sent,
7531 and return 0 on success. The value (-1) indicates error and the
7532 handshake will be terminated.
7534 gnutls_certificate_set_dh_params
7535 --------------------------------
7537 -- Function: void gnutls_certificate_set_dh_params
7538 (gnutls_certificate_credentials_t RES, gnutls_dh_params_t
7540 RES: is a gnutls_certificate_credentials_t structure
7542 DH_PARAMS: is a structure that holds Diffie-Hellman parameters.
7544 This function will set the Diffie-Hellman parameters for a
7545 certificate server to use. These parameters will be used in
7546 Ephemeral Diffie-Hellman cipher suites. Note that only a pointer
7547 to the parameters are stored in the certificate handle, so if you
7548 deallocate the parameters before the certificate is deallocated,
7549 you must change the parameters stored in the certificate first.
7551 gnutls_certificate_set_params_function
7552 --------------------------------------
7554 -- Function: void gnutls_certificate_set_params_function
7555 (gnutls_certificate_credentials_t RES, gnutls_params_function
7557 RES: is a gnutls_certificate_credentials_t structure
7559 FUNC: is the function to be called
7561 This function will set a callback in order for the server to get
7562 the Diffie-Hellman or RSA parameters for certificate
7563 authentication. The callback should return zero on success.
7565 gnutls_certificate_set_retrieve_function
7566 ----------------------------------------
7568 -- Function: void gnutls_certificate_set_retrieve_function
7569 (gnutls_certificate_credentials_t CRED,
7570 gnutls_certificate_retrieve_function * FUNC)
7571 CRED: is a 'gnutls_certificate_credentials_t' structure.
7573 FUNC: is the callback function
7575 This function sets a callback to be called in order to retrieve the
7576 certificate to be used in the handshake.
7578 The callback's function prototype is: int
7579 (*callback)(gnutls_session_t, const gnutls_datum_t* req_ca_dn, int
7580 nreqs, const gnutls_pk_algorithm_t* pk_algos, int pk_algos_length,
7581 gnutls_retr2_st* st);
7583 'req_ca_cert' is only used in X.509 certificates. Contains a list
7584 with the CA names that the server considers trusted. Normally we
7585 should send a certificate that is signed by one of these CAs.
7586 These names are DER encoded. To get a more meaningful value use
7587 the function 'gnutls_x509_rdn_get()'.
7589 'pk_algos' contains a list with server's acceptable signature
7590 algorithms. The certificate returned should support the server's
7593 'st' should contain the certificates and private keys.
7595 If the callback function is provided then gnutls will call it, in
7596 the handshake, after the certificate request message has been
7599 In server side pk_algos and req_ca_dn are NULL.
7601 The callback function should set the certificate list to be sent,
7602 and return 0 on success. If no certificate was selected then the
7603 number of certificates should be set to zero. The value (-1)
7604 indicates error and the handshake will be terminated.
7606 gnutls_certificate_set_rsa_export_params
7607 ----------------------------------------
7609 -- Function: void gnutls_certificate_set_rsa_export_params
7610 (gnutls_certificate_credentials_t RES, gnutls_rsa_params_t
7612 RES: is a gnutls_certificate_credentials_t structure
7614 RSA_PARAMS: is a structure that holds temporary RSA parameters.
7616 This function will set the temporary RSA parameters for a
7617 certificate server to use. These parameters will be used in
7618 RSA-EXPORT cipher suites.
7620 gnutls_certificate_set_verify_flags
7621 -----------------------------------
7623 -- Function: void gnutls_certificate_set_verify_flags
7624 (gnutls_certificate_credentials_t RES, unsigned int FLAGS)
7625 RES: is a gnutls_certificate_credentials_t structure
7627 FLAGS: are the flags
7629 This function will set the flags to be used at verification of the
7630 certificates. Flags must be OR of the
7631 'gnutls_certificate_verify_flags' enumerations.
7633 gnutls_certificate_set_verify_function
7634 --------------------------------------
7636 -- Function: void gnutls_certificate_set_verify_function
7637 (gnutls_certificate_credentials_t CRED,
7638 gnutls_certificate_verify_function * FUNC)
7639 CRED: is a 'gnutls_certificate_credentials_t' structure.
7641 FUNC: is the callback function
7643 This function sets a callback to be called when peer's certificate
7644 has been received in order to verify it on receipt rather than
7645 doing after the handshake is completed.
7647 The callback's function prototype is: int
7648 (*callback)(gnutls_session_t);
7650 If the callback function is provided then gnutls will call it, in
7651 the handshake, just after the certificate message has been
7652 received. To verify or obtain the certificate the
7653 'gnutls_certificate_verify_peers2()',
7654 'gnutls_certificate_type_get()', 'gnutls_certificate_get_peers()'
7655 functions can be used.
7657 The callback function should return 0 for the handshake to continue
7658 or non-zero to terminate.
7662 gnutls_certificate_set_verify_limits
7663 ------------------------------------
7665 -- Function: void gnutls_certificate_set_verify_limits
7666 (gnutls_certificate_credentials_t RES, unsigned int MAX_BITS,
7667 unsigned int MAX_DEPTH)
7668 RES: is a gnutls_certificate_credentials structure
7670 MAX_BITS: is the number of bits of an acceptable certificate
7673 MAX_DEPTH: is maximum depth of the verification of a certificate
7676 This function will set some upper limits for the default
7677 verification function, 'gnutls_certificate_verify_peers2()', to
7678 avoid denial of service attacks. You can set them to zero to
7681 gnutls_certificate_set_x509_crl_file
7682 ------------------------------------
7684 -- Function: int gnutls_certificate_set_x509_crl_file
7685 (gnutls_certificate_credentials_t RES, const char * CRLFILE,
7686 gnutls_x509_crt_fmt_t TYPE)
7687 RES: is a 'gnutls_certificate_credentials_t' structure.
7689 CRLFILE: is a file containing the list of verified CRLs (DER or PEM
7694 This function adds the trusted CRLs in order to verify client or
7695 server certificates. In case of a client this is not required to
7696 be called if the certificates are not verified using
7697 'gnutls_certificate_verify_peers2()'. This function may be called
7700 *Returns:* number of CRLs processed or a negative value on error.
7702 gnutls_certificate_set_x509_crl_mem
7703 -----------------------------------
7705 -- Function: int gnutls_certificate_set_x509_crl_mem
7706 (gnutls_certificate_credentials_t RES, const gnutls_datum_t *
7707 CRL, gnutls_x509_crt_fmt_t TYPE)
7708 RES: is a 'gnutls_certificate_credentials_t' structure.
7710 CRL: is a list of trusted CRLs. They should have been verified
7715 This function adds the trusted CRLs in order to verify client or
7716 server certificates. In case of a client this is not required to
7717 be called if the certificates are not verified using
7718 'gnutls_certificate_verify_peers2()'. This function may be called
7721 *Returns:* number of CRLs processed, or a negative value on error.
7723 gnutls_certificate_set_x509_crl
7724 -------------------------------
7726 -- Function: int gnutls_certificate_set_x509_crl
7727 (gnutls_certificate_credentials_t RES, gnutls_x509_crl_t *
7728 CRL_LIST, int CRL_LIST_SIZE)
7729 RES: is a 'gnutls_certificate_credentials_t' structure.
7731 CRL_LIST: is a list of trusted CRLs. They should have been
7734 CRL_LIST_SIZE: holds the size of the crl_list
7736 This function adds the trusted CRLs in order to verify client or
7737 server certificates. In case of a client this is not required to
7738 be called if the certificates are not verified using
7739 'gnutls_certificate_verify_peers2()'. This function may be called
7742 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7746 gnutls_certificate_set_x509_key_file
7747 ------------------------------------
7749 -- Function: int gnutls_certificate_set_x509_key_file
7750 (gnutls_certificate_credentials_t RES, const char * CERTFILE,
7751 const char * KEYFILE, gnutls_x509_crt_fmt_t TYPE)
7752 RES: is a 'gnutls_certificate_credentials_t' structure.
7754 CERTFILE: is a file that containing the certificate list (path) for
7755 the specified private key, in PKCS7 format, or a list of
7758 KEYFILE: is a file that contains the private key
7762 This function sets a certificate/private key pair in the
7763 gnutls_certificate_credentials_t structure. This function may be
7764 called more than once (in case multiple keys/certificates exist for
7765 the server). For clients that wants to send more than its own end
7766 entity certificate (e.g., also an intermediate CA cert) then put
7767 the certificate chain in 'certfile'.
7769 Currently only PKCS-1 encoded RSA and DSA private keys are accepted
7772 This function can also accept PKCS '11' URLs. In that case it will
7773 import the private key and certificate indicated by the urls.
7775 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7777 gnutls_certificate_set_x509_key_mem
7778 -----------------------------------
7780 -- Function: int gnutls_certificate_set_x509_key_mem
7781 (gnutls_certificate_credentials_t RES, const gnutls_datum_t *
7782 CERT, const gnutls_datum_t * KEY, gnutls_x509_crt_fmt_t TYPE)
7783 RES: is a 'gnutls_certificate_credentials_t' structure.
7785 CERT: contains a certificate list (path) for the specified private
7788 KEY: is the private key, or 'NULL'
7792 This function sets a certificate/private key pair in the
7793 gnutls_certificate_credentials_t structure. This function may be
7794 called more than once (in case multiple keys/certificates exist for
7797 *Currently are supported:* RSA PKCS-1 encoded private keys, DSA
7800 DSA private keys are encoded the OpenSSL way, which is an ASN.1 DER
7801 sequence of 6 INTEGERs - version, p, q, g, pub, priv.
7803 Note that the keyUsage (2.5.29.15) PKIX extension in X.509
7804 certificates is supported. This means that certificates intended
7805 for signing cannot be used for ciphersuites that require
7808 If the certificate and the private key are given in PEM encoding
7809 then the strings that hold their values must be null terminated.
7811 The 'key' may be 'NULL' if you are using a sign callback, see
7812 'gnutls_sign_callback_set()'.
7814 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7816 gnutls_certificate_set_x509_key
7817 -------------------------------
7819 -- Function: int gnutls_certificate_set_x509_key
7820 (gnutls_certificate_credentials_t RES, gnutls_x509_crt_t *
7821 CERT_LIST, int CERT_LIST_SIZE, gnutls_x509_privkey_t KEY)
7822 RES: is a 'gnutls_certificate_credentials_t' structure.
7824 CERT_LIST: contains a certificate list (path) for the specified
7827 CERT_LIST_SIZE: holds the size of the certificate list
7829 KEY: is a gnutls_x509_privkey_t key
7831 This function sets a certificate/private key pair in the
7832 gnutls_certificate_credentials_t structure. This function may be
7833 called more than once (in case multiple keys/certificates exist for
7834 the server). For clients that wants to send more than its own end
7835 entity certificate (e.g., also an intermediate CA cert) then put
7836 the certificate chain in 'cert_list'.
7838 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7842 gnutls_certificate_set_x509_simple_pkcs12_file
7843 ----------------------------------------------
7845 -- Function: int gnutls_certificate_set_x509_simple_pkcs12_file
7846 (gnutls_certificate_credentials_t RES, const char *
7847 PKCS12FILE, gnutls_x509_crt_fmt_t TYPE, const char * PASSWORD)
7848 RES: is a 'gnutls_certificate_credentials_t' structure.
7850 PKCS12FILE: filename of file containing PKCS'12' blob.
7852 TYPE: is PEM or DER of the 'pkcs12file'.
7854 PASSWORD: optional password used to decrypt PKCS'12' file, bags and
7857 This function sets a certificate/private key pair and/or a CRL in
7858 the gnutls_certificate_credentials_t structure. This function may
7859 be called more than once (in case multiple keys/certificates exist
7862 *MAC:* ed PKCS'12' files are supported. Encrypted PKCS'12' bags
7863 are supported. Encrypted PKCS'8' private keys are supported.
7864 However, only password based security, and the same password for
7865 all operations, are supported.
7867 The private keys may be RSA PKCS'1' or DSA private keys encoded in
7870 PKCS'12' file may contain many keys and/or certificates, and there
7871 is no way to identify which key/certificate pair you want. You
7872 should make sure the PKCS'12' file only contain one key/certificate
7873 pair and/or one CRL.
7875 It is believed that the limitations of this function is acceptable
7876 for most usage, and that any more flexibility would introduce
7877 complexity that would make it harder to use this functionality at
7880 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7882 gnutls_certificate_set_x509_simple_pkcs12_mem
7883 ---------------------------------------------
7885 -- Function: int gnutls_certificate_set_x509_simple_pkcs12_mem
7886 (gnutls_certificate_credentials_t RES, const gnutls_datum_t *
7887 P12BLOB, gnutls_x509_crt_fmt_t TYPE, const char * PASSWORD)
7888 RES: is a 'gnutls_certificate_credentials_t' structure.
7890 P12BLOB: the PKCS'12' blob.
7892 TYPE: is PEM or DER of the 'pkcs12file'.
7894 PASSWORD: optional password used to decrypt PKCS'12' file, bags and
7897 This function sets a certificate/private key pair and/or a CRL in
7898 the gnutls_certificate_credentials_t structure. This function may
7899 be called more than once (in case multiple keys/certificates exist
7902 *MAC:* ed PKCS'12' files are supported. Encrypted PKCS'12' bags
7903 are supported. Encrypted PKCS'8' private keys are supported.
7904 However, only password based security, and the same password for
7905 all operations, are supported.
7907 The private keys may be RSA PKCS'1' or DSA private keys encoded in
7910 PKCS'12' file may contain many keys and/or certificates, and there
7911 is no way to identify which key/certificate pair you want. You
7912 should make sure the PKCS'12' file only contain one key/certificate
7913 pair and/or one CRL.
7915 It is believed that the limitations of this function is acceptable
7916 for most usage, and that any more flexibility would introduce
7917 complexity that would make it harder to use this functionality at
7920 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
7924 gnutls_certificate_set_x509_trust_file
7925 --------------------------------------
7927 -- Function: int gnutls_certificate_set_x509_trust_file
7928 (gnutls_certificate_credentials_t RES, const char * CAFILE,
7929 gnutls_x509_crt_fmt_t TYPE)
7930 RES: is a 'gnutls_certificate_credentials_t' structure.
7932 CAFILE: is a file containing the list of trusted CAs (DER or PEM
7937 This function adds the trusted CAs in order to verify client or
7938 server certificates. In case of a client this is not required to
7939 be called if the certificates are not verified using
7940 'gnutls_certificate_verify_peers2()'. This function may be called
7943 In case of a server the names of the CAs set here will be sent to
7944 the client if a certificate request is sent. This can be disabled
7945 using 'gnutls_certificate_send_x509_rdn_sequence()'.
7947 This function can also accept PKCS '11' URLs. In that case it will
7948 import all certificates that are marked as trusted.
7950 *Returns:* number of certificates processed, or a negative value on
7953 gnutls_certificate_set_x509_trust_mem
7954 -------------------------------------
7956 -- Function: int gnutls_certificate_set_x509_trust_mem
7957 (gnutls_certificate_credentials_t RES, const gnutls_datum_t *
7958 CA, gnutls_x509_crt_fmt_t TYPE)
7959 RES: is a 'gnutls_certificate_credentials_t' structure.
7961 CA: is a list of trusted CAs or a DER certificate
7965 This function adds the trusted CAs in order to verify client or
7966 server certificates. In case of a client this is not required to
7967 be called if the certificates are not verified using
7968 'gnutls_certificate_verify_peers2()'. This function may be called
7971 In case of a server the CAs set here will be sent to the client if
7972 a certificate request is sent. This can be disabled using
7973 'gnutls_certificate_send_x509_rdn_sequence()'.
7975 *Returns:* the number of certificates processed or a negative value
7978 gnutls_certificate_set_x509_trust
7979 ---------------------------------
7981 -- Function: int gnutls_certificate_set_x509_trust
7982 (gnutls_certificate_credentials_t RES, gnutls_x509_crt_t *
7983 CA_LIST, int CA_LIST_SIZE)
7984 RES: is a 'gnutls_certificate_credentials_t' structure.
7986 CA_LIST: is a list of trusted CAs
7988 CA_LIST_SIZE: holds the size of the CA list
7990 This function adds the trusted CAs in order to verify client or
7991 server certificates. In case of a client this is not required to
7992 be called if the certificates are not verified using
7993 'gnutls_certificate_verify_peers2()'. This function may be called
7996 In case of a server the CAs set here will be sent to the client if
7997 a certificate request is sent. This can be disabled using
7998 'gnutls_certificate_send_x509_rdn_sequence()'.
8000 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
8004 gnutls_certificate_type_get_id
8005 ------------------------------
8007 -- Function: gnutls_certificate_type_t gnutls_certificate_type_get_id
8009 NAME: is a certificate type name
8011 The names are compared in a case insensitive way.
8013 *Returns:* a 'gnutls_certificate_type_t' for the specified in a
8014 string certificate type, or 'GNUTLS_CRT_UNKNOWN' on error.
8016 gnutls_certificate_type_get_name
8017 --------------------------------
8019 -- Function: const char * gnutls_certificate_type_get_name
8020 (gnutls_certificate_type_t TYPE)
8021 TYPE: is a certificate type
8023 Convert a 'gnutls_certificate_type_t' type to a string.
8025 *Returns:* a string that contains the name of the specified
8026 certificate type, or 'NULL' in case of unknown types.
8028 gnutls_certificate_type_get
8029 ---------------------------
8031 -- Function: gnutls_certificate_type_t gnutls_certificate_type_get
8032 (gnutls_session_t SESSION)
8033 SESSION: is a 'gnutls_session_t' structure.
8035 The certificate type is by default X.509, unless it is negotiated
8038 *Returns:* the currently used 'gnutls_certificate_type_t'
8041 gnutls_certificate_type_list
8042 ----------------------------
8044 -- Function: const gnutls_certificate_type_t *
8045 gnutls_certificate_type_list ( VOID)
8047 Get a list of certificate types. Note that to be able to use
8048 OpenPGP certificates, you must link to libgnutls-extra and call
8049 'gnutls_global_init_extra()'.
8051 *Returns:* a zero-terminated list of 'gnutls_certificate_type_t'
8052 integers indicating the available certificate types.
8054 gnutls_certificate_type_set_priority
8055 ------------------------------------
8057 -- Function: int gnutls_certificate_type_set_priority (gnutls_session_t
8058 SESSION, const int * LIST)
8059 SESSION: is a 'gnutls_session_t' structure.
8061 LIST: is a 0 terminated list of gnutls_certificate_type_t elements.
8063 Sets the priority on the certificate types supported by gnutls.
8064 Priority is higher for elements specified before others. After
8065 specifying the types you want, you must append a 0. Note that the
8066 certificate type priority is set on the client. The server does
8067 not use the cert type priority except for disabling types that were
8070 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
8072 gnutls_certificate_verify_peers2
8073 --------------------------------
8075 -- Function: int gnutls_certificate_verify_peers2 (gnutls_session_t
8076 SESSION, unsigned int * STATUS)
8077 SESSION: is a gnutls session
8079 STATUS: is the output of the verification
8081 This function will try to verify the peer's certificate and return
8082 its status (trusted, invalid etc.). The value of 'status' should
8083 be one or more of the gnutls_certificate_status_t enumerated
8084 elements bitwise or'd. To avoid denial of service attacks some
8085 default upper limits regarding the certificate key size and chain
8086 size are set. To override them use
8087 'gnutls_certificate_set_verify_limits()'.
8089 Note that you must also check the peer's name in order to check if
8090 the verified certificate belongs to the actual peer.
8092 This function uses 'gnutls_x509_crt_list_verify()' with the CAs in
8093 the credentials as trusted CAs.
8095 *Returns:* a negative error code on error and zero on success.
8097 gnutls_certificate_verify_peers
8098 -------------------------------
8100 -- Function: int gnutls_certificate_verify_peers (gnutls_session_t
8102 SESSION: is a gnutls session
8104 This function will try to verify the peer's certificate and return
8105 its status (trusted, invalid etc.). However you must also check
8106 the peer's name in order to check if the verified certificate
8107 belongs to the actual peer.
8109 This function uses 'gnutls_x509_crt_list_verify()'.
8111 *Returns:* one or more of the 'gnutls_certificate_status_t'
8112 enumerated elements bitwise or'd, or a negative value on error.
8114 *Deprecated:* Use 'gnutls_certificate_verify_peers2()' instead.
8116 gnutls_check_version
8117 --------------------
8119 -- Function: const char * gnutls_check_version (const char *
8121 REQ_VERSION: version string to compare with, or 'NULL'.
8123 Check GnuTLS Library version.
8125 See 'GNUTLS_VERSION' for a suitable 'req_version' string.
8127 *Return value:* Check that the version of the library is at minimum
8128 the one given as a string in 'req_version' and return the actual
8129 version string of the library; return 'NULL' if the condition is
8130 not met. If 'NULL' is passed to this function no check is done and
8131 only the version string is returned.
8133 gnutls_cipher_decrypt2
8134 ----------------------
8136 -- Function: int gnutls_cipher_decrypt2 (gnutls_cipher_hd_t HANDLE,
8137 const void * CIPHERTEXT, size_t CIPHERTEXTLEN, void * TEXT,
8139 HANDLE: is a 'gnutls_cipher_hd_t' structure.
8141 CIPHERTEXT: the data to encrypt
8143 CIPHERTEXTLEN: The length of data to encrypt
8145 TEXT: the decrypted data
8147 TEXTLEN: The available length for decrypted data
8149 This function will decrypt the given data using the algorithm
8150 specified by the context.
8152 *Returns:* Zero or a negative value on error.
8156 gnutls_cipher_decrypt
8157 ---------------------
8159 -- Function: int gnutls_cipher_decrypt (gnutls_cipher_hd_t HANDLE, void
8160 * CIPHERTEXT, size_t CIPHERTEXTLEN)
8161 HANDLE: is a 'gnutls_cipher_hd_t' structure.
8163 CIPHERTEXT: the data to encrypt
8165 CIPHERTEXTLEN: The length of data to encrypt
8167 This function will decrypt the given data using the algorithm
8168 specified by the context.
8170 *Returns:* Zero or a negative value on error.
8174 gnutls_cipher_deinit
8175 --------------------
8177 -- Function: void gnutls_cipher_deinit (gnutls_cipher_hd_t HANDLE)
8178 HANDLE: is a 'gnutls_cipher_hd_t' structure.
8180 This function will deinitialize all resources occupied by the given
8185 gnutls_cipher_encrypt2
8186 ----------------------
8188 -- Function: int gnutls_cipher_encrypt2 (gnutls_cipher_hd_t HANDLE,
8189 void * TEXT, size_t TEXTLEN, void * CIPHERTEXT, size_t
8191 HANDLE: is a 'gnutls_cipher_hd_t' structure.
8193 TEXT: the data to encrypt
8195 TEXTLEN: The length of data to encrypt
8197 CIPHERTEXT: the encrypted data
8199 CIPHERTEXTLEN: The available length for encrypted data
8201 This function will encrypt the given data using the algorithm
8202 specified by the context.
8204 *Returns:* Zero or a negative value on error.
8208 gnutls_cipher_encrypt
8209 ---------------------
8211 -- Function: int gnutls_cipher_encrypt (gnutls_cipher_hd_t HANDLE, void
8212 * TEXT, size_t TEXTLEN)
8213 HANDLE: is a 'gnutls_cipher_hd_t' structure.
8215 TEXT: the data to encrypt
8217 TEXTLEN: The length of data to encrypt
8219 This function will encrypt the given data using the algorithm
8220 specified by the context.
8222 *Returns:* Zero or a negative value on error.
8226 gnutls_cipher_get_block_size
8227 ----------------------------
8229 -- Function: int gnutls_cipher_get_block_size
8230 (gnutls_cipher_algorithm_t ALGORITHM)
8231 ALGORITHM: is an encryption algorithm
8233 Get block size for encryption algorithm.
8235 *Returns:* block size for encryption algorithm.
8239 gnutls_cipher_get_id
8240 --------------------
8242 -- Function: gnutls_cipher_algorithm_t gnutls_cipher_get_id (const char
8244 NAME: is a MAC algorithm name
8246 The names are compared in a case insensitive way.
8248 *Returns:* return a 'gnutls_cipher_algorithm_t' value corresponding
8249 to the specified cipher, or 'GNUTLS_CIPHER_UNKNOWN' on error.
8251 gnutls_cipher_get_key_size
8252 --------------------------
8254 -- Function: size_t gnutls_cipher_get_key_size
8255 (gnutls_cipher_algorithm_t ALGORITHM)
8256 ALGORITHM: is an encryption algorithm
8258 Get key size for cipher.
8260 *Returns:* length (in bytes) of the given cipher's key size, or 0
8261 if the given cipher is invalid.
8263 gnutls_cipher_get_name
8264 ----------------------
8266 -- Function: const char * gnutls_cipher_get_name
8267 (gnutls_cipher_algorithm_t ALGORITHM)
8268 ALGORITHM: is an encryption algorithm
8270 Convert a 'gnutls_cipher_algorithm_t' type to a string.
8272 *Returns:* a pointer to a string that contains the name of the
8273 specified cipher, or 'NULL'.
8278 -- Function: gnutls_cipher_algorithm_t gnutls_cipher_get
8279 (gnutls_session_t SESSION)
8280 SESSION: is a 'gnutls_session_t' structure.
8282 Get currently used cipher.
8284 *Returns:* the currently used cipher, a 'gnutls_cipher_algorithm_t'
8290 -- Function: int gnutls_cipher_init (gnutls_cipher_hd_t * HANDLE,
8291 gnutls_cipher_algorithm_t CIPHER, const gnutls_datum_t * KEY,
8292 const gnutls_datum_t * IV)
8293 HANDLE: is a 'gnutls_cipher_hd_t' structure.
8295 CIPHER: the encryption algorithm to use
8297 KEY: The key to be used for encryption
8299 IV: The IV to use (if not applicable set NULL)
8301 This function will initialize an context that can be used for
8302 encryption/decryption of data. This will effectively use the
8303 current crypto backend in use by gnutls or the cryptographic
8306 *Returns:* Zero or a negative value on error.
8313 -- Function: const gnutls_cipher_algorithm_t * gnutls_cipher_list (
8316 Get a list of supported cipher algorithms. Note that not
8317 necessarily all ciphers are supported as TLS cipher suites. For
8318 example, DES is not supported as a cipher suite, but is supported
8319 for other purposes (e.g., PKCS'8' or similar).
8321 *Returns:* a zero-terminated list of 'gnutls_cipher_algorithm_t'
8322 integers indicating the available ciphers.
8324 gnutls_cipher_set_priority
8325 --------------------------
8327 -- Function: int gnutls_cipher_set_priority (gnutls_session_t SESSION,
8329 SESSION: is a 'gnutls_session_t' structure.
8331 LIST: is a 0 terminated list of gnutls_cipher_algorithm_t elements.
8333 Sets the priority on the ciphers supported by gnutls. Priority is
8334 higher for elements specified before others. After specifying the
8335 ciphers you want, you must append a 0. Note that the priority is
8336 set on the client. The server does not use the algorithm's
8337 priority except for disabling algorithms that were not specified.
8339 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
8341 gnutls_cipher_suite_get_name
8342 ----------------------------
8344 -- Function: const char * gnutls_cipher_suite_get_name
8345 (gnutls_kx_algorithm_t KX_ALGORITHM, gnutls_cipher_algorithm_t
8346 CIPHER_ALGORITHM, gnutls_mac_algorithm_t MAC_ALGORITHM)
8347 KX_ALGORITHM: is a Key exchange algorithm
8349 CIPHER_ALGORITHM: is a cipher algorithm
8351 MAC_ALGORITHM: is a MAC algorithm
8353 Note that the full cipher suite name must be prepended by TLS or
8354 SSL depending of the protocol in use.
8356 *Returns:* a string that contains the name of a TLS cipher suite,
8357 specified by the given algorithms, or 'NULL'.
8359 gnutls_cipher_suite_info
8360 ------------------------
8362 -- Function: const char * gnutls_cipher_suite_info (size_t IDX, char *
8363 CS_ID, gnutls_kx_algorithm_t * KX, gnutls_cipher_algorithm_t *
8364 CIPHER, gnutls_mac_algorithm_t * MAC, gnutls_protocol_t *
8366 IDX: index of cipher suite to get information about, starts on 0.
8368 CS_ID: output buffer with room for 2 bytes, indicating cipher suite
8371 KX: output variable indicating key exchange algorithm, or 'NULL'.
8373 CIPHER: output variable indicating cipher, or 'NULL'.
8375 MAC: output variable indicating MAC algorithm, or 'NULL'.
8377 Get information about supported cipher suites. Use the function
8378 iteratively to get information about all supported cipher suites.
8379 Call with idx=0 to get information about first cipher suite, then
8380 idx=1 and so on until the function returns NULL.
8382 *Returns:* the name of 'idx' cipher suite, and set the information
8383 about the cipher suite in the output variables. If 'idx' is out of
8384 bounds, 'NULL' is returned.
8386 gnutls_compression_get_id
8387 -------------------------
8389 -- Function: gnutls_compression_method_t gnutls_compression_get_id
8391 NAME: is a compression method name
8393 The names are compared in a case insensitive way.
8395 *Returns:* an id of the specified in a string compression method,
8396 or 'GNUTLS_COMP_UNKNOWN' on error.
8398 gnutls_compression_get_name
8399 ---------------------------
8401 -- Function: const char * gnutls_compression_get_name
8402 (gnutls_compression_method_t ALGORITHM)
8403 ALGORITHM: is a Compression algorithm
8405 Convert a 'gnutls_compression_method_t' value to a string.
8407 *Returns:* a pointer to a string that contains the name of the
8408 specified compression algorithm, or 'NULL'.
8410 gnutls_compression_get
8411 ----------------------
8413 -- Function: gnutls_compression_method_t gnutls_compression_get
8414 (gnutls_session_t SESSION)
8415 SESSION: is a 'gnutls_session_t' structure.
8417 Get currently used compression algorithm.
8419 *Returns:* the currently used compression method, a
8420 'gnutls_compression_method_t' value.
8422 gnutls_compression_list
8423 -----------------------
8425 -- Function: const gnutls_compression_method_t *
8426 gnutls_compression_list ( VOID)
8428 Get a list of compression methods. Note that to be able to use LZO
8429 compression, you must link to libgnutls-extra and call
8430 'gnutls_global_init_extra()'.
8432 *Returns:* a zero-terminated list of 'gnutls_compression_method_t'
8433 integers indicating the available compression methods.
8435 gnutls_compression_set_priority
8436 -------------------------------
8438 -- Function: int gnutls_compression_set_priority (gnutls_session_t
8439 SESSION, const int * LIST)
8440 SESSION: is a 'gnutls_session_t' structure.
8442 LIST: is a 0 terminated list of gnutls_compression_method_t
8445 Sets the priority on the compression algorithms supported by
8446 gnutls. Priority is higher for elements specified before others.
8447 After specifying the algorithms you want, you must append a 0.
8448 Note that the priority is set on the client. The server does not
8449 use the algorithm's priority except for disabling algorithms that
8452 TLS 1.0 does not define any compression algorithms except NULL.
8453 Other compression algorithms are to be considered as gnutls
8456 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
8458 gnutls_credentials_clear
8459 ------------------------
8461 -- Function: void gnutls_credentials_clear (gnutls_session_t SESSION)
8462 SESSION: is a 'gnutls_session_t' structure.
8464 Clears all the credentials previously set in this session.
8466 gnutls_credentials_set
8467 ----------------------
8469 -- Function: int gnutls_credentials_set (gnutls_session_t SESSION,
8470 gnutls_credentials_type_t TYPE, void * CRED)
8471 SESSION: is a 'gnutls_session_t' structure.
8473 TYPE: is the type of the credentials
8475 CRED: is a pointer to a structure.
8477 Sets the needed credentials for the specified type. Eg username,
8478 password - or public and private keys etc. The 'cred' parameter is
8479 a structure that depends on the specified type and on the current
8480 session (client or server).
8482 In order to minimize memory usage, and share credentials between
8483 several threads gnutls keeps a pointer to cred, and not the whole
8484 cred structure. Thus you will have to keep the structure allocated
8485 until you call 'gnutls_deinit()'.
8487 For 'GNUTLS_CRD_ANON', 'cred' should be
8488 'gnutls_anon_client_credentials_t' in case of a client. In case of
8489 a server it should be 'gnutls_anon_server_credentials_t'.
8491 For 'GNUTLS_CRD_SRP', 'cred' should be
8492 'gnutls_srp_client_credentials_t' in case of a client, and
8493 'gnutls_srp_server_credentials_t', in case of a server.
8495 For 'GNUTLS_CRD_CERTIFICATE', 'cred' should be
8496 'gnutls_certificate_credentials_t'.
8498 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
8499 otherwise an error code is returned.
8501 gnutls_crypto_bigint_register2
8502 ------------------------------
8504 -- Function: int gnutls_crypto_bigint_register2 (int PRIORITY, int
8505 VERSION, const gnutls_crypto_bigint_st * S)
8506 PRIORITY: is the priority of the interface
8508 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8510 S: is a structure holding new interface's data
8512 This function will register an interface for gnutls to operate on
8513 big integers. Any interface registered will override the included
8514 interface. The interface with the lowest priority will be used by
8517 Note that the bigint interface must interoperate with the public
8518 key interface. Thus if this interface is updated the
8519 'gnutls_crypto_pk_register()' should also be used.
8521 This function should be called before 'gnutls_global_init()'.
8523 For simplicity you can use the convenience
8524 'gnutls_crypto_bigint_register()' macro.
8526 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8530 gnutls_crypto_cipher_register2
8531 ------------------------------
8533 -- Function: int gnutls_crypto_cipher_register2 (int PRIORITY, int
8534 VERSION, const gnutls_crypto_cipher_st * S)
8535 PRIORITY: is the priority of the cipher interface
8537 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8539 S: is a structure holding new interface's data
8541 This function will register a cipher interface to be used by
8542 gnutls. Any interface registered will override the included engine
8543 and by convention kernel implemented interfaces should have
8544 priority of 90. The interface with the lowest priority will be
8547 This function should be called before 'gnutls_global_init()'.
8549 For simplicity you can use the convenience
8550 'gnutls_crypto_cipher_register()' macro.
8552 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8556 gnutls_crypto_digest_register2
8557 ------------------------------
8559 -- Function: int gnutls_crypto_digest_register2 (int PRIORITY, int
8560 VERSION, const gnutls_crypto_digest_st * S)
8561 PRIORITY: is the priority of the digest interface
8563 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8565 S: is a structure holding new interface's data
8567 This function will register a digest interface to be used by
8568 gnutls. Any interface registered will override the included engine
8569 and by convention kernel implemented interfaces should have
8570 priority of 90. The interface with the lowest priority will be
8573 This function should be called before 'gnutls_global_init()'.
8575 For simplicity you can use the convenience
8576 'gnutls_crypto_digest_register()' macro.
8578 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8582 gnutls_crypto_mac_register2
8583 ---------------------------
8585 -- Function: int gnutls_crypto_mac_register2 (int PRIORITY, int
8586 VERSION, const gnutls_crypto_mac_st * S)
8587 PRIORITY: is the priority of the mac interface
8589 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8591 S: is a structure holding new interface's data
8593 This function will register a mac interface to be used by gnutls.
8594 Any interface registered will override the included engine and by
8595 convention kernel implemented interfaces should have priority of
8596 90. The interface with the lowest priority will be used by gnutls.
8598 This function should be called before 'gnutls_global_init()'.
8600 For simplicity you can use the convenience
8601 'gnutls_crypto_digest_register()' macro.
8603 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8607 gnutls_crypto_pk_register2
8608 --------------------------
8610 -- Function: int gnutls_crypto_pk_register2 (int PRIORITY, int VERSION,
8611 const gnutls_crypto_pk_st * S)
8612 PRIORITY: is the priority of the interface
8614 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8616 S: is a structure holding new interface's data
8618 This function will register an interface for gnutls to operate on
8619 public key operations. Any interface registered will override the
8620 included interface. The interface with the lowest priority will be
8623 Note that the bigint interface must interoperate with the bigint
8624 interface. Thus if this interface is updated the
8625 'gnutls_crypto_bigint_register()' should also be used.
8627 This function should be called before 'gnutls_global_init()'.
8629 For simplicity you can use the convenience
8630 'gnutls_crypto_pk_register()' macro.
8632 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8636 gnutls_crypto_rnd_register2
8637 ---------------------------
8639 -- Function: int gnutls_crypto_rnd_register2 (int PRIORITY, int
8640 VERSION, const gnutls_crypto_rnd_st * S)
8641 PRIORITY: is the priority of the generator
8643 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8645 S: is a structure holding new generator's data
8647 This function will register a random generator to be used by
8648 gnutls. Any generator registered will override the included
8649 generator and by convention kernel implemented generators have
8650 priority of 90. The generator with the lowest priority will be
8653 This function should be called before 'gnutls_global_init()'.
8655 For simplicity you can use the convenience
8656 'gnutls_crypto_rnd_register()' macro.
8658 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8662 gnutls_crypto_single_cipher_register2
8663 -------------------------------------
8665 -- Function: int gnutls_crypto_single_cipher_register2
8666 (gnutls_cipher_algorithm_t ALGORITHM, int PRIORITY, int
8667 VERSION, const gnutls_crypto_cipher_st * S)
8668 ALGORITHM: is the gnutls algorithm identifier
8670 PRIORITY: is the priority of the algorithm
8672 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8674 S: is a structure holding new cipher's data
8676 This function will register a cipher algorithm to be used by
8677 gnutls. Any algorithm registered will override the included
8678 algorithms and by convention kernel implemented algorithms have
8679 priority of 90. The algorithm with the lowest priority will be
8682 This function should be called before 'gnutls_global_init()'.
8684 For simplicity you can use the convenience
8685 'gnutls_crypto_single_cipher_register()' macro.
8687 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8691 gnutls_crypto_single_digest_register2
8692 -------------------------------------
8694 -- Function: int gnutls_crypto_single_digest_register2
8695 (gnutls_digest_algorithm_t ALGORITHM, int PRIORITY, int
8696 VERSION, const gnutls_crypto_digest_st * S)
8697 ALGORITHM: is the gnutls algorithm identifier
8699 PRIORITY: is the priority of the algorithm
8701 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8703 S: is a structure holding new algorithms's data
8705 This function will register a digest (hash) algorithm to be used by
8706 gnutls. Any algorithm registered will override the included
8707 algorithms and by convention kernel implemented algorithms have
8708 priority of 90. The algorithm with the lowest priority will be
8711 This function should be called before 'gnutls_global_init()'.
8713 For simplicity you can use the convenience
8714 'gnutls_crypto_single_digest_register()' macro.
8716 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8720 gnutls_crypto_single_mac_register2
8721 ----------------------------------
8723 -- Function: int gnutls_crypto_single_mac_register2
8724 (gnutls_mac_algorithm_t ALGORITHM, int PRIORITY, int VERSION,
8725 const gnutls_crypto_mac_st * S)
8726 ALGORITHM: is the gnutls algorithm identifier
8728 PRIORITY: is the priority of the algorithm
8730 VERSION: should be set to 'GNUTLS_CRYPTO_API_VERSION'
8732 S: is a structure holding new algorithms's data
8734 This function will register a MAC algorithm to be used by gnutls.
8735 Any algorithm registered will override the included algorithms and
8736 by convention kernel implemented algorithms have priority of 90.
8737 The algorithm with the lowest priority will be used by gnutls.
8739 This function should be called before 'gnutls_global_init()'.
8741 For simplicity you can use the convenience
8742 'gnutls_crypto_single_mac_register()' macro.
8744 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
8748 gnutls_db_check_entry
8749 ---------------------
8751 -- Function: int gnutls_db_check_entry (gnutls_session_t SESSION,
8752 gnutls_datum_t SESSION_ENTRY)
8753 SESSION: is a 'gnutls_session_t' structure.
8755 SESSION_ENTRY: is the session data (not key)
8757 Check if database entry has expired. This function is to be used
8758 when you want to clear unnesessary session which occupy space in
8761 *Returns:* Returns 'GNUTLS_E_EXPIRED', if the database entry has
8762 expired or 0 otherwise.
8767 -- Function: void * gnutls_db_get_ptr (gnutls_session_t SESSION)
8768 SESSION: is a 'gnutls_session_t' structure.
8770 Get db function pointer.
8772 *Returns:* the pointer that will be sent to db store, retrieve and
8773 delete functions, as the first argument.
8775 gnutls_db_remove_session
8776 ------------------------
8778 -- Function: void gnutls_db_remove_session (gnutls_session_t SESSION)
8779 SESSION: is a 'gnutls_session_t' structure.
8781 This function will remove the current session data from the session
8782 database. This will prevent future handshakes reusing these
8783 session data. This function should be called if a session was
8784 terminated abnormally, and before 'gnutls_deinit()' is called.
8786 Normally 'gnutls_deinit()' will remove abnormally terminated
8789 gnutls_db_set_cache_expiration
8790 ------------------------------
8792 -- Function: void gnutls_db_set_cache_expiration (gnutls_session_t
8793 SESSION, int SECONDS)
8794 SESSION: is a 'gnutls_session_t' structure.
8796 SECONDS: is the number of seconds.
8798 Set the expiration time for resumed sessions. The default is 3600
8799 (one hour) at the time writing this.
8804 -- Function: void gnutls_db_set_ptr (gnutls_session_t SESSION, void *
8806 SESSION: is a 'gnutls_session_t' structure.
8810 Sets the pointer that will be provided to db store, retrieve and
8811 delete functions, as the first argument.
8813 gnutls_db_set_remove_function
8814 -----------------------------
8816 -- Function: void gnutls_db_set_remove_function (gnutls_session_t
8817 SESSION, gnutls_db_remove_func REM_FUNC)
8818 SESSION: is a 'gnutls_session_t' structure.
8820 REM_FUNC: is the function.
8822 Sets the function that will be used to remove data from the resumed
8823 sessions database. This function must return 0 on success.
8825 The first argument to 'rem_func' will be null unless
8826 'gnutls_db_set_ptr()' has been called.
8828 gnutls_db_set_retrieve_function
8829 -------------------------------
8831 -- Function: void gnutls_db_set_retrieve_function (gnutls_session_t
8832 SESSION, gnutls_db_retr_func RETR_FUNC)
8833 SESSION: is a 'gnutls_session_t' structure.
8835 RETR_FUNC: is the function.
8837 Sets the function that will be used to retrieve data from the
8838 resumed sessions database. This function must return a
8839 gnutls_datum_t containing the data on success, or a gnutls_datum_t
8840 containing null and 0 on failure.
8842 The datum's data must be allocated using the function
8845 The first argument to 'retr_func' will be null unless
8846 'gnutls_db_set_ptr()' has been called.
8848 gnutls_db_set_store_function
8849 ----------------------------
8851 -- Function: void gnutls_db_set_store_function (gnutls_session_t
8852 SESSION, gnutls_db_store_func STORE_FUNC)
8853 SESSION: is a 'gnutls_session_t' structure.
8855 STORE_FUNC: is the function
8857 Sets the function that will be used to store data from the resumed
8858 sessions database. This function must remove 0 on success.
8860 The first argument to 'store_func()' will be null unless
8861 'gnutls_db_set_ptr()' has been called.
8866 -- Function: void gnutls_deinit (gnutls_session_t SESSION)
8867 SESSION: is a 'gnutls_session_t' structure.
8869 This function clears all buffers associated with the 'session'.
8870 This function will also remove session data from the session
8871 database if the session was terminated abnormally.
8876 -- Function: int gnutls_dh_get_group (gnutls_session_t SESSION,
8877 gnutls_datum_t * RAW_GEN, gnutls_datum_t * RAW_PRIME)
8878 SESSION: is a gnutls session
8880 RAW_GEN: will hold the generator.
8882 RAW_PRIME: will hold the prime.
8884 This function will return the group parameters used in the last
8885 Diffie-Hellman key exchange with the peer. These are the prime and
8886 the generator used. This function should be used for both
8887 anonymous and ephemeral Diffie-Hellman. The output parameters must
8888 be freed with 'gnutls_free()'.
8890 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
8891 otherwise an error code is returned.
8893 gnutls_dh_get_peers_public_bits
8894 -------------------------------
8896 -- Function: int gnutls_dh_get_peers_public_bits (gnutls_session_t
8898 SESSION: is a gnutls session
8900 Get the Diffie-Hellman public key bit size. Can be used for both
8901 anonymous and ephemeral Diffie-Hellman.
8903 *Returns:* the public key bit size used in the last Diffie-Hellman
8904 key exchange with the peer, or a negative value in case of error.
8906 gnutls_dh_get_prime_bits
8907 ------------------------
8909 -- Function: int gnutls_dh_get_prime_bits (gnutls_session_t SESSION)
8910 SESSION: is a gnutls session
8912 This function will return the bits of the prime used in the last
8913 Diffie-Hellman key exchange with the peer. Should be used for both
8914 anonymous and ephemeral Diffie-Hellman. Note that some ciphers,
8915 like RSA and DSA without DHE, does not use a Diffie-Hellman key
8916 exchange, and then this function will return 0.
8918 *Returns:* The Diffie-Hellman bit strength is returned, or 0 if no
8919 Diffie-Hellman key exchange was done, or a negative error code on
8922 gnutls_dh_get_pubkey
8923 --------------------
8925 -- Function: int gnutls_dh_get_pubkey (gnutls_session_t SESSION,
8926 gnutls_datum_t * RAW_KEY)
8927 SESSION: is a gnutls session
8929 RAW_KEY: will hold the public key.
8931 This function will return the peer's public key used in the last
8932 Diffie-Hellman key exchange. This function should be used for both
8933 anonymous and ephemeral Diffie-Hellman. The output parameters must
8934 be freed with 'gnutls_free()'.
8936 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
8937 otherwise an error code is returned.
8939 gnutls_dh_get_secret_bits
8940 -------------------------
8942 -- Function: int gnutls_dh_get_secret_bits (gnutls_session_t SESSION)
8943 SESSION: is a gnutls session
8945 This function will return the bits used in the last Diffie-Hellman
8946 key exchange with the peer. Should be used for both anonymous and
8947 ephemeral Diffie-Hellman.
8949 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
8950 otherwise an error code is returned.
8952 gnutls_dh_params_cpy
8953 --------------------
8955 -- Function: int gnutls_dh_params_cpy (gnutls_dh_params_t DST,
8956 gnutls_dh_params_t SRC)
8957 DST: Is the destination structure, which should be initialized.
8959 SRC: Is the source structure
8961 This function will copy the DH parameters structure from source to
8964 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
8965 otherwise an error code is returned.
8967 gnutls_dh_params_deinit
8968 -----------------------
8970 -- Function: void gnutls_dh_params_deinit (gnutls_dh_params_t
8972 DH_PARAMS: Is a structure that holds the prime numbers
8974 This function will deinitialize the DH parameters structure.
8976 gnutls_dh_params_export_pkcs3
8977 -----------------------------
8979 -- Function: int gnutls_dh_params_export_pkcs3 (gnutls_dh_params_t
8980 PARAMS, gnutls_x509_crt_fmt_t FORMAT, unsigned char *
8981 PARAMS_DATA, size_t * PARAMS_DATA_SIZE)
8982 PARAMS: Holds the DH parameters
8984 FORMAT: the format of output params. One of PEM or DER.
8986 PARAMS_DATA: will contain a PKCS3 DHParams structure PEM or DER
8989 PARAMS_DATA_SIZE: holds the size of params_data (and will be
8990 replaced by the actual size of parameters)
8992 This function will export the given dh parameters to a PKCS3
8993 DHParams structure. This is the format generated by "openssl
8994 dhparam" tool. If the buffer provided is not long enough to hold
8995 the output, then GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.
8997 If the structure is PEM encoded, it will have a header of "BEGIN DH
9000 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9001 otherwise an error code is returned.
9003 gnutls_dh_params_export_raw
9004 ---------------------------
9006 -- Function: int gnutls_dh_params_export_raw (gnutls_dh_params_t
9007 PARAMS, gnutls_datum_t * PRIME, gnutls_datum_t * GENERATOR,
9008 unsigned int * BITS)
9009 PARAMS: Holds the DH parameters
9011 PRIME: will hold the new prime
9013 GENERATOR: will hold the new generator
9015 BITS: if non null will hold is the prime's number of bits
9017 This function will export the pair of prime and generator for use
9018 in the Diffie-Hellman key exchange. The new parameters will be
9019 allocated using 'gnutls_malloc()' and will be stored in the
9022 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9023 otherwise an error code is returned.
9025 gnutls_dh_params_generate2
9026 --------------------------
9028 -- Function: int gnutls_dh_params_generate2 (gnutls_dh_params_t PARAMS,
9030 PARAMS: Is the structure that the DH parameters will be stored
9032 BITS: is the prime's number of bits
9034 This function will generate a new pair of prime and generator for
9035 use in the Diffie-Hellman key exchange. The new parameters will be
9036 allocated using 'gnutls_malloc()' and will be stored in the
9037 appropriate datum. This function is normally slow.
9039 Do not set the number of bits directly, use
9040 'gnutls_sec_param_to_pk_bits()' to get bits for 'GNUTLS_PK_DSA'.
9041 Also note that the DH parameters are only useful to servers. Since
9042 clients use the parameters sent by the server, it's of no use to
9043 call this in client side.
9045 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9046 otherwise an error code is returned.
9048 gnutls_dh_params_import_pkcs3
9049 -----------------------------
9051 -- Function: int gnutls_dh_params_import_pkcs3 (gnutls_dh_params_t
9052 PARAMS, const gnutls_datum_t * PKCS3_PARAMS,
9053 gnutls_x509_crt_fmt_t FORMAT)
9054 PARAMS: A structure where the parameters will be copied to
9056 PKCS3_PARAMS: should contain a PKCS3 DHParams structure PEM or DER
9059 FORMAT: the format of params. PEM or DER.
9061 This function will extract the DHParams found in a PKCS3 formatted
9062 structure. This is the format generated by "openssl dhparam" tool.
9064 If the structure is PEM encoded, it should have a header of "BEGIN
9067 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9068 otherwise an error code is returned.
9070 gnutls_dh_params_import_raw
9071 ---------------------------
9073 -- Function: int gnutls_dh_params_import_raw (gnutls_dh_params_t
9074 DH_PARAMS, const gnutls_datum_t * PRIME, const gnutls_datum_t
9076 DH_PARAMS: Is a structure that will hold the prime numbers
9078 PRIME: holds the new prime
9080 GENERATOR: holds the new generator
9082 This function will replace the pair of prime and generator for use
9083 in the Diffie-Hellman key exchange. The new parameters should be
9084 stored in the appropriate gnutls_datum.
9086 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9087 otherwise an error code is returned.
9089 gnutls_dh_params_init
9090 ---------------------
9092 -- Function: int gnutls_dh_params_init (gnutls_dh_params_t * DH_PARAMS)
9093 DH_PARAMS: Is a structure that will hold the prime numbers
9095 This function will initialize the DH parameters structure.
9097 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9098 otherwise an error code is returned.
9100 gnutls_dh_set_prime_bits
9101 ------------------------
9103 -- Function: void gnutls_dh_set_prime_bits (gnutls_session_t SESSION,
9105 SESSION: is a 'gnutls_session_t' structure.
9107 BITS: is the number of bits
9109 This function sets the number of bits, for use in an Diffie-Hellman
9110 key exchange. This is used both in DH ephemeral and DH anonymous
9111 cipher suites. This will set the minimum size of the prime that
9112 will be used for the handshake.
9114 In the client side it sets the minimum accepted number of bits. If
9115 a server sends a prime with less bits than that
9116 'GNUTLS_E_DH_PRIME_UNACCEPTABLE' will be returned by the handshake.
9118 This function has no effect in server side.
9120 gnutls_error_is_fatal
9121 ---------------------
9123 -- Function: int gnutls_error_is_fatal (int ERROR)
9124 ERROR: is a GnuTLS error code, a negative value
9126 If a GnuTLS function returns a negative value you may feed that
9127 value to this function to see if the error condition is fatal.
9129 Note that you may want to check the error code manually, since some
9130 non-fatal errors to the protocol may be fatal for you program.
9132 This function is only useful if you are dealing with errors from
9133 the record layer or the handshake layer.
9135 *Returns:* 1 if the error code is fatal, for positive 'error'
9136 values, 0 is returned. For unknown 'error' values, -1 is returned.
9138 gnutls_error_to_alert
9139 ---------------------
9141 -- Function: int gnutls_error_to_alert (int ERR, int * LEVEL)
9142 ERR: is a negative integer
9144 LEVEL: the alert level will be stored there
9146 Get an alert depending on the error code returned by a gnutls
9147 function. All alerts sent by this function should be considered
9148 fatal. The only exception is when 'err' is 'GNUTLS_E_REHANDSHAKE',
9149 where a warning alert should be sent to the peer indicating that no
9150 renegotiation will be performed.
9152 If there is no mapping to a valid alert the alert to indicate
9153 internal error is returned.
9155 *Returns:* the alert code to use for a particular error code.
9160 -- Function: int gnutls_ext_register (int TYPE, const char * NAME,
9161 gnutls_ext_parse_type_t PARSE_TYPE, gnutls_ext_recv_func
9162 RECV_FUNC, gnutls_ext_send_func SEND_FUNC)
9163 TYPE: the 16-bit integer referring to the extension type
9165 NAME: human printable name of the extension used for debugging
9167 PARSE_TYPE: either 'GNUTLS_EXT_TLS' or 'GNUTLS_EXT_APPLICATION'.
9169 RECV_FUNC: a function to receive extension data
9171 SEND_FUNC: a function to send extension data
9173 This function is used to register a new TLS extension handler.
9175 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
9177 *Deprecated in:* 2.12.0
9182 -- Function: int gnutls_fingerprint (gnutls_digest_algorithm_t ALGO,
9183 const gnutls_datum_t * DATA, void * RESULT, size_t *
9185 ALGO: is a digest algorithm
9189 RESULT: is the place where the result will be copied (may be null).
9191 RESULT_SIZE: should hold the size of the result. The actual size
9192 of the returned result will also be copied there.
9194 This function will calculate a fingerprint (actually a hash), of
9195 the given data. The result is not printable data. You should
9196 convert it to hex, or to something else printable.
9198 This is the usual way to calculate a fingerprint of an X.509 DER
9199 encoded certificate. Note however that the fingerprint of an
9200 OpenPGP is not just a hash and cannot be calculated with this
9203 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
9204 otherwise an error code is returned.
9209 -- Function: void gnutls_free (void * PTR)
9210 This function will free data pointed by ptr.
9212 The deallocation function used is the one set by
9213 'gnutls_global_set_mem_functions()'.
9215 gnutls_global_deinit
9216 --------------------
9218 -- Function: void gnutls_global_deinit ( VOID)
9220 This function deinitializes the global data, that were initialized
9221 using 'gnutls_global_init()'.
9223 Note! This function is not thread safe. See the discussion for
9224 'gnutls_global_init()' for more information.
9229 -- Function: int gnutls_global_init ( VOID)
9231 This function initializes the global data to defaults. Every
9232 gnutls application has a global data which holds common parameters
9233 shared by gnutls session structures. You should call
9234 'gnutls_global_deinit()' when gnutls usage is no longer needed
9236 Note that this function will also initialize the underlying crypto
9237 backend, if it has not been initialized before.
9239 This function increment a global counter, so that
9240 'gnutls_global_deinit()' only releases resources when it has been
9241 called as many times as 'gnutls_global_init()'. This is useful
9242 when GnuTLS is used by more than one library in an application.
9243 This function can be called many times, but will only do something
9246 Note! This function is not thread safe. If two threads call this
9247 function simultaneously, they can cause a race between checking the
9248 global counter and incrementing it, causing both threads to execute
9249 the library initialization code. That would lead to a memory leak.
9250 To handle this, your application could invoke this function after
9251 aquiring a thread mutex. To ignore the potential memory leak is
9254 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
9255 otherwise an error code is returned.
9257 gnutls_global_set_log_function
9258 ------------------------------
9260 -- Function: void gnutls_global_set_log_function (gnutls_log_func
9262 LOG_FUNC: it's a log function
9264 This is the function where you set the logging function gnutls is
9265 going to use. This function only accepts a character array.
9266 Normally you may not use this function since it is only used for
9269 gnutls_log_func is of the form, void (*gnutls_log_func)( int level,
9272 gnutls_global_set_log_level
9273 ---------------------------
9275 -- Function: void gnutls_global_set_log_level (int LEVEL)
9276 LEVEL: it's an integer from 0 to 9.
9278 This is the function that allows you to set the log level. The
9279 level is an integer between 0 and 9. Higher values mean more
9280 verbosity. The default value is 0. Larger values should only be
9281 used with care, since they may reveal sensitive information.
9283 Use a log level over 10 to enable all debugging options.
9285 gnutls_global_set_mem_functions
9286 -------------------------------
9288 -- Function: void gnutls_global_set_mem_functions
9289 (gnutls_alloc_function ALLOC_FUNC, gnutls_alloc_function
9290 SECURE_ALLOC_FUNC, gnutls_is_secure_function IS_SECURE_FUNC,
9291 gnutls_realloc_function REALLOC_FUNC, gnutls_free_function
9293 ALLOC_FUNC: it's the default memory allocation function. Like
9296 SECURE_ALLOC_FUNC: This is the memory allocation function that will
9297 be used for sensitive data.
9299 IS_SECURE_FUNC: a function that returns 0 if the memory given is
9300 not secure. May be NULL.
9302 REALLOC_FUNC: A realloc function
9304 FREE_FUNC: The function that frees allocated data. Must accept a
9307 This is the function were you set the memory allocation functions
9308 gnutls is going to use. By default the libc's allocation functions
9309 ('malloc()', 'free()'), are used by gnutls, to allocate both
9310 sensitive and not sensitive data. This function is provided to set
9311 the memory allocation functions to something other than the
9314 This function must be called before 'gnutls_global_init()' is
9315 called. This function is not thread safe.
9317 gnutls_global_set_mutex
9318 -----------------------
9320 -- Function: void gnutls_global_set_mutex (mutex_init_func INIT,
9321 mutex_deinit_func DEINIT, mutex_lock_func LOCK,
9322 mutex_unlock_func UNLOCK)
9323 INIT: mutex initialization function
9325 DEINIT: mutex deinitialization function
9327 LOCK: mutex locking function
9329 UNLOCK: mutex unlocking function
9331 With this function you are allowed to override the default mutex
9332 locks used in some parts of gnutls and dependent libraries. This
9333 function should be used if you have complete control of your
9334 program and libraries. Do not call this function from a library.
9335 Instead only initialize gnutls and the default OS mutex locks will
9338 This function must be called before 'gnutls_global_init()'.
9340 gnutls_global_set_time_function
9341 -------------------------------
9343 -- Function: void gnutls_global_set_time_function (gnutls_time_func
9345 TIME_FUNC: it's the system time function
9347 This is the function where you can override the default system time
9350 gnutls_time_func is of the form, time_t (*gnutls_time_func)(
9353 gnutls_handshake_get_last_in
9354 ----------------------------
9356 -- Function: gnutls_handshake_description_t
9357 gnutls_handshake_get_last_in (gnutls_session_t SESSION)
9358 SESSION: is a 'gnutls_session_t' structure.
9360 This function is only useful to check where the last performed
9361 handshake failed. If the previous handshake succeed or was not
9362 performed at all then no meaningful value will be returned.
9364 Check 'gnutls_handshake_description_t' in gnutls.h for the
9365 available handshake descriptions.
9367 *Returns:* the last handshake message type received, a
9368 'gnutls_handshake_description_t'.
9370 gnutls_handshake_get_last_out
9371 -----------------------------
9373 -- Function: gnutls_handshake_description_t
9374 gnutls_handshake_get_last_out (gnutls_session_t SESSION)
9375 SESSION: is a 'gnutls_session_t' structure.
9377 This function is only useful to check where the last performed
9378 handshake failed. If the previous handshake succeed or was not
9379 performed at all then no meaningful value will be returned.
9381 Check 'gnutls_handshake_description_t' in gnutls.h for the
9382 available handshake descriptions.
9384 *Returns:* the last handshake message type sent, a
9385 'gnutls_handshake_description_t'.
9387 gnutls_handshake_set_max_packet_length
9388 --------------------------------------
9390 -- Function: void gnutls_handshake_set_max_packet_length
9391 (gnutls_session_t SESSION, size_t MAX)
9392 SESSION: is a 'gnutls_session_t' structure.
9394 MAX: is the maximum number.
9396 This function will set the maximum size of all handshake messages.
9397 Handshakes over this size are rejected with
9398 'GNUTLS_E_HANDSHAKE_TOO_LARGE' error code. The default value is
9399 48kb which is typically large enough. Set this to 0 if you do not
9400 want to set an upper limit.
9402 The reason for restricting the handshake message sizes are to limit
9403 Denial of Service attacks.
9405 gnutls_handshake_set_post_client_hello_function
9406 -----------------------------------------------
9408 -- Function: void gnutls_handshake_set_post_client_hello_function
9409 (gnutls_session_t SESSION,
9410 gnutls_handshake_post_client_hello_func FUNC)
9411 SESSION: is a 'gnutls_session_t' structure.
9413 FUNC: is the function to be called
9415 This function will set a callback to be called after the client
9416 hello has been received (callback valid in server side only). This
9417 allows the server to adjust settings based on received extensions.
9419 Those settings could be ciphersuites, requesting certificate, or
9420 anything else except for version negotiation (this is done before
9421 the hello message is parsed).
9423 This callback must return 0 on success or a gnutls error code to
9424 terminate the handshake.
9426 *Warning:* You should not use this function to terminate the
9427 handshake based on client input unless you know what you are doing.
9428 Before the handshake is finished there is no way to know if there
9429 is a man-in-the-middle attack being performed.
9431 gnutls_handshake_set_private_extensions
9432 ---------------------------------------
9434 -- Function: void gnutls_handshake_set_private_extensions
9435 (gnutls_session_t SESSION, int ALLOW)
9436 SESSION: is a 'gnutls_session_t' structure.
9438 ALLOW: is an integer (0 or 1)
9440 This function will enable or disable the use of private cipher
9441 suites (the ones that start with 0xFF). By default or if 'allow' is
9442 0 then these cipher suites will not be advertized nor used.
9444 Unless this function is called with the option to allow (1), then
9445 no compression algorithms, like LZO. That is because these
9446 algorithms are not yet defined in any RFC or even internet draft.
9448 Enabling the private ciphersuites when talking to other than gnutls
9449 servers and clients may cause interoperability problems.
9454 -- Function: int gnutls_handshake (gnutls_session_t SESSION)
9455 SESSION: is a 'gnutls_session_t' structure.
9457 This function does the handshake of the TLS/SSL protocol, and
9458 initializes the TLS connection.
9460 This function will fail if any problem is encountered, and will
9461 return a negative error code. In case of a client, if the client
9462 has asked to resume a session, but the server couldn't, then a full
9463 handshake will be performed.
9465 The non-fatal errors such as 'GNUTLS_E_AGAIN' and
9466 'GNUTLS_E_INTERRUPTED' interrupt the handshake procedure, which
9467 should be later be resumed. Call this function again, until it
9468 returns 0; cf. 'gnutls_record_get_direction()' and
9469 'gnutls_error_is_fatal()'.
9471 If this function is called by a server after a rehandshake request
9472 then 'GNUTLS_E_GOT_APPLICATION_DATA' or
9473 'GNUTLS_E_WARNING_ALERT_RECEIVED' may be returned. Note that these
9474 are non fatal errors, only in the specific case of a rehandshake.
9475 Their meaning is that the client rejected the rehandshake request
9476 or in the case of 'GNUTLS_E_GOT_APPLICATION_DATA' it might also
9477 mean that some data were pending.
9479 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
9484 -- Function: void gnutls_hash_deinit (gnutls_hash_hd_t HANDLE, void *
9486 HANDLE: is a 'gnutls_hash_hd_t' structure.
9488 DIGEST: is the output value of the hash
9490 This function will deinitialize all resources occupied by the given
9498 -- Function: int gnutls_hash_fast (gnutls_digest_algorithm_t ALGORITHM,
9499 const void * TEXT, size_t TEXTLEN, void * DIGEST)
9500 ALGORITHM: the hash algorithm to use
9502 TEXT: the data to hash
9504 TEXTLEN: The length of data to hash
9506 DIGEST: is the output value of the hash
9508 This convenience function will hash the given data and return
9509 output on a single call.
9511 *Returns:* Zero or a negative value on error.
9518 -- Function: int gnutls_hash_get_len (gnutls_digest_algorithm_t
9520 ALGORITHM: the hash algorithm to use
9522 This function will return the length of the output data of the
9523 given hash algorithm.
9525 *Returns:* The length or zero on error.
9532 -- Function: int gnutls_hash_init (gnutls_hash_hd_t * DIG,
9533 gnutls_digest_algorithm_t ALGORITHM)
9534 DIG: is a 'gnutls_hash_hd_t' structure.
9536 ALGORITHM: the hash algorithm to use
9538 This function will initialize an context that can be used to
9539 produce a Message Digest of data. This will effectively use the
9540 current crypto backend in use by gnutls or the cryptographic
9543 *Returns:* Zero or a negative value on error.
9550 -- Function: void gnutls_hash_output (gnutls_hash_hd_t HANDLE, void *
9552 HANDLE: is a 'gnutls_hash_hd_t' structure.
9554 DIGEST: is the output value of the hash
9556 This function will output the current hash value.
9563 -- Function: int gnutls_hash (gnutls_hash_hd_t HANDLE, const void *
9564 TEXT, size_t TEXTLEN)
9565 HANDLE: is a 'gnutls_cipher_hd_t' structure.
9567 TEXT: the data to hash
9569 TEXTLEN: The length of data to hash
9571 This function will hash the given data using the algorithm
9572 specified by the context.
9574 *Returns:* Zero or a negative value on error.
9581 -- Function: int gnutls_hex2bin (const char * HEX_DATA, size_t
9582 HEX_SIZE, char * BIN_DATA, size_t * BIN_SIZE)
9583 HEX_DATA: string with data in hex format
9585 HEX_SIZE: size of hex data
9587 BIN_DATA: output array with binary data
9589 BIN_SIZE: when calling *'bin_size' should hold size of 'bin_data',
9590 on return will hold actual size of 'bin_data'.
9592 Convert a buffer with hex data to binary data.
9594 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
9601 -- Function: int gnutls_hex_decode (const gnutls_datum_t * HEX_DATA,
9602 char * RESULT, size_t * RESULT_SIZE)
9603 HEX_DATA: contain the encoded data
9605 RESULT: the place where decoded data will be copied
9607 RESULT_SIZE: holds the size of the result
9609 This function will decode the given encoded data, using the hex
9610 encoding used by PSK password files.
9612 Note that hex_data should be null terminated.
9614 *Returns:* 'GNUTLS_E_SHORT_MEMORY_BUFFER' if the buffer given is
9615 not long enough, or 0 on success.
9620 -- Function: int gnutls_hex_encode (const gnutls_datum_t * DATA, char *
9621 RESULT, size_t * RESULT_SIZE)
9622 DATA: contain the raw data
9624 RESULT: the place where hex data will be copied
9626 RESULT_SIZE: holds the size of the result
9628 This function will convert the given data to printable data, using
9629 the hex encoding, as used in the PSK password files.
9631 *Returns:* 'GNUTLS_E_SHORT_MEMORY_BUFFER' if the buffer given is
9632 not long enough, or 0 on success.
9637 -- Function: void gnutls_hmac_deinit (gnutls_hmac_hd_t HANDLE, void *
9639 HANDLE: is a 'gnutls_hmac_hd_t' structure.
9641 DIGEST: is the output value of the MAC
9643 This function will deinitialize all resources occupied by the given
9651 -- Function: int gnutls_hmac_fast (gnutls_mac_algorithm_t ALGORITHM,
9652 const void * KEY, size_t KEYLEN, const void * TEXT, size_t
9653 TEXTLEN, void * DIGEST)
9654 ALGORITHM: the hash algorithm to use
9658 KEYLEN: The length of the key
9660 TEXT: the data to hash
9662 TEXTLEN: The length of data to hash
9664 DIGEST: is the output value of the hash
9666 This convenience function will hash the given data and return
9667 output on a single call.
9669 *Returns:* Zero or a negative value on error.
9676 -- Function: int gnutls_hmac_get_len (gnutls_mac_algorithm_t ALGORITHM)
9677 ALGORITHM: the hmac algorithm to use
9679 This function will return the length of the output data of the
9680 given hmac algorithm.
9682 *Returns:* The length or zero on error.
9689 -- Function: int gnutls_hmac_init (gnutls_hmac_hd_t * DIG,
9690 gnutls_digest_algorithm_t ALGORITHM, const void * KEY, size_t
9692 DIG: is a 'gnutls_hmac_hd_t' structure.
9694 ALGORITHM: the HMAC algorithm to use
9696 KEY: The key to be used for encryption
9698 KEYLEN: The length of the key
9700 This function will initialize an context that can be used to
9701 produce a Message Authentication Code (MAC) of data. This will
9702 effectively use the current crypto backend in use by gnutls or the
9703 cryptographic accelerator in use.
9705 *Returns:* Zero or a negative value on error.
9712 -- Function: void gnutls_hmac_output (gnutls_hmac_hd_t HANDLE, void *
9714 HANDLE: is a 'gnutls_hmac_hd_t' structure.
9716 DIGEST: is the output value of the MAC
9718 This function will output the current MAC value.
9725 -- Function: int gnutls_hmac (gnutls_hmac_hd_t HANDLE, const void *
9726 TEXT, size_t TEXTLEN)
9727 HANDLE: is a 'gnutls_cipher_hd_t' structure.
9729 TEXT: the data to hash
9731 TEXTLEN: The length of data to hash
9733 This function will hash the given data using the algorithm
9734 specified by the context.
9736 *Returns:* Zero or a negative value on error.
9743 -- Function: int gnutls_init (gnutls_session_t * SESSION,
9744 gnutls_connection_end_t CON_END)
9745 SESSION: is a pointer to a 'gnutls_session_t' structure.
9747 CON_END: indicate if this session is to be used for server or
9750 This function initializes the current session to null. Every
9751 session must be initialized before use, so internal structures can
9752 be allocated. This function allocates structures which can only be
9753 free'd by calling 'gnutls_deinit()'. Returns zero on success.
9755 'con_end' can be one of 'GNUTLS_CLIENT' and 'GNUTLS_SERVER'.
9757 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
9762 -- Function: gnutls_kx_algorithm_t gnutls_kx_get_id (const char * NAME)
9765 Convert a string to a 'gnutls_kx_algorithm_t' value. The names are
9766 compared in a case insensitive way.
9768 *Returns:* an id of the specified KX algorithm, or
9769 'GNUTLS_KX_UNKNOWN' on error.
9774 -- Function: const char * gnutls_kx_get_name (gnutls_kx_algorithm_t
9776 ALGORITHM: is a key exchange algorithm
9778 Convert a 'gnutls_kx_algorithm_t' value to a string.
9780 *Returns:* a pointer to a string that contains the name of the
9781 specified key exchange algorithm, or 'NULL'.
9786 -- Function: gnutls_kx_algorithm_t gnutls_kx_get (gnutls_session_t
9788 SESSION: is a 'gnutls_session_t' structure.
9790 Get currently used key exchange algorithm.
9792 *Returns:* the key exchange algorithm used in the last handshake, a
9793 'gnutls_kx_algorithm_t' value.
9798 -- Function: const gnutls_kx_algorithm_t * gnutls_kx_list ( VOID)
9800 Get a list of supported key exchange algorithms.
9802 *Returns:* a zero-terminated list of 'gnutls_kx_algorithm_t'
9803 integers indicating the available key exchange algorithms.
9805 gnutls_kx_set_priority
9806 ----------------------
9808 -- Function: int gnutls_kx_set_priority (gnutls_session_t SESSION,
9810 SESSION: is a 'gnutls_session_t' structure.
9812 LIST: is a 0 terminated list of gnutls_kx_algorithm_t elements.
9814 Sets the priority on the key exchange algorithms supported by
9815 gnutls. Priority is higher for elements specified before others.
9816 After specifying the algorithms you want, you must append a 0.
9817 Note that the priority is set on the client. The server does not
9818 use the algorithm's priority except for disabling algorithms that
9821 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
9826 -- Function: gnutls_mac_algorithm_t gnutls_mac_get_id (const char *
9828 NAME: is a MAC algorithm name
9830 Convert a string to a 'gnutls_mac_algorithm_t' value. The names
9831 are compared in a case insensitive way.
9833 *Returns:* a 'gnutls_mac_algorithm_t' id of the specified MAC
9834 algorithm string, or 'GNUTLS_MAC_UNKNOWN' on failures.
9836 gnutls_mac_get_key_size
9837 -----------------------
9839 -- Function: size_t gnutls_mac_get_key_size (gnutls_mac_algorithm_t
9841 ALGORITHM: is an encryption algorithm
9843 Get size of MAC key.
9845 *Returns:* length (in bytes) of the given MAC key size, or 0 if the
9846 given MAC algorithm is invalid.
9851 -- Function: const char * gnutls_mac_get_name (gnutls_mac_algorithm_t
9853 ALGORITHM: is a MAC algorithm
9855 Convert a 'gnutls_mac_algorithm_t' value to a string.
9857 *Returns:* a string that contains the name of the specified MAC
9858 algorithm, or 'NULL'.
9863 -- Function: gnutls_mac_algorithm_t gnutls_mac_get (gnutls_session_t
9865 SESSION: is a 'gnutls_session_t' structure.
9867 Get currently used MAC algorithm.
9869 *Returns:* the currently used mac algorithm, a
9870 'gnutls_mac_algorithm_t' value.
9875 -- Function: const gnutls_mac_algorithm_t * gnutls_mac_list ( VOID)
9877 Get a list of hash algorithms for use as MACs. Note that not
9878 necessarily all MACs are supported in TLS cipher suites. For
9879 example, MD2 is not supported as a cipher suite, but is supported
9880 for other purposes (e.g., X.509 signature verification or similar).
9882 *Returns:* Return a zero-terminated list of
9883 'gnutls_mac_algorithm_t' integers indicating the available MACs.
9885 gnutls_mac_set_priority
9886 -----------------------
9888 -- Function: int gnutls_mac_set_priority (gnutls_session_t SESSION,
9890 SESSION: is a 'gnutls_session_t' structure.
9892 LIST: is a 0 terminated list of gnutls_mac_algorithm_t elements.
9894 Sets the priority on the mac algorithms supported by gnutls.
9895 Priority is higher for elements specified before others. After
9896 specifying the algorithms you want, you must append a 0. Note that
9897 the priority is set on the client. The server does not use the
9898 algorithm's priority except for disabling algorithms that were not
9901 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
9906 -- Function: void * gnutls_malloc (size_t S)
9908 This function will allocate 's' bytes data, and return a pointer to
9909 memory. This function is supposed to be used by callbacks.
9911 The allocation function used is the one set by
9912 'gnutls_global_set_mem_functions()'.
9914 gnutls_openpgp_send_cert
9915 ------------------------
9917 -- Function: void gnutls_openpgp_send_cert (gnutls_session_t SESSION,
9918 gnutls_openpgp_crt_status_t STATUS)
9919 SESSION: is a pointer to a 'gnutls_session_t' structure.
9921 STATUS: is one of GNUTLS_OPENPGP_CERT, or
9922 GNUTLS_OPENPGP_CERT_FINGERPRINT
9924 This function will order gnutls to send the key fingerprint instead
9925 of the key in the initial handshake procedure. This should be used
9926 with care and only when there is indication or knowledge that the
9927 server can obtain the client's key.
9929 gnutls_pem_base64_decode_alloc
9930 ------------------------------
9932 -- Function: int gnutls_pem_base64_decode_alloc (const char * HEADER,
9933 const gnutls_datum_t * B64_DATA, gnutls_datum_t * RESULT)
9934 HEADER: The PEM header (eg. CERTIFICATE)
9936 B64_DATA: contains the encoded data
9938 RESULT: the place where decoded data lie
9940 This function will decode the given encoded data. The decoded data
9941 will be allocated, and stored into result. If the header given is
9942 non null this function will search for "---BEGIN header" and decode
9943 only this part. Otherwise it will decode the first PEM packet
9946 You should use 'gnutls_free()' to free the returned data.
9948 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
9949 otherwise an error code is returned.
9951 gnutls_pem_base64_decode
9952 ------------------------
9954 -- Function: int gnutls_pem_base64_decode (const char * HEADER, const
9955 gnutls_datum_t * B64_DATA, unsigned char * RESULT, size_t *
9957 HEADER: A null terminated string with the PEM header (eg.
9960 B64_DATA: contain the encoded data
9962 RESULT: the place where decoded data will be copied
9964 RESULT_SIZE: holds the size of the result
9966 This function will decode the given encoded data. If the header
9967 given is non null this function will search for "---BEGIN header"
9968 and decode only this part. Otherwise it will decode the first PEM
9971 *Returns:* On success 'GNUTLS_E_SUCCESS' (0) is returned,
9972 'GNUTLS_E_SHORT_MEMORY_BUFFER' is returned if the buffer given is
9973 not long enough, or 0 on success.
9975 gnutls_pem_base64_encode_alloc
9976 ------------------------------
9978 -- Function: int gnutls_pem_base64_encode_alloc (const char * MSG,
9979 const gnutls_datum_t * DATA, gnutls_datum_t * RESULT)
9980 MSG: is a message to be put in the encoded header
9982 DATA: contains the raw data
9984 RESULT: will hold the newly allocated encoded data
9986 This function will convert the given data to printable data, using
9987 the base64 encoding. This is the encoding used in PEM messages.
9988 This function will allocate the required memory to hold the encoded
9991 You should use 'gnutls_free()' to free the returned data.
9993 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
9994 otherwise an error code is returned.
9996 gnutls_pem_base64_encode
9997 ------------------------
9999 -- Function: int gnutls_pem_base64_encode (const char * MSG, const
10000 gnutls_datum_t * DATA, char * RESULT, size_t * RESULT_SIZE)
10001 MSG: is a message to be put in the header
10003 DATA: contain the raw data
10005 RESULT: the place where base64 data will be copied
10007 RESULT_SIZE: holds the size of the result
10009 This function will convert the given data to printable data, using
10010 the base64 encoding. This is the encoding used in PEM messages.
10012 The output string will be null terminated, although the size will
10013 not include the terminating null.
10015 *Returns:* On success 'GNUTLS_E_SUCCESS' (0) is returned,
10016 'GNUTLS_E_SHORT_MEMORY_BUFFER' is returned if the buffer given is
10017 not long enough, or 0 on success.
10022 -- Function: void gnutls_perror (int ERROR)
10023 ERROR: is a GnuTLS error code, a negative value
10025 This function is like 'perror()'. The only difference is that it
10026 accepts an error number returned by a gnutls function.
10028 gnutls_pk_algorithm_get_name
10029 ----------------------------
10031 -- Function: const char * gnutls_pk_algorithm_get_name
10032 (gnutls_pk_algorithm_t ALGORITHM)
10033 ALGORITHM: is a pk algorithm
10035 Convert a 'gnutls_pk_algorithm_t' value to a string.
10037 *Returns:* a string that contains the name of the specified public
10038 key algorithm, or 'NULL'.
10040 gnutls_pk_bits_to_sec_param
10041 ---------------------------
10043 -- Function: gnutls_sec_param_t gnutls_pk_bits_to_sec_param
10044 (gnutls_pk_algorithm_t ALGO, unsigned int BITS)
10045 ALGO: is a public key algorithm
10047 BITS: is the number of bits
10049 This is the inverse of 'gnutls_sec_param_to_pk_bits()'. Given an
10050 algorithm and the number of bits, it will return the security
10051 parameter. This is a rough indication.
10053 *Returns:* The security parameter.
10058 -- Function: gnutls_pk_algorithm_t gnutls_pk_get_id (const char * NAME)
10059 NAME: is a string containing a public key algorithm name.
10061 Convert a string to a 'gnutls_pk_algorithm_t' value. The names are
10062 compared in a case insensitive way. For example,
10063 gnutls_pk_get_id("RSA") will return 'GNUTLS_PK_RSA'.
10065 *Returns:* a 'gnutls_pk_algorithm_t' id of the specified public key
10066 algorithm string, or 'GNUTLS_PK_UNKNOWN' on failures.
10073 -- Function: const char * gnutls_pk_get_name (gnutls_pk_algorithm_t
10075 ALGORITHM: is a public key algorithm
10077 Convert a 'gnutls_pk_algorithm_t' value to a string.
10079 *Returns:* a pointer to a string that contains the name of the
10080 specified public key algorithm, or 'NULL'.
10087 -- Function: const gnutls_pk_algorithm_t * gnutls_pk_list ( VOID)
10089 Get a list of supported public key algorithms.
10091 *Returns:* a zero-terminated list of 'gnutls_pk_algorithm_t'
10092 integers indicating the available ciphers.
10096 gnutls_pkcs11_add_provider
10097 --------------------------
10099 -- Function: int gnutls_pkcs11_add_provider (const char * NAME, const
10101 NAME: The filename of the module
10103 PARAMS: should be NULL
10105 This function will load and add a PKCS 11 module to the module list
10106 used in gnutls. After this function is called the module will be
10107 used for PKCS 11 operations.
10109 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10110 negative error value.
10112 gnutls_pkcs11_copy_secret_key
10113 -----------------------------
10115 -- Function: int gnutls_pkcs11_copy_secret_key (const char * TOKEN_URL,
10116 gnutls_datum_t * KEY, const char * LABEL, unsigned int
10117 KEY_USAGE, unsigned int FLAGS)
10118 TOKEN_URL: A PKCS '11' URL specifying a token
10122 LABEL: A name to be used for the stored data
10124 KEY_USAGE: One of GNUTLS_KEY_*
10126 FLAGS: One of GNUTLS_PKCS11_OBJ_FLAG_*
10128 This function will copy a raw secret (symmetric) key into a PKCS
10129 '11' token specified by a URL. The key can be marked as sensitive
10132 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10133 negative error value.
10135 gnutls_pkcs11_copy_x509_crt
10136 ---------------------------
10138 -- Function: int gnutls_pkcs11_copy_x509_crt (const char * TOKEN_URL,
10139 gnutls_x509_crt_t CRT, const char * LABEL, unsigned int FLAGS)
10140 TOKEN_URL: A PKCS '11' URL specifying a token
10144 LABEL: A name to be used for the stored data
10146 FLAGS: One of GNUTLS_PKCS11_OBJ_FLAG_*
10148 This function will copy a certificate into a PKCS '11' token
10149 specified by a URL. The certificate can be marked as trusted or
10152 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10153 negative error value.
10155 gnutls_pkcs11_copy_x509_privkey
10156 -------------------------------
10158 -- Function: int gnutls_pkcs11_copy_x509_privkey (const char *
10159 TOKEN_URL, gnutls_x509_privkey_t KEY, const char * LABEL,
10160 unsigned int KEY_USAGE, unsigned int FLAGS)
10161 TOKEN_URL: A PKCS '11' URL specifying a token
10165 LABEL: A name to be used for the stored data
10167 KEY_USAGE: One of GNUTLS_KEY_*
10169 FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
10171 This function will copy a private key into a PKCS '11' token
10172 specified by a URL. It is highly recommended flags to contain
10173 'GNUTLS_PKCS11_OBJ_FLAG_MARK_SENSITIVE' unless there is a strong
10176 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10177 negative error value.
10179 gnutls_pkcs11_deinit
10180 --------------------
10182 -- Function: void gnutls_pkcs11_deinit ( VOID)
10184 This function will deinitialize the PKCS 11 subsystem in gnutls.
10186 gnutls_pkcs11_delete_url
10187 ------------------------
10189 -- Function: int gnutls_pkcs11_delete_url (const char * OBJECT_URL,
10190 unsigned int FLAGS)
10191 OBJECT_URL: The URL of the object to delete.
10193 FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
10195 This function will delete objects matching the given URL.
10197 *Returns:* On success, the number of objects deleted is returned,
10198 otherwise a negative error value.
10203 -- Function: int gnutls_pkcs11_init (unsigned int FLAGS, const char *
10204 DEPRECATED_CONFIG_FILE)
10205 FLAGS: 'GNUTLS_PKCS11_FLAG_MANUAL' or 'GNUTLS_PKCS11_FLAG_AUTO'
10207 DEPRECATED_CONFIG_FILE: either NULL or the location of a deprecated
10210 This function will initialize the PKCS 11 subsystem in gnutls. It
10211 will read configuration files if 'GNUTLS_PKCS11_FLAG_AUTO' is used
10212 or allow you to independently load PKCS 11 modules using
10213 'gnutls_pkcs11_add_provider()' if 'GNUTLS_PKCS11_FLAG_MANUAL' is
10216 Using a custom configfile is deprecated and will not be supported
10217 in future versions of gnutls.
10219 Normally you don't need to call this function since it is being
10220 called by 'gnutls_global_init()' using the
10221 'GNUTLS_PKCS11_FLAG_AUTO'. If you need to call this function, you
10222 must call it before 'gnutls_global_init()'.
10224 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10225 negative error value.
10227 gnutls_pkcs11_obj_deinit
10228 ------------------------
10230 -- Function: void gnutls_pkcs11_obj_deinit (gnutls_pkcs11_obj_t OBJ)
10231 OBJ: The structure to be initialized
10233 This function will deinitialize a certificate structure.
10235 gnutls_pkcs11_obj_export_url
10236 ----------------------------
10238 -- Function: int gnutls_pkcs11_obj_export_url (gnutls_pkcs11_obj_t OBJ,
10239 gnutls_pkcs11_url_type_t DETAILED, char ** URL)
10240 OBJ: Holds the PKCS 11 certificate
10242 DETAILED: non zero if a detailed URL is required
10244 URL: will contain an allocated url
10246 This function will export a URL identifying the given certificate.
10248 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10249 negative error value.
10251 gnutls_pkcs11_obj_export
10252 ------------------------
10254 -- Function: int gnutls_pkcs11_obj_export (gnutls_pkcs11_obj_t OBJ,
10255 void * OUTPUT_DATA, size_t * OUTPUT_DATA_SIZE)
10256 OBJ: Holds the object
10258 OUTPUT_DATA: will contain a certificate PEM or DER encoded
10260 OUTPUT_DATA_SIZE: holds the size of output_data (and will be
10261 replaced by the actual size of parameters)
10263 This function will export the pkcs11 object data. It is normal for
10264 PKCS '11' data to be inaccesible and in that case
10265 'GNUTLS_E_INVALID_REQUEST' will be returned.
10267 If the buffer provided is not long enough to hold the output, then
10268 *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will
10271 If the structure is PEM encoded, it will have a header of "BEGIN
10274 *Return value:* In case of failure a negative value will be
10275 returned, and 0 on success.
10277 gnutls_pkcs11_obj_get_info
10278 --------------------------
10280 -- Function: int gnutls_pkcs11_obj_get_info (gnutls_pkcs11_obj_t CRT,
10281 gnutls_pkcs11_obj_info_t ITYPE, void * OUTPUT, size_t *
10283 CRT: should contain a 'gnutls_pkcs11_obj_t' structure
10285 ITYPE: Denotes the type of information requested
10287 OUTPUT: where output will be stored
10289 OUTPUT_SIZE: contains the maximum size of the output and will be
10290 overwritten with actual
10292 This function will return information about the PKCS 11
10293 certificatesuch as the label, id as well as token information where
10294 the key is stored. When output is text it returns null terminated
10295 string although 'output_size' contains the size of the actual data
10298 *Returns:* zero on success or a negative value on error.
10300 gnutls_pkcs11_obj_get_type
10301 --------------------------
10303 -- Function: gnutls_pkcs11_obj_type_t gnutls_pkcs11_obj_get_type
10304 (gnutls_pkcs11_obj_t OBJ)
10305 This function will return the type of the certificate being stored
10308 *Returns:* The type of the certificate.
10310 gnutls_pkcs11_obj_import_url
10311 ----------------------------
10313 -- Function: int gnutls_pkcs11_obj_import_url (gnutls_pkcs11_obj_t
10314 CERT, const char * URL, unsigned int FLAGS)
10315 CERT: The structure to store the parsed certificate
10317 URL: a PKCS 11 url identifying the key
10319 FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
10321 This function will "import" a PKCS 11 URL identifying a certificate
10322 key to the 'gnutls_pkcs11_obj_t' structure. This does not involve
10323 any parsing (such as X.509 or OpenPGP) since the
10324 'gnutls_pkcs11_obj_t' is format agnostic. Only data are
10327 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10328 negative error value.
10330 gnutls_pkcs11_obj_init
10331 ----------------------
10333 -- Function: int gnutls_pkcs11_obj_init (gnutls_pkcs11_obj_t * OBJ)
10334 OBJ: The structure to be initialized
10336 This function will initialize a pkcs11 certificate structure.
10338 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10339 negative error value.
10341 gnutls_pkcs11_obj_list_import_url
10342 ---------------------------------
10344 -- Function: int gnutls_pkcs11_obj_list_import_url (gnutls_pkcs11_obj_t
10345 * P_LIST, unsigned int * N_LIST, const char * URL,
10346 gnutls_pkcs11_obj_attr_t ATTRS, unsigned int FLAGS)
10347 P_LIST: An uninitialized object list (may be NULL)
10349 N_LIST: initially should hold the maximum size of the list. Will
10350 contain the actual size.
10352 URL: A PKCS 11 url identifying a set of objects
10354 ATTRS: Attributes of type 'gnutls_pkcs11_obj_attr_t' that can be
10355 used to limit output
10357 FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
10359 This function will initialize and set values to an object list by
10360 using all objects identified by a PKCS 11 URL.
10362 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10363 negative error value.
10365 gnutls_pkcs11_privkey_deinit
10366 ----------------------------
10368 -- Function: void gnutls_pkcs11_privkey_deinit (gnutls_pkcs11_privkey_t
10370 KEY: The structure to be initialized
10372 This function will deinitialize a private key structure.
10374 gnutls_pkcs11_privkey_export_url
10375 --------------------------------
10377 -- Function: int gnutls_pkcs11_privkey_export_url
10378 (gnutls_pkcs11_privkey_t KEY, gnutls_pkcs11_url_type_t
10379 DETAILED, char ** URL)
10380 KEY: Holds the PKCS 11 key
10382 DETAILED: non zero if a detailed URL is required
10384 URL: will contain an allocated url
10386 This function will export a URL identifying the given key.
10388 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10389 negative error value.
10391 gnutls_pkcs11_privkey_get_info
10392 ------------------------------
10394 -- Function: int gnutls_pkcs11_privkey_get_info
10395 (gnutls_pkcs11_privkey_t PKEY, gnutls_pkcs11_obj_info_t ITYPE,
10396 void * OUTPUT, size_t * OUTPUT_SIZE)
10397 PKEY: should contain a 'gnutls_pkcs11_privkey_t' structure
10399 ITYPE: Denotes the type of information requested
10401 OUTPUT: where output will be stored
10403 OUTPUT_SIZE: contains the maximum size of the output and will be
10404 overwritten with actual
10406 This function will return information about the PKCS 11 private key
10407 such as the label, id as well as token information where the key is
10408 stored. When output is text it returns null terminated string
10409 although 'output_size' contains the size of the actual data only.
10411 *Returns:* zero on success or a negative value on error.
10413 gnutls_pkcs11_privkey_get_pk_algorithm
10414 --------------------------------------
10416 -- Function: int gnutls_pkcs11_privkey_get_pk_algorithm
10417 (gnutls_pkcs11_privkey_t KEY, unsigned int * BITS)
10418 KEY: should contain a 'gnutls_pkcs11_privkey_t' structure
10420 This function will return the public key algorithm of a private
10423 *Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
10424 success, or a negative value on error.
10426 gnutls_pkcs11_privkey_import_url
10427 --------------------------------
10429 -- Function: int gnutls_pkcs11_privkey_import_url
10430 (gnutls_pkcs11_privkey_t PKEY, const char * URL, unsigned int
10432 PKEY: The structure to store the parsed key
10434 URL: a PKCS 11 url identifying the key
10436 FLAGS: sequence of GNUTLS_PKCS_PRIVKEY_*
10438 This function will "import" a PKCS 11 URL identifying a private key
10439 to the 'gnutls_pkcs11_privkey_t' structure. In reality since in
10440 most cases keys cannot be exported, the private key structure is
10441 being associated with the available operations on the token.
10443 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10444 negative error value.
10446 gnutls_pkcs11_privkey_init
10447 --------------------------
10449 -- Function: int gnutls_pkcs11_privkey_init (gnutls_pkcs11_privkey_t *
10451 KEY: The structure to be initialized
10453 This function will initialize an private key structure.
10455 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10456 negative error value.
10458 gnutls_pkcs11_reinit
10459 --------------------
10461 -- Function: int gnutls_pkcs11_reinit ( VOID)
10463 This function will reinitialize the PKCS 11 subsystem in gnutls.
10464 This is required by PKCS 11 when an application uses 'fork()'. The
10465 reinitialization function must be called on the child.
10467 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
10468 otherwise a negative error value.
10472 gnutls_pkcs11_set_pin_function
10473 ------------------------------
10475 -- Function: void gnutls_pkcs11_set_pin_function
10476 (gnutls_pkcs11_pin_callback_t FN, void * USERDATA)
10477 FN: The PIN callback
10479 USERDATA: data to be supplied to callback
10481 This function will set a callback function to be used when a PIN is
10482 required for PKCS 11 operations.
10484 Callback for PKCS'11' PIN entry. The callback provides the PIN
10485 code to unlock the token with label 'token_label', specified by the
10488 The PIN code, as a NUL-terminated ASCII string, should be copied
10489 into the 'pin' buffer (of maximum size pin_max), and return 0 to
10490 indicate success. Alternatively, the callback may return a
10491 negative gnutls error code to indicate failure and cancel PIN entry
10492 (in which case, the contents of the 'pin' parameter are ignored).
10494 When a PIN is required, the callback will be invoked repeatedly
10495 (and indefinitely) until either the returned PIN code is correct,
10496 the callback returns failure, or the token refuses login (e.g.
10497 when the token is locked due to too many incorrect PINs!). For the
10498 first such invocation, the 'attempt' counter will have value zero;
10499 it will increase by one for each subsequent attempt.
10501 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10502 negative error value.
10504 gnutls_pkcs11_set_token_function
10505 --------------------------------
10507 -- Function: void gnutls_pkcs11_set_token_function
10508 (gnutls_pkcs11_token_callback_t FN, void * USERDATA)
10509 FN: The token callback
10511 USERDATA: data to be supplied to callback
10513 This function will set a callback function to be used when a token
10514 needs to be inserted to continue PKCS 11 operations.
10516 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10517 negative error value.
10519 gnutls_pkcs11_token_get_flags
10520 -----------------------------
10522 -- Function: int gnutls_pkcs11_token_get_flags (const char * URL,
10523 unsigned int * FLAGS)
10524 URL: should contain a PKCS 11 URL
10526 FLAGS: The output flags (GNUTLS_PKCS11_TOKEN_*)
10528 This function will return information about the PKCS 11 token
10531 *Returns:* zero on success or a negative value on error.
10533 gnutls_pkcs11_token_get_info
10534 ----------------------------
10536 -- Function: int gnutls_pkcs11_token_get_info (const char * URL,
10537 gnutls_pkcs11_token_info_t TTYPE, void * OUTPUT, size_t *
10539 URL: should contain a PKCS 11 URL
10541 TTYPE: Denotes the type of information requested
10543 OUTPUT: where output will be stored
10545 OUTPUT_SIZE: contains the maximum size of the output and will be
10546 overwritten with actual
10548 This function will return information about the PKCS 11 token such
10549 as the label, id as well as token information where the key is
10552 *Returns:* zero on success or a negative value on error.
10554 gnutls_pkcs11_token_get_mechanism
10555 ---------------------------------
10557 -- Function: int gnutls_pkcs11_token_get_mechanism (const char * URL,
10558 int IDX, unsigned long * MECHANISM)
10559 URL: should contain a PKCS 11 URL
10561 IDX: The index of the mechanism
10563 MECHANISM: The PKCS '11' mechanism ID
10565 This function will return the names of the supported mechanisms by
10566 the token. It should be called with an increasing index until it
10567 return GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE.
10569 *Returns:* zero on success or a negative value on error.
10571 gnutls_pkcs11_token_get_url
10572 ---------------------------
10574 -- Function: int gnutls_pkcs11_token_get_url (unsigned int SEQ,
10575 gnutls_pkcs11_url_type_t DETAILED, char ** URL)
10576 SEQ: sequence number starting from 0
10578 DETAILED: non zero if a detailed URL is required
10580 URL: will contain an allocated url
10582 This function will return the URL for each token available in
10583 system. The url has to be released using 'gnutls_free()'
10585 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned,
10586 'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE' if the sequence number
10587 exceeds the available tokens, otherwise a negative error value.
10589 gnutls_pkcs11_token_init
10590 ------------------------
10592 -- Function: int gnutls_pkcs11_token_init (const char * TOKEN_URL,
10593 const char * SO_PIN, const char * LABEL)
10594 TOKEN_URL: A PKCS '11' URL specifying a token
10596 SO_PIN: Security Officer's PIN
10598 LABEL: A name to be used for the token
10600 This function will initialize (format) a token. If the token is at
10601 a factory defaults state the security officer's PIN given will be
10602 set to be the default. Otherwise it should match the officer's
10605 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10606 negative error value.
10608 gnutls_pkcs11_token_set_pin
10609 ---------------------------
10611 -- Function: int gnutls_pkcs11_token_set_pin (const char * TOKEN_URL,
10612 const char * OLDPIN, const char * NEWPIN, unsigned int FLAGS)
10613 TOKEN_URL: A PKCS '11' URL specifying a token
10615 OLDPIN: old user's PIN
10617 NEWPIN: new user's PIN
10619 FLAGS: one of gnutls_pkcs11_pin_flag_t
10621 This function will modify or set a user's PIN for the given token.
10622 If it is called to set a user pin for first time the oldpin must be
10625 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10626 negative error value.
10631 -- Function: int gnutls_prf_raw (gnutls_session_t SESSION, size_t
10632 LABEL_SIZE, const char * LABEL, size_t SEED_SIZE, const char *
10633 SEED, size_t OUTSIZE, char * OUT)
10634 SESSION: is a 'gnutls_session_t' structure.
10636 LABEL_SIZE: length of the 'label' variable.
10638 LABEL: label used in PRF computation, typically a short string.
10640 SEED_SIZE: length of the 'seed' variable.
10642 SEED: optional extra data to seed the PRF with.
10644 OUTSIZE: size of pre-allocated output buffer to hold the output.
10646 OUT: pre-allocate buffer to hold the generated data.
10648 Apply the TLS Pseudo-Random-Function (PRF) using the master secret
10651 The 'label' variable usually contain a string denoting the purpose
10652 for the generated data. The 'seed' usually contain data such as
10653 the client and server random, perhaps together with some additional
10654 data that is added to guarantee uniqueness of the output for a
10655 particular purpose.
10657 Because the output is not guaranteed to be unique for a particular
10658 session unless 'seed' include the client random and server random
10659 fields (the PRF would output the same data on another connection
10660 resumed from the first one), it is not recommended to use this
10661 function directly. The 'gnutls_prf()' function seed the PRF with
10662 the client and server random fields directly, and is recommended if
10663 you want to generate pseudo random data unique for each session.
10665 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
10670 -- Function: int gnutls_prf (gnutls_session_t SESSION, size_t
10671 LABEL_SIZE, const char * LABEL, int SERVER_RANDOM_FIRST,
10672 size_t EXTRA_SIZE, const char * EXTRA, size_t OUTSIZE, char *
10674 SESSION: is a 'gnutls_session_t' structure.
10676 LABEL_SIZE: length of the 'label' variable.
10678 LABEL: label used in PRF computation, typically a short string.
10680 SERVER_RANDOM_FIRST: non-0 if server random field should be first
10683 EXTRA_SIZE: length of the 'extra' variable.
10685 EXTRA: optional extra data to seed the PRF with.
10687 OUTSIZE: size of pre-allocated output buffer to hold the output.
10689 OUT: pre-allocate buffer to hold the generated data.
10691 Apply the TLS Pseudo-Random-Function (PRF) using the master secret
10692 on some data, seeded with the client and server random fields.
10694 The 'label' variable usually contain a string denoting the purpose
10695 for the generated data. The 'server_random_first' indicate whether
10696 the client random field or the server random field should be first
10697 in the seed. Non-0 indicate that the server random field is first,
10698 0 that the client random field is first.
10700 The 'extra' variable can be used to add more data to the seed,
10701 after the random variables. It can be used to tie make sure the
10702 generated output is strongly connected to some additional data
10703 (e.g., a string used in user authentication).
10705 The output is placed in *'OUT', which must be pre-allocated.
10707 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
10709 gnutls_priority_deinit
10710 ----------------------
10712 -- Function: void gnutls_priority_deinit (gnutls_priority_t
10714 PRIORITY_CACHE: is a 'gnutls_prioritity_t' structure.
10716 Deinitializes the priority cache.
10718 gnutls_priority_init
10719 --------------------
10721 -- Function: int gnutls_priority_init (gnutls_priority_t *
10722 PRIORITY_CACHE, const char * PRIORITIES, const char **
10724 PRIORITY_CACHE: is a 'gnutls_prioritity_t' structure.
10726 PRIORITIES: is a string describing priorities
10728 ERR_POS: In case of an error this will have the position in the
10729 string the error occured
10731 Sets priorities for the ciphers, key exchange methods, macs and
10732 compression methods.
10734 The 'priorities' option allows you to specify a colon separated
10735 list of the cipher priorities to enable.
10737 *Common keywords:* Some keywords are defined to provide quick
10738 access to common preferences.
10740 "PERFORMANCE" means all the "secure" ciphersuites are enabled,
10741 limited to 128 bit ciphers and sorted by terms of speed
10744 "NORMAL" means all "secure" ciphersuites. The 256-bit ciphers are
10745 included as a fallback only. The ciphers are sorted by security
10748 "SECURE128" means all "secure" ciphersuites with ciphers up to 128
10749 bits, sorted by security margin.
10751 "SECURE256" means all "secure" ciphersuites including the 256 bit
10752 ciphers, sorted by security margin.
10754 "EXPORT" means all ciphersuites are enabled, including the
10755 low-security 40 bit ciphers.
10757 "NONE" means nothing is enabled. This disables even protocols and
10758 compression methods.
10760 *Special keywords:* "!" or "-" appended with an algorithm will
10761 remove this algorithm.
10763 "+" appended with an algorithm will add this algorithm.
10765 Check the GnuTLS manual section "Priority strings" for detailed
10769 "NONE:+VERS-TLS-ALL:+MAC-ALL:+RSA:+AES-128-CBC:+SIGN-ALL:+COMP-NULL"
10771 "NORMAL:-ARCFOUR-128" means normal ciphers except for ARCFOUR-128.
10773 "SECURE:-VERS-SSL3.0:+COMP-DEFLATE" means that only secure ciphers
10774 are enabled, SSL3.0 is disabled, and libz compression enabled.
10776 "NONE:+VERS-TLS-ALL:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1",
10778 "NORMAL:'COMPAT'" is the most compatible mode.
10780 *Returns:* On syntax error 'GNUTLS_E_INVALID_REQUEST' is returned,
10781 'GNUTLS_E_SUCCESS' on success, or an error code.
10783 gnutls_priority_set_direct
10784 --------------------------
10786 -- Function: int gnutls_priority_set_direct (gnutls_session_t SESSION,
10787 const char * PRIORITIES, const char ** ERR_POS)
10788 SESSION: is a 'gnutls_session_t' structure.
10790 PRIORITIES: is a string describing priorities
10792 ERR_POS: In case of an error this will have the position in the
10793 string the error occured
10795 Sets the priorities to use on the ciphers, key exchange methods,
10796 macs and compression methods. This function avoids keeping a
10797 priority cache and is used to directly set string priorities to a
10798 TLS session. For documentation check the 'gnutls_priority_init()'.
10800 *Returns:* On syntax error 'GNUTLS_E_INVALID_REQUEST' is returned,
10801 'GNUTLS_E_SUCCESS' on success, or an error code.
10803 gnutls_priority_set
10804 -------------------
10806 -- Function: int gnutls_priority_set (gnutls_session_t SESSION,
10807 gnutls_priority_t PRIORITY)
10808 SESSION: is a 'gnutls_session_t' structure.
10810 PRIORITY: is a 'gnutls_priority_t' structure.
10812 Sets the priorities to use on the ciphers, key exchange methods,
10813 macs and compression methods.
10815 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
10817 gnutls_privkey_decrypt_data
10818 ---------------------------
10820 -- Function: int gnutls_privkey_decrypt_data (gnutls_privkey_t KEY,
10821 unsigned int FLAGS, const gnutls_datum_t * CIPHERTEXT,
10822 gnutls_datum_t * PLAINTEXT)
10825 FLAGS: zero for now
10827 CIPHERTEXT: holds the data to be decrypted
10829 PLAINTEXT: will contain the decrypted data, allocated with
10832 This function will decrypt the given data using the algorithm
10833 supported by the private key.
10835 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10836 negative error value.
10838 gnutls_privkey_deinit
10839 ---------------------
10841 -- Function: void gnutls_privkey_deinit (gnutls_privkey_t KEY)
10842 KEY: The structure to be deinitialized
10844 This function will deinitialize a private key structure.
10846 gnutls_privkey_get_pk_algorithm
10847 -------------------------------
10849 -- Function: int gnutls_privkey_get_pk_algorithm (gnutls_privkey_t KEY,
10850 unsigned int * BITS)
10851 KEY: should contain a 'gnutls_privkey_t' structure
10853 BITS: If set will return the number of bits of the parameters (may
10856 This function will return the public key algorithm of a private key
10857 and if possible will return a number of bits that indicates the
10858 security parameter of the key.
10860 *Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
10861 success, or a negative value on error.
10863 gnutls_privkey_get_type
10864 -----------------------
10866 -- Function: gnutls_privkey_type_t gnutls_privkey_get_type
10867 (gnutls_privkey_t KEY)
10868 KEY: should contain a 'gnutls_privkey_t' structure
10870 This function will return the type of the private key. This is
10871 actually the type of the subsystem used to set this private key.
10873 *Returns:* a member of the 'gnutls_privkey_type_t' enumeration on
10874 success, or a negative value on error.
10876 gnutls_privkey_import_openpgp
10877 -----------------------------
10879 -- Function: int gnutls_privkey_import_openpgp (gnutls_privkey_t PKEY,
10880 gnutls_openpgp_privkey_t KEY, unsigned int FLAGS)
10881 PKEY: The private key
10883 KEY: The private key to be imported
10885 FLAGS: should be zero
10887 This function will import the given private key to the abstract
10888 'gnutls_privkey_t' structure.
10890 The 'gnutls_openpgp_privkey_t' object must not be deallocated
10891 during the lifetime of this structure. The subkey set as preferred
10892 will be used, or the master key otherwise.
10894 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10895 negative error value.
10897 gnutls_privkey_import_pkcs11
10898 ----------------------------
10900 -- Function: int gnutls_privkey_import_pkcs11 (gnutls_privkey_t PKEY,
10901 gnutls_pkcs11_privkey_t KEY, unsigned int FLAGS)
10902 PKEY: The private key
10904 KEY: The private key to be imported
10906 FLAGS: should be zero
10908 This function will import the given private key to the abstract
10909 'gnutls_privkey_t' structure.
10911 The 'gnutls_pkcs11_privkey_t' object must not be deallocated during
10912 the lifetime of this structure.
10914 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10915 negative error value.
10917 gnutls_privkey_import_x509
10918 --------------------------
10920 -- Function: int gnutls_privkey_import_x509 (gnutls_privkey_t PKEY,
10921 gnutls_x509_privkey_t KEY, unsigned int FLAGS)
10922 PKEY: The private key
10924 KEY: The private key to be imported
10926 FLAGS: should be zero
10928 This function will import the given private key to the abstract
10929 'gnutls_privkey_t' structure.
10931 The 'gnutls_x509_privkey_t' object must not be deallocated during
10932 the lifetime of this structure.
10934 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10935 negative error value.
10937 gnutls_privkey_init
10938 -------------------
10940 -- Function: int gnutls_privkey_init (gnutls_privkey_t * KEY)
10941 KEY: The structure to be initialized
10943 This function will initialize an private key structure.
10945 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10946 negative error value.
10948 gnutls_privkey_sign_data
10949 ------------------------
10951 -- Function: int gnutls_privkey_sign_data (gnutls_privkey_t SIGNER,
10952 gnutls_digest_algorithm_t HASH, unsigned int FLAGS, const
10953 gnutls_datum_t * DATA, gnutls_datum_t * SIGNATURE)
10954 SIGNER: Holds the key
10956 HASH: should be a digest algorithm
10958 FLAGS: should be 0 for now
10960 DATA: holds the data to be signed
10962 SIGNATURE: will contain the signature allocate with
10965 This function will sign the given data using a signature algorithm
10966 supported by the private key. Signature algorithms are always used
10967 together with a hash functions. Different hash functions may be
10968 used for the RSA algorithm, but only SHA-1 for the DSA keys.
10970 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
10971 negative error value.
10975 gnutls_privkey_sign_hash
10976 ------------------------
10978 -- Function: int gnutls_privkey_sign_hash (gnutls_privkey_t SIGNER,
10979 gnutls_digest_algorithm_t HASH_ALGO, unsigned int FLAGS, const
10980 gnutls_datum_t * HASH_DATA, gnutls_datum_t * SIGNATURE)
10981 SIGNER: Holds the signer's key
10983 HASH_ALGO: The hash algorithm used
10985 FLAGS: zero for now
10987 HASH_DATA: holds the data to be signed
10989 SIGNATURE: will contain newly allocated signature
10991 This function will sign the given hashed data using a signature
10992 algorithm supported by the private key. Signature algorithms are
10993 always used together with a hash functions. Different hash
10994 functions may be used for the RSA algorithm, but only SHA-XXX for
10997 Use 'gnutls_x509_crt_get_preferred_hash_algorithm()' to determine
10998 the hash algorithm.
11000 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11001 negative error value.
11005 gnutls_protocol_get_id
11006 ----------------------
11008 -- Function: gnutls_protocol_t gnutls_protocol_get_id (const char *
11010 NAME: is a protocol name
11012 The names are compared in a case insensitive way.
11014 *Returns:* an id of the specified protocol, or
11015 'GNUTLS_VERSION_UNKNOWN' on error.
11017 gnutls_protocol_get_name
11018 ------------------------
11020 -- Function: const char * gnutls_protocol_get_name (gnutls_protocol_t
11022 VERSION: is a (gnutls) version number
11024 Convert a 'gnutls_protocol_t' value to a string.
11026 *Returns:* a string that contains the name of the specified TLS
11027 version (e.g., "TLS1.0"), or 'NULL'.
11029 gnutls_protocol_get_version
11030 ---------------------------
11032 -- Function: gnutls_protocol_t gnutls_protocol_get_version
11033 (gnutls_session_t SESSION)
11034 SESSION: is a 'gnutls_session_t' structure.
11036 Get TLS version, a 'gnutls_protocol_t' value.
11038 *Returns:* the version of the currently used protocol.
11040 gnutls_protocol_list
11041 --------------------
11043 -- Function: const gnutls_protocol_t * gnutls_protocol_list ( VOID)
11045 Get a list of supported protocols, e.g. SSL 3.0, TLS 1.0 etc.
11047 *Returns:* a zero-terminated list of 'gnutls_protocol_t' integers
11048 indicating the available protocols.
11050 gnutls_protocol_set_priority
11051 ----------------------------
11053 -- Function: int gnutls_protocol_set_priority (gnutls_session_t
11054 SESSION, const int * LIST)
11055 SESSION: is a 'gnutls_session_t' structure.
11057 LIST: is a 0 terminated list of gnutls_protocol_t elements.
11059 Sets the priority on the protocol versions supported by gnutls.
11060 This function actually enables or disables protocols. Newer
11061 protocol versions always have highest priority.
11063 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11065 gnutls_psk_allocate_client_credentials
11066 --------------------------------------
11068 -- Function: int gnutls_psk_allocate_client_credentials
11069 (gnutls_psk_client_credentials_t * SC)
11070 SC: is a pointer to a 'gnutls_psk_server_credentials_t' structure.
11072 This structure is complex enough to manipulate directly thus this
11073 helper function is provided in order to allocate it.
11075 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11077 gnutls_psk_allocate_server_credentials
11078 --------------------------------------
11080 -- Function: int gnutls_psk_allocate_server_credentials
11081 (gnutls_psk_server_credentials_t * SC)
11082 SC: is a pointer to a 'gnutls_psk_server_credentials_t' structure.
11084 This structure is complex enough to manipulate directly thus this
11085 helper function is provided in order to allocate it.
11087 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11089 gnutls_psk_client_get_hint
11090 --------------------------
11092 -- Function: const char * gnutls_psk_client_get_hint (gnutls_session_t
11094 SESSION: is a gnutls session
11096 The PSK identity hint may give the client help in deciding which
11097 username to use. This should only be called in case of PSK
11098 authentication and in case of a client.
11100 *Returns:* the identity hint of the peer, or 'NULL' in case of an
11105 gnutls_psk_free_client_credentials
11106 ----------------------------------
11108 -- Function: void gnutls_psk_free_client_credentials
11109 (gnutls_psk_client_credentials_t SC)
11110 SC: is a 'gnutls_psk_client_credentials_t' structure.
11112 This structure is complex enough to manipulate directly thus this
11113 helper function is provided in order to free (deallocate) it.
11115 gnutls_psk_free_server_credentials
11116 ----------------------------------
11118 -- Function: void gnutls_psk_free_server_credentials
11119 (gnutls_psk_server_credentials_t SC)
11120 SC: is a 'gnutls_psk_server_credentials_t' structure.
11122 This structure is complex enough to manipulate directly thus this
11123 helper function is provided in order to free (deallocate) it.
11125 gnutls_psk_netconf_derive_key
11126 -----------------------------
11128 -- Function: int gnutls_psk_netconf_derive_key (const char * PASSWORD,
11129 const char * PSK_IDENTITY, const char * PSK_IDENTITY_HINT,
11130 gnutls_datum_t * OUTPUT_KEY)
11131 PASSWORD: zero terminated string containing password.
11133 PSK_IDENTITY: zero terminated string with PSK identity.
11135 PSK_IDENTITY_HINT: zero terminated string with PSK identity hint.
11137 OUTPUT_KEY: output variable, contains newly allocated *data
11140 This function will derive a PSK key from a password, for use with
11141 the Netconf protocol.
11143 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11147 *Deprecated:* The need for this interface was dropped from the
11148 standard on publication as a RFC. The function works now but will
11149 return a hard failure in a future release.
11151 gnutls_psk_server_get_username
11152 ------------------------------
11154 -- Function: const char * gnutls_psk_server_get_username
11155 (gnutls_session_t SESSION)
11156 SESSION: is a gnutls session
11158 This should only be called in case of PSK authentication and in
11161 *Returns:* the username of the peer, or 'NULL' in case of an error.
11163 gnutls_psk_set_client_credentials_function
11164 ------------------------------------------
11166 -- Function: void gnutls_psk_set_client_credentials_function
11167 (gnutls_psk_client_credentials_t CRED,
11168 gnutls_psk_client_credentials_function * FUNC)
11169 CRED: is a 'gnutls_psk_server_credentials_t' structure.
11171 FUNC: is the callback function
11173 This function can be used to set a callback to retrieve the
11174 username and password for client PSK authentication. The
11175 callback's function form is: int (*callback)(gnutls_session_t,
11176 char** username, gnutls_datum_t* key);
11178 The 'username' and 'key'->data must be allocated using
11179 'gnutls_malloc()'. 'username' should be ASCII strings or UTF-8
11180 strings prepared using the "SASLprep" profile of "stringprep".
11182 The callback function will be called once per handshake.
11184 The callback function should return 0 on success. -1 indicates an
11187 gnutls_psk_set_client_credentials
11188 ---------------------------------
11190 -- Function: int gnutls_psk_set_client_credentials
11191 (gnutls_psk_client_credentials_t RES, const char * USERNAME,
11192 const gnutls_datum_t * KEY, gnutls_psk_key_flags FLAGS)
11193 RES: is a 'gnutls_psk_client_credentials_t' structure.
11195 USERNAME: is the user's zero-terminated userid
11197 KEY: is the user's key
11199 This function sets the username and password, in a
11200 gnutls_psk_client_credentials_t structure. Those will be used in
11201 PSK authentication. 'username' should be an ASCII string or UTF-8
11202 strings prepared using the "SASLprep" profile of "stringprep". The
11203 key can be either in raw byte format or in Hex format (without the
11206 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11208 gnutls_psk_set_params_function
11209 ------------------------------
11211 -- Function: void gnutls_psk_set_params_function
11212 (gnutls_psk_server_credentials_t RES, gnutls_params_function *
11214 RES: is a gnutls_psk_server_credentials_t structure
11216 FUNC: is the function to be called
11218 This function will set a callback in order for the server to get
11219 the Diffie-Hellman or RSA parameters for PSK authentication. The
11220 callback should return zero on success.
11222 gnutls_psk_set_server_credentials_file
11223 --------------------------------------
11225 -- Function: int gnutls_psk_set_server_credentials_file
11226 (gnutls_psk_server_credentials_t RES, const char *
11228 RES: is a 'gnutls_psk_server_credentials_t' structure.
11230 PASSWORD_FILE: is the PSK password file (passwd.psk)
11232 This function sets the password file, in a
11233 'gnutls_psk_server_credentials_t' structure. This password file
11234 holds usernames and keys and will be used for PSK authentication.
11236 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11238 gnutls_psk_set_server_credentials_function
11239 ------------------------------------------
11241 -- Function: void gnutls_psk_set_server_credentials_function
11242 (gnutls_psk_server_credentials_t CRED,
11243 gnutls_psk_server_credentials_function * FUNC)
11244 CRED: is a 'gnutls_psk_server_credentials_t' structure.
11246 FUNC: is the callback function
11248 This function can be used to set a callback to retrieve the user's
11249 PSK credentials. The callback's function form is: int
11250 (*callback)(gnutls_session_t, const char* username, gnutls_datum_t*
11253 'username' contains the actual username. The 'key' must be filled
11254 in using the 'gnutls_malloc()'.
11256 In case the callback returned a negative number then gnutls will
11257 assume that the username does not exist.
11259 The callback function will only be called once per handshake. The
11260 callback function should return 0 on success, while -1 indicates an
11263 gnutls_psk_set_server_credentials_hint
11264 --------------------------------------
11266 -- Function: int gnutls_psk_set_server_credentials_hint
11267 (gnutls_psk_server_credentials_t RES, const char * HINT)
11268 RES: is a 'gnutls_psk_server_credentials_t' structure.
11270 HINT: is the PSK identity hint string
11272 This function sets the identity hint, in a
11273 'gnutls_psk_server_credentials_t' structure. This hint is sent to
11274 the client to help it chose a good PSK credential (i.e., username
11277 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
11281 gnutls_psk_set_server_dh_params
11282 -------------------------------
11284 -- Function: void gnutls_psk_set_server_dh_params
11285 (gnutls_psk_server_credentials_t RES, gnutls_dh_params_t
11287 RES: is a gnutls_psk_server_credentials_t structure
11289 DH_PARAMS: is a structure that holds Diffie-Hellman parameters.
11291 This function will set the Diffie-Hellman parameters for an
11292 anonymous server to use. These parameters will be used in
11293 Diffie-Hellman exchange with PSK cipher suites.
11295 gnutls_psk_set_server_params_function
11296 -------------------------------------
11298 -- Function: void gnutls_psk_set_server_params_function
11299 (gnutls_psk_server_credentials_t RES, gnutls_params_function *
11301 RES: is a 'gnutls_certificate_credentials_t' structure
11303 FUNC: is the function to be called
11305 This function will set a callback in order for the server to get
11306 the Diffie-Hellman parameters for PSK authentication. The callback
11307 should return zero on success.
11309 gnutls_pubkey_deinit
11310 --------------------
11312 -- Function: void gnutls_pubkey_deinit (gnutls_pubkey_t KEY)
11313 KEY: The structure to be deinitialized
11315 This function will deinitialize a public key structure.
11317 gnutls_pubkey_export
11318 --------------------
11320 -- Function: int gnutls_pubkey_export (gnutls_pubkey_t KEY,
11321 gnutls_x509_crt_fmt_t FORMAT, void * OUTPUT_DATA, size_t *
11323 KEY: Holds the certificate
11325 FORMAT: the format of output params. One of PEM or DER.
11327 OUTPUT_DATA: will contain a certificate PEM or DER encoded
11329 OUTPUT_DATA_SIZE: holds the size of output_data (and will be
11330 replaced by the actual size of parameters)
11332 This function will export the certificate to DER or PEM format.
11334 If the buffer provided is not long enough to hold the output, then
11335 *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will
11338 If the structure is PEM encoded, it will have a header of "BEGIN
11341 *Return value:* In case of failure a negative value will be
11342 returned, and 0 on success.
11344 gnutls_pubkey_get_key_id
11345 ------------------------
11347 -- Function: int gnutls_pubkey_get_key_id (gnutls_pubkey_t KEY,
11348 unsigned int FLAGS, unsigned char * OUTPUT_DATA, size_t *
11350 KEY: Holds the public key
11352 FLAGS: should be 0 for now
11354 OUTPUT_DATA: will contain the key ID
11356 OUTPUT_DATA_SIZE: holds the size of output_data (and will be
11357 replaced by the actual size of parameters)
11359 This function will return a unique ID the depends on the public key
11360 parameters. This ID can be used in checking whether a certificate
11361 corresponds to the given public key.
11363 If the buffer provided is not long enough to hold the output, then
11364 *output_data_size is updated and GNUTLS_E_SHORT_MEMORY_BUFFER will
11365 be returned. The output will normally be a SHA-1 hash output,
11368 *Return value:* In case of failure a negative value will be
11369 returned, and 0 on success.
11371 gnutls_pubkey_get_key_usage
11372 ---------------------------
11374 -- Function: int gnutls_pubkey_get_key_usage (gnutls_pubkey_t KEY,
11375 unsigned int * USAGE)
11376 KEY: should contain a 'gnutls_pubkey_t' structure
11378 USAGE: If set will return the number of bits of the parameters (may
11381 This function will return the key usage of the public key.
11383 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11384 negative error value.
11386 gnutls_pubkey_get_pk_algorithm
11387 ------------------------------
11389 -- Function: int gnutls_pubkey_get_pk_algorithm (gnutls_pubkey_t KEY,
11390 unsigned int * BITS)
11391 KEY: should contain a 'gnutls_pubkey_t' structure
11393 BITS: If set will return the number of bits of the parameters (may
11396 This function will return the public key algorithm of a public key
11397 and if possible will return a number of bits that indicates the
11398 security parameter of the key.
11400 *Returns:* a member of the 'gnutls_pk_algorithm_t' enumeration on
11401 success, or a negative value on error.
11403 gnutls_pubkey_get_pk_dsa_raw
11404 ----------------------------
11406 -- Function: int gnutls_pubkey_get_pk_dsa_raw (gnutls_pubkey_t KEY,
11407 gnutls_datum_t * P, gnutls_datum_t * Q, gnutls_datum_t * G,
11408 gnutls_datum_t * Y)
11409 KEY: Holds the public key
11419 This function will export the DSA public key's parameters found in
11420 the given certificate. The new parameters will be allocated using
11421 'gnutls_malloc()' and will be stored in the appropriate datum.
11423 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
11425 gnutls_pubkey_get_pk_rsa_raw
11426 ----------------------------
11428 -- Function: int gnutls_pubkey_get_pk_rsa_raw (gnutls_pubkey_t KEY,
11429 gnutls_datum_t * M, gnutls_datum_t * E)
11430 KEY: Holds the certificate
11432 M: will hold the modulus
11434 E: will hold the public exponent
11436 This function will export the RSA public key's parameters found in
11437 the given structure. The new parameters will be allocated using
11438 'gnutls_malloc()' and will be stored in the appropriate datum.
11440 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
11442 gnutls_pubkey_get_preferred_hash_algorithm
11443 ------------------------------------------
11445 -- Function: int gnutls_pubkey_get_preferred_hash_algorithm
11446 (gnutls_pubkey_t KEY, gnutls_digest_algorithm_t * HASH,
11447 unsigned int * MAND)
11448 KEY: Holds the certificate
11450 HASH: The result of the call with the hash algorithm used for
11453 MAND: If non zero it means that the algorithm MUST use this hash.
11456 This function will read the certifcate and return the appropriate
11457 digest algorithm to use for signing with this certificate. Some
11458 certificates (i.e. DSA might not be able to sign without the
11459 preferred algorithm).
11461 *Returns:* the 0 if the hash algorithm is found. A negative value
11462 is returned on error.
11466 gnutls_pubkey_get_verify_algorithm
11467 ----------------------------------
11469 -- Function: int gnutls_pubkey_get_verify_algorithm (gnutls_pubkey_t
11470 KEY, const gnutls_datum_t * SIGNATURE,
11471 gnutls_digest_algorithm_t * HASH)
11472 KEY: Holds the certificate
11474 SIGNATURE: contains the signature
11476 HASH: The result of the call with the hash algorithm used for
11479 This function will read the certifcate and the signed data to
11480 determine the hash algorithm used to generate the signature.
11482 *Returns:* the 0 if the hash algorithm is found. A negative value
11483 is returned on error.
11485 gnutls_pubkey_import_dsa_raw
11486 ----------------------------
11488 -- Function: int gnutls_pubkey_import_dsa_raw (gnutls_pubkey_t KEY,
11489 const gnutls_datum_t * P, const gnutls_datum_t * Q, const
11490 gnutls_datum_t * G, const gnutls_datum_t * Y)
11491 KEY: The structure to store the parsed key
11501 This function will convert the given DSA raw parameters to the
11502 native 'gnutls_pubkey_t' format. The output will be stored in
11505 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11506 negative error value.
11508 gnutls_pubkey_import_openpgp
11509 ----------------------------
11511 -- Function: int gnutls_pubkey_import_openpgp (gnutls_pubkey_t KEY,
11512 gnutls_openpgp_crt_t CRT, unsigned int FLAGS)
11513 KEY: The public key
11515 CRT: The certificate to be imported
11517 FLAGS: should be zero
11519 This function will import the given public key to the abstract
11520 'gnutls_pubkey_t' structure. The subkey set as preferred will be
11521 imported or the master key otherwise.
11523 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11524 negative error value.
11526 gnutls_pubkey_import_pkcs11_url
11527 -------------------------------
11529 -- Function: int gnutls_pubkey_import_pkcs11_url (gnutls_pubkey_t KEY,
11530 const char * URL, unsigned int FLAGS)
11531 KEY: A key of type 'gnutls_pubkey_t'
11535 FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
11537 This function will import a PKCS 11 certificate to a
11538 'gnutls_pubkey_t' structure.
11540 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11541 negative error value.
11543 gnutls_pubkey_import_pkcs11
11544 ---------------------------
11546 -- Function: int gnutls_pubkey_import_pkcs11 (gnutls_pubkey_t KEY,
11547 gnutls_pkcs11_obj_t OBJ, unsigned int FLAGS)
11548 KEY: The public key
11550 OBJ: The parameters to be imported
11552 FLAGS: should be zero
11554 This function will import the given public key to the abstract
11555 'gnutls_pubkey_t' structure.
11557 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11558 negative error value.
11560 gnutls_pubkey_import_privkey
11561 ----------------------------
11563 -- Function: int gnutls_pubkey_import_privkey (gnutls_pubkey_t KEY,
11564 gnutls_privkey_t PKEY, unsigned int USAGE, unsigned int FLAGS)
11565 KEY: The public key
11567 PKEY: The private key
11569 USAGE: GNUTLS_KEY_* key usage flags.
11571 FLAGS: should be zero
11573 This function will import the given public key to the abstract
11574 'gnutls_pubkey_t' structure.
11576 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11577 negative error value.
11581 gnutls_pubkey_import_rsa_raw
11582 ----------------------------
11584 -- Function: int gnutls_pubkey_import_rsa_raw (gnutls_pubkey_t KEY,
11585 const gnutls_datum_t * M, const gnutls_datum_t * E)
11586 KEY: Is a structure will hold the parameters
11588 M: holds the modulus
11590 E: holds the public exponent
11592 This function will replace the parameters in the given structure.
11593 The new parameters should be stored in the appropriate
11596 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
11599 gnutls_pubkey_import_x509
11600 -------------------------
11602 -- Function: int gnutls_pubkey_import_x509 (gnutls_pubkey_t KEY,
11603 gnutls_x509_crt_t CRT, unsigned int FLAGS)
11604 KEY: The public key
11606 CRT: The certificate to be imported
11608 FLAGS: should be zero
11610 This function will import the given public key to the abstract
11611 'gnutls_pubkey_t' structure.
11613 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11614 negative error value.
11616 gnutls_pubkey_import
11617 --------------------
11619 -- Function: int gnutls_pubkey_import (gnutls_pubkey_t KEY, const
11620 gnutls_datum_t * DATA, gnutls_x509_crt_fmt_t FORMAT)
11621 KEY: The structure to store the parsed public key.
11623 DATA: The DER or PEM encoded certificate.
11625 FORMAT: One of DER or PEM
11627 This function will convert the given DER or PEM encoded Public key
11628 to the native gnutls_pubkey_t format.The output will be stored * in
11629 key. If the Certificate is PEM encoded it should have a header of
11632 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11633 negative error value.
11638 -- Function: int gnutls_pubkey_init (gnutls_pubkey_t * KEY)
11639 KEY: The structure to be initialized
11641 This function will initialize an public key structure.
11643 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11644 negative error value.
11646 gnutls_pubkey_set_key_usage
11647 ---------------------------
11649 -- Function: int gnutls_pubkey_set_key_usage (gnutls_pubkey_t KEY,
11650 unsigned int USAGE)
11651 KEY: a certificate of type 'gnutls_x509_crt_t'
11653 USAGE: an ORed sequence of the GNUTLS_KEY_* elements.
11655 This function will set the key usage flags of the public key. This
11656 is only useful if the key is to be exported to a certificate or
11657 certificate request.
11659 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
11660 negative error value.
11662 gnutls_pubkey_verify_data
11663 -------------------------
11665 -- Function: int gnutls_pubkey_verify_data (gnutls_pubkey_t PUBKEY,
11666 unsigned int FLAGS, const gnutls_datum_t * DATA, const
11667 gnutls_datum_t * SIGNATURE)
11668 PUBKEY: Holds the public key
11670 FLAGS: should be 0 for now
11672 DATA: holds the data to be signed
11674 SIGNATURE: contains the signature
11676 This function will verify the given signed data, using the
11677 parameters from the certificate.
11679 *Returns:* In case of a verification failure
11680 'GNUTLS_E_PK_SIG_VERIFY_FAILED' is returned, and a positive code on
11685 gnutls_pubkey_verify_hash
11686 -------------------------
11688 -- Function: int gnutls_pubkey_verify_hash (gnutls_pubkey_t KEY,
11689 unsigned int FLAGS, const gnutls_datum_t * HASH, const
11690 gnutls_datum_t * SIGNATURE)
11691 KEY: Holds the certificate
11693 FLAGS: should be 0 for now
11695 HASH: holds the hash digest to be verified
11697 SIGNATURE: contains the signature
11699 This function will verify the given signed digest, using the
11700 parameters from the certificate.
11702 *Returns:* In case of a verification failure
11703 'GNUTLS_E_PK_SIG_VERIFY_FAILED' is returned, and a positive code on
11706 gnutls_record_check_pending
11707 ---------------------------
11709 -- Function: size_t gnutls_record_check_pending (gnutls_session_t
11711 SESSION: is a 'gnutls_session_t' structure.
11713 This function checks if there are any data to receive in the gnutls
11716 *Returns:* the size of that data or 0.
11718 gnutls_record_disable_padding
11719 -----------------------------
11721 -- Function: void gnutls_record_disable_padding (gnutls_session_t
11723 SESSION: is a 'gnutls_session_t' structure.
11725 Used to disabled padding in TLS 1.0 and above. Normally you do not
11726 need to use this function, but there are buggy clients that
11727 complain if a server pads the encrypted data. This of course will
11728 disable protection against statistical attacks on the data.
11730 Normally only servers that require maximum compatibility with
11731 everything out there, need to call this function.
11733 gnutls_record_get_direction
11734 ---------------------------
11736 -- Function: int gnutls_record_get_direction (gnutls_session_t SESSION)
11737 SESSION: is a 'gnutls_session_t' structure.
11739 This function provides information about the internals of the
11740 record protocol and is only useful if a prior gnutls function call
11741 (e.g. 'gnutls_handshake()') was interrupted for some reason, that
11742 is, if a function returned 'GNUTLS_E_INTERRUPTED' or
11743 'GNUTLS_E_AGAIN'. In such a case, you might want to call
11744 'select()' or 'poll()' before calling the interrupted gnutls
11745 function again. To tell you whether a file descriptor should be
11746 selected for either reading or writing,
11747 'gnutls_record_get_direction()' returns 0 if the interrupted
11748 function was trying to read data, and 1 if it was trying to write
11751 *Returns:* 0 if trying to read data, 1 if trying to write data.
11753 gnutls_record_get_max_size
11754 --------------------------
11756 -- Function: size_t gnutls_record_get_max_size (gnutls_session_t
11758 SESSION: is a 'gnutls_session_t' structure.
11760 Get the record size. The maximum record size is negotiated by the
11761 client after the first handshake message.
11763 *Returns:* The maximum record packet size in this connection.
11768 -- Function: ssize_t gnutls_record_recv (gnutls_session_t SESSION, void
11769 * DATA, size_t SIZEOFDATA)
11770 SESSION: is a 'gnutls_session_t' structure.
11772 DATA: the buffer that the data will be read into
11774 SIZEOFDATA: the number of requested bytes
11776 This function has the similar semantics with 'recv()'. The only
11777 difference is that it accepts a GnuTLS session, and uses different
11780 In the special case that a server requests a renegotiation, the
11781 client may receive an error code of 'GNUTLS_E_REHANDSHAKE'. This
11782 message may be simply ignored, replied with an alert
11783 'GNUTLS_A_NO_RENEGOTIATION', or replied with a new handshake,
11784 depending on the client's will.
11786 If 'EINTR' is returned by the internal push function (the default
11787 is 'recv()') then 'GNUTLS_E_INTERRUPTED' will be returned. If
11788 'GNUTLS_E_INTERRUPTED' or 'GNUTLS_E_AGAIN' is returned, you must
11789 call this function again to get the data. See also
11790 'gnutls_record_get_direction()'.
11792 A server may also receive 'GNUTLS_E_REHANDSHAKE' when a client has
11793 initiated a handshake. In that case the server can only initiate a
11794 handshake or terminate the connection.
11796 *Returns:* the number of bytes received and zero on EOF. A negative
11797 error code is returned in case of an error. The number of bytes
11798 received might be less than 'sizeofdata'.
11803 -- Function: ssize_t gnutls_record_send (gnutls_session_t SESSION,
11804 const void * DATA, size_t SIZEOFDATA)
11805 SESSION: is a 'gnutls_session_t' structure.
11807 DATA: contains the data to send
11809 SIZEOFDATA: is the length of the data
11811 This function has the similar semantics with 'send()'. The only
11812 difference is that it accepts a GnuTLS session, and uses different
11815 Note that if the send buffer is full, 'send()' will block this
11816 function. See the 'send()' documentation for full information.
11817 You can replace the default push function by using
11818 'gnutls_transport_set_ptr2()' with a call to 'send()' with a
11819 MSG_DONTWAIT flag if blocking is a problem.
11821 If the EINTR is returned by the internal push function (the default
11822 is 'send()'} then 'GNUTLS_E_INTERRUPTED' will be returned. If
11823 'GNUTLS_E_INTERRUPTED' or 'GNUTLS_E_AGAIN' is returned, you must
11824 call this function again, with the same parameters; alternatively
11825 you could provide a 'NULL' pointer for data, and 0 for size. cf.
11826 'gnutls_record_get_direction()'.
11828 *Returns:* the number of bytes sent, or a negative error code. The
11829 number of bytes sent might be less than 'sizeofdata'. The maximum
11830 number of bytes this function can send in a single call depends on
11831 the negotiated maximum record size.
11833 gnutls_record_set_max_size
11834 --------------------------
11836 -- Function: ssize_t gnutls_record_set_max_size (gnutls_session_t
11837 SESSION, size_t SIZE)
11838 SESSION: is a 'gnutls_session_t' structure.
11840 SIZE: is the new size
11842 This function sets the maximum record packet size in this
11843 connection. This property can only be set to clients. The server
11844 may choose not to accept the requested size.
11846 Acceptable values are 512(=2^9), 1024(=2^10), 2048(=2^11) and
11847 4096(=2^12). The requested record size does get in effect
11848 immediately only while sending data. The receive part will take
11849 effect after a successful handshake.
11851 This function uses a TLS extension called 'max record size'. Not
11852 all TLS implementations use or even understand this extension.
11854 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
11855 otherwise an error code is returned.
11860 -- Function: int gnutls_rehandshake (gnutls_session_t SESSION)
11861 SESSION: is a 'gnutls_session_t' structure.
11863 This function will renegotiate security parameters with the client.
11864 This should only be called in case of a server.
11866 This message informs the peer that we want to renegotiate
11867 parameters (perform a handshake).
11869 If this function succeeds (returns 0), you must call the
11870 'gnutls_handshake()' function in order to negotiate the new
11873 Since TLS is full duplex some application data might have been sent
11874 during peer's processing of this message. In that case one should
11875 call 'gnutls_record_recv()' until GNUTLS_E_REHANDSHAKE is returned
11876 to clear any pending data. Care must be taken if rehandshake is
11877 mandatory to terminate if it does not start after some threshold.
11879 If the client does not wish to renegotiate parameters he will
11880 should with an alert message, thus the return code will be
11881 'GNUTLS_E_WARNING_ALERT_RECEIVED' and the alert will be
11882 'GNUTLS_A_NO_RENEGOTIATION'. A client may also choose to ignore
11885 *Returns:* 'GNUTLS_E_SUCCESS' on success, otherwise an error.
11890 -- Function: int gnutls_rnd (gnutls_rnd_level_t LEVEL, void * DATA,
11892 LEVEL: a security level
11894 DATA: place to store random bytes
11896 LEN: The requested size
11898 This function will generate random data and store it to output
11901 *Returns:* Zero or a negative value on error.
11903 gnutls_rsa_export_get_modulus_bits
11904 ----------------------------------
11906 -- Function: int gnutls_rsa_export_get_modulus_bits (gnutls_session_t
11908 SESSION: is a gnutls session
11910 Get the export RSA parameter's modulus size.
11912 *Returns:* the bits used in the last RSA-EXPORT key exchange with
11913 the peer, or a negative value in case of error.
11915 gnutls_rsa_export_get_pubkey
11916 ----------------------------
11918 -- Function: int gnutls_rsa_export_get_pubkey (gnutls_session_t
11919 SESSION, gnutls_datum_t * EXPONENT, gnutls_datum_t * MODULUS)
11920 SESSION: is a gnutls session
11922 EXPONENT: will hold the exponent.
11924 MODULUS: will hold the modulus.
11926 This function will return the peer's public key exponent and
11927 modulus used in the last RSA-EXPORT authentication. The output
11928 parameters must be freed with 'gnutls_free()'.
11930 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
11931 otherwise an error code is returned.
11933 gnutls_rsa_params_cpy
11934 ---------------------
11936 -- Function: int gnutls_rsa_params_cpy (gnutls_rsa_params_t DST,
11937 gnutls_rsa_params_t SRC)
11938 DST: Is the destination structure, which should be initialized.
11940 SRC: Is the source structure
11942 This function will copy the RSA parameters structure from source to
11945 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
11948 gnutls_rsa_params_deinit
11949 ------------------------
11951 -- Function: void gnutls_rsa_params_deinit (gnutls_rsa_params_t
11953 RSA_PARAMS: Is a structure that holds the parameters
11955 This function will deinitialize the RSA parameters structure.
11957 gnutls_rsa_params_export_pkcs1
11958 ------------------------------
11960 -- Function: int gnutls_rsa_params_export_pkcs1 (gnutls_rsa_params_t
11961 PARAMS, gnutls_x509_crt_fmt_t FORMAT, unsigned char *
11962 PARAMS_DATA, size_t * PARAMS_DATA_SIZE)
11963 PARAMS: Holds the RSA parameters
11965 FORMAT: the format of output params. One of PEM or DER.
11967 PARAMS_DATA: will contain a PKCS1 RSAPublicKey structure PEM or DER
11970 PARAMS_DATA_SIZE: holds the size of params_data (and will be
11971 replaced by the actual size of parameters)
11973 This function will export the given RSA parameters to a PKCS1
11974 RSAPublicKey structure. If the buffer provided is not long enough
11975 to hold the output, then GNUTLS_E_SHORT_MEMORY_BUFFER will be
11978 If the structure is PEM encoded, it will have a header of "BEGIN
11981 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
11984 gnutls_rsa_params_export_raw
11985 ----------------------------
11987 -- Function: int gnutls_rsa_params_export_raw (gnutls_rsa_params_t
11988 PARAMS, gnutls_datum_t * M, gnutls_datum_t * E, gnutls_datum_t
11989 * D, gnutls_datum_t * P, gnutls_datum_t * Q, gnutls_datum_t *
11990 U, unsigned int * BITS)
11991 PARAMS: a structure that holds the rsa parameters
11993 M: will hold the modulus
11995 E: will hold the public exponent
11997 D: will hold the private exponent
11999 P: will hold the first prime (p)
12001 Q: will hold the second prime (q)
12003 U: will hold the coefficient
12005 BITS: if non null will hold the prime's number of bits
12007 This function will export the RSA parameters found in the given
12008 structure. The new parameters will be allocated using
12009 'gnutls_malloc()' and will be stored in the appropriate datum.
12011 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
12014 gnutls_rsa_params_generate2
12015 ---------------------------
12017 -- Function: int gnutls_rsa_params_generate2 (gnutls_rsa_params_t
12018 PARAMS, unsigned int BITS)
12019 PARAMS: The structure where the parameters will be stored
12021 BITS: is the prime's number of bits
12023 This function will generate new temporary RSA parameters for use in
12024 RSA-EXPORT ciphersuites. This function is normally slow.
12026 Note that if the parameters are to be used in export cipher suites
12027 the bits value should be 512 or less. Also note that the
12028 generation of new RSA parameters is only useful to servers.
12029 Clients use the parameters sent by the server, thus it's no use
12030 calling this in client side.
12032 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
12035 gnutls_rsa_params_import_pkcs1
12036 ------------------------------
12038 -- Function: int gnutls_rsa_params_import_pkcs1 (gnutls_rsa_params_t
12039 PARAMS, const gnutls_datum_t * PKCS1_PARAMS,
12040 gnutls_x509_crt_fmt_t FORMAT)
12041 PARAMS: A structure where the parameters will be copied to
12043 PKCS1_PARAMS: should contain a PKCS1 RSAPublicKey structure PEM or
12046 FORMAT: the format of params. PEM or DER.
12048 This function will extract the RSAPublicKey found in a PKCS1
12049 formatted structure.
12051 If the structure is PEM encoded, it should have a header of "BEGIN
12054 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
12057 gnutls_rsa_params_import_raw
12058 ----------------------------
12060 -- Function: int gnutls_rsa_params_import_raw (gnutls_rsa_params_t
12061 RSA_PARAMS, const gnutls_datum_t * M, const gnutls_datum_t *
12062 E, const gnutls_datum_t * D, const gnutls_datum_t * P, const
12063 gnutls_datum_t * Q, const gnutls_datum_t * U)
12064 RSA_PARAMS: Is a structure will hold the parameters
12066 M: holds the modulus
12068 E: holds the public exponent
12070 D: holds the private exponent
12072 P: holds the first prime (p)
12074 Q: holds the second prime (q)
12076 U: holds the coefficient
12078 This function will replace the parameters in the given structure.
12079 The new parameters should be stored in the appropriate
12082 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
12085 gnutls_rsa_params_init
12086 ----------------------
12088 -- Function: int gnutls_rsa_params_init (gnutls_rsa_params_t *
12090 RSA_PARAMS: Is a structure that will hold the parameters
12092 This function will initialize the temporary RSA parameters
12095 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an negative error
12098 gnutls_safe_renegotiation_status
12099 --------------------------------
12101 -- Function: int gnutls_safe_renegotiation_status (gnutls_session_t
12103 SESSION: is a 'gnutls_session_t' structure.
12105 Can be used to check whether safe renegotiation is being used in
12106 the current session.
12108 *Returns:* 0 when safe renegotiation is not used and non zero when
12109 safe renegotiation is used.
12113 gnutls_sec_param_get_name
12114 -------------------------
12116 -- Function: const char * gnutls_sec_param_get_name (gnutls_sec_param_t
12118 PARAM: is a security parameter
12120 Convert a 'gnutls_sec_param_t' value to a string.
12122 *Returns:* a pointer to a string that contains the name of the
12123 specified public key algorithm, or 'NULL'.
12125 gnutls_sec_param_to_pk_bits
12126 ---------------------------
12128 -- Function: unsigned int gnutls_sec_param_to_pk_bits
12129 (gnutls_pk_algorithm_t ALGO, gnutls_sec_param_t PARAM)
12130 ALGO: is a public key algorithm
12132 PARAM: is a security parameter
12134 When generating private and public key pairs a difficult question
12135 is which size of "bits" the modulus will be in RSA and the group
12136 size in DSA. The easy answer is 1024, which is also wrong. This
12137 function will convert a human understandable security parameter to
12138 an appropriate size for the specific algorithm.
12140 *Returns:* The number of bits, or zero.
12142 gnutls_server_name_get
12143 ----------------------
12145 -- Function: int gnutls_server_name_get (gnutls_session_t SESSION, void
12146 * DATA, size_t * DATA_LENGTH, unsigned int * TYPE, unsigned
12148 SESSION: is a 'gnutls_session_t' structure.
12150 DATA: will hold the data
12152 DATA_LENGTH: will hold the data length. Must hold the maximum size
12155 TYPE: will hold the server name indicator type
12157 INDX: is the index of the server_name
12159 This function will allow you to get the name indication (if any), a
12160 client has sent. The name indication may be any of the enumeration
12161 gnutls_server_name_type_t.
12163 If 'type' is GNUTLS_NAME_DNS, then this function is to be used by
12164 servers that support virtual hosting, and the data will be a null
12165 terminated UTF-8 string.
12167 If 'data' has not enough size to hold the server name
12168 GNUTLS_E_SHORT_MEMORY_BUFFER is returned, and 'data_length' will
12169 hold the required size.
12171 'index' is used to retrieve more than one server names (if sent by
12172 the client). The first server name has an index of 0, the second 1
12173 and so on. If no name with the given index exists
12174 GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned.
12176 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
12177 otherwise an error code is returned.
12179 gnutls_server_name_set
12180 ----------------------
12182 -- Function: int gnutls_server_name_set (gnutls_session_t SESSION,
12183 gnutls_server_name_type_t TYPE, const void * NAME, size_t
12185 SESSION: is a 'gnutls_session_t' structure.
12187 TYPE: specifies the indicator type
12189 NAME: is a string that contains the server name.
12191 NAME_LENGTH: holds the length of name
12193 This function is to be used by clients that want to inform (via a
12194 TLS extension mechanism) the server of the name they connected to.
12195 This should be used by clients that connect to servers that do
12198 The value of 'name' depends on the 'type' type. In case of
12199 'GNUTLS_NAME_DNS', an ASCII zero-terminated domain name string,
12200 without the trailing dot, is expected. IPv4 or IPv6 addresses are
12203 *Returns:* On success, 'GNUTLS_E_SUCCESS' (zero) is returned,
12204 otherwise an error code is returned.
12206 gnutls_session_channel_binding
12207 ------------------------------
12209 -- Function: int gnutls_session_channel_binding (gnutls_session_t
12210 SESSION, gnutls_channel_binding_t CBTYPE, gnutls_datum_t * CB)
12211 SESSION: is a 'gnutls_session_t' structure.
12213 CBTYPE: an 'gnutls_channel_binding_t' enumeration type
12215 CB: output buffer array with data
12217 Extract given channel binding data of the 'cbtype' (e.g.,
12218 'GNUTLS_CB_TLS_UNIQUE') type.
12220 *Returns:* 'GNUTLS_E_SUCCESS' on success,
12221 'GNUTLS_E_UNIMPLEMENTED_FEATURE' if the 'cbtype' is unsupported,
12222 'GNUTLS_E_CHANNEL_BINDING_NOT_AVAILABLE' if the data is not
12223 currently available, or an error code.
12227 gnutls_session_enable_compatibility_mode
12228 ----------------------------------------
12230 -- Function: void gnutls_session_enable_compatibility_mode
12231 (gnutls_session_t SESSION)
12232 SESSION: is a 'gnutls_session_t' structure.
12234 This function can be used to disable certain (security) features in
12235 TLS in order to maintain maximum compatibility with buggy clients.
12236 It is equivalent to calling: 'gnutls_record_disable_padding()'
12238 Normally only servers that require maximum compatibility with
12239 everything out there, need to call this function.
12241 gnutls_session_get_data2
12242 ------------------------
12244 -- Function: int gnutls_session_get_data2 (gnutls_session_t SESSION,
12245 gnutls_datum_t * DATA)
12246 SESSION: is a 'gnutls_session_t' structure.
12248 DATA: is a pointer to a datum that will hold the session.
12250 Returns all session parameters, in order to support resuming. The
12251 client should call this, and keep the returned session, if he wants
12252 to resume that current version later by calling
12253 'gnutls_session_set_data()'. This function must be called after a
12254 successful handshake. The returned datum must be freed with
12257 Resuming sessions is really useful and speedups connections after a
12260 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
12261 otherwise an error code is returned.
12263 gnutls_session_get_data
12264 -----------------------
12266 -- Function: int gnutls_session_get_data (gnutls_session_t SESSION,
12267 void * SESSION_DATA, size_t * SESSION_DATA_SIZE)
12268 SESSION: is a 'gnutls_session_t' structure.
12270 SESSION_DATA: is a pointer to space to hold the session.
12272 SESSION_DATA_SIZE: is the session_data's size, or it will be set by
12275 Returns all session parameters, in order to support resuming. The
12276 client should call this, and keep the returned session, if he wants
12277 to resume that current version later by calling
12278 'gnutls_session_set_data()' This function must be called after a
12279 successful handshake.
12281 Resuming sessions is really useful and speedups connections after a
12284 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
12285 otherwise an error code is returned.
12287 gnutls_session_get_id
12288 ---------------------
12290 -- Function: int gnutls_session_get_id (gnutls_session_t SESSION, void
12291 * SESSION_ID, size_t * SESSION_ID_SIZE)
12292 SESSION: is a 'gnutls_session_t' structure.
12294 SESSION_ID: is a pointer to space to hold the session id.
12296 SESSION_ID_SIZE: is the session id's size, or it will be set by the
12299 Returns the current session id. This can be used if you want to
12300 check if the next session you tried to resume was actually resumed.
12301 This is because resumed sessions have the same sessionID with the
12304 Session id is some data set by the server, that identify the
12305 current session. In TLS 1.0 and SSL 3.0 session id is always less
12308 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
12309 otherwise an error code is returned.
12311 gnutls_session_get_ptr
12312 ----------------------
12314 -- Function: void * gnutls_session_get_ptr (gnutls_session_t SESSION)
12315 SESSION: is a 'gnutls_session_t' structure.
12317 Get user pointer for session. Useful in callbacks. This is the
12318 pointer set with 'gnutls_session_set_ptr()'.
12320 *Returns:* the user given pointer from the session structure, or
12321 'NULL' if it was never set.
12323 gnutls_session_is_resumed
12324 -------------------------
12326 -- Function: int gnutls_session_is_resumed (gnutls_session_t SESSION)
12327 SESSION: is a 'gnutls_session_t' structure.
12329 Check whether session is resumed or not.
12331 *Returns:* non zero if this session is resumed, or a zero if this
12334 gnutls_session_set_data
12335 -----------------------
12337 -- Function: int gnutls_session_set_data (gnutls_session_t SESSION,
12338 const void * SESSION_DATA, size_t SESSION_DATA_SIZE)
12339 SESSION: is a 'gnutls_session_t' structure.
12341 SESSION_DATA: is a pointer to space to hold the session.
12343 SESSION_DATA_SIZE: is the session's size
12345 Sets all session parameters, in order to resume a previously
12346 established session. The session data given must be the one
12347 returned by 'gnutls_session_get_data()'. This function should be
12348 called before 'gnutls_handshake()'.
12350 Keep in mind that session resuming is advisory. The server may
12351 choose not to resume the session, thus a full handshake will be
12354 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
12355 otherwise an error code is returned.
12357 gnutls_session_set_ptr
12358 ----------------------
12360 -- Function: void gnutls_session_set_ptr (gnutls_session_t SESSION,
12362 SESSION: is a 'gnutls_session_t' structure.
12364 PTR: is the user pointer
12366 This function will set (associate) the user given pointer 'ptr' to
12367 the session structure. This is pointer can be accessed with
12368 'gnutls_session_get_ptr()'.
12370 gnutls_session_ticket_enable_client
12371 -----------------------------------
12373 -- Function: int gnutls_session_ticket_enable_client (gnutls_session_t
12375 SESSION: is a 'gnutls_session_t' structure.
12377 Request that the client should attempt session resumption using
12380 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12385 gnutls_session_ticket_enable_server
12386 -----------------------------------
12388 -- Function: int gnutls_session_ticket_enable_server (gnutls_session_t
12389 SESSION, const gnutls_datum_t * KEY)
12390 SESSION: is a 'gnutls_session_t' structure.
12392 KEY: key to encrypt session parameters.
12394 Request that the server should attempt session resumption using
12395 SessionTicket. 'key' must be initialized with
12396 'gnutls_session_ticket_key_generate()'.
12398 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12403 gnutls_session_ticket_key_generate
12404 ----------------------------------
12406 -- Function: int gnutls_session_ticket_key_generate (gnutls_datum_t *
12408 KEY: is a pointer to a 'gnutls_datum_t' which will contain a newly
12411 Generate a random key to encrypt security parameters within
12414 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12419 gnutls_set_default_export_priority
12420 ----------------------------------
12422 -- Function: int gnutls_set_default_export_priority (gnutls_session_t
12424 SESSION: is a 'gnutls_session_t' structure.
12426 Sets some default priority on the ciphers, key exchange methods,
12427 macs and compression methods. This function also includes weak
12430 *This is the same as calling:* gnutls_priority_set_direct (session,
12433 This function is kept around for backwards compatibility, but
12434 because of its wide use it is still fully supported. If you wish
12435 to allow users to provide a string that specify which ciphers to
12436 use (which is recommended), you should use
12437 'gnutls_priority_set_direct()' or 'gnutls_priority_set()' instead.
12439 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
12441 gnutls_set_default_priority
12442 ---------------------------
12444 -- Function: int gnutls_set_default_priority (gnutls_session_t SESSION)
12445 SESSION: is a 'gnutls_session_t' structure.
12447 Sets some default priority on the ciphers, key exchange methods,
12448 macs and compression methods.
12450 *This is the same as calling:* gnutls_priority_set_direct (session,
12453 This function is kept around for backwards compatibility, but
12454 because of its wide use it is still fully supported. If you wish
12455 to allow users to provide a string that specify which ciphers to
12456 use (which is recommended), you should use
12457 'gnutls_priority_set_direct()' or 'gnutls_priority_set()' instead.
12459 *Returns:* 'GNUTLS_E_SUCCESS' on success, or an error code.
12461 gnutls_sign_algorithm_get_name
12462 ------------------------------
12464 -- Function: const char * gnutls_sign_algorithm_get_name
12465 (gnutls_sign_algorithm_t SIGN)
12466 SIGN: is a sign algorithm
12468 Convert a 'gnutls_sign_algorithm_t' value to a string.
12470 *Returns:* a string that contains the name of the specified sign
12471 algorithm, or 'NULL'.
12473 gnutls_sign_algorithm_get_requested
12474 -----------------------------------
12476 -- Function: int gnutls_sign_algorithm_get_requested (gnutls_session_t
12477 SESSION, size_t INDX, gnutls_sign_algorithm_t * ALGO)
12478 SESSION: is a 'gnutls_session_t' structure.
12480 INDX: is an index of the signature algorithm to return
12482 ALGO: the returned certificate type will be stored there
12484 Returns the signature algorithm specified by index that was
12485 requested by the peer. If the specified index has no data
12486 available this function returns
12487 'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE'. If the negotiated TLS
12488 version does not support signature algorithms then
12489 'GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE' will be returned even for
12490 the first index. The first index is 0.
12492 This function is useful in the certificate callback functions to
12493 assist in selecting the correct certificate.
12495 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned,
12496 otherwise an error code is returned.
12500 gnutls_sign_callback_get
12501 ------------------------
12503 -- Function: gnutls_sign_func gnutls_sign_callback_get
12504 (gnutls_session_t SESSION, void ** USERDATA)
12505 SESSION: is a gnutls session
12507 USERDATA: if non-'NULL', will be set to abstract callback pointer.
12509 Retrieve the callback function, and its userdata pointer.
12511 *Returns:* The function pointer set by
12512 'gnutls_sign_callback_set()', or if not set, 'NULL'.
12514 *Deprecated:* Use the PKCS 11 interfaces instead.
12516 gnutls_sign_callback_set
12517 ------------------------
12519 -- Function: void gnutls_sign_callback_set (gnutls_session_t SESSION,
12520 gnutls_sign_func SIGN_FUNC, void * USERDATA)
12521 SESSION: is a gnutls session
12523 SIGN_FUNC: function pointer to application's sign callback.
12525 USERDATA: void pointer that will be passed to sign callback.
12527 Set the callback function. The function must have this prototype:
12529 typedef int (*gnutls_sign_func) (gnutls_session_t session, void
12530 *userdata, gnutls_certificate_type_t cert_type, const
12531 gnutls_datum_t * cert, const gnutls_datum_t * hash, gnutls_datum_t
12534 The 'userdata' parameter is passed to the 'sign_func' verbatim, and
12535 can be used to store application-specific data needed in the
12536 callback function. See also 'gnutls_sign_callback_get()'.
12538 *Deprecated:* Use the PKCS 11 interfaces instead.
12543 -- Function: gnutls_sign_algorithm_t gnutls_sign_get_id (const char *
12545 NAME: is a MAC algorithm name
12547 The names are compared in a case insensitive way.
12549 *Returns:* return a 'gnutls_sign_algorithm_t' value corresponding
12550 to the specified cipher, or 'GNUTLS_SIGN_UNKNOWN' on error.
12552 gnutls_sign_get_name
12553 --------------------
12555 -- Function: const char * gnutls_sign_get_name (gnutls_sign_algorithm_t
12557 ALGORITHM: is a public key signature algorithm
12559 Convert a 'gnutls_sign_algorithm_t' value to a string.
12561 *Returns:* a pointer to a string that contains the name of the
12562 specified public key signature algorithm, or 'NULL'.
12569 -- Function: const gnutls_sign_algorithm_t * gnutls_sign_list ( VOID)
12571 Get a list of supported public key signature algorithms.
12573 *Returns:* a zero-terminated list of 'gnutls_sign_algorithm_t'
12574 integers indicating the available ciphers.
12576 gnutls_srp_allocate_client_credentials
12577 --------------------------------------
12579 -- Function: int gnutls_srp_allocate_client_credentials
12580 (gnutls_srp_client_credentials_t * SC)
12581 SC: is a pointer to a 'gnutls_srp_server_credentials_t' structure.
12583 This structure is complex enough to manipulate directly thus this
12584 helper function is provided in order to allocate it.
12586 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12589 gnutls_srp_allocate_server_credentials
12590 --------------------------------------
12592 -- Function: int gnutls_srp_allocate_server_credentials
12593 (gnutls_srp_server_credentials_t * SC)
12594 SC: is a pointer to a 'gnutls_srp_server_credentials_t' structure.
12596 This structure is complex enough to manipulate directly thus this
12597 helper function is provided in order to allocate it.
12599 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12602 gnutls_srp_base64_decode_alloc
12603 ------------------------------
12605 -- Function: int gnutls_srp_base64_decode_alloc (const gnutls_datum_t *
12606 B64_DATA, gnutls_datum_t * RESULT)
12607 B64_DATA: contains the encoded data
12609 RESULT: the place where decoded data lie
12611 This function will decode the given encoded data. The decoded data
12612 will be allocated, and stored into result. It will decode using
12613 the base64 algorithm as used in libsrp.
12615 You should use 'gnutls_free()' to free the returned data.
12617 Warning! This base64 encoding is not the "standard" encoding, so
12618 do not use it for non-SRP purposes.
12620 *Returns:* 0 on success, or an error code.
12622 gnutls_srp_base64_decode
12623 ------------------------
12625 -- Function: int gnutls_srp_base64_decode (const gnutls_datum_t *
12626 B64_DATA, char * RESULT, size_t * RESULT_SIZE)
12627 B64_DATA: contain the encoded data
12629 RESULT: the place where decoded data will be copied
12631 RESULT_SIZE: holds the size of the result
12633 This function will decode the given encoded data, using the base64
12634 encoding found in libsrp.
12636 Note that 'b64_data' should be null terminated.
12638 Warning! This base64 encoding is not the "standard" encoding, so
12639 do not use it for non-SRP purposes.
12641 *Returns:* 'GNUTLS_E_SHORT_MEMORY_BUFFER' if the buffer given is
12642 not long enough, or 0 on success.
12644 gnutls_srp_base64_encode_alloc
12645 ------------------------------
12647 -- Function: int gnutls_srp_base64_encode_alloc (const gnutls_datum_t *
12648 DATA, gnutls_datum_t * RESULT)
12649 DATA: contains the raw data
12651 RESULT: will hold the newly allocated encoded data
12653 This function will convert the given data to printable data, using
12654 the base64 encoding. This is the encoding used in SRP password
12655 files. This function will allocate the required memory to hold the
12658 You should use 'gnutls_free()' to free the returned data.
12660 Warning! This base64 encoding is not the "standard" encoding, so
12661 do not use it for non-SRP purposes.
12663 *Returns:* 0 on success, or an error code.
12665 gnutls_srp_base64_encode
12666 ------------------------
12668 -- Function: int gnutls_srp_base64_encode (const gnutls_datum_t * DATA,
12669 char * RESULT, size_t * RESULT_SIZE)
12670 DATA: contain the raw data
12672 RESULT: the place where base64 data will be copied
12674 RESULT_SIZE: holds the size of the result
12676 This function will convert the given data to printable data, using
12677 the base64 encoding, as used in the libsrp. This is the encoding
12678 used in SRP password files. If the provided buffer is not long
12679 enough GNUTLS_E_SHORT_MEMORY_BUFFER is returned.
12681 Warning! This base64 encoding is not the "standard" encoding, so
12682 do not use it for non-SRP purposes.
12684 *Returns:* 'GNUTLS_E_SHORT_MEMORY_BUFFER' if the buffer given is
12685 not long enough, or 0 on success.
12687 gnutls_srp_free_client_credentials
12688 ----------------------------------
12690 -- Function: void gnutls_srp_free_client_credentials
12691 (gnutls_srp_client_credentials_t SC)
12692 SC: is a 'gnutls_srp_client_credentials_t' structure.
12694 This structure is complex enough to manipulate directly thus this
12695 helper function is provided in order to free (deallocate) it.
12697 gnutls_srp_free_server_credentials
12698 ----------------------------------
12700 -- Function: void gnutls_srp_free_server_credentials
12701 (gnutls_srp_server_credentials_t SC)
12702 SC: is a 'gnutls_srp_server_credentials_t' structure.
12704 This structure is complex enough to manipulate directly thus this
12705 helper function is provided in order to free (deallocate) it.
12707 gnutls_srp_server_get_username
12708 ------------------------------
12710 -- Function: const char * gnutls_srp_server_get_username
12711 (gnutls_session_t SESSION)
12712 SESSION: is a gnutls session
12714 This function will return the username of the peer. This should
12715 only be called in case of SRP authentication and in case of a
12716 server. Returns NULL in case of an error.
12718 *Returns:* SRP username of the peer, or NULL in case of error.
12720 gnutls_srp_set_client_credentials_function
12721 ------------------------------------------
12723 -- Function: void gnutls_srp_set_client_credentials_function
12724 (gnutls_srp_client_credentials_t CRED,
12725 gnutls_srp_client_credentials_function * FUNC)
12726 CRED: is a 'gnutls_srp_server_credentials_t' structure.
12728 FUNC: is the callback function
12730 This function can be used to set a callback to retrieve the
12731 username and password for client SRP authentication. The
12732 callback's function form is:
12734 int (*callback)(gnutls_session_t, char** username, char**password);
12736 The 'username' and 'password' must be allocated using
12737 'gnutls_malloc()'. 'username' and 'password' should be ASCII
12738 strings or UTF-8 strings prepared using the "SASLprep" profile of
12741 The callback function will be called once per handshake before the
12742 initial hello message is sent.
12744 The callback should not return a negative error code the second
12745 time called, since the handshake procedure will be aborted.
12747 The callback function should return 0 on success. -1 indicates an
12750 gnutls_srp_set_client_credentials
12751 ---------------------------------
12753 -- Function: int gnutls_srp_set_client_credentials
12754 (gnutls_srp_client_credentials_t RES, const char * USERNAME,
12755 const char * PASSWORD)
12756 RES: is a 'gnutls_srp_client_credentials_t' structure.
12758 USERNAME: is the user's userid
12760 PASSWORD: is the user's password
12762 This function sets the username and password, in a
12763 'gnutls_srp_client_credentials_t' structure. Those will be used in
12764 SRP authentication. 'username' and 'password' should be ASCII
12765 strings or UTF-8 strings prepared using the "SASLprep" profile of
12768 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12771 gnutls_srp_set_prime_bits
12772 -------------------------
12774 -- Function: void gnutls_srp_set_prime_bits (gnutls_session_t SESSION,
12776 SESSION: is a 'gnutls_session_t' structure.
12778 BITS: is the number of bits
12780 This function sets the minimum accepted number of bits, for use in
12781 an SRP key exchange. If zero, the default 2048 bits will be used.
12783 In the client side it sets the minimum accepted number of bits. If
12784 a server sends a prime with less bits than that
12785 'GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER' will be returned by the
12788 This function has no effect in server side.
12792 gnutls_srp_set_server_credentials_file
12793 --------------------------------------
12795 -- Function: int gnutls_srp_set_server_credentials_file
12796 (gnutls_srp_server_credentials_t RES, const char *
12797 PASSWORD_FILE, const char * PASSWORD_CONF_FILE)
12798 RES: is a 'gnutls_srp_server_credentials_t' structure.
12800 PASSWORD_FILE: is the SRP password file (tpasswd)
12802 PASSWORD_CONF_FILE: is the SRP password conf file (tpasswd.conf)
12804 This function sets the password files, in a
12805 'gnutls_srp_server_credentials_t' structure. Those password files
12806 hold usernames and verifiers and will be used for SRP
12809 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12812 gnutls_srp_set_server_credentials_function
12813 ------------------------------------------
12815 -- Function: void gnutls_srp_set_server_credentials_function
12816 (gnutls_srp_server_credentials_t CRED,
12817 gnutls_srp_server_credentials_function * FUNC)
12818 CRED: is a 'gnutls_srp_server_credentials_t' structure.
12820 FUNC: is the callback function
12822 This function can be used to set a callback to retrieve the user's
12823 SRP credentials. The callback's function form is:
12825 int (*callback)(gnutls_session_t, const char* username,
12826 gnutls_datum_t* salt, gnutls_datum_t *verifier, gnutls_datum_t* g,
12827 gnutls_datum_t* n);
12829 'username' contains the actual username. The 'salt', 'verifier',
12830 'generator' and 'prime' must be filled in using the
12831 'gnutls_malloc()'. For convenience 'prime' and 'generator' may
12832 also be one of the static parameters defined in extra.h.
12834 In case the callback returned a negative number then gnutls will
12835 assume that the username does not exist.
12837 In order to prevent attackers from guessing valid usernames, if a
12838 user does not exist, g and n values should be filled in using a
12839 random user's parameters. In that case the callback must return
12840 the special value (1).
12842 The callback function will only be called once per handshake. The
12843 callback function should return 0 on success, while -1 indicates an
12846 gnutls_srp_verifier
12847 -------------------
12849 -- Function: int gnutls_srp_verifier (const char * USERNAME, const char
12850 * PASSWORD, const gnutls_datum_t * SALT, const gnutls_datum_t
12851 * GENERATOR, const gnutls_datum_t * PRIME, gnutls_datum_t *
12853 USERNAME: is the user's name
12855 PASSWORD: is the user's password
12857 SALT: should be some randomly generated bytes
12859 GENERATOR: is the generator of the group
12861 PRIME: is the group's prime
12863 RES: where the verifier will be stored.
12865 This function will create an SRP verifier, as specified in RFC2945.
12866 The 'prime' and 'generator' should be one of the static parameters
12867 defined in gnutls/extra.h or may be generated using the libgcrypt
12868 functions 'gcry_prime_generate()' and
12869 'gcry_prime_group_generator()'.
12871 The verifier will be allocated with 'malloc' and will be stored in
12872 'res' using binary format.
12874 *Returns:* On success, 'GNUTLS_E_SUCCESS' (0) is returned, or an
12877 gnutls_strerror_name
12878 --------------------
12880 -- Function: const char * gnutls_strerror_name (int ERROR)
12881 ERROR: is an error returned by a gnutls function.
12883 Return the GnuTLS error code define as a string. For example,
12884 gnutls_strerror_name (GNUTLS_E_DH_PRIME_UNACCEPTABLE) will return
12885 the string "GNUTLS_E_DH_PRIME_UNACCEPTABLE".
12887 *Returns:* A string corresponding to the symbol name of the error
12895 -- Function: const char * gnutls_strerror (int ERROR)
12896 ERROR: is a GnuTLS error code, a negative value
12898 This function is similar to strerror. The difference is that it
12899 accepts an error number returned by a gnutls function; In case of
12900 an unknown error a descriptive string is sent instead of 'NULL'.
12902 Error codes are always a negative value.
12904 *Returns:* A string explaining the GnuTLS error message.
12906 gnutls_supplemental_get_name
12907 ----------------------------
12909 -- Function: const char * gnutls_supplemental_get_name
12910 (gnutls_supplemental_data_format_type_t TYPE)
12911 TYPE: is a supplemental data format type
12913 Convert a 'gnutls_supplemental_data_format_type_t' value to a
12916 *Returns:* a string that contains the name of the specified
12917 supplemental data format type, or 'NULL' for unknown types.
12919 gnutls_transport_get_ptr2
12920 -------------------------
12922 -- Function: void gnutls_transport_get_ptr2 (gnutls_session_t SESSION,
12923 gnutls_transport_ptr_t * RECV_PTR, gnutls_transport_ptr_t *
12925 SESSION: is a 'gnutls_session_t' structure.
12927 RECV_PTR: will hold the value for the pull function
12929 SEND_PTR: will hold the value for the push function
12931 Used to get the arguments of the transport functions (like PUSH and
12932 PULL). These should have been set using
12933 'gnutls_transport_set_ptr2()'.
12935 gnutls_transport_get_ptr
12936 ------------------------
12938 -- Function: gnutls_transport_ptr_t gnutls_transport_get_ptr
12939 (gnutls_session_t SESSION)
12940 SESSION: is a 'gnutls_session_t' structure.
12942 Used to get the first argument of the transport function (like PUSH
12943 and PULL). This must have been set using
12944 'gnutls_transport_set_ptr()'.
12946 *Returns:* first argument of the transport function.
12948 gnutls_transport_set_errno_function
12949 -----------------------------------
12951 -- Function: void gnutls_transport_set_errno_function (gnutls_session_t
12952 SESSION, gnutls_errno_func ERRNO_FUNC)
12953 SESSION: is a 'gnutls_session_t' structure.
12955 ERRNO_FUNC: a callback function similar to 'write()'
12957 This is the function where you set a function to retrieve errno
12958 after a failed push or pull operation.
12960 errno_func is of the form, int
12961 (*gnutls_errno_func)(gnutls_transport_ptr_t); and should return the
12964 gnutls_transport_set_errno
12965 --------------------------
12967 -- Function: void gnutls_transport_set_errno (gnutls_session_t SESSION,
12969 SESSION: is a 'gnutls_session_t' structure.
12971 ERR: error value to store in session-specific errno variable.
12973 Store 'err' in the session-specific errno variable. Useful values
12974 for 'err' is EAGAIN and EINTR, other values are treated will be
12975 treated as real errors in the push/pull function.
12977 This function is useful in replacement push/pull functions set by
12978 gnutls_transport_set_push_function and
12979 gnutls_transport_set_pullpush_function under Windows, where the
12980 replacement push/pull may not have access to the same 'errno'
12981 variable that is used by GnuTLS (e.g., the application is linked to
12982 msvcr71.dll and gnutls is linked to msvcrt.dll).
12984 If you don't have the 'session' variable easily accessible from the
12985 push/pull function, and don't worry about thread conflicts, you can
12986 also use 'gnutls_transport_set_global_errno()'.
12988 gnutls_transport_set_global_errno
12989 ---------------------------------
12991 -- Function: void gnutls_transport_set_global_errno (int ERR)
12992 ERR: error value to store in global errno variable.
12994 Store 'err' in the global errno variable. Useful values for 'err'
12995 is EAGAIN and EINTR, other values are treated will be treated as
12996 real errors in the push/pull function.
12998 This function is useful in replacement push/pull functions set by
12999 gnutls_transport_set_push_function and
13000 gnutls_transport_set_pullpush_function under Windows, where the
13001 replacement push/pull may not have access to the same 'errno'
13002 variable that is used by GnuTLS (e.g., the application is linked to
13003 msvcr71.dll and gnutls is linked to msvcrt.dll).
13005 Whether this function is thread safe or not depends on whether the
13006 global variable errno is thread safe, some system libraries make it
13007 a thread-local variable. When feasible, using the guaranteed
13008 thread-safe 'gnutls_transport_set_errno()' may be better.
13010 gnutls_transport_set_lowat
13011 --------------------------
13013 -- Function: void gnutls_transport_set_lowat (gnutls_session_t SESSION,
13015 SESSION: is a 'gnutls_session_t' structure.
13017 NUM: is the low water value.
13019 Used to set the lowat value in order for select to check if there
13020 are pending data to socket buffer. Used only if you have changed
13021 the default low water value (default is 1). Normally you will not
13022 need that function. This function is only useful if using berkeley
13023 style sockets. Otherwise it must be called and set lowat to zero.
13025 gnutls_transport_set_ptr2
13026 -------------------------
13028 -- Function: void gnutls_transport_set_ptr2 (gnutls_session_t SESSION,
13029 gnutls_transport_ptr_t RECV_PTR, gnutls_transport_ptr_t
13031 SESSION: is a 'gnutls_session_t' structure.
13033 RECV_PTR: is the value for the pull function
13035 SEND_PTR: is the value for the push function
13037 Used to set the first argument of the transport function (like PUSH
13038 and PULL). In berkeley style sockets this function will set the
13039 connection handle. With this function you can use two different
13040 pointers for receiving and sending.
13042 gnutls_transport_set_ptr
13043 ------------------------
13045 -- Function: void gnutls_transport_set_ptr (gnutls_session_t SESSION,
13046 gnutls_transport_ptr_t PTR)
13047 SESSION: is a 'gnutls_session_t' structure.
13051 Used to set the first argument of the transport function (like PUSH
13052 and PULL). In berkeley style sockets this function will set the
13055 gnutls_transport_set_pull_function
13056 ----------------------------------
13058 -- Function: void gnutls_transport_set_pull_function (gnutls_session_t
13059 SESSION, gnutls_pull_func PULL_FUNC)
13060 SESSION: is a 'gnutls_session_t' structure.
13062 PULL_FUNC: a callback function similar to 'read()'
13064 This is the function where you set a function for gnutls to receive
13065 data. Normally, if you use berkeley style sockets, do not need to
13066 use this function since the default (recv(2)) will probably be ok.
13068 PULL_FUNC is of the form, ssize_t
13069 (*gnutls_pull_func)(gnutls_transport_ptr_t, void*, size_t);
13071 gnutls_transport_set_push_function
13072 ----------------------------------
13074 -- Function: void gnutls_transport_set_push_function (gnutls_session_t
13075 SESSION, gnutls_push_func PUSH_FUNC)
13076 SESSION: is a 'gnutls_session_t' structure.
13078 PUSH_FUNC: a callback function similar to 'write()'
13080 This is the function where you set a push function for gnutls to
13081 use in order to send data. If you are going to use berkeley style
13082 sockets, you do not need to use this function since the default
13083 (send(2)) will probably be ok. Otherwise you should specify this
13084 function for gnutls to be able to send data.
13086 PUSH_FUNC is of the form, ssize_t
13087 (*gnutls_push_func)(gnutls_transport_ptr_t, const void*, size_t);
13089 gnutls_transport_set_vec_push_function
13090 --------------------------------------
13092 -- Function: void gnutls_transport_set_vec_push_function
13093 (gnutls_session_t SESSION, gnutls_vec_push_func VEC_FUNC)
13094 SESSION: is a 'gnutls_session_t' structure.
13096 VEC_FUNC: a callback function similar to 'writev()'
13098 This is the function where you set a push function for gnutls to
13099 use in order to send data. If you are going to use berkeley style
13100 sockets, you do not need to use this function since the default
13101 (send(2)) will probably be ok. Otherwise you should specify this
13102 function for gnutls to be able to send data.
13104 PUSH_FUNC is of the form, ssize_t
13105 (*gnutls_push_func)(gnutls_transport_ptr_t, const void*, size_t);
13107 gnutls_x509_crq_set_pubkey
13108 --------------------------
13110 -- Function: int gnutls_x509_crq_set_pubkey (gnutls_x509_crq_t CRQ,
13111 gnutls_pubkey_t KEY)
13112 CRQ: should contain a 'gnutls_x509_crq_t' structure
13114 KEY: holds a public key
13116 This function will set the public parameters from the given public
13117 key to the request.
13119 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
13120 negative error value.
13122 gnutls_x509_crt_import_pkcs11_url
13123 ---------------------------------
13125 -- Function: int gnutls_x509_crt_import_pkcs11_url (gnutls_x509_crt_t
13126 CRT, const char * URL, unsigned int FLAGS)
13127 CRT: A certificate of type 'gnutls_x509_crt_t'
13131 FLAGS: One of GNUTLS_PKCS11_OBJ_* flags
13133 This function will import a PKCS 11 certificate directly from a
13134 token without involving the 'gnutls_pkcs11_obj_t' structure. This
13135 function will fail if the certificate stored is not of X.509 type.
13137 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
13138 negative error value.
13140 gnutls_x509_crt_import_pkcs11
13141 -----------------------------
13143 -- Function: int gnutls_x509_crt_import_pkcs11 (gnutls_x509_crt_t CRT,
13144 gnutls_pkcs11_obj_t PKCS11_CRT)
13145 CRT: A certificate of type 'gnutls_x509_crt_t'
13147 PKCS11_CRT: A PKCS 11 object that contains a certificate
13149 This function will import a PKCS 11 certificate to a
13150 'gnutls_x509_crt_t' structure.
13152 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
13153 negative error value.
13155 gnutls_x509_crt_list_import_pkcs11
13156 ----------------------------------
13158 -- Function: int gnutls_x509_crt_list_import_pkcs11 (gnutls_x509_crt_t
13159 * CERTS, unsigned int CERT_MAX, gnutls_pkcs11_obj_t * const
13160 OBJS, unsigned int FLAGS)
13161 CERTS: A list of certificates of type 'gnutls_x509_crt_t'
13163 CERT_MAX: The maximum size of the list
13165 OBJS: A list of PKCS 11 objects
13169 This function will import a PKCS 11 certificate list to a list of
13170 'gnutls_x509_crt_t' structure. These must not be initialized.
13172 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
13173 negative error value.
13175 gnutls_x509_crt_set_pubkey
13176 --------------------------
13178 -- Function: int gnutls_x509_crt_set_pubkey (gnutls_x509_crt_t CRT,
13179 gnutls_pubkey_t KEY)
13180 CRT: should contain a 'gnutls_x509_crt_t' structure
13182 KEY: holds a public key
13184 This function will set the public parameters from the given public
13185 key to the request.
13187 *Returns:* On success, 'GNUTLS_E_SUCCESS' is returned, otherwise a
13188 negative error value.