modules/jretools/src/main/java/org/apache/harmony/jretools/keytool/CertImporter.java [144:191]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private static void importSingleX509Reply(KeytoolParameters param,
            X509Certificate newCert) throws CertificateException,
            FileNotFoundException, IOException, KeyStoreException,
            NoSuchAlgorithmException, UnrecoverableKeyException,
            CertPathBuilderException, KeytoolException, NoSuchProviderException {

        String alias = param.getAlias();
        KeyStore keyStore = param.getKeyStore();

        // the certificate to be replaced with certificate reply.
        X509Certificate csrCert = (X509Certificate) keyStore
                .getCertificate(alias);
        // quit if public keys of the imported certificate and csrCert don't
        // match
        PublicKey publicKey = csrCert.getPublicKey();
        if (!Arrays.equals(publicKey.getEncoded(), newCert.getPublicKey()
                .getEncoded())) {
            throw new KeytoolException("Public keys don't match.");
        }
        // quit if the certificates are identical
        if (newCert.equals(csrCert)) {
            throw new KeytoolException("Certificate reply is identical to the "
                    + "certificate in keystore");
        }

        // save the private key to put it in a newly created entry
        PrivateKey privateKey;
        try {
            privateKey = (PrivateKey) keyStore
                    .getKey(alias, param.getKeyPass());
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(
                    "Cannot find the algorithm to recover the key. ", e);
        }

        X509Certificate[] newChain = CertChainVerifier.buildFullCertPath(param,
                newCert);

        // changing the certificate chain //
        // remove the entry with old certificate chain
        keyStore.deleteEntry(alias);

        // set the new certificate chain
        keyStore.setKeyEntry(alias, privateKey, param.getKeyPass(), newChain);
        param.setNeedSaveKS(true);
        System.out
                .println("Certificate reply is successfully installed into the keystore.");
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/jdktools/src/main/java/org/apache/harmony/tools/keytool/CertImporter.java [144:191]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private static void importSingleX509Reply(KeytoolParameters param,
            X509Certificate newCert) throws CertificateException,
            FileNotFoundException, IOException, KeyStoreException,
            NoSuchAlgorithmException, UnrecoverableKeyException,
            CertPathBuilderException, KeytoolException, NoSuchProviderException {

        String alias = param.getAlias();
        KeyStore keyStore = param.getKeyStore();

        // the certificate to be replaced with certificate reply.
        X509Certificate csrCert = (X509Certificate) keyStore
                .getCertificate(alias);
        // quit if public keys of the imported certificate and csrCert don't
        // match
        PublicKey publicKey = csrCert.getPublicKey();
        if (!Arrays.equals(publicKey.getEncoded(), newCert.getPublicKey()
                .getEncoded())) {
            throw new KeytoolException("Public keys don't match.");
        }
        // quit if the certificates are identical
        if (newCert.equals(csrCert)) {
            throw new KeytoolException("Certificate reply is identical to the "
                    + "certificate in keystore");
        }

        // save the private key to put it in a newly created entry
        PrivateKey privateKey;
        try {
            privateKey = (PrivateKey) keyStore
                    .getKey(alias, param.getKeyPass());
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(
                    "Cannot find the algorithm to recover the key. ", e);
        }

        X509Certificate[] newChain = CertChainVerifier.buildFullCertPath(param,
                newCert);

        // changing the certificate chain //
        // remove the entry with old certificate chain
        keyStore.deleteEntry(alias);

        // set the new certificate chain
        keyStore.setKeyEntry(alias, privateKey, param.getKeyPass(), newChain);
        param.setNeedSaveKS(true);
        System.out
                .println("Certificate reply is successfully installed into the keystore.");
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



