Skip to content

Instantly share code, notes, and snippets.

View kasimok's full-sized avatar
💭
Moving to AI

kakaiikaka kasimok

💭
Moving to AI
View GitHub Profile
@kasimok
kasimok / InternalCA.java
Created June 15, 2016 08:57
Load File in resources folder
//Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("certs/root/ca-key.pkcs8").getFile());
return readPrivateKey(file.getPath());
@kasimok
kasimok / gist:614dafef4be1f7ec3247ae68c51ccf37
Created June 10, 2016 08:07 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@kasimok
kasimok / OCSPIntegrationTest.java
Created June 7, 2016 00:59
Extract Issuer from cert
/**
* Extract the issuer cert's URI from cert.
* @param var0
* @return
*/
private URI getIssuerCertURL(X509CertImpl var0) {
AuthorityInfoAccessExtension var1 = var0.getAuthorityInfoAccessExtension();
if(var1 == null) {
return null;
} else {
@kasimok
kasimok / OCSPIntegrationTest.java
Last active June 7, 2016 01:02
Read file by RandomAccessFile
RandomAccessFile raf = new RandomAccessFile("certs/client/client.cer.pem", "r");
byte[] buf = new byte[(int) raf.length()];
raf.readFully(buf);
raf.close();
/**
* Read PEM certificate into javax.security.x509Certificate.
* @param certText
* @return
*/
private X509Certificate readPemCert(String certText) {
CertificateFactory certificateFactory = null;
try {
certificateFactory = CertificateFactory.getInstance("X.509");
@kasimok
kasimok / TestPortListening.java
Created June 6, 2016 08:49
Method to test port opening and listening
public static boolean available(int port) {
if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
throw new IllegalArgumentException("Invalid start port: " + port);
}
ServerSocket ss = null;
DatagramSocket ds = null;
try {
ss = new ServerSocket(port);
ss.setReuseAddress(true);