Пример #1
0
        public static WebAuthnResult AuthenticatorMakeCredential(IntPtr window,
                                                                 RelayingPartyInfo rp,
                                                                 UserInfo user,
                                                                 ICollection <CoseCredentialParameter> coseParams,
                                                                 ClientData clientData,
                                                                 AuthenticatorMakeCredentialOptions makeOptions,
                                                                 out CredentialAttestation credential)
        {
            //TODO: extensions
            credential = null;

            var rawUser            = new RawUserInfo(user);
            var rawCredList        = new RawCoseCredentialParameters(coseParams);
            var rawClientData      = new RawClientData(clientData);
            var rawMakeCredOptions = makeOptions == null
                ? null
                : new RawAuthenticatorMakeCredentialOptions(makeOptions);

            var res = RawAuthenticatorMakeCredential(window, rp, rawUser, rawCredList, rawClientData,
                                                     rawMakeCredOptions, out var rawCredPtr);

            if (rawCredPtr != IntPtr.Zero)
            {
                var rawCredObj = Marshal.PtrToStructure <RawCredentialAttestation>(rawCredPtr);
                credential = rawCredObj?.MarshalToPublic();
                FreeRawCredentialAttestation(rawCredPtr);
            }

            rawUser.Dispose();
            rawCredList.Dispose();
            rawClientData.Dispose();
            rawMakeCredOptions?.Dispose();

            return(res);
        }
        public RawAuthenticatorMakeCredentialOptions(AuthenticatorMakeCredentialOptions makeOptions)
        {
            ExcludeCredentialsList = new RawCredentialsList(makeOptions.ExcludeCredentials);

            if (makeOptions.ExcludeCredentialsEx?.Count > 0)
            {
                _excludeCredentialsExList = new RawCredentialExList(makeOptions.ExcludeCredentialsEx);
                ExcludeCredentialsExListPtr = Marshal.AllocHGlobal(Marshal.SizeOf<RawCredentialExList>());
                Marshal.StructureToPtr(_excludeCredentialsExList, ExcludeCredentialsExListPtr, false);
            }

            CancellationId = IntPtr.Zero;
            if (makeOptions.CancellationId.HasValue)
            {
                CancellationId = Marshal.AllocHGlobal(Marshal.SizeOf<Guid>());
                Marshal.StructureToPtr(makeOptions.CancellationId.Value, CancellationId, false);
            }

            TimeoutMilliseconds = makeOptions.TimeoutMilliseconds;
            AuthenticatorAttachment = makeOptions.AuthenticatorAttachment;
            UserVerificationRequirement = makeOptions.UserVerificationRequirement;
            AttestationConveyancePreference = makeOptions.AttestationConveyancePreference;
            RequireResidentKey = makeOptions.RequireResidentKey;

            Extensions = new RawWebauthnExtensions { Count = 0, Extensions = IntPtr.Zero }; //TODO
        }