Пример #1
0
 /// <summary>
 /// 反初始化SSL环境
 /// </summary>
 public virtual void Uninitialize()
 {
     if (Interlocked.Decrement(ref ObjectReferer) == 0)
     {
         SSLSdk.HP_SSL_Cleanup();
     }
 }
Пример #2
0
 public new bool Start()
 {
     if (SSLSdk.HP_SSL_IsValid() == false && Initialize() == false)
     {
         throw new Exception("法初始化SSL环境失败!");
     }
     return(base.Start());
 }
Пример #3
0
        /// <summary>
        /// 终止服务并释放资源
        /// </summary>
        public override void Destroy()
        {
            Stop();

            if (pServer != IntPtr.Zero)
            {
                SSLSdk.Destroy_HP_SSLPullServer(pServer);
                pServer = IntPtr.Zero;
            }
            if (pListener != IntPtr.Zero)
            {
                Sdk.Destroy_HP_TcpPullServerListener(pListener);
                pListener = IntPtr.Zero;
            }
            IsCreate = false;
        }
Пример #4
0
        public override void Destroy()
        {
            Stop();
            if (pClient != IntPtr.Zero)
            {
                SSLSdk.Destroy_HP_SSLClient(pClient);
                pClient = IntPtr.Zero;
            }
            if (pListener != IntPtr.Zero)
            {
                Sdk.Destroy_HP_TcpClientListener(pListener);
                pListener = IntPtr.Zero;
            }

            IsCreate = false;
        }
Пример #5
0
        /// <summary>
        /// 初始化SSL环境
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public virtual bool Initialize()
        {
            lock (SSLInitLock)
            {
                if (SSLSdk.HP_SSL_IsValid() == false)
                {
                    PemCertFile         = string.IsNullOrWhiteSpace(PemCertFile) ? null : PemCertFile;
                    PemKeyFile          = string.IsNullOrWhiteSpace(PemKeyFile) ? null : PemKeyFile;
                    KeyPasswod          = string.IsNullOrWhiteSpace(KeyPasswod) ? null : KeyPasswod;
                    CAPemCertFileOrPath = string.IsNullOrWhiteSpace(CAPemCertFileOrPath) ? null : CAPemCertFileOrPath;

                    return(SSLSdk.HP_SSL_Initialize(SSLSessionMode.Server, VerifyMode, PemCertFile, PemKeyFile, KeyPasswod, CAPemCertFileOrPath, SNIServerNameCallback));
                }

                return(true);
            }
        }
Пример #6
0
        /// <summary>
        /// 初始化SSL环境
        /// </summary>
        /// <returns></returns>
        protected virtual bool Initialize()
        {
            lock (SSLInitLock)
            {
                if (SSLSdk.HP_SSL_IsValid() == false)
                {
                    PemCertFile         = string.IsNullOrWhiteSpace(PemCertFile) ? null : PemCertFile;
                    PemKeyFile          = string.IsNullOrWhiteSpace(PemKeyFile) ? null : PemKeyFile;
                    KeyPasswod          = string.IsNullOrWhiteSpace(KeyPasswod) ? null : KeyPasswod;
                    CAPemCertFileOrPath = string.IsNullOrWhiteSpace(CAPemCertFileOrPath) ? null : CAPemCertFileOrPath;


                    return(SSLSdk.HP_SSL_Initialize(SSLSessionMode.Client, VerifyMode, PemCertFile, PemKeyFile, KeyPasswod, CAPemCertFileOrPath, null));
                }

                return(true);
            }
        }
Пример #7
0
        /// <summary>
        /// 名称:增加 SNI 主机证书(只用于服务端)
        /// 描述:SSL 服务端在 Initialize() 成功后可以调用本方法增加多个 SNI 主机证书
        /// 成功:正数, 返回 SNI 主机证书对应的索引,该索引用于在 SNI 回调函数中定位 SNI 主机
        /// 失败:负数, 可通过 SYS_GetLastError() 获取失败原因
        /// </summary>
        /// <param name="verifyMode">SSL 验证模式(参考 EnSSLVerifyMode)</param>
        /// <param name="pemCertFile">证书文件</param>
        /// <param name="pemKeyFile">私钥文件</param>
        /// <param name="keyPasswod">私钥密码(没有密码则为空)</param>
        /// <param name="caPemCertFileOrPath">CA 证书文件或目录(单向验证可选)</param>
        /// <returns></returns>
        public int AddServerContext(SSLVerifyMode verifyMode, string pemCertFile, string pemKeyFile, string keyPasswod, string caPemCertFileOrPath)
        {
            if (SSLSdk.HP_SSL_IsValid() == false)
            {
                throw new InvalidOperationException("请先调用Initialize()方法初始化SSL环境");
            }

            if (string.IsNullOrWhiteSpace(pemCertFile))
            {
                throw new ArgumentException("参数无效", pemCertFile);
            }
            if (string.IsNullOrWhiteSpace(pemKeyFile))
            {
                throw new ArgumentException("参数无效", pemKeyFile);
            }
            keyPasswod          = string.IsNullOrWhiteSpace(keyPasswod) ? null : keyPasswod;
            caPemCertFileOrPath = string.IsNullOrWhiteSpace(caPemCertFileOrPath) ? null : caPemCertFileOrPath;

            return(SSLSdk.HP_SSL_AddServerContext(verifyMode, pemCertFile, pemKeyFile, KeyPasswod, caPemCertFileOrPath));
        }
Пример #8
0
        protected override bool CreateListener()
        {
            if (IsCreate == true || pListener != IntPtr.Zero || pServer != IntPtr.Zero)
            {
                return(false);
            }

            pListener = Sdk.Create_HP_TcpServerListener();
            if (pListener == IntPtr.Zero)
            {
                return(false);
            }
            pServer = SSLSdk.Create_HP_SSLServer(pListener);
            if (pServer == IntPtr.Zero)
            {
                return(false);
            }

            IsCreate = true;

            return(true);
        }
Пример #9
0
        /// <summary>
        /// 创建socket监听&服务组件
        /// </summary>
        /// <returns></returns>
        protected override bool CreateListener()
        {
            if (IsCreate == true || pListener != IntPtr.Zero || pAgent != IntPtr.Zero)
            {
                return(false);
            }

            pListener = Sdk.Create_HP_TcpPullAgentListener();
            if (pListener == IntPtr.Zero)
            {
                return(false);
            }

            pAgent = SSLSdk.Create_HP_SSLPullAgent(pListener);
            if (pAgent == IntPtr.Zero)
            {
                return(false);
            }

            IsCreate = true;

            return(true);
        }