Skip to content

Instantly share code, notes, and snippets.

@after-the-sunrise
Last active March 1, 2023 15:34
Show Gist options
  • Select an option

  • Save after-the-sunrise/10889451 to your computer and use it in GitHub Desktop.

Select an option

Save after-the-sunrise/10889451 to your computer and use it in GitHub Desktop.

Revisions

  1. after-the-sunrise revised this gist Apr 16, 2014. 2 changed files with 1 addition and 3 deletions.
    1 change: 0 additions & 1 deletion JKS to PEM
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    # Check the alias
    keytool -list -keystore ${MYKEY}.jks

    3 changes: 1 addition & 2 deletions SSL Socket
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,8 @@

    import socket, ssl

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    ssl_sock = ssl.wrap_socket(s,certfile="${MYKEY}.pem")
    ssl_sock = ssl.wrap_socket(s, certfile="${MYKEY}.pem")

    ssl_sock.connect(('example.com', 443))

  2. after-the-sunrise created this gist Apr 16, 2014.
    9 changes: 9 additions & 0 deletions JKS to PEM
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@

    # 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
    16 changes: 16 additions & 0 deletions SSL Socket
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@

    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