[Bedework-commit] calendarapi r1393 - in trunk: calFacade/src/org/bedework/calfacade/security calsvc/src/org/bedework/calsvc

svnadmin at bedework.org svnadmin at bedework.org
Tue Oct 26 15:30:51 EDT 2010


Author: douglm
Date: 2010-10-26 15:30:50 -0400 (Tue, 26 Oct 2010)
New Revision: 1393

Removed:
   trunk/calFacade/src/org/bedework/calfacade/security/DefaultPwEncryptionConfig.java
   trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionDefault.java
   trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionIntf.java
Modified:
   trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
   trunk/calsvc/src/org/bedework/calsvc/Calendars.java
Log:
Move en/decryption classes into rpiutil. 

Change configs to match

Deleted: trunk/calFacade/src/org/bedework/calfacade/security/DefaultPwEncryptionConfig.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/security/DefaultPwEncryptionConfig.java	2010-10-04 21:37:06 UTC (rev 1392)
+++ trunk/calFacade/src/org/bedework/calfacade/security/DefaultPwEncryptionConfig.java	2010-10-26 19:30:50 UTC (rev 1393)
@@ -1,102 +0,0 @@
-/* **********************************************************************
-    Copyright 2006 Rensselaer Polytechnic Institute. All worldwide rights reserved.
-
-    Redistribution and use of this distribution in source and binary forms,
-    with or without modification, are permitted provided that:
-       The above copyright notice and this permission notice appear in all
-        copies and supporting documentation;
-
-        The name, identifiers, and trademarks of Rensselaer Polytechnic
-        Institute are not used in advertising or publicity without the
-        express prior written permission of Rensselaer Polytechnic Institute;
-
-    DISCLAIMER: The software is distributed" AS IS" without any express or
-    implied warranty, including but not limited to, any implied warranties
-    of merchantability or fitness for a particular purpose or any warrant)'
-    of non-infringement of any current or pending patent rights. The authors
-    of the software make no representations about the suitability of this
-    software for any particular purpose. The entire risk as to the quality
-    and performance of the software is with the user. Should the software
-    prove defective, the user assumes the cost of all necessary servicing,
-    repair or correction. In particular, neither Rensselaer Polytechnic
-    Institute, nor the authors of the software are liable for any indirect,
-    special, consequential, or incidental damages related to the software,
-    to the maximum extent the law permits.
-*/
-
-package org.bedework.calfacade.security;
-
-import java.io.Serializable;
-
-/**
- * @author Mike Douglass
- */
-public class DefaultPwEncryptionConfig implements Serializable {
-  private String privKeys;
-
-  private String pubKeys;
-
-  private boolean debug;
-
-  private boolean verbose;
-
-  /** File for private keys
-   *
-   * @param val
-   */
-  public void setPrivKeys(String val)  {
-    privKeys  = val;
-  }
-
-  /**
-   * @return String
-   */
-  public String getPrivKeys()  {
-    return privKeys;
-  }
-
-  /** File for public keys
-   *
-   * @param val
-   */
-  public void setPubKeys(String val)  {
-    pubKeys  = val;
-  }
-
-  /**
-   * @return String
-   */
-  public String getPubKeys()  {
-    return pubKeys;
-  }
-
-  /** Set debugging
-   *
-   * @param val
-   */
-  public void setDebug(boolean val)  {
-    debug = val;
-  }
-
-  /**
-   * @return boolean
-   */
-  public boolean getDebug()  {
-    return debug;
-  }
-
-  /** Set debugging verbose
-   *
-   * @param val
-   */
-  public void setVerbose(boolean val)  {
-    verbose = val;
-  }
-
-  /**
-   * @return boolean
-   */
-  public boolean getVerbose()  {
-    return verbose;
-  }
-}

Deleted: trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionDefault.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionDefault.java	2010-10-04 21:37:06 UTC (rev 1392)
+++ trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionDefault.java	2010-10-26 19:30:50 UTC (rev 1393)
@@ -1,135 +0,0 @@
-/* **********************************************************************
-    Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
-
-    Redistribution and use of this distribution in source and binary forms,
-    with or without modification, are permitted provided that:
-       The above copyright notice and this permission notice appear in all
-        copies and supporting documentation;
-
-        The name, identifiers, and trademarks of Rensselaer Polytechnic
-        Institute are not used in advertising or publicity without the
-        express prior written permission of Rensselaer Polytechnic Institute;
-
-    DISCLAIMER: The software is distributed" AS IS" without any express or
-    implied warranty, including but not limited to, any implied warranties
-    of merchantability or fitness for a particular purpose or any warrant)'
-    of non-infringement of any current or pending patent rights. The authors
-    of the software make no representations about the suitability of this
-    software for any particular purpose. The entire risk as to the quality
-    and performance of the software is with the user. Should the software
-    prove defective, the user assumes the cost of all necessary servicing,
-    repair or correction. In particular, neither Rensselaer Polytechnic
-    Institute, nor the authors of the software are liable for any indirect,
-    special, consequential, or incidental damages related to the software,
-    to the maximum extent the law permits.
-*/
-package org.bedework.calfacade.security;
-
-import org.bedework.calfacade.env.CalOptionsFactory;
-import org.bedework.calfacade.exc.CalFacadeException;
-
-import edu.rpi.cmt.security.pki.PKITools;
-
-import org.apache.log4j.Logger;
-
-/**
- * @author Mike Douglass
- */
-public class PwEncryptionDefault implements PwEncryptionIntf {
-  private DefaultPwEncryptionConfig config;
-
-  static final String configOptionsName = "module.default-pwencrypt";
-
-  private PKITools pki;
-
-  private transient Logger log;
-
-  /**
-   * @throws CalFacadeException
-   */
-  public PwEncryptionDefault() throws CalFacadeException {
-    pki = new PKITools(getConfig().getVerbose(), getConfig().getDebug());
-
-  }
-
-  public String encrypt(String val) throws CalFacadeException {
-    try {
-      int numKeys = pki.countKeys(getConfig().getPrivKeys());
-
-      if (getConfig().getDebug()) {
-        debugMsg("Number of keys: " + numKeys);
-      }
-
-      int keyNum = numKeys - 1;
-
-      String etext = pki.encryptWithKeyFile(getConfig().getPubKeys(),
-                                            val, keyNum);
-
-      StringBuilder sb = new StringBuilder();
-
-      sb.append(keyNum);
-      sb.append("{");
-      sb.append(etext);
-      sb.append("}");
-
-      return sb.toString();
-    } catch (CalFacadeException cfe) {
-      throw cfe;
-    } catch (Throwable t) {
-      throw new CalFacadeException(t);
-    }
-  }
-
-  /* (non-Javadoc)
-   * @see org.bedework.calfacade.security.PwEncryptionIntf#match(java.lang.String, java.lang.String)
-   */
-  public boolean match(String plain,
-                       String encrypted) throws CalFacadeException {
-    return encrypt(plain).equals(encrypted);
-  }
-
-  public String decrypt(String encrypted) throws CalFacadeException {
-    try {
-      int pos = encrypted.indexOf("{");
-
-      if ((pos < 0) || (encrypted.lastIndexOf("}") != encrypted.length() - 1)) {
-        throw new CalFacadeException(CalFacadeException.badPwFormat);
-      }
-
-      int keyNum = Integer.valueOf(encrypted.substring(0, pos));
-      return pki.decryptWithKeyFile(getConfig().getPrivKeys(),
-                                    encrypted.substring(pos + 1, encrypted.length() - 1),
-                                    keyNum);
-    } catch (NumberFormatException nfe) {
-      throw new CalFacadeException(CalFacadeException.badPwFormat);
-    } catch (CalFacadeException cfe) {
-      throw cfe;
-    } catch (Throwable t) {
-      throw new CalFacadeException(t);
-    }
-  }
-
-  private DefaultPwEncryptionConfig getConfig() throws CalFacadeException {
-    if (config == null) {
-      try {
-        config = (DefaultPwEncryptionConfig)CalOptionsFactory.getOptions(false).
-                getGlobalProperty(configOptionsName);
-      } catch (Throwable t) {
-        throw new CalFacadeException(t);
-      }
-    }
-    return config;
-  }
-
-  private Logger getLog() {
-    if (log == null) {
-      log = Logger.getLogger(this.getClass());
-    }
-
-    return log;
-  }
-
-  private void debugMsg(String msg) {
-    getLog().debug(msg);
-  }
-}

Deleted: trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionIntf.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionIntf.java	2010-10-04 21:37:06 UTC (rev 1392)
+++ trunk/calFacade/src/org/bedework/calfacade/security/PwEncryptionIntf.java	2010-10-26 19:30:50 UTC (rev 1393)
@@ -1,63 +0,0 @@
-/* **********************************************************************
-    Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
-
-    Redistribution and use of this distribution in source and binary forms,
-    with or without modification, are permitted provided that:
-       The above copyright notice and this permission notice appear in all
-        copies and supporting documentation;
-
-        The name, identifiers, and trademarks of Rensselaer Polytechnic
-        Institute are not used in advertising or publicity without the
-        express prior written permission of Rensselaer Polytechnic Institute;
-
-    DISCLAIMER: The software is distributed" AS IS" without any express or
-    implied warranty, including but not limited to, any implied warranties
-    of merchantability or fitness for a particular purpose or any warrant)'
-    of non-infringement of any current or pending patent rights. The authors
-    of the software make no representations about the suitability of this
-    software for any particular purpose. The entire risk as to the quality
-    and performance of the software is with the user. Should the software
-    prove defective, the user assumes the cost of all necessary servicing,
-    repair or correction. In particular, neither Rensselaer Polytechnic
-    Institute, nor the authors of the software are liable for any indirect,
-    special, consequential, or incidental damages related to the software,
-    to the maximum extent the law permits.
-*/
-package org.bedework.calfacade.security;
-
-import org.bedework.calfacade.exc.CalFacadeException;
-
-import java.io.Serializable;
-
-/** Interface for classes which encrypt and decrypt passwords
- *
- * @author Mike Douglass
- */
-public interface PwEncryptionIntf extends Serializable {
-  /** Encrypt the password and return the result.
-   *
-   * @param val
-   * @return String
-   * @throws CalFacadeException
-   */
-  public String encrypt(String val) throws CalFacadeException;
-
-  /** Match the encrypted password - that is, encrypt the plain text and
-   * compare.
-   *
-   * @param plain
-   * @param encrypted
-   * @return boolean true for a match
-   * @throws CalFacadeException
-   */
-  public boolean match(String plain,
-                       String encrypted) throws CalFacadeException;
-
-  /** Decrypt the value
-   *
-   * @param encrypted
-   * @return String plain text.
-   * @throws CalFacadeException
-   */
-  public String decrypt(String encrypted) throws CalFacadeException;
-}

Modified: trunk/calsvc/src/org/bedework/calsvc/CalSvc.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/CalSvc.java	2010-10-04 21:37:06 UTC (rev 1392)
+++ trunk/calsvc/src/org/bedework/calsvc/CalSvc.java	2010-10-26 19:30:50 UTC (rev 1393)
@@ -48,7 +48,6 @@
 import org.bedework.calfacade.filter.SimpleFilterParser;
 import org.bedework.calfacade.ifs.Directories;
 import org.bedework.calfacade.mail.MailerIntf;
-import org.bedework.calfacade.security.PwEncryptionIntf;
 import org.bedework.calfacade.svc.BwAuthUser;
 import org.bedework.calfacade.svc.BwCalSuite;
 import org.bedework.calfacade.svc.UserAuth;
@@ -88,6 +87,7 @@
 import edu.rpi.cmt.access.PrivilegeDefs;
 import edu.rpi.cmt.access.PrivilegeSet;
 import edu.rpi.cmt.access.Acl.CurrentAccess;
+import edu.rpi.cmt.security.PwEncryptionIntf;
 import edu.rpi.cmt.timezones.Timezones;
 import edu.rpi.sss.util.OptionsI;
 
@@ -1312,13 +1312,25 @@
       return pwEncrypt;
     }
 
-    String pwEncryptClass = "org.bedework.calfacade.security.PwEncryptionDefault";
-    //String pwEncryptClass = getSysparsHandler().get().getPwEncryptClass();
+    try {
+      OptionsI opts = CalOptionsFactory.getOptions(debug);
+      String pwEncryptClass = "org.rpi.cmt.security.PwEncryptionDefault";
+      //String pwEncryptClass = getSysparsHandler().get().getPwEncryptClass();
 
-    pwEncrypt = (PwEncryptionIntf)CalFacadeUtil.getObject(
-                          pwEncryptClass, PwEncryptionIntf.class);
+      pwEncrypt = (PwEncryptionIntf)CalFacadeUtil.getObject(pwEncryptClass,
+                                                            PwEncryptionIntf.class);
 
-    return pwEncrypt;
+      pwEncrypt.init((String)opts.getGlobalProperty("privKeys"),
+                     (String)opts.getGlobalProperty("pubKeys"));
+
+      return pwEncrypt;
+    } catch (CalFacadeException cfe) {
+      cfe.printStackTrace();
+      throw cfe;
+    } catch (Throwable t) {
+      t.printStackTrace();
+      throw new CalFacadeException(t);
+    }
   }
 
   /* Get current parameters

Modified: trunk/calsvc/src/org/bedework/calsvc/Calendars.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Calendars.java	2010-10-04 21:37:06 UTC (rev 1392)
+++ trunk/calsvc/src/org/bedework/calsvc/Calendars.java	2010-10-26 19:30:50 UTC (rev 1393)
@@ -580,11 +580,19 @@
   }
 
   private void encryptPw(final BwCalendar val) throws CalFacadeException {
-    val.setRemotePw(getSvc().getEncrypter().encrypt(val.getRemotePw()));
+    try {
+      val.setRemotePw(getSvc().getEncrypter().encrypt(val.getRemotePw()));
+    } catch (Throwable t) {
+      throw new CalFacadeException(t);
+    }
   }
 
   private String decryptPw(final BwCalendar val) throws CalFacadeException {
-    return getSvc().getEncrypter().decrypt(val.getRemotePw());
+    try {
+      return getSvc().getEncrypter().decrypt(val.getRemotePw());
+    } catch (Throwable t) {
+      throw new CalFacadeException(t);
+    }
   }
 
   /** The calendar object represents a url to an external subscription.



More information about the Bedework-commit mailing list