首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >using pexpect to automate openssl pexpect -new -key server.key -out server.csr (使用pexpect自动化openssl请求)

using pexpect to automate openssl pexpect -new -key server.key -out server.csr (使用pexpect自动化openssl请求)
EN

Stack Overflow用户
提问于 2012-08-31 20:43:14
回答 1查看 911关注 0票数 0

我正在尝试自动化下面的dialgoue。除了第一个密码外,我不关心输入的是什么。我很难让pexpect去工作。

代码语言:javascript
复制
root@ffffff:/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代码:

代码语言:javascript
复制
  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)

下面是我的错误:

代码语言:javascript
复制
challenge password []:
An optional company name []:
root@li494-175:/home/ubuntu# clear
root@li494-175:/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
EN

回答 1

Stack Overflow用户

发布于 2012-08-31 21:11:29

为什么你不用一个配置文件来尝试上面的方法呢?

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12215635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档