webauthn.py (2564B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 __all__ = ["WebAuthn"] 7 8 9 class WebAuthn: 10 def __init__(self, marionette): 11 self.marionette = marionette 12 13 def add_virtual_authenticator(self, config): 14 body = { 15 "protocol": config["protocol"], 16 "transport": config["transport"], 17 "hasResidentKey": config.get("hasResidentKey", False), 18 "hasUserVerification": config.get("hasUserVerification", False), 19 "isUserConsenting": config.get("isUserConsenting", True), 20 "isUserVerified": config.get("isUserVerified", False), 21 } 22 return self.marionette._send_message( 23 "WebAuthn:AddVirtualAuthenticator", body, key="value" 24 ) 25 26 def remove_virtual_authenticator(self, authenticator_id): 27 body = {"authenticatorId": authenticator_id} 28 return self.marionette._send_message( 29 "WebAuthn:RemoveVirtualAuthenticator", body 30 ) 31 32 def add_credential(self, authenticator_id, credential): 33 body = { 34 "authenticatorId": authenticator_id, 35 "credentialId": credential["credentialId"], 36 "isResidentCredential": credential["isResidentCredential"], 37 "rpId": credential["rpId"], 38 "privateKey": credential["privateKey"], 39 "userHandle": credential.get("userHandle"), 40 "signCount": credential.get("signCount", 0), 41 } 42 return self.marionette._send_message("WebAuthn:AddCredential", body) 43 44 def get_credentials(self, authenticator_id): 45 body = {"authenticatorId": authenticator_id} 46 return self.marionette._send_message( 47 "WebAuthn:GetCredentials", body, key="value" 48 ) 49 50 def remove_credential(self, authenticator_id, credential_id): 51 body = {"authenticatorId": authenticator_id, "credentialId": credential_id} 52 return self.marionette._send_message("WebAuthn:RemoveCredential", body) 53 54 def remove_all_credentials(self, authenticator_id): 55 body = {"authenticatorId": authenticator_id} 56 return self.marionette._send_message("WebAuthn:RemoveAllCredentials", body) 57 58 def set_user_verified(self, authenticator_id, uv): 59 body = { 60 "authenticatorId": authenticator_id, 61 "isUserVerified": uv["isUserVerified"], 62 } 63 return self.marionette._send_message("WebAuthn:SetUserVerified", body)