-1

I am new to Azure development and want some help.

I have a HTTPS end point of a web service from my third party.

The webservice call uses a client certificate and user name and password for invoking the SOAP action.

I am using a default HTTP action API and passing the URL, headers, authentication and body as required.

How can i set the certificate setting there ??

Any help or way forward would be great help.Thanks in advance

  • What application framework are you using? What language are you using? What do you mean "How can I set the certificate setting there"? – theadriangreen Nov 24 '15 at 19:50

1 Answers1

0

This is an example for Java, you should find the right implementation for the language that you use.

public static void main(String[] args) throws Exception {

    DefaultHttpClient httpClient = new DefaultHttpClient();

    try {
        SSLContext ctx = SSLContext.getInstance("TLS");
        TrustManager[] trustManagers = getTrustManagers("jks", new FileInputStream(new File("cacerts")), "changeit");
        KeyManager[] keyManagers = getKeyManagers("pkcs12", new FileInputStream(new File("clientCert.pfx")), "password");
        ctx.init(keyManagers, trustManagers, new SecureRandom());
        SSLSocketFactory factory = new SSLSocketFactory(ctx, new StrictHostnameVerifier());

        ClientConnectionManager manager = httpClient.getConnectionManager();
        manager.getSchemeRegistry().register(new Scheme("https", 443, factory));

        //as before
    }
}

protected static KeyManager[] getKeyManagers(String keyStoreType, InputStream keyStoreFile, String keyStorePassword) throws Exception {
    KeyStore keyStore = KeyStore.getInstance(keyStoreType);
    keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(keyStore, keyStorePassword.toCharArray());
    return kmf.getKeyManagers();
}

protected static TrustManager[] getTrustManagers(String trustStoreType, InputStream trustStoreFile, String trustStorePassword) throws Exception {
    KeyStore trustStore = KeyStore.getInstance(trustStoreType);
    trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(trustStore);
    return tmf.getTrustManagers();
}

PS: This code was provided by Barry Pitman in this link

Community
  • 1
  • 1
Ansel
  • 360
  • 1
  • 10
  • don't forget to accept this as answer if it works so it will also help people that have the same problem – Ansel Dec 27 '15 at 15:01