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 java.io.File;
008: import java.io.IOException;
009: import java.net.UnknownHostException;
010:
011: public class SslConfiguration {
012: public SslConfiguration(SecurityContext securityContext) {
013: this .securityContext = securityContext;
014: passwordManager = new PasswordManager(securityContext
015: .getPropertyHelper());
016: }
017:
018: private SecurityContext securityContext;
019: private PasswordManager passwordManager;
020:
021: public void createKeyStore() throws SecurityException {
022: CertificateContext certificate;
023: try {
024: certificate = securityContext.getCertificateContext();
025: } catch (UnknownHostException uhe) {
026: throw new SecurityException(uhe);
027: }
028:
029: KeyStoreContext keyStore = securityContext.getKeyStoreContext();
030: keyStore.clean();
031:
032: try {
033: KeyToolWrapper.createCertificate(keyStore, certificate);
034: } catch (IOException ioe) {
035: throw new SecurityException(ioe);
036: }
037:
038: File file = new File(keyStore.getKeyStoreDirectory()
039: + File.separator + keyStore.getExportImportFileName());
040: if (file.exists()) {
041: file.delete();
042: }
043: try {
044: KeyToolWrapper.exportCertificate(keyStore, certificate,
045: keyStore.getKeyStoreDirectory() + File.separator
046: + keyStore.getExportImportFileName());
047: } catch (IOException ioe) {
048: throw new SecurityException(ioe);
049: }
050:
051: Password password = new Password(securityContext
052: .getPropertyHelper());
053: password.setPassword(keyStore.getKeyStorePassword());
054: passwordManager.write(password, keyStore.getKeyStoreDirectory()
055: + File.separator
056: + keyStore.getKeyStorePasswordFileName());
057: }
058:
059: public void deleteKeyStore() {
060: KeyStoreContext keyStore = securityContext.getKeyStoreContext();
061: keyStore.clean();
062:
063: File file = new File(keyStore.getKeyStoreDirectory()
064: + File.separator
065: + keyStore.getKeyStorePasswordFileName());
066: if (file.exists()) {
067: file.delete();
068: }
069:
070: file = new File(keyStore.getKeyStoreDirectory()
071: + File.separator + keyStore.getExportImportFileName());
072: if (file.exists()) {
073: file.delete();
074: }
075: }
076:
077: public void createTrustStore() throws SecurityException {
078: CertificateContext certificate;
079: try {
080: certificate = securityContext.getCertificateContext();
081: } catch (UnknownHostException uhe) {
082: throw new SecurityException(uhe);
083: }
084:
085: KeyStoreContext trustStore = securityContext
086: .getTrustStoreContext();
087: trustStore.clean();
088:
089: try {
090: KeyToolWrapper.importCertificate(trustStore, certificate,
091: trustStore.getKeyStoreDirectory() + File.separator
092: + trustStore.getExportImportFileName());
093: } catch (IOException ioe) {
094: throw new SecurityException(ioe);
095: }
096:
097: Password password = new Password(securityContext
098: .getPropertyHelper());
099: password.setPassword(trustStore.getKeyStorePassword());
100: passwordManager.write(password, trustStore
101: .getKeyStoreDirectory()
102: + File.separator
103: + trustStore.getKeyStorePasswordFileName());
104: }
105:
106: public void deleteTrustStore() {
107: KeyStoreContext trustStore = securityContext
108: .getTrustStoreContext();
109: trustStore.clean();
110:
111: File file = new File(trustStore.getKeyStoreDirectory()
112: + File.separator
113: + trustStore.getKeyStorePasswordFileName());
114: if (file.exists()) {
115: file.delete();
116: }
117: }
118: }
|