Skip to content

Commit

Permalink
[client/common] add c interface for retrieving certificate data
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-toterman committed May 31, 2023
1 parent 25cefba commit b1b1eb9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/multipass/cli/client_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ void post_setup();

// used by Flutter through Dart FFI
extern "C" const char* get_server_address();
extern "C" struct KeyCertificatePair get_cert_pair();

#endif // MULTIPASS_CLIENT_COMMON_H
8 changes: 8 additions & 0 deletions include/multipass/ssl_cert_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ class SSLCertProvider : public CertProvider
KeyCertificatePair key_cert_pair;
};
} // namespace multipass

// used by Flutter through Dart FFI
extern "C" struct KeyCertificatePair
{
const char* pem_cert;
const char* pem_cert_key;
};

#endif // MULTIPASS_SSL_CERT_PROVIDER_H
23 changes: 23 additions & 0 deletions src/client/common/client_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,26 @@ catch (...)
return nullptr;
}

extern "C" struct KeyCertificatePair get_cert_pair()
try
{

auto cert_provider = mp::client::get_cert_provider(mp::client::get_server_address());
auto cert = cert_provider->PEM_certificate();
auto key = cert_provider->PEM_signing_key();
struct KeyCertificatePair pair
{
.pem_cert = strdup(cert.c_str()), .pem_cert_key = strdup(key.c_str()),
};
return pair;
}
catch (const std::exception& e)
{
mpl::log(mpl::Level::error, "client", fmt::format("failed getting certificate pair: {}", e.what()));
return KeyCertificatePair{nullptr, nullptr};
}
catch (...)
{
mpl::log(mpl::Level::error, "client", "failed getting certificate pair");
return KeyCertificatePair{nullptr, nullptr};
}

0 comments on commit b1b1eb9

Please sign in to comment.