-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Add support to debug virtual authenticators #7842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7ee0a6d
addCredential support.
nsatragno 551b8cd
Add test for resident credential.
nsatragno fd3f397
Refactor method into authenticator itself.
nsatragno 89dafdd
Add getCredentials.
nsatragno f8e051e
Add support for removeCredential.
nsatragno f23df45
Add removeAllCredentials.
nsatragno dbb16ea
Add support for setUserVerified.
nsatragno ddb40fb
Format code.
nsatragno b756678
Remove unused import.
nsatragno a441fb1
Prettier test.
nsatragno a423f36
fix nit.
nsatragno f18639a
Less verbose method name.
nsatragno 3998dad
Use ImmutableMap instead of HashMap.
nsatragno 059d4e0
Use Collections.unmodifiableMap instead of guava
nsatragno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
java/client/src/org/openqa/selenium/virtualauthenticator/Credential.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.virtualauthenticator; | ||
|
||
import java.security.spec.PKCS8EncodedKeySpec; | ||
import java.util.Base64; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A credential stored in a virtual authenticator. | ||
* @see https://w3c.github.io/webauthn/#credential-parameters | ||
*/ | ||
public class Credential { | ||
|
||
private final byte[] id; | ||
private final boolean isResidentCredential; | ||
private final String rpId; | ||
private final PKCS8EncodedKeySpec privateKey; | ||
private final byte[] userHandle; | ||
private final int signCount; | ||
|
||
/** | ||
* Creates a non resident (i.e. stateless) credential. | ||
*/ | ||
public static Credential createNonResidentCredential(byte[] id, String rpId, | ||
PKCS8EncodedKeySpec privateKey, int signCount) { | ||
return new Credential(id, /*isResidentCredential=*/false, Objects.requireNonNull(rpId), | ||
privateKey, /*userHandle=*/null, signCount); | ||
} | ||
|
||
/** | ||
* Creates a resident (i.e. stateful) credential. | ||
*/ | ||
public static Credential createResidentCredential(byte[] id, String rpId, | ||
PKCS8EncodedKeySpec privateKey, byte[] userHandle, int signCount) { | ||
return new Credential(id, /*isResidentCredential=*/true, Objects.requireNonNull(rpId), | ||
privateKey, Objects.requireNonNull(userHandle), signCount); | ||
} | ||
|
||
/** | ||
* Creates a credential from a map. | ||
*/ | ||
public static Credential fromMap(Map<String, Object> map) { | ||
Base64.Decoder decoder = Base64.getUrlDecoder(); | ||
return new Credential(decoder.decode((String) map.get("credentialId")), | ||
(boolean) map.get("isResidentCredential"), | ||
(String) map.get("rpId"), | ||
new PKCS8EncodedKeySpec(decoder.decode((String) map.get("privateKey"))), | ||
map.get("userHandle") == null ? null : decoder.decode((String) map.get("userHandle")), | ||
((Long) map.get("signCount")).intValue()); | ||
} | ||
|
||
private Credential(byte[] id, boolean isResidentCredential, String rpId, | ||
PKCS8EncodedKeySpec privateKey, byte[] userHandle, int signCount) { | ||
this.id = Objects.requireNonNull(id); | ||
this.isResidentCredential = isResidentCredential; | ||
this.rpId = rpId; | ||
this.privateKey = Objects.requireNonNull(privateKey); | ||
this.userHandle = userHandle; | ||
this.signCount = signCount; | ||
} | ||
|
||
public byte[] getId() { | ||
return id; | ||
} | ||
|
||
public boolean isResidentCredential() { | ||
return isResidentCredential; | ||
} | ||
|
||
public String getRpId() { | ||
return rpId; | ||
} | ||
|
||
public PKCS8EncodedKeySpec getPrivateKey() { | ||
nsatragno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return privateKey; | ||
} | ||
|
||
public byte[] getUserHandle() { | ||
return userHandle; | ||
} | ||
|
||
public int getSignCount() { | ||
return signCount; | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
Base64.Encoder encoder = Base64.getUrlEncoder(); | ||
Map<String, Object> map = new HashMap<String, Object>(); | ||
map.put("credentialId", encoder.encodeToString(id)); | ||
map.put("isResidentCredential", isResidentCredential); | ||
map.put("rpId", rpId); | ||
map.put("privateKey", encoder.encodeToString(privateKey.getEncoded())); | ||
map.put("signCount", signCount); | ||
if (userHandle != null) { | ||
map.put("userHandle", encoder.encodeToString(userHandle)); | ||
} | ||
return Collections.unmodifiableMap(map); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.