Skip to content
Snippets Groups Projects
Verified Commit bb4cff3b authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: ssl

parent cee90bed
No related branches found
No related tags found
No related merge requests found
Pipeline #9846 passed
Pipeline: caosdb-cppinttest

#9847

    ......@@ -35,6 +35,7 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
    ###########################################
    ### DEPENDENCY MANAGEMENT with CONAN
    ###########################################
    message(STATUS "Build directory ${CMAKE_BINARY_DIR}")
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
    ......@@ -53,10 +54,15 @@ add_executable(caosdbcli src/caosdbcli.cpp)
    ### LINTING with CLANG-TIDY and INCLUDE-WHAT-YOU-USE
    #######################################################
    # linting is active when BUILD_TYPE == "Debug"
    if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
    option(LINTING "Enable linting with clang-tidy and iwyu when in non-Debug build-type" OFF)
    if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" OR LINTING)
    set(_LINTING ON)
    endif()
    option(SKIP_LINTING "Skip linting even when in Debug build-type" OFF)
    if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" AND SKIP_LINTING)
    message(WARNING "Skipping linting due to SKIP_LINTING option")
    set(_LINTING OFF)
    endif()
    if(_LINTING)
    find_program(iwyu
    NAMES include-what-you-use iwyu
    ......
    ......@@ -110,6 +110,7 @@ public:
    class SslCaosDBConnectionConfig : public CaosDBConnectionConfig {
    private:
    std::shared_ptr<ChannelCredentials> credentials;
    std::string cacert;
    public:
    SslCaosDBConnectionConfig(
    ......@@ -128,6 +129,7 @@ public:
    * @brief A reusable connection to a CaosDBServer.
    */
    class CaosDBConnection {
    std::shared_ptr<grpc::Channel> channel;
    std::shared_ptr<CaosDBConnectionConfig> config;
    std::unique_ptr<GeneralInfoService::Stub> stub_;
    ......
    ......@@ -115,6 +115,7 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(
    : CaosDBConnectionConfig(host, port) {
    SslCredentialsOptions options;
    options.pem_root_certs = cacert->getCACertPem();
    this->cacert = cacert->getCACertPem();
    this->credentials = SslCredentials(options);
    }
    ......@@ -126,6 +127,7 @@ SslCaosDBConnectionConfig::SslCaosDBConnectionConfig(
    SslCredentialsOptions options;
    options.pem_root_certs = cacert->getCACertPem();
    this->cacert = cacert->getCACertPem();
    this->credentials = grpc::CompositeChannelCredentials(
    SslCredentials(options), authenticator->getCallCredentials());
    }
    ......@@ -137,7 +139,7 @@ auto SslCaosDBConnectionConfig::getChannelCredentials() const
    auto SslCaosDBConnectionConfig::toString() const -> std::string {
    return "SslCaosDBConnectionConfig(" + this->getHost() + "," +
    std::to_string(this->getPort()) + ")";
    std::to_string(this->getPort()) + "," + this->cacert + ")";
    }
    CaosDBConnection::CaosDBConnection(
    ......@@ -145,9 +147,9 @@ CaosDBConnection::CaosDBConnection(
    this->config = config;
    const std::string target =
    this->config->getHost() + ":" + std::to_string(this->config->getPort());
    const std::shared_ptr<grpc::Channel> &channel =
    this->channel =
    grpc::CreateChannel(target, this->config->getChannelCredentials());
    this->stub_ = GeneralInfoService::NewStub(channel);
    this->stub_ = GeneralInfoService::NewStub(this->channel);
    }
    auto operator<<(std::ostream &out, const CaosDBConnection &connection)
    ......@@ -162,7 +164,7 @@ auto operator<<(std::ostream &out, const CaosDBConnection &connection)
    GetVersionInfoResponse response;
    grpc::ClientContext context;
    const grpc::Status status =
    stub_->GetVersionInfo(&context, request, &response);
    this->stub_->GetVersionInfo(&context, request, &response);
    if (!status.ok()) {
    switch (status.error_code()) {
    ......
    ......@@ -49,6 +49,7 @@ auto main() -> int {
    std::cout << "USER: " << user << "\n";
    std::cout << "PORT: " << port_str << "\n";
    std::cout << "HOST: " << host << "\n";
    std::cout << "CACERT: " << pem_file << "\n";
    auto auth =
    std::make_shared<caosdb::authentication::PlainPasswordAuthenticator>(
    ......
    ......@@ -28,9 +28,9 @@
    #include <boost/beast/core/detail/base64.hpp>
    TEST(test_utils, base64_encode) {
    auto test_plain = std::string("Test");
    auto test_encoded = std::string("VGVzdA==");
    ASSERT_EQ(4, test_plain.size());
    ASSERT_EQ(8, boost::beast::detail::base64::encoded_size(test_plain.size()));
    auto test_plain = std::string("admin:caosdb");
    auto test_encoded = std::string("YWRtaW46Y2Fvc2Ri");
    ASSERT_EQ(12, test_plain.size());
    ASSERT_EQ(16, boost::beast::detail::base64::encoded_size(test_plain.size()));
    ASSERT_EQ(test_encoded, caosdb::utils::base64_encode(test_plain));
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment