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