如何将* .p7s证书链导入密钥库?


1

我用这个命令来创建我的csr

keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore domain.jks -dname "CN=*.domain.com,OU=Software Development, O=Company Name, L=Asuncion, ST=Central, C=PY"
keytool -certreq -alias server -keyalg RSA -sigalg SHA256withRSA -file domain.csr -keystore domain.jks

然后我签了我的证书

Web Server CERTIFICATE
-----------------
-----BEGIN CERTIFICATE-----
MIIFZjCCBE6gAwIBAgIQeg8KZmYMVuy/9w/yfpEWozANBgkqhkiG9w0BAQsFADBC
MQswCQYDVQQGEwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEbMBkGA1UEAxMS
UmFwaWRTU0wgU0hBMjU2IENBMB4XDTE2MDMwNzAwMDAwMFoXDTE3MDQwNjIzNTk1
OVowFjEUMBIGA1UEAwwLKi5zZWdweS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQCk2tfnkEN7n6Qtg7wt4lbFHyBN0UW19aSjwme5/zXbLp5S0TUN
MSwxilEGFumUE700oAyT0uQBakV9m/qwrljDdZNgrR2+4VSJfMTL+fRSNQh//pls
TFV8sc6czPxnSKeT8ufsCFF50aadRnK2+GdLC5Vpfhlwfknpu7d3RI5aMFwWzSfG
YNsqShm7sJtYnwA1y3o9eG2XiDuNt6Y5+5lHEafwGxwg8gaL5MpY5wNPDNfr6sYp
YOkJi/JdgRlLnEZn2nTawJRhkODb64vZ5arteN06fBMJjw+yrhfFqt/MEwy2Odiv
WOrWgi1ODft3QHO8jd2JCX4j/apBTEm/acmtAgMBAAGjggKCMIICfjAhBgNVHREE
GjAYggsqLnNlZ3B5LmNvbYIJc2VncHkuY29tMAkGA1UdEwQCMAAwKwYDVR0fBCQw
IjAgoB6gHIYaaHR0cDovL2dwLnN5bWNiLmNvbS9ncC5jcmwwbwYDVR0gBGgwZjBk
BgZngQwBAgEwWjAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29t
L2xlZ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Nvxm5suOpDkZALeVAjmR
Cw7+OC7RHQWa9k0+bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5asz
PeE4uwc2hGKceeoWMPRfwCvocWvk+QIDAQABo4HwMIHtMB8GA1UdIwQYMBaAFEjm
aPkr0rKV10fYIyAQTzOYkJ/UMB0GA1UdDgQWBBTAephojYn7qwVkDBF9qn1luMrM
TjAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjA6BgNVHR8EMzAxMC+g
LaArhilodHRwOi8vY3JsLmdlb3RydXN0LmNvbS9jcmxzL3NlY3VyZWNhLmNybDBO
BgNVHSAERzBFMEMGBFUdIAAwOzA5BggrBgEFBQcCARYtaHR0cHM6Ly93d3cuZ2Vv
dHJ1c3QuY29tL3Jlc291cmNlcy9yZXBvc2l0b3J5MA0GCSqGSIb3DQEBBQUAA4GB
AHbhEm5OSxYShjAGsoEIz/AIx8dxfmbuwu3UOx//8PDITtZDOLC5MH0Y0FWDomrL
NhGc6Ehmo21/uBPUR/6LWlxz/K7ZGzIZOKuXNBSqltLroxwUCEm2u+WR74M26x1W
b8ravHNjkOR/ez4iyz0H7V84dJzjA1BOoa+Y7mHyhD8S
-----END CERTIFICATE-----

我还收到了一个p7s文件(domain.com.p7s)

我已尝试以多种不同的方式将其正确导入密钥库,但我收到此页面中显示的错误 https://thedomain.com/ > ERR_CERT_AUTHORITY_INVALID

导入此链的命令是什么?这不是我第一次这样做,但这次我无法让它发挥作用。


.p7s文件是数字签名电子邮件的证书。

Answers:


4

在您的情况下,由于您已在密钥库中拥有私钥,因此可以通过以下命令导入PKCS#7证书链(* .p7s / * .p7b ...):

 keytool -import -alias <same alias as the key> -file <p7 filename> -keystore <keystore filename>

然而,如果您要导入密钥库中具有密钥的证书链whitout,则keytool不接受一次性导入它,因此您必须遵循此方法(或者如果之前的方法不起作用):

要继续,只需为每个证书创建一个pem文件并将其导入密钥库,并将证书的别名设置为密钥别名。

(每个pem文件的内容是证书的base64形式:

-----BEGIN CERTIFICATE-----

...

-----END CERTIFICATE-----

要使用keytool导入证书:

keytool -import -alias server -file server.pem -trustcacerts -keystore domain.jks

资料来源:

注意 :
管理密钥库时,kse51非常有用。你可以在这里找到它 : https://sourceforge.net/projects/keystore-explorer/ 。 (我和软件编辑器没什么关系)


这实际上解决了这个问题,是的,keytool确实可以使用p7s文件,至少在我的情况下 stackoverflow.com/a/35857320/39998
David Hofmann

@DavidHofmann具体, keytool 接受pkcs7证书链 为你的私人钥匙 (或者确切地说,对于密钥库中的私钥条目),但不是具有(一)其他密钥的证书的一个,包括(a)属于(一个)其他方的密钥。
dave_thompson_085

感谢那些信息@ dave_thompson_085,我更新了我的答案
zr_ifrit
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.