Importing .p12 files

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
anders_g
Posts: 8
Joined: Sun 03 Feb 2013 14:55

Importing .p12 files

Post by anders_g » Wed 05 Jun 2013 09:02

Hi, I am trying to replace my CAPICOM handling of certificates with SecureBridge. Seemed promising, but now i tried importing a .p12 file with code like this:

var
crt: TScCertificate;

crt := TScCertificate.Create(<TScCryptoAPIStorage>.Certificates);
crt.ImportFrom(<FileName>, <Pwd>);

This doesn't work as the import doesn't seem to find anything in the file, especially not the CertName.

However, after importing the cert from e g InternetExplorer, I can handle it with help of SecureBridge: list, use, delete...

Am I missing something, or is it just impossible to open .p12 certs? Is there a way to circumvent the problem?

/Anders

anders_g
Posts: 8
Joined: Sun 03 Feb 2013 14:55

Re: Importing .p12 files

Post by anders_g » Wed 26 Jun 2013 06:46

Support obviously died, went on vaccation or something, no answer to anything during the whole of June...

/Anders

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Importing .p12 files

Post by Dimon » Thu 27 Jun 2013 11:25

Please give more detailed description of the problem. Is there an exception raised? If yes, specify the exact exception message.

anders_g
Posts: 8
Joined: Sun 03 Feb 2013 14:55

Re: Importing .p12 files

Post by anders_g » Thu 27 Jun 2013 15:28

I thought maybe .p12 was not able to be opened, as that filetype is not in the list of values?

The error I get is:
"<my project> raised exception class EScError with message 'Certificate name missing'."

This is what I see:
* ScBridge.pas 6350: After setting value to CertData, the string is totally unreadable, thus the 2 following searches for 'CERTIFICATE' and 'X509 CERTIFICATE' fail => CertStr is empty.

* ScBridge.pas 6367: the call to BaseStorage.ImportCert seems to work => ce has a value.

* ScBridge.pas 6407: CertName is empty => no CertificateList.Storage.Save(Self)!

I see now, that the error really shows up on a line I didn't show you. This is my - fuller - code:

var
crt: TScCertificate;
begin
crt := TScCertificate.Create(CryptoStorage.Certificates);
crt.ImportFrom(AFileName, APwd);
CryptoStorage.Certificates.Add(crt); // << This is where I get the error!
end;


I thought maybe importing did the whole thing, but removing third line and reloading the repository doesn't seem to help.

Hopefully this was clearer? :-)

/Anders

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Re: Importing .p12 files

Post by Dimon » Mon 08 Jul 2013 09:21

You should set the certificate name before saving the certificate into the certificate storage. You can use the following code:

Code: Select all

  crt := TScCertificate.Create(CryptoStorage.Certificates);
  crt.ImportFrom(AFileName, APwd);
  crt.CertName := 'my_cert';
  CryptoStorage.Certificates.Add(crt);

anders_g
Posts: 8
Joined: Sun 03 Feb 2013 14:55

Re: Importing .p12 files

Post by anders_g » Fri 12 Jul 2013 06:38

Thanks, that seems to work fine :-)

... with the exception that the last line (CryptoStorage.Certificates.Add(crt);
) should be removed. Setting the CertName already adds the cert to the list, and the Add just causes a "duplicate name" error!

/Anders

Post Reply