001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.monitoring.security;
006:
007: import com.sun.portal.monitoring.utilities.ProcessHelper;
008:
009: import java.io.File;
010: import java.io.IOException;
011:
012: public class KeyToolWrapper {
013: public static void createCertificate(KeyStoreContext keyStore,
014: CertificateContext certificate) throws IOException {
015: String[] cmdArray = new String[] {
016: UTILITY,
017: SUBCOMMAND_PREFIX + SUBCOMMAND_GENKEY,
018: OPTION_PREFIX + OPTION_ALIAS,
019: certificate.getAlias(),
020: OPTION_PREFIX + OPTION_KEY_ALG,
021: certificate.getKeyAlg(),
022: OPTION_PREFIX + OPTION_DNAME,
023: certificate.getDn(),
024: OPTION_PREFIX + OPTION_KEY_PASS,
025: new String(keyStore.getKeyStorePassword()),
026: OPTION_PREFIX + OPTION_VALIDITY,
027: certificate.getValidity(),
028: OPTION_PREFIX + OPTION_KEY_STORE,
029: keyStore.getKeyStoreDirectory() + File.separator
030: + keyStore.getKeyStoreFileName(),
031: OPTION_PREFIX + OPTION_STORE_PASS,
032: new String(keyStore.getKeyStorePassword()) };
033:
034: ProcessHelper.exec(cmdArray, null);
035: }
036:
037: public static void exportCertificate(KeyStoreContext keyStore,
038: CertificateContext certificate, String exportFilePathName)
039: throws IOException {
040: String[] cmdArray = new String[] {
041: UTILITY,
042: SUBCOMMAND_PREFIX + SUBCOMMAND_EXPORT,
043: OPTION_PREFIX + OPTION_ALIAS,
044: certificate.getAlias(),
045: OPTION_PREFIX + OPTION_FILE,
046: exportFilePathName,
047: OPTION_PREFIX + OPTION_KEY_STORE,
048: keyStore.getKeyStoreDirectory() + File.separator
049: + keyStore.getKeyStoreFileName(),
050: OPTION_PREFIX + OPTION_STORE_PASS,
051: new String(keyStore.getKeyStorePassword()),
052: OPTION_PREFIX + OPTION_RFC };
053:
054: ProcessHelper.exec(cmdArray, null);
055: }
056:
057: public static void deleteCertificate(KeyStoreContext keyStore,
058: CertificateContext certificate) throws IOException {
059: String[] cmdArray = new String[] {
060: UTILITY,
061: SUBCOMMAND_PREFIX + SUBCOMMAND_DELETE,
062: OPTION_PREFIX + OPTION_ALIAS,
063: certificate.getAlias(),
064: OPTION_PREFIX + OPTION_KEY_STORE,
065: keyStore.getKeyStoreDirectory() + File.separator
066: + keyStore.getKeyStoreFileName(),
067: OPTION_PREFIX + OPTION_STORE_PASS,
068: new String(keyStore.getKeyStorePassword()) };
069:
070: ProcessHelper.exec(cmdArray, null);
071: }
072:
073: public static void importCertificate(KeyStoreContext keyStore,
074: CertificateContext certificate, String importFilePathName)
075: throws IOException {
076: String[] cmdArray = new String[] {
077: UTILITY,
078: SUBCOMMAND_PREFIX + SUBCOMMAND_IMPORT,
079: OPTION_PREFIX + OPTION_ALIAS,
080: certificate.getAlias(),
081: OPTION_PREFIX + OPTION_FILE,
082: importFilePathName,
083: OPTION_PREFIX + OPTION_NO_PROMPT,
084: OPTION_PREFIX + OPTION_TRUST_CA_CERTS,
085: OPTION_PREFIX + OPTION_KEY_STORE,
086: keyStore.getKeyStoreDirectory() + File.separator
087: + keyStore.getKeyStoreFileName(),
088: OPTION_PREFIX + OPTION_STORE_PASS,
089: new String(keyStore.getKeyStorePassword()) };
090:
091: ProcessHelper.exec(cmdArray, null);
092: }
093:
094: private static String UTILITY = System.getProperty("java.home")
095: + File.separator + "bin" + File.separator + "keytool";
096:
097: private static String SUBCOMMAND_PREFIX = "-";
098: private static String SUBCOMMAND_GENKEY = "genkey";
099: private static String SUBCOMMAND_EXPORT = "export";
100: private static String SUBCOMMAND_DELETE = "delete";
101: private static String SUBCOMMAND_IMPORT = "import";
102:
103: private static String OPTION_PREFIX = "-";
104: private static String OPTION_ALIAS = "alias";
105: private static String OPTION_KEY_ALG = "keyalg";
106: private static String OPTION_DNAME = "dname";
107: private static String OPTION_KEY_PASS = "keypass";
108: private static String OPTION_VALIDITY = "validity";
109: private static String OPTION_KEY_STORE = "keystore";
110: private static String OPTION_STORE_PASS = "storepass";
111: private static String OPTION_FILE = "file";
112: private static String OPTION_RFC = "rfc";
113: private static String OPTION_NO_PROMPT = "noprompt";
114: private static String OPTION_TRUST_CA_CERTS = "trustcacerts";
115: }
|