Line data Source code
1 : /* 2 : * Copyright (C) 2001-2012 Free Software Foundation, Inc. 3 : * 4 : * Author: Nikos Mavrogiannopoulos 5 : * 6 : * This file is part of GnuTLS. 7 : * 8 : * The GnuTLS 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. 12 : * 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. 17 : * 18 : * You should have received a copy of the GNU Lesser General Public License 19 : * along with this program. If not, see <https://www.gnu.org/licenses/> 20 : * 21 : */ 22 : 23 : #include "gnutls_int.h" 24 : 25 : #ifdef ENABLE_ANON 26 : 27 : #include "errors.h" 28 : #include <auth/anon.h> 29 : #include "auth.h" 30 : #include "dh.h" 31 : #include "num.h" 32 : #include "mpi.h" 33 : 34 : /** 35 : * gnutls_anon_free_server_credentials: 36 : * @sc: is a #gnutls_anon_server_credentials_t type. 37 : * 38 : * Free a gnutls_anon_server_credentials_t structure. 39 : **/ 40 : void 41 1007 : gnutls_anon_free_server_credentials(gnutls_anon_server_credentials_t sc) 42 : { 43 1007 : if (sc->deinit_dh_params) { 44 0 : gnutls_dh_params_deinit(sc->dh_params); 45 : } 46 1007 : gnutls_free(sc); 47 1007 : } 48 : 49 : /** 50 : * gnutls_anon_allocate_server_credentials: 51 : * @sc: is a pointer to a #gnutls_anon_server_credentials_t type. 52 : * 53 : * Allocate a gnutls_anon_server_credentials_t structure. 54 : * 55 : * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 56 : **/ 57 : int 58 1327 : gnutls_anon_allocate_server_credentials(gnutls_anon_server_credentials_t * 59 : sc) 60 : { 61 : 62 1327 : *sc = gnutls_calloc(1, sizeof(anon_server_credentials_st)); 63 : 64 1327 : return 0; 65 : } 66 : 67 : 68 : /** 69 : * gnutls_anon_free_client_credentials: 70 : * @sc: is a #gnutls_anon_client_credentials_t type. 71 : * 72 : * Free a gnutls_anon_client_credentials_t structure. 73 : **/ 74 : void 75 800 : gnutls_anon_free_client_credentials(gnutls_anon_client_credentials_t sc) 76 : { 77 800 : } 78 : 79 : static struct gnutls_anon_client_credentials_st anon_dummy_struct; 80 : static const gnutls_anon_client_credentials_t anon_dummy = 81 : &anon_dummy_struct; 82 : 83 : /** 84 : * gnutls_anon_allocate_client_credentials: 85 : * @sc: is a pointer to a #gnutls_anon_client_credentials_t type. 86 : * 87 : * Allocate a gnutls_anon_client_credentials_t structure. 88 : * 89 : * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 90 : **/ 91 : int 92 878 : gnutls_anon_allocate_client_credentials(gnutls_anon_client_credentials_t * 93 : sc) 94 : { 95 : /* anon_dummy is only there for *sc not to be null. 96 : * it is not used at all; 97 : */ 98 878 : *sc = anon_dummy; 99 : 100 878 : return 0; 101 : } 102 : 103 : /** 104 : * gnutls_anon_set_server_dh_params: 105 : * @res: is a gnutls_anon_server_credentials_t type 106 : * @dh_params: The Diffie-Hellman parameters. 107 : * 108 : * This function will set the Diffie-Hellman parameters for an 109 : * anonymous server to use. These parameters will be used in 110 : * Anonymous Diffie-Hellman cipher suites. 111 : * 112 : * Deprecated: This function is unnecessary and discouraged on GnuTLS 3.6.0 113 : * or later. Since 3.6.0, DH parameters are negotiated 114 : * following RFC7919. 115 : **/ 116 : void 117 432 : gnutls_anon_set_server_dh_params(gnutls_anon_server_credentials_t res, 118 : gnutls_dh_params_t dh_params) 119 : { 120 432 : if (res->deinit_dh_params) { 121 0 : res->deinit_dh_params = 0; 122 0 : gnutls_dh_params_deinit(res->dh_params); 123 0 : res->dh_params = NULL; 124 : } 125 : 126 432 : res->dh_params = dh_params; 127 432 : res->dh_sec_param = gnutls_pk_bits_to_sec_param(GNUTLS_PK_DH, _gnutls_mpi_get_nbits(dh_params->params[0])); 128 432 : } 129 : 130 : /** 131 : * gnutls_anon_set_server_known_dh_params: 132 : * @res: is a gnutls_anon_server_credentials_t type 133 : * @sec_param: is an option of the %gnutls_sec_param_t enumeration 134 : * 135 : * This function will set the Diffie-Hellman parameters for an 136 : * anonymous server to use. These parameters will be used in 137 : * Anonymous Diffie-Hellman cipher suites and will be selected from 138 : * the FFDHE set of RFC7919 according to the security level provided. 139 : * 140 : * Deprecated: This function is unnecessary and discouraged on GnuTLS 3.6.0 141 : * or later. Since 3.6.0, DH parameters are negotiated 142 : * following RFC7919. 143 : * 144 : * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a 145 : * negative error value. 146 : * 147 : * Since: 3.5.6 148 : **/ 149 : int 150 196 : gnutls_anon_set_server_known_dh_params(gnutls_anon_server_credentials_t res, 151 : gnutls_sec_param_t sec_param) 152 : { 153 196 : res->dh_sec_param = sec_param; 154 : 155 196 : return 0; 156 : } 157 : 158 : /** 159 : * gnutls_anon_set_server_params_function: 160 : * @res: is a gnutls_certificate_credentials_t type 161 : * @func: is the function to be called 162 : * 163 : * This function will set a callback in order for the server to get 164 : * the Diffie-Hellman parameters for anonymous authentication. The 165 : * callback should return %GNUTLS_E_SUCCESS (0) on success. 166 : * 167 : * Deprecated: This function is unnecessary and discouraged on GnuTLS 3.6.0 168 : * or later. Since 3.6.0, DH parameters are negotiated 169 : * following RFC7919. 170 : * 171 : **/ 172 : void 173 100 : gnutls_anon_set_server_params_function(gnutls_anon_server_credentials_t 174 : res, gnutls_params_function * func) 175 : { 176 100 : res->params_func = func; 177 100 : } 178 : 179 : /** 180 : * gnutls_anon_set_params_function: 181 : * @res: is a gnutls_anon_server_credentials_t type 182 : * @func: is the function to be called 183 : * 184 : * This function will set a callback in order for the server to get 185 : * the Diffie-Hellman or RSA parameters for anonymous authentication. 186 : * The callback should return %GNUTLS_E_SUCCESS (0) on success. 187 : * 188 : * Deprecated: This function is unnecessary and discouraged on GnuTLS 3.6.0 189 : * or later. Since 3.6.0, DH parameters are negotiated 190 : * following RFC7919. 191 : * 192 : **/ 193 : void 194 0 : gnutls_anon_set_params_function(gnutls_anon_server_credentials_t res, 195 : gnutls_params_function * func) 196 : { 197 0 : res->params_func = func; 198 0 : } 199 : #endif