Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / utility / importer / nss_decryptor_mac.h
blob731f8ad1123588c46b916d4860d52255a333bf44
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_MAC_H_
6 #define CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_MAC_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
14 namespace base {
15 class FilePath;
18 // The following declarations of functions and types are from Firefox
19 // NSS library.
20 // source code:
21 // security/nss/lib/util/seccomon.h
22 // security/nss/lib/nss/nss.h
23 // The license block is:
25 /* ***** BEGIN LICENSE BLOCK *****
26 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
28 * The contents of this file are subject to the Mozilla Public License Version
29 * 1.1 (the "License"); you may not use this file except in compliance with
30 * the License. You may obtain a copy of the License at
31 * http://www.mozilla.org/MPL/
33 * Software distributed under the License is distributed on an "AS IS" basis,
34 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
35 * for the specific language governing rights and limitations under the
36 * License.
38 * The Original Code is the Netscape security libraries.
40 * The Initial Developer of the Original Code is
41 * Netscape Communications Corporation.
42 * Portions created by the Initial Developer are Copyright (C) 1994-2000
43 * the Initial Developer. All Rights Reserved.
45 * Contributor(s):
47 * Alternatively, the contents of this file may be used under the terms of
48 * either the GNU General Public License Version 2 or later (the "GPL"), or
49 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
50 * in which case the provisions of the GPL or the LGPL are applicable instead
51 * of those above. If you wish to allow use of your version of this file only
52 * under the terms of either the GPL or the LGPL, and not to allow others to
53 * use your version of this file under the terms of the MPL, indicate your
54 * decision by deleting the provisions above and replace them with the notice
55 * and other provisions required by the GPL or the LGPL. If you do not delete
56 * the provisions above, a recipient may use your version of this file under
57 * the terms of any one of the MPL, the GPL or the LGPL.
59 * ***** END LICENSE BLOCK ***** */
61 enum SECItemType {
62 siBuffer = 0,
63 siClearDataBuffer = 1,
64 siCipherDataBuffer = 2,
65 siDERCertBuffer = 3,
66 siEncodedCertBuffer = 4,
67 siDERNameBuffer = 5,
68 siEncodedNameBuffer = 6,
69 siAsciiNameString = 7,
70 siAsciiString = 8,
71 siDEROID = 9,
72 siUnsignedInteger = 10,
73 siUTCTime = 11,
74 siGeneralizedTime = 12
77 struct SECItem {
78 SECItemType type;
79 unsigned char *data;
80 unsigned int len;
83 enum SECStatus {
84 SECWouldBlock = -2,
85 SECFailure = -1,
86 SECSuccess = 0
89 typedef int PRBool;
90 #define PR_TRUE 1
91 #define PR_FALSE 0
93 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
95 typedef struct PK11SlotInfoStr PK11SlotInfo;
97 typedef SECStatus (*NSSInitFunc)(const char *configdir);
98 typedef SECStatus (*NSSShutdownFunc)(void);
99 typedef PK11SlotInfo* (*PK11GetInternalKeySlotFunc)(void);
100 typedef void (*PK11FreeSlotFunc)(PK11SlotInfo *slot);
101 typedef SECStatus (*PK11CheckUserPasswordFunc)(PK11SlotInfo *slot, char *pw);
102 typedef SECStatus
103 (*PK11AuthenticateFunc)(PK11SlotInfo *slot, PRBool loadCerts, void *wincx);
104 typedef SECStatus
105 (*PK11SDRDecryptFunc)(SECItem *data, SECItem *result, void *cx);
106 typedef void (*SECITEMFreeItemFunc)(SECItem *item, PRBool free_it);
107 typedef void (*PLArenaFinishFunc)(void);
108 typedef PRStatus (*PRCleanupFunc)(void);
110 struct FirefoxRawPasswordInfo;
112 namespace autofill {
113 struct PasswordForm;
116 // A wrapper for Firefox NSS decrypt component.
117 class NSSDecryptor {
118 public:
119 NSSDecryptor()
120 : NSS_Init(NULL), NSS_Shutdown(NULL), PK11_GetInternalKeySlot(NULL),
121 PK11_CheckUserPassword(NULL), PK11_FreeSlot(NULL),
122 PK11_Authenticate(NULL), PK11SDR_Decrypt(NULL), SECITEM_FreeItem(NULL),
123 is_nss_initialized_(false) {}
124 ~NSSDecryptor();
126 // Initializes NSS if it hasn't already been initialized.
127 bool Init(const base::FilePath& dll_path, const base::FilePath& db_path);
129 // Decrypts Firefox stored passwords. Before using this method,
130 // make sure Init() returns true.
131 base::string16 Decrypt(const std::string& crypt) const;
133 // Parses the Firefox password file content, decrypts the
134 // username/password and reads other related information.
135 // The result will be stored in |forms|.
136 void ParseSignons(const base::FilePath& signon_file,
137 std::vector<autofill::PasswordForm>* forms);
139 // Reads and parses the Firefox password sqlite db, decrypts the
140 // username/password and reads other related information.
141 // The result will be stored in |forms|.
142 bool ReadAndParseSignons(const base::FilePath& sqlite_file,
143 std::vector<autofill::PasswordForm>* forms);
145 // Reads and parses the Firefox password file logins.json, decrypts the
146 // username/password and reads other related information.
147 // The result will be stored in |forms|.
148 bool ReadAndParseLogins(const base::FilePath& json_file,
149 std::vector<autofill::PasswordForm>* forms);
151 private:
152 PK11SlotInfo* GetKeySlotForDB() const { return PK11_GetInternalKeySlot(); }
154 void FreeSlot(PK11SlotInfo* slot) const { PK11_FreeSlot(slot); }
156 // Turns unprocessed information extracted from Firefox's password file
157 // into PasswordForm.
158 bool CreatePasswordFormFromRawInfo(
159 const FirefoxRawPasswordInfo& raw_password_info,
160 autofill::PasswordForm* form);
162 // Methods in Firefox security components.
163 NSSInitFunc NSS_Init;
164 NSSShutdownFunc NSS_Shutdown;
165 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot;
166 PK11CheckUserPasswordFunc PK11_CheckUserPassword;
167 PK11FreeSlotFunc PK11_FreeSlot;
168 PK11AuthenticateFunc PK11_Authenticate;
169 PK11SDRDecryptFunc PK11SDR_Decrypt;
170 SECITEMFreeItemFunc SECITEM_FreeItem;
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_MAC_H_