Guile: Fix `x509-certificate-dn-oid' and related functions.
[gnutls.git] / lib / auth_anon.c
blobed65a3cc1b086c97e2233334b4ef44a5057b2b97
1 /*
2 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation
4 * Author: Nikos Mavroyanopoulos
6 * This file is part of GNUTLS.
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 * USA
25 /* This file contains the Anonymous Diffie Hellman key exchange part of
26 * the anonymous authentication. The functions here are used in the
27 * handshake.
30 #include <gnutls_int.h>
32 #ifdef ENABLE_ANON
34 #include "gnutls_auth_int.h"
35 #include "gnutls_errors.h"
36 #include "gnutls_dh.h"
37 #include "auth_anon.h"
38 #include "gnutls_num.h"
39 #include "gnutls_mpi.h"
40 #include <gnutls_state.h>
41 #include <auth_dh_common.h>
43 static int gen_anon_server_kx (gnutls_session_t, opaque **);
44 static int proc_anon_client_kx (gnutls_session_t, opaque *, size_t);
45 static int proc_anon_server_kx (gnutls_session_t, opaque *, size_t);
47 const mod_auth_st anon_auth_struct = {
48 "ANON",
49 NULL,
50 NULL,
51 gen_anon_server_kx,
52 _gnutls_gen_dh_common_client_kx, /* this can be shared */
53 NULL,
54 NULL,
56 NULL,
57 NULL, /* certificate */
58 proc_anon_server_kx,
59 proc_anon_client_kx,
60 NULL,
61 NULL
64 static int
65 gen_anon_server_kx (gnutls_session_t session, opaque ** data)
67 mpi_t g, p;
68 const mpi_t *mpis;
69 int ret;
70 gnutls_dh_params_t dh_params;
71 gnutls_anon_server_credentials_t cred;
73 cred = (gnutls_anon_server_credentials_t)
74 _gnutls_get_cred (session->key, GNUTLS_CRD_ANON, NULL);
75 if (cred == NULL)
77 gnutls_assert ();
78 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
81 dh_params =
82 _gnutls_get_dh_params (cred->dh_params, cred->params_func, session);
83 mpis = _gnutls_dh_params_to_mpi (dh_params);
84 if (mpis == NULL)
86 gnutls_assert ();
87 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS;
90 p = mpis[0];
91 g = mpis[1];
93 if ((ret =
94 _gnutls_auth_info_set (session, GNUTLS_CRD_ANON,
95 sizeof (anon_auth_info_st), 1)) < 0)
97 gnutls_assert ();
98 return ret;
101 _gnutls_dh_set_group (session, g, p);
103 ret = _gnutls_dh_common_print_server_kx (session, g, p, data, 0);
104 if (ret < 0)
106 gnutls_assert ();
109 return ret;
113 static int
114 proc_anon_client_kx (gnutls_session_t session, opaque * data,
115 size_t _data_size)
117 gnutls_anon_server_credentials_t cred;
118 int bits;
119 int ret;
120 mpi_t p, g;
121 gnutls_dh_params_t dh_params;
122 const mpi_t *mpis;
124 bits = _gnutls_dh_get_allowed_prime_bits (session);
126 cred = (gnutls_anon_server_credentials_t)
127 _gnutls_get_cred (session->key, GNUTLS_CRD_ANON, NULL);
128 if (cred == NULL)
130 gnutls_assert ();
131 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
134 dh_params =
135 _gnutls_get_dh_params (cred->dh_params, cred->params_func, session);
136 mpis = _gnutls_dh_params_to_mpi (dh_params);
137 if (mpis == NULL)
139 gnutls_assert ();
140 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS;
143 p = mpis[0];
144 g = mpis[1];
146 ret = _gnutls_proc_dh_common_client_kx (session, data, _data_size, g, p);
148 return ret;
153 proc_anon_server_kx (gnutls_session_t session, opaque * data,
154 size_t _data_size)
157 int ret;
159 /* set auth_info */
160 if ((ret =
161 _gnutls_auth_info_set (session, GNUTLS_CRD_ANON,
162 sizeof (anon_auth_info_st), 1)) < 0)
164 gnutls_assert ();
165 return ret;
168 ret = _gnutls_proc_dh_common_server_kx (session, data, _data_size, 0);
169 if (ret < 0)
171 gnutls_assert ();
172 return ret;
175 return 0;
178 #endif /* ENABLE_ANON */