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.
5 #ifndef CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_WIN_H_
6 #define CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_WIN_H_
11 #include "base/basictypes.h"
12 #include "base/native_library.h"
13 #include "base/strings/string16.h"
15 // The following declarations of functions and types are from Firefox
18 // security/nss/lib/util/seccomon.h
19 // security/nss/lib/nss/nss.h
20 // The license block is:
22 /* ***** BEGIN LICENSE BLOCK *****
23 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
25 * The contents of this file are subject to the Mozilla Public License Version
26 * 1.1 (the "License"); you may not use this file except in compliance with
27 * the License. You may obtain a copy of the License at
28 * http://www.mozilla.org/MPL/
30 * Software distributed under the License is distributed on an "AS IS" basis,
31 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
32 * for the specific language governing rights and limitations under the
35 * The Original Code is the Netscape security libraries.
37 * The Initial Developer of the Original Code is
38 * Netscape Communications Corporation.
39 * Portions created by the Initial Developer are Copyright (C) 1994-2000
40 * the Initial Developer. All Rights Reserved.
44 * Alternatively, the contents of this file may be used under the terms of
45 * either the GNU General Public License Version 2 or later (the "GPL"), or
46 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
47 * in which case the provisions of the GPL or the LGPL are applicable instead
48 * of those above. If you wish to allow use of your version of this file only
49 * under the terms of either the GPL or the LGPL, and not to allow others to
50 * use your version of this file under the terms of the MPL, indicate your
51 * decision by deleting the provisions above and replace them with the notice
52 * and other provisions required by the GPL or the LGPL. If you do not delete
53 * the provisions above, a recipient may use your version of this file under
54 * the terms of any one of the MPL, the GPL or the LGPL.
56 * ***** END LICENSE BLOCK ***** */
60 siClearDataBuffer
= 1,
61 siCipherDataBuffer
= 2,
63 siEncodedCertBuffer
= 4,
65 siEncodedNameBuffer
= 6,
66 siAsciiNameString
= 7,
69 siUnsignedInteger
= 10,
71 siGeneralizedTime
= 12
90 typedef enum { PR_FAILURE
= -1, PR_SUCCESS
= 0 } PRStatus
;
92 typedef struct PK11SlotInfoStr PK11SlotInfo
;
94 typedef SECStatus (*NSSInitFunc
)(const char *configdir
);
95 typedef SECStatus (*NSSShutdownFunc
)(void);
96 typedef PK11SlotInfo
* (*PK11GetInternalKeySlotFunc
)(void);
97 typedef void (*PK11FreeSlotFunc
)(PK11SlotInfo
*slot
);
98 typedef SECStatus (*PK11CheckUserPasswordFunc
)(PK11SlotInfo
*slot
, char *pw
);
100 (*PK11AuthenticateFunc
)(PK11SlotInfo
*slot
, PRBool loadCerts
, void *wincx
);
102 (*PK11SDRDecryptFunc
)(SECItem
*data
, SECItem
*result
, void *cx
);
103 typedef void (*SECITEMFreeItemFunc
)(SECItem
*item
, PRBool free_it
);
104 typedef void (*PLArenaFinishFunc
)(void);
105 typedef PRStatus (*PRCleanupFunc
)(void);
107 struct FirefoxRawPasswordInfo
;
113 // A wrapper for Firefox NSS decrypt component.
119 // Loads NSS3 library and returns true if successful.
120 // |dll_path| indicates the location of NSS3 DLL files, and |db_path|
121 // is the location of the database file that stores the keys.
122 bool Init(const base::FilePath
& dll_path
, const base::FilePath
& db_path
);
124 // Frees the libraries.
127 // Decrypts Firefox stored passwords. Before using this method,
128 // make sure Init() returns true.
129 base::string16
Decrypt(const std::string
& crypt
) const;
131 // Parses the Firefox password file content, decrypts the
132 // username/password and reads other related information.
133 // The result will be stored in |forms|.
134 void ParseSignons(const base::FilePath
& signon_file
,
135 std::vector
<autofill::PasswordForm
>* forms
);
137 // Reads and parses the Firefox password sqlite db, decrypts the
138 // username/password and reads other related information.
139 // The result will be stored in |forms|.
140 bool ReadAndParseSignons(const base::FilePath
& sqlite_file
,
141 std::vector
<autofill::PasswordForm
>* forms
);
143 // Reads and parses the Firefox password file logins.json, decrypts the
144 // username/password and reads other related information.
145 // The result will be stored in |forms|.
146 bool ReadAndParseLogins(const base::FilePath
& json_file
,
147 std::vector
<autofill::PasswordForm
>* forms
);
150 // Call NSS initialization funcs.
151 bool InitNSS(const base::FilePath
& db_path
,
152 base::NativeLibrary plds4_dll
,
153 base::NativeLibrary nspr4_dll
);
155 PK11SlotInfo
* GetKeySlotForDB() const { return PK11_GetInternalKeySlot(); }
157 void FreeSlot(PK11SlotInfo
* slot
) const { PK11_FreeSlot(slot
); }
159 // Turns unprocessed information extracted from Firefox's password file
160 // into PasswordForm.
161 bool CreatePasswordFormFromRawInfo(
162 const FirefoxRawPasswordInfo
& raw_password_info
,
163 autofill::PasswordForm
* form
);
165 // Methods in Firefox security components.
166 NSSInitFunc NSS_Init
;
167 NSSShutdownFunc NSS_Shutdown
;
168 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot
;
169 PK11CheckUserPasswordFunc PK11_CheckUserPassword
;
170 PK11FreeSlotFunc PK11_FreeSlot
;
171 PK11AuthenticateFunc PK11_Authenticate
;
172 PK11SDRDecryptFunc PK11SDR_Decrypt
;
173 SECITEMFreeItemFunc SECITEM_FreeItem
;
174 PLArenaFinishFunc PL_ArenaFinish
;
175 PRCleanupFunc PR_Cleanup
;
177 // Libraries necessary for decrypting the passwords.
178 static const wchar_t kNSS3Library
[];
179 static const wchar_t kSoftokn3Library
[];
180 static const wchar_t kPLDS4Library
[];
181 static const wchar_t kNSPR4Library
[];
183 // NSS3 module handles.
184 base::NativeLibrary nss3_dll_
;
185 base::NativeLibrary softokn3_dll_
;
187 // True if NSS_Init() has been called
188 bool is_nss_initialized_
;
190 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor
);
193 #endif // CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_WIN_H_