public HttpPostIntTest() { Log4jInit.setLevel("ca.nrc.cadc.net", Level.DEBUG); String hostname = NetUtil.getServerName(HttpPostIntTest.class); baseHttpUrl = "http://" + hostname + "/test"; baseHttpsUrl = "https://" + hostname + "/test"; SSL_CERT = FileUtil.getFileFromResource(TEST_CERT_FN, HttpDownloadTest.class); SSL_KEY = FileUtil.getFileFromResource(TEST_KEY_FN, HttpDownloadTest.class); System.setProperty(BasicX509TrustManager.class.getName() + ".trust", "true"); }
@SuppressWarnings("unchecked") public static X509Certificate[] readCertificateChain(File certFile) throws CertificateException, IOException { try { X509Certificate[] chain = readCertificateChain(FileUtil.readFile(certFile)); log.debug("X509 certificate is valid"); return chain; } catch (CertificateException ex) { throw new RuntimeException("certificate from file " + certFile + " is not valid", ex); } }
/** * Convenience method to parse a PEM encoded file and return the corresponding X509 Certificate * chain. * * @param pemFile * @return certificate chain * @throws InvalidKeySpecException * @throws NoSuchAlgorithmException * @throws IOException * @throws CertificateException */ public static X509CertificateChain readPemCertificateAndKey(File pemFile) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException, CertificateException { byte[] data = FileUtil.readFile(pemFile); return readPemCertificateAndKey(data); }
public static PrivateKey readPrivateKey(File keyFile) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException { byte[] priv = FileUtil.readFile(keyFile); return readPrivateKey(priv); }