2
0

gosttest.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. 0,
  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. OPT_TEST_DECLARE_USAGE("certfile1 privkeyfile1 certfile2 privkeyfile2\n")
  71. int setup_tests(void)
  72. {
  73. if (!TEST_ptr(cert1 = test_get_argument(0))
  74. || !TEST_ptr(privkey1 = test_get_argument(1))
  75. || !TEST_ptr(cert2 = test_get_argument(2))
  76. || !TEST_ptr(privkey2 = test_get_argument(3)))
  77. return 0;
  78. ADD_ALL_TESTS(test_tls13, OSSL_NELEM(ciphers));
  79. return 1;
  80. }