【发布时间】:2016-10-08 06:48:56
【问题描述】:
有一个java项目,有一个jks认证文件。但它很旧(已过期)。现在我必须将其更改为新的 pfx 认证文件。但我不知道我是怎么做到的。
这里有一些关于当前项目的信息;
这是带有旧 jks 文件配置的 pom.xml
<profile>
<id>sign-base</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<storepass>OldJKSKeystorePass</storepass>
<keypass>OldJKSKeyPass</keypass>
<arguments>
<argument>-tsa</argument>
<argument>http://timestamp.globalsign.com/scripts/timestamp.dll</argument>
</arguments>
<keystore>${pom.parent.basedir}${file.separator}OldJKSFile.jks</keystore>
<alias>1</alias>
</configuration>
</plugin>
</plugins>
</build>
</profile>
这里有一个名为“SpecialHttpsClient”的java类扩展了默认的httpsClient,它有一个类似的方法。 mykeystore 文件在资源包下,我不知道。
private SSLSocketFactory newSslSocketFactory() {
InputStream in =null;
try {
KeyStore trusted = KeyStore.getInstance("JKS");
in = this.getClass().getResourceAsStream("/mykeystore");
trusted.load(in, "mykeystorepass".toCharArray());
SSLSocketFactory sf = new SSLSocketFactory(trusted);
sf.setHostnameVerifier(sslSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
return sf;
} catch (Exception e) {
logger.error("An error was occurred while creating SSLSocketFactory!***************", e);
return null;
} finally {
if(in!=null )
try {
in.close();
} catch (IOException e) {
logger.error("An error was occurred while creating SSLSocketFactory!***************", e);
}
}
}
这是另一个名为 SpecialHttpsConnection 的类,它有一个类似的方法。我对文档文件一无所知。
private static TrustManagerFactory getTrustManagerFactory() throws Exception {
if(trustManagerFactory==null) {
try {
KeyStore trusted =null;
trusted = KeyStore.getInstance("JKS");
InputStream in = SpecialHttpsConnection.class.getResourceAsStream("/document");
try {
trusted.load(in, "T1@ePudf27?wE".toCharArray());
} finally {
in.close();
}
trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trusted);
} catch(Exception e) {
logger.error("An error was occurred while creating TrustManagerFactory!***************",e);
throw e;
}
}
return trustManagerFactory;
}
我的问题是;我怎样才能用旧的更改“mynewcert.pfx”文件?
【问题讨论】:
-
如果您不想更改代码,则必须使用
keytool手动将 JKS 文件转换为 PKCS12 文件。
标签: java keystore pfx jarsigner jks