前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python练习之通过python pe

python练习之通过python pe

作者头像
py3study
发布2020-01-09 01:51:05
4580
发布2020-01-09 01:51:05
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
#!/usr/bin/evn python
import re,sys,os,pexpect
from pexpect import *
#coding=utf-8
#create environment
if os.path.exists('./demoCA'):
        os.system('rm -rf ./demoCA')
os.system("mkdir ./demoCA")
os.system("mkdir ./demoCA/newcerts  ./demoCA/private")
os.system('chmod g-rwx,o-rwx ./demoCA/private')
os.system('echo "01" > ./demoCA/serial')
os.system('touch ./demoCA/index.txt')
#create root ca
child0=pexpect.spawn('openssl req -new -x509 -keyout ca0.key -out ca0.crt -config openssl.cnf')
child0.expect('phrase:')
child0.sendline('ding123')
child0.expect('phrase:')
child0.sendline('ding123')
#input root certificate information
child0.expect('Country Name *')
child0.sendline('cn')
child0.expect('Province')
child0.sendline('beijing')
child0.expect('City')
child0.sendline('haidian')
child0.expect('Company')
child0.sendline('test')
child0.expect('Organizational')
child0.sendline('test')
child0.expect('hostname')
child0.sendline('www.test.com')
child0.expect('Email')
child0.sendline('test@test.com')
#create root.pfx
child1=pexpect.spawn('openssl pkcs12 -export -inkey ca0.key -in ca0.crt -out ca0.pfx')
child1.expect('phrase')
child1.sendline('ding123')
child1.expect('Password')
child1.sendline('')
child1.expect('Password')
child1.sendline('')
#os.system('openssl pkcs12 -export -inkey ca0.key -in ca0.crt -out ca0.pfx')
print("creat root ca sucess")
#start sycle
for i in range(1,10):
        a='ca'
# Create key file
        cmd2='openssl genrsa -des3 -out '+a+str(i)+'.key' + ' 2048'
        child2=pexpect.spawn(cmd2)
        child2.expect('phrase')
        child2.sendline('ding123')
        child2.expect('Verifying')
        child2.sendline('ding123')
        print("create %s sucess") %(a+str(i)+'.key')
# Certificate Signing Request
        cmd3='openssl req -new -key '+ a+str(i)+'.key' + ' -out '+a+str(i)+'.csr' +' -config openssl.cnf' 
        child3=pexpect.spawn(cmd3)
        child3.expect('phrase')
        child3.sendline('ding123')
        child3.expect('Country')
        child3.sendline('cn')
        child3.expect('Province')
        child3.sendline('beijing')
        child3.expect('City')
        child3.sendline('haidian')
        child3.expect('Company')
        child3.sendline('test')
        child3.expect('Unit Name')
        Uname='test'+str(i)
        child3.sendline(Uname)
        child3.expect('hostname')
        hname='www.test'+str(i)+'.com'
        child3.sendline(hname)
        child3.expect('Email')
        email='test'+str(i)+'@test'+str(i)+'.com'
        child3.sendline(email)
        child3.expect('password')
        child3.sendline('')
        child3.expect('company')
        child3.sendline('')
        print("create %s sucess") %(a+str(i)+'.csr')
#Signature
        cmd4='openssl ca -in ' + a+str(i)+'.csr'+' -out '+a+str(i)+'.crt'+' -cert '+ a+str(i-1)+'.crt' +' -keyfile ' + a+str(i-1)+'.key'+ ' -config openssl.cnf'
        child4=pexpect.spawn(cmd4)
        child4.expect('phrase')
        child4.sendline('ding123')
        child4.expect('y/n')
        child4.sendline('y')
        child4.expect('y/n')
        child4.sendline('y')
        print('create %s sucess') %(a+str(i)+'.crt')
#create pfx file
        cmd5='openssl pkcs12 -export -inkey ' + a+str(i)+'.key' + ' -in ' + a+str(i)+'.crt' + ' -out ' +a+str(i)+'.pfx'
        child5=pexpect.spawn(cmd5)
        child5.expect('phrase')
        child5.sendline('ding123')
        child5.expect('Password')
        child5.sendline('')
        child5.expect('Password')
        child5.sendline('')
        print('create %s sucess') %(a+str(i)+'.pfx')
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档