diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/selftests')
9 files changed, 2453 insertions, 0 deletions
diff --git a/pki/base/common/src/com/netscape/cms/selftests/ASelfTest.java b/pki/base/common/src/com/netscape/cms/selftests/ASelfTest.java new file mode 100644 index 000000000..d2b54c3b8 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/ASelfTest.java @@ -0,0 +1,194 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests; + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.selftests.*; +import java.util.*; + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements an individual self test. + * <P> + * + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public abstract class ASelfTest + implements ISelfTest { + //////////////////////// + // default parameters // + //////////////////////// + + + + ////////////////////////// + // ISelfTest parameters // + ////////////////////////// + + // parameter information + private static final String SELF_TEST_NAME = "ASelfTest"; + + // variables associated with this specific object + protected ISelfTestSubsystem mSelfTestSubsystem = null; + protected String mInstanceName = null; + protected IConfigStore mConfig = null; + protected String mPrefix = null; + + ///////////////////// + // default methods // + ///////////////////// + + + + /////////////////////// + // ISelfTest methods // + /////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest(ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException { + // store individual self test class values for this instance + mSelfTestSubsystem = (ISelfTestSubsystem) subsystem; + + // strip preceding/trailing whitespace + // from passed-in String parameters + if (instanceName != null) { + instanceName = instanceName.trim(); + } else { + mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_PARAMETER_WAS_NULL", + SELF_TEST_NAME)); + + throw new EMissingSelfTestException(); + } + + // store additional individual self test class values for this instance + mInstanceName = instanceName; + + // compose self test plugin parameter property prefix + String pluginPath = PROP_PLUGIN + "." + instanceName; + + mConfig = parameters.getSubStore(pluginPath); + + if ((mConfig != null) && + (mConfig.getName() != null) && + (mConfig.getName() != "")) { + mPrefix = mConfig.getName().trim(); + } else { + mSelfTestSubsystem.log(mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_PARAMETER_WAS_NULL", + SELF_TEST_NAME)); + + throw new EMissingSelfTestException(); + } + + return; + } + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public abstract void startupSelfTest() + throws ESelfTestException; + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public abstract void shutdownSelfTest(); + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() { + return mInstanceName; + } + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() { + return mConfig; + } + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public abstract String getSelfTestDescription(Locale locale); + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public abstract void runSelfTest(ILogEventListener logger) + throws ESelfTestException; +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/ca/CAPresence.java b/pki/base/common/src/com/netscape/cms/selftests/ca/CAPresence.java new file mode 100644 index 000000000..19fb71cff --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/ca/CAPresence.java @@ -0,0 +1,279 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.ca; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.ca.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.cert.*; +import java.util.*; +import netscape.security.x509.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check for CA presence. + * <P> + * + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public class CAPresence +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + /////////////////////////// + // CAPresence parameters // + /////////////////////////// + + // parameter information + public static final String PROP_CA_SUB_ID = "CaSubId"; + private String mCaSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + //////////////////////// + // CAPresence methods // + //////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mCaSubId = mConfig.getString( PROP_CA_SUB_ID ); + if( mCaSubId != null ) { + mCaSubId = mCaSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_CA_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_CA_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_CA_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_CA_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_CA_PRESENCE_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + ICertificateAuthority ca = null; + X509CertImpl caCert = null; + X509Key caPubKey = null; + + ca = ( ICertificateAuthority ) CMS.getSubsystem( mCaSubId ); + + if( ca == null ) { + // log that the CA is not installed + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_NOT_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } else { + // Retrieve the CA certificate + caCert = ca.getCACert(); + + if( caCert == null ) { + // log that the CA is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_CA_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the CA certificate public key + try { + caPubKey = ( X509Key ) caCert.get( X509CertImpl.PUBLIC_KEY ); + + if( caPubKey == null ) { + // log that something is seriously wrong with the CA + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_CORRUPT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + } catch( CertificateParsingException e ) { + // log that something is seriously wrong with the CA + mSelfTestSubsystem.log( logger, + e.toString() ); + + throw new ESelfTestException( e.toString() ); + } + + // log that the CA is present + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/ca/CAValidity.java b/pki/base/common/src/com/netscape/cms/selftests/ca/CAValidity.java new file mode 100644 index 000000000..ec8651059 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/ca/CAValidity.java @@ -0,0 +1,279 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.ca; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.ca.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.cert.*; +import java.util.*; +import netscape.security.x509.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check the validity of the CA. + * <P> + * + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public class CAValidity +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + /////////////////////////// + // CAValidity parameters // + /////////////////////////// + + // parameter information + public static final String PROP_CA_SUB_ID = "CaSubId"; + private String mCaSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + //////////////////////// + // CAValidity methods // + //////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mCaSubId = mConfig.getString( PROP_CA_SUB_ID ); + if( mCaSubId != null ) { + mCaSubId = mCaSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_CA_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_CA_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_CA_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_CA_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_CA_VALIDITY_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + ICertificateAuthority ca = null; + X509CertImpl caCert = null; + + ca = ( ICertificateAuthority ) CMS.getSubsystem( mCaSubId ); + + if( ca == null ) { + // log that the CA is not installed + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_NOT_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } else { + // Retrieve the CA certificate + caCert = ca.getCACert(); + + if( caCert == null ) { + // log that the CA is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_CA_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the CA validity period + try { + caCert.checkValidity(); + } catch( CertificateNotYetValidException e ) { + // log that the CA is not yet valid + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_NOT_YET_VALID", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } catch( CertificateExpiredException e ) { + // log that the CA is expired + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_EXPIRED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // log that the CA is valid + logMessage = CMS.getLogMessage( "SELFTESTS_CA_IS_VALID", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/common/SystemCertsVerification.java b/pki/base/common/src/com/netscape/cms/selftests/common/SystemCertsVerification.java new file mode 100644 index 000000000..5338cfff8 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/common/SystemCertsVerification.java @@ -0,0 +1,235 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2010 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.common; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.ca.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.cert.*; +import java.util.*; +import netscape.security.x509.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check the system certs + * of the subsystem + * <P> + * + * @version $Revision: $, $Date: $ + */ +public class SystemCertsVerification +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + /////////////////////////// + // SystemCertsVerification parameters // + /////////////////////////// + + // parameter information + public static final String PROP_SUB_ID = "SubId"; + private String mSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + //////////////////////// + // SystemCertsVerification methods // + //////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mSubId = mConfig.getString( PROP_SUB_ID ); + if( mSubId != null ) { + mSubId = mSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_SYSTEM_CERTS_VERIFICATION_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + boolean rc = false; + + rc = CMS.verifySystemCerts(); + if (rc == true) { + logMessage = CMS.getLogMessage( "SELFTESTS_COMMON_SYSTEM_CERTS_VERIFICATION_SUCCESS", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } else { + logMessage = CMS.getLogMessage( "SELFTESTS_COMMON_SYSTEM_CERTS_VERIFICATION_FAILURE", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + throw new ESelfTestException( logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/kra/KRAPresence.java b/pki/base/common/src/com/netscape/cms/selftests/kra/KRAPresence.java new file mode 100644 index 000000000..2cf481dde --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/kra/KRAPresence.java @@ -0,0 +1,270 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.kra; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.kra.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.*; +import java.util.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check for KRA presence. + * <P> + * + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public class KRAPresence +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + /////////////////////////// + // KRAPresence parameters // + /////////////////////////// + + // parameter information + public static final String PROP_KRA_SUB_ID = "SubId"; + private String mSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + //////////////////////// + // KRAPresence methods // + //////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mSubId = mConfig.getString( PROP_KRA_SUB_ID ); + if( mSubId != null ) { + mSubId = mSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_KRA_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_KRA_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_KRA_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_KRA_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_KRA_PRESENCE_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + IKeyRecoveryAuthority kra = null; + org.mozilla.jss.crypto.X509Certificate kraCert = null; + PublicKey kraPubKey = null; + + kra = ( IKeyRecoveryAuthority ) CMS.getSubsystem( mSubId ); + + if( kra == null ) { + // log that the KRA is not installed + logMessage = CMS.getLogMessage( "SELFTESTS_KRA_IS_NOT_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } else { + // Retrieve the KRA certificate + kraCert = kra.getTransportCert(); + + if( kraCert == null ) { + // log that the RA is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_KRA_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the KRA certificate public key + kraPubKey = ( PublicKey ) kraCert.getPublicKey(); + + if( kraPubKey == null ) { + // log that something is seriously wrong with the KRA + logMessage = CMS.getLogMessage( "SELFTESTS_KRA_IS_CORRUPT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // log that the KRA is present + logMessage = CMS.getLogMessage( "SELFTESTS_KRA_IS_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/ocsp/OCSPPresence.java b/pki/base/common/src/com/netscape/cms/selftests/ocsp/OCSPPresence.java new file mode 100644 index 000000000..a05294a8e --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/ocsp/OCSPPresence.java @@ -0,0 +1,297 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.ocsp; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.ocsp.*; +import com.netscape.certsrv.security.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.cert.*; +import java.util.*; +import netscape.security.x509.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check for OCSP presence. + * <P> + * + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public class OCSPPresence +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + ///////////////////////////// + // OCSPPresence parameters // + ///////////////////////////// + + // parameter information + public static final String PROP_OCSP_SUB_ID = "OcspSubId"; + private String mOcspSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + ////////////////////////// + // OCSPPresence methods // + ////////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mOcspSubId = mConfig.getString( PROP_OCSP_SUB_ID ); + if( mOcspSubId != null ) { + mOcspSubId = mOcspSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_OCSP_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_OCSP_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_OCSP_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_OCSP_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_OCSP_PRESENCE_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + IOCSPAuthority ocsp = null; + ISigningUnit ocspSigningUnit = null; + X509CertImpl ocspCert = null; + X509Key ocspPubKey = null; + + ocsp = ( IOCSPAuthority ) CMS.getSubsystem( mOcspSubId ); + + if( ocsp == null ) { + // log that the OCSP is not installed + logMessage = CMS.getLogMessage( "SELFTESTS_OCSP_IS_NOT_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } else { + // Retrieve the OCSP signing unit + ocspSigningUnit = ocsp.getSigningUnit(); + + if( ocspSigningUnit == null ) { + // log that the OCSP is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_OCSP_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the OCSP certificate + ocspCert = ocspSigningUnit.getCertImpl(); + + if( ocspCert == null ) { + // log that the OCSP is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_OCSP_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the OCSP certificate public key + try { + ocspPubKey = ( X509Key ) + ocspCert.get( X509CertImpl.PUBLIC_KEY ); + + if( ocspPubKey == null ) { + // log that something is seriously wrong with the OCSP + logMessage = CMS.getLogMessage( "SELFTESTS_OCSP_IS_CORRUPT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + } catch( CertificateParsingException e ) { + // log that something is seriously wrong with the OCSP + mSelfTestSubsystem.log( logger, + e.toString() ); + + throw new ESelfTestException( e.toString() ); + } + + // log that the OCSP is present + logMessage = CMS.getLogMessage( "SELFTESTS_OCSP_IS_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/ocsp/OCSPValidity.java b/pki/base/common/src/com/netscape/cms/selftests/ocsp/OCSPValidity.java new file mode 100644 index 000000000..2bfe9ffd9 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/ocsp/OCSPValidity.java @@ -0,0 +1,297 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.ocsp; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.ocsp.*; +import com.netscape.certsrv.security.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.cert.*; +import java.util.*; +import netscape.security.x509.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check the validity of the OCSP. + * <P> + * + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public class OCSPValidity +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + ///////////////////////////// + // OCSPValidity parameters // + ///////////////////////////// + + // parameter information + public static final String PROP_OCSP_SUB_ID = "OcspSubId"; + private String mOcspSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + ////////////////////////// + // OCSPValidity methods // + ////////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mOcspSubId = mConfig.getString( PROP_OCSP_SUB_ID ); + if( mOcspSubId != null ) { + mOcspSubId = mOcspSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_OCSP_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_OCSP_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_OCSP_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_OCSP_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_OCSP_VALIDITY_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + IOCSPAuthority ocsp = null; + ISigningUnit ocspSigningUnit = null; + X509CertImpl ocspCert = null; + + ocsp = ( IOCSPAuthority ) CMS.getSubsystem( mOcspSubId ); + + if( ocsp == null ) { + // log that the OCSP is not installed + logMessage = CMS.getLogMessage( "SELFTESTS_OCSP_IS_NOT_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } else { + // Retrieve the OCSP signing unit + ocspSigningUnit = ocsp.getSigningUnit(); + + if( ocspSigningUnit == null ) { + // log that the OCSP is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_OCSP_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the OCSP certificate + ocspCert = ocspSigningUnit.getCertImpl(); + + if( ocspCert == null ) { + // log that the OCSP is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_OCSP_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the OCSP validity period + try { + ocspCert.checkValidity(); + } catch( CertificateNotYetValidException e ) { + // log that the OCSP is not yet valid + logMessage = CMS.getLogMessage( + "SELFTESTS_OCSP_IS_NOT_YET_VALID", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } catch( CertificateExpiredException e ) { + // log that the OCSP is expired + logMessage = CMS.getLogMessage( "SELFTESTS_OCSP_IS_EXPIRED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // log that the OCSP is valid + logMessage = CMS.getLogMessage( "SELFTESTS_OCSP_IS_VALID", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/ra/RAPresence.java b/pki/base/common/src/com/netscape/cms/selftests/ra/RAPresence.java new file mode 100644 index 000000000..f87c07128 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/ra/RAPresence.java @@ -0,0 +1,279 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.ra; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.ra.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.security.*; +import java.util.*; + + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check for RA presence. + * <P> + * <PRE> + * NOTE: This self-test is for Registration Authorities prior to + * Netscape Certificate Management System 7.0. It does NOT + * apply to the Registration Authority found in + * Red Hat Certificate System 7.3 or later (including + * ALL versions of Dogtag Certificate System). + * </PRE> + * <P> + * + * @deprecated + * @author mharmsen + * @author thomask + * @version $Revision$, $Date$ + */ +public class RAPresence +extends ASelfTest +{ + //////////////////////// + // default parameters // + //////////////////////// + + + + /////////////////////////// + // RAPresence parameters // + /////////////////////////// + + // parameter information + public static final String PROP_RA_SUB_ID = "RaSubId"; + private String mRaSubId = null; + + + + ///////////////////// + // default methods // + ///////////////////// + + + + //////////////////////// + // RAPresence methods // + //////////////////////// + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest( ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters ) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + super.initSelfTest( subsystem, instanceName, parameters ); + + // retrieve mandatory parameter(s) + try { + mRaSubId = mConfig.getString( PROP_RA_SUB_ID ); + if( mRaSubId != null ) { + mRaSubId = mRaSubId.trim(); + } else { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_VALUES", + getSelfTestName(), + mPrefix + + "." + + PROP_RA_SUB_ID ) ); + + throw new EMissingSelfTestException( PROP_RA_SUB_ID ); + } + } catch( EBaseException e ) { + mSelfTestSubsystem.log( mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage( + "SELFTESTS_MISSING_NAME", + getSelfTestName(), + mPrefix + + "." + + PROP_RA_SUB_ID ) ); + + throw new EMissingSelfTestException( mPrefix, + PROP_RA_SUB_ID, + null ); + } + + // retrieve optional parameter(s) + + return; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage( locale, + "CMS_SELFTESTS_RA_PRESENCE_DESCRIPTION" ); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest( ILogEventListener logger ) + throws ESelfTestException + { + String logMessage = null; + IRegistrationAuthority ra = null; + org.mozilla.jss.crypto.X509Certificate raCert = null; + PublicKey raPubKey = null; + + ra = ( IRegistrationAuthority ) CMS.getSubsystem( mRaSubId ); + + if( ra == null ) { + // log that the RA is not installed + logMessage = CMS.getLogMessage( "SELFTESTS_RA_IS_NOT_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } else { + // Retrieve the RA certificate + raCert = ra.getRACert(); + + if( raCert == null ) { + // log that the RA is not yet initialized + logMessage = CMS.getLogMessage( + "SELFTESTS_RA_IS_NOT_INITIALIZED", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // Retrieve the RA certificate public key + raPubKey = ( PublicKey ) raCert.getPublicKey(); + + if( raPubKey == null ) { + // log that something is seriously wrong with the RA + logMessage = CMS.getLogMessage( "SELFTESTS_RA_IS_CORRUPT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + + throw new ESelfTestException( logMessage ); + } + + // log that the RA is present + logMessage = CMS.getLogMessage( "SELFTESTS_RA_IS_PRESENT", + getSelfTestName() ); + + mSelfTestSubsystem.log( logger, + logMessage ); + } + + return; + } +} + diff --git a/pki/base/common/src/com/netscape/cms/selftests/tks/TKSKnownSessionKey.java b/pki/base/common/src/com/netscape/cms/selftests/tks/TKSKnownSessionKey.java new file mode 100644 index 000000000..05337bd96 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/selftests/tks/TKSKnownSessionKey.java @@ -0,0 +1,323 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +// package statement // +/////////////////////// + +package com.netscape.cms.selftests.tks; + + + +/////////////////////// +// import statements // +/////////////////////// + +import com.netscape.certsrv.apps.*; +import com.netscape.certsrv.base.*; +import com.netscape.certsrv.tks.*; +import com.netscape.certsrv.logging.*; +import com.netscape.certsrv.selftests.*; +import com.netscape.cms.selftests.*; +import java.util.*; +import com.netscape.symkey.*; + + +////////////////////// +// class definition // +////////////////////// + +/** + * This class implements a self test to check for TKS known session key. + * <P> + * + * @author mharmsen + * @author thomask + * @author awnuk + * @version $Revision$, $Date$ + */ +public class TKSKnownSessionKey +extends ASelfTest +{ + // parameter information + public static final String PROP_TKS_SUB_ID = "TksSubId"; + private String mTksSubId = null; + private String mToken = null; + private String mUseSoftToken = null; + private String mKeyName = null; + private byte[] mKeyInfo = null; + private byte[] mCardChallenge = null; + private byte[] mHostChallenge = null; + private byte[] mCUID = null; + private byte[] mMacKey = null; + private byte[] mSessionKey = null; + + + /** + * Initializes this subsystem with the configuration store + * associated with this instance name. + * <P> + * + * @param subsystem the associated subsystem + * @param instanceName the name of this self test instance + * @param parameters configuration store (self test parameters) + * @exception EDuplicateSelfTestException subsystem has duplicate name/value + * @exception EInvalidSelfTestException subsystem has invalid name/value + * @exception EMissingSelfTestException subsystem has missing name/value + */ + public void initSelfTest (ISelfTestSubsystem subsystem, + String instanceName, + IConfigStore parameters) + throws EDuplicateSelfTestException, + EInvalidSelfTestException, + EMissingSelfTestException + { + ISubsystem tks = null; + IConfigStore tksConfig = null; + String logMessage = null; + + super.initSelfTest( subsystem, instanceName, parameters ); + + mTksSubId = getConfigString(PROP_TKS_SUB_ID); + mToken = getConfigString("token"); + mKeyName = getConfigString("keyName"); + mCardChallenge = getConfigByteArray("cardChallenge", 8); + mHostChallenge = getConfigByteArray("hostChallenge", 8); + mKeyInfo = getConfigByteArray("keyName", 2); + mCUID = getConfigByteArray("CUID", 10); + mMacKey = getConfigByteArray("macKey", 16); + mUseSoftToken = getConfigString("useSoftToken"); + + String defKeySetMacKey = null; + tks = (ISubsystem) CMS.getSubsystem(mTksSubId); + if (tks != null) { + tksConfig = tks.getConfigStore(); + if (tksConfig != null) { + try { + defKeySetMacKey = tksConfig.getString("defKeySet.mac_key"); + byte defMacKey[] = com.netscape.cmsutil.util.Utils.SpecialDecode(defKeySetMacKey); + if (!Arrays.equals(mMacKey, defMacKey)) { + defKeySetMacKey = null; + } + } catch (EBaseException e) { + defKeySetMacKey = null; + } + } + } + if (defKeySetMacKey == null) { + CMS.debug("TKSKnownSessionKey: invalid mac key"); + CMS.debug("TKSKnownSessionKey self test FAILED"); + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_INVALID_VALUES", + getSelfTestName(), mPrefix + "." + "macKey")); + throw new EInvalidSelfTestException (mPrefix, "macKey", null); + } + + try { + mSessionKey = getConfigByteArray("sessionKey", 16); + } catch (EMissingSelfTestException e) { + if (mSessionKey == null) { + mSessionKey = SessionKey.ComputeSessionKey (mToken, mKeyName, + mCardChallenge, mHostChallenge, + mKeyInfo, mCUID, mMacKey, mUseSoftToken); + if (mSessionKey == null || mSessionKey.length != 16) { + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_VALUES", + getSelfTestName(), mPrefix + ".sessionKey")); + throw new EMissingSelfTestException ("sessionKey"); + } + String sessionKey = SpecialEncode(mSessionKey); + mConfig.putString("sessionKey", sessionKey); + try { + CMS.getConfigStore().commit(true); + } catch (EBaseException be) { + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_VALUES", + getSelfTestName(), mPrefix + ".sessionKey")); + throw new EMissingSelfTestException ("sessionKey"); + } + } + } + + return; + } + + + private String SpecialEncode (byte data[]) + { + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < data.length; i++) { + sb.append("#"); + if ((data[i] & 0xff) < 16) { + sb.append("0"); + } + sb.append(Integer.toHexString((data[i] & 0xff))); + } + + return sb.toString(); + } + + + private String getConfigString (String name) throws EMissingSelfTestException + { + String value = null; + + try { + value = mConfig.getString(name); + if (value != null) { + value = value.trim(); + } else { + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_VALUES", + getSelfTestName(), mPrefix + "." + name)); + throw new EMissingSelfTestException (name); + } + } catch (EBaseException e) { + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_NAME", + getSelfTestName(), mPrefix + "." + name)); + throw new EMissingSelfTestException (mPrefix, name, null); + } + + return value; + } + + + private byte[] getConfigByteArray (String name, int size) throws EMissingSelfTestException, + EInvalidSelfTestException + { + String stringValue = getConfigString(name); + + byte byteValue[] = com.netscape.cmsutil.util.Utils.SpecialDecode(stringValue); + if (byteValue == null) { + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_MISSING_NAME", + getSelfTestName(), mPrefix + "." + name)); + throw new EMissingSelfTestException (name); + } + if (byteValue.length != size) { + mSelfTestSubsystem.log (mSelfTestSubsystem.getSelfTestLogger(), + CMS.getLogMessage("SELFTESTS_INVALID_VALUES", + getSelfTestName(), mPrefix + "." + name)); + throw new EInvalidSelfTestException (mPrefix, name, stringValue); + } + + return byteValue; + } + + + /** + * Notifies this subsystem if it is in execution mode. + * <P> + * + * @exception ESelfTestException failed to start + */ + public void startupSelfTest() + throws ESelfTestException + { + return; + } + + + /** + * Stops this subsystem. The subsystem may call shutdownSelfTest + * anytime after initialization. + * <P> + */ + public void shutdownSelfTest() + { + return; + } + + + /** + * Returns the name associated with this self test. This method may + * return null if the self test has not been intialized. + * <P> + * + * @return instanceName of this self test + */ + public String getSelfTestName() + { + return super.getSelfTestName(); + } + + + /** + * Returns the root configuration storage (self test parameters) + * associated with this subsystem. + * <P> + * + * @return configuration store (self test parameters) of this subsystem + */ + public IConfigStore getSelfTestConfigStore() + { + return super.getSelfTestConfigStore(); + } + + + /** + * Retrieves description associated with an individual self test. + * This method may return null. + * <P> + * + * @param locale locale of the client that requests the description + * @return description of self test + */ + public String getSelfTestDescription( Locale locale ) + { + return CMS.getUserMessage (locale, "CMS_SELFTESTS_TKS_PRESENCE_DESCRIPTION"); + } + + + /** + * Execute an individual self test. + * <P> + * + * @param logger specifies logging subsystem + * @exception ESelfTestException self test exception + */ + public void runSelfTest (ILogEventListener logger) + throws ESelfTestException + { + String logMessage = null; + + byte[] sessionKey = SessionKey.ComputeSessionKey (mToken, mKeyName, + mCardChallenge, mHostChallenge, + mKeyInfo, mCUID, mMacKey, mUseSoftToken); + if (sessionKey == null) { + CMS.debug("TKSKnownSessionKey: generated no session key"); + CMS.debug("TKSKnownSessionKey self test FAILED"); + logMessage = CMS.getLogMessage ("SELFTESTS_TKS_FAILED", getSelfTestName(), getSelfTestName()); + mSelfTestSubsystem.log (logger, logMessage); + throw new ESelfTestException( logMessage ); + } else if (!Arrays.equals(mSessionKey, sessionKey)) { + CMS.debug("TKSKnownSessionKey: generated invalid session key"); + CMS.debug("TKSKnownSessionKey self test FAILED"); + logMessage = CMS.getLogMessage ("SELFTESTS_TKS_FAILED", getSelfTestName(), getSelfTestName()); + mSelfTestSubsystem.log (logger, logMessage); + throw new ESelfTestException( logMessage ); + } else { + logMessage = CMS.getLogMessage ("SELFTESTS_TKS_SUCCEEDED", getSelfTestName(), getSelfTestName()); + mSelfTestSubsystem.log (logger, logMessage); + CMS.debug("TKSKnownSessionKey self test SUCCEEDED"); + } + + return; + } +} + |