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

Side by Side Diff: chrome/browser/extensions/api/cast_channel/cast_message_util.cc

Issue 35443002: Update CastSocket connection flow to check for receiver credentials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_message_util.h" 5 #include "chrome/browser/extensions/api/cast_channel/cast_message_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" 11 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h"
12 #include "chrome/common/extensions/api/cast_channel.h" 12 #include "chrome/common/extensions/api/cast_channel.h"
13 13
14 namespace {
15 static const char kAuthNamespace[] =
16 "urn:x-cast:com.google.cast.tp.deviceauth";
mark a. foltz 2013/10/23 00:33:41 wrap to previous line?
Munjal (Google) 2013/10/23 03:22:55 Becomes 81 cols.
17 } // namespace
18
14 namespace extensions { 19 namespace extensions {
15 namespace api { 20 namespace api {
16 namespace cast_channel { 21 namespace cast_channel {
17 22
18 bool MessageInfoToCastMessage(const MessageInfo& message, 23 bool MessageInfoToCastMessage(const MessageInfo& message,
19 CastMessage* message_proto) { 24 CastMessage* message_proto) {
20 DCHECK(message_proto); 25 DCHECK(message_proto);
21 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); 26 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0);
22 message_proto->set_source_id(message.source_id); 27 message_proto->set_source_id(message.source_id);
23 message_proto->set_destination_id(message.destination_id); 28 message_proto->set_destination_id(message.destination_id);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 81 }
77 if (value.get()) { 82 if (value.get()) {
78 DCHECK(!message->data.get()); 83 DCHECK(!message->data.get());
79 message->data.reset(value.release()); 84 message->data.reset(value.release());
80 return true; 85 return true;
81 } else { 86 } else {
82 return false; 87 return false;
83 } 88 }
84 } 89 }
85 90
86 const std::string MessageProtoToString(const CastMessage& message_proto) { 91 std::string CastMessageToString(const CastMessage& message_proto) {
87 std::string out("{"); 92 std::string out("{");
88 out += "namespace = " + message_proto.namespace_(); 93 out += "namespace = " + message_proto.namespace_();
89 out += ", sourceId = " + message_proto.source_id(); 94 out += ", sourceId = " + message_proto.source_id();
90 out += ", destId = " + message_proto.destination_id(); 95 out += ", destId = " + message_proto.destination_id();
91 out += ", type = " + base::IntToString(message_proto.payload_type()); 96 out += ", type = " + base::IntToString(message_proto.payload_type());
92 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; 97 out += ", str = \"" + message_proto.payload_utf8() + "\"}";
93 return out; 98 return out;
94 } 99 }
95 100
101 std::string AuthMessageToString(const DeviceAuthMessage& message) {
102 std::string out("{");
103 if (message.has_challenge()) {
104 out += "\n challenge = {},";
105 }
106 if (message.has_response()) {
107 out += "\n response = {";
108 out += "\n signature = " + message.response().signature();
109 out += "\n, certificate = " +
110 message.response().client_auth_certificate();
111 out += "\n }";
112 }
113 if (message.has_error()) {
114 out += "\n error = {";
115 out += base::IntToString(message.error().error_type());
116 out += "}";
117 }
118 out += "}";
119 return out;
120 }
121
122 void CreateAuthChallengeMessage(CastMessage* message_proto) {
123 CHECK(message_proto);
124 DeviceAuthMessage auth_message;
125 auth_message.mutable_challenge();
126 std::string auth_message_string;
127 auth_message.SerializeToString(&auth_message_string);
128
129 message_proto->set_namespace_(kAuthNamespace);
mark a. foltz 2013/10/23 00:33:41 You need to set source and destination ids.
Munjal (Google) 2013/10/23 03:22:55 Ah I see. To what values?
mark a. foltz 2013/10/23 05:27:45 The destination id should be 'receiver-0'. The so
Munjal (Google) 2013/10/23 16:21:41 Done.
130 message_proto->set_payload_type(CastMessage_PayloadType_BINARY);
131 message_proto->set_payload_binary(auth_message_string);
132 }
133
134 bool IsAuthMessage(const CastMessage& message) {
135 return message.namespace_() == kAuthNamespace;
136 }
137
96 } // namespace cast_channel 138 } // namespace cast_channel
97 } // namespace api 139 } // namespace api
98 } // namespace extensions 140 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698