OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 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" |
| 8 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" |
| 9 |
| 10 namespace chromeos { |
| 11 namespace attestation { |
| 12 |
| 13 // static |
| 14 void PlatformVerificationImpl::Create( |
| 15 content::RenderFrameHost* render_frame_host, |
| 16 mojo::InterfaceRequest<media::interfaces::PlatformVerification> request) { |
| 17 DVLOG(2) << __FUNCTION__; |
| 18 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 19 DCHECK(render_frame_host); |
| 20 |
| 21 // The created object is bound to (and owned by) the pipe. |
| 22 mojo::BindToRequest(new PlatformVerificationImpl(render_frame_host), |
| 23 &request); |
| 24 } |
| 25 |
| 26 PlatformVerificationImpl::PlatformVerificationImpl( |
| 27 content::RenderFrameHost* render_frame_host) |
| 28 : render_frame_host_(render_frame_host), weak_factory_(this) { |
| 29 DCHECK(render_frame_host); |
| 30 } |
| 31 |
| 32 PlatformVerificationImpl::~PlatformVerificationImpl() { |
| 33 } |
| 34 |
| 35 void PlatformVerificationImpl::ChallengePlatform( |
| 36 const mojo::String& service_id, |
| 37 const mojo::String& challenge, |
| 38 const ChallengePlatformCallback& callback) { |
| 39 DVLOG(2) << __FUNCTION__; |
| 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 41 |
| 42 if (!platform_verification_flow_.get()) |
| 43 platform_verification_flow_ = new PlatformVerificationFlow(); |
| 44 |
| 45 platform_verification_flow_->ChallengePlatformKey( |
| 46 content::WebContents::FromRenderFrameHost(render_frame_host_), service_id, |
| 47 challenge, base::Bind(&PlatformVerificationImpl::OnPlatformChallenged, |
| 48 weak_factory_.GetWeakPtr(), callback)); |
| 49 } |
| 50 |
| 51 void PlatformVerificationImpl::OnPlatformChallenged( |
| 52 const ChallengePlatformCallback& callback, |
| 53 Result result, |
| 54 const std::string& signed_data, |
| 55 const std::string& signature, |
| 56 const std::string& platform_key_certificate) { |
| 57 DVLOG(2) << __FUNCTION__ << ": " << result; |
| 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 59 |
| 60 if (result != PlatformVerificationFlow::SUCCESS) { |
| 61 DCHECK(signed_data.empty()); |
| 62 DCHECK(signature.empty()); |
| 63 DCHECK(platform_key_certificate.empty()); |
| 64 LOG(ERROR) << "Platform verification failed."; |
| 65 callback.Run(false, "", "", ""); |
| 66 return; |
| 67 } |
| 68 |
| 69 DCHECK(!signed_data.empty()); |
| 70 DCHECK(!signature.empty()); |
| 71 DCHECK(!platform_key_certificate.empty()); |
| 72 callback.Run(true, signed_data, signature, platform_key_certificate); |
| 73 } |
| 74 |
| 75 } // namespace attestation |
| 76 } // namespace chromeos |
OLD | NEW |