| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <proton/ssl.h> |
| 21 |
|
| 22 |
#include "./pn_test.hpp" |
| 23 |
|
| 24 |
TEST_CASE("ssl_protocols") { |
| 25 |
if (!pn_ssl_present()) { |
| 26 |
WARN("SSL not available, skipping"); |
| 27 |
return; |
| 28 |
} |
| 29 |
pn_test::auto_free<pn_ssl_domain_t, pn_ssl_domain_free> sd( |
| 30 |
pn_ssl_domain(PN_SSL_MODE_CLIENT)); |
| 31 |
|
| 32 |
// Error no protocol set |
| 33 |
CHECK(pn_ssl_domain_set_protocols(sd, "") == PN_ARG_ERR); |
| 34 |
// Unknown protocol |
| 35 |
CHECK(pn_ssl_domain_set_protocols(sd, "blah") == PN_ARG_ERR); |
| 36 |
// Unknown protocol with known protocl prefix |
| 37 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1.x") == PN_ARG_ERR); |
| 38 |
|
| 39 |
// known protocols |
| 40 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1") == 0); |
| 41 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1.1") == 0); |
| 42 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1.2") == 0); |
| 43 |
|
| 44 |
// Check whether TLS 1.3 is supported |
| 45 |
bool tls1_3 = (pn_ssl_domain_set_protocols(sd, "TLSv1.3") == 0); |
| 46 |
|
| 47 |
// Multiple protocols |
| 48 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1 TLSv1.1 TLSv1.2") == 0); |
| 49 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1 TLSv1.1") == 0); |
| 50 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1.1 TLSv1.2") == 0); |
| 51 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1 TLSv1.2") == 0); |
| 52 |
|
| 53 |
// Can only do these if we have tls 1.3 |
| 54 |
if (tls1_3) { |
| 55 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3") == 0); |
| 56 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1.2 TLSv1.3") == 0); |
| 57 |
} else { |
| 58 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3") == PN_ARG_ERR); |
| 59 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1.2 TLSv1.3") == PN_ARG_ERR); |
| 60 |
} |
| 61 |
|
| 62 |
// Illegal separators |
| 63 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1/TLSv1.1 TLSv1.2") == PN_ARG_ERR); |
| 64 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1-TLSv1.1 TLSv1.2") == PN_ARG_ERR); |
| 65 |
|
| 66 |
// Legal separators |
| 67 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1,TLSv1.1;TLSv1.2 ; ") == 0); |
| 68 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1;TLSv1.1 TLSv1.2,,,,") == 0); |
| 69 |
|
| 70 |
// Known followed by unknown protocols |
| 71 |
CHECK(pn_ssl_domain_set_protocols(sd, "TLSv1 TLSv1.x;TLSv1_2") == PN_ARG_ERR); |
| 72 |
} |