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

Side by Side Diff: content/browser/webauth/authenticator_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698