2 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2010 Free Software
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GNUTLS.
9 * The GNUTLS library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include <gnutls_int.h>
31 #include "gnutls_auth.h"
33 #include "gnutls_errors.h"
34 #include "gnutls_algorithms.h"
35 #include <gnutls_num.h>
38 _gnutls_srp_recv_params (gnutls_session_t session
, const opaque
* data
,
42 ssize_t data_size
= _data_size
;
44 if (session
->security_parameters
.entity
== GNUTLS_SERVER
)
49 DECR_LEN (data_size
, len
);
51 if (MAX_SRP_USERNAME
< len
)
54 return GNUTLS_E_ILLEGAL_SRP_USERNAME
;
56 memcpy (session
->security_parameters
.extensions
.srp_username
,
59 session
->security_parameters
.extensions
.srp_username
[len
] = 0;
65 /* returns data_size or a negative number on failure
66 * data is allocated locally
69 _gnutls_srp_send_params (gnutls_session_t session
, opaque
* data
,
74 if (_gnutls_kx_priority (session
, GNUTLS_KX_SRP
) < 0 &&
75 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_DSS
) < 0 &&
76 _gnutls_kx_priority (session
, GNUTLS_KX_SRP_RSA
) < 0)
78 /* algorithm was not allowed in this session
83 /* this function sends the client extension data (username) */
84 if (session
->security_parameters
.entity
== GNUTLS_CLIENT
)
86 gnutls_srp_client_credentials_t cred
= (gnutls_srp_client_credentials_t
)
87 _gnutls_get_cred (session
->key
, GNUTLS_CRD_SRP
, NULL
);
92 if (cred
->username
!= NULL
)
94 len
= MIN (strlen (cred
->username
), 255);
96 if (data_size
< len
+ 1)
99 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
102 data
[0] = (uint8_t) len
;
103 memcpy (&data
[1], cred
->username
, len
);
106 else if (cred
->get_function
!= NULL
)
110 char *username
= NULL
, *password
= NULL
;
112 if (cred
->get_function (session
, &username
, &password
) < 0
113 || username
== NULL
|| password
== NULL
)
116 return GNUTLS_E_ILLEGAL_SRP_USERNAME
;
119 len
= MIN (strlen (username
), 255);
121 if (data_size
< len
+ 1)
123 gnutls_free (username
);
124 gnutls_free (password
);
126 return GNUTLS_E_SHORT_MEMORY_BUFFER
;
129 session
->internals
.srp_username
= username
;
130 session
->internals
.srp_password
= password
;
132 data
[0] = (uint8_t) len
;
133 memcpy (&data
[1], username
, len
);
140 #endif /* ENABLE_SRP */