Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / attestation / platform_verification_impl.cc
blob89b098a9b1ee84ed4d7edbd75e9a28b8dc2ef5b6
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/attestation/platform_verification_impl.h"
6 #include "content/public/browser/browser_thread.h"
7 #include "content/public/browser/web_contents.h"
9 namespace chromeos {
10 namespace attestation {
12 using media::interfaces::PlatformVerification;
14 // static
15 void PlatformVerificationImpl::Create(
16 content::RenderFrameHost* render_frame_host,
17 mojo::InterfaceRequest<PlatformVerification> request) {
18 DVLOG(2) << __FUNCTION__;
19 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
20 DCHECK(render_frame_host);
22 // The created object is strongly bound to (and owned by) the pipe.
23 new PlatformVerificationImpl(render_frame_host, request.Pass());
26 PlatformVerificationImpl::PlatformVerificationImpl(
27 content::RenderFrameHost* render_frame_host,
28 mojo::InterfaceRequest<PlatformVerification> request)
29 : binding_(this, request.Pass()),
30 render_frame_host_(render_frame_host),
31 weak_factory_(this) {
32 DCHECK(render_frame_host);
35 PlatformVerificationImpl::~PlatformVerificationImpl() {
38 void PlatformVerificationImpl::ChallengePlatform(
39 const mojo::String& service_id,
40 const mojo::String& challenge,
41 const ChallengePlatformCallback& callback) {
42 DVLOG(2) << __FUNCTION__;
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
45 if (!platform_verification_flow_.get())
46 platform_verification_flow_ = new PlatformVerificationFlow();
48 platform_verification_flow_->ChallengePlatformKey(
49 content::WebContents::FromRenderFrameHost(render_frame_host_), service_id,
50 challenge, base::Bind(&PlatformVerificationImpl::OnPlatformChallenged,
51 weak_factory_.GetWeakPtr(), callback));
54 void PlatformVerificationImpl::OnPlatformChallenged(
55 const ChallengePlatformCallback& callback,
56 Result result,
57 const std::string& signed_data,
58 const std::string& signature,
59 const std::string& platform_key_certificate) {
60 DVLOG(2) << __FUNCTION__ << ": " << result;
61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
63 if (result != PlatformVerificationFlow::SUCCESS) {
64 DCHECK(signed_data.empty());
65 DCHECK(signature.empty());
66 DCHECK(platform_key_certificate.empty());
67 LOG(ERROR) << "Platform verification failed.";
68 callback.Run(false, "", "", "");
69 return;
72 DCHECK(!signed_data.empty());
73 DCHECK(!signature.empty());
74 DCHECK(!platform_key_certificate.empty());
75 callback.Run(true, signed_data, signature, platform_key_certificate);
78 } // namespace attestation
79 } // namespace chromeos