.pem文件和.p12文件和URL - 哦,我的

时间:2014-09-24 10:32:33

标签: c# ssl windows-7 openssl ssl-certificate

我在尝试联系安全的其他网址时遇到了实际问题。基本上我对证书知之甚少,并且想知道我对证书文件的处理是否正确。

  1. 我有2个URL,有效一个用于读取,一个用于写入。
  2. 我有2个.pem文件,每个文件一个,随URL提供。将这些导入证书管理器的行为并未改变以下结果。)
  3. 我还有一个.p12文件,如果我老实说不知道它适合所有这些...(我无法将其导入我的Win7认证资格器中,因为我没有密码)< / LI>

    运行req.GetResponse()时会发生异常:

    "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
    Inner Ex: "The remote certificate is invalid according to the validation procedure."
    

    我目前不确定是否需要进行一些修修补补,或者我只是暂时离开。 代码基本上就是......

    if (!File.Exists(certificateLocation)) 
    {
        throw new Exception(string.Format("The specified certificate file does not exist: {0}", certificateLocation));
    }
    
    //Cert Challenge URL 
    Uri requestURI = new Uri(url);
    
    //Create the Request Object
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestURI);
    
    //Set the Request Object parameters
    req.ContentType = "application/x-www-form-urlencoded";
    req.Method = "POST";
    req.AllowAutoRedirect = false;
    
    //Create certificate from our file
    X509Certificate cert = X509Certificate.CreateFromCertFile(certificateLocation);
    req.ClientCertificates.Add(cert);
    
    WebResponse response = req.GetResponse(); // *** Errors here
    
    ...
    

    编辑:目前我只是尝试“阅读”网址 - 似乎合乎逻辑。

    在与发卡行联系以获取.p12证书附带的密码并将其导入认证管理器的“受信任的根证书颁发机构”部分后,错误现已更改为以下内容...

    System.Net.WebException
    "The underlying connection was closed: An unexpected error occurred on a receive."
    Inner Ex:
    "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
    

1 个答案:

答案 0 :(得分:1)

- 将评论重新发布为答案 -

此密码是必须的。

它与.p12文件同时创建。