Dmitry
Dmitry

Reputation: 347

curl command with certificates to php SoapClient (BankID)

Based on https://www.bankid.com/assets/bankid/rp/bankid-relying-party-guidelines-v2.13.pdf

I have working curl command:

curl https://appapi.test.bankid.com/rp/v4?wsdl -E --cacert /path/to/BankID_SSL_Root_Certification_Authority_TEST.pem --cert /path/to/ServerCertificate.cer --key /path/to/PrivateKey.key

ServerCertificate.cer and PrivateKey.key were extracted from PFX certificate (https://www.bankid.com/assets/bankid/rp/FPTestcert2_20150818_102329.pfx) with openssl command.

But I can't make it work with PHP SoapClient:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://appapi.test.bankid.com/rp/v4?wsdl' : failed to load external entity "https://appapi.test.bankid.com/rp/v4?wsdl"

I will appreciate any help here.

Upvotes: 2

Views: 2077

Answers (2)

Fran
Fran

Reputation: 11

Just for future people finding themselves with the same BankID problem, Dmitry gave a very good tutorial on how to get the correct certificate, but the code that worked for me required a few more parameters:

try {
    $client = new SoapClient('https://appapi2.test.bankid.com/rp/v4?wsdl',
        ["local_cert" => "certname.pem",
         "stream_context" => [
             "ssl" => [
                 "verify_peer" => false,
                 "verify_peer_name" => false,
                 "allow_self_signed" => true
             ]
         ]
     ]);
} catch (Exception $e) {
    return json_encode( array( "result" => false, "reason" => $e->getMessage() ) );
}

Upvotes: 1

Dmitry
Dmitry

Reputation: 347

Thank you guys for your answers.

The solution:

  1. openssl pkcs12 -in FPTestcert2_20150818_102329.pfx -nocerts -out key.pem -nodes
  2. openssl pkcs12 -in FPTestcert2_20150818_102329.pfx -nokeys -out cert.pem
  3. openssl rsa -in key.pem -out server.key
  4. Copy
    -----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY-----
    section from server.key and
    -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----
    section from cert.pem and put them into new certname.pem file.

Then:

try {
    $this->client = new SoapClient( $this->wsdl, array( "local_cert" => "/path_to_cert/certname.pem" ) );
} catch (Exception $e) {
    return json_encode( array( "result" => false, "reason" => $e->getMessage() ) );
}

Upvotes: 2

Related Questions