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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ipc/ipc_message_utils.cc
diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc
index 60c12ab60f96f879259612c993acf89d0c749cd0..e6b1527effe7a53dd3ab361c3da30622fa4f9981 100644
--- a/ipc/ipc_message_utils.cc
+++ b/ipc/ipc_message_utils.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
+#include "base/unguessable_token.h"
#include "base/values.h"
#include "build/build_config.h"
#include "ipc/ipc_channel_handle.h"
@@ -998,6 +999,48 @@ void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) {
ParamTraits<int64_t>::Log(p.ToInternalValue(), l);
}
+// If base::UnguessableToken is no longer 128 bits, the IPC serialization logic
+// below should be updated.
+static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t),
+ "base::UnguessableToken should be of size 2 * sizeof(uint64_t).");
+
+void ParamTraits<base::UnguessableToken>::GetSize(base::PickleSizer* sizer,
+ const param_type& p) {
+ sizer->AddBytes(2 * sizeof(uint64_t));
+}
+
+void ParamTraits<base::UnguessableToken>::Write(base::Pickle* m,
+ const param_type& p) {
+ DCHECK(!p.is_empty());
+
+ uint64_t high, low;
+ p.Serialize(&high, &low);
+
+ ParamTraits<uint64_t>::Write(m, high);
+ ParamTraits<uint64_t>::Write(m, low);
+}
+
+bool ParamTraits<base::UnguessableToken>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* r) {
+ uint64_t high, low;
+ if (!ParamTraits<uint64_t>::Read(m, iter, &high) ||
+ !ParamTraits<uint64_t>::Read(m, iter, &low))
+ return false;
+
+ // Receiving a zeroed UnguessableToken is a security issue.
+ if(high == 0 && low == 0)
+ return false;
danakj 2016/09/16 22:52:46 please "git cl format" there's a couple style erro
+
+ *r = base::UnguessableToken::Deserialize(high, low);
+ return true;
+}
+
+void ParamTraits<base::UnguessableToken>::Log(const param_type& p,
+ std::string* l) {
+ l->append(p.ToString());
+}
+
void ParamTraits<IPC::ChannelHandle>::GetSize(base::PickleSizer* sizer,
const param_type& p) {
GetParamSize(sizer, p.name);

Powered by Google App Engine
This is Rietveld 408576698