Пример #1
0
 public void Close()
 {
     OpenSslNative.SSL_shutdown(_ssl);
     if (_socket.Connected)
     {
         _socket.Close();
     }
 }
Пример #2
0
        private static IntPtr GetMethodFromProtocol(OpenSslProtocol protocol, bool server)
        {
            IntPtr method = IntPtr.Zero;

            switch (protocol)
            {
            case OpenSslProtocol.AutoDetect:
                if (server)
                {
                    method = OpenSslNative.SSLv23_server_method();
                }
                else
                {
                    method = OpenSslNative.SSLv23_client_method();
                }
                break;

            case OpenSslProtocol.SSLv2:
                if (server)
                {
                    method = OpenSslNative.SSLv2_server_method();
                }
                else
                {
                    method = OpenSslNative.SSLv2_client_method();
                }
                break;

            case OpenSslProtocol.SSLv3:
                if (server)
                {
                    method = OpenSslNative.SSLv3_server_method();
                }
                else
                {
                    method = OpenSslNative.SSLv3_client_method();
                }
                break;

            case OpenSslProtocol.TLSv1:
                if (server)
                {
                    method = OpenSslNative.TLSv1_server_method();
                }
                else
                {
                    method = OpenSslNative.TLSv1_client_method();
                }
                break;

            default:
                break;
            }

            return(OpenSslUtility.AssertNotNull(method));
        }
Пример #3
0
 public static string GetErrorMessage(uint err)
 {
     if (err == 0)
     {
         return("Unknown OpenSSL Error");
     }
     byte[] buf = new byte[1024];
     OpenSslNative.ERR_error_string_n(err, buf, buf.Length);
     return(Encoding.ASCII.GetString(buf));
 }
Пример #4
0
        public static string GetErrorMessages()
        {
            StringBuilder sb = new StringBuilder();

            for (; ;)
            {
                uint err = OpenSslNative.ERR_get_error();
                if (err == 0)
                {
                    break;
                }
                sb.AppendLine(GetErrorMessage(err));
            }
            return(sb.ToString().TrimEnd());
        }
Пример #5
0
 public void Write(byte[] buffer, int offset, int count)
 {
     if (buffer.Length < (count + offset))
     {
         count = buffer.Length - offset;
     }
     if (offset == 0)
     {
         OpenSslNative.SSL_write(_ssl, buffer, count);
     }
     else if (count > 0)
     {
         byte[] temp = new byte[count];
         Buffer.BlockCopy(buffer, offset, temp, 0, count);
         OpenSslNative.SSL_write(_ssl, temp, (int)count);
     }
 }
Пример #6
0
 public int Read(byte[] buffer, int offset, int count)
 {
     if (buffer.Length < (count + offset))
     {
         count = buffer.Length - offset;
     }
     if (offset == 0)
     {
         return(OpenSslNative.SSL_read(_ssl, buffer, count));
     }
     else
     {
         byte[] temp = new byte[count];
         int    res  = OpenSslNative.SSL_read(_ssl, temp, count);
         if (res > 0)
         {
             Buffer.BlockCopy(temp, 0, buffer, offset, res);
         }
         return(res);
     }
 }
Пример #7
0
 public void Dispose()
 {
     OpenSslNative.BIO_free(_bio);
 }
Пример #8
0
 public static OpenSslBIO FromFile(string file)
 {
     return(new OpenSslBIO(OpenSslUtility.AssertNotNull(OpenSslNative.BIO_new_file(file, "r"))));
 }
Пример #9
0
 public OpenSslCertificate(OpenSslBIO bio)
 {
     _x509 = OpenSslUtility.AssertNotNull(OpenSslNative.PEM_read_bio_X509(bio.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
 }
Пример #10
0
 public void Dispose()
 {
     OpenSslNative.SSL_free(_ssl);
 }
Пример #11
0
 public OpenSslContext(OpenSslProtocol protocol, bool server)
 {
     _ctx = OpenSslUtility.AssertNotNull(OpenSslNative.SSL_CTX_new(GetMethodFromProtocol(protocol, server)));
 }
Пример #12
0
 public void Connect(Socket socket)
 {
     InitializeSocket(socket);
     OpenSslUtility.AssertSuccess(OpenSslNative.SSL_connect(_ssl));
 }
Пример #13
0
 public OpenSslConnection(OpenSslContext ctx)
 {
     _context = ctx;
     _ssl     = OpenSslUtility.AssertNotNull(OpenSslNative.SSL_new(_context.Handle));
 }
Пример #14
0
 public void Dispose()
 {
     OpenSslNative.SSL_CTX_free(_ctx);
 }
Пример #15
0
 public void Dispose()
 {
     OpenSslNative.X509_free(_x509);
 }
Пример #16
0
 private void InitializeSocket(Socket socket)
 {
     OpenSslUtility.AssertSuccess(OpenSslNative.SSL_set_fd(_ssl, socket.Handle.ToInt32()));
     _socket = socket;
 }
Пример #17
0
 public OpenSslPrivateKey(OpenSslBIO bio)
 {
     _pkey = OpenSslUtility.AssertNotNull(OpenSslNative.PEM_read_bio_PrivateKey(bio.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
 }
Пример #18
0
 public void Dispose()
 {
     OpenSslNative.EVP_PKEY_free(_pkey);
 }