2
0

ssl_ctx_test.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2018-2020 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 "testutil.h"
  10. #include <openssl/ssl.h>
  11. typedef struct {
  12. int min_version;
  13. int max_version;
  14. int min_ok;
  15. int max_ok;
  16. int expected_min;
  17. int expected_max;
  18. } version_test;
  19. static const version_test version_testdata[] = {
  20. /* min max ok expected min expected max */
  21. {0, 0, 1, 1, 0, 0},
  22. {TLS1_VERSION, TLS1_2_VERSION, 1, 1, TLS1_VERSION, TLS1_2_VERSION},
  23. {TLS1_2_VERSION, TLS1_2_VERSION, 1, 1, TLS1_2_VERSION, TLS1_2_VERSION},
  24. {TLS1_2_VERSION, TLS1_1_VERSION, 1, 1, TLS1_2_VERSION, TLS1_1_VERSION},
  25. {7, 42, 0, 0, 0, 0},
  26. };
  27. static int test_set_min_max_version(int idx_tst)
  28. {
  29. SSL_CTX *ctx = NULL;
  30. SSL *ssl = NULL;
  31. int testresult = 0;
  32. version_test t = version_testdata[idx_tst];
  33. ctx = SSL_CTX_new(TLS_server_method());
  34. if (ctx == NULL)
  35. goto end;
  36. ssl = SSL_new(ctx);
  37. if (ssl == NULL)
  38. goto end;
  39. if (!TEST_int_eq(SSL_CTX_set_min_proto_version(ctx, t.min_version), t.min_ok))
  40. goto end;
  41. if (!TEST_int_eq(SSL_CTX_set_max_proto_version(ctx, t.max_version), t.max_ok))
  42. goto end;
  43. if (!TEST_int_eq(SSL_CTX_get_min_proto_version(ctx), t.expected_min))
  44. goto end;
  45. if (!TEST_int_eq(SSL_CTX_get_max_proto_version(ctx), t.expected_max))
  46. goto end;
  47. if (!TEST_int_eq(SSL_set_min_proto_version(ssl, t.min_version), t.min_ok))
  48. goto end;
  49. if (!TEST_int_eq(SSL_set_max_proto_version(ssl, t.max_version), t.max_ok))
  50. goto end;
  51. if (!TEST_int_eq(SSL_get_min_proto_version(ssl), t.expected_min))
  52. goto end;
  53. if (!TEST_int_eq(SSL_get_max_proto_version(ssl), t.expected_max))
  54. goto end;
  55. testresult = 1;
  56. end:
  57. SSL_free(ssl);
  58. SSL_CTX_free(ctx);
  59. return testresult;
  60. }
  61. int setup_tests(void)
  62. {
  63. ADD_ALL_TESTS(test_set_min_max_version, sizeof(version_testdata) / sizeof(version_test));
  64. return 1;
  65. }