FileDocCategorySizeDatePackage
CertificateTransfer.javaAPI DocGlassfish v2 API12302Mon May 28 05:42:00 BST 2007com.sun.enterprise.tools.upgrade.certconversion

CertificateTransfer

public class CertificateTransfer extends Object implements com.sun.enterprise.tools.upgrade.common.BaseModule
This class is for future use when the server supports the use of both NSS and JKS keystore types. The CertificateTransfer class copies the source certificate databases to the target server and configure the target to use the appropriate keystore type JKS/NSS
author
Hans Hrasna

Fields Summary
private com.sun.enterprise.util.i18n.StringManager
stringManager
private Logger
logger
private Vector
recoveryList
private com.sun.enterprise.tools.upgrade.common.UpgradeUtils
utils
private String
JAVA_HOME
private com.sun.enterprise.tools.upgrade.common.CommonInfoModel
cim
private String
targetJksPath
private String
sourceJksPath
private String
targetCaJksPath
private String
sourceCaJksPath
private String
targetNssPath
private String
sourceNssPath
private String
targetCaNssPath
private String
sourceCaNssPath
private static String
JKS_CERTS
private static String
CA_JKS_CERTS
private static String
NSS_CERTS
private static String
CA_NSS_CERTS
private static String
CA_70_CERTS
Constructors Summary
public CertificateTransfer()
Creates a new instance of CertificateTransfer

    
           
      
        JAVA_HOME = System.getProperty("com.sun.aas.java.home");
    
Methods Summary
private voidbackup(java.lang.String filePath)

        String backupFilePath = filePath + ".bak";
        utils.copyFile(filePath, backupFilePath);
        recoveryList.add(filePath);
    
private booleanbackupJksCerts()

        try {
            backup(targetJksPath);
            backup(targetCaJksPath);
        } catch (Exception e) {
            logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.certconversion.could_not_migrate_certificates",e));
            return false;
        }
        return true;
    
private booleanbackupNssCerts()

        try {
            backup(targetNssPath);
            backup(targetCaNssPath);
        } catch (Exception e) {
            //if there is an exception, don't do anything
            //logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.certconversion.could_not_migrate_certificates",e));
            //return false;
        }
        return true;
    
private voidconfigureJks()

        
        //set keystore.type=jks
        String securityFile = JAVA_HOME + File.separator + "lib" + File.separator + "security" + File.separator + "java.security";
        File security = getSecurityFile();
        if(!security.exists()){
            logger.warning(stringManager.getString("enterprise.tools.upgrade.certconversion.errorConfiguringJKS"));
            return;
        }
        
        //TODO 
        
    
private voidconfigureNss()

        File security = getSecurityFile();
        if(!security.exists()){
            logger.warning(stringManager.getString("enterprise.tools.upgrade.certconversion.errorConfiguringNSS"));
            return;
        }
        //TODO 
        
    
private booleancopyJksCerts()

        try {
            UpgradeUtils.copyFile(sourceJksPath, targetJksPath);
            UpgradeUtils.copyFile(sourceCaJksPath, targetCaJksPath);
        } catch (Exception e) {
            logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.certconversion.could_not_migrate_certificates",e));
            return false;
        }
        return true;
    
private booleancopyNssCerts()

        
        try {
            UpgradeUtils.copyFile(sourceNssPath, targetNssPath);
            UpgradeUtils.copyFile(sourceCaNssPath, targetCaNssPath);
        } catch (Exception e) {
            logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.certconversion.could_not_migrate_certificates",e));
            return false;
        }
        return true;
    
public java.lang.StringgetName()

        return stringManager.getString("enterprise.tools.upgrade.certconversion.moduleName");
    
private java.io.FilegetSecurityFile()

        String securityFile = JAVA_HOME + File.separator + "lib" + File.separator + "security" + File.separator + "java.security";
        return new File(securityFile);
    
private booleanjksToJks()

        backupJksCerts();
        return copyJksCerts();
    
private booleanjksToNss()

        configureJks();
        return copyJksCerts();
    
private booleannssToJks()

        configureNss();
        return copyNssCerts();
        
    
private booleannssToNss()

        backupNssCerts();
        return copyNssCerts();
    
public voidrecovery(com.sun.enterprise.tools.upgrade.common.CommonInfoModel commonInfo)

        Enumeration e = recoveryList.elements();
        while(e.hasMoreElements()){
            String recoverPath = (String)e.nextElement();
            String backupPath = recoverPath + ".bak";
            try {
                utils.copyFile(backupPath, recoverPath);
                new File(backupPath).delete();
            } catch (IOException ioe) {
                logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.certconversion.could_not_migrate_certificates",ioe.getMessage()),new Object[]{recoverPath,ioe});
            }
        }
    
public booleanupgrade(com.sun.enterprise.tools.upgrade.common.CommonInfoModel cmi)

        cim = cmi;
        logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.certconversion.start_certificate_migration",cmi.getCurrentDomain()));
        targetJksPath = cim.getTargetJKSKeyStorePath();
        sourceJksPath = cim.getSourceJKSKeyStorePath();
        targetCaJksPath = cim.getTargetTrustedJKSKeyStorePath();
        sourceCaJksPath = cim.getSourceTrustedJKSKeyStorePath();
        String sourceConfigPath = cim.getSourceDomainPath()+ File.separator + "config";
        String targetConfigPath = cim.getTargetConfig();
        targetNssPath = targetConfigPath + File.separator + NSS_CERTS;
        sourceNssPath = sourceConfigPath + File.separator + NSS_CERTS;
        targetCaNssPath = targetConfigPath + File.separator + CA_NSS_CERTS;
        if (cim.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS7X_PE)) {
            sourceCaNssPath = sourceConfigPath + File.separator + CA_70_CERTS;
        } else {
            sourceCaNssPath = sourceConfigPath + File.separator + CA_NSS_CERTS;
        }
        utils = UpgradeUtils.getUpgradeUtils(cim);
        //String tv = cim.getTargetVersionAndEdition();
        String sv = cim.getSourceEdition();//cim.getSourceVersionAndEdition();
        
        //8.0PE and 8.1PE have JKS certs
        if(sv.equals(UpgradeConstants.EDITION_PE)) {
       // if(sv.equals(UpgradeConstants.VERSION_AS80_PE) || sv.equals(UpgradeConstants.VERSION_AS81_PE)) {
            //PE source upgrade will always create a domain with developer profile.
            return jksToJks();
            /*if(tv.equals(UpgradeConstants.VERSION_AS90_PE)) {
                return jksToJks();
            }
            else if ( tv.equals(UpgradeConstants.VERSION_AS91_EE) ){
                return jksToNss();
            }*/
        }
        //7.0PE, 7.1SE, 7.1EE, 8.0EE and 8.1EE have NSS certs
        //7.x not supported.
        //if(sv.equals(UpgradeConstants.VERSION_AS81_EE)) {
        //EE source will always create a domain with enterprise profile
        if(sv.equals(UpgradeConstants.EDITION_EE)) {
            //Not a valid upgrade since EE source to a developer profile not supported.
            //Target will be an enterprise profile always.
	    return nssToNss();
            /*if(tv.equals(UpgradeConstants.VERSION_AS90_PE)) {
                return nssToJks();
            } else if ( tv.equals(UpgradeConstants.VERSION_AS91_EE) ){
                return nssToNss();
            }*/
        }
        return false;