Changeset 1320 for trunk


Ignore:
Timestamp:
04/16/19 16:06:37 (5 years ago)
Author:
bln4
Message:

You can now check for new mail while logged in (when you open the mail bay)

Location:
trunk/src/org/expeditee/auth
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/Actions.java

    r1316 r1320  
    1010import java.nio.file.StandardCopyOption;
    1111import java.security.InvalidKeyException;
     12import java.security.KeyFactory;
    1213import java.security.KeyPair;
    1314import java.security.KeyPairGenerator;
    1415import java.security.KeyStoreException;
    1516import java.security.NoSuchAlgorithmException;
     17import java.security.PrivateKey;
    1618import java.security.PublicKey;
    1719import java.security.SecureRandom;
    1820import java.security.cert.CertificateException;
    1921import java.security.spec.InvalidKeySpecException;
     22import java.security.spec.PKCS8EncodedKeySpec;
    2023import java.sql.SQLException;
    2124import java.text.ParseException;
     
    109112         * @throws KeyStoreException
    110113         * @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 {
    113121                if (!AuthenticatorBrowser.isAuthenticated()) return;
    114122                if (!DisplayController.isMailMode()) {
    115123                        MailBay.ensureLink();
    116124                        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);
    118129                }
    119130                DisplayController.ToggleMailMode();
  • trunk/src/org/expeditee/auth/Mail.java

    r1294 r1320  
    3434import javax.crypto.NoSuchPaddingException;
    3535
     36import org.expeditee.auth.gui.MailBay;
    3637import org.expeditee.gui.FrameIO;
    3738import org.expeditee.settings.UserSettings;
     
    5556        public static void sendMail(MailEntry mail, String colleagueName) {
    5657                // 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                }
    5864                Path databaseFilePath = databaseFileDirPath.resolve(colleagueName + ".db");
    5965                File databaseFile = databaseFilePath.toFile();
     
    234240                }
    235241        }
     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        }
    236262}
  • trunk/src/org/expeditee/auth/account/Authenticate.java

    r1316 r1320  
    11package org.expeditee.auth.account;
    22
    3 import java.io.File;
    43import java.io.IOException;
    5 import java.nio.file.Path;
    6 import java.nio.file.Paths;
    74import java.security.InvalidKeyException;
    85import java.security.KeyFactory;
     
    2926import org.expeditee.auth.AuthenticatorBrowser;
    3027import org.expeditee.auth.Mail;
    31 import org.expeditee.auth.Mail.MailEntry;
    3228import org.expeditee.auth.gui.MailBay;
    3329import org.expeditee.auth.tags.AuthenticationTag;
     
    107103                                        byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
    108104                                        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);
    122106                                } else {
    123107                                        res.additionalInfo.add("No private key present: your communication with other Expeditee users will be limited until this is resolved.");
     
    163147                return AuthenticationResult.SuccessLogout;
    164148        }
    165 
     149       
    166150        public enum AuthenticationResult {
    167151
Note: See TracChangeset for help on using the changeset viewer.