@@ -42,11 +42,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
42
42
FAIL_IF(!(status & (flag)), (text));\
43
43
}
44
44
45
- #define CHECK_NO_TLS_FLAGS(m )\
45
+ #define CHECK_NO_TLS_FLAG(m, flag, text )\
46
46
{\
47
47
unsigned int status;\
48
48
mariadb_get_infov(mysql, MARIADB_TLS_VERIFY_STATUS, &status);\
49
- FAIL_IF(status), "Expected MARIADB_TLS_VERIFY_OK" );\
49
+ FAIL_IF(( status & (flag)), (text) );\
50
50
}
51
51
52
52
my_bool auto_generated_cert= 0;
@@ -141,7 +141,7 @@ static int test_start_tls_server(MYSQL *my __attribute__((unused)))
141
141
142
142
snprintf(hostname, sizeof(hostname), "--host=%s", tls_dummy_host);
143
143
snprintf(port, sizeof(port), "--port=%d", tls_dummy_port);
144
- execlp("@Python3_EXECUTABLE@", "@Python3_EXECUTABLE@", "tls_server.py", hostname, port, NULL);
144
+ execlp("@Python3_EXECUTABLE@", "@Python3_EXECUTABLE@", "@CC_SOURCE_DIR@/unittest/libmariadb/ tls_server.py", hostname, port, NULL);
145
145
}
146
146
147
147
#endif
@@ -658,11 +658,72 @@ static int stop_tls_server(MYSQL *my __attribute__((unused)))
658
658
return OK;
659
659
}
660
660
661
+ my_bool tls_wildcard_callback(MYSQL *mysql, unsigned int *flags, my_bool verified)
662
+ {
663
+ if (!verified)
664
+ {
665
+ free(mysql->host);
666
+ mysql->host= strdup("test.example.com");
667
+ *flags= MARIADB_TLS_VERIFY_HOST;
668
+ return 0;
669
+ }
670
+ /* Indicate error, since the dummy server can't handle further client server
671
+ communication after TLS handshake */
672
+ mysql->net.tls_verify_status|= MARIADB_TLS_VERIFY_ERROR;
673
+ my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN,
674
+ ER(CR_SSL_CONNECTION_ERROR),
675
+ "Certificate verification aborted by callback");
676
+ return 1;
677
+ }
678
+
679
+ static int test_cert_wildcard(MYSQL *my __attribute((unused)))
680
+ {
681
+ MYSQL *mysql= mysql_init(NULL);
682
+ if (set_tls_dummy_options("CMD:create_new=True commonName='*.example.com'"))
683
+ {
684
+ diag("Error when setting TLS options");
685
+ return FAIL;
686
+ }
687
+ mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL);
688
+ mysql_optionsv(mysql, MARIADB_OPT_TLS_VERIFICATION_CALLBACK, tls_wildcard_callback);
689
+
690
+ if (!my_test_connect(mysql, tls_dummy_host, "tlsuser", "foo", NULL, tls_dummy_port, NULL, 0, 0))
691
+ {
692
+ CHECK_NO_TLS_FLAG(mysql, MARIADB_TLS_VERIFY_HOST, "Hostname verification didn't pass");
693
+ CHECK_TLS_FLAGS(mysql, MARIADB_TLS_VERIFY_TRUST, "Self signed certificate expected");
694
+ mysql_close(mysql);
695
+ } else {
696
+ mysql_close(mysql);
697
+ return FAIL;
698
+ }
699
+
700
+ mysql= mysql_init(NULL);
701
+ if (set_tls_dummy_options("CMD:create_new=True commonName='*.noexample.com'"))
702
+ {
703
+ diag("Error when setting TLS options");
704
+ return FAIL;
705
+ }
706
+ mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL);
707
+ mysql_optionsv(mysql, MARIADB_OPT_TLS_VERIFICATION_CALLBACK, tls_wildcard_callback);
708
+
709
+ if (!my_test_connect(mysql, tls_dummy_host, "tlsuser", "foo", NULL, tls_dummy_port, NULL, 0, 0))
710
+ {
711
+ CHECK_TLS_FLAGS(mysql, MARIADB_TLS_VERIFY_HOST, "Hostname verification passed with wrong wildcard");
712
+ mysql_close(mysql);
713
+ } else {
714
+ mysql_close(mysql);
715
+ return FAIL;
716
+ }
717
+ return OK;
718
+ }
719
+
720
+
661
721
struct my_tests_st my_tests[] = {
662
722
/* Don't add test above, test_init needs to be run first */
663
723
{"test_start_tls_server", test_start_tls_server, TEST_CONNECTION_NONE, 0, NULL, NULL},
664
724
{"test_init", test_init, TEST_CONNECTION_NONE, 0, NULL, NULL},
665
725
/* Here you can add more tests */
726
+ {"test_cert_wildcard", test_cert_wildcard, TEST_CONNECTION_NEW, 0, NULL, NULL},
666
727
{"test_cert_expired", test_cert_expired, TEST_CONNECTION_NEW, 0, NULL, NULL},
667
728
{"test_pw_check", test_pw_check, TEST_CONNECTION_NEW, 0, NULL, NULL},
668
729
{"test_ca_cert_check", test_ca_cert_check, TEST_CONNECTION_NONE, 0, NULL, NULL},
0 commit comments