Ejemplo n.º 1
0
        public static WebAuthnResult AuthenticatorGetAssertion(
            IntPtr window,
            string rpId,
            ClientData clientData,
            AuthenticatorGetAssertionOptions getOptions,
            out Assertion assertion)
        {
            //TODO: extensions
            assertion = null;

            var rawClientData = new RawClientData(clientData);
            var rawGetOptions = getOptions == null
                ? null
                : new RawAuthenticatorGetAssertionOptions(getOptions);

            var res = RawAuthenticatorGetAssertion(window, rpId, rawClientData, rawGetOptions, out var rawAsnPtr);

            if (rawAsnPtr != IntPtr.Zero)
            {
                var rawAssertion = Marshal.PtrToStructure <RawAssertion>(rawAsnPtr);
                assertion = rawAssertion?.MarshalToPublic();

                if (assertion != null && rawGetOptions != null)
                {
                    assertion.U2fAppIdUsed = rawGetOptions.CheckU2fAppIdUsed();
                }

                FreeRawAssertion(rawAsnPtr);
            }

            rawClientData.Dispose();
            rawGetOptions?.Dispose();

            return(res);
        }
Ejemplo n.º 2
0
        public RawAuthenticatorGetAssertionOptions(AuthenticatorGetAssertionOptions getOptions)
        {
            AllowCredentialsList = new RawCredentialsList(getOptions.AllowedCredentials);

            if (getOptions.AllowedCredentialsEx?.Count > 0)
            {
                _allowedCredentialsExList = new RawCredentialExList(getOptions.AllowedCredentialsEx);
                AllowCredentialsExListPtr = Marshal.AllocHGlobal(Marshal.SizeOf <RawCredentialExList>());
                Marshal.StructureToPtr(_allowedCredentialsExList, AllowCredentialsExListPtr, false);
            }

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

            U2fAppId            = getOptions.U2fAppId;
            U2fAppIdUsedBoolPtr = Marshal.AllocHGlobal(Marshal.SizeOf <bool>());

            TimeoutMilliseconds         = getOptions.TimeoutMilliseconds;
            AuthenticatorAttachment     = getOptions.AuthenticatorAttachment;
            UserVerificationRequirement = getOptions.UserVerificationRequirement;

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