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

Side by Side Diff: components/webauth/authenticator_impl.cc

Issue 2788823002: Add the Mojo implementation of authenticator.mojom's MakeCredential. (Closed)
Patch Set: Move mojom to blink and add unittests. Created 3 years, 5 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
(Empty)
1 // Copyright 2017 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 "components/webauth/authenticator_impl.h"
6
7 #include <memory>
8
9 #include "base/json/json_writer.h"
10 #include "base/memory/ptr_util.h"
11 #include "content/public/browser/render_frame_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "crypto/sha2.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h"
15
16 using content::RenderFrameHost;
17 using content::WebContents;
18
19 namespace webauth {
20
21 const char kGetAssertionType[] = "navigator.id.getAssertion";
22
23 // JSON key values
24 const char kTypeKey[] = "type";
25 const char kChallengeKey[] = "challenge";
26 const char kOriginKey[] = "origin";
27 const char kCidPubkeyKey[] = "cid_pubkey";
28
29 // Serializes the |value| to a JSON string and returns the result.
30 std::string SerializeValueToJson(const base::Value& value) {
31 std::string json;
32 base::JSONWriter::Write(value, &json);
33 return json;
34 }
35
36 // static
37 void AuthenticatorImpl::Create(RenderFrameHost* render_frame_host,
38 mojom::AuthenticatorRequest request) {
39 auto authenticator_impl =
40 base::WrapUnique(new AuthenticatorImpl(render_frame_host));
41 mojo::MakeStrongBinding(std::move(authenticator_impl), std::move(request));
42 }
43
44 AuthenticatorImpl::~AuthenticatorImpl() {}
45
46 AuthenticatorImpl::AuthenticatorImpl(RenderFrameHost* render_frame_host) {
47 DCHECK(render_frame_host);
48 caller_origin_ = render_frame_host->GetLastCommittedOrigin();
49 }
50
51 // mojom:Authenticator
52 void AuthenticatorImpl::MakeCredential(
53 mojom::RelyingPartyAccountPtr account,
54 std::vector<mojom::ScopedCredentialParametersPtr> parameters,
55 const std::vector<uint8_t>& challenge,
56 mojom::ScopedCredentialOptionsPtr options,
57 MakeCredentialCallback callback) {
58 std::string effective_domain;
59 std::string relying_party_id;
60 std::string client_data_json;
61 base::DictionaryValue client_data;
62
63 // Steps 6 & 7 of https://w3c.github.io/webauthn/#createCredential
64 // opaque origin
65 if (caller_origin_.unique()) {
66 std::move(callback).Run(mojom::AuthenticatorStatus::NOT_ALLOWED_ERROR,
67 NULL);
68 return;
69 }
70
71 if (!options->relying_party_id) {
72 relying_party_id = caller_origin_.Serialize();
73 } else {
74 effective_domain = caller_origin_.host();
75
76 DCHECK(!effective_domain.empty());
77 // TODO(kpaulhamus): Check if relyingPartyId is a registrable domain
78 // suffix of and equal to effectiveDomain and set relyingPartyId
79 // appropriately.
80 relying_party_id = options->relying_party_id.value_or(std::string());
81 }
82
83 // TODO(kpaulhamus): Check ScopedCredentialParameter's type and
84 // algorithmIdentifier after algorithmIdentifier is added to mojom to
85 // make sure it is U2F_V2.
86
87 client_data.SetString(kTypeKey, kGetAssertionType);
88 client_data.SetString(
89 kChallengeKey,
90 base::StringPiece(reinterpret_cast<const char*>(challenge.data()),
91 challenge.size()));
92 client_data.SetString(kOriginKey, relying_party_id);
93 // Channel ID is optional, and missing if the browser doesn't support it.
94 // It is present and set to the constant "unused" if the browser
95 // supports Channel ID but is not using it to talk to the origin.
96 // TODO(kpaulhamus): Fetch and add the Channel ID public key used to
97 // communicate with the origin.
98 client_data.SetString(kCidPubkeyKey, "unused");
99
100 // SHA-256 hash the JSON data structure
101 client_data_json = SerializeValueToJson(client_data);
102 std::string client_data_hash = crypto::SHA256HashString(client_data_json);
103
104 std::move(callback).Run(mojom::AuthenticatorStatus::NOT_IMPLEMENTED, NULL);
105 }
106 } // namespace webauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698