feat(GODT-2771): gRPC calls for TLS certificates.

This commit is contained in:
Xavier Michelon
2023-08-17 10:22:56 +02:00
parent 2d6f42e0b5
commit f57a40677e
14 changed files with 1578 additions and 1073 deletions

View File

@ -278,6 +278,28 @@ void QMLBackend::clearAnswers() {
}
//****************************************************************************************************************************************************
/// \return true iff the Bridge TLS certificate is installed.
//****************************************************************************************************************************************************
bool QMLBackend::isTLSCertificateInstalled() {
HANDLE_EXCEPTION_RETURN_BOOL(
bool v = false;
app().grpc().isTLSCertificateInstalled(v);
return v;
)
}
//****************************************************************************************************************************************************
//
//****************************************************************************************************************************************************
void QMLBackend::installTLSCertificate() {
HANDLE_EXCEPTION(
app().grpc().installTLSCertificate();
)
}
//****************************************************************************************************************************************************
/// \return The value for the 'showOnStartup' property.
//****************************************************************************************************************************************************
@ -1267,6 +1289,9 @@ void QMLBackend::connectGrpcEvents() {
connect(client, &GRPCClient::reportBugSuccess, this, &QMLBackend::bugReportSendSuccess);
connect(client, &GRPCClient::reportBugFallback, this, &QMLBackend::bugReportSendFallback);
connect(client, &GRPCClient::reportBugError, this, &QMLBackend::bugReportSendError);
connect(client, &GRPCClient::certificateInstallSuccess, this, &QMLBackend::certificateInstallSuccess);
connect(client, &GRPCClient::certificateInstallCanceled, this, &QMLBackend::certificateInstallCanceled);
connect(client, &GRPCClient::certificateInstallFailed, this, &QMLBackend::certificateInstallFailed);
connect(client, &GRPCClient::showMainWindow, [&]() { this->showMainWindow("gRPC showMainWindow event"); });
// cache events

View File

@ -64,6 +64,8 @@ public: // member functions.
Q_INVOKABLE QString getQuestionAnswer(quint8 questionId) const; ///< Get the answer for a given question.
Q_INVOKABLE QString collectAnswers(quint8 categoryId) const; ///< Collect answer for a given set of questions.
Q_INVOKABLE void clearAnswers(); ///< Clear all collected answers.
Q_INVOKABLE bool isTLSCertificateInstalled(); ///< Check if the bridge certificate is installed in the OS keychain.
Q_INVOKABLE void installTLSCertificate(); ///< Installs the Bridge TLS certificate in the Keychain.
public: // Qt/QML properties. Note that the NOTIFY-er signal is required even for read-only properties (QML warning otherwise)
Q_PROPERTY(bool showOnStartup READ showOnStartup NOTIFY showOnStartupChanged)
@ -268,6 +270,9 @@ signals: // Signals received from the Go backend, to be forwarded to QML
void bugReportSendSuccess(); ///< Signal for the 'bugReportSendSuccess' gRPC stream event.
void bugReportSendFallback(); ///< Signal for the 'bugReportSendFallback' gRPC stream event.
void bugReportSendError(); ///< Signal for the 'bugReportSendError' gRPC stream event.
void certificateInstallSuccess(); ///< Signal for the 'certificateInstallSuccess' gRPC stream event.
void certificateInstallCanceled(); ///< Signal for the 'certificateInstallCanceled' gRPC stream event.
void certificateInstallFailed(); /// Signal for the 'certificateInstallFailed' gRPC stream event.
void showMainWindow(); ///< Signal for the 'showMainWindow' gRPC stream event.
void hideMainWindow(); ///< Signal for the 'hideMainWindow' gRPC stream event.
void showHelp(); ///< Signal for the 'showHelp' event (from the context menu).

View File

@ -202,6 +202,39 @@ SPStreamEvent newReportBugErrorEvent() {
}
//****************************************************************************************************************************************************
/// \return The event.
//****************************************************************************************************************************************************
SPStreamEvent newCertificateInstallSuccessEvent() {
auto event = new grpc::CertificateInstallSuccessEvent;
auto appEvent = new grpc::AppEvent;
appEvent->set_allocated_certificateinstallsuccess(event);
return wrapAppEvent(appEvent);
}
//****************************************************************************************************************************************************
/// \return The event.
//****************************************************************************************************************************************************
SPStreamEvent newCertificateInstallCanceledEvent() {
auto event = new grpc::CertificateInstallCanceledEvent;
auto appEvent = new grpc::AppEvent;
appEvent->set_allocated_certificateinstallcanceled(event);
return wrapAppEvent(appEvent);
}
//****************************************************************************************************************************************************
/// \return The event.
//****************************************************************************************************************************************************
SPStreamEvent newCertificateInstallFailedEvent() {
auto event = new grpc::CertificateInstallFailedEvent;
auto appEvent = new grpc::AppEvent;
appEvent->set_allocated_certificateinstallfailed(event);
return wrapAppEvent(appEvent);
}
//****************************************************************************************************************************************************
/// \return The event.
//****************************************************************************************************************************************************

View File

@ -34,6 +34,9 @@ SPStreamEvent newResetFinishedEvent(); ///< Create a new ResetFinishedEvent even
SPStreamEvent newReportBugFinishedEvent(); ///< Create a new ReportBugFinishedEvent event.
SPStreamEvent newReportBugSuccessEvent(); ///< Create a new ReportBugSuccessEvent event.
SPStreamEvent newReportBugErrorEvent(); ///< Create a new ReportBugErrorEvent event.
SPStreamEvent newCertificateInstallSuccessEvent(); ///< Create a new CertificateInstallSuccessEvent event.
SPStreamEvent newCertificateInstallCanceledEvent(); ///< Create a new CertificateInstallCanceledEvent event.
SPStreamEvent newCertificateInstallFailedEvent(); ///< Create anew CertificateInstallFailedEvent event.
SPStreamEvent newShowMainWindowEvent(); ///< Create a new ShowMainWindowEvent event.
// Login events

View File

@ -373,14 +373,6 @@ grpc::Status GRPCClient::reportBug(QString const &category, QString const &descr
}
//****************************************************************************************************************************************************
/// \param[in] folderPath of the folder where the TLS files should be stored.
//****************************************************************************************************************************************************
grpc::Status GRPCClient::exportTLSCertificates(QString const &folderPath) {
return this->logGRPCCallStatus(this->setString(&Bridge::Stub::ExportTLSCertificates, folderPath), __FUNCTION__);
}
//****************************************************************************************************************************************************
/// \param[out] outIMAPPort The IMAP port.
/// \param[out] outSMTPPort The SMTP port.
@ -811,6 +803,32 @@ grpc::Status GRPCClient::setCurrentKeychain(QString const &keychain) {
}
//****************************************************************************************************************************************************
/// \param[out] isInstalled is The Bridge certificate installed in the keychain.
/// \return The status for the call
//****************************************************************************************************************************************************
grpc::Status GRPCClient::isTLSCertificateInstalled(bool isInstalled) {
return this->logGRPCCallStatus(this->getBool(&Bridge::Stub::IsTLSCertificateInstalled, isInstalled), __FUNCTION__);
}
//****************************************************************************************************************************************************
/// \return The status for the gRPC call.
//****************************************************************************************************************************************************
grpc::Status GRPCClient::installTLSCertificate() {
return this->logGRPCCallStatus(this->simpleMethod(&Bridge::Stub::InstallTLSCertificate), __FUNCTION__);
}
//****************************************************************************************************************************************************
/// \param[in] folderPath of the folder where the TLS files should be stored.
/// \return The status for the gRPC call.
//****************************************************************************************************************************************************
grpc::Status GRPCClient::exportTLSCertificates(QString const &folderPath) {
return this->logGRPCCallStatus(this->setString(&Bridge::Stub::ExportTLSCertificates, folderPath), __FUNCTION__);
}
//****************************************************************************************************************************************************
/// \return true iff the event stream is active.
//****************************************************************************************************************************************************
@ -1134,6 +1152,18 @@ void GRPCClient::processAppEvent(AppEvent const &event) {
this->logTrace("App event received: ReportBugFallback.");
emit reportBugFallback();
break;
case AppEvent::kCertificateInstallSuccess:
this->logTrace("App event received: CertificateInstallSuccess.");
emit certificateInstallSuccess();
break;
case AppEvent::kCertificateInstallCanceled:
this->logTrace("App event received: CertificateInstallCanceled.");
emit certificateInstallCanceled();
break;
case AppEvent::kCertificateInstallFailed:
this->logTrace("App event received: CertificateInstallFailed.");
emit certificateInstallFailed();
break;
default:
this->logError("Unknown App event received.");
}
@ -1517,4 +1547,5 @@ grpc::Status GRPCClient::KBArticleClicked(QString const &article) {
return this->logGRPCCallStatus(stub_->KBArticleClicked(this->clientContext().get(), s, &empty), __FUNCTION__);
}
} // namespace bridgepp

View File

@ -78,7 +78,6 @@ public: // member functions.
grpc::Status setColorSchemeName(QString const &name); ///< Performs the "setColorSchemeName' gRPC call.
grpc::Status currentEmailClient(QString &outName); ///< Performs the 'currentEmailClient' gRPC call.
grpc::Status reportBug(QString const &category, QString const &description, QString const &address, QString const &emailClient, bool includeLogs); ///< Performs the 'ReportBug' gRPC call.
grpc::Status exportTLSCertificates(QString const &folderPath); ///< Performs the 'ExportTLSCertificates' gRPC call.
grpc::Status quit(); ///< Perform the "Quit" gRPC call.
grpc::Status restart(); ///< Performs the Restart gRPC call.
grpc::Status triggerReset(); ///< Performs the triggerReset gRPC call.
@ -103,6 +102,9 @@ signals: // app related signals
void reportBugSuccess();
void reportBugError();
void reportBugFallback();
void certificateInstallSuccess();
void certificateInstallCanceled();
void certificateInstallFailed();
void showMainWindow();
// cache related calls
@ -201,6 +203,11 @@ public: // keychain related calls
grpc::Status currentKeychain(QString &outKeychain);
grpc::Status setCurrentKeychain(QString const &keychain);
public: // cert related calls
grpc::Status isTLSCertificateInstalled(bool isInstalled); ///< Perform the 'IsTLSCertificateInstalled' gRPC call.
grpc::Status installTLSCertificate(); ///< Perform the 'InstallTLSCertificate' gRPC call.
grpc::Status exportTLSCertificates(QString const &folderPath); ///< Performs the 'ExportTLSCertificates' gRPC call.
signals:
void changeKeychainFinished();
void hasNoKeychain();