2 * Copyright (C) 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,
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 (_gnutls_kx_priority (session
, GNUTLS_KX_SRP
) < 0 &&
44 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_DSS
) < 0 &&
45 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_RSA
) < 0)
47 /* algorithm was not allowed in this session
52 if (session
->security_parameters
.entity
== GNUTLS_SERVER
)
57 DECR_LEN (data_size
, len
);
59 if (MAX_SRP_USERNAME
< len
)
62 return GNUTLS_E_ILLEGAL_SRP_USERNAME
;
64 memcpy (session
->security_parameters
.extensions
.srp_username
,
67 session
->security_parameters
.extensions
.srp_username
[len
] = 0;
73 /* returns data_size or a negative number on failure
74 * data is allocated locally
77 _gnutls_srp_send_params (gnutls_session_t session
, opaque
* data
,
82 if (_gnutls_kx_priority (session
, GNUTLS_KX_SRP
) < 0 &&
83 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_DSS
) < 0 &&
84 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_RSA
) < 0)
86 /* algorithm was not allowed in this session
91 /* this function sends the client extension data (username) */
92 if (session
->security_parameters
.entity
== GNUTLS_CLIENT
)
94 gnutls_srp_client_credentials_t cred
= (gnutls_srp_client_credentials_t
)
95 _gnutls_get_cred (session
->key
, GNUTLS_CRD_SRP
, NULL
);
100 if (cred
->username
!= NULL
)
101 { /* send username */
102 len
= MIN (strlen (cred
->username
), 255);
104 if (data_size
< len
+ 1)
107 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
110 data
[0] = (uint8_t) len
;
111 memcpy (&data
[1], cred
->username
, len
);
114 else if (cred
->get_function
!= NULL
)
118 char *username
= NULL
, *password
= NULL
;
120 if (cred
->get_function (session
,
121 session
->internals
.handshake_restarted
,
122 &username
, &password
) < 0
123 || username
== NULL
|| password
== NULL
)
126 if (session
->internals
.handshake_restarted
)
129 return GNUTLS_E_ILLEGAL_SRP_USERNAME
;
135 len
= MIN (strlen (username
), 255);
137 if (data_size
< len
+ 1)
139 gnutls_free (username
);
140 gnutls_free (password
);
142 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
145 session
->internals
.srp_username
= username
;
146 session
->internals
.srp_password
= password
;
148 data
[0] = (uint8_t) len
;
149 memcpy (&data
[1], username
, len
);
156 #endif /* ENABLE_SRP */