+ Start a Discussion
anupammanianupammani 

Client certification issue in apex class during external web service call.

Hi

 

i have a client certificate provided:

 

-----BEGIN CERTIFICATE-----
MIIEwDCCA6igAwIBAgIEOGPLSjANBgkqhkiG9w0BAQUFADCBtDEUMBIGA1UEChML
RW50cnVzdC5uZXQxQDA+BgNVBAsUN3d3dy5lbnRydXN0Lm5ldC9DUFNfMjA0OCBp
bmNvcnAuIGJ5IHJlZi4gKGxpbWl0cyBsaWFiLikxJTAjBgNVBAsTHChjKSAxOTk5
IEVudHJ1c3QubmV0IExpbWl0ZWQxMzAxBgNVBAMTKkVudHJ1c3QubmV0IENlcnRp
ZmljYXRpb24gQXV0aG9yaXR5ICgyMDQ4KTAeFw0wODExMDcyMDM4NDFaFw0xNDA3
MDEwNDAwMDBaMGMxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMx
GTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xIjAgBgNVBAMTGURpZ2lDZXJ0IEds
b2JhbCBDQSAoMjA0OCkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDE
PLzMuupi5p5CI6+0shGuYo3ZodOPzBRyGe2Z9v3eXbtZwLDCr2qZUpVXCzX/4Yb6
r6LDwQVlJyB2LwpUJXzqK92VQVebDzvPR+gBBozFREj8By7zcoMwUZSeaTqDqYeQ
FNlexKJ4j8E+1BlhDhrn3BqVIEG+bxfauBxB7piw+tcdNT8WpwQoE109BXWaLoae
LLAXhyBYV+/h6lVguCxwIawpYwwQ/GC8+dUcN2TVtPseqyY5Roiky80wZ8AmeeXK
aPki1+XSsbtITJsLmFtCkuXS7Q5HMPrdJ1ZjaqUBx46v8E47G1UVRNU+TVce4ZHq
uKCPzjpjX5aJugg+/kS7AgMBAAGjggEoMIIBJDAOBgNVHQ8BAf8EBAMCAQYwEgYD
VR0TAQH/BAgwBgEB/wIBADAnBgNVHSUEIDAeBggrBgEFBQcDAQYIKwYBBQUHAwIG
CCsGAQUFBwMEMDMGCCsGAQUFBwEBBCcwJTAjBggrBgEFBQcwAYYXaHR0cDovL29j
c3AuZW50cnVzdC5uZXQwMgYDVR0fBCswKTAnoCWgI4YhaHR0cDovL2NybC5lbnRy
dXN0Lm5ldC8yMDQ4Y2EuY3JsMBEGA1UdIAQKMAgwBgYEVR0gADAdBgNVHQ4EFgQU
Q0lH589A0ZqokvKMisqYk8/JCA8wHwYDVR0jBBgwFoAUVeSB0RGAvtiJuQijMfmh
JAkWuXAwGQYJKoZIhvZ9B0EABAwwChsEVjcuMQMCAIEwDQYJKoZIhvcNAQEFBQAD
ggEBAGgUlCIvPADB6IfhYPg91XNYOvbL3dNQt4AOHJu6M5wmLH4eJlpK4G0Ch6DD
Woy9gOtIx54iyu2amOO90ACoBXMizEGGmR1Z2C5UeiTedov3g3fJIOqH7O/rd41L
GaYm4AzKRwsNZXoOTukUSQA7vdSTI4sdZQ6gmElqJ/ZgalGAy5ZJSWSLSeXcB5+Z
CeVoGPLjq2rh62N6JS3J/j8Jn/gBDNVzbBa5BBySBTT/Ow+hDgGJV8sD35z/aF8Z
W5VX4pNfSbzSPS8U26jGpmEqrqHAdgTgK8OVHVa40o7K4K6/E7CRO+v/6Ts2pP2N
BihOJhXLn+HbRoukESiGrQOxT3U=
-----END CERTIFICATE-----

 

Its seems it is a .Pem file. but while sending the certificate to the variable of the external web service it need to be converted into base64. we followed the below steps:

      

       Blob hash = Crypto.generateDigest('SHA1',Blob.valueOf(certificate));  

       String encoded_certificate= EncodingUtil.base64Encode(hash);

       stub.clientCert_x = encoded_certificate; 
       stub.clientCertPasswd_x = '';

 

 

but it throws an exception :

 

System.CalloutException: IO Exception: DER input, Integer tag error

 

can anybody suggest how to implement this thing. Do we need to follow any step to put the certificate in proper format? If yes could anybody suggest how to do this in detail..

 

Thanks in Advance

Anupam

 



 

dddddd

Hi Anupama,

 

Were you able to fix it i am also getting the same error, appreciate your reply.

 

Thanks

Kris