gosttest.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "ssltestlib.h"
  10. #include "testutil.h"
  11. #include "internal/nelem.h"
  12. static char *cert1 = NULL;
  13. static char *privkey1 = NULL;
  14. static char *cert2 = NULL;
  15. static char *privkey2 = NULL;
  16. static struct {
  17. char *cipher;
  18. int expected_prot;
  19. int certnum;
  20. } ciphers[] = {
  21. /* Server doesn't have a cert with appropriate sig algs - should fail */
  22. {"AES128-SHA", 0, 0},
  23. /* Server doesn't have a TLSv1.3 capable cert - should use TLSv1.2 */
  24. {"GOST2012-GOST8912-GOST8912", TLS1_2_VERSION, 0},
  25. /* Server doesn't have a TLSv1.3 capable cert - should use TLSv1.2 */
  26. {"GOST2012-GOST8912-GOST8912", TLS1_2_VERSION, 1},
  27. /* Server doesn't have a TLSv1.3 capable cert - should use TLSv1.2 */
  28. {"GOST2001-GOST89-GOST89", TLS1_2_VERSION, 0},
  29. };
  30. /* Test that we never negotiate TLSv1.3 if using GOST */
  31. static int test_tls13(int idx)
  32. {
  33. SSL_CTX *cctx = NULL, *sctx = NULL;
  34. SSL *clientssl = NULL, *serverssl = NULL;
  35. int testresult = 0;
  36. if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
  37. TLS_client_method(),
  38. TLS1_VERSION,
  39. TLS_MAX_VERSION,
  40. &sctx, &cctx,
  41. ciphers[idx].certnum == 0 ? cert1
  42. : cert2,
  43. ciphers[idx].certnum == 0 ? privkey1
  44. : privkey2)))
  45. goto end;
  46. if (!TEST_true(SSL_CTX_set_cipher_list(cctx, ciphers[idx].cipher))
  47. || !TEST_true(SSL_CTX_set_cipher_list(sctx, ciphers[idx].cipher))
  48. || !TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
  49. NULL, NULL)))
  50. goto end;
  51. if (ciphers[idx].expected_prot == 0) {
  52. if (!TEST_false(create_ssl_connection(serverssl, clientssl,
  53. SSL_ERROR_NONE)))
  54. goto end;
  55. } else {
  56. if (!TEST_true(create_ssl_connection(serverssl, clientssl,
  57. SSL_ERROR_NONE))
  58. || !TEST_int_eq(SSL_version(clientssl),
  59. ciphers[idx].expected_prot))
  60. goto end;
  61. }
  62. testresult = 1;
  63. end:
  64. SSL_free(serverssl);
  65. SSL_free(clientssl);
  66. SSL_CTX_free(sctx);
  67. SSL_CTX_free(cctx);
  68. return testresult;
  69. }
  70. int setup_tests(void)
  71. {
  72. if (!TEST_ptr(cert1 = test_get_argument(0))
  73. || !TEST_ptr(privkey1 = test_get_argument(1))
  74. || !TEST_ptr(cert2 = test_get_argument(2))
  75. || !TEST_ptr(privkey2 = test_get_argument(3)))
  76. return 0;
  77. ADD_ALL_TESTS(test_tls13, OSSL_NELEM(ciphers));
  78. return 1;
  79. }