public ResCertificateKeyMatcher CertificateMatch(ReqCertificateKeyMatcher req) { ResCertificateKeyMatcher response = new ResCertificateKeyMatcher(); req.Certificate = req.Certificate.Replace(" ", "+").Replace("BEGIN+CERTIFICATE", "BEGIN CERTIFICATE").Replace("END+CERTIFICATE", "END CERTIFICATE"); req.CSROrPrivateKey = req.CSROrPrivateKey.Replace(" ", "+").Replace("BEGIN+CERTIFICATE+REQUEST", "BEGIN CERTIFICATE REQUEST").Replace("END+CERTIFICATE+REQUEST", "END CERTIFICATE REQUEST"); req.CSROrPrivateKey = req.CSROrPrivateKey.Replace(" ", "+").Replace("BEGIN+RSA+PRIVATE+KEY", "BEGIN RSA PRIVATE KEY").Replace("END+RSA+PRIVATE+KEY", "END RSA PRIVATE KEY"); // Alınan certificate text, OpenSSL işlemesi için dosya haline getirilir var certFilePath = string.Format("{0}{1}.crt", ConfigurationManager.AppSettings["opensslTmpPath"], DateTime.Now.Ticks); File.WriteAllText(certFilePath, req.Certificate); // Certificate Hash string certificateHashOutput = ExecuteOpenSSL(string.Format("x509 -noout -modulus -in {0}", certFilePath)); if (!certificateHashOutput.Contains(":error")) { response.CertificateHash = certificateHashOutput.Replace("Modulus=", string.Empty).Trim(); } // Oluşturulan dosyayı yer kaplamasın diye siliyorum #YalcinG File.Delete(certFilePath); // Alınan certificate text, OpenSSL işlemesi için dosya haline getirilir var csrOrPrivateKeyFilePath = string.Format("{0}{1}.key", ConfigurationManager.AppSettings["opensslTmpPath"], DateTime.Now.Ticks); File.WriteAllText(csrOrPrivateKeyFilePath, req.CSROrPrivateKey); // Private Key or CSR Hash string csrOrPrivateKeyOutput = ExecuteOpenSSL(req.MatchType == "privateKey" ? string.Format("rsa -noout -modulus -in {0}", csrOrPrivateKeyFilePath) : string.Format("req -noout -modulus -in {0}", csrOrPrivateKeyFilePath)); if (!csrOrPrivateKeyOutput.Contains(":error")) { response.CSROrPrivateKeyHash = csrOrPrivateKeyOutput.Replace("Modulus=", string.Empty).Trim(); } // Oluşturduğum csr veya private kley dosyasını diskte yer kaplamasın diye geri siliyorum File.Delete(csrOrPrivateKeyFilePath); // Dosya modulus hashlerini kontrol ederek birbirine ait olup olmadığına bakıyorum response.IsMatch = !string.IsNullOrEmpty(response.CSROrPrivateKeyHash) && Equals(response.CSROrPrivateKeyHash, response.CertificateHash); return(response); }
public ResCertificateKeyMatcher CertificateMatch(ReqCertificateKeyMatcher req) { return(Call <ResCertificateKeyMatcher, ReqCertificateKeyMatcher>(req, MethodBase.GetCurrentMethod().Name)); }