/// <summary> /// 名称:增加 SNI 主机证书(只用于服务端) /// 描述:SSL 服务端在 SetupSSLContext() 成功后可以调用本方法增加多个 SNI 主机证书 /// 返回值:正数 -- 成功,并返回 SNI 主机证书对应的索引,该索引用于在 SNI 回调函数中定位 SNI 主机 /// 返回值:负数 -- 失败,可通过 SYS_GetLastError() 获取失败原因 /// </summary> /// <param name="verifyMode">SSL 验证模式(参考 EnSSLVerifyMode)</param> /// <param name="pemCertFile">证书文件</param> /// <param name="pemKeyFile">私钥文件</param> /// <param name="keyPassword">私钥密码(没有密码则为空)</param> /// <param name="caPemCertFileOrPath">CA 证书文件或目录(单向验证可选)</param> /// <returns></returns> public int AddServerContext(SSLVerifyMode verifyMode, string pemCertFile, string pemKeyFile, string keyPassword, string caPemCertFileOrPath) { if (string.IsNullOrWhiteSpace(pemCertFile)) { throw new ArgumentException("参数无效", pemCertFile); } if (string.IsNullOrWhiteSpace(pemKeyFile)) { throw new ArgumentException("参数无效", pemKeyFile); } keyPassword = string.IsNullOrWhiteSpace(keyPassword) ? null : keyPassword; caPemCertFileOrPath = string.IsNullOrWhiteSpace(caPemCertFileOrPath) ? null : caPemCertFileOrPath; return(SSLSdk.HP_SSLServer_AddSSLContext(pServer, verifyMode, pemCertFile, pemKeyFile, KeyPassword, caPemCertFileOrPath)); }
/// <summary> /// 名称:增加 SNI 主机证书(只用于服务端) /// 描述:SSL 服务端在 SetupSSLContext() 成功后可以调用本方法增加多个 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_SSLServer_AddSSLContext(pServer, verifyMode, pemCertFile, pemKeyFile, KeyPasswod, caPemCertFileOrPath)); }