|
I have the following java pgm running in a q-shell.
It is attempting to connect to another site via https, and needs to
identify itself with a certificate issued by the other site (Motorweb).
The certificate is in PKCS12 keystore format, but program execution fails
at the commented line with:
java.io.IOException: Keystore type is invalid
Any ideas?
----------------------------------------------------------------------------------------------------------------------------------------
import java.util.*;
import java.net.*;
import java.io.*;
import javax.net.ssl.*;
import javax.security.cert.X509Certificate;
import java.security.KeyStore;
public class TestMotorWeb {
/**
* This example shows how to send a motorweb https request with
client side
* authentication. Requires Java 1.4
*
*
*/
public static void main(String[] args) throws Exception {
String URLstr = null;
String ClientCertFileName = null;
String XMLFileName = null;
String ClientCertPasswd = null;
long startTime = System.currentTimeMillis();
// submit to test URL
URLstr = "
https://www.motorweb.co.nz/action/robotLoadVir/1.0?reference=e2f93d0f";
ClientCertFileName = "/java/hnzdev/motorweb.p12";
ClientCertPasswd = "notreallymypassword";
try {
// set up a key manager so that we can do client authentication
// if asked by server
SSLSocketFactory factory = null;
try {
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks;
// Password on p12 file
ctx = SSLContext.getInstance("SSL");
kmf = KeyManagerFactory.getInstance("IbmISeriesX509");
ks = KeyStore.getInstance("PKCS12");
//load p12 client certificate file
char[] passphrase = ClientCertPasswd.toCharArray();
ks.load(new FileInputStream(ClientCertFileName), passphrase);
// The following line is failing with " java.io.IOException: Keystore type
is invalid "
kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(), null, null);
factory = ctx.getSocketFactory();
} catch (Exception e) {
throw new IOException(e.getMessage());
}
// start up https connection
HttpsURLConnection.setDefaultSSLSocketFactory(factory);
URL g2b = new URL(URLstr);
startTime = System.currentTimeMillis();
System.out.println("startTime="+startTime);
URLConnection connection = g2b.openConnection();
connection.setDoOutput(true);
connection.setUseCaches(false);
// This is probably redundant but set anyway
connection.setRequestProperty("Connection", "Keep-Alive");
// Read in the result and write to standard out
BufferedReader in = new BufferedReader( new
InputStreamReader(connection.getInputStream()) );
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
System.out.println("FinishTime="+(System.currentTimeMillis()-startTime));
} catch (Exception e) {
e.printStackTrace();
}
}
}
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.