2 * Copyright (C) 2001,2002 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * GNUTLS-EXTRA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS-EXTRA is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include "gnutls_int.h"
25 #include "gnutls_auth_int.h"
27 #include "gnutls_errors.h"
28 #include "gnutls_algorithms.h"
30 int _gnutls_srp_recv_params( GNUTLS_STATE state
, const opaque
* data
, int data_size
) {
33 if (_gnutls_kx_priority( state
, GNUTLS_KX_SRP
) < 0) {
34 /* algorithm was not allowed in this state
39 if (state
->security_parameters
.entity
== GNUTLS_SERVER
) {
42 if (len
> data_size
) {
44 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH
;
46 if ( sizeof( state
->security_parameters
.extensions
.srp_username
) <= len
) {
48 return GNUTLS_E_MEMORY_ERROR
;
50 memcpy( state
->security_parameters
.extensions
.srp_username
, &data
[1], len
);
51 state
->security_parameters
.extensions
.srp_username
[len
]=0; /* null terminated */
53 } else { /* client side reading server hello extensions */
54 if (state
->gnutls_internals
.resumed
==RESUME_FALSE
)
55 return proc_srp_server_hello( state
, data
, data_size
);
56 else /* we do not need to process this if
64 /* returns data_size or a negative number on failure
65 * data is allocated localy
67 int _gnutls_srp_send_params( GNUTLS_STATE state
, opaque
* data
, int data_size
) {
70 if (_gnutls_kx_priority( state
, GNUTLS_KX_SRP
) < 0) {
71 /* algorithm was not allowed in this state
76 /* this function sends the client extension data (username) */
77 if (state
->security_parameters
.entity
== GNUTLS_CLIENT
) {
78 const GNUTLS_SRP_CLIENT_CREDENTIALS cred
= _gnutls_get_cred( state
->gnutls_key
, GNUTLS_CRD_SRP
, NULL
);
80 if (cred
==NULL
) return 0;
82 if (cred
->username
!=NULL
) { /* send username */
83 len
= strlen(cred
->username
);
84 if (data_size
< len
+1) {
86 return GNUTLS_E_INVALID_REQUEST
;
90 memcpy( &data
[1], cred
->username
, len
);
93 } else { /* SERVER SIDE sending (g,n,s) */
94 /* We only send the packet if we are NOT
95 * resuming AND we are using SRP
98 /* note that security parameters are not fully established
100 if ( _gnutls_cipher_suite_get_kx_algo(state
->security_parameters
.current_cipher_suite
) != GNUTLS_KX_SRP
)
101 return 0; /* no data to send */
103 if (state
->gnutls_internals
.resumed
==RESUME_FALSE
)
104 return gen_srp_server_hello( state
, data
, data_size
);
111 #endif /* ENABLE_SRP */