Skip to content

Instantly share code, notes, and snippets.

@acidprime
Last active December 22, 2015 20:39
Show Gist options
  • Save acidprime/6527638 to your computer and use it in GitHub Desktop.
Save acidprime/6527638 to your computer and use it in GitHub Desktop.
Python Example of Openssl commands needed for CSRs needed for windows
#!/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python
openssl = '/usr/bin/openssl'
from subprocess import Popen, PIPE, STDOUT
def generateUserCSR(user_name,key,csr):
arguments = [
openssl,
'req',
'-new',
'-batch',
'-newkey',
'rsa:2048',
'-nodes',
'-keyout',
'%s' % key,
'-out',
'%s' % csr,
'-subj',
'/CN=%s$' % user_name,
]
execute = Popen(arguments, stdout=PIPE)
out, err = execute.communicate()
def generateMachineCSR(machine_name,key,csr):
arguments = [
openssl,
'req',
'-new',
'-batch',
'-newkey',
'rsa:2048',
'-nodes',
'-keyout',
'%s' % key,
'-out',
'%s' % csr,
'-subj',
'/CN=%s$' % machine_name ,
]
execute = Popen(arguments, stdout=PIPE)
out, err = execute.communicate()
generateMachineCSR('/tmp/machine.key','/tmp/machine.csr')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment