Calling a Java web service from a C # client using JKS and / or PFX certificates

I basically need to provide my requests for this service.

I have been given a test JAR client and two trust.jks and Client.pfx , but I have no idea how to use them: I understand that the X509Certificate2 class is somehow involved.

The command line for starting the test client is as follows:

 java -Djavax.net.ssl.trustStore=trust.jks -Djavax.net.ssl.trustStorePassword=******** -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStore=Client.pfx -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=******** -jar TestClient.jar https://myServiceurl 

It works, so I can see the service, and the service itself must be configured correctly.

My C # client (oriented to .NET 2.0) uses a regular web link to execute requests:

 wsReferenceClient service = new wsReferenceClient(); //certificate code here ? //maybe service.ClientCertificates.Add(<X509Certificate2 object built somehow>); ? service.MyRequest(myParameters); 

Server settings must be configured correctly.

I was messing around with X509Certificate2 methods, but I can’t find something that makes sense, so the answer to the question "what have you tried?" the question at the moment is: "I really don't know what to try first."

Any help would be really appreciated.

+6
source share
1 answer

Turns out I don't have to do anything with the JKS file.

 wsReferenceClient service = new wsReferenceClient(); X509Certificate2 cert = new X509Certificate2(); cert.Import("Client.pfx", "<the password>", DefaultKeySet); service.ClientCertificates.Add(cert); service.MyRequest(myParameters); 

This allows my HTTPS requests to succeed.

+7
source

Source: https://habr.com/ru/post/913118/


All Articles