Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 2333443002: Add base::UnguessableToken (Closed)
Patch Set: Removed MOJO_COMMON_EXPORT Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/strings/nullable_string16.h" 12 #include "base/strings/nullable_string16.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/unguessable_token.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "ipc/ipc_channel_handle.h" 19 #include "ipc/ipc_channel_handle.h"
19 #include "ipc/ipc_message_attachment.h" 20 #include "ipc/ipc_message_attachment.h"
20 #include "ipc/ipc_message_attachment_set.h" 21 #include "ipc/ipc_message_attachment_set.h"
21 #include "ipc/ipc_mojo_param_traits.h" 22 #include "ipc/ipc_mojo_param_traits.h"
22 23
23 #if defined(OS_POSIX) 24 #if defined(OS_POSIX)
24 #include "ipc/ipc_platform_file_attachment_posix.h" 25 #include "ipc/ipc_platform_file_attachment_posix.h"
25 #endif 26 #endif
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 if (ret) 992 if (ret)
992 *r = base::TimeTicks::FromInternalValue(value); 993 *r = base::TimeTicks::FromInternalValue(value);
993 994
994 return ret; 995 return ret;
995 } 996 }
996 997
997 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { 998 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) {
998 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); 999 ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
999 } 1000 }
1000 1001
1002 // If base::UnguessableToken is no longer 128 bits, the IPC serialization logic
1003 // below should be updated.
1004 static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t),
1005 "base::UnguessableToken should be of size 2 * sizeof(uint64_t).");
1006
1007 void ParamTraits<base::UnguessableToken>::GetSize(base::PickleSizer* sizer,
1008 const param_type& p) {
1009 sizer->AddBytes(2 * sizeof(uint64_t));
1010 }
1011
1012 void ParamTraits<base::UnguessableToken>::Write(base::Pickle* m,
1013 const param_type& p) {
1014 DCHECK(!p.is_empty());
1015
1016 ParamTraits<uint64_t>::Write(m, p.GetHighForSerialization());
1017 ParamTraits<uint64_t>::Write(m, p.GetLowForSerialization());
1018 }
1019
1020 bool ParamTraits<base::UnguessableToken>::Read(const base::Pickle* m,
1021 base::PickleIterator* iter,
1022 param_type* r) {
1023 uint64_t high, low;
1024 if (!ParamTraits<uint64_t>::Read(m, iter, &high) ||
1025 !ParamTraits<uint64_t>::Read(m, iter, &low))
1026 return false;
1027
1028 // Receiving a zeroed UnguessableToken is a security issue.
1029 if (high == 0 && low == 0)
1030 return false;
1031
1032 *r = base::UnguessableToken::Deserialize(high, low);
1033 return true;
1034 }
1035
1036 void ParamTraits<base::UnguessableToken>::Log(const param_type& p,
1037 std::string* l) {
1038 l->append(p.ToString());
1039 }
1040
1001 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, 1041 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer,
1002 const param_type& p) { 1042 const param_type& p) {
1003 GetParamSize(sizer, p.name); 1043 GetParamSize(sizer, p.name);
1004 #if defined(OS_POSIX) 1044 #if defined(OS_POSIX)
1005 GetParamSize(sizer, p.socket); 1045 GetParamSize(sizer, p.socket);
1006 #endif 1046 #endif
1007 GetParamSize(sizer, p.mojo_handle); 1047 GetParamSize(sizer, p.mojo_handle);
1008 } 1048 }
1009 1049
1010 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, 1050 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 return result; 1251 return result;
1212 } 1252 }
1213 1253
1214 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1254 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1215 l->append("<MSG>"); 1255 l->append("<MSG>");
1216 } 1256 }
1217 1257
1218 #endif // OS_WIN 1258 #endif // OS_WIN
1219 1259
1220 } // namespace IPC 1260 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698