2 * Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation
4 * Author: Nikos Mavrogiannopoulos
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,
25 #include <gnutls_int.h>
30 #include "gnutls_auth_int.h"
32 #include "gnutls_errors.h"
33 #include "gnutls_algorithms.h"
34 #include <gnutls_num.h>
37 _gnutls_srp_recv_params (gnutls_session_t session
, const opaque
* data
,
41 ssize_t data_size
= _data_size
;
43 if (session
->security_parameters
.entity
== GNUTLS_SERVER
)
48 DECR_LEN (data_size
, len
);
50 if (MAX_SRP_USERNAME
< len
)
53 return GNUTLS_E_ILLEGAL_SRP_USERNAME
;
55 memcpy (session
->security_parameters
.extensions
.srp_username
,
58 session
->security_parameters
.extensions
.srp_username
[len
] = 0;
64 /* returns data_size or a negative number on failure
65 * data is allocated locally
68 _gnutls_srp_send_params (gnutls_session_t session
, opaque
* data
,
73 if (_gnutls_kx_priority (session
, GNUTLS_KX_SRP
) < 0 &&
74 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_DSS
) < 0 &&
75 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_RSA
) < 0)
77 /* algorithm was not allowed in this session
82 /* this function sends the client extension data (username) */
83 if (session
->security_parameters
.entity
== GNUTLS_CLIENT
)
85 gnutls_srp_client_credentials_t cred
= (gnutls_srp_client_credentials_t
)
86 _gnutls_get_cred (session
->key
, GNUTLS_CRD_SRP
, NULL
);
91 if (cred
->username
!= NULL
)
93 len
= MIN (strlen (cred
->username
), 255);
95 if (data_size
< len
+ 1)
98 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
101 data
[0] = (uint8_t) len
;
102 memcpy (&data
[1], cred
->username
, len
);
105 else if (cred
->get_function
!= NULL
)
109 char *username
= NULL
, *password
= NULL
;
111 if (cred
->get_function (session
, &username
, &password
) < 0
112 || username
== NULL
|| password
== NULL
)
115 return GNUTLS_E_ILLEGAL_SRP_USERNAME
;
118 len
= MIN (strlen (username
), 255);
120 if (data_size
< len
+ 1)
122 gnutls_free (username
);
123 gnutls_free (password
);
125 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
128 session
->internals
.srp_username
= username
;
129 session
->internals
.srp_password
= password
;
131 data
[0] = (uint8_t) len
;
132 memcpy (&data
[1], username
, len
);
139 #endif /* ENABLE_SRP */