electron/shell/browser/electron_crypto_module_delegate_nss.h
arno renevier 81bdba67ec
feat: Implement password delegate for NSS (#41205)
* feat: Implement password delegate for NSS (#41188)

Introduce an app event client-certificate-request-password. It allows
the user to display a UI to prompt for the password.

An alternative would have been to implement a class similar to
CryptoModulePasswordDialogView, to provide the UI. This might have been
simpler for the user, comparing to letting them implement the UI. But it
seems like electron does not have an i18n framework, so it's not
possible to provide a locale aware UI.

* fix lint:markdown error

* address review comments

* use a trampoline handler in JS. The api exposed is now app.setClientCertRequestPasswordHandler
* use properties on the Event object instead of positional parameters
* remove ChromeNSSCryptoModuleDelegate::OnPassword in favor of args->GetNext(&password_)

* address review comments second round

- backslash escape parametrized TypeScript
- rename hostName param to hostname
- use base::ScopedAllowBaseSyncPrimitivesForTesting
- and then, rename ChromeNSSCryptoModuleDelegate to ElectronNSSCryptoModuleDelegate

* Update docs/api/app.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/app.md

Co-authored-by: Erick Zhao <erick@hotmail.ca>

---------

Co-authored-by: Arno Renevier <arnaud@switchboard.app>
Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>
Co-authored-by: Erick Zhao <erick@hotmail.ca>
2024-07-17 09:48:03 -04:00

43 lines
1.4 KiB
C++

// Copyright (c) 2024 Switchboard
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_CRYPTO_MODULE_DELEGATE_NSS_H_
#define ELECTRON_SHELL_CRYPTO_MODULE_DELEGATE_NSS_H_
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread_restrictions.h"
#include "crypto/nss_crypto_module_delegate.h"
#include "net/base/host_port_pair.h"
namespace gin {
class Arguments;
}
class ElectronNSSCryptoModuleDelegate
: public crypto::CryptoModuleBlockingPasswordDelegate {
public:
explicit ElectronNSSCryptoModuleDelegate(const net::HostPortPair& server);
ElectronNSSCryptoModuleDelegate(const ElectronNSSCryptoModuleDelegate&) =
delete;
ElectronNSSCryptoModuleDelegate& operator=(
const ElectronNSSCryptoModuleDelegate&) = delete;
std::string RequestPassword(const std::string& token_name,
bool retry,
bool* cancelled) override;
private:
friend class base::RefCountedThreadSafe<ElectronNSSCryptoModuleDelegate>;
~ElectronNSSCryptoModuleDelegate() override;
void RequestPasswordOnUIThread(const std::string& token_name, bool retry);
void OnPassword(gin::Arguments* args);
net::HostPortPair server_;
base::WaitableEvent event_;
std::string password_;
bool cancelled_ = false;
};
#endif // ELECTRON_SHELL_CRYPTO_MODULE_DELEGATE_NSS_H_