-
-
Save cheewaphat/5f2f2294123da5e64fc962095da48b1f to your computer and use it in GitHub Desktop.
Python SSL socket with PEM from JKS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check the alias | |
keytool -list -keystore ${MYKEY}.jks | |
# Export to PKCS12 | |
keytool -importkeystore -srckeystore ${MYKEY}.jks -destkeystore ${MYKEY}.pkcs -srcstoretype JKS -deststoretype PKCS12 -alias ${MYALIAS} | |
# Convert to PEM | |
openssl pkcs12 -in ${MYKEY}.pkcs -out ${MYKEY}.pem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket, ssl | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
ssl_sock = ssl.wrap_socket(s, certfile="${MYKEY}.pem") | |
ssl_sock.connect(('example.com', 443)) | |
ssl_sock.send(bytes('test\n', 'UTF-8')) | |
ssl_sock.recv(512) | |
ssl_sock.close | |
s.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment