Changeset 1283


Ignore:
Timestamp:
04/05/19 10:25:31 (5 years ago)
Author:
bln4
Message:

When loading in messages from the mail databases now uses the timestamp last-accessed companion file to only load in new ones.

Location:
trunk/src/org/expeditee
Files:
4 edited

Legend:

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

    r1280 r1283  
    100100                if (!DisplayController.isMailMode()) {
    101101                        Mail.clear();
    102                         Authenticator.getInstance().loadMailDatabase();
     102                        AuthenticatorBrowser.getInstance().loadMailDatabase();
    103103                }
    104104                DisplayController.ToggleMailMode();
     
    172172                        createAccount(userData);
    173173                        login(userData);
    174                         Authenticator.Authenticated = true;
     174                        AuthenticatorBrowser.Authenticated = true;
    175175                } else {
    176176                        MessageBay.errorMessage(Constants.ERROR_INSUFFICIENT_INFORMATION_PROVIDED);
     
    189189                if (userdata.isPresent()) {
    190190                        login(userdata.get());
    191                         Authenticator.Authenticated = true;
     191                        AuthenticatorBrowser.Authenticated = true;
    192192                } else {
    193193                        MessageBay.errorMessage(Constants.ERROR_INSUFFICIENT_INFORMATION_PROVIDED);
     
    211211                final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    212212               
    213                 if (!Authenticator.Authenticated) {
     213                if (!AuthenticatorBrowser.Authenticated) {
    214214                        MessageBay.errorMessage(Constants.ERROR_MUST_BE_LOGGED_IN);
    215215                } else {
     
    230230       
    231231        public static void AuthGotoAccountManagement() {
    232                 if (Authenticator.Authenticated) {
     232                if (AuthenticatorBrowser.Authenticated) {
    233233                        DisplayController.setCurrentFrame(FrameIO.LoadFrame(Constants.FRAME_MULTIUSER1), false);
    234234                } else {
     
    284284                Collection<Text> textItems = currentFrame.getTextItems();
    285285               
    286                 if (!Authenticator.Authenticated) {
     286                if (!AuthenticatorBrowser.Authenticated) {
    287287                        MessageBay.errorMessage(Constants.ERROR_MUST_BE_LOGGED_IN);
    288288                        return;
     
    369369                rand.nextBytes(keyBytes);
    370370                SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
    371                 Authenticator.getInstance().putKey(username, password, key);
     371                AuthenticatorBrowser.getInstance().putKey(username, password, key);
    372372                String personalKey = Base64.getEncoder().encodeToString(key.getEncoded());
    373373                //      Public and private keys
     
    401401                Map<String, Consumer<Frame>> notifiers = new HashMap<String, Consumer<Frame>>();
    402402                notifiers.put(Constants.SETTINGS_AUTH, frame -> {
    403                         Authenticator.CREDENTIALS_FRAME = frame.getNumber();
     403                        AuthenticatorBrowser.CREDENTIALS_FRAME = frame.getNumber();
    404404                        Collection<Text> textItems = frame.getTextItems();
    405405                        for (Text t: textItems) {
     
    424424                        f.getAllItems().stream().forEach(item -> item.setOwner(username));
    425425                        f.setChanged(true);
    426                         if (f.getNumber() != Authenticator.CREDENTIALS_FRAME) {
     426                        if (f.getNumber() != AuthenticatorBrowser.CREDENTIALS_FRAME) {
    427427                                f.setEncryptionLabel("Profile");
    428428                        }
     
    441441                }
    442442               
    443                 if (Authenticator.CREDENTIALS_FRAME == -1) {
     443                if (AuthenticatorBrowser.CREDENTIALS_FRAME == -1) {
    444444                        System.err.println("authActions::Unable to establish credentials frame for new profile frame.  Account creation failed.");
    445445                        return;
     
    456456                credentialsFile.createNewFile();
    457457                FileWriter out = new FileWriter(credentialsFile);
    458                 out.write(Authenticator.CREDENTIALS_FRAME + ".exp");
     458                out.write(AuthenticatorBrowser.CREDENTIALS_FRAME + ".exp");
    459459                out.flush();
    460460                out.close();
    461461                //      migrate credentials frame
    462                 Frame credentialsFrame = FrameIO.LoadFrame(username + Authenticator.CREDENTIALS_FRAME);
     462                Frame credentialsFrame = FrameIO.LoadFrame(username + AuthenticatorBrowser.CREDENTIALS_FRAME);
    463463                Path destinationDirectory = Paths.get(credentialsDir.getAbsolutePath());
    464                 Path destinationFile = destinationDirectory.resolve(Authenticator.CREDENTIALS_FRAME + ExpReader.EXTENTION);
     464                Path destinationFile = destinationDirectory.resolve(AuthenticatorBrowser.CREDENTIALS_FRAME + ExpReader.EXTENTION);
    465465                FrameIO.migrateFrame(credentialsFrame, destinationFile);
    466466               
     
    498498               
    499499                try {
    500                         personalKey = Authenticator.getInstance().getSecretKey(username, password);
     500                        personalKey = AuthenticatorBrowser.getInstance().getSecretKey(username, password);
    501501                } catch (Exception e) {
    502502                        // leave personalKey null
     
    523523
    524524                Frame oneFrame = null;
    525                 if (!username.equals(Authenticator.ADMINACCOUNT)) {
     525                if (!username.equals(AuthenticatorBrowser.ADMINACCOUNT)) {
    526526                        // Load in and cache the profile frame using the personal key fetched from keystore.
    527527                        // Reset the personal key once finished so that setting parsing can correctly set it.
     
    534534                        for (int i = 1; i <= FrameIO.getLastNumber(username); i++) {
    535535                                Frame f = FrameIO.LoadFrame(oneFrame.getFramesetName() + i);
    536                                 if (f.getData() != null && f.getData().contains("MultiuserCredentials")) {
    537                                         Authenticator.CREDENTIALS_FRAME = f.getNumber();
     536                                if (f != null && f.getData() != null && f.getData().contains("MultiuserCredentials")) {
     537                                        AuthenticatorBrowser.CREDENTIALS_FRAME = f.getNumber();
    538538                                }
    539539                        }
     
    549549                        // Check mail
    550550                        MailBay.clear();
    551                         Authenticator.getInstance().loadMailDatabase();
     551                        AuthenticatorBrowser.getInstance().loadMailDatabase();
    552552                        Text keyItem = org.expeditee.settings.identity.secrets.KeyList.PrivateKey.get();
    553553                        if (keyItem.getData() != null) {
     
    555555                                byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
    556556                                PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
    557                                 List<MailEntry> mailForLoggingInUser = Mail.getEntries(UserSettings.UserName.get(), key);
     557                                List<MailEntry> mailForLoggingInUser = Mail.getEntries(UserSettings.UserName.get(), key);                       
    558558                                for (MailEntry mail: mailForLoggingInUser) {
    559559                                        MailBay.addMessage(mail.timestamp, mail.message, mail.message2, mail.options);
    560560                                }
    561561                        }
     562                        Path deadDropPath = Paths.get(FrameIO.DEAD_DROPS_PATH);
     563                        for (File connectionDir: deadDropPath.toFile().listFiles()) {
     564                                if (connectionDir.isDirectory()) {
     565                                        Path deaddropforcontactPath = Paths.get(connectionDir.getAbsolutePath());
     566                                        AuthenticatorBrowser.getInstance().updateLastReadMailTime(deaddropforcontactPath);
     567                                }
     568                        }
     569                       
    562570                } else {
    563                         UserSettings.UserName.set(Authenticator.ADMINACCOUNT);
     571                        UserSettings.UserName.set(AuthenticatorBrowser.ADMINACCOUNT);
    564572                        oneFrame = FrameIO.LoadFrame("multiuser1");
    565573                }
     
    606614                String colleagueOne = userData.get(AuthenticationTag.ColleagueOne);
    607615                String colleagueTwo = userData.get(AuthenticationTag.ColleagueTwo);
    608                 PublicKey colleagueOneKey = Authenticator.getInstance().getPublicKey(colleagueOne);
    609                 PublicKey colleagueTwoKey = Authenticator.getInstance().getPublicKey(colleagueTwo);
     616                PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueOne);
     617                PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueTwo);
    610618                if (colleagueOneKey == null) {
    611619                        MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);
     
    626634                        mail = new MailEntry(time, sender, colleagueTwo, topic, message, arguments);
    627635                        Mail.sendMail(mail, colleagueTwo);
    628                         Authenticator.getInstance().markRequestedColleagues(UserSettings.UserName.get());
     636                        AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get());
    629637                        return true;
    630638                }
     
    661669                final String newpassword = userdata.get(AuthenticationTag.NewPassword);
    662670
    663                 final SecretKey key = Authenticator.getInstance().getSecretKey(username, password);
     671                final SecretKey key = AuthenticatorBrowser.getInstance().getSecretKey(username, password);
    664672                if (key == null) {
    665673                        MessageBay.errorMessage("The username + existing password combination was incorrect.");
    666674                } else {
    667                         Authenticator.getInstance().putKey(username, newpassword, key);
     675                        AuthenticatorBrowser.getInstance().putKey(username, newpassword, key);
    668676                        MessageBay.displayMessage("Password changed successfully.");
    669677                }
  • trunk/src/org/expeditee/auth/Mail.java

    r1277 r1283  
    22
    33import java.io.File;
     4import java.io.FileNotFoundException;
    45import java.io.IOException;
    56import java.nio.file.Path;
     
    1718import java.sql.SQLException;
    1819import java.sql.Statement;
     20import java.text.ParseException;
     21import java.text.SimpleDateFormat;
    1922import java.util.ArrayList;
    2023import java.util.Arrays;
    2124import java.util.Base64;
     25import java.util.Date;
    2226import java.util.HashMap;
    2327import java.util.List;
    2428import java.util.Map;
     29import java.util.Scanner;
    2530
    2631import javax.crypto.BadPaddingException;
     
    7883                PublicKey publicKey = null;
    7984                try {
    80                         publicKey = Authenticator.getInstance().getPublicKey(colleagueName);
     85                        publicKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueName);
    8186                } catch (InvalidKeySpecException | NoSuchAlgorithmException | KeyStoreException | CertificateException
    8287                                | ClassNotFoundException | IOException | SQLException e) {
     
    182187                                }
    183188                               
    184                                 //String arguments = new String(c.doFinal(Base64.getDecoder().decode(mail.args)));
    185                                 filtered.add(new MailEntry(mail.timestamp, sender, receiverDecrypted, message, message2, options));
     189                                Path lastAccessedFile = Paths.get(FrameIO.DEAD_DROPS_PATH).resolve(sender).resolve(name + ".last-accessed");
     190                                SimpleDateFormat format = new SimpleDateFormat("ddMMMyyyy[HH:mm]");
     191                                MailEntry mailEntry = new MailEntry(mail.timestamp, sender, receiverDecrypted, message, message2, options);
     192                                try (Scanner in = new Scanner(lastAccessedFile.toFile())) {
     193                                        Date lastAccessedTimestamp = format.parse(in.nextLine());
     194                                        Date mailTimestamp = format.parse(mail.timestamp);
     195                                        if (mailTimestamp.after(lastAccessedTimestamp)) {
     196                                                filtered.add(mailEntry);
     197                                        }
     198                                } catch (FileNotFoundException e) {
     199                                        // It may not have been created yet, then err on the safe side and add it in.
     200                                        filtered.add(mailEntry);
     201                                } catch (ParseException e) {
     202                                        // If we fail to parse, then err on the safe side and add it in.
     203                                        filtered.add(mailEntry);
     204                                }                       
     205                               
    186206                        }
    187207                }
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r1280 r1283  
    115115                int lastNumber = FrameIO.getLastNumber(framesetName);
    116116                for (int i = 1; i <= lastNumber; i++) {
    117                         Frame frame = FrameIO.LoadFrame(framesetName + i, path.toAbsolutePath().toString());
     117                        Frame frame = FrameIO.LoadFrame(framesetName + i, path.toAbsolutePath().toString() + File.separator);
    118118                        this.framesCreated.add(frame);
    119119                }
     
    147147                        resetGlobals(toUse);
    148148                        _firstFrame = toUse;
    149                        
    150                         path.toAbsolutePath().resolve(framesetName);
    151149                } catch (InvalidFramesetNameException e) {
    152150                        e.printStackTrace();
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1280 r1283  
    5050import org.expeditee.agents.ExistingFramesetException;
    5151import org.expeditee.agents.InvalidFramesetNameException;
    52 import org.expeditee.auth.Authenticator;
     52import org.expeditee.auth.AuthenticatorBrowser;
    5353import org.expeditee.auth.EncryptedExpReader;
    5454import org.expeditee.auth.EncryptedExpWriter;
     
    375375                        List<String> directoriesToSearch = FolderSettings.FrameDirs.getAbsoluteDirs();
    376376                       
    377                         if (Authenticator.Authenticated) {
     377                        if (AuthenticatorBrowser.Authenticated) {
    378378                                // if we are running Expeditee Authenticated, consult user profile as location for framesets first
    379379                                String profilePath = FrameIO.PROFILE_PATH + UserSettings.UserName.get() + File.separator;
     
    11021102                        // if its a new frame or an existing Exp frame...
    11031103                        if (fullPath == null || fullPath.endsWith(ExpReader.EXTENTION)) {                               
    1104                                 if (toSave.getNumber() != Authenticator.CREDENTIALS_FRAME &&
     1104                                if (toSave.getNumber() != AuthenticatorBrowser.CREDENTIALS_FRAME &&
    11051105                                                toSave.getEncryptionLabel() != null) {
    11061106                                        writer = new EncryptedExpWriter(toSave.getEncryptionLabel());
Note: See TracChangeset for help on using the changeset viewer.