Skip to content

Instantly share code, notes, and snippets.

@after-the-sunrise
Last active March 1, 2023 15:34
Show Gist options
  • Save after-the-sunrise/10889451 to your computer and use it in GitHub Desktop.
Save after-the-sunrise/10889451 to your computer and use it in GitHub Desktop.
Python SSL socket with PEM from JKS
# 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
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