src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java
changeset 55312 d8942f5d6c75
parent 53398 dd1be616c95e
child 57766 81ce766c9111
equal deleted inserted replaced
55311:d60b24a09900 55312:d8942f5d6c75
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1298             certStr.append(tab).append(c.getType());
  1298             certStr.append(tab).append(c.getType());
  1299         }
  1299         }
  1300 
  1300 
  1301         String alias = storeHash.get(c);
  1301         String alias = storeHash.get(c);
  1302         if (alias != null) {
  1302         if (alias != null) {
  1303             certStr.append(space).append(alias);
  1303             certStr.append(space).append("(").append(alias).append(")");
  1304         }
  1304         }
  1305 
  1305 
  1306         if (x509Cert != null) {
  1306         if (x509Cert != null) {
  1307 
  1307 
  1308             certStr.append("\n").append(tab).append("[");
  1308             certStr.append("\n").append(tab).append("[");
  1423         if (cacheForInKS.containsKey(signer)) {
  1423         if (cacheForInKS.containsKey(signer)) {
  1424             return cacheForInKS.get(signer);
  1424             return cacheForInKS.get(signer);
  1425         }
  1425         }
  1426 
  1426 
  1427         int result = 0;
  1427         int result = 0;
  1428         List<? extends Certificate> certs = signer.getSignerCertPath().getCertificates();
  1428         if (store != null) {
  1429         for (Certificate c : certs) {
  1429             try {
  1430             String alias = storeHash.get(c);
  1430                 List<? extends Certificate> certs =
  1431             if (alias != null) {
  1431                         signer.getSignerCertPath().getCertificates();
  1432                 if (alias.startsWith("(")) {
  1432                 for (Certificate c : certs) {
  1433                     result |= IN_KEYSTORE;
  1433                     String alias = storeHash.get(c);
  1434                 }
  1434                     if (alias == null) {
  1435                 if (ckaliases.contains(alias.substring(1, alias.length() - 1))) {
       
  1436                     result |= SIGNED_BY_ALIAS;
       
  1437                 }
       
  1438             } else {
       
  1439                 if (store != null) {
       
  1440                     try {
       
  1441                         alias = store.getCertificateAlias(c);
  1435                         alias = store.getCertificateAlias(c);
  1442                     } catch (KeyStoreException kse) {
  1436                         if (alias != null) {
  1443                         // never happens, because keystore has been loaded
  1437                             storeHash.put(c, alias);
       
  1438                         }
  1444                     }
  1439                     }
  1445                     if (alias != null) {
  1440                     if (alias != null) {
  1446                         storeHash.put(c, "(" + alias + ")");
       
  1447                         result |= IN_KEYSTORE;
  1441                         result |= IN_KEYSTORE;
  1448                     }
  1442                     }
  1449                 }
  1443                     for (String ckalias : ckaliases) {
  1450                 if (ckaliases.contains(alias)) {
  1444                         if (c.equals(store.getCertificate(ckalias))) {
  1451                     result |= SIGNED_BY_ALIAS;
  1445                             result |= SIGNED_BY_ALIAS;
  1452                 }
  1446                             // must continue with next certificate c and cannot
       
  1447                             // return or break outer loop because has to fill
       
  1448                             // storeHash for printCert
       
  1449                             break;
       
  1450                         }
       
  1451                     }
       
  1452                 }
       
  1453             } catch (KeyStoreException kse) {
       
  1454                 // never happens, because keystore has been loaded
  1453             }
  1455             }
  1454         }
  1456         }
  1455         cacheForInKS.put(signer, result);
  1457         cacheForInKS.put(signer, result);
  1456         return result;
  1458         return result;
  1457     }
  1459     }
  1458 
  1460 
       
  1461     /**
       
  1462      * Maps certificates (as keys) to alias names associated in the keystore
       
  1463      * {@link #store} (as values).
       
  1464      */
  1459     Hashtable<Certificate, String> storeHash = new Hashtable<>();
  1465     Hashtable<Certificate, String> storeHash = new Hashtable<>();
  1460 
  1466 
  1461     int inKeyStore(CodeSigner[] signers) {
  1467     int inKeyStore(CodeSigner[] signers) {
  1462 
  1468 
  1463         if (signers == null)
  1469         if (signers == null)