2016-06-08 2 views
0

Il existe un projet java et un fichier de certification jks. Mais c'est vieux (expiré). Maintenant, je dois changer un nouveau fichier de certification pfx. Mais je ne sais pas comment je le fais.Comment changer le nouveau fichier cert pfx en ancien fichier jks dans le projet java

Voici quelques informations sur le projet en cours;

c'est pom.xml avec une ancienne configuration de fichier de

<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> 

Ici, il y a une classe java qui appelle « SpecialHttpsClient » extension par défaut httpsClient, et il a une méthode comme ça. Le fichier mykeystore est sous le paquet de ressources et je ne sais pas à ce sujet.

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); 
       } 
     } 
    } 

Voici une autre classe dont le nom est SpecialHttpsConnection et dont la méthode est similaire. Je ne sais rien sur le fichier de document.

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, "[email protected]?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; 
    } 

Mon problème est que; comment puis-je changer "mynewcert.pfx" fichier avec vieux?

+0

Si vous ne voulez pas changer votre code, vous devez convertir manuellement votre fichier JKS en fichier PKCS12 en utilisant 'keytool'. –

Répondre

0

Voici la solution pour jarsigner, peut être utile pour quelqu'un

cmd ouvert et tapez cd aller/votre/jre/bin/répertoire/

Type

keytool - importkeystore -srckeystore "c: \ mypfxfolderdirectory \ mypfxfile.pfx" -srcstoretype PKCS12 -destkeystore "c: \ mypfxfolderdirectory \ myjksfile.jks" -deststoretype JKS -srcstorepass pfxFilePass -deststorepass jksFileStorePass -srcalias 1 -destalias 1 -destkeypass jksFileKeyPass -nopromptAprès cela, votre fichier jks sera créé avec deux mots de passe: passe magasin, passe clé.