| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser/importer/nss_decryptor.h" | 5 #include "chrome/browser/importer/nss_decryptor.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_LINUX) | 9 #if defined(OS_LINUX) |
| 10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // Do nothing if NSS is not loaded. | 61 // Do nothing if NSS is not loaded. |
| 62 if (!is_nss_initialized_) | 62 if (!is_nss_initialized_) |
| 63 return std::wstring(); | 63 return std::wstring(); |
| 64 | 64 |
| 65 // The old style password is encoded in base64. They are identified | 65 // The old style password is encoded in base64. They are identified |
| 66 // by a leading '~'. Otherwise, we should decrypt the text. | 66 // by a leading '~'. Otherwise, we should decrypt the text. |
| 67 std::string plain; | 67 std::string plain; |
| 68 if (crypt[0] != '~') { | 68 if (crypt[0] != '~') { |
| 69 std::string decoded_data; | 69 std::string decoded_data; |
| 70 net::Base64Decode(crypt, &decoded_data); | 70 net::Base64Decode(crypt, &decoded_data); |
| 71 PK11SlotInfo* slot = NULL; | 71 PK11SlotInfo* slot = GetKeySlotForDB(); |
| 72 slot = PK11_GetInternalKeySlot(); | |
| 73 SECStatus result = PK11_Authenticate(slot, PR_TRUE, NULL); | 72 SECStatus result = PK11_Authenticate(slot, PR_TRUE, NULL); |
| 74 if (result != SECSuccess) { | 73 if (result != SECSuccess) { |
| 75 PK11_FreeSlot(slot); | 74 FreeSlot(slot); |
| 76 return std::wstring(); | 75 return std::wstring(); |
| 77 } | 76 } |
| 78 | 77 |
| 79 SECItem request; | 78 SECItem request; |
| 80 request.data = reinterpret_cast<unsigned char*>( | 79 request.data = reinterpret_cast<unsigned char*>( |
| 81 const_cast<char*>(decoded_data.data())); | 80 const_cast<char*>(decoded_data.data())); |
| 82 request.len = static_cast<unsigned int>(decoded_data.size()); | 81 request.len = static_cast<unsigned int>(decoded_data.size()); |
| 83 SECItem reply; | 82 SECItem reply; |
| 84 reply.data = NULL; | 83 reply.data = NULL; |
| 85 reply.len = 0; | 84 reply.len = 0; |
| 85 #if defined(OS_LINUX) |
| 86 result = PK11SDR_DecryptWithSlot(slot, &request, &reply, NULL); |
| 87 #else |
| 86 result = PK11SDR_Decrypt(&request, &reply, NULL); | 88 result = PK11SDR_Decrypt(&request, &reply, NULL); |
| 89 #endif // defined(OS_LINUX) |
| 87 if (result == SECSuccess) | 90 if (result == SECSuccess) |
| 88 plain.assign(reinterpret_cast<char*>(reply.data), reply.len); | 91 plain.assign(reinterpret_cast<char*>(reply.data), reply.len); |
| 89 | 92 |
| 90 SECITEM_FreeItem(&reply, PR_FALSE); | 93 SECITEM_FreeItem(&reply, PR_FALSE); |
| 91 PK11_FreeSlot(slot); | 94 FreeSlot(slot); |
| 92 } else { | 95 } else { |
| 93 // Deletes the leading '~' before decoding. | 96 // Deletes the leading '~' before decoding. |
| 94 net::Base64Decode(crypt.substr(1), &plain); | 97 net::Base64Decode(crypt.substr(1), &plain); |
| 95 } | 98 } |
| 96 | 99 |
| 97 return UTF8ToWide(plain); | 100 return UTF8ToWide(plain); |
| 98 } | 101 } |
| 99 | 102 |
| 100 // There are three versions of password filess. They store saved user | 103 // There are three versions of password filess. They store saved user |
| 101 // names and passwords. | 104 // names and passwords. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 219 } |
| 217 // Version 3 has an extra line for further use. | 220 // Version 3 has an extra line for further use. |
| 218 if (version == 3) { | 221 if (version == 3) { |
| 219 ++begin; | 222 ++begin; |
| 220 } | 223 } |
| 221 | 224 |
| 222 forms->push_back(form); | 225 forms->push_back(form); |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 } | 228 } |
| OLD | NEW |