- validar el .cer, key y la contraseña
- valida en el ocsp del sat que el .cer no este revocado http://www.sat.gob.mx/ocsp
- firma un pdf
El problema es que este programa funciona con .cer y funciona perfectamente con el cifrado SHA1, pero con los certificados con cifrado SHA-256 no funciona, el ocsp siempre regresa intentelo más tarde (TryLater), el código es el siguiente:
Código HTML:
public string validar(byte[] certificadoValidar, byte[] certificadoRoot2, string pathOut, byte[] certificadoRoot3 = null, byte[] certificadoRoot4 = null, byte[] certificadoRoot5= null) { byte[] input = certificadoRoot2; try { string str1 = "http://www.sat.gob.mx/ocsp"; X509CertificateParser certificateParser = new X509CertificateParser(); X509Certificate checkCert = certificateParser.ReadCertificate(certificadoValidar); string[] strArray = string.Concat((object)checkCert.IssuerDN).Split(new char[1] { '=' }); string str2 = ""; foreach (string str3 in strArray) { if (str3.Trim().StartsWith("Responsable:")) str2 = str3; } if (str2 != "") { string str3 = str2.Replace("Responsable: ", ""); str3.Trim(); if (str3.StartsWith("Cecilia Guillermina García Guerra")) input = certificadoRoot3; else if (str3.StartsWith("Fernando Martínez Coss")) input = certificadoRoot2; else if (str3.StartsWith("Claudia Covarrubias Ochoa")) input = certificadoRoot4; else if (str3.StartsWith("Administración Central de Servicios Tributarios al Contribuyente")) input = certificadoRoot5; } X509Certificate x509Certificate = certificateParser.ReadCertificate(input); //bouncycastle.asn1.ASN1ObjectIdentifier getHashAlgOID //Org.BouncyCastle.Asn1.Asn1O //2.16.840.1.101.3.4.2.1 //string sha = x509Certificate.SigAlgName; //x509Certificate.GetSigAlgParams // x509Certificate. CertificateID certId = new CertificateID("1.3.14.3.2.26", x509Certificate, checkCert.SerialNumber); //CertificateID certId = new CertificateID("1.3.6.1.5.5.7.48.1", x509Certificate, checkCert.SerialNumber); OcspReqGenerator ocspReqGenerator = new OcspReqGenerator(); ocspReqGenerator.AddRequest(certId); BigInteger bigInteger = BigInteger.ValueOf(DateTime.Now.Ticks / 10000L); ocspReqGenerator.SetRequestExtensions(new X509Extensions(new ArrayList() { (object)OcspObjectIdentifiers.PkixOcspNonce }, new ArrayList(){(object) new X509Extension(false, (Asn1OctetString) new DerOctetString(bigInteger.ToByteArray()))})); byte[] encoded = ocspReqGenerator.Generate().GetEncoded(); byte[] numArray = Ocsp.LeerStream(this.WebResponsePostOcsp(str1, encoded)); //Directory.GetCurrentDirectory(); //using (FileStream fileStream = new FileStream(pathOut + "Ocsp.res", FileMode.Create)) //{ // fileStream.Write(numArray, 0, numArray.Length); // fileStream.Dispose(); //} OcspResp ocspResp = new OcspResp(numArray); string str4 = (string)null; if (0 == ocspResp.Status) { this.setData(checkCert, x509Certificate, str1); Console.WriteLine((object)this.GetEncoded()); str4 = "Successful"; } else if (2 == ocspResp.Status) str4 = "InternalError"; else if (1 == ocspResp.Status) str4 = "MalformedRequest"; else if (5 == ocspResp.Status) str4 = "SignatureRequired"; else if (3 == ocspResp.Status) str4 = "TryLater"; else if (6 == ocspResp.Status) str4 = "Unauthorized"; return str4; } catch (Exception ex) { Console.WriteLine(ex.Message); return "Error" + ex.Message; } }