SSL_CTX_set_srp_password.pod 8.0 KB

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