Skip to content

Instantly share code, notes, and snippets.

@xombiemp
Created June 11, 2015 05:29
Show Gist options
  • Save xombiemp/c21f6996919cdc32b171 to your computer and use it in GitHub Desktop.
Save xombiemp/c21f6996919cdc32b171 to your computer and use it in GitHub Desktop.
Convert the certificate.p12 that Plex provides to pem format.
#!/usr/bin/python
import sys
import hashlib
from OpenSSL.crypto import *
def main():
if(len(sys.argv) != 3):
print sys.argv[0] + " /path/to/file.p12 ProcessedMachineIdentifier"
sys.exit(0)
hash = hashlib.sha512()
hash.update('plex')
hash.update(sys.argv[2])
passphrase = hash.hexdigest()
with open(sys.argv[1], 'rb') as f:
c = f.read()
p = load_pkcs12(c, passphrase)
certificate = p.get_certificate()
private_key = p.get_privatekey()
type_ = FILETYPE_PEM
key = dump_privatekey(type_, private_key)
cert = dump_certificate(type_, certificate)
print(key + cert)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment