| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "remoting/protocol/content_description.h" | 5 #include "remoting/protocol/content_description.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const char kChromotingContentName[] = "chromoting"; | 24 const char kChromotingContentName[] = "chromoting"; |
| 25 | 25 |
| 26 // Following constants are used to format session description in XML. | 26 // Following constants are used to format session description in XML. |
| 27 const char kDescriptionTag[] = "description"; | 27 const char kDescriptionTag[] = "description"; |
| 28 const char kControlTag[] = "control"; | 28 const char kControlTag[] = "control"; |
| 29 const char kEventTag[] = "event"; | 29 const char kEventTag[] = "event"; |
| 30 const char kVideoTag[] = "video"; | 30 const char kVideoTag[] = "video"; |
| 31 const char kResolutionTag[] = "initial-resolution"; | 31 const char kResolutionTag[] = "initial-resolution"; |
| 32 const char kAuthenticationTag[] = "authentication"; | 32 const char kAuthenticationTag[] = "authentication"; |
| 33 const char kCertificateTag[] = "certificate"; | 33 const char kCertificateTag[] = "certificate"; |
| 34 const char kMasterKeyTag[] = "master-key"; | |
| 35 const char kAuthTokenTag[] = "auth-token"; | 34 const char kAuthTokenTag[] = "auth-token"; |
| 36 | 35 |
| 37 const char kTransportAttr[] = "transport"; | 36 const char kTransportAttr[] = "transport"; |
| 38 const char kVersionAttr[] = "version"; | 37 const char kVersionAttr[] = "version"; |
| 39 const char kCodecAttr[] = "codec"; | 38 const char kCodecAttr[] = "codec"; |
| 40 const char kWidthAttr[] = "width"; | 39 const char kWidthAttr[] = "width"; |
| 41 const char kHeightAttr[] = "height"; | 40 const char kHeightAttr[] = "height"; |
| 42 | 41 |
| 43 const char kStreamTransport[] = "stream"; | 42 const char kStreamTransport[] = "stream"; |
| 44 const char kDatagramTransport[] = "datagram"; | 43 const char kDatagramTransport[] = "datagram"; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 145 } |
| 147 | 146 |
| 148 return true; | 147 return true; |
| 149 } | 148 } |
| 150 | 149 |
| 151 } // namespace | 150 } // namespace |
| 152 | 151 |
| 153 ContentDescription::ContentDescription( | 152 ContentDescription::ContentDescription( |
| 154 const CandidateSessionConfig* candidate_config, | 153 const CandidateSessionConfig* candidate_config, |
| 155 const std::string& auth_token, | 154 const std::string& auth_token, |
| 156 const std::string& master_key, | |
| 157 const std::string& certificate) | 155 const std::string& certificate) |
| 158 : candidate_config_(candidate_config), | 156 : candidate_config_(candidate_config), |
| 159 auth_token_(auth_token), | 157 auth_token_(auth_token), |
| 160 master_key_(master_key), | |
| 161 certificate_(certificate) { | 158 certificate_(certificate) { |
| 162 } | 159 } |
| 163 | 160 |
| 164 ContentDescription::~ContentDescription() { } | 161 ContentDescription::~ContentDescription() { } |
| 165 | 162 |
| 166 // ToXml() creates content description for chromoting session. The | 163 // ToXml() creates content description for chromoting session. The |
| 167 // description looks as follows: | 164 // description looks as follows: |
| 168 // <description xmlns="google:remoting"> | 165 // <description xmlns="google:remoting"> |
| 169 // <control transport="stream" version="1" /> | 166 // <control transport="stream" version="1" /> |
| 170 // <event transport="datagram" version="1" /> | 167 // <event transport="datagram" version="1" /> |
| 171 // <video transport="srtp" codec="vp8" version="1" /> | 168 // <video transport="srtp" codec="vp8" version="1" /> |
| 172 // <initial-resolution width="800" height="600" /> | 169 // <initial-resolution width="800" height="600" /> |
| 173 // <authentication> | 170 // <authentication> |
| 174 // <certificate>[BASE64 Encoded Certificate]</certificate> | 171 // <certificate>[BASE64 Encoded Certificate]</certificate> |
| 175 // <master-key>[master key encrypted with hosts | |
| 176 // public key encoded with BASE64]</master-key> | |
| 177 // <auth-token>...</auth-token> // IT2Me only. | 172 // <auth-token>...</auth-token> // IT2Me only. |
| 178 // </authentication> | 173 // </authentication> |
| 179 // </description> | 174 // </description> |
| 180 // | 175 // |
| 181 XmlElement* ContentDescription::ToXml() const { | 176 XmlElement* ContentDescription::ToXml() const { |
| 182 XmlElement* root = new XmlElement( | 177 XmlElement* root = new XmlElement( |
| 183 QName(kChromotingXmlNamespace, kDescriptionTag), true); | 178 QName(kChromotingXmlNamespace, kDescriptionTag), true); |
| 184 | 179 |
| 185 std::vector<ChannelConfig>::const_iterator it; | 180 std::vector<ChannelConfig>::const_iterator it; |
| 186 | 181 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 214 |
| 220 std::string base64_cert; | 215 std::string base64_cert; |
| 221 if (!base::Base64Encode(certificate(), &base64_cert)) { | 216 if (!base::Base64Encode(certificate(), &base64_cert)) { |
| 222 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; | 217 LOG(DFATAL) << "Cannot perform base64 encode on certificate"; |
| 223 } | 218 } |
| 224 | 219 |
| 225 certificate_tag->SetBodyText(base64_cert); | 220 certificate_tag->SetBodyText(base64_cert); |
| 226 authentication_tag->AddElement(certificate_tag); | 221 authentication_tag->AddElement(certificate_tag); |
| 227 } | 222 } |
| 228 | 223 |
| 229 if (!master_key().empty()) { | |
| 230 XmlElement* master_key_tag = new XmlElement( | |
| 231 QName(kChromotingXmlNamespace, kMasterKeyTag)); | |
| 232 | |
| 233 std::string master_key_base64; | |
| 234 if (!base::Base64Encode(master_key(), &master_key_base64)) { | |
| 235 LOG(DFATAL) << "Cannot perform base64 encode on master key"; | |
| 236 } | |
| 237 | |
| 238 master_key_tag->SetBodyText(master_key_base64); | |
| 239 authentication_tag->AddElement(master_key_tag); | |
| 240 } | |
| 241 | |
| 242 if (!auth_token().empty()) { | 224 if (!auth_token().empty()) { |
| 243 XmlElement* auth_token_tag = new XmlElement( | 225 XmlElement* auth_token_tag = new XmlElement( |
| 244 QName(kChromotingXmlNamespace, kAuthTokenTag)); | 226 QName(kChromotingXmlNamespace, kAuthTokenTag)); |
| 245 auth_token_tag->SetBodyText(auth_token()); | 227 auth_token_tag->SetBodyText(auth_token()); |
| 246 authentication_tag->AddElement(auth_token_tag); | 228 authentication_tag->AddElement(auth_token_tag); |
| 247 } | 229 } |
| 248 | 230 |
| 249 root->AddElement(authentication_tag); | 231 root->AddElement(authentication_tag); |
| 250 } | 232 } |
| 251 | 233 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 ScreenResolution resolution(width, height); | 290 ScreenResolution resolution(width, height); |
| 309 if (!resolution.IsValid()) { | 291 if (!resolution.IsValid()) { |
| 310 return NULL; | 292 return NULL; |
| 311 } | 293 } |
| 312 | 294 |
| 313 *config->mutable_initial_resolution() = resolution; | 295 *config->mutable_initial_resolution() = resolution; |
| 314 | 296 |
| 315 // Parse authentication information. | 297 // Parse authentication information. |
| 316 std::string certificate; | 298 std::string certificate; |
| 317 std::string auth_token; | 299 std::string auth_token; |
| 318 std::string master_key; | |
| 319 child = element->FirstNamed(QName(kChromotingXmlNamespace, | 300 child = element->FirstNamed(QName(kChromotingXmlNamespace, |
| 320 kAuthenticationTag)); | 301 kAuthenticationTag)); |
| 321 if (child) { | 302 if (child) { |
| 322 // Parse the certificate. | 303 // Parse the certificate. |
| 323 const XmlElement* cert_tag = | 304 const XmlElement* cert_tag = |
| 324 child->FirstNamed(QName(kChromotingXmlNamespace, kCertificateTag)); | 305 child->FirstNamed(QName(kChromotingXmlNamespace, kCertificateTag)); |
| 325 if (cert_tag) { | 306 if (cert_tag) { |
| 326 std::string base64_cert = cert_tag->BodyText(); | 307 std::string base64_cert = cert_tag->BodyText(); |
| 327 if (!base::Base64Decode(base64_cert, &certificate)) { | 308 if (!base::Base64Decode(base64_cert, &certificate)) { |
| 328 LOG(ERROR) << "Failed to decode certificate received from the peer."; | 309 LOG(ERROR) << "Failed to decode certificate received from the peer."; |
| 329 return NULL; | 310 return NULL; |
| 330 } | 311 } |
| 331 } | 312 } |
| 332 | 313 |
| 333 // Parse master-key. | |
| 334 const XmlElement* master_key_tag = | |
| 335 child->FirstNamed(QName(kChromotingXmlNamespace, kMasterKeyTag)); | |
| 336 if (master_key_tag) { | |
| 337 if (!base::Base64Decode(master_key_tag->BodyText(), &master_key)) { | |
| 338 LOG(ERROR) << "Failed to decode master-key received from the peer."; | |
| 339 return NULL; | |
| 340 } | |
| 341 master_key = master_key_tag->BodyText(); | |
| 342 } | |
| 343 | |
| 344 // Parse auth-token. | 314 // Parse auth-token. |
| 345 const XmlElement* auth_token_tag = | 315 const XmlElement* auth_token_tag = |
| 346 child->FirstNamed(QName(kChromotingXmlNamespace, kAuthTokenTag)); | 316 child->FirstNamed(QName(kChromotingXmlNamespace, kAuthTokenTag)); |
| 347 if (auth_token_tag) { | 317 if (auth_token_tag) { |
| 348 auth_token = auth_token_tag->BodyText(); | 318 auth_token = auth_token_tag->BodyText(); |
| 349 } | 319 } |
| 350 } | 320 } |
| 351 | 321 |
| 352 return new ContentDescription(config.release(), auth_token, master_key, | 322 return new ContentDescription(config.release(), auth_token, certificate); |
| 353 certificate); | |
| 354 } | 323 } |
| 355 LOG(ERROR) << "Invalid description: " << element->Str(); | 324 LOG(ERROR) << "Invalid description: " << element->Str(); |
| 356 return NULL; | 325 return NULL; |
| 357 } | 326 } |
| 358 | 327 |
| 359 } // namespace protocol | 328 } // namespace protocol |
| 360 } // namespace remoting | 329 } // namespace remoting |
| OLD | NEW |