@@ -3251,6 +3251,61 @@ LT_BEGIN_AUTO_TEST(basic_suite, large_multipart_form_field)
32513251 ws2.stop();
32523252LT_END_AUTO_TEST (large_multipart_form_field)
32533253
3254+ #ifdef HAVE_GNUTLS
3255+ // Resource that tests client certificate methods on non-TLS requests
3256+ class client_cert_non_tls_resource : public http_resource {
3257+ public:
3258+ shared_ptr<http_response> render_GET (const http_request& req) {
3259+ std::string result;
3260+ // All these should return false/empty since this is not a TLS connection
3261+ result += " has_tls_session:" + std::string (req.has_tls_session () ? " yes" : " no" ) + " ;" ;
3262+ result += " has_client_cert:" + std::string (req.has_client_certificate () ? " yes" : " no" ) + " ;" ;
3263+ result += " dn:" + req.get_client_cert_dn () + " ;" ;
3264+ result += " issuer:" + req.get_client_cert_issuer_dn () + " ;" ;
3265+ result += " cn:" + req.get_client_cert_cn () + " ;" ;
3266+ result += " verified:" + std::string (req.is_client_cert_verified () ? " yes" : " no" ) + " ;" ;
3267+ result += " fingerprint:" + req.get_client_cert_fingerprint_sha256 () + " ;" ;
3268+ result += " not_before:" + std::to_string (req.get_client_cert_not_before ()) + " ;" ;
3269+ result += " not_after:" + std::to_string (req.get_client_cert_not_after ());
3270+ return std::make_shared<string_response>(result, 200 , " text/plain" );
3271+ }
3272+ };
3273+
3274+ // Test that client certificate methods return appropriate values for non-TLS requests
3275+ LT_BEGIN_AUTO_TEST (basic_suite, client_cert_methods_non_tls)
3276+ webserver ws = create_webserver(PORT + 79 );
3277+ client_cert_non_tls_resource ccnr;
3278+ ws.register_resource(" /cert_test" , &ccnr);
3279+ ws.start(false );
3280+
3281+ curl_global_init (CURL_GLOBAL_ALL);
3282+ std::string s;
3283+ CURL *curl = curl_easy_init();
3284+ CURLcode res;
3285+ std::string url = " http://localhost:" + std::to_string(PORT + 79 ) + " /cert_test" ;
3286+ curl_easy_setopt (curl, CURLOPT_URL, url.c_str());
3287+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
3288+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
3289+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
3290+ res = curl_easy_perform(curl);
3291+ LT_ASSERT_EQ (res, 0 );
3292+
3293+ // Verify all methods return false/empty for non-TLS
3294+ LT_CHECK_NEQ (s.find(" has_tls_session:no" ), std::string::npos);
3295+ LT_CHECK_NEQ (s.find(" has_client_cert:no" ), std::string::npos);
3296+ LT_CHECK_NEQ (s.find(" dn:;" ), std::string::npos);
3297+ LT_CHECK_NEQ (s.find(" issuer:;" ), std::string::npos);
3298+ LT_CHECK_NEQ (s.find(" cn:;" ), std::string::npos);
3299+ LT_CHECK_NEQ (s.find(" verified:no" ), std::string::npos);
3300+ LT_CHECK_NEQ (s.find(" fingerprint:;" ), std::string::npos);
3301+ LT_CHECK_NEQ (s.find(" not_before:-1" ), std::string::npos);
3302+ LT_CHECK_NEQ (s.find(" not_after:-1" ), std::string::npos);
3303+
3304+ curl_easy_cleanup (curl);
3305+ ws.stop();
3306+ LT_END_AUTO_TEST (client_cert_methods_non_tls)
3307+ #endif // HAVE_GNUTLS
3308+
32543309LT_BEGIN_AUTO_TEST_ENV ()
32553310 AUTORUN_TESTS()
32563311LT_END_AUTO_TEST_ENV()
0 commit comments