private ECertificate selectCertificate(bool checkIsQualified, bool checkBeingNonQualified, List <byte[]> aCerts) { if (aCerts != null && aCerts.Count == 0) { throw new ESYAException("Kartta sertifika bulunmuyor"); } if (checkIsQualified && checkBeingNonQualified) { throw new ESYAException( "Bir sertifika ya nitelikli sertifikadir, ya niteliksiz sertifikadir. Hem nitelikli hem niteliksiz olamaz"); } List <ECertificate> certs = new List <ECertificate>(); foreach (byte[] bs in aCerts) { ECertificate cert = new ECertificate(bs); if (checkIsQualified) { if (cert.isQualifiedCertificate()) { certs.Add(cert); } } else if (checkBeingNonQualified) { if (!cert.isQualifiedCertificate()) { certs.Add(cert); } } else { certs.Add(cert); } } ECertificate selectedCert = null; if (certs.Count == 0) { if (checkIsQualified) { throw new ESYAException("Kartta nitelikli sertifika bulunmuyor"); } else if (checkBeingNonQualified) { throw new ESYAException("Kartta niteliksiz sertifika bulunmuyor"); } } else if (certs.Count == 1) { selectedCert = certs[0]; } else { String[] optionList = new String[certs.Count]; for (int i = 0; i < certs.Count; i++) { optionList[i] = certs[i].getSubject().getCommonNameAttribute(); } int result = askOption(null, null, optionList, "Sertifika Listesi", new[] { "Tamam" }); if (result < 0) { selectedCert = null; } else { selectedCert = certs[result]; } } return(selectedCert); }
public ECertificate getEInvoiceCertificate(string pinNo) { if (mSignatureCert == null) { List <byte[]> aCerts = bsc.getSignatureCertificates(); List <ECertificate> certs = new List <ECertificate>(); foreach (byte[] bs in aCerts) { ECertificate cert = new ECertificate(bs); if (cert.isQualifiedCertificate()) { certs.Add(cert); } else if (cert.isMaliMuhurCertificate()) { certs.Add(cert); } } if (certs.Count == 0) { throw new ESYAException("Kartta fatura imzalayabiliceğiniz bir sertifika bulunmuyor"); } else if (certs.Count == 1) { mSignatureCert = certs[0]; } else { String[] optionList = new String[certs.Count]; for (int i = 0; i < certs.Count; i++) { if (certs[i].isQualifiedCertificate()) { optionList[i] = certs[i].getSubject().getCommonNameAttribute() + " (Nitelikli)"; } else { optionList[i] = certs[i].getSubject().getCommonNameAttribute() + " (MaliMühür)"; } } int result = askOption(null, null, optionList, "Sertifika Listesi", new String[] { "Tamam", "\u0130ptal" }); if (result < 0) { throw new ESYAException("Sertifika secmediniz"); } else { mSignatureCert = certs[result]; } } return(mSignatureCert); } return(mSignatureCert); }
private ECertificate selectCertificate(bool checkIsQualified, bool checkBeingNonQualified, List <byte[]> aCerts) { if (aCerts != null && aCerts.Count == 0) { throw new ESYAException("Kartta sertifika bulunmuyor"); } if (checkIsQualified && checkBeingNonQualified) { throw new ESYAException( "Bir sertifika ya nitelikli sertifikadir, ya niteliksiz sertifikadir. Hem nitelikli hem niteliksiz olamaz"); } List <ECertificate> certs = new List <ECertificate>(); foreach (byte[] bs in aCerts) { ECertificate cert = new ECertificate(bs); if (checkIsQualified) { if (cert.isQualifiedCertificate()) { certs.Add(cert); } } else if (checkBeingNonQualified) { if (!cert.isQualifiedCertificate()) { certs.Add(cert); } } else { certs.Add(cert); } } ECertificate selectedCert = null; if (certs.Count == 0) { if (checkIsQualified) { throw new ESYAException("Kartta nitelikli sertifika bulunmuyor"); } else if (checkBeingNonQualified) { throw new ESYAException("Kartta niteliksiz sertifika bulunmuyor"); } } else if (certs.Count == 1) { selectedCert = certs[0]; } else { selectedCert = certs[0]; } return(selectedCert); }
public Task <List <SignatureInfo> > CheckSignaturesAsync(byte[] input) { return(Task.Factory.StartNew(() => { if (!IsSignedData(input) && !IsSignedPDF(input)) { throw new SignatureNotFoundException("İmza bilgisi bulunamdı."); } List <SignatureInfo> signInfo = new List <SignatureInfo>(); if (IsSignedData(input)) { BaseSignedData bs = new BaseSignedData(input); Dictionary <string, object> params_ = new Dictionary <string, object>(); params_[EParameters.P_CERT_VALIDATION_POLICY] = _policy; params_[EParameters.P_FORCE_STRICT_REFERENCE_USE] = true; SignedDataValidation sdv = new SignedDataValidation(); SignedDataValidationResult sdvr = sdv.verify(input, params_); for (int i = 0; i < sdvr.getSDValidationResults().Count; i++) { var item = sdvr.getSDValidationResults()[i]; var signatureType = bs.getSignerList()[i].getType().name(); var certificate = item.getSignerCertificate(); var name = certificate.getSubject().getCommonNameAttribute(); var identity = certificate.getSubject().getSerialNumberAttribute(); var serialnumber = certificate.getSerialNumber().ToString(); var issuer = certificate.getIssuer().getCommonNameAttribute(); bool isvalid = false; if (item.getSignatureStatus() == Types.Signature_Status.VALID) { isvalid = true; } var info = new SignatureInfo() { Identity = identity, Name = name, IsValid = isvalid, Issuer = issuer, SerialNumber = serialnumber, SignatureType = signatureType }; if (certificate.getNotAfter().HasValue) { info.ValidUntil = certificate.getNotAfter().Value; } if (certificate.getNotBefore().HasValue) { info.ValidFrom = certificate.getNotBefore().Value; } var signaturealgorithm = SignatureAlg.fromAlgorithmIdentifier(certificate.getSignatureAlgorithm()).first().getName(); var publickeyalgorithm = SignatureAlg.fromAlgorithmIdentifier(certificate.getPublicKeyAlgorithm()).first().getName(); var publicKey = certificate.asX509Certificate2().GetPublicKeyString(); info.PublicKey = publicKey; info.SignatureAlgorithm = signaturealgorithm; info.PublicKeyAlgorithm = publickeyalgorithm; info.IsTimeStampedCertificate = certificate.isTimeStampingCertificate(); info.IsQualifiedCertificate = certificate.isQualifiedCertificate(); if (item.getSigningTime().HasValue) { info.SignedOn = item.getSigningTime().Value; } signInfo.Add(info); } } if (IsSignedPDF(input)) { PdfReader reader = new PdfReader(input); AcroFields af = reader.AcroFields; var names = af.GetSignatureNames(); for (int i = 0; i < names.Count; ++i) { String name = (string)names[i]; PdfPKCS7 pk = af.VerifySignature(name); var cert = new ECertificate(pk.SigningCertificate.GetEncoded()); var signatureType = "ES_XL"; var commonname = cert.getSubject().getCommonNameAttribute(); var identity = cert.getSubject().getSerialNumberAttribute(); var serialnumber = cert.getSerialNumber().ToString(); var issuer = cert.getIssuer().getCommonNameAttribute(); var info = new SignatureInfo() { Identity = identity, Name = commonname, IsValid = pk.SigningCertificate.IsValidNow, Issuer = issuer, SerialNumber = serialnumber, SignatureType = signatureType }; if (cert.getNotAfter().HasValue) { info.ValidUntil = cert.getNotAfter().Value; } if (cert.getNotBefore().HasValue) { info.ValidFrom = cert.getNotBefore().Value; } var signaturealgorithm = SignatureAlg.fromAlgorithmIdentifier(cert.getSignatureAlgorithm()).first().getName(); var publickeyalgorithm = SignatureAlg.fromAlgorithmIdentifier(cert.getPublicKeyAlgorithm()).first().getName(); var publicKey = cert.asX509Certificate2().GetPublicKeyString(); info.PublicKey = publicKey; info.SignatureAlgorithm = signaturealgorithm; info.PublicKeyAlgorithm = publickeyalgorithm; info.IsTimeStampedCertificate = cert.isTimeStampingCertificate(); info.IsQualifiedCertificate = cert.isQualifiedCertificate(); if (cert.isQualifiedCertificate()) { info.SignedOn = pk.SignDate; } else if (cert.isTimeStampingCertificate()) { info.SignedOn = pk.TimeStampDate; } signInfo.Add(info); } } return signInfo; })); }