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