我想使用 pyjks 加载包含受信任证书的密钥库,并且我一直在尝试添加受信任证书,从文件('trust2.pub')中读取。
import jks
ks = jks.KeyStore.load('trustore_file.jks', 'trustore_pass')
new_entry = jks.TrustedCertEntry.new("trust2", open('trust2.pub', 'rb').read())
# Since I have not found an explicit way to add a new TrustedCertEntry,
# I thought this would work (add the 'new_entry' in the ks.entries dict).
ks.entries['trust2']=new_entry
# save the file with the new cert.
ks.save('trustore_file.jks', 'trustore_pass')
这实际上将 jks 文件与新条目一起保存,如果我尝试使用给定密码重新加载文件,我可以看到它。但是当我尝试使用 ubuntu 中的 keytool 或 Windows 中的 KeyStore Explorer 打开它时,我收到以下错误:
java.io.IOException:DER 长度的短读
所以,也许这是我在 jks 文件中添加新的 TrustedCertEntry 的方式,但我不知道,因为 pyjks 加载它没有问题。
如果有人可以提供帮助,我将不胜感激。
谢谢