- Timestamp:
- 01/31/19 16:34:06 (5 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/auth/Actions.java
r1202 r1227 42 42 /** 43 43 * Display Expeditee Mail 44 */ 45 public static void MailMode() { 44 * @throws IOException 45 * @throws SQLException 46 * @throws ClassNotFoundException 47 * @throws CertificateException 48 * @throws NoSuchAlgorithmException 49 * @throws FileNotFoundException 50 * @throws KeyStoreException 51 */ 52 public static void MailMode() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException { 53 if (!DisplayController.isMailMode()) { 54 Mail.clear(); 55 Authenticator.getInstance().loadMailDatabase(); 56 } 46 57 DisplayController.ToggleMailMode(); 47 58 } … … 375 386 Frame frame = FrameIO.LoadFrame(profile.getFramesetName() + i); 376 387 frame.setOwner(username); 388 frame.setEncryptionLabel("Profile"); 377 389 Collection<Item> items = frame.getAllItems(); 378 390 for (Item item: items) { -
trunk/src/org/expeditee/auth/EncryptedExpReader.java
r1202 r1227 12 12 import java.util.Arrays; 13 13 import java.util.Base64; 14 import java.util.List;15 import java.util.stream.Collectors;16 14 17 15 import javax.crypto.BadPaddingException; … … 26 24 import org.expeditee.items.Text; 27 25 import org.expeditee.settings.auth.secrets.KeyList; 28 import org.ngikm.Util.ThrowingFunction;29 26 import org.ngikm.cryptography.CryptographyConstants; 27 28 import sun.reflect.generics.reflectiveObjects.NotImplementedException; 30 29 31 30 public class EncryptedExpReader extends ExpReader implements CryptographyConstants { 32 31 static final String ENCRYPTED_EXP_FLAG = "EncryptedExp"; 33 32 private SecretKey personalKey; 34 private List<SecretKey> multiKey;33 //private List<SecretKey> multiKey; 35 34 private boolean accessDenied = false; 36 private boolean usePersonalKey;37 38 public EncryptedExpReader(final String frameName , final boolean usePersonalKey) throws UnsupportedEncodingException {35 //private boolean usePersonalKey; 36 37 public EncryptedExpReader(final String frameName) throws UnsupportedEncodingException { 39 38 super(frameName); 40 this.usePersonalKey = usePersonalKey;41 39 } 42 40 … … 50 48 public int getVersionEnc(String fullpath) { 51 49 try { 52 BufferedReader reader ;53 if (usePersonalKey) {54 reader = new EncryptedProfileLineReader(new BufferedReader(new FileReader(fullpath)));55 } else {56 reader = new EncryptedLineReader(new BufferedReader(new FileReader(fullpath)));57 }50 BufferedReader reader = new EncryptedLineReader(new BufferedReader(new FileReader(fullpath))); 51 //if (usePersonalKey) { 52 // reader = new EncryptedProfileLineReader(new BufferedReader(new FileReader(fullpath))); 53 //} else { 54 // reader = new EncryptedLineReader(new BufferedReader(new FileReader(fullpath))); 55 //} 58 56 String next = ""; 59 57 // First read the header lines until we get the version number … … 76 74 @Override 77 75 public Frame readFrame(final String fullPath) throws IOException { 78 final Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8"); 79 if (usePersonalKey) { 80 return readFrame(new EncryptedProfileLineReader(new BufferedReader(in))); 81 } else { 82 return readFrame(new EncryptedLineReader(new BufferedReader(in))); 83 } 76 Reader in = new InputStreamReader(new FileInputStream(fullPath), "UTF-8"); 77 return readFrame(new EncryptedLineReader(in)); 78 //if (usePersonalKey) { 79 // return readFrame(new EncryptedProfileLineReader(new BufferedReader(in))); 80 //} else { 81 // return readFrame(new EncryptedLineReader(new BufferedReader(in))); 82 //} 84 83 } 85 84 … … 111 110 } 112 111 113 private class EncryptedProfileLineReader extends BufferedReader { 114 115 public EncryptedProfileLineReader(final Reader in) { 112 private class EncryptedLineReader extends BufferedReader { 113 public EncryptedLineReader(Reader in) { 116 114 super(in); 117 115 } … … 119 117 @Override 120 118 /** 121 * Reads a line from an encrypted exp file that uses profile encryption (single key; personal key)122 * Returns that line to process, null if the currently logged in users personal key is not the appropriate one(access denied).119 * Reads a line from an encrypted exp file that uses an encryption specified by the first line of the file. 120 * Returns that line to process, null if the currently logged in users doesn't own the appropriate key (access denied). 123 121 */ 124 122 public String readLine() throws IOException { 125 // read encrypted line 126 final String line = super.readLine(); 123 String line = super.readLine(); 127 124 128 if (line.isEmpty()) { return ""; } 125 if (line.isEmpty()) { 126 return ""; 127 } 129 128 if (line.startsWith(ENCRYPTED_EXP_FLAG)) { 130 // record/overwrite previous personal key then ignore this line by recursing 131 final Text text = KeyList.PersonalKey.get(); 132 final byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0)); 133 personalKey = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 134 return readLine(); 129 String label = line.replace(ENCRYPTED_EXP_FLAG, ""); 130 // if using Profile label, use personal key 131 if (label.startsWith("Profile")) { 132 Text text = KeyList.PersonalKey.get(); 133 byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0)); 134 personalKey = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 135 return readLine(); 136 } else { 137 // TODO: resolve encryption label, what does this mean? 138 personalKey = resolveLabel(label); 139 return readLine(); 140 } 135 141 } 136 142 137 143 // decrypt line and return result 138 finalbyte[] toDecrypt = Base64.getDecoder().decode(line);139 finalbyte[] decrypted = DecryptSymmetric(toDecrypt, personalKey);144 byte[] toDecrypt = Base64.getDecoder().decode(line); 145 byte[] decrypted = DecryptSymmetric(toDecrypt, personalKey); 140 146 if (decrypted == null) { 141 147 accessDenied = true; 142 148 return null; // access denied 143 149 } else { 144 finalString decryptedLine = new String(decrypted);145 if (decryptedLine.startsWith("Z")) { return decryptedLine.trim(); }146 else { return decryptedLine; }147 }148 }149 }150 151 private class EncryptedLineReader extends BufferedReader {150 String decryptedLine = new String(decrypted); 151 if (decryptedLine.startsWith("Z")) { 152 return decryptedLine.trim(); 153 } else { 154 return decryptedLine; 155 } 156 } 157 } 152 158 153 public EncryptedLineReader(final Reader in) { 154 super(in); 155 } 156 157 @Override 158 /** 159 * Reads a line from an encrypted exp file that uses (potentially multiple) labeled keys 160 * Returns that line to process, null if the ... 161 */ 162 public String readLine() throws IOException { 163 // read encrypted line 164 final String line = super.readLine(); 165 166 if (line.isEmpty()) { return ""; } 167 if (line.startsWith(ENCRYPTED_EXP_FLAG)) { 168 // resolve labels to secret keys 169 final List<String> labels = Arrays.asList(line.split(" ")).stream().skip(1).collect(Collectors.toList()); 170 final ThrowingFunction<String, SecretKey, Exception> worker = new ThrowingFunction<String, SecretKey, Exception>() { 171 @Override 172 public SecretKey applyThrows(final String label) throws Exception { 173 return Authenticator.getInstance().getSecretKey(label, System.getProperty("password")); 174 } 175 }; 176 multiKey = labels.stream().map(l -> { 177 try { 178 return worker.apply(l); 179 } catch (final Exception e) { 180 return null; 181 } 182 }).collect(Collectors.toList()); 183 184 // confirm you have all the keys necessary for decryption 185 if (multiKey.contains(null)) { 186 return null; 187 } 188 189 // move onto the next line 190 return readLine(); 191 } 192 193 // decrypt line and return result 194 final byte[] toDecrypt = Base64.getDecoder().decode(line); 195 byte[] decryptedBytes = null; 196 for (final SecretKey key: multiKey) { 197 decryptedBytes = DecryptSymmetric(toDecrypt, key); 198 if (decryptedBytes == null) { return null; } 199 } 200 final String decrypted = new String(decryptedBytes); 201 if (decrypted.startsWith("Z")) { return decrypted.trim(); } 202 else { return decrypted; } 203 } 204 } 159 private SecretKeySpec resolveLabel(String label) { 160 throw new NotImplementedException(); 161 } 162 } 163 164 // private class EncryptedProfileLineReader extends BufferedReader { 165 // 166 // public EncryptedProfileLineReader(final Reader in) { 167 // super(in); 168 // } 169 // 170 // @Override 171 // /** 172 // * Reads a line from an encrypted exp file that uses profile encryption (single key; personal key) 173 // * Returns that line to process, null if the currently logged in users personal key is not the appropriate one (access denied). 174 // */ 175 // public String readLine() throws IOException { 176 // // read encrypted line 177 // final String line = super.readLine(); 178 // 179 // if (line.isEmpty()) { return ""; } 180 // if (line.startsWith(ENCRYPTED_EXP_FLAG)) { 181 // // record/overwrite previous personal key then ignore this line by recursing 182 // final Text text = KeyList.PersonalKey.get(); 183 // final byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0)); 184 // personalKey = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 185 // return readLine(); 186 // } 187 // 188 // // decrypt line and return result 189 // final byte[] toDecrypt = Base64.getDecoder().decode(line); 190 // final byte[] decrypted = DecryptSymmetric(toDecrypt, personalKey); 191 // if (decrypted == null) { 192 // accessDenied = true; 193 // return null; // access denied 194 // } else { 195 // final String decryptedLine = new String(decrypted); 196 // if (decryptedLine.startsWith("Z")) { return decryptedLine.trim(); } 197 // else { return decryptedLine; } 198 // } 199 // } 200 // } 201 // 202 // private class EncryptedLineReader extends BufferedReader { 203 // 204 // public EncryptedLineReader(final Reader in) { 205 // super(in); 206 // } 207 // 208 // @Override 209 // /** 210 // * Reads a line from an encrypted exp file that uses (potentially multiple) labeled keys 211 // * Returns that line to process, null if the ... 212 // */ 213 // public String readLine() throws IOException { 214 // // read encrypted line 215 // final String line = super.readLine(); 216 // 217 // if (line.isEmpty()) { return ""; } 218 // if (line.startsWith(ENCRYPTED_EXP_FLAG)) { 219 // // resolve labels to secret keys 220 // final List<String> labels = Arrays.asList(line.split(" ")).stream().skip(1).collect(Collectors.toList()); 221 // final ThrowingFunction<String, SecretKey, Exception> worker = new ThrowingFunction<String, SecretKey, Exception>() { 222 // @Override 223 // public SecretKey applyThrows(final String label) throws Exception { 224 // return Authenticator.getInstance().getSecretKey(label, System.getProperty("password")); 225 // } 226 // }; 227 // multiKey = labels.stream().map(l -> { 228 // try { 229 // return worker.apply(l); 230 // } catch (final Exception e) { 231 // return null; 232 // } 233 // }).collect(Collectors.toList()); 234 // 235 // // confirm you have all the keys necessary for decryption 236 // if (multiKey.contains(null)) { 237 // return null; 238 // } 239 // 240 // // move onto the next line 241 // return readLine(); 242 // } 243 // 244 // // decrypt line and return result 245 // final byte[] toDecrypt = Base64.getDecoder().decode(line); 246 // byte[] decryptedBytes = null; 247 // for (final SecretKey key: multiKey) { 248 // decryptedBytes = DecryptSymmetric(toDecrypt, key); 249 // if (decryptedBytes == null) { return null; } 250 // } 251 // final String decrypted = new String(decryptedBytes); 252 // if (decrypted.startsWith("Z")) { return decrypted.trim(); } 253 // else { return decrypted; } 254 // } 255 // } 205 256 } -
trunk/src/org/expeditee/auth/EncryptedExpWriter.java
r1226 r1227 19 19 import org.ngikm.cryptography.CryptographyConstants; 20 20 21 public class EncryptedProfileExpWriter extends ExpWriter implements CryptographyConstants { 22 private SecretKey personalKey; 21 public class EncryptedExpWriter extends ExpWriter implements CryptographyConstants { 22 private SecretKey key; 23 private String label; 23 24 private static final String nl = "\n"; 24 25 25 public EncryptedProfileExpWriter() throws IOException { 26 // obtain personal key 27 final Text text = KeyList.PersonalKey.get(); 28 final byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0)); 29 personalKey = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 26 public EncryptedExpWriter(String encryptionLabel) throws IOException { 27 if (encryptionLabel.compareTo("Profile") == 0) { 28 // obtain personal key 29 Text text = KeyList.PersonalKey.get(); 30 byte[] keyBytes = Base64.getDecoder().decode(text.getData().get(0)); 31 key = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 32 label = "Profile"; 33 } else { 34 byte[] keyBytes = resolveKeyFromLabel(encryptionLabel); 35 key = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 36 label = encryptionLabel; 37 } 30 38 } 31 39 … … 33 41 protected void preOutputFrame() { 34 42 try { 35 final String line = EncryptedExpReader.ENCRYPTED_EXP_FLAG+ nl;43 String line = EncryptedExpReader.ENCRYPTED_EXP_FLAG + label + nl; 36 44 _writer.write(line); 37 45 _stringWriter.append(line); … … 47 55 48 56 // prepare line to write out 49 final byte[] encrypted = EncryptSymmetric(line.getBytes(), personalKey);50 finalString toWrite = Base64.getEncoder().encodeToString(encrypted) + nl;57 byte[] encrypted = EncryptSymmetric(line.getBytes(), key); 58 String toWrite = Base64.getEncoder().encodeToString(encrypted) + nl; 51 59 52 60 // output … … 55 63 } 56 64 57 private static byte[] EncryptSymmetric(final byte[] toEncrypt, final SecretKey key) { 65 private byte[] resolveKeyFromLabel(String label) { 66 return null; 67 } 68 69 private static byte[] EncryptSymmetric(byte[] toEncrypt, SecretKey key) { 58 70 try { 59 finalCipher cipher = Cipher.getInstance(SymmetricAlgorithm + SymmetricAlgorithmParameters);71 Cipher cipher = Cipher.getInstance(SymmetricAlgorithm + SymmetricAlgorithmParameters); 60 72 cipher.init(Cipher.ENCRYPT_MODE, key); 61 73 //could use modulus 62 finalint length = (int) ((Math.ceil(toEncrypt.length / 16f)) * 16);63 finalbyte[] toEncryptSizeAdjusted = Arrays.copyOf(toEncrypt, length);64 finalbyte[] result = cipher.doFinal(toEncryptSizeAdjusted);74 int length = (int) ((Math.ceil(toEncrypt.length / 16f)) * 16); 75 byte[] toEncryptSizeAdjusted = Arrays.copyOf(toEncrypt, length); 76 byte[] result = cipher.doFinal(toEncryptSizeAdjusted); 65 77 return result; 66 78 } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException -
trunk/src/org/expeditee/gui/AttributeUtils.java
r1200 r1227 197 197 _FrameAttrib.put("BackgroundColor", Frame.class.getMethod("getBackgroundColor"), 198 198 Frame.class.getMethod("setBackgroundColor", pColor)); 199 _FrameAttrib.put("EncryptionLabel", Frame.class.getMethod("getEncryptionLabel"), 200 Frame.class.getMethod("setEncryptionLabel", pString)); 201 199 202 200 203 // aliases for attribute setting 201 _FrameAttrib.alias("fgc", "foregroundcolor"); 202 _FrameAttrib.alias("bgc", "backgroundcolor"); 203 _FrameAttrib.alias("p", "permission"); 204 _FrameAttrib.alias("fgc", "foregroundcolor"); 205 _FrameAttrib.alias("bgc", "backgroundcolor"); 206 _FrameAttrib.alias("p", "permission"); 207 _FrameAttrib.alias("enc", "encryptionlabel"); 204 208 205 209 -
trunk/src/org/expeditee/gui/Frame.java
r1217 r1227 163 163 private Collection<FrameObserver> _observers = new HashSet<FrameObserver>(); 164 164 165 private String _encryptionLabel; 166 165 167 /** Default constructor, nothing is set. */ 166 168 public Frame() … … 2622 2624 } 2623 2625 2624 public Collection<? extends Item> getInteractableItems() 2625 { 2626 public Collection<? extends Item> getInteractableItems() { 2626 2627 /* 2627 2628 * TODO: Cache the interactableItems list so we dont have to recreate it … … 2655 2656 return _interactableItems; 2656 2657 } 2658 2659 public String getEncryptionLabel() { 2660 return _encryptionLabel; 2661 } 2662 2663 public void setEncryptionLabel(String label) { 2664 _encryptionLabel = label; 2665 } 2657 2666 2658 2667 private static final class History { -
trunk/src/org/expeditee/gui/FrameIO.java
r1219 r1227 43 43 import org.expeditee.auth.Authenticator; 44 44 import org.expeditee.auth.EncryptedExpReader; 45 import org.expeditee.auth.Encrypted ProfileExpWriter;45 import org.expeditee.auth.EncryptedExpWriter; 46 46 import org.expeditee.auth.gui.MailBay; 47 47 import org.expeditee.io.Conversion; … … 92 92 STATISTICS_DIR = PARENT_FOLDER + "statistics" + File.separator; 93 93 LOGS_DIR = PARENT_FOLDER + "logs" + File.separator; 94 SHARED_BY_ME_FRAMESETS = PARENT_FOLDER + "framesets-shared-by-me" + File.separator; 95 SHARED_WITH_ME_FRAMESETS = PARENT_FOLDER + "framesets-shared-with-me" + File.separator; 94 96 } 95 97 … … 125 127 126 128 public static String STATISTICS_DIR; 129 130 public static String SHARED_BY_ME_FRAMESETS; 131 132 public static String SHARED_WITH_ME_FRAMESETS; 127 133 128 134 public static String LOGS_DIR; … … 475 481 if (fullPath.endsWith(ExpReader.EXTENTION)) { 476 482 if (EncryptedExpReader.isEncryptedExpediteeFile(fullPath)) { 477 final boolean isProfile = frameName.startsWith(UserSettings.UserName.get()); 478 reader = new EncryptedExpReader(frameName, isProfile); 483 //final boolean isProfile = frameName.startsWith(UserSettings.UserName.get()); 484 //reader = new EncryptedExpReader(frameName, isProfile); 485 reader = new EncryptedExpReader(frameName); 479 486 } else { 480 487 reader = new ExpReader(frameName); … … 1006 1013 // if its a new frame or an existing Exp frame... 1007 1014 if (fullPath == null || fullPath.endsWith(ExpReader.EXTENTION)) { 1008 //Frame currentFrame = DisplayController.getCurrentFrame();1009 1015 if (UserSettings.Authenticated.get() && 1010 toSave.getN ame().startsWith(UserSettings.UserName.get())&&1011 toSave.get Number() != Authenticator.PUBLIC_KEY_FRAME) {1012 writer = new Encrypted ProfileExpWriter();1016 toSave.getNumber() != Authenticator.PUBLIC_KEY_FRAME && 1017 toSave.getEncryptionLabel() != null) { 1018 writer = new EncryptedExpWriter(toSave.getEncryptionLabel()); 1013 1019 savedVersion = EncryptedExpReader.getVersion(fullPath); 1014 1020 } else { -
trunk/src/org/expeditee/settings/UserSettings.java
r1213 r1227 264 264 FolderSettings.FrameDirs.get().add(FrameIO.HELP_PATH); 265 265 FolderSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH); 266 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_BY_ME_FRAMESETS); 267 FolderSettings.FrameDirs.get().add(FrameIO.SHARED_WITH_ME_FRAMESETS); 266 268 FolderSettings.FrameDirs.setDefault(FolderSettings.FrameDirs.get()); 267 269 FolderSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
Note:
See TracChangeset
for help on using the changeset viewer.