Last active
August 29, 2015 14:15
-
-
Save Neoklosch/3dcf263e0077ab204211 to your computer and use it in GitHub Desktop.
This is a tool to create a apns certificate without passphrase. You need these kind of certificate for the django push server.
This file contains 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
#!/usr/bin/env python | |
import subprocess, sys, os, getopt, os.path | |
''' | |
This is a tool to create a apns certificate without passphrase. | |
You need these kind of certificate for the django push server (https://github.com/jleclanche/django-push-notifications). | |
''' | |
def print_help(): | |
print ''' | |
CertyPy | |
This is a tool to create a apns certificate without a passphrase. | |
You need these kind of certificate for the django push server. | |
SYNOPSIS | |
./certypy.py cer_input p12_input pem_output | |
DESCRIPTION | |
cer_input | |
the certificate file, extension is .cer | |
p12_input | |
the p12 file, extension is .p12 | |
pem_output | |
the ouput file | |
''' | |
def merge_two_files(first_file_path, second_file_path, output_file_path): | |
output_file = open(output_file_path, 'w') | |
first_file = open(first_file_path, 'r') | |
output_file.write(first_file.read()) | |
first_file.close() | |
second_file = open(second_file_path, 'r') | |
output_file.write(second_file.read()) | |
second_file.close() | |
output_file.close() | |
def main(): | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "hc:p:o:", ["cerfile=", "p12file=", "outputfile="]) | |
except getopt.GetoptError: | |
print_help() | |
sys.exit(2) | |
cer_input_file = '' | |
p12_input_file = '' | |
outputfile = '' | |
for opt, arg in opts: | |
if opt == '-h': | |
print_help() | |
sys.exit() | |
elif opt in ("-c", "--cerfile"): | |
cer_input_file = arg | |
elif opt in ("-p", "--p12file"): | |
p12_input_file = arg | |
elif opt in ("-o", "--outputfile"): | |
outputfile = arg | |
if cer_input_file == '' or p12_input_file == '' or outputfile == '': | |
print_help() | |
sys.exit() | |
if not os.path.exists(cer_input_file): | |
print "certypy: " + cer_input_file + ": No such file or directory" | |
sys.exit() | |
elif not os.path.exists(p12_input_file): | |
print "certypy: " + p12_input_file + ": No such file or directory" | |
sys.exit() | |
elif os.path.exists(outputfile): | |
print "certypy: " + outputfile + ": File already exists" | |
sys.exit() | |
cer_to_pem_command = ["openssl", "x509", "-in", cer_input_file, "-inform", "DER", "-outform", "PEM", "-out", "cert.pem"] | |
p12_to_pem_command = ["openssl", "pkcs12", "-in", p12_input_file, "-out", "key.pem", "-nocerts", "-nodes"] | |
remove_passphrase_command = ["openssl", "rsa", "-in", "key.pem", "-out", "key_noenc.pem"] | |
subprocess.call(cer_to_pem_command) | |
subprocess.call(p12_to_pem_command) | |
subprocess.call(remove_passphrase_command) | |
merge_two_files("cert.pem", "key_noenc.pem", outputfile) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment