Skip to content

Commit

Permalink
SSLUtil: cleanup cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Feb 22, 2024
1 parent c52380b commit 5f86fb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 295 deletions.
123 changes: 4 additions & 119 deletions cadc-util/src/intTest/java/ca/nrc/cadc/auth/SSLUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,62 +107,6 @@ public class SSLUtilTest
private static String TEST_PEM_FN = "proxy.pem";
private static File SSL_PEM;

private static final String KEY_512 =
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIBOgIBAAJBAOvm3yk/tr7/8ZaT584T54tOviYIpoWWRfwDgd176c0kTfTj43+C\n" +
"BgxFcequf5mY51mgD7v38krRA3+xXi/igfsCAwEAAQJBAMqVrQXGcpDaScVPZV1j\n" +
"WJAY4lDVUvQb1iQTev4SwPjqUy8H/f0Zt+Bezwf1LaxcHcCFA6QnDxHw6l99/5zw\n" +
"p7kCIQD+4rfjcZyYUKwF0C2deKEgvZUjpiLYVyh/G4qKfT2sPwIhAOzu598CHLLn\n" +
"LSZoBRJtjuhAr1zUrfkoBsNHQwTKi6tFAiBOpKtyXPKhOHrrTEFWzgqBLJ2gozkr\n" +
"ITFYjqnfcycdRwIgbMW1L31hvYRCBxrEEVS4wclIeJ6vC+6jRC1ICEAQZN0CIFe+\n" +
"Az22zN/URBRVBK32tI2axHy/j80Asysh+hxalp1F\n" +
"-----END RSA PRIVATE KEY-----\n";
private static final String KEY_1024 =
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIICXQIBAAKBgQDIcNIXiBAPuOjTNWJUbsI+TR1FSXNGM2bv2naU7pKQ0OWI+DDs\n" +
"K1xlctgTi5WrfsMjPKoM+0zpVT5qjUrHyFatbTu9tYjLblPmi/yzOEOIloqZ8lF1\n" +
"hrkUG98f8IBbgx4BbkXscVKdP9awngEpIYrZt3QXLUwUP+oF2PCGH5f+nwIDAQAB\n" +
"AoGBAI5gVVuRspb4aaldSjNfWWqXrCsDOXasHHpTW9f+fu2O9PyOD3Iyerc1FHcN\n" +
"t4rRyBrHhKMj/kXf3y4gnvW6QJY8MM+lHx7oubS8O5aqVexKa8dawQNHvMfLz9PU\n" +
"OuN7X2+rvLS3+qPUtL2LiklCSsrr137M4OBNdfTcZKqAEaLBAkEA/QWsVzhx526D\n" +
"HCBaJ6cgfo6Ravqjg17DDe/yt5iC+dQzGMozWJdHjOS/066aZNF4Els4iSVWdIT5\n" +
"KqBmgjBFZQJBAMrMub59uqqHFGQzWgtOdQamiyeEwr48+a3xHUYy5p+1h7TWetHR\n" +
"OQTFOwGfpv8h7RGd2TS3fxzK+G5LKIUChbMCQQDF+rpvROtbe017pJTmkg8K9+Mx\n" +
"IgzvriZRsX7pyZwyf6e7rfufRj/mLtcqe2SznnOlaVtDdMPBSIrun7OWCs9BAkB6\n" +
"V2b2dALYPQUgLZp0l7AhgvcPsBeLjF1TgdGXN73JO0nS3lDZos4zAojGQfoMj/rk\n" +
"VcVi+A/G3utgHhcjppHhAkBpxQmU1fAB2wKVNtTh2puPmKt+g1wob1yZASRJEadZ\n" +
"5QR7EgNAJtdlouvJcdnTXHJS9JazpcS3061+u2TfgIvx\n" +
"-----END RSA PRIVATE KEY-----\n";
private static final String KEY_2048 =
"-----BEGIN RSA PRIVATE KEY-----\n" +
"MIIEpgIBAAKCAQEA4Sa+glBzaztCbgZ90uFm5sfjSWUtZCGTw1UwcIFsQtkBa1ut\n" +
"gn1b2LtGevctPoXMreMq4f/5TNAtJuBOHP+2Xv+mIBBbm+zJwTAfk9I0/6wcNlkS\n" +
"FKhSqkpvwSv6+ecQ6R5zUrQv1aMwI392GyAiY8Jo4J6UVGKe7+YY1yvWraVFZYzB\n" +
"FeCNb9Qlo4X+uyZRjz0JJmJZE8H6USmrAa1DPQoWRBpJPJ/sIM1ejTz6lLyC3A54\n" +
"e0Nh+z8dPfUVzBySOgPzypPbuyEaVEFlmm+PqyrfoSIgNQNeOY0SbyhN374xpSH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aCIVQdwBpNHyCwkJYTXRVF09P+8XLpA2Pyg6U96b0TTFmVv\n" +
"l4SqX1CMvxrR/YeaESFTdnznN9fsob/1tAKjBv5L9LmfokfAuWdmKocs/r4x0dhq\n" +
"BLXt4EDpAoGBAKN61XJ+kwO6FkxuyTlbv458Bc9toFyPqSaafJeEp/p3KdLMlphr\n" +
"0GzdeGNkrNfseVbSAjnlO2zmmhVe6Oz3oIR4d/5Hb8QEZi8f7nOZboufITyGTtYG\n" +
"LfVRkN/AuTrxRxWQDbZOo55ACoJA3DH7/BMOXhf9RikjrvESLtCWzsf2\n" +
"-----END RSA PRIVATE KEY-----\n";


/**
* @throws java.lang.Exception
*/
Expand All @@ -173,21 +117,6 @@ public static void setUpBeforeClass() throws Exception
SSL_PEM = FileUtil.getFileFromResource(TEST_PEM_FN, SSLUtilTest.class);
}

@Test
public void testReadPem() throws Exception
{
try
{
X509CertificateChain chain = SSLUtil.readPemCertificateAndKey(SSL_PEM);
Assert.assertNotNull("Null chain", chain);
}
catch (Throwable t)
{
t.printStackTrace();
Assert.fail("unexpected exception: " + t);
}
}

@Test
public void testGetSocketFactoryFromNull() throws Exception
{
Expand Down Expand Up @@ -228,7 +157,8 @@ public void testGetSocketFactoryFromFile() throws Exception
}

@Test
public void testReadCert() {
public void testReadUserCert() {
// test reading a real user cert
try {
File f = new File(System.getProperty("user.home") + "/.ssl/" + System.getProperty("user.name") + ".pem");
log.info("in: " + f.getAbsolutePath());
Expand All @@ -251,6 +181,7 @@ public void testReadCert() {

@Test
public void testReadUserProxyCert() {
// test reading a proxy cert (usually made from user cert using openssl)
try {
File f = new File(System.getProperty("user.home") + "/.ssl/cadcproxy.pem");
log.info("in: " + f.getAbsolutePath());
Expand All @@ -273,6 +204,7 @@ public void testReadUserProxyCert() {

@Test
public void testReadProxyCert() {
// test read proxy.pem found in classpath (test resources)
try {
File f = SSL_PEM;
log.info("in: " + f.getAbsolutePath());
Expand Down Expand Up @@ -307,53 +239,6 @@ public void testInitSSL() throws Exception
}
}

public void testHTTPS(URL url) throws Exception
{
HttpURLConnection.setFollowRedirects(false);

SSLSocketFactory sf = SSLUtil.getSocketFactory(SSL_PEM);
URLConnection con = url.openConnection();

log.debug("URLConnection type: " + con.getClass().getName());
HttpsURLConnection ucon = (HttpsURLConnection) con;
ucon.setSSLSocketFactory(sf);
log.debug("status: " + ucon.getResponseCode());
log.debug("content-length: " + ucon.getContentLength());
log.debug("content-type: " + ucon.getContentType());
}

@Test
public void testGoogleHTTPS() throws Exception
{
try
{
URL url = new URL("https://www.google.com/");
log.debug("test URL: " + url);
testHTTPS(url);
}
catch (Throwable t)
{
t.printStackTrace();
Assert.fail("unexpected exception: " + t);
}
}

@Test
public void testCadcHTTPS() throws Exception
{
try
{
URL url = new URL("https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/");
log.debug("test URL: " + url);
testHTTPS(url);
}
catch (Throwable t)
{
t.printStackTrace();
Assert.fail("unexpected exception: " + t);
}
}

@Test
public void testValidSubject() throws Exception
{
Expand Down
Loading

0 comments on commit 5f86fb1

Please sign in to comment.