bikram990/PyScep
GitHub: bikram990/PyScep
一个 Python 编写的 SCEP 客户端/服务器库,用于从 CA 自动注册和管理数字证书,主要面向测试环境。
Stars: 9 | Forks: 7
# PyScep
一个用于从 SCEP CA 注册证书的 Python SCEP 客户端库。
**注意:它旨在用于测试环境**
## 入门指南
### 前置条件
生成一个自签名证书,或使用由 CA 签发的现有证书
#### 生成自签名证书
```
identity, identity_private_key = Client.SigningRequest.generate_self_signed(
cn=u'PyScep-test',
key_usage={u'digital_signature', u'key_encipherment'}
)
```
注意:这将自动生成一个新的 RSA 密钥对,您可以选择性地提供一个 `private_key`。
#### 加载现有证书
```
identity, identity_private_key = Client.Certificate.from_p12_file(
p12_file='/path/to/cert.p12',
password='password'
)
```
### 签名请求
```
csr, private_key = Client.SigningRequest.generate_csr(
cn=u'PyScep-test',
key_usage={u'digital_signature', u'key_encipherment'},
password='password'
)
```
注意:这将自动生成一个新的 RSA 密钥对,您可以选择性地提供一个 `private_key`。
### 创建客户端
```
client = Client.Client(
'http://:/ejbca/publicweb/apply/scep/pkiclient.exe'
)
```
上面的示例为 [EJBCA](https://www.ejbca.org/) 创建了一个示例客户端。请根据正在使用的 CA 服务器更新路径。
### 注册
```
res = client.enrol(
csr=csr,
identity=identity,
identity_private_key=identity_private_key,
identifier=identifier ## An optional identifier how CA Server identifies the CA
)
if res.status == PKIStatus.FAILURE:
print res.fail_info
elif res.status == PKIStatus.PENDING:
print res.transaction_id
else:
print res.certificate
```
### 轮询
```
res = client.poll(
identity=identity,
identity_private_key=identity_private_key,
subject=subject,
transaction_id=transaction_id
)
```
响应与注册相同。
### 获取证书
```
res = client.get_cert(
identity=identity,
identity_private_key=identity_private_key,
serial_number=1234567890
)
```
响应与注册相同。
### CRL
```
res = client.get_crl(
identity=identity,
identity_private_key=identity_private_key,
serial_number=1234567890
)
if res.status == PKIStatus.FAILURE:
print res.fail_info
elif res.status == PKIStatus.PENDING:
print res.transaction_id
else:
print res.crl
```
### 获取轮换证书
```
ca_certificate = client.rollover_certificate()
```
## 致谢
[SCEPy](https://github.com/mosen/SCEPy) 为本项目提供了基础实现
[jscep](https://github.com/jscep/jscep) 提供了接口
标签:Azure 安全, Python, SCEP, 客户端库, 密码学, 手动系统调用, 无后门, 证书管理, 逆向工具