pyjks保存无法通过keytool打开的jks文件
问题描述:
我想使用pyjks加载包含可信证书的密钥库,并且我一直试图添加一个可信证书,从文件('trust2.pub')中读取到它。pyjks保存无法通过keytool打开的jks文件
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与密钥工具将其打开,或密匙资源管理器在Windows中,我得到以下错误:
java.io.IOException: Short read of DER length
所以,也许这是我在JKS文件中添加新TrustedCertEntry的方式,但我可以不知道,因为pyjks加载它没有问题。
如果有人能帮上忙,我会很感激。
谢谢
答
我想通了。导入.pub文件是我的错误。要导入的正确文件是.cer文件X.509格式。所以如果其他人犯了同样的错误,我会在这里留下。