OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/utility/importer/nss_decryptor.h" | 5 #include "chrome/utility/importer/nss_decryptor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 * of those above. If you wish to allow use of your version of this file only | 54 * of those above. If you wish to allow use of your version of this file only |
55 * under the terms of either the GPL or the LGPL, and not to allow others to | 55 * under the terms of either the GPL or the LGPL, and not to allow others to |
56 * use your version of this file under the terms of the MPL, indicate your | 56 * use your version of this file under the terms of the MPL, indicate your |
57 * decision by deleting the provisions above and replace them with the notice | 57 * decision by deleting the provisions above and replace them with the notice |
58 * and other provisions required by the GPL or the LGPL. If you do not delete | 58 * and other provisions required by the GPL or the LGPL. If you do not delete |
59 * the provisions above, a recipient may use your version of this file under | 59 * the provisions above, a recipient may use your version of this file under |
60 * the terms of any one of the MPL, the GPL or the LGPL. | 60 * the terms of any one of the MPL, the GPL or the LGPL. |
61 * | 61 * |
62 * ***** END LICENSE BLOCK ***** */ | 62 * ***** END LICENSE BLOCK ***** */ |
63 | 63 |
64 string16 NSSDecryptor::Decrypt(const std::string& crypt) const { | 64 base::string16 NSSDecryptor::Decrypt(const std::string& crypt) const { |
65 // Do nothing if NSS is not loaded. | 65 // Do nothing if NSS is not loaded. |
66 if (!is_nss_initialized_) | 66 if (!is_nss_initialized_) |
67 return string16(); | 67 return base::string16(); |
68 | 68 |
69 // The old style password is encoded in base64. They are identified | 69 // The old style password is encoded in base64. They are identified |
70 // by a leading '~'. Otherwise, we should decrypt the text. | 70 // by a leading '~'. Otherwise, we should decrypt the text. |
71 std::string plain; | 71 std::string plain; |
72 if (crypt[0] != '~') { | 72 if (crypt[0] != '~') { |
73 std::string decoded_data; | 73 std::string decoded_data; |
74 base::Base64Decode(crypt, &decoded_data); | 74 base::Base64Decode(crypt, &decoded_data); |
75 PK11SlotInfo* slot = GetKeySlotForDB(); | 75 PK11SlotInfo* slot = GetKeySlotForDB(); |
76 SECStatus result = PK11_Authenticate(slot, PR_TRUE, NULL); | 76 SECStatus result = PK11_Authenticate(slot, PR_TRUE, NULL); |
77 if (result != SECSuccess) { | 77 if (result != SECSuccess) { |
78 FreeSlot(slot); | 78 FreeSlot(slot); |
79 return string16(); | 79 return base::string16(); |
80 } | 80 } |
81 | 81 |
82 SECItem request; | 82 SECItem request; |
83 request.data = reinterpret_cast<unsigned char*>( | 83 request.data = reinterpret_cast<unsigned char*>( |
84 const_cast<char*>(decoded_data.data())); | 84 const_cast<char*>(decoded_data.data())); |
85 request.len = static_cast<unsigned int>(decoded_data.size()); | 85 request.len = static_cast<unsigned int>(decoded_data.size()); |
86 SECItem reply; | 86 SECItem reply; |
87 reply.data = NULL; | 87 reply.data = NULL; |
88 reply.len = 0; | 88 reply.len = 0; |
89 #if defined(USE_NSS) | 89 #if defined(USE_NSS) |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // The user name, password and action. | 290 // The user name, password and action. |
291 form.username_element = s2.ColumnString16(3); | 291 form.username_element = s2.ColumnString16(3); |
292 form.username_value = Decrypt(s2.ColumnString(5)); | 292 form.username_value = Decrypt(s2.ColumnString(5)); |
293 form.password_element = s2.ColumnString16(4); | 293 form.password_element = s2.ColumnString16(4); |
294 form.password_value = Decrypt(s2.ColumnString(6)); | 294 form.password_value = Decrypt(s2.ColumnString(6)); |
295 form.action = GURL(s2.ColumnString(2)).ReplaceComponents(rep); | 295 form.action = GURL(s2.ColumnString(2)).ReplaceComponents(rep); |
296 forms->push_back(form); | 296 forms->push_back(form); |
297 } | 297 } |
298 return true; | 298 return true; |
299 } | 299 } |
OLD | NEW |