- Timestamp:
- 04/16/19 16:06:37 (5 years ago)
- Location:
- trunk/src/org/expeditee/auth
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/auth/Actions.java
r1316 r1320 10 10 import java.nio.file.StandardCopyOption; 11 11 import java.security.InvalidKeyException; 12 import java.security.KeyFactory; 12 13 import java.security.KeyPair; 13 14 import java.security.KeyPairGenerator; 14 15 import java.security.KeyStoreException; 15 16 import java.security.NoSuchAlgorithmException; 17 import java.security.PrivateKey; 16 18 import java.security.PublicKey; 17 19 import java.security.SecureRandom; 18 20 import java.security.cert.CertificateException; 19 21 import java.security.spec.InvalidKeySpecException; 22 import java.security.spec.PKCS8EncodedKeySpec; 20 23 import java.sql.SQLException; 21 24 import java.text.ParseException; … … 109 112 * @throws KeyStoreException 110 113 * @throws ParseException 111 */ 112 public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException { 114 * @throws InvalidKeySpecException 115 * @throws BadPaddingException 116 * @throws IllegalBlockSizeException 117 * @throws NoSuchPaddingException 118 * @throws InvalidKeyException 119 */ 120 public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { 113 121 if (!AuthenticatorBrowser.isAuthenticated()) return; 114 122 if (!DisplayController.isMailMode()) { 115 123 MailBay.ensureLink(); 116 124 Mail.clear(); 117 AuthenticatorBrowser.getInstance().loadMailDatabase(); 125 String keyEncoded = KeyList.PrivateKey.get().getData().get(0); 126 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded); 127 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes)); 128 Mail.checkMail(key); 118 129 } 119 130 DisplayController.ToggleMailMode(); -
trunk/src/org/expeditee/auth/Mail.java
r1294 r1320 34 34 import javax.crypto.NoSuchPaddingException; 35 35 36 import org.expeditee.auth.gui.MailBay; 36 37 import org.expeditee.gui.FrameIO; 37 38 import org.expeditee.settings.UserSettings; … … 55 56 public static void sendMail(MailEntry mail, String colleagueName) { 56 57 // Ensure dead drop area is set up. 57 Path databaseFileDirPath = Paths.get(FrameIO.DEAD_DROPS_PATH).resolve(UserSettings.UserName.get() + "+" + colleagueName); 58 String me = UserSettings.UserName.get().toLowerCase(); 59 String them = colleagueName.toLowerCase(); 60 Path databaseFileDirPath = Paths.get(FrameIO.DEAD_DROPS_PATH).resolve(me + "+" + them); 61 if (!databaseFileDirPath.toFile().exists()) { 62 databaseFileDirPath = Paths.get(FrameIO.DEAD_DROPS_PATH).resolve(them + "+" + me); 63 } 58 64 Path databaseFilePath = databaseFileDirPath.resolve(colleagueName + ".db"); 59 65 File databaseFile = databaseFilePath.toFile(); … … 234 240 } 235 241 } 242 243 public static void checkMail(PrivateKey key) throws NoSuchAlgorithmException, NoSuchPaddingException, 244 IllegalBlockSizeException, BadPaddingException, InvalidKeyException, KeyStoreException, 245 FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException, ParseException { 246 MailBay.clear(); 247 AuthenticatorBrowser.getInstance().loadMailDatabase(); 248 List<MailEntry> mailForLoggingInUser = Mail.getEntries(UserSettings.UserName.get(), key); 249 for (MailEntry mail: mailForLoggingInUser) { 250 MailBay.addMessage(mail.timestamp, mail.message, mail.message2, mail.options); 251 } 252 253 // Update last read files. 254 Path deadDropPath = Paths.get(FrameIO.DEAD_DROPS_PATH); 255 for (File connectionDir: deadDropPath.toFile().listFiles()) { 256 if (connectionDir.isDirectory()) { 257 Path deaddropforcontactPath = Paths.get(connectionDir.getAbsolutePath()); 258 AuthenticatorBrowser.getInstance().updateLastReadMailTime(deaddropforcontactPath); 259 } 260 } 261 } 236 262 } -
trunk/src/org/expeditee/auth/account/Authenticate.java
r1316 r1320 1 1 package org.expeditee.auth.account; 2 2 3 import java.io.File;4 3 import java.io.IOException; 5 import java.nio.file.Path;6 import java.nio.file.Paths;7 4 import java.security.InvalidKeyException; 8 5 import java.security.KeyFactory; … … 29 26 import org.expeditee.auth.AuthenticatorBrowser; 30 27 import org.expeditee.auth.Mail; 31 import org.expeditee.auth.Mail.MailEntry;32 28 import org.expeditee.auth.gui.MailBay; 33 29 import org.expeditee.auth.tags.AuthenticationTag; … … 107 103 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded); 108 104 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes)); 109 List<MailEntry> mailForLoggingInUser = Mail.getEntries(UserSettings.UserName.get(), key); 110 for (MailEntry mail: mailForLoggingInUser) { 111 MailBay.addMessage(mail.timestamp, mail.message, mail.message2, mail.options); 112 } 113 114 // Update last read files. 115 Path deadDropPath = Paths.get(FrameIO.DEAD_DROPS_PATH); 116 for (File connectionDir: deadDropPath.toFile().listFiles()) { 117 if (connectionDir.isDirectory()) { 118 Path deaddropforcontactPath = Paths.get(connectionDir.getAbsolutePath()); 119 AuthenticatorBrowser.getInstance().updateLastReadMailTime(deaddropforcontactPath); 120 } 121 } 105 org.expeditee.auth.Mail.checkMail(key); 122 106 } else { 123 107 res.additionalInfo.add("No private key present: your communication with other Expeditee users will be limited until this is resolved."); … … 163 147 return AuthenticationResult.SuccessLogout; 164 148 } 165 149 166 150 public enum AuthenticationResult { 167 151
Note:
See TracChangeset
for help on using the changeset viewer.