1. DEMETRIUS SOUZA
  2. PowerBuilder
  3. Wednesday, 14 December 2022 16:22 PM UTC

I need to consume a soap webservice (defined as usual by a wsdl), but the main problem is that it requires the user to be authenticated with a digital certificate (those stored in a cryptographic media, with Public Key Infrastructure).

I'm running Powerbuilder 2021 and used httpclient to make the request. But it is not accepted by the server because I was not able to authenticate myself with my certificate in the soap transaction.

Could anyone tell me how do I code so that the application generated asks the client for his certificate authentication?

Thanks

DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Wednesday, 28 December 2022 18:36 PM UTC
  2. PowerBuilder
  3. # 1

I corrected (there is no "d" after "v5") and nothing changed.
Attached is a new image showing the result.
But, in both cases, the certificate was found by the application. The problem is that a window asking me my password/pin should appear and it didn't happen. So it will never authenticate successfully.

Attachments (1)
Comment
  1. Logan Liu @Appeon
  2. Thursday, 29 December 2022 03:37 AM UTC
Please notice it's using the client certification installed in the windows certification store. We usually need to enter the password the first time to install the certificate. But don't need to enter the password every time.



Some sites can make your certification testing process easier. E.g.: https://badssl.com

You can download the client certification (badssl.com-client.p12) from https://badssl.com/download/, and install it. Then verify it again.

ls_certSN = "0098f5669f18f5fc93"

ls_certIssue = 'CN = BadSSL Client Root Certificate Authority~r~nO = BadSSL~r~nL = San Francisco~r~nS = California~r~nC = US'

ln_rtn = l_httpclient.SetClientCert("MY", ls_certIssue, ls_certSN);

ln_rtn = l_httpclient.SendRequest("GET", "https://client.badssl.com/";)



If still not solved, please report your issue via our support ticketing system to ensure it is being properly received by our tech support and tracked at: https://www.appeon.com/standardsupport/

Regards, Logan
  1. Helpful
  1. DEMETRIUS SOUZA
  2. Thursday, 29 December 2022 16:49 PM UTC
Hello, Logan.



We probably are not talking about the same thing.

When we use a usb (PKI) token, the password/pin (as far as I know) is not saved in the Windows' store. The authentication needs to use the software provided by the company that issues the certificate (in my case, Soluti).

This doesn't seem to be the same thing as using a p12 file, wich holds the private key of the certificate.

As far as I know (and I have to advise that I am NOT an expert), in the case of a PKI usb token, the private key is kept safe inside the USB media.



I am already looking for other alternatives (like Chilkat). But I will report this issue via support ticket, anyway.

Thank you,
  1. Helpful
There are no comments made yet.
DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Wednesday, 28 December 2022 17:15 PM UTC
  2. PowerBuilder
  3. # 2

I put commas before the "~r~n" strings and it finally found the certificate.

(Instead of 

"CN = AC SOLUTI Multipla v5~r~n OU = AC SOLUTI v5d~r~n O = ICP-Brasil~r~n C = BR"

I used

CN = AC SOLUTI Multipla v5,~r~n OU = AC SOLUTI v5d,~r~n O = ICP-Brasil,~r~n C = BR

)

But connection still returns "-16", as shown in the picture I attached to this message.

And it could not be any different because the form that requests my password (witch is native to the company that issued the certificate) did not appear.

 

Attachments (1)
Comment
  1. DEMETRIUS SOUZA
  2. Wednesday, 28 December 2022 18:35 PM UTC
I corrected (there is no "d" after "v5").

But, in both cases, the certificate was found by the application. The problem is that a window asking me my password sould appear ans it didn't happen. So it will never authenticate successfully.
  1. Helpful
  1. Arnd Schmidt
  2. Wednesday, 28 December 2022 20:18 PM UTC
Then I would try the approach by using the pfx filename (full path) and password.

If you want the user to enter these values then it is up to you to write that little piece of code (simple response window) before the setClientCert() call.

  1. Helpful
  1. DEMETRIUS SOUZA
  2. Wednesday, 28 December 2022 20:35 PM UTC
Asking the user his password looks like an enormous security breach to me.

It seems that, unfortunately, whoever coded this upgrade did not consider the use of the certificate on a usb token.

All applications (even browsers) that access usb tokens do not build their own forms to collect certificates data and pins (passwords).

The certificate is chosen with an interface provided by the OS (Windows) and the pin/password is collected by a software designed by the certificate authority that issued the certificate.
  1. Helpful
There are no comments made yet.
DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Wednesday, 28 December 2022 13:45 PM UTC
  2. PowerBuilder
  3. # 3

Hello, Logan.
Nothing has changed.

See the image attached to this message, please.

Any other suggestion?

 

Thanks.

Attachments (1)
Comment
There are no comments made yet.
DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Tuesday, 27 December 2022 20:42 PM UTC
  2. PowerBuilder
  3. # 4

Ok.  Now I have upgraded to Powerbuilder 2022.

I have used of one of the examples listed in the page https://docs.appeon.com/pb2022/powerscript_reference/SetClientCert_func.html 

(See below, at the end of this message, please.)


The variable ls_certSN received the serial number of my certificate and ls_certIssue received the entity that signed the certificate, as shown in the image attached to this message.

(In fact, what I expected was that the application called a pop up window listing the available certificates so that I could choose one, instead of hard-coding it in the script, but, since I could not figure out how to do it, I followed  dutifully the instructions to achieve my first success, but it didn't work.)

I tried all the options presented for "store name"

  • "MY" -- The certificate store for personal certificates.

  • "Root" -- The certificate store for trusted root certificate authorities (CAs).

  • "Trust" -- The certificate store for directly trusted people, resources, and publishers.

  • "CA" -- The certificate store for intermediate certificate authorities (CAs).

None of them worked. The error was always "-2 -- Failed to import certificate or the specified certificate is not found."

 

httpClient l_httpclient

String    ls_urlName            &
,        ls_ResPonse            &
,        ls_certSN            &        
,        ls_certIssue
integer    ln_rtn

l_httpclient = Create httpClient

 
ls_urlName = "https://webservices.consulta.esocial.gov.br/servicos/empregador/consultarloteeventos/WsConsultarLoteEventos.svc"

ln_rtn = l_httpclient.SendRequest("GET", ls_urlName)
ls_certSN = "7e0e209878604451"
ls_certIssue = 'CN = AC SOLUTI Multipla v5~r~n OU = AC SOLUTI v5d~r~n O = ICP-Brasil~r~n C = BR'
If ln_rtn = -16 Then
  l_httpclient.anonymousAccess = false
  ln_rtn = l_httpclient.SetClientCert("Trust", ls_certSN, ls_certIssue);
  ln_rtn = l_httpclient.SendRequest("GET", ls_urlName)
End If

 

Attachments (1)
Comment
  1. Logan Liu @Appeon
  2. Wednesday, 28 December 2022 05:34 AM UTC
Please use 'MY' for the personal certification store and change the sequence of the last two parameters and try again:

ln_rtn = l_httpclient.SetClientCert("Trust", ls_certSN, ls_certIssue);

->

ln_rtn = l_httpclient.SetClientCert("MY", ls_certIssue, ls_certSN);



BTW: we will correct the examples in the documentation.

Regards, Logan
  1. Helpful 1
There are no comments made yet.
DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Tuesday, 20 December 2022 19:08 PM UTC
  2. PowerBuilder
  3. # 5

Hi, Logan.


No I have not upgraded to 2022 version yet. I will probably be able to do this in the following days.
I don't know exactly how to set the variabes storeName, certIssue and certSN . By the examples, they those variables seem to be very specific the the user/client computer, witch is very unusual. But I guess I am misunderstanding something.

I will upgrade my PB installation and make some tests. When I finish, I will publish here the results.

You helped a lot.
Thanks.

Comment
There are no comments made yet.
DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Friday, 16 December 2022 17:09 PM UTC
  2. PowerBuilder
  3. # 6

Hello, Logan!

If the server requires the client to provide a certificate (ln_rtn = -16, in your example), do you mean that I shoud build a screen asking the user to write the address of the certificate and his password? An then, once with these informations, I would call the method below?

l_httpclient.SetClientCert("e:\\testclient.pfx", "123456");

Is it what you meant?

It could be a solution. But, in fact, I thought the midia of the certificate itself (usb token, for example) would offer me the interfaces/screens so that the user could select his certificate and fill his password safely, the way it happens when we use a web (ou even client/server) software (please, see the images I attached to this message, showing the windows that appers when I log in a server that requires a client certificate).

The object httpClient should't call these standard forms/screeens/windows where the user chooses his certificate and fills his password avoiding, this way, the need for the software (that is accessing the webservice, in our case, built with PB) to "know" the client's password?

Sorry if I am being dumb on some(many)thing(s). I promisse it's not on purpose!

Thanks again.

Attachments (2)
Comment
  1. Logan Liu @Appeon
  2. Tuesday, 20 December 2022 16:00 PM UTC
In the case of using the USB Token, have you ever tried to obtain the client certificate in the Windows certificate store?

HttpClient.SetClientCert ( string storeName, string certIssue, string certSN )

https://docs.appeon.com/pb2022/powerscript_reference/SetClientCert_func.html

Regards, Logan
  1. Helpful 1
There are no comments made yet.
DEMETRIUS SOUZA Accepted Answer Pending Moderation
  1. Thursday, 15 December 2022 12:09 PM UTC
  2. PowerBuilder
  3. # 7

Hey, Logan.
Thanks for your help!

I had already realized that 2022 version of Powerbuilder could solve the problem. But, looking at the examples, and the parameters of SetClientCert function I culdn't figure out how to tell the application to ask the user the certificate he/she wuold like to use, just like when happens when we use any software that requires client cetificate. It seemed to me that the certificate to be used - as well as the password to access the cryptographic media - would be chosen by the user when makind the http request.

If you (or anyone) have any clue on how to set the parameters so that the user, during runtime, will be able to specify witch certificate will be used, please, let me know.

 

Thanks again.

Comment
  1. Logan Liu @Appeon
  2. Friday, 16 December 2022 08:41 AM UTC
Hi Demetrius,

You can add code to provide UI to let the user specify the parameters before calling the SetClientCert method. They should know the path of the client certificate.

You can also ask the user to verify these parameters after getting an error after Sending a Request to test the server.

E.g:

ln_rtn = l_httpclient.SendRequest("GET", "https://test.appeon.com";)

If ln_rtn = -16 Then // The server requires the client to provide a certificate.

l_httpclient.SetClientCert("e:\\testclient.pfx", "123456");

l_httpclient.SendRequest("GET", "https://test.appeon.com";)

End If

Regards, Logan
  1. Helpful 1
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Thursday, 15 December 2022 01:40 AM UTC
  2. PowerBuilder
  3. # 8

Hi Demetrius,

Please try the HttpClient.SetClientCert method new provided by PowerBuilder 2022, but you need to upgrade PowerBuilder since you are running Powerbuilder 2021.

https://docs.appeon.com/pb/whats_new/Supports_two-way_SSL_authentication.html

https://docs.appeon.com/pb2022/powerscript_reference/SetClientCert_func.html

Regards, Logan

Comment
  1. Anton Novak
  2. Thursday, 13 April 2023 09:47 AM UTC
Hello,



I have the same problem.

Working with file cert but not from cert store. Is there any other way to set cert password ?



Work: li_ret = 1

li_ret = ref_client.SetClientCert( ls_certLocation, ls_certPass )



NOT work: li_ret = 1

li_cert = ref_client.SetClientCert( "MY", ls_certIssue, ls_certSN )



Thanks
  1. Helpful
  1. Anton Novak
  2. Friday, 14 April 2023 13:15 PM UTC
p.s.: In one option i have to read cert in cert store and private key of cert is on USB card and user have to put his PIN number to add private key. Is this even posible in PB2022 or I have to use any other library ?

So in witch case is working for ref_client.SetClientCert( "MY", ls_certIssue, ls_certSN ). In witch type of cert.

Thanks.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.