< prev index next >

src/java.base/share/classes/sun/security/tools/keytool/Main.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.tools.keytool;
  27 
  28 import java.io.*;
  29 import java.nio.file.Files;
  30 import java.nio.file.Paths;
  31 import java.security.CodeSigner;
  32 import java.security.CryptoPrimitive;
  33 import java.security.KeyStore;
  34 import java.security.KeyStoreException;
  35 import java.security.MessageDigest;
  36 import java.security.Key;
  37 import java.security.PublicKey;
  38 import java.security.PrivateKey;
  39 import java.security.Signature;
  40 import java.security.Timestamp;
  41 import java.security.UnrecoverableEntryException;
  42 import java.security.UnrecoverableKeyException;
  43 import java.security.Principal;
  44 import java.security.cert.Certificate;
  45 import java.security.cert.CertificateFactory;
  46 import java.security.cert.CertStoreException;
  47 import java.security.cert.CRL;
  48 import java.security.cert.X509Certificate;
  49 import java.security.cert.CertificateException;
  50 import java.security.cert.URICertStoreParameters;


2172      */
2173     private void doImportKeyStore(KeyStore srcKS) throws Exception {
2174 
2175         if (alias != null) {
2176             doImportKeyStoreSingle(srcKS, alias);
2177         } else {
2178             if (dest != null || srckeyPass != null) {
2179                 throw new Exception(rb.getString(
2180                         "if.alias.not.specified.destalias.and.srckeypass.must.not.be.specified"));
2181             }
2182             doImportKeyStoreAll(srcKS);
2183         }
2184 
2185         if (inplaceImport) {
2186             // Backup to file.old or file.old2...
2187             // The keystore is not rewritten yet now.
2188             for (int n = 1; /* forever */; n++) {
2189                 inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n);
2190                 File bkFile = new File(inplaceBackupName);
2191                 if (!bkFile.exists()) {
2192                     Files.copy(Paths.get(srcksfname), bkFile.toPath());
2193                     break;
2194                 }
2195             }
2196 
2197         }
2198 
2199         /*
2200          * Information display rule of -importkeystore
2201          * 1. inside single, shows failure
2202          * 2. inside all, shows sucess
2203          * 3. inside all where there is a failure, prompt for continue
2204          * 4. at the final of all, shows summary
2205          */
2206     }
2207 
2208     /**
2209      * Import a single entry named alias from srckeystore
2210      * @return  1 if the import action succeed
2211      *          0 if user choose to ignore an alias-dumplicated entry
2212      *          2 if setEntry throws Exception




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.security.tools.keytool;
  27 
  28 import java.io.*;
  29 import java.nio.file.Files;
  30 import java.nio.file.Path;
  31 import java.security.CodeSigner;
  32 import java.security.CryptoPrimitive;
  33 import java.security.KeyStore;
  34 import java.security.KeyStoreException;
  35 import java.security.MessageDigest;
  36 import java.security.Key;
  37 import java.security.PublicKey;
  38 import java.security.PrivateKey;
  39 import java.security.Signature;
  40 import java.security.Timestamp;
  41 import java.security.UnrecoverableEntryException;
  42 import java.security.UnrecoverableKeyException;
  43 import java.security.Principal;
  44 import java.security.cert.Certificate;
  45 import java.security.cert.CertificateFactory;
  46 import java.security.cert.CertStoreException;
  47 import java.security.cert.CRL;
  48 import java.security.cert.X509Certificate;
  49 import java.security.cert.CertificateException;
  50 import java.security.cert.URICertStoreParameters;


2172      */
2173     private void doImportKeyStore(KeyStore srcKS) throws Exception {
2174 
2175         if (alias != null) {
2176             doImportKeyStoreSingle(srcKS, alias);
2177         } else {
2178             if (dest != null || srckeyPass != null) {
2179                 throw new Exception(rb.getString(
2180                         "if.alias.not.specified.destalias.and.srckeypass.must.not.be.specified"));
2181             }
2182             doImportKeyStoreAll(srcKS);
2183         }
2184 
2185         if (inplaceImport) {
2186             // Backup to file.old or file.old2...
2187             // The keystore is not rewritten yet now.
2188             for (int n = 1; /* forever */; n++) {
2189                 inplaceBackupName = srcksfname + ".old" + (n == 1 ? "" : n);
2190                 File bkFile = new File(inplaceBackupName);
2191                 if (!bkFile.exists()) {
2192                     Files.copy(Path.get(srcksfname), bkFile.toPath());
2193                     break;
2194                 }
2195             }
2196 
2197         }
2198 
2199         /*
2200          * Information display rule of -importkeystore
2201          * 1. inside single, shows failure
2202          * 2. inside all, shows sucess
2203          * 3. inside all where there is a failure, prompt for continue
2204          * 4. at the final of all, shows summary
2205          */
2206     }
2207 
2208     /**
2209      * Import a single entry named alias from srckeystore
2210      * @return  1 if the import action succeed
2211      *          0 if user choose to ignore an alias-dumplicated entry
2212      *          2 if setEntry throws Exception


< prev index next >