Pkcs7SignatureGenerator icon indicating copy to clipboard operation
Pkcs7SignatureGenerator copied to clipboard

Error building certpath

Open atumminia opened this issue 7 years ago • 9 comments

Hi, i got this error while building certpath while signing a file

errore per jariq

List<byte[]> otherCertificates = pkcs7.GetAllCertificates(); ICollection<Org.BouncyCastle.X509.X509Certificate> certPath = CertUtils.BuildCertPath(CertCKA, otherCertificates,false);

thank you

atumminia avatar Feb 21 '18 16:02 atumminia

CertUtils.BuildCertPath() method builds the whole certificate chain up to a root certificate which is always self-signed.

jariq avatar Feb 21 '18 17:02 jariq

Hi, i try to write an example to explain my case:

I have 1 User Certificate and 2 User Keys (Public and Private)

this is my function to generate pkcs7 pkcs7=Pkcs7SignatureGenerator(Library,_selectedSlot.TokenInfo.SerialNumber,_selectedSlot.TokenInfo.Label,pin,PrivateKey.CkaLabel,PrivateKey.CkaId,HashAlgorithm.SHA256,SignatureScheme.RSASSA_PKCS1_v1_5);

now i take all certificate from pkcs7 List<byte[]> otherCertificates = pkcs7.GetAllCertificates();

and in the end ICollection<Org.BouncyCastle.X509.X509Certificate> certPath = CertUtils.BuildCertPath(UserCertificate.CkaValue, otherCertificates ,true);

when i run my application i got this error errore per jariq

What should I do to correct this error?

thank you

atumminia avatar Feb 22 '18 09:02 atumminia

In this case pkcs7.GetAllCertificates(); returns all certificates stored on your token/card. Import CA certificates on your card and let me know the result.

jariq avatar Feb 26 '18 20:02 jariq

Hi, this is my code for import CA

List<byte[]> otherCertificates = new List<byte[]>();
byte[] certUnobyte = File.ReadAllBytes("C:\\temp\\InfoCert_Servizi_di_Certificazione.cer");
byte[] certDuebyte = File.ReadAllBytes("C:\\temp\\InfoCert_Servizi_di_Certificazione_2.cer");
otherCertificates.Add(certUnobyte);
otherCertificates.Add(certDuebyte);

ICollection<Org.BouncyCastle.X509.X509Certificate> certPath = CertUtils.BuildCertPath(CertCKA, otherCertificates,true);

this is the error i got

2error

atumminia avatar Feb 27 '18 08:02 atumminia

You are most likely not importing all CAs (up to root CA) forming the certification path or you are importing incorrect ones.

jariq avatar Feb 28 '18 17:02 jariq

how can i do to import all the certificates?

atumminia avatar Feb 28 '18 17:02 atumminia

Can you post your certificate here?

jariq avatar Feb 28 '18 17:02 jariq

CA certificate or my.cer certificate?

atumminia avatar Mar 01 '18 08:03 atumminia

Ideally all of them.

jariq avatar Mar 01 '18 08:03 jariq