/// <summary> /// Connect to the given host on the port asynchronously /// </summary> /// <param name="host">The host to connect to</param> /// <param name="port">The port to use for communication</param> public async Task ConnectAsync(string host, int port) { // Don't reconnect if (_state == LDAPConnectionState.Connected) { return; } try { await _conn.ConnectAsync(host, port); if (_sslEnabled) { _raw = _conn.GetStream(); var options = new SslClientAuthenticationOptions { TargetHost = host, EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, ClientCertificates = null, LocalCertificateSelectionCallback = null, CertificateRevocationCheckMode = X509RevocationMode.NoCheck, RemoteCertificateValidationCallback = (sender, cert, chain, errors) => { // Accept all...bad idea return(true); }, ApplicationProtocols = new List <SslApplicationProtocol>() { SslApplicationProtocol.Http11 }, EncryptionPolicy = EncryptionPolicy.RequireEncryption, }; _transport = new SslStream(_raw); await(_transport as SslStream).AuthenticateAsClientAsync(options, CancellationToken.None); Reader = new LDAPReader(_transport); Writer = new LDAPWriter(_transport); } else { _raw = _conn.GetStream(); _transport = null; Reader = new LDAPReader(_raw); Writer = new LDAPWriter(_raw); } // Create the pump and start it _pump = new MessagePump(Reader, _raw, _log); _pump.Start(); _state = LDAPConnectionState.Connected; } catch (Exception e) { _state = LDAPConnectionState.Faulted; throw new LDAPException("Failed to connect", e); } }
protected override async Task WriteContentsAsync(LDAPWriter writer) { var opWriter = new LDAPWriter(); await opWriter.WriteAsync(Version); await opWriter.WriteAsync(Name); await Authentication.WriteAsync(opWriter); await writer.WriteAsync(opWriter, 0, EncodingScope.APPLICATION); }
public async Task WriteAsync(LDAPWriter writer) { // Buffer the sequence to a memory stream first var opWriter = new LDAPWriter(); await opWriter.WriteAsync(MessageId); // Write the op choice await WriteContentsAsync(opWriter); // Write the message as a generic sequence await writer.WriteAsync(opWriter); }
protected override async Task WriteContentsAsync(LDAPWriter writer) { var opWriter = new LDAPWriter(); await opWriter.WriteAsync(DistinguishedName); var attrWriter = new LDAPWriter(); foreach (var attr in Attributes ?? new LDAPAttribute[] { }) { await attrWriter.WriteAsync(attr); } await opWriter.WriteAsync(attrWriter); await writer.WriteAsync(opWriter, (int)Operation, EncodingScope.APPLICATION); }
protected override async Task WriteContentsAsync(LDAPWriter writer) { var opWriter = new LDAPWriter(); await opWriter.WriteAsync(DistinguishedName); await opWriter.WriteAsync((int)Scope); await opWriter.WriteAsync((int)Aliasing); await opWriter.WriteAsync(SizeLimit); await opWriter.WriteAsync(TimeLimit); await opWriter.WriteAsync(TypesOnly); // Encode filters here await opWriter.WriteAsync(Filter); // Attributes if (Attributes == null || Attributes.Length == 0) { await opWriter.WriteNullAsync(); } else { var atWriter = new LDAPWriter(); foreach (var s in Attributes) { await atWriter.WriteAsync(s); } await opWriter.WriteAsync(atWriter); } await writer.WriteAsync(opWriter, 3, EncodingScope.APPLICATION); }
protected override async Task WriteContentsAsync(LDAPWriter writer) { var opWriter = new LDAPWriter(); await opWriter.WriteAsync(DistinguishedName); var modWriter = new LDAPWriter(); foreach (var attr in Added ?? new LDAPAttribute[0]) { var w = new LDAPWriter(); await w.WriteAsync(attr); await modWriter.WriteAsync(w, 0, EncodingScope.CONTEXT_SPECIFIC); } foreach (var attr in Removed ?? new LDAPAttribute[0]) { var w = new LDAPWriter(); await w.WriteAsync(attr); await modWriter.WriteAsync(w, 1, EncodingScope.CONTEXT_SPECIFIC); } foreach (var attr in Modified ?? new LDAPAttribute[0]) { var w = new LDAPWriter(); await w.WriteAsync(attr); await modWriter.WriteAsync(w, 2, EncodingScope.CONTEXT_SPECIFIC); } await opWriter.WriteAsync(modWriter); await writer.WriteAsync(opWriter, (int)Operation, EncodingScope.APPLICATION); }
public override async Task WriteAsync(LDAPWriter writer) => // Tag for simple is 0 await writer.WriteAsync(Credentials, 0, EncodingScope.CONTEXT_SPECIFIC);
public abstract Task WriteAsync(LDAPWriter writer);
protected override async Task WriteContentsAsync(LDAPWriter writer) => await writer.WriteAsync(DistinguishedName, 10, EncodingScope.APPLICATION);
protected override async Task WriteContentsAsync(LDAPWriter writer) => await writer.WriteNullAsync(2, EncodingScope.APPLICATION);
protected abstract Task WriteContentsAsync(LDAPWriter writer);