Ejemplo n.º 1
0
 /**
  * Zero argument constructor for generation a key pair There will be a public key and a private
  * key available
  *
  * @throws KOAException This exception will be thrown when there is a problem with generation a
  *     key pair
  */
 public KOAKeyPair() throws KOAException {
   try {
     KEYPAIR_KEY_LENGTH = TechnicalProps.getIntProperty(TechnicalProps.RSA_KEY_LENGTH);
     KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEYPAIR_GENERATOR_ALGORITHM);
     keyPairGen.initialize(KEYPAIR_KEY_LENGTH);
     keyPair = keyPairGen.generateKeyPair();
   } catch (NoSuchAlgorithmException nsae) {
     // KOALogHelper.logError ("KOAKeyPair", "Cannot generate key pair", nsae);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_GENERATE, nsae);
   }
 }
Ejemplo n.º 2
0
 /**
  * Constructor writes an open tag to the writer
  *
  * @param xWriter de xml data wil be writen to this writer
  */
 public KielijstExportWriter(Writer xWriter) throws KOAException {
   try {
     this.xWriter = xWriter;
     xWriter.write(
         "<?xml version=\"1.0\" encoding=\""
             + TechnicalProps.getProperty(TechnicalProps.KL_EXPORT_XML_ENCODING)
             + "\"?>\n");
     xWriter.write("<result action=\"replace\" contenttype=\"kieslijst\">\n");
   } catch (IOException ioe) {
     String[] params = {"writer"};
     KOALogHelper.logErrorCode("KielijstExportWriter", ErrorConstants.ERR_IO, params, ioe);
     throw new KOADataBeheerException(KOADataBeheerException.IO_EXCETION, ioe);
   }
 }
Ejemplo n.º 3
0
 /**
  * Constructor for decryption of a key. Only the public of private key of the <code>keyType</code>
  * will be available the other will return null
  *
  * @param password The password used for decryption
  * @param criptKey A stream with the encrypted key
  * @param keyType The type of the key public (<code>PUBLIC_KEY</code>) or private (<code>
  *     PRIVATE_KEY</code>)
  * @throws KOAException This exception will be thrown when there is a problem with decryption
  */
 public KOAKeyPair(String password, InputStream cryptKey, int keyType) throws KOAException {
   try {
     KEYPAIR_KEY_LENGTH = TechnicalProps.getIntProperty(TechnicalProps.RSA_KEY_LENGTH);
     PBEParameterSpec paramSpec = new PBEParameterSpec(SALT, 20);
     PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());
     SecretKeyFactory kf = SecretKeyFactory.getInstance(KEY_ENCRIPTION_AKGORITHM);
     SecretKey passwordKey = kf.generateSecret(keySpec);
     Cipher cipher = Cipher.getInstance(KEY_ENCRIPTION_AKGORITHM);
     cipher.init(Cipher.UNWRAP_MODE, passwordKey, paramSpec);
     byte[] dummy = new byte[128];
     int length;
     ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
     while ((length = cryptKey.read(dummy)) != -1) {
       byteArray.write(dummy, 0, length);
     }
     if (keyType == PRIVATE_KEY) {
       Key unwrappedKey =
           cipher.unwrap(byteArray.toByteArray(), KEYPAIR_GENERATOR_ALGORITHM, keyType);
       keyPair = new KeyPair(null, (PrivateKey) unwrappedKey);
     } else if (keyType == PUBLIC_KEY) {
       Key unwrappedKey =
           cipher.unwrap(byteArray.toByteArray(), KEYPAIR_GENERATOR_ALGORITHM, keyType);
       keyPair = new KeyPair((PublicKey) unwrappedKey, null);
     } else {
       throw new InvalidKeyException("criptKey does not represent a wrapped key of type keyType");
     }
   } catch (NoSuchAlgorithmException nsae) {
     KOALogHelper.logError("KOAKeyPair", "Cannot decrypt key pair", nsae);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_DECRYPT, nsae);
   } catch (NoSuchPaddingException nspe) {
     KOALogHelper.logError("KOAKeyPair", "Cannot decrypt key pair", nspe);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_DECRYPT, nspe);
   } catch (InvalidKeySpecException ikse) {
     KOALogHelper.logError("KOAKeyPair", "Cannot decrypt key pair", ikse);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_DECRYPT, ikse);
   } catch (InvalidKeyException ike) {
     KOALogHelper.logError("KOAKeyPair", "Cannot decrypt key pair", ike);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_DECRYPT, ike);
   } catch (InvalidAlgorithmParameterException iape) {
     KOALogHelper.logError("KOAKeyPair", "Cannot decrypt key pair", iape);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_DECRYPT, iape);
   } catch (IOException ioe) {
     KOALogHelper.logError("KOAKeyPair", "Cannot decrypt key pair", ioe);
     throw new KOAException(ErrorConstants.SECURITY_KEYPAIR_DECRYPT, ioe);
   }
 }
Ejemplo n.º 4
0
 /**
  * The execute method on the Suspend command. This method is executed in the ejb command target.
  *
  * @throws CommandException necessary to fullfill abstract method signature
  * @throws EPlatformException thrown when the remote instance of the Controller can not be
  *     created.
  */
 public void execute()
     throws ie.ucd.srg.logica.eplatform.command.CommandException, EPlatformException {
   LogHelper.log(LogHelper.INFO, "[SuspendCommand.exeute] execute ");
   boolean bBackupFailed = false;
   try {
     /* init the variabeles */
     Hashtable htProps = new Hashtable();
     htProps.put(
         Context.INITIAL_CONTEXT_FACTORY,
         JNDIProperties.getProperty(JNDIProperties.CONTROLLER_CONTEXT_FACTORY));
     htProps.put(
         Context.PROVIDER_URL, JNDIProperties.getProperty(JNDIProperties.CONTROLLER_PROVIDER));
     /* init the context */
     InitialContext icContext = new InitialContext(htProps);
     /* lookup the controller */
     Object obj = icContext.lookup(JNDIProperties.getProperty(JNDIProperties.CONTROLLER_NAME));
     /* create the controller */
     ControllerHome xControllerHome =
         (ControllerHome) PortableRemoteObject.narrow(obj, ControllerHome.class);
     Controller xController = xControllerHome.create();
     // Verify pincodes. If validated then continue with change of state
     g_crCallResult = xController.checkPinCode(sPincode1, sPincode2);
     if (g_crCallResult.getResult() == CallResult.RESULT_OK) {
       // change state to suspended
       g_crCallResult = xController.suspend();
       try {
         /* Call script to backup database to removable medium */
         String sBackupPath = TechnicalProps.getProperty(TechnicalProps.BACKUP_SCRIPT);
         LogHelper.log(LogHelper.INFO, "[SuspendCommand.exeute] Start creating backup...");
         if (sBackupPath != null) {
           Process xProcess = Runtime.getRuntime().exec(sBackupPath);
           int iProcessRes = xProcess.waitFor();
           if (iProcessRes != 0) {
             bBackupFailed = true;
             KOALogHelper.log(
                 KOALogHelper.ERROR,
                 "Error executing script for backup to fs (suspend state) code = " + iProcessRes);
           } else {
             bBackupFailed = false;
             String sMessage =
                 ie.ucd.srg.logica.eplatform.error.ErrorMessageFactory.getErrorMessageFactory()
                     .getErrorMessage(ErrorConstants.CREATE_BACKUP_OK, null);
             KOALogHelper.audit(
                 KOALogHelper.INFO,
                 AuditEventListener.STATE_CHANGE,
                 "SuspendElection",
                 g_sUser,
                 sMessage);
             // set callresult for backup
             g_crCallResult.setBackupResult(sMessage);
             LogHelper.log(LogHelper.INFO, "[SuspendCommand.exeute] backup created OK...");
           }
         }
       } catch (java.lang.InterruptedException xInterruptedExc) {
         bBackupFailed = true;
         KOALogHelper.logErrorCode(
             "SuspendCommand.execute",
             ErrorConstants.UNABLE_TO_START_BACKUP_SCRIPT,
             null,
             xInterruptedExc);
       } catch (java.io.IOException xioExc) {
         bBackupFailed = true;
         String[] params = {"backupscript"};
         KOALogHelper.logErrorCode(
             "SuspendCommand.execute", ErrorConstants.ERR_IO, params, xioExc);
       }
     }
   } catch (NamingException ne) {
     String[] params = {"Controller"};
     KOALogHelper.logErrorCode("SuspendCommand.execute", ErrorConstants.ERR_NAMING, params, ne);
     throw new KOAException(ErrorConstants.COMMAND_SUSPEND_EXEC, ne);
   } catch (RemoteException re) {
     String[] params = {"Controller"};
     KOALogHelper.logErrorCode("SuspendCommand.execute", ErrorConstants.ERR_REMOTE, params, re);
     throw new KOAException(ErrorConstants.COMMAND_SUSPEND_EXEC, re);
   } catch (CreateException ce) {
     String[] params = {"Controller"};
     KOALogHelper.logErrorCode("SuspendCommand.execute", ErrorConstants.ERR_CREATE, params, ce);
     throw new KOAException(ErrorConstants.COMMAND_SUSPEND_EXEC, ce);
   } catch (KOAException koae) {
     KOALogHelper.logError("SuspendCommand.execute", "KOAException", koae);
     throw koae;
   }
   // Always perform the following code, to check if the backup was successful
   finally {
     if (bBackupFailed) {
       try {
         String sMessage =
             ie.ucd.srg.logica.eplatform.error.ErrorMessageFactory.getErrorMessageFactory()
                 .getErrorMessage(ErrorConstants.CREATE_BACKUP_ERROR, null);
         KOALogHelper.audit(
             KOALogHelper.ERROR,
             AuditEventListener.STATE_CHANGE,
             "SuspendElection",
             g_sUser,
             sMessage);
         g_crCallResult.setBackupResult(sMessage);
         LogHelper.log(
             LogHelper.ERROR,
             "[SuspendCommand.exeute] Error occured with result that back up is not created...");
       } catch (java.io.IOException ioe) {
         String[] params = {"Error message factory"};
         KOALogHelper.logErrorCode("SuspendCommand.execute", ErrorConstants.ERR_IO, params, ioe);
       }
     }
   }
 }