guile: Rename to `libguile-gnutls-v-2'.
[gnutls.git] / doc / cha-auth.texi
blobfcbe26bce1c7a3d17ad2c31dbe618574c47572a0
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: Authenticated key exchange using public key infrastructure and certificates (X.509 or OpenPGP).
13 @item @acronym{SRP} authentication: Authenticated key exchange using a password.
15 @item @acronym{PSK} authentication: Authenticated key exchange using a pre-shared key.
17 @item Anonymous authentication: Key exchange without peer 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 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 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 @showfuncD{gnutls_certificate_set_x509_key_mem,gnutls_certificate_set_openpgp_key,gnutls_certificate_set_openpgp_key_file,gnutls_certificate_set_openpgp_key_mem}
87 @showfuncB{gnutls_certificate_set_x509_key,gnutls_certificate_set_key}
89 @showfuncdesc{gnutls_certificate_set_x509_key_file}
91 As an alternative to loading from files, a callback may be used so that the 
92 server or the client can specify the certificate and the key at the handshake time.
93 In that case a certificate should be selected according the peer's signature
94 algorithm preferences. To get those preferences use
95 @funcref{gnutls_sign_algorithm_get_requested}. Both functions are shown below.
97 @showfuncdesc{gnutls_certificate_set_retrieve_function}
99 @showfuncdesc{gnutls_sign_algorithm_get_requested}
102 Certificate verification is possible by loading the trusted
103 authorities into the credentials structure by using
104 the following functions, applicable to X.509 and OpenPGP certificates.
106 @showfuncB{gnutls_certificate_set_x509_trust_file,gnutls_certificate_set_openpgp_keyring_file}
108 Note however that the peer's certificate is not automatically
109 verified, you should call @funcref{gnutls_certificate_verify_peers2},
110 after a successful handshake or during if @funcref{gnutls_certificate_set_verify_function}
111 has been used, to verify the certificate's signature.
112 An alternative way, which reports a more detailed
113 verification output, is to use @funcref{gnutls_certificate_get_peers} to
114 obtain the raw certificate of the peer and verify it using the
115 functions discussed in @ref{X.509 certificates}.
117 @showfuncdesc{gnutls_certificate_verify_peers2}
119 In a handshake, the negotiated cipher suite also depends on the
120 certificate's parameters, so some key exchange methods might not be
121 available with some certificates. @acronym{GnuTLS} will disable
122 ciphersuites that are not compatible with the key, or the enabled
123 authentication methods.  For example keys marked as sign-only, will
124 not be able to access the plain RSA ciphersuites, that require
125 decryption. It is not recommended to use RSA keys for both
126 signing and encryption. If possible use a different key for the
127 @code{DHE_RSA} which uses signing and @code{RSA} that requires decryption.
128 All the key exchange methods shown in @ref{tab:key-exchange} are
129 available in certificate authentication.
131 @showfuncdesc{gnutls_certificate_set_verify_function}
133 Note that the DHE key exchange methods are generally
134 slower@footnote{It depends on the group used.  Primes with
135 lesser bits are always faster, but also easier to break.  See @ref{Selecting cryptographic key sizes}
136 for the acceptable security levels.} than the elliptic curves counterpart
137 (ECDHE). Moreover the plain Diffie-Hellman key exchange
138 requires parameters to be generated and associated with a credentials
139 structure by the server (see @ref{Parameter generation}). 
141 @float Table,tab:key-exchange
142 @multitable @columnfractions .2 .7
144 @headitem Key exchange @tab Description
146 @item RSA @tab
147 The RSA algorithm is used to encrypt a key and send it to the peer.
148 The certificate must allow the key to be used for encryption.
150 @item RSA_EXPORT @tab
151 The RSA algorithm is used to encrypt a key and send it to the peer.
152 In the EXPORT algorithm, the server signs temporary RSA parameters of
153 512 bits --- which are considered weak --- and sends them to the
154 client.
156 @item DHE_RSA @tab
157 The RSA algorithm is used to sign ephemeral Diffie-Hellman parameters
158 which are sent to the peer. The key in the certificate must allow the
159 key to be used for signing. Note that key exchange algorithms which
160 use ephemeral Diffie-Hellman parameters, offer perfect forward
161 secrecy. That means that even if the private key used for signing is
162 compromised, it cannot be used to reveal past session data.
164 @item ECDHE_RSA @tab
165 The RSA algorithm is used to sign ephemeral elliptic curve Diffie-Hellman 
166 parameters which are sent to the peer. The key in the certificate must allow 
167 the key to be used for signing. It also offers perfect forward
168 secrecy. That means that even if the private key used for signing is
169 compromised, it cannot be used to reveal past session data.
171 @item DHE_DSS @tab
172 The DSA algorithm is used to sign ephemeral Diffie-Hellman parameters
173 which are sent to the peer. The certificate must contain DSA
174 parameters to use this key exchange algorithm. DSA is the algorithm
175 of the Digital Signature Standard (DSS).
177 @item ECDHE_ECDSA @tab
178 The Elliptic curve DSA algorithm is used to sign ephemeral elliptic
179 curve Diffie-Hellman parameters which are sent to the peer. The 
180 certificate must contain ECDSA parameters to use this key exchange 
181 algorithm. 
183 @end multitable
184 @caption{Supported key exchange algorithms.}
185 @end float
187 @node Anonymous authentication
188 @section Anonymous authentication
189 @cindex anonymous authentication
191 The anonymous key exchange offers encryption without any
192 indication of the peer's identity.  This kind of authentication
193 is vulnerable to a man in the middle attack, but can be
194 used even if there is no prior communication or shared trusted parties 
195 with the peer. Moreover it is useful when complete anonymity is required. 
196 Unless in one of the above cases, do not use anonymous authentication.  
198 Note that the key exchange methods for anonymous authentication
199 require Diffie-Hellman parameters to be generated by the server and
200 associated with an anonymous credentials structure. Check
201 @ref{Parameter generation} for more information.
203 The initialization functions for the credentials are shown below.
205 @showfuncD{gnutls_anon_allocate_server_credentials,gnutls_anon_allocate_client_credentials,gnutls_anon_free_server_credentials,gnutls_anon_free_client_credentials}
208 The available key exchange algorithms for anonymous authentication are
209 shown below.
211 @table @code
213 @item ANON_DH:
214 This algorithm exchanges Diffie-Hellman parameters.
216 @item ANON_ECDH:
217 This algorithm exchanges elliptic curve Diffie-Hellman parameters. It is more 
218 efficient than ANON_DH on equivalent security levels.
220 @end table
222 @node Authentication using SRP
223 @section Authentication using @acronym{SRP}
224 @cindex SRP authentication
226 @acronym{GnuTLS} supported authentication via the Secure Remote Password 
227 or @acronym{SRP} protocol (see @xcite{RFC2945,TOMSRP} for a description).
228 The @acronym{SRP} key exchange is an extension to the
229 @acronym{TLS} protocol, and it provided an authenticated with a 
230 password key exchange. The peers can be identified using a single password, 
231 or there can be combinations where the client is authenticated using @acronym{SRP}
232 and the server using a certificate.
234 The advantage of @acronym{SRP} authentication, over other proposed
235 secure password authentication schemes, is that @acronym{SRP} is not
236 susceptible to off-line dictionary attacks.
237 Moreover, SRP does not require the server to hold the user's password.
238 This kind of protection is similar to the one used traditionally in the @acronym{UNIX}
239 @file{/etc/passwd} file, where the contents of this file did not cause
240 harm to the system security if they were revealed.  The @acronym{SRP}
241 needs instead of the plain password something called a verifier, which
242 is calculated using the user's password, and if stolen cannot be used
243 to impersonate the user. 
244 The Stanford @acronym{SRP} libraries, include a PAM module that synchronizes
245 the system's users passwords with the @acronym{SRP} password
246 files. That way @acronym{SRP} authentication could be used for all users
247 of a system.
249 The implementation in @acronym{GnuTLS} is based on @xcite{TLSSRP}. The
250 supported key exchange methods are shown below.
252 @table @code
254 @item SRP:
255 Authentication using the @acronym{SRP} protocol.
257 @item SRP_DSS:
258 Client authentication using the @acronym{SRP} protocol. Server is
259 authenticated using a certificate with DSA parameters.
261 @item SRP_RSA:
262 Client authentication using the @acronym{SRP} protocol. Server is
263 authenticated using a certificate with RSA parameters.
265 @end table
267 The initialization functions in SRP credentials differ between
268 client and server.
270 @showfuncD{gnutls_srp_allocate_server_credentials,gnutls_srp_allocate_client_credentials,gnutls_srp_free_server_credentials,gnutls_srp_free_client_credentials}
272 Clients supporting @acronym{SRP} should set the username and password
273 prior to connection, to the credentials structure.
274 Alternatively @funcref{gnutls_srp_set_client_credentials_function}
275 may be used instead, to specify a callback function that should return the
276 SRP username and password.
277 The callback is called once during the @acronym{TLS} handshake.
279 @showfuncA{gnutls_srp_set_client_credentials}
281 @showfuncdesc{gnutls_srp_set_client_credentials_function}
283 In server side the default behavior of @acronym{GnuTLS} is to read
284 the usernames and @acronym{SRP} verifiers from password files. These
285 password file format is compatible the with the @emph{Stanford srp libraries}
286 format.  If a different password file format is to be used, then 
287 @funcref{gnutls_srp_set_server_credentials_function} should be called,
288 to set an appropriate callback. 
290 @showfuncdesc{gnutls_srp_set_server_credentials_file}
292 @showfuncdesc{gnutls_srp_set_server_credentials_function}
294 Other helper functions are included in @acronym{GnuTLS}, used to generate and
295 maintain @acronym{SRP} verifiers and password files.  A program to
296 manipulate the required parameters for @acronym{SRP} authentication is
297 also included.  See @ref{srptool}, for more information.
299 @showfuncdesc{gnutls_srp_verifier}
301 @showfuncB{gnutls_srp_base64_encode,gnutls_srp_base64_decode}
304 @node Authentication using PSK
305 @section Authentication using @acronym{PSK}
306 @cindex PSK authentication
308 Authentication using Pre-shared keys is a method to authenticate using
309 usernames and binary keys. This protocol avoids making use of public
310 key infrastructure and expensive calculations, thus it is suitable for
311 constraint clients.
313 The implementation in @acronym{GnuTLS} is based on @xcite{TLSPSK}.  
314 The supported @acronym{PSK} key exchange methods are:
316 @table @code
318 @item PSK:
319 Authentication using the @acronym{PSK} protocol.
321 @item DHE-PSK:
322 Authentication using the @acronym{PSK} protocol and Diffie-Hellman key
323 exchange.  This method offers perfect forward secrecy.
325 @item ECDHE-PSK:
326 Authentication using the @acronym{PSK} protocol and Elliptic curve Diffie-Hellman key
327 exchange.  This method offers perfect forward secrecy.
329 @end table
331 The initialization functions in PSK credentials differ between
332 client and server.
334 @showfuncD{gnutls_psk_allocate_server_credentials,gnutls_psk_allocate_client_credentials,gnutls_psk_free_server_credentials,gnutls_psk_free_client_credentials}
336 Clients supporting @acronym{PSK} should supply the username and key
337 before a TLS session is established.  Alternatively 
338 @funcref{gnutls_psk_set_client_credentials_function} can be used to
339 specify a callback function. This has the
340 advantage that the callback will be called only if @acronym{PSK} has
341 been negotiated.
343 @showfuncA{gnutls_psk_set_client_credentials}
345 @showfuncdesc{gnutls_psk_set_client_credentials_function}
347 In server side the default behavior of @acronym{GnuTLS} is to read
348 the usernames and @acronym{PSK} keys from a password file. The
349 password file should contain usernames and keys in hexadecimal
350 format. The name of the password file can be stored to the credentials
351 structure by calling @funcref{gnutls_psk_set_server_credentials_file}.  If
352 a different password file format is to be used, then
353 a callback should be set instead by @funcref{gnutls_psk_set_server_credentials_function}.
355 The server can help the client chose a suitable username and password,
356 by sending a hint. Note that there is no common profile for the PSK hint and applications
357 are discouraged to use it.
358 A server, may specify the hint by calling
359 @funcref{gnutls_psk_set_server_credentials_hint}.  The client can retrieve
360 the hint, for example in the callback function, using
361 @funcref{gnutls_psk_client_get_hint}.
363 @showfuncdesc{gnutls_psk_set_server_credentials_file}
365 @showfuncC{gnutls_psk_set_server_credentials_function,gnutls_psk_set_server_credentials_hint,gnutls_psk_client_get_hint}
367 Helper functions to generate and maintain @acronym{PSK} keys are also included
368 in @acronym{GnuTLS}.
370 @showfuncC{gnutls_key_generate,gnutls_hex_encode,gnutls_hex_decode}
373 @node Authentication and credentials
374 @section Authentication and credentials
376 In @acronym{GnuTLS} every key exchange method is associated with a
377 credentials type. For a key exchange method to be available it
378 must be listed as a priority string (see @ref{Priority Strings}) and
379 the corresponding credentials type should be initialized and set using
380 @funcref{gnutls_credentials_set}.  A mapping of the key exchange methods
381 with the credential types is shown in @ref{tab:key-exchange-cred}.
383 @float Table,tab:key-exchange-cred
384 @multitable @columnfractions .4 .25 .25
386 @headitem Key exchange @tab Client credentials @tab Server credentials
388 @item @code{KX_RSA},
389 @code{KX_DHE_RSA},
390 @code{KX_DHE_DSS},
391 @code{KX_ECDHE_RSA},
392 @code{KX_ECDHE_ECDSA},
393 @code{KX_RSA_EXPORT}
394 @tab @code{CRD_CERTIFICATE}
395 @tab @code{CRD_CERTIFICATE}
397 @item @code{KX_SRP_RSA}, @code{KX_SRP_DSS}
398 @tab @code{CRD_SRP}
399 @tab @code{CRD_CERTIFICATE}, @code{CRD_SRP}
401 @item @code{KX_SRP}
402 @tab @code{CRD_SRP}
403 @tab @code{CRD_SRP}
405 @item @code{KX_ANON_DH},
406 @code{KX_ANON_ECDH}
407 @tab @code{CRD_ANON}
408 @tab @code{CRD_ANON}
410 @item @code{KX_PSK},
411 @code{KX_DHE_PSK}, @code{KX_ECDHE_PSK}
412 @tab @code{CRD_PSK}
413 @tab @code{CRD_PSK}
415 @end multitable
416 @caption{Key exchange algorithms and the corresponding credential types.}
417 @end float