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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 2333443002: Add base::UnguessableToken (Closed)
Patch Set: Addressed comments. 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
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 uint64_t high, low;
1017 p.Serialize(&high, &low);
1018
1019 ParamTraits<uint64_t>::Write(m, high);
1020 ParamTraits<uint64_t>::Write(m, low);
1021 }
1022
1023 bool ParamTraits<base::UnguessableToken>::Read(const base::Pickle* m,
1024 base::PickleIterator* iter,
1025 param_type* r) {
1026 uint64_t high, low;
1027 if (!ParamTraits<uint64_t>::Read(m, iter, &high) ||
1028 !ParamTraits<uint64_t>::Read(m, iter, &low))
1029 return false;
1030
1031 // Receiving a zeroed UnguessableToken is a security issue.
1032 if(high == 0 && low == 0)
1033 return false;
danakj 2016/09/16 22:52:46 please "git cl format" there's a couple style erro
1034
1035 *r = base::UnguessableToken::Deserialize(high, low);
1036 return true;
1037 }
1038
1039 void ParamTraits<base::UnguessableToken>::Log(const param_type& p,
1040 std::string* l) {
1041 l->append(p.ToString());
1042 }
1043
1001 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, 1044 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer,
1002 const param_type& p) { 1045 const param_type& p) {
1003 GetParamSize(sizer, p.name); 1046 GetParamSize(sizer, p.name);
1004 #if defined(OS_POSIX) 1047 #if defined(OS_POSIX)
1005 GetParamSize(sizer, p.socket); 1048 GetParamSize(sizer, p.socket);
1006 #endif 1049 #endif
1007 GetParamSize(sizer, p.mojo_handle); 1050 GetParamSize(sizer, p.mojo_handle);
1008 } 1051 }
1009 1052
1010 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, 1053 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 return result; 1254 return result;
1212 } 1255 }
1213 1256
1214 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1257 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1215 l->append("<MSG>"); 1258 l->append("<MSG>");
1216 } 1259 }
1217 1260
1218 #endif // OS_WIN 1261 #endif // OS_WIN
1219 1262
1220 } // namespace IPC 1263 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698