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