我很新HTTPS/SSL/TLS,我对使用证书进行身份验证时客户端应该提供的内容有点困惑.
我正在编写一个Java客户端,需要为POST特定的数据执行简单的数据URL.那部分工作正常,唯一的问题是应该完成它HTTPS.该HTTPS部分相当容易处理(使用HTTPclient或使用Java的内置HTTPS支持),但我仍然坚持使用客户端证书进行身份验证.我注意到这里已经有一个非常类似的问题,我还没有用我的代码试过(很快就会这么做).我当前的问题是 - 无论我做什么 - Java客户端永远不会发送证书(我可以使用PCAP转储检查).
我想知道客户端在使用证书进行身份验证时应该向服务器提供什么内容(特别是对于Java - 如果这一点很重要)?这是一个JKS文件,还是PKCS#12?什么应该在他们身上; 只是客户端证书,还是密钥?如果是这样,哪个关键?对于所有不同类型的文件,证书类型等存在相当多的混淆.
正如我之前所说,我是新手,HTTPS/SSL/TLS所以我也会欣赏一些背景信息(不必是一篇文章;我会接受好文章的链接).
我使用以下步骤创建一个新的Java密钥库,其中包含一对私有/公共密钥,供Java(内部)服务器使用TLS.请注意证书是自签名的:
1)使用AES256生成密钥
openssl genrsa -aes256 -out server.key 1024
Run Code Online (Sandbox Code Playgroud)
2)为CA生成证书请求
openssl req -x509 -sha256 -new -key server.key -out server.csr
Run Code Online (Sandbox Code Playgroud)
3)生成自签名到期时间10年
openssl x509 -sha256 -days 3652 -in server.csr -signkey server.key -out selfsigned.crt
Run Code Online (Sandbox Code Playgroud)
4)使用像KeyStoreExplorer这样的程序在新的JKS中导入对(私钥和自签名证书)
这有效,但我想在不使用GUI的情况下实现最后一步.
我知道如何仅导入自签名证书:
// create the keystore and import the public key. THIS WILL NOT IMPORT THE PRIVATE KEY SO THE KEYSTORE CAN'T BE USED ON THE SERVER TO MAKE THE TLS CONNECTION
/usr/java/jdk1.6.0_45/bin/keytool -import -alias myservercert -file server.crt -keystore mykeystore.jks
Run Code Online (Sandbox Code Playgroud)
所以问题是:我如何创建Java KeyStore并使用公钥和私钥导入证书而不使用GUI?
我正在尝试连接到安全的Web服务.
即使我的密钥库和信任库已正确设置,我也会收到握手失败.
经过几天的挫折,无休止的谷歌搜索并询问周围的每个人我发现唯一的问题是java选择不在握手期间将客户端证书发送到服务器.
特别:
我的问题:
我确实为此设置了一个肮脏的解决方法,但我对此并不高兴所以如果有人能为我澄清这个,我会很高兴.
我怎样才能使用字符串的签名SHA1withRSA,如果我已经有了私钥byte[]或String?
我通过复制我计划连接的IDP的509条目生成了testIdp.cer文件.然后我通过执行以下命令创建了JKS文件
keytool -importcert -alias adfssigning -keystore C:\Users\user\Desktop\samlKeystore.jks -file C:\Users\user\Desktop\testIdp.cer
Run Code Online (Sandbox Code Playgroud)
执行时,它要求输入我已给出密码的密码.对于"信任这个证书?[no]:"这个问题,我给出了"y"作为输入.消息出现为"证书已添加到密钥库".
然后我在securityContext.xml中配置了以下详细信息
<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
<constructor-arg value="classpath:security/samlKeystore.jks"/>
<constructor-arg type="java.lang.String" value="mypassword"/>
<constructor-arg>
<map>
<entry key="adfssigning" value="mypassword"/>
</map>
</constructor-arg>
<constructor-arg type="java.lang.String" value="adfssigning"/>
</bean>
<bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
<property name="alias" value="adfssigning" />
<property name="signingKey" value="adfssigning"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
但是当我运行应用程序时,我在服务器启动时以及加载应用程序的主页时会遇到以下两个异常.如果我错过任何其他内容,任何人都可以告诉我.
启动服务器时发生此异常
Caused by: org.opensaml.saml2.metadata.provider.FilterException: Signature trust establishment failed for metadata entry
at org.opensaml.saml2.metadata.provider.SignatureValidationFilter.verifySignature(SignatureValidationFilter.java:327)
at org.opensaml.saml2.metadata.provider.SignatureValidationFilter.processEntityGroup(SignatureValidationFilter.java:240)
at org.opensaml.saml2.metadata.provider.SignatureValidationFilter.doFilter(SignatureValidationFilter.java:158)
at org.opensaml.saml2.metadata.provider.AbstractMetadataProvider.filterMetadata(AbstractMetadataProvider.java:493)
at org.opensaml.saml2.metadata.provider.AbstractReloadingMetadataProvider.processNonExpiredMetadata(AbstractReloadingMetadataProvider.java:395)
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序的主页时,会发生此异常
java.lang.UnsupportedOperationException: trusted certificate entries are not password-protected
at java.security.KeyStoreSpi.engineGetEntry(Unknown Source)
at java.security.KeyStore.getEntry(Unknown Source)
at org.opensaml.xml.security.credential.KeyStoreCredentialResolver.resolveFromSource(KeyStoreCredentialResolver.java:132)
Run Code Online (Sandbox Code Playgroud) Ubuntu 14,tomcat 7,java 7
godaddy提供的our.crt,our.key和gd_bundle-g2-g1.crt.该捆绑包中有3个证书(通过vi'ing文件看到).
注意,我们的key和crt在node.js上使用没有问题.
我们从现有的crt创建了一个密钥库:
cd /etc/ssl
openssl pkcs12 -export -in our.crt -inkey our.key -out our.p12 -name tomcat -CAfile gd_bundle-g2-g1.crt -caname root -chain
Run Code Online (Sandbox Code Playgroud)
server.xml是这样的:
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="200" scheme="https" secure="true"
keystoreType="PKCS12"
keystoreFile="/etc/ssl/our.p12" keystorePass=""
clientAuth="false" sslProtocol="TLS" /> …Run Code Online (Sandbox Code Playgroud) 一个.从商店中提取现有证书密钥:
keytool -v -importkeystore -srckeystore keystore -srcalias one -destkeystore temppp -deststoretype PKCS12 -srcstorepass passwordd -deststorepass passwordd
Run Code Online (Sandbox Code Playgroud)
湾 从导出的证书中提取私钥:
openssl pkcs12 -in temppp -out csr_private.key -nocerts -nodes -password pass:passwordd
Run Code Online (Sandbox Code Playgroud)
C.使用提取的密钥生成csr:
openssl req -nodes -sha256 -new -key csr_private.key -out request.csr -subj '/C=IL/ST=Unknown/L=Unknown/O=Bla/OU=Bla/CN=BLAAAA'
Run Code Online (Sandbox Code Playgroud)
d.生成自签名证书和密钥:
openssl req -x509 -newkey rsa:2048 -keyout ca_key.pem -nodes -sha512 -days 4096 -subj '/C=IL/ST=Unknown/L=Unknown/O=Bla Bla/OU=BLA/CN=FOOO' -out ca.pem
Run Code Online (Sandbox Code Playgroud)
即 使用自签名证书对csr进行签名:
openssl x509 -in request.csr -out signed_cert.pem -req -signkey ca_key.pem -days 1001
Run Code Online (Sandbox Code Playgroud)
F.将签名证书和csr密钥导出到一个p12文件:
openssl pkcs12 -export -in signed_cert.pem -inkey csr_private.key -out …Run Code Online (Sandbox Code Playgroud) 在从我的CA下载证书后,我按照以下步骤为Tomcat 7设置SSL,I:
修改了tomcat server.xml文件到此(很多站点都有类似的conf):
<Connector
port="8443"
SSLEnabled="true"
protocol="HTTP/1.1"
maxThreads="150"
scheme="https"
secure="true"
keystoreFile="conf/.keystore"
keystorePass="password"
clientAuth="false"
sslProtocol="TLS"
/>
Run Code Online (Sandbox Code Playgroud)在我打开浏览器访问网站并在Chrome中出现ERR_SSL_VERSION_OR_CIPHER_MISMATCH错误以及Firefox下的"无常见加密算法"错误之前,一切似乎都很好.
我花了几个小时但却无法弄清楚问题是什么,并且会感谢能够解释这个问题的人.
更新 它现在在keystoreFile更改为.pfx文件后工作,但为什么它不能通过跟随java keystore(.keystore)导入.cer文件方法?
我使用私钥创建了 PKCS12 文件,并使用 openssl 创建了公共证书。我正在尝试导入 PCKS12,但收到错误密钥库密码是正确的。我在命令行参数中添加了密码,如下所示:
openssl pkcs12 -export -in myCert.cer -inkey privatekey.key -out pkcs12.p12 -name somename -password pass:someSecret2022
Run Code Online (Sandbox Code Playgroud)
然后我使用以下 keytool 命令:
keytool -importkeystore -srckeystore pkcs12.p12 -srcstoretype pkcs12 -destkeystore some.jks -deststoretype jks -srcstorepass someSecret2022 -deststorepass changeit
Run Code Online (Sandbox Code Playgroud)
我不断收到错误
keytool error: java.io.IOException: keystore password was incorrect
Run Code Online (Sandbox Code Playgroud)
最重要的是,我使用相同的pcks12.p12文件在 Windows 中导入,它接受上述密码。
我使用的是 zulu 8 java 版本1.8.0_322和 openssl 版本 3.0.3。
感谢您的帮助。
我需要创建一个 jave 密钥库,因此我下载了最新版本的 openssl 但不断收到:
keytool error: java.io.IOException: keystore password was incorrect
如果我尝试导入 .p12,Windows 也会告诉我密码错误。经过几个小时的努力,我终于下载了 v1.1.1,POW 一切正常了!
问题解决了!但为什么 - 为什么 OpenSSL v3.0.0 不像 v1.1.1 那样工作?
C:\openssl3> openssl pkcs12 -export -name tomcat -in cert.cer -inkey key -out ks300.p12
C:\openssl3> openssl pkcs12 -info -in ks300.p12
Enter Import Password:
<works fine>
...
</works fine>
C:\openssl3> keytool -list -v -keystore ks300.p12
Enter keystore password:
keytool error: java.io.IOException: keystore password was incorrect
java.io.IOException: keystore password was incorrect
...
Caused by: java.security.UnrecoverableKeyException: failed to decrypt safe …Run Code Online (Sandbox Code Playgroud) 我们正在尝试将 Wildfly 从8.1.0.Final迁移到26.0.1.Final。目前 Wildfly 正在独立模式下运行,因此standalone.xml 用于配置,到目前为止还没有域配置。
一切正常,包括管理控制台、包部署等,但使用 https 请求 URL 会导致“无法访问此站点”。Wildfly 26.0.1.Final 中的 SSL 配置似乎有问题,因为版本 8.1.0.Final 中使用了相同的 SSL 证书。
这是我们正在使用的 SSL/TLS 配置:
<tls>
<key-stores>
<key-store name="abc-keystore">
<credential-reference clear-text="clearpasswordonetwothree"/>
<implementation type="JKS"/>
<file path="abc-keystore.jks" relative-to="jboss.server.config.dir"/>
</key-store>
</key-stores>
<key-managers>
<key-manager name="applicationKM" key-store="abc-keystore">
<credential-reference clear-text="clearpasswordonetwothree"/>
</key-manager>
</key-managers>
<server-ssl-contexts>
<server-ssl-context name="applicationSSC" key-manager="applicationKM"/>
</server-ssl-contexts>
</tls>
Run Code Online (Sandbox Code Playgroud)
我们已从generate-self-signed-certificate-host="localhsot"配置中删除,因为在我们的情况下证书不是自签名的。正如我之前提到的,8.1.0 版本中使用了相同的 SSL 证书。
请注意,这与版本 26.0.1.Final 特别相关,我不知道除了上述之外是否还需要其他配置。
非常感谢任何帮助。
我正在尝试使用 SSL 连接到 Google Cloud SQL (mysql) 实例。我已经启用了两个 IP 地址和一个具有来自这些 IP 地址的远程访问权限的用户。我还从 Google 的开发者控制台生成了证书文件。
client-key.pem client-cert.pem server-ca.pem
Run Code Online (Sandbox Code Playgroud)
使用来自两个启用的 IP 地址中的每一个的此命令,我成功地建立了连接。
mysql --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem --host=xxx.xxx.xxx.xxx --user=username --password
Run Code Online (Sandbox Code Playgroud)
由于 mysql 客户端工作,我知道我的防火墙设置、用户、证书等设置正确。
现在我想从一个可执行的 jar 文件中与 java 建立类似的连接。
遵循此处概述的步骤:http : //dev.mysql.com/doc/connector-j/en/connector-j-reference-using-ssl.html
Step 1: keytool -import -alias mysqlServerCACert -file cacert.pem -keystore truststore
Run Code Online (Sandbox Code Playgroud)
注意:我用 server-ca.pem 替换了说明中使用的 cacert.pem
Step 2: openssl x509 -outform DER -in client-cert.pem -out client.cert
Step 3: keytool -import -file client.cert -keystore keystore -alias mysqlClientCertificate
Run Code Online (Sandbox Code Playgroud)
这些步骤创建了我的密钥库和信任库文件。在生成这两个文件时,我为它们中的每一个关联了不同的密码。
这是相关的Java代码:
public void testConnection() throws ClassNotFoundException, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Java SSLSockets 将安全性应用于一个简单的聊天应用程序。
我创建了一个自签名 CA,并用它签署了两个证书(全部使用 RSA 密钥),一个用于服务器,另一个用于客户端。之后,我将证书导入服务器的密钥库和客户端的另一个密钥库。
CA :
openssl genrsa -out ca.key 1024 -rsa
openssl req -new -key ca.key -out ca.csr
openssl x509 -req -days 365 -in ca.csr -out ca.crt -signkey ca.key
SERVER CERTIFICATE:
openssl genrsa -out server.key 1024 -rsa
openssl req -new -key server.key -out server.csr
openssl ca -in server.csr -cert ca.crt -keyfile ca.key -out server.crt
CLIENT CERTIFICATE :
openssl genrsa -out client.key 1024 -rsa
openssl req -new -key client.key -out client.csr
openssl ca -in client.csr -cert …Run Code Online (Sandbox Code Playgroud) ssl ×11
java ×8
keytool ×4
https ×3
openssl ×3
certificate ×2
tomcat ×2
ca ×1
jboss ×1
mysql ×1
pkcs#12 ×1
private-key ×1
public-key ×1
sign ×1
spring ×1
spring-saml ×1
wildfly ×1
wildfly-26 ×1
x509 ×1