| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "chrome/browser/sync/util/cryptographer.h" | 6 #include "chrome/browser/sync/util/cryptographer.h" |
| 7 #include "chrome/browser/password_manager/encryptor.h" | 7 #include "chrome/browser/password_manager/encryptor.h" |
| 8 | 8 |
| 9 namespace browser_sync { | 9 namespace browser_sync { |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 encrypted->mutable_blob())) { | 52 encrypted->mutable_blob())) { |
| 53 NOTREACHED(); // Encrypt should not fail. | 53 NOTREACHED(); // Encrypt should not fail. |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool Cryptographer::Decrypt(const sync_pb::EncryptedData& encrypted, | 59 bool Cryptographer::Decrypt(const sync_pb::EncryptedData& encrypted, |
| 60 ::google::protobuf::MessageLite* message) const { | 60 ::google::protobuf::MessageLite* message) const { |
| 61 DCHECK(message); | 61 DCHECK(message); |
| 62 std::string plaintext = DecryptToString(encrypted); |
| 63 return message->ParseFromString(plaintext); |
| 64 } |
| 62 | 65 |
| 66 std::string Cryptographer::DecryptToString( |
| 67 const sync_pb::EncryptedData& encrypted) const { |
| 63 NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name()); | 68 NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name()); |
| 64 if (nigoris_.end() == it) { | 69 if (nigoris_.end() == it) { |
| 65 NOTREACHED() << "Cannot decrypt message"; | 70 NOTREACHED() << "Cannot decrypt message"; |
| 66 return false; // Caller should have called CanDecrypt(encrypt). | 71 return std::string(""); // Caller should have called CanDecrypt(encrypt). |
| 67 } | 72 } |
| 68 | 73 |
| 69 std::string plaintext; | 74 std::string plaintext; |
| 70 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { | 75 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { |
| 71 return false; | 76 return std::string(""); |
| 72 } | 77 } |
| 73 | 78 |
| 74 return message->ParseFromString(plaintext); | 79 return plaintext; |
| 75 } | 80 } |
| 76 | 81 |
| 77 bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const { | 82 bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const { |
| 78 DCHECK(encrypted); | 83 DCHECK(encrypted); |
| 79 DCHECK(!nigoris_.empty()); | 84 DCHECK(!nigoris_.empty()); |
| 80 | 85 |
| 81 // Create a bag of all the Nigori parameters we know about. | 86 // Create a bag of all the Nigori parameters we know about. |
| 82 sync_pb::NigoriKeyBag bag; | 87 sync_pb::NigoriKeyBag bag; |
| 83 for (NigoriMap::const_iterator it = nigoris_.begin(); it != nigoris_.end(); | 88 for (NigoriMap::const_iterator it = nigoris_.begin(); it != nigoris_.end(); |
| 84 ++it) { | 89 ++it) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 continue; | 251 continue; |
| 247 } | 252 } |
| 248 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); | 253 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); |
| 249 } | 254 } |
| 250 } | 255 } |
| 251 DCHECK(nigoris_.end() != nigoris_.find(default_key_name)); | 256 DCHECK(nigoris_.end() != nigoris_.find(default_key_name)); |
| 252 default_nigori_ = &*nigoris_.find(default_key_name); | 257 default_nigori_ = &*nigoris_.find(default_key_name); |
| 253 } | 258 } |
| 254 | 259 |
| 255 } // namespace browser_sync | 260 } // namespace browser_sync |
| OLD | NEW |