| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/sync/engine/syncapi_internal.h" |
| 6 |
| 7 #include "base/scoped_ptr.h" |
| 8 #include "chrome/browser/sync/util/cryptographer.h" |
| 9 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 10 |
| 11 using browser_sync::Cryptographer; |
| 12 |
| 13 namespace sync_api { |
| 14 |
| 15 sync_pb::PasswordSpecificsData* DecryptPasswordSpecifics( |
| 16 const sync_pb::EntitySpecifics& specifics, Cryptographer* crypto) { |
| 17 if (!specifics.HasExtension(sync_pb::password)) |
| 18 return NULL; |
| 19 const sync_pb::PasswordSpecifics& password_specifics = |
| 20 specifics.GetExtension(sync_pb::password); |
| 21 if (!password_specifics.has_encrypted()) |
| 22 return NULL; |
| 23 const sync_pb::EncryptedData& encrypted = password_specifics.encrypted(); |
| 24 scoped_ptr<sync_pb::PasswordSpecificsData> data( |
| 25 new sync_pb::PasswordSpecificsData); |
| 26 if (!crypto->Decrypt(encrypted, data.get())) |
| 27 return NULL; |
| 28 return data.release(); |
| 29 } |
| 30 |
| 31 // The list of names which are reserved for use by the server. |
| 32 static const char* kForbiddenServerNames[] = { "", ".", ".." }; |
| 33 |
| 34 // Checks whether |name| is a server-illegal name followed by zero or more space |
| 35 // characters. The three server-illegal names are the empty string, dot, and |
| 36 // dot-dot. Very long names (>255 bytes in UTF-8 Normalization Form C) are |
| 37 // also illegal, but are not considered here. |
| 38 bool IsNameServerIllegalAfterTrimming(const std::string& name) { |
| 39 size_t untrimmed_count = name.find_last_not_of(' ') + 1; |
| 40 for (size_t i = 0; i < arraysize(kForbiddenServerNames); ++i) { |
| 41 if (name.compare(0, untrimmed_count, kForbiddenServerNames[i]) == 0) |
| 42 return true; |
| 43 } |
| 44 return false; |
| 45 } |
| 46 |
| 47 // Compare the values of two EntitySpecifics, accounting for encryption. |
| 48 bool AreSpecificsEqual(const browser_sync::Cryptographer* cryptographer, |
| 49 const sync_pb::EntitySpecifics& left, |
| 50 const sync_pb::EntitySpecifics& right) { |
| 51 // Note that we can't compare encrypted strings directly as they are seeded |
| 52 // with a random value. |
| 53 std::string left_plaintext, right_plaintext; |
| 54 if (left.has_encrypted()) { |
| 55 if (!cryptographer->CanDecrypt(left.encrypted())) { |
| 56 NOTREACHED() << "Attempting to compare undecryptable data."; |
| 57 return false; |
| 58 } |
| 59 left_plaintext = cryptographer->DecryptToString(left.encrypted()); |
| 60 } else { |
| 61 left_plaintext = left.SerializeAsString(); |
| 62 } |
| 63 if (right.has_encrypted()) { |
| 64 if (!cryptographer->CanDecrypt(right.encrypted())) { |
| 65 NOTREACHED() << "Attempting to compare undecryptable data."; |
| 66 return false; |
| 67 } |
| 68 right_plaintext = cryptographer->DecryptToString(right.encrypted()); |
| 69 } else { |
| 70 right_plaintext = right.SerializeAsString(); |
| 71 } |
| 72 if (left_plaintext == right_plaintext) { |
| 73 return true; |
| 74 } |
| 75 return false; |
| 76 } |
| 77 |
| 78 } // namespace sync_api |
| OLD | NEW |