Verify certificates in SSL clients

This commit is contained in:
Vinnie Falco
2017-07-20 08:15:30 -07:00
parent 4b9acaaa6d
commit c01dddc4ac
5 changed files with 141 additions and 4 deletions
+11 -2
View File
@@ -5,6 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "../common/root_certificates.hpp"
#include <beast/core.hpp>
#include <beast/http.hpp>
#include <beast/version.hpp>
@@ -46,10 +48,17 @@ int main()
if(ec)
return fail("connect", ec);
// Create the required ssl context
ssl::context ctx{ssl::context::sslv23_client};
// This holds the root certificate used for verification
load_root_certificates(ctx, ec);
if(ec)
return fail("certificate", ec);
// Wrap the now-connected socket in an SSL stream
ssl::context ctx{ssl::context::sslv23};
ssl::stream<tcp::socket&> stream{sock, ctx};
stream.set_verify_mode(ssl::verify_none);
stream.set_verify_mode(ssl::verify_peer | ssl::verify_fail_if_no_peer_cert);
// Perform SSL handshaking
stream.handshake(ssl::stream_base::client, ec);