Novell.Directory.Ldap.LdapConnection.stopTLS C# (CSharp) Method

stopTLS() public method

Stops Transport Layer Security(TLS) on the LDAPConnection and reverts back to an anonymous state. @throws LDAPException This can occur for the following reasons:
  • StartTLS has not been called before stopTLS
  • There exists outstanding messages that have not received all responses
  • The sever was not able to support the operation

Note: The Sun and IBM implementions of JSSE do not currently allow stopping TLS on an open Socket. In order to produce the same results this method currently disconnects the socket and reconnects, giving the application an anonymous connection to the server, as required by StopTLS

public stopTLS ( ) : void
return void
        public virtual void stopTLS()
        {
            if (!TLS)
            {
                throw new LdapLocalException(ExceptionMessages.NO_STARTTLS, LdapException.OPERATIONS_ERROR);
            }

            int semaphoreID = conn.acquireWriteSemaphore();
            try
            {
                if (!conn.areMessagesComplete())
               {
                    throw new LdapLocalException(ExceptionMessages.OUTSTANDING_OPERATIONS, LdapException.OPERATIONS_ERROR);
                }
                //stopTLS stops and starts the reader thread for us.
                conn.stopTLS();
            }
            finally
            {
                conn.freeWriteSemaphore(semaphoreID);

                /* Now that the TLS socket is closed, reset everything.  This next
                line is temporary until JSSE is fixed to properly handle TLS stop */
                this.Connect(this.Host, this.Port);
            }
            return ;
        }

Usage Example

コード例 #1
0
ファイル: StartTLS.cs プロジェクト: EventStore/csharp-ldap
        static void Main(string[] args)
        {
            if ( args.Length != 4)
            {
            Console.WriteLine("Usage:   mono StartTLS <host name> <ldap port>  <login dn>" + " <password>  ");
            Console.WriteLine("Example: mono StartTLS Acme.com 389"  + " \"cn=admin,o=Acme\"" + " secret  \n");
            Console.WriteLine("Import the server Trusted Root Certificate in Mono trust store using certmgr.exe utility e.g.\n");
                        Console.WriteLine("certmgr -add -c Trust /home/exports/TrustedRootCert.cer\n");

            return;
            }

            string ldapHost = args[0];
            int ldapPort = System.Convert.ToInt32(args[1]);
            String loginDN  = args[2];
            String password = args[3];
            try
            {
            LdapConnection conn= new LdapConnection();
            Console.WriteLine("Connecting to:" + ldapHost);
            conn.Connect(ldapHost,ldapPort);
            conn.startTLS();
            conn.Bind(loginDN,password);
            Console.WriteLine("TLS Bind Completed Successfull");
            conn.stopTLS();
            Console.WriteLine("Stop TLS Completed Successfull");
            conn.Disconnect();
            }
            catch(Exception e)
            {
            Console.WriteLine("Error:" + e.Message);
            }
        }