1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
=pod
=head1 NAME
SSL_CTX_set_srp_username,
SSL_CTX_set_srp_password,
SSL_CTX_set_srp_strength,
SSL_CTX_set_srp_cb_arg,
SSL_CTX_set_srp_username_callback,
SSL_CTX_set_srp_client_pwd_callback,
SSL_CTX_set_srp_verify_param_callback,
SSL_set_srp_server_param,
SSL_set_srp_server_param_pw,
SSL_get_srp_g,
SSL_get_srp_N,
SSL_get_srp_username,
SSL_get_srp_userinfo
- SRP control operations
=head1 SYNOPSIS
#include <openssl/ssl.h>
int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name);
int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password);
int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength);
int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg);
int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
int (*cb) (SSL *s, int *ad, void *arg));
int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx,
char *(*cb) (SSL *s, void *arg));
int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx,
int (*cb) (SSL *s, void *arg));
int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
BIGNUM *sa, BIGNUM *v, char *info);
int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,
const char *grp);
BIGNUM *SSL_get_srp_g(SSL *s);
BIGNUM *SSL_get_srp_N(SSL *s);
char *SSL_get_srp_username(SSL *s);
char *SSL_get_srp_userinfo(SSL *s);
=head1 DESCRIPTION
These functions provide access to SRP (Secure Remote Password) parameters,
an alternate authentication mechanism for TLS. SRP allows the use of usernames
and passwords over unencrypted channels without revealing the password to an
eavesdropper. SRP also supplies a shared secret at the end of the authentication
sequence that can be used to generate encryption keys.
The SRP protocol, version 3 is specified in RFC 2945. SRP version 6 is described
in RFC 5054 with applications to TLS authentication.
The SSL_CTX_set_srp_username() function sets the SRP username for B<ctx>. This
should be called on the client prior to creating a connection to the server.
The length of B<name> must be shorter or equal to 255 characters.
The SSL_CTX_set_srp_password() function sets the SRP password for B<ctx>. This
may be called on the client prior to creating a connection to the server.
This overrides the effect of SSL_CTX_set_srp_client_pwd_callback().
The SSL_CTX_set_srp_strength() function sets the SRP strength for B<ctx>. This
is the minimal length of the SRP prime in bits. If not specified 1024 is used.
If not satisfied by the server key exchange the connection will be rejected.
The SSL_CTX_set_srp_cb_arg() function sets an extra parameter that will
be passed to all following callbacks as B<arg>.
The SSL_CTX_set_srp_username_callback() function sets the server side callback
that is invoked when an SRP username is found in a ClientHello.
The callback parameters are the SSL connection B<s>, a writable error flag B<ad>
and the extra argument B<arg> set by SSL_CTX_set_srp_cb_arg().
This callback should setup the server for the key exchange by calling
SSL_set_srp_server_param() with the appropriate parameters for the received
username. The username can be obtained by calling SSL_get_srp_username().
See L<SRP_VBASE_init(3)> to parse the verifier file created by L<openssl-srp(1)> or
L<SRP_create_verifier(3)> to generate it.
The callback should return B<SSL_ERROR_NONE> to proceed with the server key exchange,
B<SSL3_AL_FATAL> for a fatal error or any value < 0 for a retryable error.
In the event of a B<SSL3_AL_FATAL> the alert flag given by B<*al> will be sent
back. By default this will be B<SSL_AD_UNKNOWN_PSK_IDENTITY>.
The SSL_CTX_set_srp_client_pwd_callback() function sets the client password
callback on the client.
The callback parameters are the SSL connection B<s> and the extra argument B<arg>
set by SSL_CTX_set_srp_cb_arg().
The callback will be called as part of the generation of the client secrets.
It should return the client password in text form or NULL to abort the connection.
The resulting memory will be freed by the library as part of the callback resolution.
This overrides the effect of SSL_CTX_set_srp_password().
The SSL_CTX_set_srp_verify_param_callback() sets the SRP gN parameter verification
callback on the client. This allows the client to perform custom verification when
receiving the server SRP proposed parameters.
The callback parameters are the SSL connection B<s> and the extra argument B<arg>
set by SSL_CTX_set_srp_cb_arg().
The callback should return a positive value to accept the server parameters.
Returning 0 or a negative value will abort the connection. The server parameters
can be obtained by calling SSL_get_srp_N() and SSL_get_srp_g().
Sanity checks are already performed by the library after the handshake
(B % N non zero, check against the strength parameter) and are not necessary.
If no callback is set the g and N parameters will be checked against
known RFC 5054 values.
The SSL_set_srp_server_param() function sets all SRP parameters for
the connection B<s>. B<N> and B<g> are the SRP group parameters, B<sa> is the
user salt, B<v> the password verifier and B<info> is the optional user info.
The SSL_set_srp_server_param_pw() function sets all SRP parameters for the
connection B<s> by generating a random salt and a password verifier.
B<user> is the username, B<pass> the password and B<grp> the SRP group parameters
identifier for L<SRP_get_default_gN(3)>.
The SSL_get_srp_g() function returns the SRP group generator for B<s>, or from
the underlying SSL_CTX if it is NULL.
The SSL_get_srp_N() function returns the SRP prime for B<s>, or from
the underlying SSL_CTX if it is NULL.
The SSL_get_srp_username() function returns the SRP username for B<s>, or from
the underlying SSL_CTX if it is NULL.
The SSL_get_srp_userinfo() function returns the SRP user info for B<s>, or from
the underlying SSL_CTX if it is NULL.
=head1 RETURN VALUES
All SSL_CTX_set_* functions return 1 on success and 0 on failure.
SSL_set_srp_server_param() returns 1 on success and -1 on failure.
The SSL_get_SRP_* functions return a pointer to the requested data, the memory
is owned by the library and should not be freed by the caller.
=head1 EXAMPLES
Setup SRP parameters on the client:
#include <openssl/ssl.h>
const char *username = "username";
const char *password = "password";
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
if (!ctx)
/* Error */
if (!SSL_CTX_set_srp_username(ctx, username))
/* Error */
if (!SSL_CTX_set_srp_password(ctx, password))
/* Error */
Setup SRP server with verifier file:
#include <openssl/srp.h>
#include <openssl/ssl.h>
const char *srpvfile = "password.srpv";
int srpServerCallback(SSL *s, int *ad, void *arg)
{
SRP_VBASE *srpData = (SRP_VBASE*) arg;
char *username = SSL_get_srp_username(s);
SRP_user_pwd *user_pwd = SRP_VBASE_get1_by_user(srpData, username);
if (!user_pwd)
/* Error */
return SSL3_AL_FATAL;
if (SSL_set_srp_server_param(s, user_pwd->N, user_pwd->g,
user_pwd->s, user_pwd->v, user_pwd->info) < 0)
/* Error */
SRP_user_pwd_free(user_pwd);
return SSL_ERROR_NONE;
}
SSL_CTX *ctx = SSL_CTX_new(TLS_server_method());
if (!ctx)
/* Error */
/*
* seedKey should contain a NUL terminated sequence
* of random non NUL bytes
*/
const char *seedKey;
SRP_VBASE *srpData = SRP_VBASE_new(seedKey);
if (SRP_VBASE_init(srpData, (char*) srpvfile) != SRP_NO_ERROR)
/* Error */
SSL_CTX_set_srp_cb_arg(ctx, srpData);
SSL_CTX_set_srp_username_callback(ctx, srpServerCallback);
=head1 SEE ALSO
L<ssl(7)>,
L<openssl-srp(1)>,
L<SRP_VBASE_new(3)>,
L<SRP_create_verifier(3)>
=head1 HISTORY
These functions were added in OpenSSL 1.0.1.
=head1 COPYRIGHT
Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.
=cut
|