Automate SSL creation in Fabric (Python) -
i'm using fabric automate ssl creation, when run like
local('openssl genrsa -out /etc/ssl/'+hostname+'/'+hostname+'.key 2048')
it prompts me country, state, email address, etc. there can (possibly openssl.cnf?) prevent need user input prompts, or people hack using pexpect?
update:
if put prompt=no
in openssl.cnf, cd
/ssdhome/development/server
, run:
sudo openssl req -new -key './server.key' -out './server.csr' -config='./openssl.cnf'
openssl prints out help
information instead of running above command. have gone wrong?
update 2: -config should not have '=' sign, space. solved. linked copy of openssl.cnf working:
see how answer prompts automatically python fabric?
from ilogue.fexpect import expect, expecting, run def sample(): private_key = "password" hostname = "ubuntu" output_dir = '/etc/ssl/' + hostname prompts = [] prompts += expect('enter pass phrase private.key:',private_key) prompts += expect('verifying - enter pass phrase private.key:private_key',private_key) prompts += expect('enter pass phrase %s/server.key:' % output_dir, private_key) prompts += expect('country name \(2 letter code\) \[au\]:','au') prompts += expect('state or province name \(full name\) \[some-state\]:','state') prompts += expect('locality name \(eg, city\) \[\]:','city') prompts += expect('organization name \(eg, company\) \[internet widgits pty ltd\]:','company') prompts += expect('organizational unit name \(eg, section\) \[\]:','section') prompts += expect('common name \(e.g. server fqdn or name\) \[\]:','fqdn') prompts += expect('email address \[\]:','email@foo.com') prompts += expect('a challenge password \[\]:','challenge_password') prompts += expect('an optional company name \[\]:','optional_company') expecting(prompts): run('openssl genrsa -des3 -out %s/server.key 2048' % output_dir) run('openssl req -new -key %s/server.key -out %s/server.csr' % (output_dir, output_dir)) # fab sample -h localhost
the regular expression applied expect(), need escape [, ], (, ) ...
Comments
Post a Comment