views:

593

answers:

2

Hello,

I've been wrestling with a problem, maybe you guys can point me in the right direction.

I'm trying to digitally sign a pdf, on the webserver, over an https connection.

At page load i'm doing as so:

HttpClientCertificate cs = Request.ClientCertificate;
X509Certificate card = new X509Certificate(cs.Certificate);
Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
 Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(card.GetRawCertData())};

I'm getting the error "m_safeCertContext is an invalid handle" at that last line of code.

Please note that: - I am getting the same error using 2 completely different certificates. - The certificate is being retrieved to the "card" variable ok. - I used to get the card to X509Certificate2 but i read yesterday somewhere i'm not being able to find that the error could be solved by casting as a X509Certificate and then downcasting to X509Certificate2. It was one of those "well... this does not makes any sense but i havent tried it yet" moments. - I have tried to add this to properties to all methods and even de class to see if it would work... no such luck. [System.Security.SecurityCritical, System.Security.SecurityTreatAsSafe]

Can anyone one give me a hint?

A: 

Hi Sergio.

I'm trying exactly like you. I had same error. My problem was running out of an https context. Configuring that like http://www.locualo.net/programacion/activar-ssl-iis-certificado-digital-prueba/00000079.aspx, my error solved.

Once do that, i still get an error on SignMsg or Closing PdfStamper, cause the certificate in "card" variable, has not private key.

¿Do you continue with this theme? ¿Could you help me?

Thanks

Check all my other related questions on this subject, I have answered them has I went along
Sergio
A: 

First, do you have a stack?

Second, here there is a post that I would give a try. The issues mentioned in the post are typically the cause of certs-related troubles.

Ariel