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