guile: Fix `priorities' test to use `run-test'.
[gnutls.git] / doc / cha-auth.texi
blob0b20115637a0610d0f21a21e1ada548005b1cbf7
1 @node Authentication methods
2 @chapter Authentication methods
4 The @acronym{TLS} protocol provides confidentiality and encryption,
5 but also offers authentication, which is a prerequisite for a secure
6 connection. The available authentication methods in @acronym{GnuTLS}
7 are:
9 @itemize
11 @item Certificate authentication
13 @item Anonymous authentication
15 @item @acronym{SRP} authentication
17 @item @acronym{PSK} authentication
19 @end itemize
21 The rule for each method is to allocate a credentials
22 structure containing data required for authentication and
23 associate that structure with the session using
24 @funcref{gnutls_credentials_set}. Various authentication methods might
25 require additional data to be stored in the credential structures,
26 such as ephemeral Diffie-Hellman parameters etc.
27 In the next paragraphs
28 we elaborate on supported authentication methods.
30 @showfuncdesc{gnutls_credentials_set}
32 @menu
33 * Certificate authentication::
34 * Anonymous authentication::
35 * Authentication using SRP::
36 * Authentication using PSK::
37 * Authentication and credentials::
38 @end menu
40 @node Certificate authentication
41 @section Certificate authentication
43 @subsection Authentication using @acronym{X.509} certificates
44 @cindex @acronym{X.509} certificates
46 @acronym{X.509} certificates contain the public parameters, of a
47 public key algorithm, and an authority's signature, which proves the
48 authenticity of the parameters.  See @ref{X.509 certificates}, for
49 more information on @acronym{X.509} protocols.
51 @subsection Authentication using @acronym{OpenPGP} keys
52 @cindex @acronym{OpenPGP} keys
54 @acronym{OpenPGP} keys also contain public parameters of a public key
55 algorithm, and signatures from several other parties. Depending on
56 whether a signer is trusted the key is considered trusted or not.
57 @acronym{GnuTLS}'s @acronym{OpenPGP} authentication implementation is
58 based on the @xcite{TLSPGP} proposal.
60 More information on the @acronym{OpenPGP} trusted model is provided in @ref{OpenPGP certificates}.
61 For a more detailed introduction to @acronym{OpenPGP} and @acronym{GnuPG} see @xcite{GPGH}.
63 @subsection Using certificate authentication
65 In @acronym{GnuTLS} both the @acronym{OpenPGP} and @acronym{X.509}
66 certificates are part of the certificate authentication and thus are
67 handled using a common API.
68 When using certificates the server is required to have at least one
69 certificate and private key pair. A client may or may not have such a
70 pair. 
72 @showfuncB{gnutls_certificate_allocate_credentials,gnutls_certificate_free_credentials}
74 After the credentials structures are initialized using the functions
75 above, the certificate and key pair should be loaded. This should
76 occur before any @acronym{TLS} session is initialized.
77 Depending on the certificate type different loading functions
78 are available, and are shown below.
79 In the @acronym{X.509} case, the functions will
80 also accept and use a certificate list that leads to a trusted
81 authority. The certificate list must be ordered in such way that every
82 certificate certifies the one before it. The trusted authority's
83 certificate need not to be included, since the peer should possess it
84 already.
86 @showfuncE{gnutls_certificate_set_x509_key,gnutls_certificate_set_x509_key_mem,gnutls_certificate_set_openpgp_key,gnutls_certificate_set_openpgp_key_file,gnutls_certificate_set_openpgp_key_mem}
88 @showfuncdesc{gnutls_certificate_set_x509_key_file}
90 As an alternative to loading from files, a callback may be used so that the 
91 server or the client can specify the certificate and the key at the handshake time.
92 In that case a certificate should be selected according the peer's signature
93 algorithm preferences. To get those preferences use
94 @funcref{gnutls_sign_algorithm_get_requested}. Both functions are shown below.
96 @showfuncdesc{gnutls_certificate_set_retrieve_function}
98 @showfuncdesc{gnutls_sign_algorithm_get_requested}
101 Certificate verification is possible by loading the trusted
102 authorities into the credentials structure by using
103 the following functions, applicable to X.509 and OpenPGP certificates.
105 @showfuncB{gnutls_certificate_set_x509_trust_file,gnutls_certificate_set_openpgp_keyring_file}
107 Note however that the peer's certificate is not automatically
108 verified, you should call @funcref{gnutls_certificate_verify_peers2},
109 after a successful handshake or during if @funcref{gnutls_certificate_set_verify_function}
110 has been used, to verify the certificate's signature.
111 An alternative way, which reports a more detailed
112 verification output, is to use @funcref{gnutls_certificate_get_peers} to
113 obtain the raw certificate of the peer and verify it using the
114 functions discussed in @ref{X.509 certificates}.
116 @showfuncdesc{gnutls_certificate_verify_peers2}
118 In a handshake, the negotiated cipher suite also depends on the
119 certificate's parameters, so some key exchange methods might not be
120 available with some certificates. @acronym{GnuTLS} will disable
121 ciphersuites that are not compatible with the key, or the enabled
122 authentication methods.  For example keys marked as sign-only, will
123 not be able to access the plain RSA ciphersuites, that require
124 decryption. It is not recommended to use RSA keys for both
125 signing and encryption. If possible use a different key for the
126 @code{DHE_RSA} which uses signing and @code{RSA} that requires decryption.
127 All the key exchange methods shown in @ref{tab:key-exchange} are
128 available in certificate authentication.
130 @showfuncdesc{gnutls_certificate_set_verify_function}
132 Note that the DHE key exchange methods are generally
133 slower@footnote{It really depends on the group used.  Primes with
134 lesser bits are always faster, but also easier to break.  See @ref{Selecting cryptographic key sizes}
135 for the acceptable security levels.} 
136 and require Diffie-Hellman parameters to be generated and associated with a credentials
137 structure, by the server (see @ref{Parameter generation}).
139 @float Table,tab:key-exchange
140 @multitable @columnfractions .3 .7
142 @headitem Key exchange @tab Description
144 @item RSA @tab
145 The RSA algorithm is used to encrypt a key and send it to the peer.
146 The certificate must allow the key to be used for encryption.
148 @item RSA_EXPORT @tab
149 The RSA algorithm is used to encrypt a key and send it to the peer.
150 In the EXPORT algorithm, the server signs temporary RSA parameters of
151 512 bits --- which are considered weak --- and sends them to the
152 client.
154 @item DHE_RSA @tab
155 The RSA algorithm is used to sign ephemeral Diffie-Hellman parameters
156 which are sent to the peer. The key in the certificate must allow the
157 key to be used for signing. Note that key exchange algorithms which
158 use ephemeral Diffie-Hellman parameters, offer perfect forward
159 secrecy. That means that even if the private key used for signing is
160 compromised, it cannot be used to reveal past session data.
162 @item ECDHE_RSA @tab
163 The RSA algorithm is used to sign ephemeral elliptic curve Diffie-Hellman 
164 parameters which are sent to the peer. The key in the certificate must allow 
165 the key to be used for signing. It also offers perfect forward
166 secrecy. That means that even if the private key used for signing is
167 compromised, it cannot be used to reveal past session data.
169 @item DHE_DSS @tab
170 The DSA algorithm is used to sign ephemeral Diffie-Hellman parameters
171 which are sent to the peer. The certificate must contain DSA
172 parameters to use this key exchange algorithm. DSA is the algorithm
173 of the Digital Signature Standard (DSS).
175 @item ECDHE_ECDSA @tab
176 The Elliptic curve DSA algorithm is used to sign ephemeral elliptic
177 curve Diffie-Hellman parameters which are sent to the peer. The 
178 certificate must contain ECDSA parameters to use this key exchange 
179 algorithm. 
181 @end multitable
182 @caption{Supported key exchange algorithms.}
183 @end float
185 @node Anonymous authentication
186 @section Anonymous authentication
187 @cindex anonymous authentication
189 The anonymous key exchange offers encryption without any
190 indication of the peer's identity.  This kind of authentication
191 is vulnerable to a man in the middle attack, but can be
192 used even if there is no prior communication or shared trusted parties 
193 with the peer. Moreover it is useful when complete anonymity is required. 
194 Unless in one of the above cases, do not use anonymous authentication.  
196 Note that the key exchange methods for anonymous authentication
197 require Diffie-Hellman parameters to be generated by the server and
198 associated with an anonymous credentials structure. Check
199 @ref{Parameter generation} for more information.
201 The initialization functions for the credentials are shown below.
203 @showfuncD{gnutls_anon_allocate_server_credentials,gnutls_anon_allocate_client_credentials,gnutls_anon_free_server_credentials,gnutls_anon_free_client_credentials}
206 The available key exchange algorithms for anonymous authentication are
207 shown below.
209 @table @code
211 @item ANON_DH:
212 This algorithm exchanges Diffie-Hellman parameters.
214 @item ANON_ECDH:
215 This algorithm exchanges elliptic curve Diffie-Hellman parameters. It is more 
216 efficient than ANON_DH on equivalent security levels.
218 @end table
220 @node Authentication using SRP
221 @section Authentication using @acronym{SRP}
222 @cindex @acronym{SRP} authentication
224 Authentication via the Secure Remote Password protocol,
225 @acronym{SRP} (see @xcite{RFC2945} for a description of SRP),
226 is supported.  The @acronym{SRP} key exchange is an extension to the
227 @acronym{TLS} protocol, and it is a password based authentication
228 (unlike @acronym{X.509} or @acronym{OpenPGP} that use certificates).
229 The two peers can be identified using a single password, or there can
230 be combinations where the client is authenticated using @acronym{SRP}
231 and the server using a certificate.
233 The advantage of @acronym{SRP} authentication, over other proposed
234 secure password authentication schemes, is that @acronym{SRP} does not
235 require the server to hold the user's password.  This kind of
236 protection is similar to the one used traditionally in the @acronym{UNIX}
237 @file{/etc/passwd} file, where the contents of this file did not cause
238 harm to the system security if they were revealed.  The @acronym{SRP}
239 needs instead of the plain password something called a verifier, which
240 is calculated using the user's password, and if stolen cannot be used
241 to impersonate the user. Check @xcite{TOMSRP} for a detailed
242 description of the @acronym{SRP} protocol and the Stanford
243 @acronym{SRP} libraries, which includes a PAM module that synchronizes
244 the system's users passwords with the @acronym{SRP} password
245 files. That way @acronym{SRP} authentication could be used for all the
246 system's users.
248 The implementation in @acronym{GnuTLS} is based on @xcite{TLSSRP} and
249 the supported @acronym{SRP} key exchange methods are:
251 @table @code
253 @item SRP:
254 Authentication using the @acronym{SRP} protocol.
256 @item SRP_DSS:
257 Client authentication using the @acronym{SRP} protocol. Server is
258 authenticated using a certificate with DSA parameters.
260 @item SRP_RSA:
261 Client authentication using the @acronym{SRP} protocol. Server is
262 authenticated using a certificate with RSA parameters.
264 @end table
266 The initialization functions in SRP credentials differ between
267 client and server.
269 @showfuncD{gnutls_srp_allocate_server_credentials,gnutls_srp_allocate_client_credentials,gnutls_srp_free_server_credentials,gnutls_srp_free_client_credentials}
271 Clients supporting @acronym{SRP} should set the username and password
272 prior to connection, to the credentials structure.
273 Alternatively @funcref{gnutls_srp_set_client_credentials_function}
274 may be used instead, to specify a callback function that should return the
275 SRP username and password.
276 The callback is called once during the @acronym{TLS} handshake.
278 @showfuncA{gnutls_srp_set_client_credentials}
280 @showfuncdesc{gnutls_srp_set_client_credentials_function}
282 In server side the default behavior of @acronym{GnuTLS} is to read
283 the usernames and @acronym{SRP} verifiers from password files. These
284 password file format is compatible the with the @emph{Stanford srp libraries}
285 format.  If a different password file format is to be used, then 
286 @funcref{gnutls_srp_set_server_credentials_function} should be called,
287 to set an appropriate callback. 
289 @showfuncdesc{gnutls_srp_set_server_credentials_file}
291 @showfuncdesc{gnutls_srp_set_server_credentials_function}
293 Other helper functions are included in @acronym{GnuTLS}, used to generate and
294 maintain @acronym{SRP} verifiers and password files.  A program to
295 manipulate the required parameters for @acronym{SRP} authentication is
296 also included.  See @ref{srptool}, for more information.
298 @showfuncdesc{gnutls_srp_verifier}
300 @showfuncB{gnutls_srp_base64_encode,gnutls_srp_base64_decode}
303 @node Authentication using PSK
304 @section Authentication using @acronym{PSK}
305 @cindex @acronym{PSK} authentication
307 Authentication using Pre-shared keys is a method to authenticate using
308 usernames and binary keys. This protocol avoids making use of public
309 key infrastructure and expensive calculations, thus it is suitable for
310 constraint clients.
312 The implementation in @acronym{GnuTLS} is based on @xcite{TLSPSK}.  
313 The supported @acronym{PSK} key exchange methods are:
315 @table @code
317 @item PSK:
318 Authentication using the @acronym{PSK} protocol.
320 @item DHE-PSK:
321 Authentication using the @acronym{PSK} protocol and Diffie-Hellman key
322 exchange.  This method offers perfect forward secrecy.
324 @item ECDHE-PSK:
325 Authentication using the @acronym{PSK} protocol and Elliptic curve Diffie-Hellman key
326 exchange.  This method offers perfect forward secrecy.
328 @end table
330 The initialization functions in PSK credentials differ between
331 client and server.
333 @showfuncD{gnutls_psk_allocate_server_credentials,gnutls_psk_allocate_client_credentials,gnutls_psk_free_server_credentials,gnutls_psk_free_client_credentials}
335 Clients supporting @acronym{PSK} should supply the username and key
336 before a TLS session is established.  Alternatively 
337 @funcref{gnutls_psk_set_client_credentials_function} can be used to
338 specify a callback function. This has the
339 advantage that the callback will be called only if @acronym{PSK} has
340 been negotiated.
342 @showfuncA{gnutls_psk_set_client_credentials}
344 @showfuncdesc{gnutls_psk_set_client_credentials_function}
346 In server side the default behavior of @acronym{GnuTLS} is to read
347 the usernames and @acronym{PSK} keys from a password file. The
348 password file should contain usernames and keys in hexadecimal
349 format. The name of the password file can be stored to the credentials
350 structure by calling @funcref{gnutls_psk_set_server_credentials_file}.  If
351 a different password file format is to be used, then
352 a callback should be set instead by @funcref{gnutls_psk_set_server_credentials_function}.
354 The server can help the client chose a suitable username and password,
355 by sending a hint. Note that there is no common profile for the PSK hint and applications
356 are discouraged to use it.
357 A server, may specify the hint by calling
358 @funcref{gnutls_psk_set_server_credentials_hint}.  The client can retrieve
359 the hint, for example in the callback function, using
360 @funcref{gnutls_psk_client_get_hint}.
362 @showfuncdesc{gnutls_psk_set_server_credentials_file}
364 @showfuncC{gnutls_psk_set_server_credentials_function,gnutls_psk_set_server_credentials_hint,gnutls_psk_client_get_hint}
366 Helper functions are included in @acronym{GnuTLS}, and may be used to generate and
367 maintain @acronym{PSK} keys.
369 @showfuncdesc{gnutls_hex_encode}
371 @showfuncdesc{gnutls_hex_decode}
374 @node Authentication and credentials
375 @section Authentication and credentials
377 In @acronym{GnuTLS} every key exchange method is associated with a
378 credentials type. For a key exchange method to be available it
379 must be listed as a priority string (see @ref{Priority Strings}) and
380 the corresponding credentials type should be initialized and set using
381 @funcref{gnutls_credentials_set}.  A mapping of the key exchange methods
382 with the credential types is shown in @ref{tab:key-exchange-cred}.
384 @float Table,tab:key-exchange-cred
385 @multitable @columnfractions .4 .25 .25
387 @headitem Key exchange @tab Client credentials @tab Server credentials
389 @item @code{KX_RSA},
390 @code{KX_DHE_RSA},
391 @code{KX_DHE_DSS},
392 @code{KX_ECDHE_RSA},
393 @code{KX_ECDHE_ECDSA},
394 @code{KX_RSA_EXPORT}
395 @tab @code{CRD_CERTIFICATE}
396 @tab @code{CRD_CERTIFICATE}
398 @item @code{KX_SRP_RSA}, @code{KX_SRP_DSS}
399 @tab @code{CRD_SRP}
400 @tab @code{CRD_CERTIFICATE}
402 @item @code{KX_SRP}
403 @tab @code{CRD_SRP}
404 @tab @code{CRD_SRP}
406 @item @code{KX_ANON_DH},
407 @code{KX_ANON_ECDH}
408 @tab @code{CRD_ANON}
409 @tab @code{CRD_ANON}
411 @item @code{KX_PSK},
412 @code{KX_DHE_PSK}, @code{KX_ECDHE_PSK}
413 @tab @code{CRD_PSK}
414 @tab @code{CRD_PSK}
416 @end multitable
417 @caption{Key exchange algorithms and the corresponding credential types.}
418 @end float