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_
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
18 // The following declarations of functions and types are from Firefox
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
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.
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 ***** */
63 siClearDataBuffer
= 1,
64 siCipherDataBuffer
= 2,
66 siEncodedCertBuffer
= 4,
68 siEncodedNameBuffer
= 6,
69 siAsciiNameString
= 7,
72 siUnsignedInteger
= 10,
74 siGeneralizedTime
= 12
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
);
103 (*PK11AuthenticateFunc
)(PK11SlotInfo
*slot
, PRBool loadCerts
, void *wincx
);
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);
114 // A wrapper for Firefox NSS decrypt component.
118 : NSS_Init(NULL
), NSS_Shutdown(NULL
), PK11_GetInternalKeySlot(NULL
),
119 PK11_CheckUserPassword(NULL
), PK11_FreeSlot(NULL
),
120 PK11_Authenticate(NULL
), PK11SDR_Decrypt(NULL
), SECITEM_FreeItem(NULL
),
121 is_nss_initialized_(false) {}
124 // Initializes NSS if it hasn't already been initialized.
125 bool Init(const base::FilePath
& dll_path
, const base::FilePath
& db_path
);
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 std::string
& content
,
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 PK11SlotInfo
* GetKeySlotForDB() const { return PK11_GetInternalKeySlot(); }
144 void FreeSlot(PK11SlotInfo
* slot
) const { PK11_FreeSlot(slot
); }
146 // Methods in Firefox security components.
147 NSSInitFunc NSS_Init
;
148 NSSShutdownFunc NSS_Shutdown
;
149 PK11GetInternalKeySlotFunc PK11_GetInternalKeySlot
;
150 PK11CheckUserPasswordFunc PK11_CheckUserPassword
;
151 PK11FreeSlotFunc PK11_FreeSlot
;
152 PK11AuthenticateFunc PK11_Authenticate
;
153 PK11SDRDecryptFunc PK11SDR_Decrypt
;
154 SECITEMFreeItemFunc SECITEM_FreeItem
;
156 // True if NSS_Init() has been called
157 bool is_nss_initialized_
;
159 DISALLOW_COPY_AND_ASSIGN(NSSDecryptor
);
162 #endif // CHROME_UTILITY_IMPORTER_NSS_DECRYPTOR_MAC_H_