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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 2333443002: Add base::UnguessableToken (Closed)
Patch Set: NonceTokenHash CHECK --> DCHECK 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/nonce_token.h"
12 #include "base/strings/nullable_string16.h" 13 #include "base/strings/nullable_string16.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 16 #include "base/time/time.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"
(...skipping 969 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 void ParamTraits<base::NonceToken>::GetSize(base::PickleSizer* sizer,
1003 const param_type& p) {
1004 sizer->AddBytes(2 * sizeof(uint64_t));
1005 }
1006
1007 void ParamTraits<base::NonceToken>::Write(base::Pickle* m,
1008 const param_type& p) {
1009 CHECK(!p.is_empty());
1010
1011 uint64_t high, low;
1012 p.Serialize(&high, &low);
1013
1014 ParamTraits<uint64_t>::Write(m, high);
1015 ParamTraits<uint64_t>::Write(m, low);
1016 }
1017
1018 bool ParamTraits<base::NonceToken>::Read(const base::Pickle* m,
1019 base::PickleIterator* iter,
1020 param_type* r) {
1021 uint64_t high, low;
1022 if (!ParamTraits<uint64_t>::Read(m, iter, &high) ||
1023 !ParamTraits<uint64_t>::Read(m, iter, &low))
1024 return false;
1025
1026 // Receiving a zeroed NonceToken is a security issue.
1027 if (base::NonceToken::IsZeroData(high, low))
1028 return false;
1029
1030 *r = base::NonceToken::Deserialize(high, low);
1031 return true;
1032 }
1033
1034 void ParamTraits<base::NonceToken>::Log(const param_type& p, std::string* l) {
1035 l->append(p.ToString());
1036 }
1037
1001 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer, 1038 void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer,
1002 const param_type& p) { 1039 const param_type& p) {
1003 GetParamSize(sizer, p.name); 1040 GetParamSize(sizer, p.name);
1004 #if defined(OS_POSIX) 1041 #if defined(OS_POSIX)
1005 GetParamSize(sizer, p.socket); 1042 GetParamSize(sizer, p.socket);
1006 #endif 1043 #endif
1007 GetParamSize(sizer, p.mojo_handle); 1044 GetParamSize(sizer, p.mojo_handle);
1008 } 1045 }
1009 1046
1010 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, 1047 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 return result; 1248 return result;
1212 } 1249 }
1213 1250
1214 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1251 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1215 l->append("<MSG>"); 1252 l->append("<MSG>");
1216 } 1253 }
1217 1254
1218 #endif // OS_WIN 1255 #endif // OS_WIN
1219 1256
1220 } // namespace IPC 1257 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698