jdk/src/java.base/share/classes/sun/security/tools/keytool/Main.java
changeset 27038 64cb6608f8a6
parent 25859 3317bb8137f4
child 27344 890be6336eab
equal deleted inserted replaced
27037:5a6ef51923c4 27038:64cb6608f8a6
    62 import java.security.cert.X509CRLEntry;
    62 import java.security.cert.X509CRLEntry;
    63 import java.security.cert.X509CRLSelector;
    63 import java.security.cert.X509CRLSelector;
    64 import javax.security.auth.x500.X500Principal;
    64 import javax.security.auth.x500.X500Principal;
    65 import java.util.Base64;
    65 import java.util.Base64;
    66 
    66 
       
    67 import sun.security.util.KeyUtil;
    67 import sun.security.util.ObjectIdentifier;
    68 import sun.security.util.ObjectIdentifier;
    68 import sun.security.pkcs10.PKCS10;
    69 import sun.security.pkcs10.PKCS10;
    69 import sun.security.pkcs10.PKCS10Attribute;
    70 import sun.security.pkcs10.PKCS10Attribute;
    70 import sun.security.provider.X509Factory;
    71 import sun.security.provider.X509Factory;
    71 import sun.security.provider.certpath.CertStoreHelper;
    72 import sun.security.provider.certpath.CertStoreHelper;
  1101         } else if (command == KEYPASSWD) {
  1102         } else if (command == KEYPASSWD) {
  1102             keyPassNew = newPass;
  1103             keyPassNew = newPass;
  1103             doChangeKeyPasswd(alias);
  1104             doChangeKeyPasswd(alias);
  1104             kssave = true;
  1105             kssave = true;
  1105         } else if (command == LIST) {
  1106         } else if (command == LIST) {
       
  1107             if (storePass == null
       
  1108                     && !KeyStoreUtil.isWindowsKeyStore(storetype)) {
       
  1109                 printWarning();
       
  1110             }
       
  1111 
  1106             if (alias != null) {
  1112             if (alias != null) {
  1107                 doPrintEntry(alias, out, true);
  1113                 doPrintEntry(alias, out);
  1108             } else {
  1114             } else {
  1109                 doPrintEntries(out);
  1115                 doPrintEntries(out);
  1110             }
  1116             }
  1111         } else if (command == PRINTCERT) {
  1117         } else if (command == PRINTCERT) {
  1112             doPrintCert(out);
  1118             doPrintCert(out);
  1763     }
  1769     }
  1764 
  1770 
  1765     /**
  1771     /**
  1766      * Prints a single keystore entry.
  1772      * Prints a single keystore entry.
  1767      */
  1773      */
  1768     private void doPrintEntry(String alias, PrintStream out,
  1774     private void doPrintEntry(String alias, PrintStream out)
  1769                               boolean printWarning)
       
  1770         throws Exception
  1775         throws Exception
  1771     {
  1776     {
  1772         if (storePass == null && printWarning
       
  1773                 && !KeyStoreUtil.isWindowsKeyStore(storetype)) {
       
  1774             printWarning();
       
  1775         }
       
  1776 
       
  1777         if (keyStore.containsAlias(alias) == false) {
  1777         if (keyStore.containsAlias(alias) == false) {
  1778             MessageFormat form = new MessageFormat
  1778             MessageFormat form = new MessageFormat
  1779                 (rb.getString("Alias.alias.does.not.exist"));
  1779                 (rb.getString("Alias.alias.does.not.exist"));
  1780             Object[] source = {alias};
  1780             Object[] source = {alias};
  1781             throw new Exception(form.format(source));
  1781             throw new Exception(form.format(source));
  2088      * Prints all keystore entries.
  2088      * Prints all keystore entries.
  2089      */
  2089      */
  2090     private void doPrintEntries(PrintStream out)
  2090     private void doPrintEntries(PrintStream out)
  2091         throws Exception
  2091         throws Exception
  2092     {
  2092     {
  2093         if (storePass == null
       
  2094                 && !KeyStoreUtil.isWindowsKeyStore(storetype)) {
       
  2095             printWarning();
       
  2096         } else {
       
  2097             out.println();
       
  2098         }
       
  2099 
       
  2100         out.println(rb.getString("Keystore.type.") + keyStore.getType());
  2093         out.println(rb.getString("Keystore.type.") + keyStore.getType());
  2101         out.println(rb.getString("Keystore.provider.") +
  2094         out.println(rb.getString("Keystore.provider.") +
  2102                 keyStore.getProvider().getName());
  2095                 keyStore.getProvider().getName());
  2103         out.println();
  2096         out.println();
  2104 
  2097 
  2113         out.println();
  2106         out.println();
  2114 
  2107 
  2115         for (Enumeration<String> e = keyStore.aliases();
  2108         for (Enumeration<String> e = keyStore.aliases();
  2116                                         e.hasMoreElements(); ) {
  2109                                         e.hasMoreElements(); ) {
  2117             String alias = e.nextElement();
  2110             String alias = e.nextElement();
  2118             doPrintEntry(alias, out, false);
  2111             doPrintEntry(alias, out);
  2119             if (verbose || rfc) {
  2112             if (verbose || rfc) {
  2120                 out.println(rb.getString("NEWLINE"));
  2113                 out.println(rb.getString("NEWLINE"));
  2121                 out.println(rb.getString
  2114                 out.println(rb.getString
  2122                         ("STAR"));
  2115                         ("STAR"));
  2123                 out.println(rb.getString
  2116                 out.println(rb.getString
  2920                     + "\t SHA1: " + getCertFingerPrint("SHA1", cert));
  2913                     + "\t SHA1: " + getCertFingerPrint("SHA1", cert));
  2921         */
  2914         */
  2922 
  2915 
  2923         MessageFormat form = new MessageFormat
  2916         MessageFormat form = new MessageFormat
  2924                 (rb.getString(".PATTERN.printX509Cert"));
  2917                 (rb.getString(".PATTERN.printX509Cert"));
       
  2918         PublicKey pkey = cert.getPublicKey();
  2925         Object[] source = {cert.getSubjectDN().toString(),
  2919         Object[] source = {cert.getSubjectDN().toString(),
  2926                         cert.getIssuerDN().toString(),
  2920                         cert.getIssuerDN().toString(),
  2927                         cert.getSerialNumber().toString(16),
  2921                         cert.getSerialNumber().toString(16),
  2928                         cert.getNotBefore().toString(),
  2922                         cert.getNotBefore().toString(),
  2929                         cert.getNotAfter().toString(),
  2923                         cert.getNotAfter().toString(),
  2930                         getCertFingerPrint("MD5", cert),
  2924                         getCertFingerPrint("MD5", cert),
  2931                         getCertFingerPrint("SHA1", cert),
  2925                         getCertFingerPrint("SHA1", cert),
  2932                         getCertFingerPrint("SHA-256", cert),
  2926                         getCertFingerPrint("SHA-256", cert),
  2933                         cert.getSigAlgName(),
  2927                         cert.getSigAlgName(),
  2934                         cert.getVersion()
  2928                         pkey.getAlgorithm(),
       
  2929                         KeyUtil.getKeySize(pkey),
       
  2930                         cert.getVersion(),
  2935                         };
  2931                         };
  2936         out.println(form.format(source));
  2932         out.println(form.format(source));
  2937 
  2933 
  2938         if (cert instanceof X509CertImpl) {
  2934         if (cert instanceof X509CertImpl) {
  2939             X509CertImpl impl = (X509CertImpl)cert;
  2935             X509CertImpl impl = (X509CertImpl)cert;