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