tls_srp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License 2.0 (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. *
  10. * Originally written by Christophe Renou and Peter Sylvester,
  11. * for the EdelKey project.
  12. */
  13. /*
  14. * We need to use the SRP deprecated APIs in order to implement the SSL SRP
  15. * APIs - which are themselves deprecated.
  16. */
  17. #define OPENSSL_SUPPRESS_DEPRECATED
  18. #include <openssl/crypto.h>
  19. #include <openssl/rand.h>
  20. #include <openssl/err.h>
  21. #include "ssl_local.h"
  22. #ifndef OPENSSL_NO_SRP
  23. # include <openssl/srp.h>
  24. /*
  25. * The public API SSL_CTX_SRP_CTX_free() is deprecated so we use
  26. * ssl_ctx_srp_ctx_free_intern() internally.
  27. */
  28. int ssl_ctx_srp_ctx_free_intern(SSL_CTX *ctx)
  29. {
  30. if (ctx == NULL)
  31. return 0;
  32. OPENSSL_free(ctx->srp_ctx.login);
  33. OPENSSL_free(ctx->srp_ctx.info);
  34. BN_free(ctx->srp_ctx.N);
  35. BN_free(ctx->srp_ctx.g);
  36. BN_free(ctx->srp_ctx.s);
  37. BN_free(ctx->srp_ctx.B);
  38. BN_free(ctx->srp_ctx.A);
  39. BN_free(ctx->srp_ctx.a);
  40. BN_free(ctx->srp_ctx.b);
  41. BN_free(ctx->srp_ctx.v);
  42. memset(&ctx->srp_ctx, 0, sizeof(ctx->srp_ctx));
  43. ctx->srp_ctx.strength = SRP_MINIMAL_N;
  44. return 1;
  45. }
  46. int SSL_CTX_SRP_CTX_free(SSL_CTX *ctx)
  47. {
  48. return ssl_ctx_srp_ctx_free_intern(ctx);
  49. }
  50. /*
  51. * The public API SSL_SRP_CTX_free() is deprecated so we use
  52. * ssl_srp_ctx_free_intern() internally.
  53. */
  54. int ssl_srp_ctx_free_intern(SSL_CONNECTION *s)
  55. {
  56. if (s == NULL)
  57. return 0;
  58. OPENSSL_free(s->srp_ctx.login);
  59. OPENSSL_free(s->srp_ctx.info);
  60. BN_free(s->srp_ctx.N);
  61. BN_free(s->srp_ctx.g);
  62. BN_free(s->srp_ctx.s);
  63. BN_free(s->srp_ctx.B);
  64. BN_free(s->srp_ctx.A);
  65. BN_free(s->srp_ctx.a);
  66. BN_free(s->srp_ctx.b);
  67. BN_free(s->srp_ctx.v);
  68. memset(&s->srp_ctx, 0, sizeof(s->srp_ctx));
  69. s->srp_ctx.strength = SRP_MINIMAL_N;
  70. return 1;
  71. }
  72. int SSL_SRP_CTX_free(SSL *s)
  73. {
  74. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  75. /* the call works with NULL sc */
  76. return ssl_srp_ctx_free_intern(sc);
  77. }
  78. /*
  79. * The public API SSL_SRP_CTX_init() is deprecated so we use
  80. * ssl_srp_ctx_init_intern() internally.
  81. */
  82. int ssl_srp_ctx_init_intern(SSL_CONNECTION *s)
  83. {
  84. SSL_CTX *ctx;
  85. if (s == NULL || (ctx = SSL_CONNECTION_GET_CTX(s)) == NULL)
  86. return 0;
  87. memset(&s->srp_ctx, 0, sizeof(s->srp_ctx));
  88. s->srp_ctx.SRP_cb_arg = ctx->srp_ctx.SRP_cb_arg;
  89. /* set client Hello login callback */
  90. s->srp_ctx.TLS_ext_srp_username_callback =
  91. ctx->srp_ctx.TLS_ext_srp_username_callback;
  92. /* set SRP N/g param callback for verification */
  93. s->srp_ctx.SRP_verify_param_callback =
  94. ctx->srp_ctx.SRP_verify_param_callback;
  95. /* set SRP client passwd callback */
  96. s->srp_ctx.SRP_give_srp_client_pwd_callback =
  97. ctx->srp_ctx.SRP_give_srp_client_pwd_callback;
  98. s->srp_ctx.strength = ctx->srp_ctx.strength;
  99. if (((ctx->srp_ctx.N != NULL) &&
  100. ((s->srp_ctx.N = BN_dup(ctx->srp_ctx.N)) == NULL)) ||
  101. ((ctx->srp_ctx.g != NULL) &&
  102. ((s->srp_ctx.g = BN_dup(ctx->srp_ctx.g)) == NULL)) ||
  103. ((ctx->srp_ctx.s != NULL) &&
  104. ((s->srp_ctx.s = BN_dup(ctx->srp_ctx.s)) == NULL)) ||
  105. ((ctx->srp_ctx.B != NULL) &&
  106. ((s->srp_ctx.B = BN_dup(ctx->srp_ctx.B)) == NULL)) ||
  107. ((ctx->srp_ctx.A != NULL) &&
  108. ((s->srp_ctx.A = BN_dup(ctx->srp_ctx.A)) == NULL)) ||
  109. ((ctx->srp_ctx.a != NULL) &&
  110. ((s->srp_ctx.a = BN_dup(ctx->srp_ctx.a)) == NULL)) ||
  111. ((ctx->srp_ctx.v != NULL) &&
  112. ((s->srp_ctx.v = BN_dup(ctx->srp_ctx.v)) == NULL)) ||
  113. ((ctx->srp_ctx.b != NULL) &&
  114. ((s->srp_ctx.b = BN_dup(ctx->srp_ctx.b)) == NULL))) {
  115. ERR_raise(ERR_LIB_SSL, ERR_R_BN_LIB);
  116. goto err;
  117. }
  118. if ((ctx->srp_ctx.login != NULL) &&
  119. ((s->srp_ctx.login = OPENSSL_strdup(ctx->srp_ctx.login)) == NULL)) {
  120. ERR_raise(ERR_LIB_SSL, ERR_R_INTERNAL_ERROR);
  121. goto err;
  122. }
  123. if ((ctx->srp_ctx.info != NULL) &&
  124. ((s->srp_ctx.info = OPENSSL_strdup(ctx->srp_ctx.info)) == NULL)) {
  125. ERR_raise(ERR_LIB_SSL, ERR_R_INTERNAL_ERROR);
  126. goto err;
  127. }
  128. s->srp_ctx.srp_Mask = ctx->srp_ctx.srp_Mask;
  129. return 1;
  130. err:
  131. OPENSSL_free(s->srp_ctx.login);
  132. OPENSSL_free(s->srp_ctx.info);
  133. BN_free(s->srp_ctx.N);
  134. BN_free(s->srp_ctx.g);
  135. BN_free(s->srp_ctx.s);
  136. BN_free(s->srp_ctx.B);
  137. BN_free(s->srp_ctx.A);
  138. BN_free(s->srp_ctx.a);
  139. BN_free(s->srp_ctx.b);
  140. BN_free(s->srp_ctx.v);
  141. memset(&s->srp_ctx, 0, sizeof(s->srp_ctx));
  142. return 0;
  143. }
  144. int SSL_SRP_CTX_init(SSL *s)
  145. {
  146. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  147. /* the call works with NULL sc */
  148. return ssl_srp_ctx_init_intern(sc);
  149. }
  150. /*
  151. * The public API SSL_CTX_SRP_CTX_init() is deprecated so we use
  152. * ssl_ctx_srp_ctx_init_intern() internally.
  153. */
  154. int ssl_ctx_srp_ctx_init_intern(SSL_CTX *ctx)
  155. {
  156. if (ctx == NULL)
  157. return 0;
  158. memset(&ctx->srp_ctx, 0, sizeof(ctx->srp_ctx));
  159. ctx->srp_ctx.strength = SRP_MINIMAL_N;
  160. return 1;
  161. }
  162. int SSL_CTX_SRP_CTX_init(SSL_CTX *ctx)
  163. {
  164. return ssl_ctx_srp_ctx_init_intern(ctx);
  165. }
  166. /* server side */
  167. /*
  168. * The public API SSL_srp_server_param_with_username() is deprecated so we use
  169. * ssl_srp_server_param_with_username_intern() internally.
  170. */
  171. int ssl_srp_server_param_with_username_intern(SSL_CONNECTION *s, int *ad)
  172. {
  173. unsigned char b[SSL_MAX_MASTER_KEY_LENGTH];
  174. int al;
  175. SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
  176. *ad = SSL_AD_UNKNOWN_PSK_IDENTITY;
  177. if ((s->srp_ctx.TLS_ext_srp_username_callback != NULL) &&
  178. ((al =
  179. s->srp_ctx.TLS_ext_srp_username_callback(SSL_CONNECTION_GET_SSL(s),
  180. ad,
  181. s->srp_ctx.SRP_cb_arg)) !=
  182. SSL_ERROR_NONE))
  183. return al;
  184. *ad = SSL_AD_INTERNAL_ERROR;
  185. if ((s->srp_ctx.N == NULL) ||
  186. (s->srp_ctx.g == NULL) ||
  187. (s->srp_ctx.s == NULL) || (s->srp_ctx.v == NULL))
  188. return SSL3_AL_FATAL;
  189. if (RAND_priv_bytes_ex(SSL_CONNECTION_GET_CTX(s)->libctx, b, sizeof(b),
  190. 0) <= 0)
  191. return SSL3_AL_FATAL;
  192. s->srp_ctx.b = BN_bin2bn(b, sizeof(b), NULL);
  193. OPENSSL_cleanse(b, sizeof(b));
  194. /* Calculate: B = (kv + g^b) % N */
  195. return ((s->srp_ctx.B =
  196. SRP_Calc_B_ex(s->srp_ctx.b, s->srp_ctx.N, s->srp_ctx.g,
  197. s->srp_ctx.v, sctx->libctx, sctx->propq)) !=
  198. NULL) ? SSL_ERROR_NONE : SSL3_AL_FATAL;
  199. }
  200. int SSL_srp_server_param_with_username(SSL *s, int *ad)
  201. {
  202. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  203. if (sc == NULL)
  204. return SSL3_AL_FATAL;
  205. return ssl_srp_server_param_with_username_intern(sc, ad);
  206. }
  207. /*
  208. * If the server just has the raw password, make up a verifier entry on the
  209. * fly
  210. */
  211. int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,
  212. const char *grp)
  213. {
  214. SRP_gN *GN;
  215. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  216. if (sc == NULL)
  217. return -1;
  218. GN = SRP_get_default_gN(grp);
  219. if (GN == NULL)
  220. return -1;
  221. sc->srp_ctx.N = BN_dup(GN->N);
  222. sc->srp_ctx.g = BN_dup(GN->g);
  223. BN_clear_free(sc->srp_ctx.v);
  224. sc->srp_ctx.v = NULL;
  225. BN_clear_free(sc->srp_ctx.s);
  226. sc->srp_ctx.s = NULL;
  227. if (!SRP_create_verifier_BN_ex(user, pass, &sc->srp_ctx.s, &sc->srp_ctx.v,
  228. sc->srp_ctx.N, sc->srp_ctx.g, s->ctx->libctx,
  229. s->ctx->propq))
  230. return -1;
  231. return 1;
  232. }
  233. int SSL_set_srp_server_param(SSL *s, const BIGNUM *N, const BIGNUM *g,
  234. BIGNUM *sa, BIGNUM *v, char *info)
  235. {
  236. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  237. if (sc == NULL)
  238. return -1;
  239. if (N != NULL) {
  240. if (sc->srp_ctx.N != NULL) {
  241. if (!BN_copy(sc->srp_ctx.N, N)) {
  242. BN_free(sc->srp_ctx.N);
  243. sc->srp_ctx.N = NULL;
  244. }
  245. } else
  246. sc->srp_ctx.N = BN_dup(N);
  247. }
  248. if (g != NULL) {
  249. if (sc->srp_ctx.g != NULL) {
  250. if (!BN_copy(sc->srp_ctx.g, g)) {
  251. BN_free(sc->srp_ctx.g);
  252. sc->srp_ctx.g = NULL;
  253. }
  254. } else
  255. sc->srp_ctx.g = BN_dup(g);
  256. }
  257. if (sa != NULL) {
  258. if (sc->srp_ctx.s != NULL) {
  259. if (!BN_copy(sc->srp_ctx.s, sa)) {
  260. BN_free(sc->srp_ctx.s);
  261. sc->srp_ctx.s = NULL;
  262. }
  263. } else
  264. sc->srp_ctx.s = BN_dup(sa);
  265. }
  266. if (v != NULL) {
  267. if (sc->srp_ctx.v != NULL) {
  268. if (!BN_copy(sc->srp_ctx.v, v)) {
  269. BN_free(sc->srp_ctx.v);
  270. sc->srp_ctx.v = NULL;
  271. }
  272. } else
  273. sc->srp_ctx.v = BN_dup(v);
  274. }
  275. if (info != NULL) {
  276. if (sc->srp_ctx.info)
  277. OPENSSL_free(sc->srp_ctx.info);
  278. if ((sc->srp_ctx.info = OPENSSL_strdup(info)) == NULL)
  279. return -1;
  280. }
  281. if (!(sc->srp_ctx.N) ||
  282. !(sc->srp_ctx.g) || !(sc->srp_ctx.s) || !(sc->srp_ctx.v))
  283. return -1;
  284. return 1;
  285. }
  286. int srp_generate_server_master_secret(SSL_CONNECTION *s)
  287. {
  288. BIGNUM *K = NULL, *u = NULL;
  289. int ret = 0, tmp_len = 0;
  290. unsigned char *tmp = NULL;
  291. SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
  292. if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))
  293. goto err;
  294. if ((u = SRP_Calc_u_ex(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N,
  295. sctx->libctx, sctx->propq)) == NULL)
  296. goto err;
  297. if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b,
  298. s->srp_ctx.N)) == NULL)
  299. goto err;
  300. tmp_len = BN_num_bytes(K);
  301. if ((tmp = OPENSSL_malloc(tmp_len)) == NULL) {
  302. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_CRYPTO_LIB);
  303. goto err;
  304. }
  305. BN_bn2bin(K, tmp);
  306. /* Calls SSLfatal() as required */
  307. ret = ssl_generate_master_secret(s, tmp, tmp_len, 1);
  308. err:
  309. BN_clear_free(K);
  310. BN_clear_free(u);
  311. return ret;
  312. }
  313. /* client side */
  314. int srp_generate_client_master_secret(SSL_CONNECTION *s)
  315. {
  316. BIGNUM *x = NULL, *u = NULL, *K = NULL;
  317. int ret = 0, tmp_len = 0;
  318. char *passwd = NULL;
  319. unsigned char *tmp = NULL;
  320. SSL_CTX *sctx = SSL_CONNECTION_GET_CTX(s);
  321. /*
  322. * Checks if b % n == 0
  323. */
  324. if (SRP_Verify_B_mod_N(s->srp_ctx.B, s->srp_ctx.N) == 0
  325. || (u = SRP_Calc_u_ex(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N,
  326. sctx->libctx, sctx->propq))
  327. == NULL
  328. || s->srp_ctx.SRP_give_srp_client_pwd_callback == NULL) {
  329. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  330. goto err;
  331. }
  332. if ((passwd = s->srp_ctx.SRP_give_srp_client_pwd_callback(SSL_CONNECTION_GET_SSL(s),
  333. s->srp_ctx.SRP_cb_arg))
  334. == NULL) {
  335. SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_CALLBACK_FAILED);
  336. goto err;
  337. }
  338. if ((x = SRP_Calc_x_ex(s->srp_ctx.s, s->srp_ctx.login, passwd,
  339. sctx->libctx, sctx->propq)) == NULL
  340. || (K = SRP_Calc_client_key_ex(s->srp_ctx.N, s->srp_ctx.B,
  341. s->srp_ctx.g, x,
  342. s->srp_ctx.a, u,
  343. sctx->libctx,
  344. sctx->propq)) == NULL) {
  345. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
  346. goto err;
  347. }
  348. tmp_len = BN_num_bytes(K);
  349. if ((tmp = OPENSSL_malloc(tmp_len)) == NULL) {
  350. SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_CRYPTO_LIB);
  351. goto err;
  352. }
  353. BN_bn2bin(K, tmp);
  354. /* Calls SSLfatal() as required */
  355. ret = ssl_generate_master_secret(s, tmp, tmp_len, 1);
  356. err:
  357. BN_clear_free(K);
  358. BN_clear_free(x);
  359. if (passwd != NULL)
  360. OPENSSL_clear_free(passwd, strlen(passwd));
  361. BN_clear_free(u);
  362. return ret;
  363. }
  364. int srp_verify_server_param(SSL_CONNECTION *s)
  365. {
  366. SRP_CTX *srp = &s->srp_ctx;
  367. /*
  368. * Sanity check parameters: we can quickly check B % N == 0 by checking B
  369. * != 0 since B < N
  370. */
  371. if (BN_ucmp(srp->g, srp->N) >= 0 || BN_ucmp(srp->B, srp->N) >= 0
  372. || BN_is_zero(srp->B)) {
  373. SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_DATA);
  374. return 0;
  375. }
  376. if (BN_num_bits(srp->N) < srp->strength) {
  377. SSLfatal(s, SSL_AD_INSUFFICIENT_SECURITY, SSL_R_INSUFFICIENT_SECURITY);
  378. return 0;
  379. }
  380. if (srp->SRP_verify_param_callback) {
  381. if (srp->SRP_verify_param_callback(SSL_CONNECTION_GET_SSL(s),
  382. srp->SRP_cb_arg) <= 0) {
  383. SSLfatal(s, SSL_AD_INSUFFICIENT_SECURITY, SSL_R_CALLBACK_FAILED);
  384. return 0;
  385. }
  386. } else if (!SRP_check_known_gN_param(srp->g, srp->N)) {
  387. SSLfatal(s, SSL_AD_INSUFFICIENT_SECURITY,
  388. SSL_R_INSUFFICIENT_SECURITY);
  389. return 0;
  390. }
  391. return 1;
  392. }
  393. /*
  394. * The public API SRP_Calc_A_param() is deprecated so we use
  395. * ssl_srp_calc_a_param_intern() internally.
  396. */
  397. int ssl_srp_calc_a_param_intern(SSL_CONNECTION *s)
  398. {
  399. unsigned char rnd[SSL_MAX_MASTER_KEY_LENGTH];
  400. if (RAND_priv_bytes_ex(SSL_CONNECTION_GET_CTX(s)->libctx,
  401. rnd, sizeof(rnd), 0) <= 0)
  402. return 0;
  403. s->srp_ctx.a = BN_bin2bn(rnd, sizeof(rnd), s->srp_ctx.a);
  404. OPENSSL_cleanse(rnd, sizeof(rnd));
  405. if (!(s->srp_ctx.A = SRP_Calc_A(s->srp_ctx.a, s->srp_ctx.N, s->srp_ctx.g)))
  406. return 0;
  407. return 1;
  408. }
  409. int SRP_Calc_A_param(SSL *s)
  410. {
  411. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  412. if (sc == NULL)
  413. return 0;
  414. return ssl_srp_calc_a_param_intern(sc);
  415. }
  416. BIGNUM *SSL_get_srp_g(SSL *s)
  417. {
  418. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  419. if (sc == NULL)
  420. return NULL;
  421. if (sc->srp_ctx.g != NULL)
  422. return sc->srp_ctx.g;
  423. return s->ctx->srp_ctx.g;
  424. }
  425. BIGNUM *SSL_get_srp_N(SSL *s)
  426. {
  427. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  428. if (sc == NULL)
  429. return NULL;
  430. if (sc->srp_ctx.N != NULL)
  431. return sc->srp_ctx.N;
  432. return s->ctx->srp_ctx.N;
  433. }
  434. char *SSL_get_srp_username(SSL *s)
  435. {
  436. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  437. if (sc == NULL)
  438. return NULL;
  439. if (sc->srp_ctx.login != NULL)
  440. return sc->srp_ctx.login;
  441. return s->ctx->srp_ctx.login;
  442. }
  443. char *SSL_get_srp_userinfo(SSL *s)
  444. {
  445. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
  446. if (sc == NULL)
  447. return NULL;
  448. if (sc->srp_ctx.info != NULL)
  449. return sc->srp_ctx.info;
  450. return s->ctx->srp_ctx.info;
  451. }
  452. # define tls1_ctx_ctrl ssl3_ctx_ctrl
  453. # define tls1_ctx_callback_ctrl ssl3_ctx_callback_ctrl
  454. int SSL_CTX_set_srp_username(SSL_CTX *ctx, char *name)
  455. {
  456. return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_USERNAME, 0, name);
  457. }
  458. int SSL_CTX_set_srp_password(SSL_CTX *ctx, char *password)
  459. {
  460. return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD, 0, password);
  461. }
  462. int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength)
  463. {
  464. return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH, strength,
  465. NULL);
  466. }
  467. int SSL_CTX_set_srp_verify_param_callback(SSL_CTX *ctx,
  468. int (*cb) (SSL *, void *))
  469. {
  470. return tls1_ctx_callback_ctrl(ctx, SSL_CTRL_SET_SRP_VERIFY_PARAM_CB,
  471. (void (*)(void))cb);
  472. }
  473. int SSL_CTX_set_srp_cb_arg(SSL_CTX *ctx, void *arg)
  474. {
  475. return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_SRP_ARG, 0, arg);
  476. }
  477. int SSL_CTX_set_srp_username_callback(SSL_CTX *ctx,
  478. int (*cb) (SSL *, int *, void *))
  479. {
  480. return tls1_ctx_callback_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB,
  481. (void (*)(void))cb);
  482. }
  483. int SSL_CTX_set_srp_client_pwd_callback(SSL_CTX *ctx,
  484. char *(*cb) (SSL *, void *))
  485. {
  486. return tls1_ctx_callback_ctrl(ctx, SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB,
  487. (void (*)(void))cb);
  488. }
  489. #endif