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

Side by Side Diff: extensions/browser/api/cast_channel/cast_auth_util.cc

Issue 807723004: Cast audio only policy enforcement support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review changes Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/cast_channel/cast_auth_util.h" 5 #include "extensions/browser/api/cast_channel/cast_auth_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "extensions/browser/api/cast_channel/cast_message_util.h" 10 #include "extensions/browser/api/cast_channel/cast_message_util.h"
11 #include "extensions/common/api/cast_channel/cast_channel.pb.h" 11 #include "extensions/common/api/cast_channel/cast_channel.pb.h"
12 12
13 namespace extensions { 13 namespace extensions {
14 namespace core_api { 14 namespace core_api {
15 namespace cast_channel { 15 namespace cast_channel {
16 namespace { 16 namespace {
17 17
18 const char* const kParseErrorPrefix = "Failed to parse auth message: "; 18 const char* const kParseErrorPrefix = "Failed to parse auth message: ";
19 19
20 const char kAudioOnlyPolicy[] =
21 {0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xD6, 0x79, 0x02, 0x05, 0x02};
22
20 // Extracts an embedded DeviceAuthMessage payload from an auth challenge reply 23 // Extracts an embedded DeviceAuthMessage payload from an auth challenge reply
21 // message. 24 // message.
22 AuthResult ParseAuthMessage(const CastMessage& challenge_reply, 25 AuthResult ParseAuthMessage(const CastMessage& challenge_reply,
23 DeviceAuthMessage* auth_message) { 26 DeviceAuthMessage* auth_message) {
24 if (challenge_reply.payload_type() != CastMessage_PayloadType_BINARY) { 27 if (challenge_reply.payload_type() != CastMessage_PayloadType_BINARY) {
25 return AuthResult::CreateWithParseError( 28 return AuthResult::CreateWithParseError(
26 "Wrong payload type in challenge reply", 29 "Wrong payload type in challenge reply",
27 AuthResult::ERROR_WRONG_PAYLOAD_TYPE); 30 AuthResult::ERROR_WRONG_PAYLOAD_TYPE);
28 } 31 }
29 if (!challenge_reply.has_payload_binary()) { 32 if (!challenge_reply.has_payload_binary()) {
(...skipping 17 matching lines...) Expand all
47 } 50 }
48 if (!auth_message->has_response()) { 51 if (!auth_message->has_response()) {
49 return AuthResult::CreateWithParseError( 52 return AuthResult::CreateWithParseError(
50 "Auth message has no response field", AuthResult::ERROR_NO_RESPONSE); 53 "Auth message has no response field", AuthResult::ERROR_NO_RESPONSE);
51 } 54 }
52 return AuthResult(); 55 return AuthResult();
53 } 56 }
54 57
55 } // namespace 58 } // namespace
56 59
57 AuthResult::AuthResult() : error_type(ERROR_NONE), nss_error_code(0) { 60 AuthResult::AuthResult()
61 : error_type(ERROR_NONE), nss_error_code(0), channel_policy(POLICY_NONE) {
58 } 62 }
59 63
60 AuthResult::~AuthResult() { 64 AuthResult::~AuthResult() {
61 } 65 }
62 66
63 // static 67 // static
64 AuthResult AuthResult::CreateWithParseError(const std::string& error_message, 68 AuthResult AuthResult::CreateWithParseError(const std::string& error_message,
65 ErrorType error_type) { 69 ErrorType error_type) {
66 return AuthResult(kParseErrorPrefix + error_message, error_type, 0); 70 return AuthResult(kParseErrorPrefix + error_message, error_type, 0);
67 } 71 }
(...skipping 26 matching lines...) Expand all
94 if (!result.success()) { 98 if (!result.success()) {
95 return result; 99 return result;
96 } 100 }
97 101
98 const AuthResponse& response = auth_message.response(); 102 const AuthResponse& response = auth_message.response();
99 result = VerifyCredentials(response, peer_cert); 103 result = VerifyCredentials(response, peer_cert);
100 if (!result.success()) { 104 if (!result.success()) {
101 return result; 105 return result;
102 } 106 }
103 107
104 return AuthResult(); 108 if (response.client_auth_certificate().find(kAudioOnlyPolicy) !=
109 std::string::npos) {
110 result.channel_policy |= AuthResult::POLICY_AUDIO_ONLY;
111 }
112
113 return result;
105 } 114 }
106 115
107 } // namespace cast_channel 116 } // namespace cast_channel
108 } // namespace core_api 117 } // namespace core_api
109 } // namespace extensions 118 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698