Skip to content

Instantly share code, notes, and snippets.

@jiaoyk
jiaoyk / ssl-key.diff
Created May 22, 2016 09:07 — forked from ghoff/ssl-key.diff
sslkeylog patch
apps/s_client.c | 10 +++++
ssl/s3_both.c | 7 ++++
ssl/s3_clnt.c | 6 +++
ssl/ssl.h | 13 +++++++
ssl/ssl_lib.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ssl/ssl_locl.h | 19 ++++++++++
6 files changed, 171 insertions(+)
diff --git a/apps/s_client.c b/apps/s_client.c
index 8fa2b73..2b5abed 100644
@jiaoyk
jiaoyk / Decrypter.java
Created June 9, 2016 14:20 — forked from scotttam/Decrypter.java
encrypt and decrypt with PBKDF2/SHA1 and AES
import javax.crypto.Cipher;
import java.security.spec.KeySpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.SecretKeyFactory;
import java.security.AlgorithmParameters;
import javax.crypto.spec.IvParameterSpec;
public class Decrypter {
@jiaoyk
jiaoyk / SSLPoke.java
Created November 9, 2016 05:43 — forked from 4ndrej/SSLPoke.java
Test of java SSL / keystore / cert setup. Check the commet #1 for howto.
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
@jiaoyk
jiaoyk / socat_http_echo_server.sh
Created January 26, 2017 13:04 — forked from ramn/socat_http_echo_server.sh
Socat HTTP echo server
#!/bin/bash
socat -v -T0.05 tcp-l:8081,reuseaddr,fork system:"echo 'HTTP/1.1 200 OK'; echo 'Connection: close'; echo; cat"
@jiaoyk
jiaoyk / generate-certificate-chain.sh
Created February 7, 2017 09:56 — forked from yamen/generate-certificate-chain.sh
Generate a full self-signed certificate chain (Root -> Intermediate CA -> Server) using keytool, that can be used for 'localhost' development
#!/bin/bash
rm *.jks 2> /dev/null
rm *.pem 2> /dev/null
echo "===================================================="
echo "Creating fake third-party chain root -> ca"
echo "===================================================="
# generate private keys (for root and ca)
@jiaoyk
jiaoyk / Base64.md
Created February 10, 2017 02:33 — forked from barrysteyn/Base64.md
OpenSSL Base64 En/Decode: Portable and binary safe.

OpenSSL Base64 Encoding: Binary Safe and Portable

Herewith is an example of encoding to and from base64 using OpenSSL's C library. Code presented here is both binary safe, and portable (i.e. it should work on any Posix compliant system e.g. FreeBSD and Linux).

License

The MIT License (MIT)

Copyright (c) 2013 Barry Steyn

@jiaoyk
jiaoyk / OpenDJPBKDF2Test.java
Created February 16, 2017 05:54 — forked from kevinmichaelchen/OpenDJPBKDF2Test.java
Generates PBKDF2 userPassword values for OpenDJ
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.junit.Test;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
@jiaoyk
jiaoyk / LdapAuth.java
Created March 28, 2017 09:22 — forked from jbarber/LdapAuth.java
LDAP example for searching and simple binding (authentication)
/*
* First create the keystore (to allow SSL protection) by importing the LDAP
* certificate (cert.pem) with:
* keytool -import -keystore keystore -storepass changeit -noprompt -file cert.pem
*
* You can get the certificate with OpenSSL:
* openssl s_client -connect ldap.server.com:636 </dev/null 2>/dev/null | sed -n '/^-----BEGIN/,/^-----END/ { p }' > cert.pem
*
* Then compile this class with:
* javac LdapAuth.java
@jiaoyk
jiaoyk / tmux-cheatsheet.markdown
Created May 24, 2017 06:28 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@jiaoyk
jiaoyk / string_wstring.cpp
Created June 2, 2018 03:58 — forked from 1901/string_wstring.cpp
std::string和std::wstring之间相互转换
// 把一个wstring转化为string
std::string& to_string(std::string& dest, std::wstring const & src)
{
std::setlocale(LC_CTYPE, "");
size_t const mbs_len = wcstombs(NULL, src.c_str(), 0);
std::vector<char> tmp(mbs_len + 1);
wcstombs(&tmp[0], src.c_str(), tmp.size());
dest.assign(tmp.begin(), tmp.end() - 1);