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 / 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);
/**
* 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 / 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();
@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 / 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 / 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 / .gitignore
Created June 24, 2016 07:07
The gitignore file for intellij projects.
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
## All items under idea folder
.idea/
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
@kasimok
kasimok / pom.xml
Created December 9, 2016 07:45
Maven make runnable Jar and copy depencies
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
@kasimok
kasimok / Util.java
Created December 14, 2016 02:27
Method to verify if a string is legal base64 encoded
/**
* Check if valid BASE64 String.
* @param value
* @return
*/
public static boolean checkIfValidBase64(String value){
return value.matches("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$");
}
@kasimok
kasimok / ProxyTest.java
Created December 19, 2016 00:21
Selenium Driver take screenshot
driver.manage().window().setSize(new Dimension(1920,1080));
driver.get("http://adultimages.org");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("./screenshot.png"));
driver.close();