none
How to connect with SSL to a webservice? RRS feed

  • Question

  •  

    Hi,

    I try to connect to a webserver via SSL. I get a P12 container as an base64 encoded string and need to use this to connect and authorize with a webserver.

    I used to use BouncyCastle for this in Java and C#, but this project is a mixture of C and C++ and I have no clue what functions I should use.

    Right now I tried to use the following code, but I get a parsing error '-2146881269':

     

    std::string certbytesBase64("MIAC......AAAA==");
      std::string certBytes = helperutils::base64_decode(certbytesBase64);
      //char* certbytes = (char*)certBytesStr.c_str();
      PCCERT_CONTEXT pCertContext = NULL;
      if(pCertContext = CertCreateCertificateContext(
                PKCS_7_ASN_ENCODING | X509_ASN_ENCODING,
                (const BYTE*)certBytes.c_str(),
                (DWORD)certBytes.size()))
      {
        LOG( Logging::nDebug, L"P12 imported!!");
      }
      else
      {
        LOG( Logging::nDebug, L"P12 import FAILED: '%d'", GetLastError());
      }
    
    ...
    
    ...
    
    InternetSetOption(hreq, INTERNET_OPTION_CLIENT_CERT_CONTEXT, certbytes, sizeof(certbytes));
    

    Is there an "easy" way to read a P12 bytestream and use it for an SSL connection?

     

     

    Thursday, August 26, 2010 3:41 PM

Answers

  • TheGrudge_2 wrote:

    I try to connect to a webserver via SSL. I get a P12 container as an  base64 encoded string and need to use this to connect and
    authorize with a webserver.

    Right now I tried to use the following code, but I get a parsing error  '-2146881269':

     if(pCertContext = CertCreateCertificateContext(

    You want PFXImportCertStore, followed by CertEnumCertificatesInStore or  CertFindCertificateInStore.


    Igor Tandetnik

    Thursday, August 26, 2010 4:47 PM
  • TheGrudge_2 wrote:

    Ok thanks, I will try these methods. I always searched for P12, so I  never found these methods :-)

    Wikipedia is your friend. http://en.wikipedia.org/wiki/PKCS12


    Igor Tandetnik

    Saturday, August 28, 2010 1:35 PM

All replies

  • TheGrudge_2 wrote:

    I try to connect to a webserver via SSL. I get a P12 container as an  base64 encoded string and need to use this to connect and
    authorize with a webserver.

    Right now I tried to use the following code, but I get a parsing error  '-2146881269':

     if(pCertContext = CertCreateCertificateContext(

    You want PFXImportCertStore, followed by CertEnumCertificatesInStore or  CertFindCertificateInStore.


    Igor Tandetnik

    Thursday, August 26, 2010 4:47 PM
  • Ok thanks, I will try these methods. I always searched for P12, so I never found these methods :-)

     

    Saturday, August 28, 2010 11:59 AM
  • TheGrudge_2 wrote:

    Ok thanks, I will try these methods. I always searched for P12, so I  never found these methods :-)

    Wikipedia is your friend. http://en.wikipedia.org/wiki/PKCS12


    Igor Tandetnik

    Saturday, August 28, 2010 1:35 PM
  •  

    Hi,

     

    Did you solve your problem?

    If you still have any doubts and concerns about this issue, please let me know.

     

    Have a nice day!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 31, 2010 7:37 AM
    Moderator