xref: /aosp_15_r20/external/cronet/crypto/nss_crypto_module_delegate.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2013 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
6*6777b538SAndroid Build Coastguard Worker #define CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <string>
9*6777b538SAndroid Build Coastguard Worker 
10*6777b538SAndroid Build Coastguard Worker #include "base/memory/ref_counted.h"
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker namespace crypto {
13*6777b538SAndroid Build Coastguard Worker 
14*6777b538SAndroid Build Coastguard Worker // PK11_SetPasswordFunc is a global setting.  An implementation of
15*6777b538SAndroid Build Coastguard Worker // CryptoModuleBlockingPasswordDelegate should be passed using wincx() as the
16*6777b538SAndroid Build Coastguard Worker // user data argument (|wincx|) to relevant NSS functions, which the global
17*6777b538SAndroid Build Coastguard Worker // password handler will call to do the actual work. This delegate should only
18*6777b538SAndroid Build Coastguard Worker // be used in NSS calls on worker threads due to the blocking nature.
19*6777b538SAndroid Build Coastguard Worker class CryptoModuleBlockingPasswordDelegate
20*6777b538SAndroid Build Coastguard Worker     : public base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate> {
21*6777b538SAndroid Build Coastguard Worker  public:
22*6777b538SAndroid Build Coastguard Worker 
23*6777b538SAndroid Build Coastguard Worker   // Return a value suitable for passing to the |wincx| argument of relevant NSS
24*6777b538SAndroid Build Coastguard Worker   // functions. This should be used instead of passing the object pointer
25*6777b538SAndroid Build Coastguard Worker   // directly to avoid accidentally casting a pointer to a subclass to void* and
26*6777b538SAndroid Build Coastguard Worker   // then casting back to a pointer of the base class
wincx()27*6777b538SAndroid Build Coastguard Worker   void* wincx() { return this; }
28*6777b538SAndroid Build Coastguard Worker 
29*6777b538SAndroid Build Coastguard Worker   // Requests a password to unlock |slot_name|. The interface is synchronous
30*6777b538SAndroid Build Coastguard Worker   // because NSS cannot issue an asynchronous request. |retry| is true if this
31*6777b538SAndroid Build Coastguard Worker   // is a request for the retry and we previously returned the wrong password.
32*6777b538SAndroid Build Coastguard Worker   // The implementation should set |*cancelled| to true if the user cancelled
33*6777b538SAndroid Build Coastguard Worker   // instead of entering a password, otherwise it should return the password the
34*6777b538SAndroid Build Coastguard Worker   // user entered.
35*6777b538SAndroid Build Coastguard Worker   virtual std::string RequestPassword(const std::string& slot_name, bool retry,
36*6777b538SAndroid Build Coastguard Worker                                       bool* cancelled) = 0;
37*6777b538SAndroid Build Coastguard Worker 
38*6777b538SAndroid Build Coastguard Worker  protected:
39*6777b538SAndroid Build Coastguard Worker   friend class base::RefCountedThreadSafe<CryptoModuleBlockingPasswordDelegate>;
40*6777b538SAndroid Build Coastguard Worker 
~CryptoModuleBlockingPasswordDelegate()41*6777b538SAndroid Build Coastguard Worker   virtual ~CryptoModuleBlockingPasswordDelegate() {}
42*6777b538SAndroid Build Coastguard Worker };
43*6777b538SAndroid Build Coastguard Worker 
44*6777b538SAndroid Build Coastguard Worker }  // namespace crypto
45*6777b538SAndroid Build Coastguard Worker 
46*6777b538SAndroid Build Coastguard Worker #endif  // CRYPTO_NSS_CRYPTO_MODULE_DELEGATE_H_
47