Esempio n. 1
0
        public override async ValueTask AttachAsync(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey, CancellationToken cancellationToken = default)
        {
            try
            {
                await SendAttachToBufferAsync(dpb, database, cancellationToken).ConfigureAwait(false);

                await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                var response = await ReadResponseAsync(cancellationToken).ConfigureAwait(false);

                if (response is ContAuthResponse)
                {
                    while (response is ContAuthResponse contAuthResponse)
                    {
                        AuthBlock.Start(contAuthResponse.ServerData, contAuthResponse.AcceptPluginName, contAuthResponse.IsAuthenticated, contAuthResponse.ServerKeys);

                        await AuthBlock.SendContAuthToBufferAsync(Xdr, cancellationToken).ConfigureAwait(false);

                        await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                        response = await AuthBlock.ProcessContAuthResponseAsync(Xdr, cancellationToken).ConfigureAwait(false);

                        response = await ProcessCryptCallbackResponseIfNeededAsync(response, cryptKey, cancellationToken).ConfigureAwait(false);
                    }
                    var genericResponse = (GenericResponse)response;
                    await ProcessAttachResponseAsync(genericResponse, cancellationToken).ConfigureAwait(false);

                    if (genericResponse.Data.Any())
                    {
                        await AuthBlock.SendWireCryptToBufferAsync(Xdr, cancellationToken).ConfigureAwait(false);

                        await Xdr.FlushAsync(cancellationToken).ConfigureAwait(false);

                        await AuthBlock.ProcessWireCryptResponseAsync(Xdr, _connection, cancellationToken).ConfigureAwait(false);
                    }
                }
                else
                {
                    response = await ProcessCryptCallbackResponseIfNeededAsync(response, cryptKey, cancellationToken).ConfigureAwait(false);
                    await ProcessAttachResponseAsync((GenericResponse)response, cancellationToken).ConfigureAwait(false);

                    AuthBlock.Complete();
                }
                AuthBlock.WireCryptValidate(IscCodes.PROTOCOL_VERSION13);
            }
            catch (IscException)
            {
                await SafelyDetachAsync(cancellationToken).ConfigureAwait(false);

                throw;
            }
            catch (IOException ex)
            {
                await SafelyDetachAsync(cancellationToken).ConfigureAwait(false);

                throw IscException.ForIOException(ex);
            }

            await AfterAttachActionsAsync(cancellationToken).ConfigureAwait(false);
        }
Esempio n. 2
0
        public override void Attach(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey)
        {
            try
            {
                SendAttachToBuffer(dpb, database);
                Xdr.Flush();
                var response = ReadResponse();
                if (response is ContAuthResponse)
                {
                    while (response is ContAuthResponse contAuthResponse)
                    {
                        AuthBlock.Start(contAuthResponse.ServerData, contAuthResponse.AcceptPluginName, contAuthResponse.IsAuthenticated, contAuthResponse.ServerKeys);

                        AuthBlock.SendContAuthToBuffer(Xdr);
                        Xdr.Flush();
                        response = AuthBlock.ProcessContAuthResponse(Xdr);
                        response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey);
                    }
                    var genericResponse = (GenericResponse)response;
                    ProcessAttachResponse(genericResponse);

                    if (genericResponse.Data.Any())
                    {
                        AuthBlock.SendWireCryptToBuffer(Xdr);
                        Xdr.Flush();
                        AuthBlock.ProcessWireCryptResponse(Xdr, _connection);
                    }
                }
                else
                {
                    response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey);
                    ProcessAttachResponse((GenericResponse)response);
                    AuthBlock.Complete();
                }
                AuthBlock.WireCryptValidate(IscCodes.PROTOCOL_VERSION13);
            }
            catch (IscException)
            {
                SafelyDetach();
                throw;
            }
            catch (IOException ex)
            {
                SafelyDetach();
                throw IscException.ForIOException(ex);
            }

            AfterAttachActions();
        }
Esempio n. 3
0
    public override void CreateDatabase(DatabaseParameterBufferBase dpb, string database, byte[] cryptKey)
    {
        try
        {
            SendCreateToBuffer(dpb, database);
            Xdr.Flush();
            var response = ReadResponse();
            if (response is ContAuthResponse)
            {
                while (response is ContAuthResponse contAuthResponse)
                {
                    AuthBlock.Start(contAuthResponse.ServerData, contAuthResponse.AcceptPluginName, contAuthResponse.IsAuthenticated, contAuthResponse.ServerKeys);

                    AuthBlock.SendContAuthToBuffer();
                    Xdr.Flush();
                    response = AuthBlock.ProcessContAuthResponse();
                    response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey);
                }
                var genericResponse = (GenericResponse)response;
                ProcessCreateResponse(genericResponse);

                if (genericResponse.Data.Any())
                {
                    AuthBlock.SendWireCryptToBuffer();
                    Xdr.Flush();
                    AuthBlock.ProcessWireCryptResponse();
                }
            }
            else
            {
                response = ProcessCryptCallbackResponseIfNeeded(response, cryptKey);
                ProcessCreateResponse((GenericResponse)response);
                AuthBlock.Complete();
            }
        }
        catch (IOException ex)
        {
            throw IscException.ForIOException(ex);
        }
    }