1 // Copyright (c) 2011 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 CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_SYSTEM_NSS_H_ 6 #define CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_SYSTEM_NSS_H_ 7 8 #include <secmodt.h> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/strings/string16.h" 14 15 namespace base { 16 class FilePath; 17 } 18 19 namespace content { 20 struct PasswordForm; 21 } 22 23 // A wrapper for Firefox NSS decrypt component. 24 class NSSDecryptor { 25 public: 26 NSSDecryptor(); 27 ~NSSDecryptor(); 28 29 // Initializes NSS if it hasn't already been initialized. 30 bool Init(const base::FilePath& dll_path, const base::FilePath& db_path); 31 32 // Decrypts Firefox stored passwords. Before using this method, 33 // make sure Init() returns true. 34 string16 Decrypt(const std::string& crypt) const; 35 36 // Parses the Firefox password file content, decrypts the 37 // username/password and reads other related information. 38 // The result will be stored in |forms|. 39 void ParseSignons(const std::string& content, 40 std::vector<content::PasswordForm>* forms); 41 42 // Reads and parses the Firefox password sqlite db, decrypts the 43 // username/password and reads other related information. 44 // The result will be stored in |forms|. 45 bool ReadAndParseSignons(const base::FilePath& sqlite_file, 46 std::vector<content::PasswordForm>* forms); 47 private: 48 // Does not actually free the slot, since we'll free it when NSSDecryptor is 49 // destroyed. 50 void FreeSlot(PK11SlotInfo* slot) const {} 51 PK11SlotInfo* GetKeySlotForDB() const { return db_slot_; } 52 53 SECStatus PK11SDR_DecryptWithSlot( 54 PK11SlotInfo* slot, SECItem* data, SECItem* result, void* cx) const; 55 56 bool is_nss_initialized_; 57 PK11SlotInfo* db_slot_; 58 59 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor); 60 }; 61 62 #endif // CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_SYSTEM_NSS_H_ 63