当前位置: 首页>>代码示例>>C#>>正文


C# SafeHandles.SafeSslContextHandle类代码示例

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeSslContextHandle的典型用法代码示例。如果您正苦于以下问题:C# SafeSslContextHandle类的具体用法?C# SafeSslContextHandle怎么用?C# SafeSslContextHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SafeSslContextHandle类属于Microsoft.Win32.SafeHandles命名空间,在下文中一共展示了SafeSslContextHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

            public static SafeSslHandle Create(SafeSslContextHandle context, bool isServer)
            {
                IntPtr memMethod = libcrypto.BIO_s_mem();

                SafeBioHandle readBio = libcrypto.BIO_new(memMethod);
                if (readBio.IsInvalid)
                {
                    return new SafeSslHandle();
                }

                SafeBioHandle writeBio = libcrypto.BIO_new(memMethod);
                if (writeBio.IsInvalid)
                {
                    readBio.Dispose();
                    return new SafeSslHandle();
                }
                
                SafeSslHandle handle = SSL_new(context);
                if (handle.IsInvalid)
                {
                    readBio.Dispose();
                    writeBio.Dispose();
                    return handle;
                }
                handle._isServer = isServer;

                // After SSL_set_bio, the BIO handles are owned by SSL pointer
                // and are automatically freed by SSL_free. To prevent a double
                // free, we need to keep the ref counts bumped up till SSL_free
                bool gotRef = false;
                readBio.DangerousAddRef(ref gotRef);
                try
                {
                    bool ignore = false;
                    writeBio.DangerousAddRef(ref ignore);
                }
                catch
                {
                    if (gotRef)
                    {
                        readBio.DangerousRelease();
                    }
                    throw;
                }

                SSL_set_bio(handle, readBio, writeBio);
                handle._readBio = readBio;
                handle._writeBio = writeBio;

                if (isServer)
                {
                    SSL_set_accept_state(handle);
                }
                else
                {
                    SSL_set_connect_state(handle);
                }
                return handle;
            }
开发者ID:rainersigwald,项目名称:corefx,代码行数:59,代码来源:Interop.SafeSslHandle.cs

示例2: SetSslCtxVerifyCallback

            private static CURLcode SetSslCtxVerifyCallback(
                IntPtr curl,
                IntPtr sslCtx)
            {
                using (SafeSslContextHandle ctx = new SafeSslContextHandle(sslCtx, ownsHandle: false))
                {
                    Interop.Ssl.SslCtxSetCertVerifyCallback(ctx, s_sslVerifyCallback, IntPtr.Zero);
                }

                return CURLcode.CURLE_OK;
            }
开发者ID:ReedKimble,项目名称:corefx,代码行数:11,代码来源:CurlHandler.SslProvider.cs

示例3: SetSslCtxVerifyCallback

            private static int SetSslCtxVerifyCallback(
                IntPtr curl,
                IntPtr sslCtx,
                IntPtr userPtr)
            {
                using (SafeSslContextHandle ctx = new SafeSslContextHandle(sslCtx, ownsHandle: false))
                {
                    Interop.Ssl.SslCtxSetCertVerifyCallback(ctx, s_sslVerifyCallback, userPtr);
                }

                return Interop.libcurl.CURLcode.CURLE_OK;
            }
开发者ID:nadyalo,项目名称:corefx,代码行数:12,代码来源:CurlHandler.SslProvider.cs

示例4: SetSslCtxVerifyCallback

            private static CURLcode SetSslCtxVerifyCallback(
                IntPtr curl,
                IntPtr sslCtx,
                IntPtr userPointer)
            {
                using (SafeSslContextHandle ctx = new SafeSslContextHandle(sslCtx, ownsHandle: false))
                {
                    Interop.Ssl.SslCtxSetCertVerifyCallback(ctx, s_sslVerifyCallback, curl);

                    if (userPointer == IntPtr.Zero)
                    {
                        VerboseTrace("Not using client Certificate callback ");
                    }
                    else
                    {
                        ClientCertificateProvider provider = null;
                        try
                        {
                            GCHandle handle = GCHandle.FromIntPtr(userPointer);
                            provider = (ClientCertificateProvider)handle.Target;
                        }
                        catch (InvalidCastException)
                        {
                            Debug.Fail("ClientCertificateProvider wasn't the GCHandle's Target");
                            return CURLcode.CURLE_ABORTED_BY_CALLBACK;
                        }
                        catch (InvalidOperationException)
                        {
                            Debug.Fail("Invalid GCHandle in CurlSslCallback");
                            return CURLcode.CURLE_ABORTED_BY_CALLBACK;
                        }

                        Debug.Assert(provider != null, "Expected non-null sslCallback in curlCallBack");
                        Interop.Ssl.SslCtxSetClientCertCallback(ctx, provider._callback);
                    }
                }
                return CURLcode.CURLE_OK;
            }
开发者ID:rahulkotecha,项目名称:corefx,代码行数:38,代码来源:CurlHandler.SslProvider.cs

示例5: SetEncryptionPolicy

 internal static extern void SetEncryptionPolicy(SafeSslContextHandle ctx, EncryptionPolicy policy);
开发者ID:ReedKimble,项目名称:corefx,代码行数:1,代码来源:Interop.Ssl.cs

示例6: SslCtxSetVerify

 internal static extern void SslCtxSetVerify(SafeSslContextHandle ctx, SslCtxSetVerifyCallback callback);
开发者ID:ReedKimble,项目名称:corefx,代码行数:1,代码来源:Interop.Ssl.cs

示例7: SslCtxSetQuietShutdown

 internal static extern void SslCtxSetQuietShutdown(SafeSslContextHandle ctx);
开发者ID:ReedKimble,项目名称:corefx,代码行数:1,代码来源:Interop.Ssl.cs

示例8: SslCtxCheckPrivateKey

 internal static extern int SslCtxCheckPrivateKey(SafeSslContextHandle ctx);
开发者ID:ReedKimble,项目名称:corefx,代码行数:1,代码来源:Interop.Ssl.cs

示例9: SslCtxUsePrivateKey

 internal static extern int SslCtxUsePrivateKey(SafeSslContextHandle ctx, SafeEvpPKeyHandle keyPtr);
开发者ID:ReedKimble,项目名称:corefx,代码行数:1,代码来源:Interop.Ssl.cs

示例10: SSL_CTX_set_cipher_list

 internal static extern int SSL_CTX_set_cipher_list(SafeSslContextHandle ctx, string policy);
开发者ID:bbologna,项目名称:corefx,代码行数:1,代码来源:Interop.libssl.cs

示例11: SSL_new

 internal static extern SafeSslHandle SSL_new(SafeSslContextHandle ctx);
开发者ID:shrutigarg,项目名称:corefx,代码行数:1,代码来源:Interop.libssl.cs

示例12: Create

        public static SafeSslHandle Create(SafeSslContextHandle context, bool isServer)
        {
            SafeBioHandle readBio = Interop.Crypto.CreateMemoryBio();
            SafeBioHandle writeBio = Interop.Crypto.CreateMemoryBio();
            SafeSslHandle handle = Interop.Ssl.SslCreate(context);
            if (readBio.IsInvalid || writeBio.IsInvalid || handle.IsInvalid)
            {
                readBio.Dispose();
                writeBio.Dispose();
                handle.Dispose(); // will make IsInvalid==true if it's not already
                return handle;
            }
            handle._isServer = isServer;

            // SslSetBio will transfer ownership of the BIO handles to the SSL context
            try
            {
                readBio.TransferOwnershipToParent(handle);
                writeBio.TransferOwnershipToParent(handle);
                handle._readBio = readBio;
                handle._writeBio = writeBio;
                Interop.Ssl.SslSetBio(handle, readBio, writeBio);
            }
            catch (Exception exc)
            {
                // The only way this should be able to happen without thread aborts is if we hit OOMs while
                // manipulating the safe handles, in which case we may leak the bio handles.
                Debug.Fail("Unexpected exception while transferring SafeBioHandle ownership to SafeSslHandle", exc.ToString());
                throw;
            }

            if (isServer)
            {
                Interop.Ssl.SslSetAcceptState(handle);
            }
            else
            {
                Interop.Ssl.SslSetConnectState(handle);
            }
            return handle;
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:41,代码来源:Interop.Ssl.cs

示例13: SSL_CTX_set_quiet_shutdown

 internal static extern void SSL_CTX_set_quiet_shutdown(SafeSslContextHandle ctx, int mode);
开发者ID:shrutigarg,项目名称:corefx,代码行数:1,代码来源:Interop.libssl.cs

示例14: SSL_CTX_ctrl

 internal static extern long SSL_CTX_ctrl(SafeSslContextHandle ctx, int cmd, long larg, IntPtr parg);
开发者ID:shrutigarg,项目名称:corefx,代码行数:1,代码来源:Interop.libssl.cs

示例15: SSL_CTX_check_private_key

 internal static extern int SSL_CTX_check_private_key(SafeSslContextHandle ctx);
开发者ID:shrutigarg,项目名称:corefx,代码行数:1,代码来源:Interop.libssl.cs


注:本文中的Microsoft.Win32.SafeHandles.SafeSslContextHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。