You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(141) |
Sep
(184) |
Oct
(159) |
Nov
(77) |
Dec
(114) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(212) |
Feb
(302) |
Mar
(323) |
Apr
(360) |
May
(302) |
Jun
(392) |
Jul
(299) |
Aug
(858) |
Sep
(499) |
Oct
(489) |
Nov
(324) |
Dec
(438) |
2008 |
Jan
(449) |
Feb
(388) |
Mar
(811) |
Apr
(583) |
May
(949) |
Jun
(1431) |
Jul
(943) |
Aug
(527) |
Sep
(576) |
Oct
(440) |
Nov
(1046) |
Dec
(658) |
2009 |
Jan
(259) |
Feb
(192) |
Mar
(495) |
Apr
(2322) |
May
(2023) |
Jun
(1387) |
Jul
(722) |
Aug
(771) |
Sep
(167) |
Oct
(142) |
Nov
(384) |
Dec
(884) |
2010 |
Jan
(344) |
Feb
(82) |
Mar
(248) |
Apr
(341) |
May
(389) |
Jun
(289) |
Jul
(19) |
Aug
(478) |
Sep
(274) |
Oct
(431) |
Nov
(322) |
Dec
(207) |
2011 |
Jan
(125) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Joseph I. <jos...@us...> - 2006-12-25 12:52:18
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv19075/src/org/tolven/doc/bean Modified Files: DocumentBean.java Log Message: Had to valve back the introduction of SecurityDomain annotations to keep them from affecting the current code. So this represents another flag similar to the tolven.security.keys.activate flag Index: DocumentBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean/DocumentBean.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DocumentBean.java 25 Dec 2006 11:30:26 -0000 1.12 --- DocumentBean.java 25 Dec 2006 12:52:14 -0000 1.13 *************** *** 57,61 **** @Stateless() @Local(DocumentLocal.class) ! @SecurityDomain("tolvenLDAP") public class DocumentBean implements DocumentLocal { --- 57,61 ---- @Stateless() @Local(DocumentLocal.class) ! //@SecurityDomain("tolvenLDAP") public class DocumentBean implements DocumentLocal { |
From: Joseph I. <jos...@us...> - 2006-12-25 11:38:31
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/core/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv21246/src/org/tolven/core/bean Modified Files: AccountDAOBean.java Log Message: Removed unused security imports, plus a few more that were around. Index: AccountDAOBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/bean/AccountDAOBean.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** AccountDAOBean.java 25 Dec 2006 06:34:40 -0000 1.15 --- AccountDAOBean.java 25 Dec 2006 11:38:28 -0000 1.16 *************** *** 14,27 **** package org.tolven.core.bean; - import java.io.IOException; - import java.security.GeneralSecurityException; import java.security.PublicKey; import java.util.ArrayList; import java.util.Date; - import java.util.Iterator; import java.util.List; - import java.util.Set; - import javax.annotation.EJB; import javax.annotation.Resource; import javax.ejb.*; --- 14,22 ---- *************** *** 29,40 **** import javax.persistence.PersistenceContext; import javax.persistence.Query; - import javax.resource.spi.security.PasswordCredential; import javax.security.auth.Subject; import javax.security.jacc.PolicyContext; - import javax.security.jacc.PolicyContextException; - import org.jboss.annotation.security.SecurityDomain; import org.tolven.core.AccountDAOLocal; - import org.tolven.core.InvitationLocal; import org.tolven.core.SponsoredUser; import org.tolven.core.entity.Account; --- 24,31 ---- |
From: Joseph I. <jos...@us...> - 2006-12-25 11:30:30
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18062/src/org/tolven/doc/bean Modified Files: DocumentBean.java Log Message: Document Encryption can now take place within DocBase. The code will not be activated until thorough testing has been carried out. For development, it can be switched on via the property tolven.security.keys.activate=true, bearing in mind that documents encrypted cannot be retrieved if the keys are lost without backup etc Index: DocumentBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean/DocumentBean.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** DocumentBean.java 23 Dec 2006 22:52:32 -0000 1.11 --- DocumentBean.java 25 Dec 2006 11:30:26 -0000 1.12 *************** *** 33,36 **** --- 33,37 ---- import javax.xml.transform.stream.StreamSource; + import org.jboss.annotation.security.SecurityDomain; import org.tolven.admin.AdministrativeDetail; import org.tolven.admin.Details; *************** *** 56,59 **** --- 57,61 ---- @Stateless() @Local(DocumentLocal.class) + @SecurityDomain("tolvenLDAP") public class DocumentBean implements DocumentLocal { |
From: Joseph I. <jos...@us...> - 2006-12-25 11:30:30
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18062/src/org/tolven/doc/entity Modified Files: DocBase.java Log Message: Document Encryption can now take place within DocBase. The code will not be activated until thorough testing has been carried out. For development, it can be switched on via the property tolven.security.keys.activate=true, bearing in mind that documents encrypted cannot be retrieved if the keys are lost without backup etc Index: DocBase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity/DocBase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DocBase.java 23 Dec 2006 21:24:08 -0000 1.8 --- DocBase.java 25 Dec 2006 11:30:27 -0000 1.9 *************** *** 15,19 **** --- 15,25 ---- import java.io.Serializable; + import java.security.PrivateKey; + import java.security.PublicKey; + import java.util.Iterator; + import java.util.Set; + import javax.crypto.Cipher; + import javax.crypto.SecretKey; import javax.persistence.Basic; import javax.persistence.Column; *************** *** 21,24 **** --- 27,31 ---- import javax.persistence.DiscriminatorType; import javax.persistence.DiscriminatorValue; + import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.FetchType; *************** *** 31,38 **** --- 38,51 ---- import javax.persistence.ManyToOne; import javax.persistence.Table; + import javax.security.auth.Subject; + import javax.security.jacc.PolicyContext; import org.apache.commons.codec.binary.Base64; import org.tolven.core.entity.Account; + import org.tolven.core.entity.AccountUser; import org.tolven.core.entity.TolvenUser; + import org.tolven.security.key.AccountPrivateKey; + import org.tolven.security.key.DocumentSecretKey; + import org.tolven.security.key.UserPrivateKey; *************** *** 76,80 **** --- 89,97 ---- @Column(name="CONTENT") private byte[] content; + + @Embedded + private DocumentSecretKey documentSecretKey; + /** * Creates a new instance of DocBase *************** *** 145,149 **** */ public byte[] getContent() { ! return content; } --- 162,230 ---- */ public byte[] getContent() { ! if (System.getProperty("tolven.security.keys.activate") != null) { ! return getDecryptedContent(content); ! } else { ! return content; ! } ! } ! ! /** ! * Currently assumes all content is encrypted and only the authorized loggedInUser will succeed in getting the readable content ! * @param encryptedContent ! * @return ! */ ! private byte[] getDecryptedContent(byte[] encryptedContent) { ! if (encryptedContent == null || documentSecretKey == null) ! return encryptedContent; ! try { ! Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); ! if (subject == null) ! throw new IllegalStateException("No Subject found in PolicyContext"); ! //TODO: Should the Principal be identified in the Subject or via ejbContext? ! java.security.Principal principal = null; ! Object obj = null; ! for (java.util.Iterator iter = subject.getPrincipals().iterator(); iter.hasNext();) { ! obj = iter.next(); ! if (obj instanceof java.security.Principal && !(obj instanceof java.security.acl.Group)) { ! principal = (java.security.Principal) obj; ! break; ! } ! } ! if (principal == null) ! throw new IllegalStateException("No Principal found in Subject"); ! UserPrivateKey userPrivateKey = null; ! obj = null; ! for (java.util.Iterator iter = subject.getPrivateCredentials().iterator(); iter.hasNext();) { ! obj = iter.next(); ! if (obj instanceof UserPrivateKey) { ! userPrivateKey = (UserPrivateKey) obj; ! } ! } ! if (userPrivateKey == null) ! throw new RuntimeException(": No UserPrivateKey found for " + principal.getName()); ! PrivateKey privateKey = userPrivateKey.getPrivateKey(); ! //TODO: Not sure if this is the most efficient way to find the AccountUser of the logged in user ! Set<AccountUser> accountUsers = account.getAccountUsers(); ! AccountUser loggedInAccountUser = null; ! for (Iterator<AccountUser> iter = accountUsers.iterator(); iter.hasNext();) { ! loggedInAccountUser = iter.next(); ! if (loggedInAccountUser.getUser().getLdapUID().equals(principal.getName())) ! break; ! } ! if (loggedInAccountUser == null) ! throw new RuntimeException("No authorization to access documents in this account"); ! AccountPrivateKey loggedInAccountPrivateKey = loggedInAccountUser.getAccountPrivateKey(); ! if (loggedInAccountPrivateKey == null) { ! //TODO: No AccountPrivateKey means the content cannot be decrypted....for now give it back as encryptedContent ! return encryptedContent; ! } ! SecretKey docSecretKey = documentSecretKey.getSecretKey(loggedInAccountPrivateKey.getPrivateKey(privateKey)); ! Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); ! cipher.init(Cipher.DECRYPT_MODE, docSecretKey); ! return cipher.doFinal(encryptedContent); ! } catch (Exception ex) { ! ex.printStackTrace(); ! throw new RuntimeException(ex.getMessage()); ! } } *************** *** 152,159 **** return new String(getContent()); } public void setContent(byte[] content) { ! this.content = content; } public void setContentString(String content) { setContent(content.getBytes()); --- 233,265 ---- return new String(getContent()); } + public void setContent(byte[] content) { ! if (System.getProperty("tolven.security.keys.activate") != null) { ! this.content = getEncryptedContent(content); ! } else { ! this.content = content; ! } } + private byte[] getEncryptedContent(byte[] content) { + if (content == null) + return content; + try { + PublicKey accountPublicKey = account.getPublicKey(); + if (accountPublicKey == null) { + //TODO: No accountPublicKey means the content cannot be encrypted....for now give it back as content + return content; + } + documentSecretKey = DocumentSecretKey.getInstance(); + SecretKey docSecretKey = documentSecretKey.init(accountPublicKey); + Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); + cipher.init(Cipher.ENCRYPT_MODE, docSecretKey); + return cipher.doFinal(content); + } catch (Exception ex) { + ex.printStackTrace(); + throw new RuntimeException(ex.getMessage()); + } + } + public void setContentString(String content) { setContent(content.getBytes()); |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:44
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/key In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/org/tolven/security/key Added Files: AccountPrivateKey.java TolvenEncryptedSecretKey.java TolvenPublicKey.java TolvenEncryptedPrivateKey.java UserPrivateKey.java DocumentSecretKey.java AccountSecretKey.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. --- NEW FILE: DocumentSecretKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.PublicKey; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.persistence.*; /** * This class encapsulates a SecretKey which has been encrypted using a * PublicKey during initialization. To obtain the unencrypted SecretKey, the * PrivateKey companion of the encrypting PublicKey must be supplied. * * @author Joseph Isaac * */ @Embeddable public class DocumentSecretKey extends TolvenEncryptedSecretKey implements Serializable { public static final String DOC_KBE_KEY_ALGORITHM_PROP = "tolven.security.doc.kbeKeyAlgorithm"; public static final String DOC_KBE_KEY_LENGTH = "tolven.security.doc.kbeKeyLength"; protected DocumentSecretKey() { } /** * Return an instance of DocumentSecretKey * * @return */ public static DocumentSecretKey getInstance() { return new DocumentSecretKey(); } /** * Encrypt a SecretKey using a PublicKey * * @param aPublicKey * @throws GeneralSecurityException */ public SecretKey init(PublicKey aPublicKey) throws GeneralSecurityException { String kbeKeyAlgorithm = System.getProperty(DOC_KBE_KEY_ALGORITHM_PROP); KeyGenerator keyGenerator = KeyGenerator.getInstance(kbeKeyAlgorithm); keyGenerator.init(Integer.parseInt(System.getProperty(DOC_KBE_KEY_LENGTH))); SecretKey secretKey = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance(aPublicKey.getAlgorithm()); cipher.init(Cipher.WRAP_MODE, aPublicKey); setEncryptedKey(cipher.wrap(secretKey)); setAlgorithm(secretKey.getAlgorithm()); return secretKey; } } --- NEW FILE: AccountSecretKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.PublicKey; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.persistence.*; /** * This class encapsulates a SecretKey which has been encrypted using a * PublicKey during initialization. To obtain the unencrypted SecretKey, the * PrivateKey companion of the encrypting PublicKey must be supplied. * * @author Joseph Isaac * */ @Embeddable public class AccountSecretKey extends TolvenEncryptedSecretKey implements Serializable { public static final String ACCOUNT_USER_KBE_KEY_ALGORITHM_PROP = "tolven.security.accountUser.kbeKeyAlgorithm"; public static final String ACCOUNT_USER_KBE_KEY_LENGTH = "tolven.security.accountUser.kbeKeyLength"; protected AccountSecretKey() { } /** * Return an instance of AccountSecretKey * * @return */ public static AccountSecretKey getInstance() { return new AccountSecretKey(); } /** * Encrypt a SecretKey using a PublicKey * * @param aPublicKey * @throws GeneralSecurityException */ public SecretKey init(PublicKey aPublicKey) throws GeneralSecurityException { String kbeKeyAlgorithm = System.getProperty(ACCOUNT_USER_KBE_KEY_ALGORITHM_PROP); KeyGenerator keyGenerator = KeyGenerator.getInstance(kbeKeyAlgorithm); keyGenerator.init(Integer.parseInt(System.getProperty(ACCOUNT_USER_KBE_KEY_LENGTH))); SecretKey secretKey = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance(aPublicKey.getAlgorithm()); cipher.init(Cipher.WRAP_MODE, aPublicKey); setEncryptedKey(cipher.wrap(secretKey)); setAlgorithm(secretKey.getAlgorithm()); return secretKey; } } --- NEW FILE: AccountPrivateKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import java.io.IOException; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.PKCS8EncodedKeySpec; import javax.crypto.Cipher; import javax.crypto.EncryptedPrivateKeyInfo; import javax.crypto.SecretKey; import javax.persistence.*; /** * This class encapsulates a key-based encrypted PrivateKey, which has been * encrypted with a randomly generated SecretKey, which is itself then encrypted * with a PublicKey. The encrypted PrivateKey is encapsulated as an * EncryptedPrivateKeyInfo and the SecretKey is stored in a * TolvenEncryptedSecretKey. * * @author Joseph Isaac * */ @Embeddable public class AccountPrivateKey extends TolvenEncryptedPrivateKey implements Serializable { private static final String NOT_INITIALIZED = "AccountPrivateKey not initialized"; public static final String ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP = "tolven.security.account.privateKeyAlgorithm"; public static final String ACCOUNT_PRIVATE_KEY_LENGTH_PROP = "tolven.security.account.keyLength"; @Embedded private AccountSecretKey accountSecretKey; protected AccountPrivateKey() { } /** * Return an instance of AccountPrivateKey * * @return */ public static AccountPrivateKey getInstance() { return new AccountPrivateKey(); } /** * Create a PrivateKey, encrypt it with a randomly generated SecretKey and * encrypt the SecretKey with a PublicKey. Use the system-specific * privateKeyAlgorithm and kbeKeyAlgorithm * * @param anEncryptionKey * @return * @throws GeneralSecurityException * @throws IOException */ public PublicKey init(PublicKey anEncryptionKey) throws GeneralSecurityException, IOException { String privateKeyAlgorithm = System.getProperty(ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP); return init(privateKeyAlgorithm, anEncryptionKey); } /** * Decrypt the AccountPrivateKey using aDecryptionKey and re-encrypt it * using anEncryptionKey * * @param anAccountPrivateKey * @param aDecryptionKey * @param anEncryptionKey * @param anEncryptionKey * @return * @throws GeneralSecurityException */ public void init(AccountPrivateKey anAccountPrivateKey, UserPrivateKey aUserPrivateKey, PublicKey anEncryptionKey) throws GeneralSecurityException, IOException { setKeySize(anAccountPrivateKey.getKeySize()); PrivateKey privateKey = anAccountPrivateKey.getPrivateKey(aUserPrivateKey.getPrivateKey()); accountSecretKey = AccountSecretKey.getInstance(); SecretKey secretKey = accountSecretKey.init(anEncryptionKey); Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedPrivateKey = cipher.doFinal(privateKey.getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(privateKey.getAlgorithm(), encryptedPrivateKey); setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo); } /** * Create a PrivateKey, encrypt it with a randomly generated SecretKey and * encrypt the SecretKey with a PublicKey * * @param aPrivateKeyAlgorithm * @param secretKeyAlgorithm * @param anEncryptionKey * @return * @throws GeneralSecurityException */ private PublicKey init(String aPrivateKeyAlgorithm, PublicKey anEncryptionKey) throws GeneralSecurityException, IOException { setKeySize(Integer.parseInt(System.getProperty(ACCOUNT_PRIVATE_KEY_LENGTH_PROP))); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(aPrivateKeyAlgorithm); keyPairGenerator.initialize(getKeySize()); KeyPair keyPair = keyPairGenerator.genKeyPair(); accountSecretKey = AccountSecretKey.getInstance(); SecretKey secretKey = accountSecretKey.init(anEncryptionKey); Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedPrivateKey = cipher.doFinal(keyPair.getPrivate().getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(aPrivateKeyAlgorithm, encryptedPrivateKey); setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo); return keyPair.getPublic(); } /** * Decrypt and return the PrivateKey using aDecryptionKey * * @param aDecryptionKey * @return * @throws GeneralSecurityException */ public PrivateKey getPrivateKey(PrivateKey aDecryptionKey) throws GeneralSecurityException, IOException { if (accountSecretKey == null) throw new IllegalStateException(NOT_INITIALIZED); SecretKey secretKey = accountSecretKey.getSecretKey(aDecryptionKey); Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, secretKey); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(getEncodedEncryptedPrivateKeyInfo()); byte[] decryptedPrivateKey = cipher.doFinal(encryptedPrivateKeyInfo.getEncryptedData()); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decryptedPrivateKey); return KeyFactory.getInstance(encryptedPrivateKeyInfo.getAlgName()).generatePrivate(keySpec); } } --- NEW FILE: TolvenEncryptedPrivateKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import javax.crypto.EncryptedPrivateKeyInfo; import java.io.IOException; import javax.persistence.*; /** * An abstract class which encapsulates an EncryptedPrivateKeyInfo. * * @author Joseph Isaac * */ @MappedSuperclass public abstract class TolvenEncryptedPrivateKey { @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "encoded_encrypted_private_key_info") private byte[] encodedEncryptedPrivateKeyInfo; @Column(name = "private_key_size") private int keySize; @Column(name = "private_key_algorithm") private String algorithm; /** * Return the EncryptedPrivateKeyInfo * * @return */ protected byte[] getEncodedEncryptedPrivateKeyInfo() { return encodedEncryptedPrivateKeyInfo; } /** * Set the EncryptedPrivateKeyInfo * * @param privateKeyAlgorithm * @param anEncryptedPrivateKeyInfo */ protected void setEncodedEncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo anEncryptedPrivateKeyInfo) throws IOException { algorithm = anEncryptedPrivateKeyInfo.getAlgName(); encodedEncryptedPrivateKeyInfo = anEncryptedPrivateKeyInfo.getEncoded(); } /** * return the PrivateKey size * * @return */ protected int getKeySize() { return keySize; } /** * Keep the PrivateKey size since it does not appear to be readily available * from an EncryptedPrivateKeyInfo * * @param anInt */ protected void setKeySize(int anInt) { keySize = anInt; } /** * return the PrivateKey algorithm * * @return */ protected String getAlgorithm() { return algorithm; } /** * Keep the PrivateKey algorithm. It it is part of an EncryptedPrivateKeyInfo but one has to decrypt to find out what it is * * @param aString */ protected void setAlgorithm(String aString) { algorithm = aString; } } --- NEW FILE: UserPrivateKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import java.io.IOException; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; import java.security.spec.PKCS8EncodedKeySpec; import javax.crypto.Cipher; import javax.crypto.EncryptedPrivateKeyInfo; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEParameterSpec; import javax.persistence.*; /** * This class encapsulates a password-based encrypted PrivateKey, which has been * encrypted with a password-based encryption algorithm. The SecretKey used to * encrypt the PrivateKey is not saved, since it can be regenerated given the * pbeKeyAlgorithm, salt, iterationCount (which are stored) and the original * password. * * @author Joseph Isaac * */ @Embeddable public class UserPrivateKey extends TolvenEncryptedPrivateKey implements Serializable { private static final String NOT_INITIALIZED = "UserPrivateKey not initialized"; private static final String KEY_LOCKED = "UserPrivateKey is locked"; public static final String USER_PRIVATE_KEY_ALGORITHM_PROP = "tolven.security.user.privateKeyAlgorithm"; public static final String USER_PRIVATE_KEY_LENGTH_PROP = "tolven.security.user.privateKeyLength"; public static final String PBE_KEY_ALGORITHM_PROP = "tolven.security.user.pbeKeyAlgorithm"; public static final String USER_PASSWORD_SALT_LENGTH_PROP = "tolven.security.user.passwordSaltLength"; public static final String USER_PASSWORD_ITERATION_COUNT_PROP = "tolven.security.user.passwordIterationCount"; @Column(name = "pbe_key_algorithm", length = 100) private String pbeKeyAlgorithm; @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "pbe_key_salt") private byte[] salt; @Column(name = "pbe_key_iteration_count") private int iterationCount; private transient PrivateKey privateKey; protected UserPrivateKey() { } /** * Return an instance of UserPrivateKey * * @return */ public static UserPrivateKey getInstance() { return new UserPrivateKey(); } // TODO: This could be in the wrong place. Maybe shouldn't be static either. public static SecureRandom rng = new SecureRandom(); /** * Create and protect a PrivateKey using password based encryption. Use the * system-specific privateKeyAlgorithm, pbeKeyAlgorithm, random salt and * iterationCount * * @param aPassword * @return * @throws GeneralSecurityException */ public PublicKey init(char[] aPassword) throws GeneralSecurityException, IOException { String privateKeyAlgorithm = System.getProperty(USER_PRIVATE_KEY_ALGORITHM_PROP); String pbeKeyAlgorithm = System.getProperty(PBE_KEY_ALGORITHM_PROP); byte[] salt = getRandomSalt(); int iterationCount = Integer.parseInt(System.getProperty(USER_PASSWORD_ITERATION_COUNT_PROP)); return init(privateKeyAlgorithm, pbeKeyAlgorithm, aPassword, salt, iterationCount); } /** * Return a randome salt byte[] * * @return */ private byte[] getRandomSalt() { byte[] salt = new byte[Integer.parseInt(System.getProperty(USER_PASSWORD_SALT_LENGTH_PROP))]; rng.nextBytes(salt); return salt; } /** * Create and protect a PrivateKey using password based encryption * * @param aPrivateKeyAlgorithm * @param aSecretKeyAlgorithm * @param aPassword * @param salt * @param iterationCount * @return * @throws GeneralSecurityException */ private PublicKey init(String aPrivateKeyAlgorithm, String aPBEKeyAlgorithm, char[] aPassword, byte[] salt, int iterationCount) throws GeneralSecurityException, IOException { setKeySize(Integer.parseInt(System.getProperty(USER_PRIVATE_KEY_LENGTH_PROP))); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(aPrivateKeyAlgorithm); keyPairGenerator.initialize(getKeySize()); KeyPair keyPair = keyPairGenerator.genKeyPair(); PBEKeySpec pbeKeySpec = new PBEKeySpec(aPassword); SecretKey secretKey = SecretKeyFactory.getInstance(aPBEKeyAlgorithm).generateSecret(pbeKeySpec); PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, iterationCount); Cipher cipher = Cipher.getInstance(secretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, secretKey, pbeParamSpec); byte[] encryptedPrivateKey = cipher.doFinal(keyPair.getPrivate().getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(aPrivateKeyAlgorithm, encryptedPrivateKey); setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo); this.pbeKeyAlgorithm = aPBEKeyAlgorithm; this.salt = salt; this.iterationCount = iterationCount; return keyPair.getPublic(); } /** * Decrypt and return the PrivateKey using aPassword * * @param aPassword * @return * @throws GeneralSecurityException */ public PrivateKey getPrivateKey(char[] aPassword) throws GeneralSecurityException, IOException { if (getEncodedEncryptedPrivateKeyInfo() == null || pbeKeyAlgorithm == null || salt == null) throw new IllegalStateException(NOT_INITIALIZED); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(getEncodedEncryptedPrivateKeyInfo()); PKCS8EncodedKeySpec privateKeySpec = getPrivateKeySpec(aPassword); return KeyFactory.getInstance(encryptedPrivateKeyInfo.getAlgName()).generatePrivate(privateKeySpec); } /** * Decrypt the encrypted Private and unlock it for future access using * getPrivateKey() * * @param aPassword * @throws GeneralSecurityException * @throws IOException */ public void unlockPrivateKey(char[] aPassword) throws GeneralSecurityException, IOException { if (getEncodedEncryptedPrivateKeyInfo() == null || pbeKeyAlgorithm == null || salt == null) throw new IllegalStateException(NOT_INITIALIZED); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(getEncodedEncryptedPrivateKeyInfo()); PKCS8EncodedKeySpec privateKeySpec = getPrivateKeySpec(aPassword); KeyFactory keyFactory = KeyFactory.getInstance(encryptedPrivateKeyInfo.getAlgName()); privateKey = keyFactory.generatePrivate(privateKeySpec); } /** * Lock UserPrivateKey by removing the decrypted privateKey * */ public void lockPrivateKey() { privateKey = null; } /** * Return the privateKey if it is not locked, otherwise return null * * @return */ public PrivateKey getPrivateKey() { if (privateKey == null) throw new IllegalStateException(KEY_LOCKED); return privateKey; } /** * Return a PKCS8EncodedKeySpec which can be used to regenerate the * PrivateKey * * @param aPassword * @return * @throws GeneralSecurityException * @throws IOException */ private PKCS8EncodedKeySpec getPrivateKeySpec(char[] aPassword) throws GeneralSecurityException, IOException { if (getEncodedEncryptedPrivateKeyInfo() == null || pbeKeyAlgorithm == null || salt == null) throw new IllegalStateException(NOT_INITIALIZED); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(getEncodedEncryptedPrivateKeyInfo()); PBEKeySpec pbeKeySpec = new PBEKeySpec(aPassword); SecretKey secretKey = SecretKeyFactory.getInstance(pbeKeyAlgorithm).generateSecret(pbeKeySpec); PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, iterationCount); Cipher cipher = Cipher.getInstance(pbeKeyAlgorithm); cipher.init(Cipher.DECRYPT_MODE, secretKey, pbeParamSpec); return encryptedPrivateKeyInfo.getKeySpec(cipher); } } --- NEW FILE: TolvenPublicKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.KeyFactory; import java.security.PublicKey; import java.security.spec.X509EncodedKeySpec; import javax.persistence.*; /** * This class encapsulates an x509EncodedKeySpec for a Public Key * * @author Joseph Isaac * */ @Embeddable public class TolvenPublicKey implements Serializable { private static final String NOT_INITIALIZED = "TolvenPublicKey not initialized"; @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "x509_encoded__key_spec") private byte[] x509EncodedKeySpec; @Column(name = "public_key_algorithm") private String algorithm; protected TolvenPublicKey() { } /** * Return an instance of TolvenPublicKey * * @return */ public static TolvenPublicKey getInstance() { return new TolvenPublicKey(); } /** * Initialize TolvenPublicKey with aPublicKey * @param aPublicKey */ public void init(PublicKey aPublicKey) { X509EncodedKeySpec keySpec = new X509EncodedKeySpec(aPublicKey.getEncoded()); x509EncodedKeySpec = keySpec.getEncoded(); algorithm = aPublicKey.getAlgorithm(); } /** * Decode and return the encapsulated PublicKey * @return * @throws GeneralSecurityException */ public PublicKey getPublicKey() throws GeneralSecurityException { if (x509EncodedKeySpec == null || algorithm == null) throw new IllegalStateException(NOT_INITIALIZED); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(x509EncodedKeySpec); return KeyFactory.getInstance(algorithm).generatePublic(keySpec); } } --- NEW FILE: TolvenEncryptedSecretKey.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.key; import java.io.Serializable; import java.security.GeneralSecurityException; import java.security.PrivateKey; import java.security.PublicKey; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.persistence.*; /** * This class encapsulates a SecretKey which has been encrypted using a * PublicKey during initialization. To obtain the unencrypted SecretKey, the * PrivateKey companion of the encrypting PublicKey must be supplied. * * @author Joseph Isaac * */ @MappedSuperclass public abstract class TolvenEncryptedSecretKey implements Serializable { @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "encrypted_secret_key") private byte[] encryptedKey; @Column(name = "secret_key_algorithm") private String algorithm; protected TolvenEncryptedSecretKey() { } /** * Return the encrypted SecretKey * * @return */ protected byte[] getEncryptedKey() { return encryptedKey; } protected void setEncryptedKey(byte[] array) { encryptedKey = array; } /** * Encrypt a SecretKey using a PublicKey * * @param aPublicKey * @throws GeneralSecurityException */ public abstract SecretKey init(PublicKey aPublicKey) throws GeneralSecurityException; /** * Return the algorithm of the encrypted SecretKey * * @return */ public String getAlgorithm() { return algorithm; } protected void setAlgorithm(String aString) { algorithm = aString; } /** * Decrypt the SecretKey using a PrivateKey and return it * * @param aDecryptionKey * @return * @throws GeneralSecurityException */ public SecretKey getSecretKey(PrivateKey aDecryptionPrivateKey) throws GeneralSecurityException { if (encryptedKey == null || algorithm == null) throw new IllegalStateException(getClass() + " not initialized"); Cipher cipher = Cipher.getInstance(aDecryptionPrivateKey.getAlgorithm()); cipher.init(Cipher.UNWRAP_MODE, aDecryptionPrivateKey); return (SecretKey) cipher.unwrap(encryptedKey, algorithm, Cipher.SECRET_KEY); } } |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:44
|
Update of /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/key In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/test/org/tolven/security/key Added Files: DocumentEncryptionTestCase.java TolvenPublicKeyTestCase.java UserPrivateKeyTestCase.java TestCaseDocument.java DocumentSecretKeyTestCase.java SecurityTestSuite.java AccountSecretKeyTestCase.java AccountPrivateKeyTestCase.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. --- NEW FILE: AccountSecretKeyTestCase.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.PublicKey; import java.security.PrivateKey; import junit.framework.TestCase; import javax.crypto.SecretKey; import org.tolven.security.key.AccountSecretKey; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.UserPrivateKey; /** * This class is used to testing AccountSecretKey. * * @author Joseph Isaac * */ public class AccountSecretKeyTestCase extends TestCase { /* * Test method for * 'org.tolven.security.key.AccountSecretKey.getSecretKey(PrivateKey)' */ public void testGetSecretKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); PrivateKey theUserPrivateKey = userPrivateKey.getPrivateKey(password); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); PublicKey theAccountPublicKey = accountPrivateKey.init(theUserPublicKey); PrivateKey theAccountPrivateKey = accountPrivateKey.getPrivateKey(theUserPrivateKey); AccountSecretKey accountSecretKey = AccountSecretKey.getInstance(); SecretKey theOriginalSecretKey = accountSecretKey.init(theAccountPublicKey); SecretKey requestedSecretKey = accountSecretKey.getSecretKey(theAccountPrivateKey); assertTrue(requestedSecretKey.equals(theOriginalSecretKey)); } /* * Test method for 'org.tolven.security.key.AccountSecretKey.getInstance()' */ public void testGetInstance() { AccountSecretKey.getInstance(); } /* * Test method for * 'org.tolven.security.key.AccountSecretKey.init(PublicKey)' */ public void testInitPublicKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); PublicKey accountPublicKey = accountPrivateKey.init(theUserPublicKey); AccountSecretKey accountSecretKey = AccountSecretKey.getInstance(); SecretKey secretKey = accountSecretKey.init(accountPublicKey); assertTrue(secretKey.getAlgorithm().equals(System.getProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_ALGORITHM_PROP))); } } --- NEW FILE: UserPrivateKeyTestCase.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import java.security.PublicKey; import java.security.PrivateKey; import java.security.GeneralSecurityException; import java.io.IOException; import org.tolven.security.key.UserPrivateKey; import junit.framework.TestCase; /** * This class is used to testing UserPrivateKey. * * @author Joseph Isaac * */ public class UserPrivateKeyTestCase extends TestCase { /* * Test method for 'org.tolven.security.key.UserPrivateKey.getInstance()' */ public void testGetInstance() { UserPrivateKey.getInstance(); } /* * Test method for 'org.tolven.security.key.UserPrivateKey.init(char[])' */ public void testInitCharArray() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey pbePrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey publicKey = pbePrivateKey.init(password); assertTrue(publicKey.getAlgorithm().equals(System.getProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP))); } /* * Test method for * 'org.tolven.security.key.UserPrivateKey.getPrivateKey(char[])' */ public void testGetPrivateKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey publicKey = userPrivateKey.init(password); assertTrue(publicKey.getAlgorithm().equals(System.getProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP))); PrivateKey privateKey = userPrivateKey.getPrivateKey(password); assertTrue(privateKey.getAlgorithm().equals(System.getProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP))); } /* * Test method for 'org.tolven.security.key.UserPrivateKey.unlockPrivateKey()' */ public void testUnlockPrivateKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); userPrivateKey.init(password); userPrivateKey.unlockPrivateKey(password); PrivateKey privateKey = userPrivateKey.getPrivateKey(); assertNotNull(privateKey); } } --- NEW FILE: TolvenPublicKeyTestCase.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.PublicKey; import junit.framework.TestCase; import org.tolven.security.key.TolvenPublicKey; import org.tolven.security.key.UserPrivateKey; /** * This class is used to testing TolvenPublicKey. * * @author Joseph Isaac * */ public class TolvenPublicKeyTestCase extends TestCase { /* * Test method for 'org.tolven.security.key.TolvenPublicKey.getInstance()' */ public void testGetInstance() { TolvenPublicKey.getInstance(); } /* * Test method for * 'org.tolven.security.key.TolvenPublicKey.init(PublicKey)' */ public void testInitPublicKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); TolvenPublicKey tolvenPublicKey = TolvenPublicKey.getInstance(); tolvenPublicKey.init(theUserPublicKey); } /* * Test method for 'org.tolven.security.key.TolvenPublicKey.getPublicKey()' */ public void testGetPublicKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); TolvenPublicKey tolvenPublicKey = TolvenPublicKey.getInstance(); tolvenPublicKey.init(theUserPublicKey); PublicKey publicKey = tolvenPublicKey.getPublicKey(); assertTrue(publicKey.equals(theUserPublicKey)); } } --- NEW FILE: DocumentEncryptionTestCase.java --- package test.org.tolven.security.key; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.PublicKey; import junit.framework.TestCase; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.UserPrivateKey; public class DocumentEncryptionTestCase extends TestCase { /* * Test method for 'test.org.tolven.security.key.TestCaseDocument.init(byte[], PublicKey, PrivateKey, String)' */ public void testInit() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); byte[] unencryptedDocument = "The quick brown fox jumps over a lazy dog.".getBytes(); char[] password = "somepassword".toCharArray(); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); PublicKey tolvenUserPublicKey = userPrivateKey.init(password); PublicKey accountPublicKey = accountPrivateKey.init(tolvenUserPublicKey); TestCaseDocument testCaseDocument = new TestCaseDocument(); testCaseDocument.init(unencryptedDocument, accountPublicKey, userPrivateKey.getPrivateKey(password)); } /* * Test method for 'test.org.tolven.security.key.TestCaseDocument.verify(PublicKey, PrivateKey)' */ public void testVerify() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); byte[] unencryptedDocument = "The quick brown fox jumps over a lazy dog.".getBytes(); char[] password = "somepassword".toCharArray(); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); PublicKey tolvenUserPublicKey = userPrivateKey.init(password); PublicKey accountPublicKey = accountPrivateKey.init(tolvenUserPublicKey); TestCaseDocument testCaseDocument = new TestCaseDocument(); testCaseDocument.init(unencryptedDocument, accountPublicKey, userPrivateKey.getPrivateKey(password)); boolean verified = testCaseDocument.verify(tolvenUserPublicKey, accountPrivateKey.getPrivateKey(userPrivateKey.getPrivateKey(password))); assertTrue(verified); } /* * Test method for 'test.org.tolven.security.key.TestCaseDocument.decryptDocument(PrivateKey)' */ public void testDecryptDocument() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); byte[] unencryptedDocument = "The quick brown fox jumps over a lazy dog.".getBytes(); char[] password = "somepassword".toCharArray(); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); PublicKey tolvenUserPublicKey = userPrivateKey.init(password); PublicKey accountPublicKey = accountPrivateKey.init(tolvenUserPublicKey); TestCaseDocument testCaseDocument = new TestCaseDocument(); testCaseDocument.init(unencryptedDocument, accountPublicKey, userPrivateKey.getPrivateKey(password)); byte[] decryptedDocument = testCaseDocument.decryptDocument(accountPrivateKey.getPrivateKey(userPrivateKey.getPrivateKey(password))); assertTrue(new String(unencryptedDocument).equals(new String(decryptedDocument))); } } --- NEW FILE: DocumentSecretKeyTestCase.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.PublicKey; import java.security.PrivateKey; import junit.framework.TestCase; import javax.crypto.SecretKey; import org.tolven.security.key.DocumentSecretKey; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.UserPrivateKey; /** * This class is used to testing DocumentSecretKey. * * @author Joseph Isaac * */ public class DocumentSecretKeyTestCase extends TestCase { /* * Test method for * 'org.tolven.security.key.DocumentSecretKey.getSecretKey(PrivateKey)' */ public void testGetSecretKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); PrivateKey theUserPrivateKey = userPrivateKey.getPrivateKey(password); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); PublicKey theAccountPublicKey = accountPrivateKey.init(theUserPublicKey); PrivateKey theAccountPrivateKey = accountPrivateKey.getPrivateKey(theUserPrivateKey); DocumentSecretKey accountSecretKey = DocumentSecretKey.getInstance(); SecretKey theOriginalSecretKey = accountSecretKey.init(theAccountPublicKey); SecretKey requestedSecretKey = accountSecretKey.getSecretKey(theAccountPrivateKey); assertTrue(requestedSecretKey.equals(theOriginalSecretKey)); } /* * Test method for * 'org.tolven.security.key.DocumentSecretKey.getInstance()' */ public void testGetInstance() { DocumentSecretKey.getInstance(); } /* * Test method for * 'org.tolven.security.key.DocumentSecretKey.init(PublicKey)' */ public void testInitPublicKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); PublicKey accountPublicKey = accountPrivateKey.init(theUserPublicKey); DocumentSecretKey accountSecretKey = DocumentSecretKey.getInstance(); SecretKey secretKey = accountSecretKey.init(accountPublicKey); assertTrue(secretKey.getAlgorithm().equals(System.getProperty(DocumentSecretKey.DOC_KBE_KEY_ALGORITHM_PROP))); } } --- NEW FILE: AccountPrivateKeyTestCase.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.PublicKey; import java.security.PrivateKey; import junit.framework.TestCase; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.UserPrivateKey; /** * This class is used to testing AccountPrivateKey. * * @author Joseph Isaac * */ public class AccountPrivateKeyTestCase extends TestCase { /* * Test method for * 'org.tolven.security.key.AccountPrivateKey.getInstance()' */ public void testGetInstance() { AccountPrivateKey.getInstance(); } /* * Test method for * 'org.tolven.security.key.AccountPrivateKey.init(PublicKey)' */ public void testInitPublicKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey publicKey = userPrivateKey.init(password); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); PublicKey accountPublicKey = accountPrivateKey.init(publicKey); assertTrue(accountPublicKey.getAlgorithm().equals(System.getProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP))); } /* * Test method for * 'org.tolven.security.key.AccountPrivateKey.init(AccountPrivateKey, UserPrivateKey, PublicKey)' */ public void testInitAccountPrivateKeyUserPrivateKeyPublicKey() throws GeneralSecurityException, IOException { //Create UserPrivateKey1 SecurityTestSuite.initProperties(); UserPrivateKey theUserPrivateKey1 = UserPrivateKey.getInstance(); char[] password1 = "password1".toCharArray(); PublicKey publicKey1 = theUserPrivateKey1.init(password1); PrivateKey userPrivateKey1 = theUserPrivateKey1.getPrivateKey(password1); theUserPrivateKey1.unlockPrivateKey(password1); //Create AccountPrivateKey1 AccountPrivateKey accountPrivateKey1 = AccountPrivateKey.getInstance(); accountPrivateKey1.init(publicKey1); //Create UserPrivateKey2 UserPrivateKey theUserPrivateKey2 = UserPrivateKey.getInstance(); char[] password2 = "password2".toCharArray(); PublicKey publicKey2 = theUserPrivateKey2.init(password2); PrivateKey userPrivateKey2 = theUserPrivateKey2.getPrivateKey(password2); //Transfer AccountPrivateKey1 to AccountPrivateKey2 AccountPrivateKey accountPrivateKey2 = AccountPrivateKey.getInstance(); accountPrivateKey2.init(accountPrivateKey1, theUserPrivateKey1, publicKey2); assertTrue(accountPrivateKey2.getPrivateKey(userPrivateKey2).equals(accountPrivateKey1.getPrivateKey(userPrivateKey1))); } /* * Test method for * 'org.tolven.security.key.AccountPrivateKey.getEncryptedSecretKey()' */ public void testGetEncryptedSecretKey() { } /* * Test method for * 'org.tolven.security.key.AccountPrivateKey.getPrivateKey(PrivateKey)' */ public void testGetPrivateKey() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); PublicKey theUserPublicKey = userPrivateKey.init(password); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); accountPrivateKey.init(theUserPublicKey); PrivateKey theUserPrivateKey = userPrivateKey.getPrivateKey(password); PrivateKey theAccountPrivateKey = accountPrivateKey.getPrivateKey(theUserPrivateKey); assertTrue(theAccountPrivateKey.getAlgorithm().equals(System.getProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP))); } } --- NEW FILE: TestCaseDocument.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import javax.crypto.Cipher; import javax.crypto.SecretKey; import org.tolven.security.key.DocumentSecretKey; import java.security.GeneralSecurityException; import java.security.PublicKey; import java.security.PrivateKey; import java.security.Signature; /** * This class is used to test document encryption, decryption and signature * * @author Joseph Isaac * */ public class TestCaseDocument { public static final String DOC_SIGNATURE_ALGORITHM_PROP = "tolven.security.doc.signatureAlgorithm"; private byte[] encryptedContent; private DocumentSecretKey documentSecretKey; private byte[] signature; private String signatureAlgorithm; /** * Genrate a document signature for some plainText, using a document * signature algorithm, then encrypt the plainText using the document * encryption algorithm of a randomly generated SecretKey, and encrypt the * SecretKey with anEncryptionKey * * @param plainText * @param anEncryptionKey * @param aSignatureKey * @param aSignatureAlgorithm * @return * @throws GeneralSecurityException */ public void init(byte[] plainText, PublicKey anEncryptionKey, PrivateKey aSignatureKey) throws GeneralSecurityException { signatureAlgorithm = System.getProperty(DOC_SIGNATURE_ALGORITHM_PROP); Signature sig = Signature.getInstance(signatureAlgorithm); sig.initSign(aSignatureKey); sig.update(plainText); signature = sig.sign(); documentSecretKey = DocumentSecretKey.getInstance(); SecretKey docSecretKey = documentSecretKey.init(anEncryptionKey); encryptedContent = createEncryptedContent(plainText, docSecretKey); } /** * return an encrypted Document * * @return */ private byte[] getEncryptedContent() { return encryptedContent; } /** * Decrypt the SecretKey using aDecryptionKey * * @param aDecryptionKey * @return * @throws GeneralSecurityException */ private SecretKey getSecretKey(PrivateKey aDecryptionKey) throws GeneralSecurityException { return documentSecretKey.getSecretKey(aDecryptionKey); } /** * Verify the document signature belongs to aPublicKey using aDecryptionKey * to decrypt the document * * @param aPublicKey * @param aDecryptionKey * @return * @throws GeneralSecurityException */ public boolean verify(PublicKey aPublicKey, PrivateKey aDecryptionKey) throws GeneralSecurityException { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(aPublicKey); sig.update(decryptDocument(aDecryptionKey)); return sig.verify(signature); } /** * Decrypt a Document using aDecryptionKey * * @param aDecryptionKey * @return * @throws GeneralSecurityException */ public byte[] decryptDocument(PrivateKey aDecryptionKey) throws GeneralSecurityException { SecretKey docSecretKey = getSecretKey(aDecryptionKey); Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, docSecretKey); return cipher.doFinal(getEncryptedContent()); } /** * Encrypt plainText with a SecretKey * * @param plainText * @param secretKey * @return * @throws Exception */ private byte[] createEncryptedContent(byte[] plainText, SecretKey aSecretKey) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance(aSecretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, aSecretKey); return cipher.doFinal(plainText); } } --- NEW FILE: SecurityTestSuite.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.key; import org.tolven.security.key.AccountPrivateKey; import org.tolven.security.key.AccountSecretKey; import org.tolven.security.key.DocumentSecretKey; import org.tolven.security.key.UserPrivateKey; import junit.framework.Test; import junit.framework.TestSuite; /** * This class carries out testing for a number of security features. * * @author Joseph Isaac * */ public class SecurityTestSuite { public static Test suite() { TestSuite suite = new TestSuite("Test for test.org.tolven.security.key"); //$JUnit-BEGIN$ suite.addTestSuite(UserPrivateKeyTestCase.class); suite.addTestSuite(AccountSecretKeyTestCase.class); suite.addTestSuite(TolvenPublicKeyTestCase.class); suite.addTestSuite(AccountPrivateKeyTestCase.class); suite.addTestSuite(DocumentSecretKeyTestCase.class); suite.addTestSuite(DocumentEncryptionTestCase.class); //$JUnit-END$ return suite; } public static void initProperties() { System.setProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP, "RSA"); System.setProperty(UserPrivateKey.USER_PRIVATE_KEY_LENGTH_PROP, "1024"); System.setProperty(UserPrivateKey.PBE_KEY_ALGORITHM_PROP, "PBEWithMD5AndDES"); System.setProperty(UserPrivateKey.USER_PASSWORD_SALT_LENGTH_PROP, "8"); System.setProperty(UserPrivateKey.USER_PASSWORD_ITERATION_COUNT_PROP, "20"); System.setProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP, "RSA"); System.setProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_LENGTH_PROP, "1024"); System.setProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_ALGORITHM_PROP, "DESede"); System.setProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_LENGTH, "112"); System.setProperty(DocumentSecretKey.DOC_KBE_KEY_ALGORITHM_PROP, "DESede"); System.setProperty(DocumentSecretKey.DOC_KBE_KEY_LENGTH, "112"); System.setProperty(TestCaseDocument.DOC_SIGNATURE_ALGORITHM_PROP, "SHA1withRSA"); } } |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:44
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/core/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/org/tolven/core/entity Modified Files: Account.java AccountUser.java TolvenUser.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. Index: AccountUser.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/entity/AccountUser.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** AccountUser.java 8 Dec 2006 07:21:52 -0000 1.7 --- AccountUser.java 25 Dec 2006 06:34:40 -0000 1.8 *************** *** 29,33 **** import org.tolven.doc.entity.DocBase; ! import org.tolven.security.bean.AccountPrivateKey; /** --- 29,33 ---- import org.tolven.doc.entity.DocBase; ! import org.tolven.security.key.AccountPrivateKey; /** Index: Account.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/entity/Account.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Account.java 22 Dec 2006 06:40:25 -0000 1.13 --- Account.java 25 Dec 2006 06:34:40 -0000 1.14 *************** *** 30,34 **** import javax.persistence.Table; ! import org.tolven.security.bean.TolvenPublicKey; /** --- 30,34 ---- import javax.persistence.Table; ! import org.tolven.security.key.TolvenPublicKey; /** Index: TolvenUser.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/entity/TolvenUser.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TolvenUser.java 22 Dec 2006 06:40:25 -0000 1.13 --- TolvenUser.java 25 Dec 2006 06:34:40 -0000 1.14 *************** *** 23,28 **** import org.tolven.doc.entity.DocBase; ! import org.tolven.security.bean.TolvenPublicKey; ! import org.tolven.security.bean.UserPrivateKey; /** --- 23,28 ---- import org.tolven.doc.entity.DocBase; ! import org.tolven.security.key.TolvenPublicKey; ! import org.tolven.security.key.UserPrivateKey; /** |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:44
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/org/tolven/doc/entity Modified Files: Invitation.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. Index: Invitation.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity/Invitation.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Invitation.java 9 Dec 2006 11:16:23 -0000 1.6 --- Invitation.java 25 Dec 2006 06:34:40 -0000 1.7 *************** *** 31,35 **** import org.tolven.core.entity.Account; import org.tolven.core.entity.TolvenUser; ! import org.tolven.security.bean.AccountPrivateKey; /** --- 31,35 ---- import org.tolven.core.entity.Account; import org.tolven.core.entity.TolvenUser; ! import org.tolven.security.key.AccountPrivateKey; /** |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:43
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/core/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/org/tolven/core/bean Modified Files: AccountDAOBean.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. Index: AccountDAOBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/bean/AccountDAOBean.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** AccountDAOBean.java 25 Dec 2006 01:43:23 -0000 1.14 --- AccountDAOBean.java 25 Dec 2006 06:34:40 -0000 1.15 *************** *** 45,50 **** import org.tolven.core.entity.AccountUser; import org.tolven.doc.entity.Invitation; ! import org.tolven.security.bean.AccountPrivateKey; ! import org.tolven.security.bean.UserPrivateKey; --- 45,50 ---- import org.tolven.core.entity.AccountUser; import org.tolven.doc.entity.Invitation; ! import org.tolven.security.key.AccountPrivateKey; ! import org.tolven.security.key.UserPrivateKey; |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:43
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/org/tolven/security/bean Removed Files: TolvenEncryptedSecretKey.java AccountPrivateKey.java AccountSecretKey.java TolvenEncryptedPrivateKey.java DocumentSecretKey.java UserPrivateKey.java TolvenPublicKey.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. --- DocumentSecretKey.java DELETED --- --- AccountSecretKey.java DELETED --- --- AccountPrivateKey.java DELETED --- --- TolvenEncryptedPrivateKey.java DELETED --- --- UserPrivateKey.java DELETED --- --- TolvenPublicKey.java DELETED --- --- TolvenEncryptedSecretKey.java DELETED --- |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:43
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/auth In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/org/tolven/security/auth Modified Files: KeyLdapLoginModule.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. Index: KeyLdapLoginModule.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/security/auth/KeyLdapLoginModule.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** KeyLdapLoginModule.java 25 Dec 2006 01:43:24 -0000 1.3 --- KeyLdapLoginModule.java 25 Dec 2006 06:34:40 -0000 1.4 *************** *** 22,26 **** import org.jboss.security.auth.spi.LdapLoginModule; import org.tolven.core.entity.TolvenUser; ! import org.tolven.security.bean.UserPrivateKey; import org.tolven.security.LoginLocal; --- 22,26 ---- import org.jboss.security.auth.spi.LdapLoginModule; import org.tolven.core.entity.TolvenUser; ! import org.tolven.security.key.UserPrivateKey; import org.tolven.security.LoginLocal; |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:43
|
Update of /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28808/src/test/org/tolven/security/bean Removed Files: AccountPrivateKeyTestCase.java DocumentSecretKeyTestCase.java AccountSecretKeyTestCase.java SecurityTestSuite.java DocumentEncryptionTestCase.java UserPrivateKeyTestCase.java TolvenPublicKeyTestCase.java TestCaseDocument.java Log Message: Moved the keys from the bean package to a key package, and took care of all references. --- AccountSecretKeyTestCase.java DELETED --- --- UserPrivateKeyTestCase.java DELETED --- --- TolvenPublicKeyTestCase.java DELETED --- --- DocumentEncryptionTestCase.java DELETED --- --- DocumentSecretKeyTestCase.java DELETED --- --- AccountPrivateKeyTestCase.java DELETED --- --- TestCaseDocument.java DELETED --- --- SecurityTestSuite.java DELETED --- |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:34
|
Update of /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/key In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28790/src/test/org/tolven/security/key Log Message: Directory /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/key added to the repository |
From: Joseph I. <jos...@us...> - 2006-12-25 06:34:34
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/key In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv28790/src/org/tolven/security/key Log Message: Directory /cvsroot/tolven/tolvenEJB/src/org/tolven/security/key added to the repository |
From: Joseph I. <jos...@us...> - 2006-12-25 01:43:29
|
Update of /cvsroot/tolven/tolvenWEB/src/org/tolven/web In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8645/src/org/tolven/web Modified Files: TopAction.java RegisterAction.java Log Message: PasswordCredential and UserPrivateKey are added to the Subject by the KeyLoginModule. TopAction no longer has code related to adding credentials to the Subject and has been returned to its cvs revision 1.22. AccountDAOBean now using the UserPrivateKey retrieved from the Subject to encrypt the AccountPrivateKey. Index: TopAction.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/TopAction.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** TopAction.java 22 Dec 2006 06:40:31 -0000 1.24 --- TopAction.java 25 Dec 2006 01:43:28 -0000 1.25 *************** *** 15,20 **** import java.io.IOException; - import java.security.GeneralSecurityException; - import java.security.PublicKey; import java.util.Collection; import java.util.LinkedList; --- 15,18 ---- *************** *** 28,35 **** import javax.naming.InitialContext; import javax.naming.NamingException; - import javax.resource.spi.security.PasswordCredential; - import javax.security.auth.Subject; - import javax.security.jacc.PolicyContext; - import javax.security.jacc.PolicyContextException; import javax.servlet.http.HttpSession; --- 26,29 ---- *************** *** 44,48 **** import org.tolven.security.TolvenPerson; import org.tolven.security.bean.LDAPLocal; - import org.tolven.security.bean.UserPrivateKey; /** --- 38,41 ---- *************** *** 187,191 **** return dispatchingLogout("missingUserObject"); } - if (!getUser().hasUserPrivateKey() && System.getProperty("tolven.security.keys.activate") != null) initUserPrivateKey(); accountUserId = getRequestParameterAsLong( "accountUserId" ); // Otherwise, we dispatch based on the defaultAccount or the one the user selected. --- 180,183 ---- *************** *** 235,258 **** } - /** - * Initialize the user's PrivateKey, using the PasswordCredential retrieved from the Subject in the PolicyContext - * @throws PolicyContextException - * @throws GeneralSecurityException - * @throws IOException - */ - private void initUserPrivateKey() throws PolicyContextException, GeneralSecurityException, IOException { - Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); - if (subject == null) - throw new IllegalStateException("No Subject found in PolicyContext"); - PasswordCredential passwordCredential = null; - for (java.util.Iterator iter = subject.getPrivateCredentials().iterator(); iter.hasNext();) { - // TODO: Assume only one PrivateCredential for the current logged in user - passwordCredential = (PasswordCredential) iter.next(); - } - if (passwordCredential == null) - throw new IllegalStateException("No PasswordCredential found in Subject"); - getUser().initUserPrivateKey(passwordCredential.getPassword()); - } - public String logout(){ return dispatchingLogout("loggedOut"); --- 227,230 ---- Index: RegisterAction.java =================================================================== RCS file: /cvsroot/tolven/tolvenWEB/src/org/tolven/web/RegisterAction.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** RegisterAction.java 9 Dec 2006 11:16:27 -0000 1.26 --- RegisterAction.java 25 Dec 2006 01:43:28 -0000 1.27 *************** *** 608,612 **** return "fail"; } ! AccountUser accountUser = accountBean.inviteAccountUser(getAccount(), user, getNow(), false ); FacesContext.getCurrentInstance().addMessage( "accountAdmin:uid", new FacesMessage("Demo user " + uid + " added, id: " + accountUser.getUser().getId())); // force a refresh of the list --- 608,612 ---- return "fail"; } ! AccountUser accountUser = accountBean.inviteAccountUser(getAccount(), activation.findAccountUser(getTop().getAccountUserId()), user, getNow(), false ); FacesContext.getCurrentInstance().addMessage( "accountAdmin:uid", new FacesMessage("Demo user " + uid + " added, id: " + accountUser.getUser().getId())); // force a refresh of the list |
From: Joseph I. <jos...@us...> - 2006-12-25 01:43:27
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8615/src/org/tolven/security Added Files: LoginLocal.java Log Message: PasswordCredential and UserPrivateKey are added to the Subject by the KeyLoginModule. TopAction no longer has code related to adding credentials to the Subject and has been returned to its cvs revision 1.22. AccountDAOBean now using the UserPrivateKey retrieved from the Subject to encrypt the AccountPrivateKey. --- NEW FILE: LoginLocal.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security; import org.tolven.core.entity.TolvenUser; /** * This is the business interface for LoginBean. * * @author Joseph Isaac */ public interface LoginLocal { /** * Find an account given the account id. * @param accountId * @return the account object */ public TolvenUser findUser(String aPrincipal); /** * Persist the user * @param aTolvenUser */ public void update(TolvenUser aTolvenUser); } |
From: Joseph I. <jos...@us...> - 2006-12-25 01:43:27
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8615/src/org/tolven/security/bean Added Files: LoginBean.java Log Message: PasswordCredential and UserPrivateKey are added to the Subject by the KeyLoginModule. TopAction no longer has code related to adding credentials to the Subject and has been returned to its cvs revision 1.22. AccountDAOBean now using the UserPrivateKey retrieved from the Subject to encrypt the AccountPrivateKey. --- NEW FILE: LoginBean.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package org.tolven.security.bean; import java.util.List; import javax.ejb.Local; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import org.tolven.core.entity.Status; import org.tolven.core.entity.TolvenUser; import org.tolven.security.LoginLocal; /** * This class is used by LoginModules to authenticate and determine the authorization of a user * * @author Joseph Isaac */ @Stateless() @Local(LoginLocal.class) public class LoginBean { @PersistenceContext private EntityManager em; /** * Return a TolvenUser given aPrincipal * @param aPrincipal * @return */ public TolvenUser findUser(String aPrincipal) { //Support both types of active status; String activeStatus = Status.fromValue("active").value(); String oldActiveStatus = Status.fromValue("ACTIVE").value(); //Activating should be replaced by New String activatingStatus = Status.fromValue("ACTIVATING").value(); String newStatus = Status.fromValue("new").value(); String select = "SELECT DISTINCT u FROM TolvenUser u WHERE u.ldapUID = :principal " + "and ( u.status = '"; select += oldActiveStatus + "' or u.status = '" + activeStatus + "' or u.status = '" + newStatus + "' or u.status = '" + activatingStatus + "') "; Query query = em.createQuery(select); query.setParameter("principal", aPrincipal.toLowerCase()); query.setMaxResults(2); List<TolvenUser> items = query.getResultList(); if (items.size() != 1) return null; return items.get(0); } /** * Persist aTolvenUser * @param aTolvenUser */ public void update(TolvenUser aTolvenUser) { em.merge(aTolvenUser); } } |
From: Joseph I. <jos...@us...> - 2006-12-25 01:43:26
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/auth In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8615/src/org/tolven/security/auth Modified Files: KeyLdapLoginModule.java Log Message: PasswordCredential and UserPrivateKey are added to the Subject by the KeyLoginModule. TopAction no longer has code related to adding credentials to the Subject and has been returned to its cvs revision 1.22. AccountDAOBean now using the UserPrivateKey retrieved from the Subject to encrypt the AccountPrivateKey. Index: KeyLdapLoginModule.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/security/auth/KeyLdapLoginModule.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KeyLdapLoginModule.java 17 Dec 2006 07:21:33 -0000 1.2 --- KeyLdapLoginModule.java 25 Dec 2006 01:43:24 -0000 1.3 *************** *** 14,21 **** --- 14,27 ---- package org.tolven.security.auth; + import javax.naming.InitialContext; import javax.resource.spi.security.PasswordCredential; import java.security.Principal; + import javax.security.auth.login.LoginException; + import org.jboss.security.auth.spi.LdapLoginModule; + import org.tolven.core.entity.TolvenUser; + import org.tolven.security.bean.UserPrivateKey; + import org.tolven.security.LoginLocal; /** *************** *** 29,49 **** private transient PasswordCredential passwordCredential; /** ! * If the LdapLoginModule superclass validates the inputPassword as true, ! * then create a PasswordCredential and keep it for commit. */ protected boolean validatePassword(String inputPassword, String expectedPassword) { boolean validated = super.validatePassword(inputPassword, expectedPassword); if (validated) { ! log.trace("adding password credentials"); ! char[] password = null; ! if (inputPassword != null) ! password = inputPassword.toCharArray(); ! Principal identity = getIdentity(); ! String userName = null; ! if (identity != null) ! userName = identity.getName(); ! passwordCredential = new PasswordCredential(userName, password); } return validated; --- 35,71 ---- private transient PasswordCredential passwordCredential; + private transient LoginLocal loginLocal; + private transient TolvenUser user; /** ! * If the LdapLoginModule superclass validates the inputPassword as true, then create a PasswordCredential ! * and finds the TolvenUser via the pricipal and keeps both for commit phase. */ protected boolean validatePassword(String inputPassword, String expectedPassword) { + System.out.println(getClass() + ": validatePassword"); boolean validated = super.validatePassword(inputPassword, expectedPassword); if (validated) { ! try { ! if (System.getProperty("tolven.security.keys.activate") != null) { ! char[] password = null; ! if (inputPassword != null) ! password = inputPassword.toCharArray(); ! Principal principal = getIdentity(); ! String principalUserName = null; ! if (principal != null) ! principalUserName = principal.getName(); ! passwordCredential = new PasswordCredential(principalUserName, password); ! InitialContext ictx = new InitialContext(); ! loginLocal = (LoginLocal) ictx.lookup("tolven/LoginBean/local"); ! user = loginLocal.findUser(principalUserName); ! if (user == null) { ! System.out.println(getClass() + ": user == null "); ! return false; ! } ! } ! } catch (Exception ex) { ! ex.printStackTrace(); ! return false; ! } } return validated; *************** *** 51,62 **** /** ! * If the superclass commits, then place the passwordCredential in the ! * Subject PrivateCredentials */ public boolean commit() throws LoginException { boolean committed = super.commit(); ! if (committed) { ! log.trace("password credentials will be committed"); ! subject.getPrivateCredentials().add(passwordCredential); } return committed; --- 73,104 ---- /** ! * If the superclass commits, then place the PasswordCredential, UserPrivateKey and PublicKey in the Subject */ public boolean commit() throws LoginException { + System.out.println(getClass() + ": commit"); boolean committed = super.commit(); ! if (committed && System.getProperty("tolven.security.keys.activate") != null) { ! try { ! boolean newKeys = !user.hasUserPrivateKey(); ! if (newKeys) { ! System.out.println(getClass() + ": initialize keys "); ! user.initUserPrivateKey(passwordCredential.getPassword()); ! } ! UserPrivateKey userPrivateKey = user.getUserPrivateKey(); ! System.out.println(getClass() + ": Adding UserPrivateKey to Subject " + user.getLdapUID()); ! userPrivateKey.unlockPrivateKey(passwordCredential.getPassword()); ! subject.getPrivateCredentials().add(userPrivateKey); ! System.out.println(getClass() + ": Adding PublicKey to Subject " + user.getLdapUID()); ! subject.getPublicCredentials().add(user.getPublicKey()); ! System.out.println(getClass() + ": Adding PasswordCredential to Subject " + user.getLdapUID()); ! subject.getPrivateCredentials().add(passwordCredential); ! if (newKeys) { ! loginLocal.update(user); ! System.out.println(getClass() + ": persisted new keys user " + user.getLdapUID()); ! } ! } catch (Exception ex) { ! ex.printStackTrace(); ! throw new LoginException(ex.getMessage()); ! } } return committed; *************** *** 64,77 **** /** ! * If the superclass aborts, ensure that the passwordCredential is removed ! * from the Subject */ public boolean abort() throws LoginException { boolean aborted = super.abort(); ! if (aborted) { ! log.trace("password credentials aborted"); ! subject.getPrivateCredentials().remove(passwordCredential); } passwordCredential = null; return aborted; } --- 106,128 ---- /** ! * If the superclass aborts, ensure that the PasswordCredential and UserPrivateKey and PublicKey are removed from the Subject */ public boolean abort() throws LoginException { boolean aborted = super.abort(); ! if (aborted && System.getProperty("tolven.security.keys.activate") != null) { ! try { ! subject.getPrivateCredentials().remove(passwordCredential); ! if (user != null) { ! subject.getPrivateCredentials().remove(user.getUserPrivateKey()); ! subject.getPublicCredentials().remove(user.getPublicKey()); ! } ! } catch (Exception ex) { ! ex.printStackTrace(); ! throw new LoginException(ex.getMessage()); ! } } passwordCredential = null; + user = null; + loginLocal = null; return aborted; } |
From: Joseph I. <jos...@us...> - 2006-12-25 01:43:26
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/core In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8615/src/org/tolven/core Modified Files: AccountDAOLocal.java Log Message: PasswordCredential and UserPrivateKey are added to the Subject by the KeyLoginModule. TopAction no longer has code related to adding credentials to the Subject and has been returned to its cvs revision 1.22. AccountDAOBean now using the UserPrivateKey retrieved from the Subject to encrypt the AccountPrivateKey. Index: AccountDAOLocal.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/AccountDAOLocal.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** AccountDAOLocal.java 9 Dec 2006 11:16:23 -0000 1.9 --- AccountDAOLocal.java 25 Dec 2006 01:43:24 -0000 1.10 *************** *** 75,79 **** * @see ActivationBean */ ! public AccountUser inviteAccountUser(Account account, TolvenUser user, Date now, boolean accountPermission ); /** --- 75,79 ---- * @see ActivationBean */ ! public AccountUser inviteAccountUser(Account account, AccountUser accountUser, TolvenUser invidtedUser, Date now, boolean accountPermission ); /** |
From: Joseph I. <jos...@us...> - 2006-12-25 01:43:25
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/core/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8615/src/org/tolven/core/bean Modified Files: AccountDAOBean.java Log Message: PasswordCredential and UserPrivateKey are added to the Subject by the KeyLoginModule. TopAction no longer has code related to adding credentials to the Subject and has been returned to its cvs revision 1.22. AccountDAOBean now using the UserPrivateKey retrieved from the Subject to encrypt the AccountPrivateKey. Index: AccountDAOBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/core/bean/AccountDAOBean.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AccountDAOBean.java 22 Dec 2006 06:40:25 -0000 1.13 --- AccountDAOBean.java 25 Dec 2006 01:43:23 -0000 1.14 *************** *** 158,217 **** * Associate a user with an account by invitation * @param account The existing (although possibly very recent) Account object ! * @param user the existing (although possibly very recent) TolvenUser object * @param now Transactional "now" time * @param accountPermission boolean indicating if this user has account administration permission */ ! public AccountUser inviteAccountUser(Account account, TolvenUser user, Date now, boolean accountPermission) { if (System.getProperty("tolven.security.keys.activate") != null) { try { // TODO: The correct location of the creation of an Invitation is still to be determined. It is created ! // here, to simulate that but is not persisted ! TolvenUser loggedInUser = findUser(ejbContext.getCallerPrincipal().getName()); ! unlockUserPrivateKey(loggedInUser); ! // Not sure if this is the most efficient what to find the AccountUser of the logged in user ! Set<AccountUser> accountUsers = account.getAccountUsers(); ! AccountUser loggedInAccountUser = null; ! for (Iterator<AccountUser> iter = accountUsers.iterator(); iter.hasNext();) { ! loggedInAccountUser = iter.next(); ! if (loggedInAccountUser.getUser().getLdapUID().equals(loggedInUser.getLdapUID())) ! break; } ! if (loggedInAccountUser == null) ! throw new RuntimeException("No authorization to add users to this account"); ! AccountPrivateKey loggedInAccountPrivateKey = loggedInAccountUser.getAccountPrivateKey(); AccountPrivateKey invitedAccountPrivateKey = AccountPrivateKey.getInstance(); ! invitedAccountPrivateKey.init(loggedInAccountPrivateKey, loggedInUser.getUserPrivateKey(), user.getPublicKey()); ! Invitation invitation = new Invitation(); invitation.setStatus(Status.INACTIVE.value()); invitation.setAccountPrivateKey(invitedAccountPrivateKey); ! return addAccountUser(account, user, invitation, now, accountPermission); } catch (Exception ex) { //TODO: consider declaring exceptions in the method declaration ! throw new RuntimeException(getClass() + ": Debug info: Problem with inviteAccountUser - " + ex.getMessage()); } } else { ! return addAccountUser(account, user, null, now, accountPermission); ! } ! } ! ! /** ! * Unlock the PrivateKey of the TolvenUser currently logged in, using the PasswordCredential retrieved from the Subject in the PolicyContext ! * @param loggedInUser ! * @throws PolicyContextException ! * @throws GeneralSecurityException ! * @throws IOException ! */ ! private void unlockUserPrivateKey(TolvenUser loggedInUser) throws PolicyContextException, GeneralSecurityException, IOException { ! Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); ! if (subject == null) ! throw new IllegalStateException("No Subject found in PolicyContext"); ! PasswordCredential passwordCredential = null; ! for (java.util.Iterator iter = subject.getPrivateCredentials().iterator(); iter.hasNext();) { ! // TOOD: Assume one and only PrivateCredential for the current logged in user ! passwordCredential = (PasswordCredential) iter.next(); } - if (passwordCredential == null) - throw new IllegalStateException("No PasswordCredential found in Subject"); - loggedInUser.getUserPrivateKey().unlockPrivateKey(passwordCredential.getPassword()); } --- 158,204 ---- * Associate a user with an account by invitation * @param account The existing (although possibly very recent) Account object ! * @param inviterAccountUser The AccountUser of the inviter ! * @param invitedUser the existing (although possibly very recent) TolvenUser object * @param now Transactional "now" time * @param accountPermission boolean indicating if this user has account administration permission */ ! public AccountUser inviteAccountUser(Account account, AccountUser inviterAccountUser, TolvenUser invitedUser, Date now, boolean accountPermission) { if (System.getProperty("tolven.security.keys.activate") != null) { try { + if (invitedUser.getPublicKey() == null) { + throw new RuntimeException(": Invited user " + ejbContext.getCallerPrincipal() + " has no PublicKey to protect the AccountPrivateKey"); + } // TODO: The correct location of the creation of an Invitation is still to be determined. It is created ! // here, for demo purposes, but is not persisted ! Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); ! if (subject == null) ! throw new IllegalStateException("No Subject found in PolicyContext for " + ejbContext.getCallerPrincipal()); ! UserPrivateKey inviterPrivateKey = null; ! Object obj = null; ! for (java.util.Iterator iter = subject.getPrivateCredentials().iterator(); iter.hasNext();) { ! obj = iter.next(); ! if (obj instanceof UserPrivateKey) { ! inviterPrivateKey = (UserPrivateKey) obj; ! } } ! if (inviterPrivateKey == null) ! throw new RuntimeException(": No UserPrivateKey found for " + ejbContext.getCallerPrincipal()); ! AccountPrivateKey inviterAccountPrivateKey = inviterAccountUser.getAccountPrivateKey(); ! if (inviterAccountPrivateKey == null) ! throw new RuntimeException(": No AccountPrivateKey found for " + ejbContext.getCallerPrincipal()); ! Invitation invitation = null; AccountPrivateKey invitedAccountPrivateKey = AccountPrivateKey.getInstance(); ! invitedAccountPrivateKey.init(inviterAccountPrivateKey, inviterPrivateKey, invitedUser.getPublicKey()); ! invitation = new Invitation(); invitation.setStatus(Status.INACTIVE.value()); invitation.setAccountPrivateKey(invitedAccountPrivateKey); ! return addAccountUser(account, invitedUser, invitation, now, accountPermission); } catch (Exception ex) { //TODO: consider declaring exceptions in the method declaration ! throw new RuntimeException(getClass() + ": Problem with inviteAccountUser for " + ejbContext.getCallerPrincipal() + " CAUSE: " + ex.getMessage()); } } else { ! return addAccountUser(account, invitedUser, null, now, accountPermission); } } *************** *** 259,272 **** accountUser.setAccountPrivateKey(invitation.getAccountPrivateKey()); } else { ! AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); ! TolvenUser loggedInUser = findUser(ejbContext.getCallerPrincipal().getName()); ! PublicKey accountPublicKey = accountPrivateKey.init(loggedInUser.getPublicKey()); ! account.setPublicKey(accountPublicKey); ! accountUser.setAccountPrivateKey(accountPrivateKey); } } catch (Exception ex) { // TODO: Do nothing but note the fact during development of // encryption keys ! System.out.println(getClass() + ": Debug info: Problem while setting up Account Keys - " + ex.getMessage()); } } --- 246,275 ---- accountUser.setAccountPrivateKey(invitation.getAccountPrivateKey()); } else { ! Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container"); ! if (subject == null) ! throw new IllegalStateException("No Subject found in PolicyContext for " + ejbContext.getCallerPrincipal()); ! PublicKey userPublicKey = null; ! Object obj = null; ! for (java.util.Iterator iter = subject.getPublicCredentials().iterator(); iter.hasNext();) { ! // TODO: Assume one and only PublicKey for the current logged in user, and give this key a type ! obj = iter.next(); ! if (obj instanceof PublicKey) { ! userPublicKey = (PublicKey) obj; ! break; ! } ! } ! if (userPublicKey == null) { ! System.out.println(getClass() + ": Debug info: No PublicKey found for " + ejbContext.getCallerPrincipal()); ! } else { ! AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); ! PublicKey accountPublicKey = accountPrivateKey.init(userPublicKey); ! account.setPublicKey(accountPublicKey); ! accountUser.setAccountPrivateKey(accountPrivateKey); ! } } } catch (Exception ex) { // TODO: Do nothing but note the fact during development of // encryption keys ! System.out.println(getClass() + ": Debug info: Problem while setting up Account Keys for " + ejbContext.getCallerPrincipal() + " CAUSE: " + ex.getMessage()); } } |
From: Joseph I. <jos...@us...> - 2006-12-23 22:52:33
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23885/src/org/tolven/doc/bean Modified Files: DocumentBean.java Log Message: Centralized the access for creation of document Index: DocumentBean.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/bean/DocumentBean.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** DocumentBean.java 16 Oct 2006 08:58:32 -0000 1.10 --- DocumentBean.java 23 Dec 2006 22:52:32 -0000 1.11 *************** *** 55,59 **** */ @Stateless() ! @Local(DocumentLocal.class) public class DocumentBean implements DocumentLocal { --- 55,59 ---- */ @Stateless() ! @Local(DocumentLocal.class) public class DocumentBean implements DocumentLocal { *************** *** 98,102 **** doc.setAuthor(em.getReference( TolvenUser.class, userId )); doc.setAccount(em.getReference( Account.class, accountId )); ! em.persist( doc ); String oid = propertyBean.getProperties().getProperty("tolven.repository.oid"); doc.createCCR(oid); --- 98,102 ---- doc.setAuthor(em.getReference( TolvenUser.class, userId )); doc.setAccount(em.getReference( Account.class, accountId )); ! createDocument( doc ); String oid = propertyBean.getProperties().getProperty("tolven.repository.oid"); doc.createCCR(oid); *************** *** 125,130 **** public long createDocument( DocBase doc, long userId ) { doc.setAuthor(em.getReference( TolvenUser.class, userId )); ! em.persist( doc ); ! return doc.getId(); } --- 125,129 ---- public long createDocument( DocBase doc, long userId ) { doc.setAuthor(em.getReference( TolvenUser.class, userId )); ! return createDocument( doc ); } *************** *** 205,210 **** public long createImage( DocImage doc, long accountId ) { doc.setAccount(em.getReference( Account.class, accountId )); ! em.persist( doc ); ! return doc.getId(); } --- 204,208 ---- public long createImage( DocImage doc, long accountId ) { doc.setAccount(em.getReference( Account.class, accountId )); ! return createDocument( doc ); } |
From: Joseph I. <jos...@us...> - 2006-12-23 21:24:10
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv21867/src/org/tolven/doc/entity Modified Files: DocBase.java Log Message: Centralized the access to the content instance variable Index: DocBase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/doc/entity/DocBase.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DocBase.java 28 Sep 2006 19:06:01 -0000 1.7 --- DocBase.java 23 Dec 2006 21:24:08 -0000 1.8 *************** *** 150,154 **** public String getContentString() { if (getContent()==null) return null; ! return new String(content); } public void setContent(byte[] content) { --- 150,154 ---- public String getContentString() { if (getContent()==null) return null; ! return new String(getContent()); } public void setContent(byte[] content) { *************** *** 157,161 **** public void setContentString(String content) { ! this.content = content.getBytes(); } /** --- 157,161 ---- public void setContentString(String content) { ! setContent(content.getBytes()); } /** *************** *** 163,167 **** */ public String getContentB64() { ! return new String(Base64.encodeBase64(content)); } --- 163,167 ---- */ public String getContentB64() { ! return new String(Base64.encodeBase64(getContent())); } *************** *** 170,174 **** */ public void setContentB64(String content) { ! this.content = Base64.decodeBase64(content.getBytes()); } --- 170,174 ---- */ public void setContentB64(String content) { ! setContent(Base64.decodeBase64(content.getBytes())); } |
From: Joseph I. <jos...@us...> - 2006-12-23 11:19:03
|
Update of /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv6134/src/test/org/tolven/security/bean Modified Files: TestCaseDocument.java Log Message: renamed instance variable from encryptedDocument to encryptedContent Index: TestCaseDocument.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/TestCaseDocument.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TestCaseDocument.java 22 Dec 2006 08:44:30 -0000 1.1 --- TestCaseDocument.java 23 Dec 2006 11:19:00 -0000 1.2 *************** *** 31,35 **** public static final String DOC_SIGNATURE_ALGORITHM_PROP = "tolven.security.doc.signatureAlgorithm"; ! private byte[] encryptedDocument; private DocumentSecretKey documentSecretKey; private byte[] signature; --- 31,35 ---- public static final String DOC_SIGNATURE_ALGORITHM_PROP = "tolven.security.doc.signatureAlgorithm"; ! private byte[] encryptedContent; private DocumentSecretKey documentSecretKey; private byte[] signature; *************** *** 57,61 **** documentSecretKey = DocumentSecretKey.getInstance(); SecretKey docSecretKey = documentSecretKey.init(anEncryptionKey); ! encryptedDocument = createEncryptedDocument(plainText, docSecretKey); } --- 57,61 ---- documentSecretKey = DocumentSecretKey.getInstance(); SecretKey docSecretKey = documentSecretKey.init(anEncryptionKey); ! encryptedContent = createEncryptedContent(plainText, docSecretKey); } *************** *** 65,70 **** * @return */ ! private byte[] getEncryptedDocument() { ! return encryptedDocument; } --- 65,70 ---- * @return */ ! private byte[] getEncryptedContent() { ! return encryptedContent; } *************** *** 107,111 **** Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, docSecretKey); ! return cipher.doFinal(getEncryptedDocument()); } --- 107,111 ---- Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, docSecretKey); ! return cipher.doFinal(getEncryptedContent()); } *************** *** 118,122 **** * @throws Exception */ ! private byte[] createEncryptedDocument(byte[] plainText, SecretKey aSecretKey) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance(aSecretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, aSecretKey); --- 118,122 ---- * @throws Exception */ ! private byte[] createEncryptedContent(byte[] plainText, SecretKey aSecretKey) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance(aSecretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, aSecretKey); |
From: Joseph I. <jos...@us...> - 2006-12-22 08:44:32
|
Update of /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv6062/src/test/org/tolven/security/bean Modified Files: AccountPrivateKeyTestCase.java SecurityTestSuite.java UserPrivateKeyTestCase.java TolvenPublicKeyTestCase.java AccountSecretKeyTestCase.java DocumentSecretKeyTestCase.java Added Files: DocumentEncryptionTestCase.java TestCaseDocument.java Log Message: Added test cases for document encryption, decryption and signatures Index: AccountSecretKeyTestCase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/AccountSecretKeyTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AccountSecretKeyTestCase.java 9 Dec 2006 11:16:22 -0000 1.3 --- AccountSecretKeyTestCase.java 22 Dec 2006 08:44:30 -0000 1.4 *************** *** 1,2 **** --- 1,16 ---- + /* + * Copyright (C) 2006 Tolven Inc + * + * This library is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * Contact: in...@to... + */ + package test.org.tolven.security.bean; *************** *** 5,9 **** import java.security.PublicKey; import java.security.PrivateKey; - import org.tolven.security.bean.TolvenPublicKey; import junit.framework.TestCase; --- 19,22 ---- *************** *** 13,16 **** --- 26,35 ---- import org.tolven.security.bean.UserPrivateKey; + /** + * This class is used to testing AccountSecretKey. + * + * @author Joseph Isaac + * + */ public class AccountSecretKeyTestCase extends TestCase { *************** *** 20,24 **** */ public void testGetSecretKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 39,43 ---- */ public void testGetSecretKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); *************** *** 46,50 **** */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 65,69 ---- */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); Index: UserPrivateKeyTestCase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/UserPrivateKeyTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** UserPrivateKeyTestCase.java 5 Dec 2006 08:34:22 -0000 1.3 --- UserPrivateKeyTestCase.java 22 Dec 2006 08:44:30 -0000 1.4 *************** *** 1,2 **** --- 1,16 ---- + /* + * Copyright (C) 2006 Tolven Inc + * + * This library is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * Contact: in...@to... + */ + package test.org.tolven.security.bean; *************** *** 13,35 **** import junit.framework.TestCase; public class UserPrivateKeyTestCase extends TestCase { - public static void initProperties() { - System.setProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP, "RSA"); - System.setProperty(UserPrivateKey.USER_PRIVATE_KEY_LENGTH_PROP, "1024"); - System.setProperty(UserPrivateKey.PBE_KEY_ALGORITHM_PROP, "PBEWithMD5AndDES"); - System.setProperty(UserPrivateKey.USER_PASSWORD_SALT_LENGTH_PROP, "8"); - System.setProperty(UserPrivateKey.USER_PASSWORD_ITERATION_COUNT_PROP, "20"); - - System.setProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP, "RSA"); - System.setProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_LENGTH_PROP, "1024"); - - System.setProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_ALGORITHM_PROP, "DESede"); - System.setProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_LENGTH, "112"); - - System.setProperty(DocumentSecretKey.DOC_KBE_KEY_ALGORITHM_PROP, "DESede"); - System.setProperty(DocumentSecretKey.DOC_KBE_KEY_LENGTH, "112"); - } - /* * Test method for 'org.tolven.security.bean.UserPrivateKey.getInstance()' --- 27,38 ---- import junit.framework.TestCase; + /** + * This class is used to testing UserPrivateKey. + * + * @author Joseph Isaac + * + */ public class UserPrivateKeyTestCase extends TestCase { /* * Test method for 'org.tolven.security.bean.UserPrivateKey.getInstance()' *************** *** 43,47 **** */ public void testInitCharArray() throws GeneralSecurityException, IOException { ! initProperties(); UserPrivateKey pbePrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 46,50 ---- */ public void testInitCharArray() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey pbePrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); *************** *** 55,59 **** */ public void testGetPrivateKey() throws GeneralSecurityException, IOException { ! initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 58,62 ---- */ public void testGetPrivateKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); *************** *** 68,72 **** */ public void testUnlockPrivateKey() throws GeneralSecurityException, IOException { ! initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 71,75 ---- */ public void testUnlockPrivateKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); Index: TolvenPublicKeyTestCase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/TolvenPublicKeyTestCase.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TolvenPublicKeyTestCase.java 5 Dec 2006 08:45:48 -0000 1.2 --- TolvenPublicKeyTestCase.java 22 Dec 2006 08:44:30 -0000 1.3 *************** *** 1,2 **** --- 1,16 ---- + /* + * Copyright (C) 2006 Tolven Inc + * + * This library is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * Contact: in...@to... + */ + package test.org.tolven.security.bean; *************** *** 8,11 **** --- 22,31 ---- import org.tolven.security.bean.UserPrivateKey; + /** + * This class is used to testing TolvenPublicKey. + * + * @author Joseph Isaac + * + */ public class TolvenPublicKeyTestCase extends TestCase { *************** *** 22,26 **** */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 42,46 ---- */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); *************** *** 34,38 **** */ public void testGetPublicKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 54,58 ---- */ public void testGetPublicKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- NEW FILE: DocumentEncryptionTestCase.java --- package test.org.tolven.security.bean; import java.io.IOException; import java.security.GeneralSecurityException; import java.security.PublicKey; import junit.framework.TestCase; import org.tolven.security.bean.AccountPrivateKey; import org.tolven.security.bean.UserPrivateKey; public class DocumentEncryptionTestCase extends TestCase { /* * Test method for 'test.org.tolven.security.bean.TestCaseDocument.init(byte[], PublicKey, PrivateKey, String)' */ public void testInit() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); byte[] unencryptedDocument = "The quick brown fox jumps over a lazy dog.".getBytes(); char[] password = "somepassword".toCharArray(); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); PublicKey tolvenUserPublicKey = userPrivateKey.init(password); PublicKey accountPublicKey = accountPrivateKey.init(tolvenUserPublicKey); TestCaseDocument testCaseDocument = new TestCaseDocument(); testCaseDocument.init(unencryptedDocument, accountPublicKey, userPrivateKey.getPrivateKey(password)); } /* * Test method for 'test.org.tolven.security.bean.TestCaseDocument.verify(PublicKey, PrivateKey)' */ public void testVerify() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); byte[] unencryptedDocument = "The quick brown fox jumps over a lazy dog.".getBytes(); char[] password = "somepassword".toCharArray(); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); PublicKey tolvenUserPublicKey = userPrivateKey.init(password); PublicKey accountPublicKey = accountPrivateKey.init(tolvenUserPublicKey); TestCaseDocument testCaseDocument = new TestCaseDocument(); testCaseDocument.init(unencryptedDocument, accountPublicKey, userPrivateKey.getPrivateKey(password)); boolean verified = testCaseDocument.verify(tolvenUserPublicKey, accountPrivateKey.getPrivateKey(userPrivateKey.getPrivateKey(password))); assertTrue(verified); } /* * Test method for 'test.org.tolven.security.bean.TestCaseDocument.decryptDocument(PrivateKey)' */ public void testDecryptDocument() throws GeneralSecurityException, IOException { SecurityTestSuite.initProperties(); byte[] unencryptedDocument = "The quick brown fox jumps over a lazy dog.".getBytes(); char[] password = "somepassword".toCharArray(); AccountPrivateKey accountPrivateKey = AccountPrivateKey.getInstance(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); PublicKey tolvenUserPublicKey = userPrivateKey.init(password); PublicKey accountPublicKey = accountPrivateKey.init(tolvenUserPublicKey); TestCaseDocument testCaseDocument = new TestCaseDocument(); testCaseDocument.init(unencryptedDocument, accountPublicKey, userPrivateKey.getPrivateKey(password)); byte[] decryptedDocument = testCaseDocument.decryptDocument(accountPrivateKey.getPrivateKey(userPrivateKey.getPrivateKey(password))); assertTrue(new String(unencryptedDocument).equals(new String(decryptedDocument))); } } Index: DocumentSecretKeyTestCase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/DocumentSecretKeyTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DocumentSecretKeyTestCase.java 9 Dec 2006 11:16:22 -0000 1.3 --- DocumentSecretKeyTestCase.java 22 Dec 2006 08:44:30 -0000 1.4 *************** *** 1,2 **** --- 1,16 ---- + /* + * Copyright (C) 2006 Tolven Inc + * + * This library is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * Contact: in...@to... + */ + package test.org.tolven.security.bean; *************** *** 11,16 **** import org.tolven.security.bean.AccountPrivateKey; import org.tolven.security.bean.UserPrivateKey; - import org.tolven.security.bean.TolvenPublicKey; public class DocumentSecretKeyTestCase extends TestCase { --- 25,35 ---- import org.tolven.security.bean.AccountPrivateKey; import org.tolven.security.bean.UserPrivateKey; + /** + * This class is used to testing DocumentSecretKey. + * + * @author Joseph Isaac + * + */ public class DocumentSecretKeyTestCase extends TestCase { *************** *** 20,24 **** */ public void testGetSecretKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 39,43 ---- */ public void testGetSecretKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); *************** *** 47,51 **** */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 66,70 ---- */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); Index: AccountPrivateKeyTestCase.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/AccountPrivateKeyTestCase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AccountPrivateKeyTestCase.java 9 Dec 2006 11:16:22 -0000 1.4 --- AccountPrivateKeyTestCase.java 22 Dec 2006 08:44:30 -0000 1.5 *************** *** 1,2 **** --- 1,15 ---- + /* + * Copyright (C) 2006 Tolven Inc + * + * This library is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * Contact: in...@to... + */ package test.org.tolven.security.bean; *************** *** 9,14 **** import org.tolven.security.bean.AccountPrivateKey; import org.tolven.security.bean.UserPrivateKey; - import org.tolven.security.bean.TolvenPublicKey; public class AccountPrivateKeyTestCase extends TestCase { --- 22,32 ---- import org.tolven.security.bean.AccountPrivateKey; import org.tolven.security.bean.UserPrivateKey; + /** + * This class is used to testing AccountPrivateKey. + * + * @author Joseph Isaac + * + */ public class AccountPrivateKeyTestCase extends TestCase { *************** *** 26,30 **** */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 44,48 ---- */ public void testInitPublicKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); *************** *** 41,45 **** public void testInitAccountPrivateKeyUserPrivateKeyPublicKey() throws GeneralSecurityException, IOException { //Create UserPrivateKey1 ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey theUserPrivateKey1 = UserPrivateKey.getInstance(); char[] password1 = "password1".toCharArray(); --- 59,63 ---- public void testInitAccountPrivateKeyUserPrivateKeyPublicKey() throws GeneralSecurityException, IOException { //Create UserPrivateKey1 ! SecurityTestSuite.initProperties(); UserPrivateKey theUserPrivateKey1 = UserPrivateKey.getInstance(); char[] password1 = "password1".toCharArray(); *************** *** 74,78 **** */ public void testGetPrivateKey() throws GeneralSecurityException, IOException { ! UserPrivateKeyTestCase.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- 92,96 ---- */ public void testGetPrivateKey() throws GeneralSecurityException, IOException { ! SecurityTestSuite.initProperties(); UserPrivateKey userPrivateKey = UserPrivateKey.getInstance(); char[] password = "password".toCharArray(); --- NEW FILE: TestCaseDocument.java --- /* * Copyright (C) 2006 Tolven Inc * * This library is free software; you can redistribute it and/or modify it under the terms of * the GNU Lesser General Public License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * Contact: in...@to... */ package test.org.tolven.security.bean; import javax.crypto.Cipher; import javax.crypto.SecretKey; import org.tolven.security.bean.DocumentSecretKey; import java.security.GeneralSecurityException; import java.security.PublicKey; import java.security.PrivateKey; import java.security.Signature; /** * This class is used to test document encryption, decryption and signature * * @author Joseph Isaac * */ public class TestCaseDocument { public static final String DOC_SIGNATURE_ALGORITHM_PROP = "tolven.security.doc.signatureAlgorithm"; private byte[] encryptedDocument; private DocumentSecretKey documentSecretKey; private byte[] signature; private String signatureAlgorithm; /** * Genrate a document signature for some plainText, using a document * signature algorithm, then encrypt the plainText using the document * encryption algorithm of a randomly generated SecretKey, and encrypt the * SecretKey with anEncryptionKey * * @param plainText * @param anEncryptionKey * @param aSignatureKey * @param aSignatureAlgorithm * @return * @throws GeneralSecurityException */ public void init(byte[] plainText, PublicKey anEncryptionKey, PrivateKey aSignatureKey) throws GeneralSecurityException { signatureAlgorithm = System.getProperty(DOC_SIGNATURE_ALGORITHM_PROP); Signature sig = Signature.getInstance(signatureAlgorithm); sig.initSign(aSignatureKey); sig.update(plainText); signature = sig.sign(); documentSecretKey = DocumentSecretKey.getInstance(); SecretKey docSecretKey = documentSecretKey.init(anEncryptionKey); encryptedDocument = createEncryptedDocument(plainText, docSecretKey); } /** * return an encrypted Document * * @return */ private byte[] getEncryptedDocument() { return encryptedDocument; } /** * Decrypt the SecretKey using aDecryptionKey * * @param aDecryptionKey * @return * @throws GeneralSecurityException */ private SecretKey getSecretKey(PrivateKey aDecryptionKey) throws GeneralSecurityException { return documentSecretKey.getSecretKey(aDecryptionKey); } /** * Verify the document signature belongs to aPublicKey using aDecryptionKey * to decrypt the document * * @param aPublicKey * @param aDecryptionKey * @return * @throws GeneralSecurityException */ public boolean verify(PublicKey aPublicKey, PrivateKey aDecryptionKey) throws GeneralSecurityException { Signature sig = Signature.getInstance(signatureAlgorithm); sig.initVerify(aPublicKey); sig.update(decryptDocument(aDecryptionKey)); return sig.verify(signature); } /** * Decrypt a Document using aDecryptionKey * * @param aDecryptionKey * @return * @throws GeneralSecurityException */ public byte[] decryptDocument(PrivateKey aDecryptionKey) throws GeneralSecurityException { SecretKey docSecretKey = getSecretKey(aDecryptionKey); Cipher cipher = Cipher.getInstance(docSecretKey.getAlgorithm()); cipher.init(Cipher.DECRYPT_MODE, docSecretKey); return cipher.doFinal(getEncryptedDocument()); } /** * Encrypt plainText with a SecretKey * * @param plainText * @param secretKey * @return * @throws Exception */ private byte[] createEncryptedDocument(byte[] plainText, SecretKey aSecretKey) throws GeneralSecurityException { Cipher cipher = Cipher.getInstance(aSecretKey.getAlgorithm()); cipher.init(Cipher.ENCRYPT_MODE, aSecretKey); return cipher.doFinal(plainText); } } Index: SecurityTestSuite.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/test/org/tolven/security/bean/SecurityTestSuite.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SecurityTestSuite.java 22 Dec 2006 06:50:03 -0000 1.1 --- SecurityTestSuite.java 22 Dec 2006 08:44:30 -0000 1.2 *************** *** 1,7 **** --- 1,32 ---- + /* + * Copyright (C) 2006 Tolven Inc + * + * This library is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 Lesser General Public License for more details. + * + * Contact: in...@to... + */ + package test.org.tolven.security.bean; + import org.tolven.security.bean.AccountPrivateKey; + import org.tolven.security.bean.AccountSecretKey; + import org.tolven.security.bean.DocumentSecretKey; + import org.tolven.security.bean.UserPrivateKey; + import junit.framework.Test; import junit.framework.TestSuite; + /** + * This class carries out testing for a number of security features. + * + * @author Joseph Isaac + * + */ public class SecurityTestSuite { *************** *** 14,20 **** --- 39,64 ---- suite.addTestSuite(AccountPrivateKeyTestCase.class); suite.addTestSuite(DocumentSecretKeyTestCase.class); + suite.addTestSuite(DocumentEncryptionTestCase.class); //$JUnit-END$ return suite; } + public static void initProperties() { + System.setProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP, "RSA"); + System.setProperty(UserPrivateKey.USER_PRIVATE_KEY_LENGTH_PROP, "1024"); + System.setProperty(UserPrivateKey.PBE_KEY_ALGORITHM_PROP, "PBEWithMD5AndDES"); + System.setProperty(UserPrivateKey.USER_PASSWORD_SALT_LENGTH_PROP, "8"); + System.setProperty(UserPrivateKey.USER_PASSWORD_ITERATION_COUNT_PROP, "20"); + + System.setProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_ALGORITHM_PROP, "RSA"); + System.setProperty(AccountPrivateKey.ACCOUNT_PRIVATE_KEY_LENGTH_PROP, "1024"); + + System.setProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_ALGORITHM_PROP, "DESede"); + System.setProperty(AccountSecretKey.ACCOUNT_USER_KBE_KEY_LENGTH, "112"); + + System.setProperty(DocumentSecretKey.DOC_KBE_KEY_ALGORITHM_PROP, "DESede"); + System.setProperty(DocumentSecretKey.DOC_KBE_KEY_LENGTH, "112"); + System.setProperty(TestCaseDocument.DOC_SIGNATURE_ALGORITHM_PROP, "SHA1withRSA"); + } + } |
From: Joseph I. <jos...@us...> - 2006-12-22 07:10:32
|
Update of /cvsroot/tolven/tolvenEJB/src/org/tolven/security/bean In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv32743/src/org/tolven/security/bean Modified Files: AccountPrivateKey.java UserPrivateKey.java TolvenEncryptedPrivateKey.java Log Message: Placed the PrivateKey algorithm name of TolvenEncryptedPrivateKey in the database, since having to decode the PrivateKey to get it was a little extreme. It now matches TolvenEncryptedSecretKey. Index: UserPrivateKey.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/security/bean/UserPrivateKey.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** UserPrivateKey.java 9 Dec 2006 11:16:23 -0000 1.6 --- UserPrivateKey.java 22 Dec 2006 07:10:30 -0000 1.7 *************** *** 139,143 **** byte[] encryptedPrivateKey = cipher.doFinal(keyPair.getPrivate().getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(aPrivateKeyAlgorithm, encryptedPrivateKey); ! setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo.getEncoded()); this.pbeKeyAlgorithm = aPBEKeyAlgorithm; this.salt = salt; --- 139,143 ---- byte[] encryptedPrivateKey = cipher.doFinal(keyPair.getPrivate().getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(aPrivateKeyAlgorithm, encryptedPrivateKey); ! setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo); this.pbeKeyAlgorithm = aPBEKeyAlgorithm; this.salt = salt; Index: AccountPrivateKey.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/security/bean/AccountPrivateKey.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AccountPrivateKey.java 9 Dec 2006 11:16:23 -0000 1.5 --- AccountPrivateKey.java 22 Dec 2006 07:10:30 -0000 1.6 *************** *** 97,101 **** byte[] encryptedPrivateKey = cipher.doFinal(privateKey.getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(privateKey.getAlgorithm(), encryptedPrivateKey); ! setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo.getEncoded()); } --- 97,101 ---- byte[] encryptedPrivateKey = cipher.doFinal(privateKey.getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(privateKey.getAlgorithm(), encryptedPrivateKey); ! setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo); } *************** *** 121,125 **** byte[] encryptedPrivateKey = cipher.doFinal(keyPair.getPrivate().getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(aPrivateKeyAlgorithm, encryptedPrivateKey); ! setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo.getEncoded()); return keyPair.getPublic(); } --- 121,125 ---- byte[] encryptedPrivateKey = cipher.doFinal(keyPair.getPrivate().getEncoded()); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(aPrivateKeyAlgorithm, encryptedPrivateKey); ! setEncodedEncryptedPrivateKeyInfo(encryptedPrivateKeyInfo); return keyPair.getPublic(); } Index: TolvenEncryptedPrivateKey.java =================================================================== RCS file: /cvsroot/tolven/tolvenEJB/src/org/tolven/security/bean/TolvenEncryptedPrivateKey.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TolvenEncryptedPrivateKey.java 4 Dec 2006 06:52:39 -0000 1.6 --- TolvenEncryptedPrivateKey.java 22 Dec 2006 07:10:30 -0000 1.7 *************** *** 14,17 **** --- 14,19 ---- package org.tolven.security.bean; + import javax.crypto.EncryptedPrivateKeyInfo; + import java.io.IOException; import javax.persistence.*; *************** *** 33,36 **** --- 35,41 ---- private int keySize; + @Column(name = "private_key_algorithm") + private String algorithm; + /** * Return the EncryptedPrivateKeyInfo *************** *** 45,52 **** * Set the EncryptedPrivateKeyInfo * * @param anEncryptedPrivateKeyInfo */ ! protected void setEncodedEncryptedPrivateKeyInfo(byte[] anEncodedEncryptedPrivateKeyInfo) { ! encodedEncryptedPrivateKeyInfo = anEncodedEncryptedPrivateKeyInfo; } --- 50,59 ---- * Set the EncryptedPrivateKeyInfo * + * @param privateKeyAlgorithm * @param anEncryptedPrivateKeyInfo */ ! protected void setEncodedEncryptedPrivateKeyInfo(EncryptedPrivateKeyInfo anEncryptedPrivateKeyInfo) throws IOException { ! algorithm = anEncryptedPrivateKeyInfo.getAlgName(); ! encodedEncryptedPrivateKeyInfo = anEncryptedPrivateKeyInfo.getEncoded(); } *************** *** 70,72 **** --- 77,97 ---- } + /** + * return the PrivateKey algorithm + * + * @return + */ + protected String getAlgorithm() { + return algorithm; + } + + /** + * Keep the PrivateKey algorithm. It it is part of an EncryptedPrivateKeyInfo but one has to decrypt to find out what it is + * + * @param aString + */ + protected void setAlgorithm(String aString) { + algorithm = aString; + } + } |