Beispiel #1
0
 void ReleaseAuth()
 {
     _srp256 = null;
     _srp    = null;
     _sspi?.Dispose();
     _sspi = null;
 }
Beispiel #2
0
        public void Identify(string database)
        {
            using (var xdrStream = CreateXdrStreamImpl(false))
            {
                try
                {
                    xdrStream.Write(IscCodes.op_connect);
                    xdrStream.Write(IscCodes.op_attach);
                    xdrStream.Write(IscCodes.CONNECT_VERSION3);
                    xdrStream.Write(IscCodes.GenericAchitectureClient);

                    xdrStream.Write(database);

                    var protocols = ProtocolsSupported.Get(_compression);
                    xdrStream.Write(protocols.Count());
                    xdrStream.WriteBuffer(UserIdentificationData());

                    var priority = 0;
                    foreach (var protocol in protocols)
                    {
                        xdrStream.Write(protocol.Version);
                        xdrStream.Write(IscCodes.GenericAchitectureClient);
                        xdrStream.Write(protocol.MinPType);
                        xdrStream.Write(protocol.MaxPType);
                        xdrStream.Write(priority);

                        priority++;
                    }

                    xdrStream.Flush();

                    var operation = xdrStream.ReadOperation();
                    if (operation == IscCodes.op_accept || operation == IscCodes.op_cond_accept || operation == IscCodes.op_accept_data)
                    {
                        _protocolVersion      = xdrStream.ReadInt32();
                        _protocolArchitecture = xdrStream.ReadInt32();
                        _protocolMinimunType  = xdrStream.ReadInt32();

                        if (_protocolVersion < 0)
                        {
                            _protocolVersion = (ushort)(_protocolVersion & IscCodes.FB_PROTOCOL_MASK) | IscCodes.FB_PROTOCOL_FLAG;
                        }

                        if (_compression && !((_protocolMinimunType & IscCodes.pflag_compress) != 0))
                        {
                            _compression = false;
                        }

                        if (operation == IscCodes.op_cond_accept || operation == IscCodes.op_accept_data)
                        {
                            var data             = xdrStream.ReadBuffer();
                            var acceptPluginName = xdrStream.ReadString();
                            var isAuthenticated  = xdrStream.ReadBoolean();
                            var keys             = xdrStream.ReadString();
                            if (!isAuthenticated)
                            {
                                switch (acceptPluginName)
                                {
                                case SrpClient.PluginName:
                                    _authData = Encoding.ASCII.GetBytes(_srp.ClientProof(NormalizeLogin(_userID), _password, data).ToHexString());
                                    break;

                                case SspiHelper.PluginName:
                                    _authData = _sspi.GetClientSecurity(data);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException(nameof(acceptPluginName), $"{nameof(acceptPluginName)}={acceptPluginName}");
                                }
                            }
                        }
                    }
                    else if (operation == IscCodes.op_response)
                    {
                        var response = (GenericResponse)ProcessOperation(operation, xdrStream);
                        throw response.Exception;
                    }
                    else
                    {
                        try
                        {
                            Disconnect();
                        }
                        catch
                        { }
                        finally
                        {
                            throw IscException.ForErrorCode(IscCodes.isc_connect_reject);
                        }
                    }
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
                }
                finally
                {
                    // UserIdentificationData might allocate these
                    _srp = null;
                    _sspi?.Dispose();
                    _sspi = null;
                }
            }
        }