2012-08-31 2 views
0

아래 dialgoue를 자동화하려고합니다. 나는 입력 한 내용에 첫 번째 암호가 필요하다고 생각하지 않는다. 나는 힘든 시간을 보내고 pexpect를 얻으려고 노력하고 있습니다.pexpect를 사용하여 openssl req -new -key를 자동화하십시오. server.key -out server.csr

다음
import pexpect 
child = pexpect.spawn ('openssl req -new -key server.key -out server.csr') 
child.expect ('key*') 
child.sendline ('YYYY') 
child.expect ("Country Name (2 letter code) [AU]:") 
child.sendline ('US') 
child.expect ("State or Province Name (full name) [Some-State]:") 
child.sendline ('HI') 
child.expect ("Locality Name (eg, city) []:") 
child.sendline ('US') 
child.expect ("Organization Name (eg, company) [Internet Widgits Pty Ltd]:") 
child.sendline ('US') 
child.expect ("Organizational Unit Name (eg, section) []:") 
child.sendline ('US') 
child.expect ("Common Name (e.g. server FQDN or YOUR name) []:") 
child.sendline ('US') 
child.expect ("Email Address []:") 
child.sendline ('US') 
child.expect ("A challenge password []:") 
child.sendline ("yy") 
child.expect ("An optional company name []:") 
child.sendline ("yy") 
child.expect(pexpect.EOF) 

내 오류입니다 :

challenge password []: 
An optional company name []: 
[email protected]:/home/ubuntu# clear 
[email protected]:/home/ubuntu# python vv.py 
Traceback (most recent call last): 
    File "vv.py", line 5, in <module> 
    child.expect ("Country Name (2 letter code) [AU]:") 
    File "/usr/local/lib/python2.7/dist-packages/pexpect-2.4-py2.7.egg/pexpect.py", line 1316, in expect 
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize) 
    File "/usr/local/lib/python2.7/dist-packages/pexpect-2.4-py2.7.egg/pexpect.py", line 1330, in expect_list 
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize) 
    File "/usr/local/lib/python2.7/dist-packages/pexpect-2.4-py2.7.egg/pexpect.py", line 1401, in expect_loop 
    raise EOF (str(e) + '\n' + str(self)) 
pexpect.EOF: End Of File (EOF) in read_nonblocking(). Exception style platform. 
<pexpect.spawn object at 0x2083850> 
version: 2.4 ($Revision: 516 $) 
command: /usr/bin/openssl 
args: ['/usr/bin/openssl', 'req', '-new', '-key', 'server.key', '-out', 'server.csr'] 
searcher: searcher_re: 
    0: re.compile("Country Name (2 letter code) [AU]:") 
buffer (last 100 chars): 
before (last 100 chars): p_enc.c:539: 
140006640854688:error:0906A065:PEM routines:PEM_do_header:bad decrypt:pem_lib.c:476: 

after: <class 'pexpect.EOF'> 
match: None 

답변

0

왜 당신은 설정 파일과 위의를 시도하지 않는 아래

[email protected]:/home/ubuntu# openssl req -new -key server.key -out server.csr 
Enter pass phrase for server.key: 
You are about to be asked to enter information that will be incorporated 
into your certificate request. 
What you are about to enter is what is called a Distinguished Name or a DN. 
There are quite a few fields but you can leave some blank 
For some fields there will be a default value, 
If you enter '.', the field will be left blank. 
----- 
Country Name (2 letter code) [AU]: 
State or Province Name (full name) [Some-State]: 
Locality Name (eg, city) []: 
Organization Name (eg, company) [Internet Widgits Pty Ltd]: 
Organizational Unit Name (eg, section) []: 
Common Name (e.g. server FQDN or YOUR name) []: 
Email Address []: 

Please enter the following 'extra' attributes 
to be sent with your certificate request 
A challenge password []: 
An optional company name []: 

내 pexpect 코드?

하려면 openssl REQ -new -key은 server.key -out server.csr -config으로 config.txt

http://webservices.itcs.umich.edu/mediawiki/radmind/index.php/Example_OpenSSL_Configuration_File

관련 문제