o
    sh.                     @  s  U d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZ dd
lZddlmZ ddlmZ dd
lZeeZeej Z!ej"Z#G dd dZ$G dd dej%Z&G dd dej%Z'G dd dej%Z(G dd dej%Z)G dd dej%Z*G dd dej%Z+G dd dej%Z,G dd dej%Z-G dd  d ej%Z.G d!d" d"ej%Z/G d#d$ d$ej%Z0G d%d& d&ej%Z1G d'd( d(ej%Z2G d)d* d*ej%Z3G d+d, d,ej%Z4G d-d. d.ej%Z5G d/d0 d0ej%Z6G d1d2 d2ej%Z7G d3d4 d4ej%Z8G d5d6 d6ej%Z9G d7d8 d8ej%Z:G d9d: d:ej%Z;G d;d< d<e<Z=eG d=d> d>e=e
Z>eG d?d@ d@e=e
Z?eG dAdB dBe=e
Z@eG dCdD dDe=e
ZAeG dEdF dFe=e
ZBeG dGdH dHe=e
ZCeG dIdJ dJe=e
ZDeG dKdL dLe=e
ZEejFZFejZGeGH ZIeejJgeGjK_LeFeGjK_Meee*ee+ee(ee)ee:eee;geGjN_LeFeGjN_Meeee)ee8eee9geGjO_LeFeGjO_Mee;geGjP_Lee9geGjQ_Lee&geGjR_LeFeGjR_Mee&geGjS_LeFeGjS_MeFgeGjT_Le#eGjT_MdddddddMdNddMddOi dNdPdNdQdRdPdSdMddTdUdQidSdPdNdVdWdWdSdPdRdXZUdYeVdZ< ded_d`ZWG dadb dbeZXG dcdd ddZYd
S )fzR
Structs based on Microsoft's WebAuthN API.
https://github.com/microsoft/webauthn
    )annotations   )websafe_decode)AttestationObjectAuthenticatorDataResidentKeyRequirement)IntEnumunique)BOOLDWORDLONGLPCWSTRHWNDWORD)Thread)MappingDictAnyTupleN)WinDLL)LibraryLoaderc                   @  s(   e Zd ZdZdd Zdd Zdd ZdS )	BytesPropertyzProperty for structs storing byte arrays as DWORD + PBYTE.

    Allows for easy reading/writing to struct fields using Python bytes objects.
    c                 C  s   d| | _ d| | _d S )Ncbpb)cbNamepbName)selfname r   H/var/www/html/env_mimamsha/lib/python3.10/site-packages/fido2/win_api.py__init__E      
zBytesProperty.__init__c                 C  s$   t tt|| jd t|| j S N)bytes	bytearraygetattrr   r   )r   instanceownerr   r   r   __get__I   s   zBytesProperty.__get__c                 C  s<   t || j|d urt|nd t || jt|pdt d S )Nr   )setattrr   lenr   ctypescastPBYTE)r   r&   valuer   r   r   __set__N   s   zBytesProperty.__set__N)__name__
__module____qualname____doc__r    r(   r/   r   r   r   r   r   ?   s
    r   c                   @  s@   e Zd ZdZdejfdejfdejfdejd fgZdd Z	d	S )
GUIDzGUID Type in C++.Data1Data2Data3Data4   c                 C  sx   d| j | j| j| jd d | jd  | jd d | jd d  | jd	 d
  | jd d  | jd d  | jd  f S )Nz{%08X-%04X-%04X-%04X-%012X}r      r      l           l           i      i         )r5   r6   r7   r8   r   r   r   r   __str__]   s"   zGUID.__str__N)
r0   r1   r2   r3   r+   c_ulongc_ushortc_ubyte_fields_rB   r   r   r   r   r4   S   s    r4   c                   @  .   e Zd ZdZdefdefdefgZdd ZdS )WebAuthNCoseCredentialParameterzMaps to WEBAUTHN_COSE_CREDENTIAL_PARAMETER Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L185

    :param Dict[str, Any] cred_params: Dict of Credential parameters.
    	dwVersionpwszCredentialTypelAlgc                 C  s&   t | jj| _|d | _|d | _d S )Ntypealg)get_version	__class__r0   rI   rJ   rK   )r   cred_paramsr   r   r   r    z   s   
z(WebAuthNCoseCredentialParameter.__init__N)	r0   r1   r2   r3   r   r   r   rF   r    r   r   r   r   rH   l   s    rH   c                   @  .   e Zd ZdZdefdeefgZdd Z	dS ) WebAuthNCoseCredentialParameterszMaps to WEBAUTHN_COSE_CREDENTIAL_PARAMETERS Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L191

    :param List[Dict[str, Any]] params: List of Credential parameter dicts.
    cCredentialParameterspCredentialParametersc                 C  *   t || _tt | dd |D  | _d S )Nc                 s      | ]}t |V  qd S r"   )rH   ).0paramr   r   r   	<genexpr>       z<WebAuthNCoseCredentialParameters.__init__.<locals>.<genexpr>)r*   rS   rH   rT   )r   paramsr   r   r   r          


z)WebAuthNCoseCredentialParameters.__init__N)
r0   r1   r2   r3   r   r+   POINTERrH   rF   r    r   r   r   r   rR      s    rR   c                   @  s<   e Zd ZdZdefdefdefdefgZedZ	dd Z
d	S )
WebAuthNClientDatazMaps to WEBAUTHN_CLIENT_DATA Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L153

    :param bytes client_data: ClientData serialized as JSON bytes.
    rI   cbClientDataJSONpbClientDataJSONpwszHashAlgIdClientDataJSONc                 C  s   t | jj| _|| _d| _d S )NzSHA-256)rN   rO   r0   rI   jsonra   )r   client_datar   r   r   r       s   
zWebAuthNClientData.__init__N)r0   r1   r2   r3   r   r-   r   rF   r   rc   r    r   r   r   r   r^      s    r^   c                   @  s4   e Zd ZdZdefdefdefdefgZdd ZdS )	WebAuthNRpEntityInformationzMaps to WEBAUTHN_RP_ENTITY_INFORMATION Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L98

    :param Dict[str, Any] rp: Dict of RP information.
    rI   pwszIdpwszNamepwszIconc                 C  s2   t | jj| _|d | _|d | _|d| _d S )Nidr   icon)rN   rO   r0   rI   rf   rg   getrh   )r   rpr   r   r   r       s   

z$WebAuthNRpEntityInformation.__init__N)r0   r1   r2   r3   r   PCWSTRrF   r    r   r   r   r   re      s    re   c                   @  sH   e Zd ZdZdefdefdefdefdefdefgZedZ	d	d
 Z
dS )WebAuthNUserEntityInformationzMaps to WEBAUTHN_USER_ENTITY_INFORMATION Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L127

    :param Dict[str, Any] user: Dict of User information.
    rI   cbIdpbIdrg   rh   pwszDisplayNameIdc                 C  s>   t | jj| _|d | _|d | _|d| _|d| _d S )Nri   r   rj   displayName)	rN   rO   r0   rI   ri   rg   rk   rh   rq   )r   userr   r   r   r       s
   

z&WebAuthNUserEntityInformation.__init__N)r0   r1   r2   r3   r   r-   rm   rF   r   ri   r    r   r   r   r   rn      s    	rn   c                   @  sB   e Zd ZdZdefdefdefdefdefgZedZ	dd	 Z
d
S )WebAuthNCredentialExzMaps to WEBAUTHN_CREDENTIAL_EX Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L250

    :param Dict[str, Any] cred: Dict of Credential Descriptor data.
    rI   ro   rp   rJ   dwTransportsrr   c                 C  s8   t | jj| _|d | _|d | _t|dd | _d S )Nri   rL   	transportANY)	rN   rO   r0   rI   ri   rJ   WebAuthNCTAPTransportrk   rv   r   credr   r   r   r       s   

zWebAuthNCredentialEx.__init__N)r0   r1   r2   r3   r   r-   r   rF   r   ri   r    r   r   r   r   ru      s    ru   c                   @  s4   e Zd ZdZdefdeeefgZdd Z	dS )WebAuthNCredentialListzMaps to WEBAUTHN_CREDENTIAL_LIST Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L261

    :param List[Dict[str, Any]] credentials: List of dict of
        Credential Descriptor data.
    cCredentialsppCredentialsc                 C  s0   t || _ttt | dd |D  | _d S )Nc                 s  s    | ]
}t t|V  qd S r"   )r+   pointerru   rW   r{   r   r   r   rY     s    z2WebAuthNCredentialList.__init__.<locals>.<genexpr>)r*   r}   r+   r]   ru   r~   r   credentialsr   r   r   r      s   

zWebAuthNCredentialList.__init__N)
r0   r1   r2   r3   r   r+   r]   ru   rF   r    r   r   r   r   r|      s    	r|   c                   @  sB   e Zd ZdefdefdefdefgZedZedZd
dd	Z	dS )WebAuthNHmacSecretSaltcbFirstpbFirstcbSecondpbSecondFirstSecondNc                 C     || _ || _d S r"   )firstsecond)r   r   r   r   r   r   r         
zWebAuthNHmacSecretSalt.__init__r"   )
r0   r1   r2   r   r-   rF   r   r   r   r    r   r   r   r   r   
  s    r   c                   @  s8   e Zd ZdefdefdeefgZe	dZ
dd ZdS )WebAuthNCredWithHmacSecretSaltcbCredIDpbCredIDpHmacSecretSaltCredIDc                 C  s   || _ t|| _d S r"   )cred_idr+   r   salt)r   r   r   r   r   r   r    %  s   z'WebAuthNCredWithHmacSecretSalt.__init__N)r0   r1   r2   r   r-   r+   r]   r   rF   r   r   r    r   r   r   r   r     s    r   c                   @  s:   e Zd ZdeefdefdeefgZg fddZ	dS )WebAuthNHmacSecretSaltValuespGlobalHmacSaltcCredWithHmacSecretSaltListpCredWithHmacSecretSaltListc                 C  s0   |rt || _t|| _tt| | | _d S r"   )r+   r   r   r*   r   r   r   )r   global_saltcredential_saltsr   r   r   r    2  s   


z%WebAuthNHmacSecretSaltValues.__init__N)
r0   r1   r2   r+   r]   r   r   r   rF   r    r   r   r   r   r   *  s    r   c                   @  s(   e Zd ZdZdefdefgZdd ZdS )WebAuthNCredProtectExtensionInz~Maps to WEBAUTHN_CRED_PROTECT_EXTENSION_IN Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L493
    dwCredProtectbRequireCredProtectc                 C  r   r"   )r   r   )r   cred_protectrequire_cred_protectr   r   r   r    G  r   z'WebAuthNCredProtectExtensionIn.__init__N)r0   r1   r2   r3   r   r
   rF   r    r   r   r   r   r   <  s    r   c                   @  s,   e Zd ZdefdefgZedZdd ZdS )WebAuthNCredBlobExtension
cbCredBlob
pbCredBlobCredBlobc                 C  s
   || _ d S r"   )	cred_blob)r   blobr   r   r   r    T  s   
z"WebAuthNCredBlobExtension.__init__N)	r0   r1   r2   r   r-   rF   r   r   r    r   r   r   r   r   L  s    r   c                   @  rG   )WebAuthNExtensionznMaps to WEBAUTHN_EXTENSION Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L317
    pwszExtensionIdentifiercbExtensionpvExtensionc                 C  s*   || _ t|| _tt|t| _d S r"   )r   r+   sizeofr   r,   r   r-   r   )r   
identifierr.   r   r   r   r    d  s   zWebAuthNExtension.__init__N)	r0   r1   r2   r3   r   r   r-   rF   r    r   r   r   r   r   X  s    r   c                   @  rQ   )WebAuthNExtensionszoMaps to WEBAUTHN_EXTENSIONS Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L324
    cExtensionspExtensionsc                 C  s    t || _tt | | | _d S r"   )r*   r   r   r   )r   
extensionsr   r   r   r    u  s   
zWebAuthNExtensions.__init__N)
r0   r1   r2   r3   r   r+   r]   r   rF   r    r   r   r   r   r   j  s    r   c                   @  sH   e Zd ZdZdefdefdefdefgZedZ	dd Z
ed	d
 ZdS )WebAuthNCredentialzMaps to WEBAUTHN_CREDENTIAL Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L212

    :param Dict[str, Any] cred: Dict of Credential Descriptor data.
    rI   ro   rp   rJ   rr   c                 C  s   |d | _ |d | _d S )Nri   rL   )ri   rJ   rz   r   r   r   r      r!   zWebAuthNCredential.__init__c                 C  s   | j | jdS )N)rL   ri   )rJ   ri   rA   r   r   r   
descriptor  s   zWebAuthNCredential.descriptorN)r0   r1   r2   r3   r   r-   r   rF   r   ri   r    propertyr   r   r   r   r   r   z  s    r   c                   @  rQ   )WebAuthNCredentialszMaps to WEBAUTHN_CREDENTIALS Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L219

    :param List[Dict[str, Any]] credentials: List of dict of
        Credential Descriptor data.
    r}   pCredentialsc                 C  rU   )Nc                 s  rV   r"   )r   r   r   r   r   rY     rZ   z/WebAuthNCredentials.__init__.<locals>.<genexpr>)r*   r}   r   r   r   r   r   r   r      r\   zWebAuthNCredentials.__init__N)
r0   r1   r2   r3   r   r+   r]   r   rF   r    r   r   r   r   r     s    	r   c                   @  sv   e Zd ZdZdefdefdefdefdefdefdefd	efd
efdefdefgZe	dZ
e	dZe	dZe	dZdS )CtapCborHybridStorageLinkedDatazMaps to CTAPCBOR_HYBRID_STORAGE_LINKED_DATA Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L356
    rI   cbContactIdpbContactIdcbLinkIdpbLinkIdcbLinkSecretpbLinkSecretcbPublicKeypbPublicKeypwszAuthenticatorNamewEncodedTunnelServerDomain	ContactIdLinkId
LinkSecret	PublicKeyN)r0   r1   r2   r3   r   r-   rm   r   rF   r   
contact_idlink_idlink_secret
public_keyr   r   r   r   r     s$    r   c                   @  s   e Zd ZdZdefdefdefdefdefdefdefd	efd
e	e
fde	efde	efdefdefdefde	efde
fde	efde
fdefdefgZedZedZ					dddZdS )WebAuthNGetAssertionOptionsaG  Maps to WEBAUTHN_AUTHENTICATOR_GET_ASSERTION_OPTIONS Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L452

    :param int timeout: Time that the operation is expected to complete within.
        This is used as guidance, and can be overridden by the platform.
    :param WebAuthNAuthenticatorAttachment attachment: Platform vs Cross-Platform
        Authenticators.
    :param WebAuthNUserVerificationRequirement user_verification_requirement: User
        Verification Requirement.
    :param List[Dict[str,Any]] credentials: Allowed Credentials List.
    rI   dwTimeoutMillisecondsCredentialList
ExtensionsdwAuthenticatorAttachmentdwUserVerificationRequirementdwFlagspwszU2fAppId
pbU2fAppIdpCancellationIdpAllowCredentialListdwCredLargeBlobOperationcbCredLargeBlobpbCredLargeBlobpHmacSecretSaltValuesbBrowserInPrivateModepLinkedDevice	bAutoFill	cbJsonExt	pbJsonExtCredLargeBlobJsonExtNr   c                 C  s   t | jj| _|| _|| _|| _|
| _|	rt|	| _	| jdkr,|| _
|d ur,t|| _| jdkr4|| _| jdkrDt|}t|| _nt|| _| jdkrT|| _|| _| jdkrc|ret|| _d S d S d S )Nr;   r<   r=   r>   r?   )rN   rO   r0   rI   r   r   r   r   r   r   r   r+   r   r   r   r|   r   r   r   r   cred_large_blobr   )r   timeout
attachmentuser_verification_requirementr   cancellationIdcred_large_blob_operationr   hmac_secret_saltsr   flags	u2f_appidu2f_appid_usedclistr   r   r   r      s.   





z$WebAuthNGetAssertionOptions.__init__)NNr   NN)r0   r1   r2   r3   r   r   r   rm   r+   r]   r
   r4   r|   r-   r   r   rF   r   r   json_extr    r   r   r   r   r     s>    r   c                   @  s   e Zd ZdZdefdefdefdefdefdefdefd	efd
efdefdefdefde	e
fdefdefdefgZedZedZedZedZedZdd ZdS )WebAuthNAssertionznMaps to WEBAUTHN_ASSERTION Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L616
    rI   cbAuthenticatorDatapbAuthenticatorDatacbSignaturepbSignature
CredentialcbUserIdpbUserIdr   r   r   dwCredLargeBlobStatuspHmacSecretdwUsedTransportscbUnsignedExtensionOutputspbUnsignedExtensionOutputsr   	SignatureUserIdr   UnsignedExtensionOutputsc                 C     t t|  d S r"   )WEBAUTHNWebAuthNFreeAssertionr+   byrefrA   r   r   r   __del__8     zWebAuthNAssertion.__del__N)r0   r1   r2   r3   r   r-   r   r   r+   r]   r   rF   r   	auth_data	signatureuser_idr   unsigned_extension_outputsr   r   r   r   r   r     s2    r   c                   @  s   e Zd ZdZdefdefdefdefdefdefdefd	efd
efde	e
fde	efdefdefdefdefdefde	efdefdefgZedZ		dddZdS )WebAuthNMakeCredentialOptionsa  maps to WEBAUTHN_AUTHENTICATOR_MAKE_CREDENTIAL_OPTIONS Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L394

    :param int timeout: Time that the operation is expected to complete within.This
        is used as guidance, and can be overridden by the platform.
    :param bool require_resident_key: Require key to be resident or not.
    :param WebAuthNAuthenticatorAttachment attachment: Platform vs Cross-Platform
        Authenticators.
    :param WebAuthNUserVerificationRequirement user_verification_requirement: User
        Verification Requirement.
    :param WebAuthNAttestationConveyancePreference attestation_convoyence:
        Attestation Conveyance Preference.
    :param List[Dict[str,Any]] credentials: Credentials used for exclusion.
    rI   r   r   r   r   bRequireResidentKeyr   !dwAttestationConveyancePreferencer   r   pExcludeCredentialListdwEnterpriseAttestationdwLargeBlobSupportbPreferResidentKeyr   
bEnablePrfr   r   r   r   FNc                 C  s   t | jj| _|| _|| _|| _|| _|| _|rt	|| _
| jdkr%|| _| jdkr3tt|| _nt|| _| jdkrF|| _|	| _|
| _| jdkrP|| _d S d S )Nr;   r<   r=   r?   )rN   rO   r0   rI   r   r  r   r   r  r   r   r   r+   r   r|   r  r   r   r  r	  r
  r  )r   r   require_resident_keyr   r   attestation_convoyencer   r   enterprise_attestationlarge_blob_supportprefer_resident_key
enable_prfr   r   r   r   r    e  s,   






z&WebAuthNMakeCredentialOptions.__init__)FN)r0   r1   r2   r3   r   r   r   r
   r+   r]   r4   r|   r   r-   rF   r   r   r    r   r   r   r   r  <  s4    r  c                   @  s   e Zd ZdZdefdefdefdefdefdefdefd	efd
efdefdefdefdefdefdefdefdefdefdefdefgZ	e
dZe
dZe
dZe
dZe
dZdd ZdS )WebAuthNCredentialAttestationz{Maps to WEBAUTHN_CREDENTIAL_ATTESTATION Struct.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L582
    rI   pwszFormatTyper   r   cbAttestationpbAttestationdwAttestationDecodeTypepvAttestationDecodecbAttestationObjectpbAttestationObjectcbCredentialIdpbCredentialIdr   dwUsedTransportbEpAttbLargeBlobSupportedbResidentKeybPrfEnabledr   r   r   Attestationr   CredentialIdr   c                 C  r   r"   )r   !WebAuthNFreeCredentialAttestationr+   r   rA   r   r   r   r     r   z%WebAuthNCredentialAttestation.__del__N)r0   r1   r2   r3   r   r   r-   r   r
   rF   r   r   attestationattestation_objectcredential_idr  r   r   r   r   r   r    s:    r  c                   @  s   e Zd Zedd ZdS )_FromStringc                 C  s   t | | ddS )N-_)r%   upperreplace)clsr.   r   r   r   from_string  s   z_FromString.from_stringN)r0   r1   r2   classmethodr-  r   r   r   r   r'    s    r'  c                   @      e Zd ZdZdZdZdZdZdS )#WebAuthNUserVerificationRequirementz}Maps to WEBAUTHN_USER_VERIFICATION_REQUIREMENT_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L335
    r   r   r;   r<   N)r0   r1   r2   r3   rx   REQUIRED	PREFERREDDISCOURAGEDr   r   r   r   r0        r0  c                   @  r/  )'WebAuthNAttestationConveyancePreferencezMaps to WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L340
    r   r   r;   r<   N)r0   r1   r2   r3   rx   NONEINDIRECTDIRECTr   r   r   r   r5    r4  r5  c                   @  r/  )WebAuthNAuthenticatorAttachmentzxMaps to WEBAUTHN_AUTHENTICATOR_ATTACHMENT_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L330
    r   r   r;   r<   N)r0   r1   r2   r3   rx   PLATFORMCROSS_PLATFORMCROSS_PLATFORM_U2F_V2r   r   r   r   r9    r4  r9  c                   @  s,   e Zd ZdZdZdZdZdZdZdZ	dZ
d	S )
ry   znMaps to WEBAUTHN_CTAP_TRANSPORT_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L225
    r   r   r;   r=   r9         N)r0   r1   r2   r3   rx   USBNFCBLETESTINTERNAL
FLAGS_MASKr   r   r   r   ry     s    ry   c                   @     e Zd ZdZdZdZdZdS )WebAuthNEnterpriseAttestationzvMaps to WEBAUTHN_ENTERPRISE_ATTESTATION_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L401
    r   r   r;   N)r0   r1   r2   r3   r6  VENDOR_FACILITATEDPLATFORM_MANAGEDr   r   r   r   rF    
    rF  c                   @  rE  )WebAuthNLargeBlobSupportzrMaps to WEBAUTHN_LARGE_BLOB_SUPPORT_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L405
    r   r   r;   N)r0   r1   r2   r3   r6  r1  r2  r   r   r   r   rJ    rI  rJ  c                   @  r/  )WebAuthNLargeBlobOperationztMaps to WEBAUTHN_LARGE_BLOB_OPERATION_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L478
    r   r   r;   r<   N)r0   r1   r2   r3   r6  GETSETDELETEr   r   r   r   rK    r4  rK  c                   @  r/  )WebAuthNUserVerificationzqMaps to WEBAUTHN_USER_VERIFICATION_*.

    https://github.com/microsoft/webauthn/blob/master/webauthn.h#L482
    r   r   r;   r<   N)r0   r1   r2   r3   rx   OPTIONAL OPTIONAL_WITH_CREDENTIAL_ID_LISTr1  r   r   r   r   rO    r4  rO  r<   r=   )re   rn   r^   rH   r   ru   r  r   WebAuthNCommonAttestationr  r   r>   r;   )r  r   r  r   r?   )r  r   r   WebAuthNCredentialDetailsrS  )r  r  r   r@   )r   r;   r<   r=   r>   r?   r@   zMapping[int, Mapping[str, int]]WEBAUTHN_STRUCT_VERSIONS
class_namestrreturnintc                 C  s>   t tddD ]}|tv r| t| v rt| |    S qtd)zGet version of struct.

    :param str class_name: Struct class name.
    :returns: Version of Struct to use.
    :rtype: int
    r   zUnknown class name)rangeWEBAUTHN_API_VERSIONrT  
ValueError)rU  api_versionr   r   r   rN     s   rN   c                      s,   e Zd Z fddZdd Zdd Z  ZS )CancelThreadc                   s:   t    d| _d| _|| _t | _tt	
| j d S )NTF)superr    daemon
_completedeventr4   guidr   WebAuthNGetCancellationIdr+   r   )r   rb  rO   r   r   r      s   
zCancelThread.__init__c                 C  s*   | j   | jstt| j d S d S r"   )rb  waitra  r   WebAuthNCancelCurrentOperationr+   r   rc  rA   r   r   r   run  s   
zCancelThread.runc                 C  s   d| _ | j  |   d S )NT)ra  rb  setjoinrA   r   r   r   complete  s   
zCancelThread.complete)r0   r1   r2   r    rh  rk  __classcell__r   r   re  r   r^    s    r^  c                	   @  sh   e Zd ZdZeZdddZdd Zddej	e
j	ejdddejf	dddZdej	e
j	dddfdddZdS )WinAPIzuImplementation of Microsoft's WebAuthN APIs.

    :param ctypes.HWND handle: Window handle to use for API calls.
    NFc                 C  s0   |pt j | _|stdt || _|| _d S )NzWinAPI will start returning extension outputs in the next major version, to opt in to this behaivor now, set return_extensions=True.)	windlluser32GetForegroundWindowhandlewarningswarnDeprecationWarning_return_extensions_allow_hmac_secret)r   rq  return_extensionsallow_hmac_secretr   r   r   r      s   
zWinAPI.__init__c                 C  s
   t |S )aa  Returns an error name given an error HRESULT value.

        :param int winerror: Windows error code from an OSError.
        :return: An error name.
        :rtype: str

        Example:
            try:
                api.make_credential(*args, **kwargs)
            except OSError as e:
                print(api.get_error_name(e.winerror))
        )r   WebAuthNGetErrorName)r   winerrorr   r   r   get_error_name  s   
zWinAPI.get_error_namer   rW  (Tuple[AttestationObject, Dict[str, Any]]c                 C  sX  t |trtdt g }tj}d}|rd|v r,|tdt	t
|d |dd d|v r<|tdt|d  d|v rKt|d dd	}|d
dr[|td
td d|v rnd}d}|tdtd nd|v r| jrd}|tdtd ni }|rt|}|  tt }t| jtt|tt|tt|tt|tt||dtjfv |||	|
pg |rt |j!nd|||tj"k||t| |r|#  |j$}t%|j&}|j'j(pi }i }|drdt|j)i|d< d|v r|rd|d i|d< n|d |d< d|v r"dt|j*i|d< | j+r*||fS |S )a  Make credential using Windows WebAuthN API.

        :param Dict[str,Any] rp: Relying Party Entity data.
        :param Dict[str,Any] user: User Entity data.
        :param List[Dict[str,Any]] pub_key_cred_params: List of
            PubKeyCredentialParams data.
        :param bytes client_data: ClientData JSON.
        :param int timeout: (optional) Timeout value, in ms.
        :param bool resident_key: (optional) Require resident key, default: False.
        :param WebAuthNAuthenticatorAttachment platform_attachment: (optional)
            Authenticator Attachment, default: any.
        :param WebAuthNUserVerificationRequirement user_verification: (optional)
            User Verification Requirement, default: any.
        :param WebAuthNAttestationConveyancePreference attestation: (optional)
            Attestation Conveyance Preference, default: direct.
        :param List[Dict[str,Any]] exclude_credentials: (optional) List of
            PublicKeyCredentialDescriptor of previously registered credentials.
        :param Any extensions: Currently not supported.
        :param threading.Event event: (optional) Signal to abort the operation.
        zQPassing resident_key as a bool is deprecated. Use ResidentKeyRequirement instead.FcredentialProtectionPolicycredProtect!enforceCredentialProtectionPolicycredBlob	largeBlobsupportnoneminPinLengthTprfzhmac-secrethmacCreateSecretN	credPropsrkenabled	supported),
isinstanceboolrr  rs  rt  rJ  r6  appendr   r   rO  r-  rk   r   r
   rv  r^  startr+   r]   r  r   #WebAuthNAuthenticatorMakeCredentialrq  r   re   rn   rR   r^   r  r   r1  r   rc  r2  rk  contentsr   r%  r   r   r  r  ru  )r   rl   rt   pub_key_cred_paramsrd   r   resident_keyplatform_attachmentuser_verificationr$  exclude_credentialsr   rb  r  win_extensionsr  r  tattestation_pointerobjatt_objextensions_outextension_outputsr   r   r   make_credential  s   
&






zWinAPI.make_credentialFTuple[Dict[str, Any], AuthenticatorData, bytes, bytes, Dict[str, Any]]c	                 C  s  d}	d}
t j}d}g }d}td}|r|dr|d }|dr+|tdtd d|v rD|d d	dr;t j}n	|d d
 }
t j}d|v rm|d d}|d di }t|rat	di |nddd |
 D }nd|v r| jr|	dO }	|d }tt	|d |d}|rt|}|  tt }t| j|tt|tt||||pg |rt|jnd||
|||	||t| |r|  |j}t|j}i }|r|jdkrt|j|d< |r>|r|jdkr|j j}d|v rd|j!i}|j"r|j"|d< d|i|d< nd|j!i}|j"r|j"|d< ||d< |j#dkr>|d d	dr5d|j$i|d< n	d|j#dki|d< | j%rM|j&j'||j(|j)|fS |j&j'||j(|j)fS )a  Get assertion using Windows WebAuthN API.

        :param str rp_id: Relying Party ID string.
        :param bytes client_data: ClientData JSON.
        :param int timeout: (optional) Timeout value, in ms.
        :param WebAuthNAuthenticatorAttachment platform_attachment: (optional)
            Authenticator Attachment, default: any.
        :param WebAuthNUserVerificationRequirement user_verification: (optional)
            User Verification Requirement, default: any.
        :param List[Dict[str,Any]] allow_credentials: (optional) List of
            PublicKeyCredentialDescriptor of previously registered credentials.
        :param Any extensions: Currently not supported.
        :param threading.Event event: (optional) Signal to abort the operation.
        r   NFappidgetCredBlobr  Tr  readwriter  evalevalByCredentialc                 S  s(   g | ]\}}t t|td i |qS )r   )r   r   r   )rW   r   saltsr   r   r   
<listcomp>  s    z(WinAPI.get_assertion.<locals>.<listcomp>hmacGetSecreti   salt1salt2r;   r<   r   r   resultsoutput1output2r   writtenr   r   )*rK  r6  r
   rk   r  r   rL  rM  r   r   itemsrv  r^  r  r+   r]   r   r   !WebAuthNAuthenticatorGetAssertionrq  r   r^   r   r   rc  rk  r  r   r   rI   r  r.   r   r   r   r   r   ru  r   r   r  r  )r   rp_idrd   r   r  r  allow_credentialsr   rb  r   
large_bloblarge_blob_operationr   r  r   r   global_salts
cred_saltsr  r  assertion_pointerr  r   r  secretresultr   r   r   get_assertionU  s   









	zWinAPI.get_assertion)NFF)rW  r|  )rW  r  )r0   r1   r2   r3   r[  versionr    r{  r9  rx   r0  r5  r8  rF  r6  r  r  r   r   r   r   rm    s.    
 rm  )rU  rV  rW  rX  )Zr3   
__future__r   utilsr   webauthnr   r   r   enumr   r	   ctypes.wintypesr
   r   r   r   r   r   	threadingr   typingr   r   r   r   r+   r   r   rr  rn  r]   rE   r-   	c_wchar_prm   r   	Structurer4   rH   rR   r^   re   rn   ru   r|   r   r   r   r   r   r   r   r   r   r   r   r   r  r  objectr'  r0  r5  r9  ry   rF  rJ  rK  rO  HRESULTr   WebAuthNGetApiVersionNumberr[  c_bool5WebAuthNIsUserVerifyingPlatformAuthenticatorAvailableargtypesrestyper  r  r#  r   rd  rg  ry  rT  __annotations__rN   r^  rm  r   r   r   r   <module>   s    V#U'
	

,