<HTML dir=ltr><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16762" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial color=#000000 size=2>We have been using XEP for a few years now.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Recently one of our online resource locations renewed their SSL certificates using GoDaddy's Intermediate Certificate.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Once this was active on their web server, XEP and XEPwin have started throwing errors.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Could not retrieve image from 'https://www....com/logo-for-report.jpg': javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>To remiedy this problem, we compiled and ran the following code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV>import java.io.*;<BR>import java.net.URL;</DIV>
<DIV>import java.security.*;<BR>import java.security.cert.*;</DIV>
<DIV>import javax.net.ssl.*;</DIV>
<DIV>public class InstallCert {</DIV>
<DIV>&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Exception {<BR>&nbsp;String host;<BR>&nbsp;int port;<BR>&nbsp;char[] passphrase;<BR>&nbsp;if ((args.length == 1) || (args.length == 2)) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; String[] c = args[0].split(":");<BR>&nbsp;&nbsp;&nbsp;&nbsp; host = c[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp; port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);<BR>&nbsp;&nbsp;&nbsp;&nbsp; String p = (args.length == 1) ? "changeit" : args[1];<BR>&nbsp;&nbsp;&nbsp;&nbsp; passphrase = p.toCharArray();<BR>&nbsp;} else {<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Usage: java InstallCert &lt;host&gt;[:port] [passphrase]");<BR>&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;}</DIV>
<DIV>&nbsp;File file = new File("jssecacerts");<BR>&nbsp;if (file.isFile() == false) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; char SEP = File.separatorChar;<BR>&nbsp;&nbsp;&nbsp;&nbsp; File dir = new File(System.getProperty("java.home") + SEP<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + "lib" + SEP + "security");<BR>&nbsp;&nbsp;&nbsp;&nbsp; file = new File(dir, "jssecacerts");<BR>&nbsp;&nbsp;&nbsp;&nbsp; if (file.isFile() == false) {<BR>&nbsp;&nbsp;file = new File(dir, "cacerts");<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;}<BR>&nbsp;System.out.println("Loading KeyStore " + file + "...");<BR>&nbsp;InputStream in = new FileInputStream(file);<BR>&nbsp;KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());<BR>&nbsp;ks.load(in, passphrase);<BR>&nbsp;in.close();</DIV>
<DIV>&nbsp;SSLContext context = SSLContext.getInstance("TLS");<BR>&nbsp;TrustManagerFactory tmf =<BR>&nbsp;&nbsp;&nbsp;&nbsp; TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());<BR>&nbsp;tmf.init(ks);<BR>&nbsp;X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];<BR>&nbsp;SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);<BR>&nbsp;context.init(null, new TrustManager[] {tm}, null);<BR>&nbsp;SSLSocketFactory factory = context.getSocketFactory();</DIV>
<DIV>&nbsp;System.out.println("Opening connection to " + host + ":" + port + "...");<BR>&nbsp;SSLSocket socket = (SSLSocket)factory.createSocket(host, port);<BR>&nbsp;socket.setSoTimeout(10000);<BR>&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Starting SSL handshake...");<BR>&nbsp;&nbsp;&nbsp;&nbsp; socket.startHandshake();<BR>&nbsp;&nbsp;&nbsp;&nbsp; socket.close();<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println();<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("No errors, certificate is already trusted");<BR>&nbsp;} catch (SSLException e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println();<BR>&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace(System.out);<BR>&nbsp;}</DIV>
<DIV>&nbsp;X509Certificate[] chain = tm.chain;<BR>&nbsp;if (chain == null) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Could not obtain server certificate chain");<BR>&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;}</DIV>
<DIV>&nbsp;BufferedReader reader =<BR>&nbsp;&nbsp;new BufferedReader(new InputStreamReader(System.in));</DIV>
<DIV>&nbsp;System.out.println();<BR>&nbsp;System.out.println("Server sent " + chain.length + " certificate(s):");<BR>&nbsp;System.out.println();<BR>&nbsp;MessageDigest sha1 = MessageDigest.getInstance("SHA1");<BR>&nbsp;MessageDigest md5 = MessageDigest.getInstance("MD5");<BR>&nbsp;for (int i = 0; i &lt; chain.length; i++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; X509Certificate cert = chain[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;(" " + (i + 1) + " Subject " + cert.getSubjectDN());<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("&nbsp;&nbsp; Issuer&nbsp; " + cert.getIssuerDN());<BR>&nbsp;&nbsp;&nbsp;&nbsp; sha1.update(cert.getEncoded());<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("&nbsp;&nbsp; sha1&nbsp;&nbsp;&nbsp; " + toHexString(sha1.digest()));<BR>&nbsp;&nbsp;&nbsp;&nbsp; md5.update(cert.getEncoded());<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("&nbsp;&nbsp; md5&nbsp;&nbsp;&nbsp;&nbsp; " + toHexString(md5.digest()));<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println();<BR>&nbsp;}</DIV>
<DIV>&nbsp;System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");<BR>&nbsp;String line = reader.readLine().trim();<BR>&nbsp;int k;<BR>&nbsp;try {<BR>&nbsp;&nbsp;&nbsp;&nbsp; k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;<BR>&nbsp;} catch (NumberFormatException e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("KeyStore not changed");<BR>&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;}</DIV>
<DIV>&nbsp;X509Certificate cert = chain[k];<BR>&nbsp;String alias = host + "-" + (k + 1);<BR>&nbsp;ks.setCertificateEntry(alias, cert);</DIV>
<DIV>&nbsp;OutputStream out = new FileOutputStream("jssecacerts");<BR>&nbsp;ks.store(out, passphrase);<BR>&nbsp;out.close();</DIV>
<DIV>&nbsp;System.out.println();<BR>&nbsp;System.out.println(cert);<BR>&nbsp;System.out.println();<BR>&nbsp;System.out.println<BR>&nbsp;&nbsp;("Added certificate to keystore 'jssecacerts' using alias '"<BR>&nbsp;&nbsp;+ alias + "'");<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();</DIV>
<DIV>&nbsp;&nbsp;&nbsp; private static String toHexString(byte[] bytes) {<BR>&nbsp;StringBuilder sb = new StringBuilder(bytes.length * 3);<BR>&nbsp;for (int b : bytes) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; b &amp;= 0xff;<BR>&nbsp;&nbsp;&nbsp;&nbsp; sb.append(HEXDIGITS[b &gt;&gt; 4]);<BR>&nbsp;&nbsp;&nbsp;&nbsp; sb.append(HEXDIGITS[b &amp; 15]);<BR>&nbsp;&nbsp;&nbsp;&nbsp; sb.append(' ');<BR>&nbsp;}<BR>&nbsp;return sb.toString();<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; private static class SavingTrustManager implements X509TrustManager {</DIV>
<DIV>&nbsp;private final X509TrustManager tm;<BR>&nbsp;private X509Certificate[] chain;</DIV>
<DIV>&nbsp;SavingTrustManager(X509TrustManager tm) {<BR>&nbsp;&nbsp;&nbsp;&nbsp; this.tm = tm;<BR>&nbsp;}</DIV>
<DIV>&nbsp;public X509Certificate[] getAcceptedIssuers() {<BR>&nbsp;&nbsp;&nbsp;&nbsp; throw new UnsupportedOperationException();<BR>&nbsp;}</DIV>
<DIV>&nbsp;public void checkClientTrusted(X509Certificate[] chain, String authType)<BR>&nbsp;&nbsp;throws CertificateException {<BR>&nbsp;&nbsp;&nbsp;&nbsp; throw new UnsupportedOperationException();<BR>&nbsp;}</DIV>
<DIV>&nbsp;public void checkServerTrusted(X509Certificate[] chain, String authType)<BR>&nbsp;&nbsp;throws CertificateException {<BR>&nbsp;&nbsp;&nbsp;&nbsp; this.chain = chain;<BR>&nbsp;&nbsp;&nbsp;&nbsp; tm.checkServerTrusted(chain, authType);<BR>&nbsp;}<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>}<BR></DIV>
<DIV>Output as Follows:</DIV>
<DIV>&nbsp;</DIV>
<DIV>C:\certs&gt;java InstallCert <A href="http://www....com">www....com</A><BR>Loading KeyStore jssecacerts...<BR>Opening connection to <A href="http://www.....com:443">www.....com:443</A>...<BR>Starting SSL handshake...</DIV>
<DIV>No errors, certificate is already trusted</DIV>
<DIV>Server sent 1 certificate(s):</DIV>
<DIV>&nbsp;1 Subject OU=Domain Control Validated, CN=www.....com, O=www.....com<BR>&nbsp;&nbsp; Issuer&nbsp; SERIALNUMBER=07969287, CN=Go Daddy Secure Certification Authority, OU=http://certificates.godaddy.com/repository, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US<BR>&nbsp;&nbsp; sha1&nbsp;&nbsp;&nbsp; b8 00 d6 93 be 7e b4 64 9b c7 d1 be 6c f3 13 86 f8 1e 72 20<BR>&nbsp;&nbsp; md5&nbsp;&nbsp;&nbsp;&nbsp; 1b 2a 3a 42 9f 7e f1 07 19 58 a3 a9 b4 06 2b 53</DIV>
<DIV>Enter certificate to add to trusted keystore or 'q' to quit: [1]</DIV></BODY></HTML>