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);
111 // A wrapper for Firefox NSS decrypt component.
117 // Loads NSS3 library and returns true if successful.
118 // |dll_path| indicates the location of NSS3 DLL files, and |db_path|
119 // is the location of the database file that stores the keys.
120 bool Init(const base::FilePath
& dll_path
, const base::FilePath
& db_path
);
122 // Frees the libraries.
125 // Decrypts Firefox stored passwords. Before using this method,
126 // make sure Init() returns true.
127 base::string16
Decrypt(const std::string
& crypt
) const;
129 // Parses the Firefox password file content, decrypts the
130 // username/password and reads other related information.
131 // The result will be stored in |forms|.
132 void ParseSignons(const std::string
& content
,
133 std::vector
<autofill::PasswordForm
>* forms
);
135 // Reads and parses the Firefox password sqlite db, decrypts the
136 // username/password and reads other related information.
137 // The result will be stored in |forms|.
138 bool ReadAndParseSignons(const base::FilePath
& sqlite_file
,
139 std::vector
<autofill::PasswordForm
>* forms
);
142 // Call NSS initialization funcs.
143 bool InitNSS(const base::FilePath
& db_path
,
144 base::NativeLibrary plds4_dll
,
145 base::NativeLibrary nspr4_dll
);
147 PK11SlotInfo
* GetKeySlotForDB() const { return PK11_GetInternalKeySlot(); }
148 void FreeSlot(PK11SlotInfo
* slot
) const { PK11_FreeSlot(slot
); }
150 // Methods in Firefox security components.
151 NSSInitFunc NSS_Init
;
152 NSSShutdownFunc NSS_Shutdown
;
153 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot
;
154 PK11CheckUserPasswordFunc PK11_CheckUserPassword
;
155 PK11FreeSlotFunc PK11_FreeSlot
;
156 PK11AuthenticateFunc PK11_Authenticate
;
157 PK11SDRDecryptFunc PK11SDR_Decrypt
;
158 SECITEMFreeItemFunc SECITEM_FreeItem
;
159 PLArenaFinishFunc PL_ArenaFinish
;
160 PRCleanupFunc PR_Cleanup
;
162 // Libraries necessary for decrypting the passwords.
163 static const wchar_t kNSS3Library
[];
164 static const wchar_t kSoftokn3Library
[];
165 static const wchar_t kPLDS4Library
[];
166 static const wchar_t kNSPR4Library
[];
168 // NSS3 module handles.
169 base::NativeLibrary nss3_dll_
;
170 base::NativeLibrary softokn3_dll_
;
172 // True if NSS_Init() has been called
173 bool is_nss_initialized_
;
175 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor
);
178 #endif // CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_WIN_H_