Changeset 1363 for trunk


Ignore:
Timestamp:
05/17/19 14:37:12 (5 years ago)
Author:
bln4
Message:

It is now possible to complete the process of recovering access to a Expeditee account. Further work, in the form of frames in the authentication frameset, are to follow.
A refactoring/tidy up has also been completed.

Location:
trunk/src/org/expeditee
Files:
3 added
2 deleted
10 edited
2 copied
1 moved

Legend:

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

    r1362 r1363  
    2323import java.util.Collection;
    2424import java.util.HashMap;
    25 import java.util.Iterator;
    2625import java.util.List;
    2726import java.util.Map;
     
    3938import org.expeditee.agents.ExistingFramesetException;
    4039import org.expeditee.agents.InvalidFramesetNameException;
    41 import org.expeditee.auth.Mail.MailEntry;
    4240import org.expeditee.auth.account.Authenticate;
    4341import org.expeditee.auth.account.Authenticate.AuthenticationResult;
     
    4543import org.expeditee.auth.account.Create.CreateResult;
    4644import org.expeditee.auth.account.Password;
    47 import org.expeditee.auth.gui.MailBay;
     45import org.expeditee.auth.mail.Mail;
     46import org.expeditee.auth.mail.Mail.MailEntry;
     47import org.expeditee.auth.mail.gui.MailBay;
    4848import org.expeditee.auth.tags.AuthenticationTag;
    49 import org.expeditee.core.Colour;
    5049import org.expeditee.gio.gesture.StandardGestureActions;
    5150import org.expeditee.gui.DisplayController;
     
    5655import org.expeditee.items.Text;
    5756import org.expeditee.settings.UserSettings;
    58 import org.expeditee.settings.identity.passwordrecovery.Colleagues;
    5957import org.expeditee.settings.identity.secrets.KeyList;
    6058import org.expeditee.stats.Formatter;
     
    6361public class Actions implements CryptographyConstants {
    6462       
    65         //Debug Functions
     63        //      Start Debug Actions
    6664        public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException {
    6765                String time = org.expeditee.stats.Formatter.getDateTime();
     
    7573                MessageBay.displayMessage("Test message sent.");
    7674        }
     75       
    7776        public static void SendTestMessageHemi(String param) {
    7877                String time = Formatter.getDateTime();
     
    8786                MessageBay.displayMessage("Test message sent.");
    8887        }
     88       
    8989        public static void SendTestOneOffMessage(String colleagueName) {
    9090                String time = Formatter.getDateTime();
     
    101101                Mail.sendOneOffMail(mail, colleagueName, key);
    102102        }
    103         public static void AuthOneOffSecureMessage(Text cursor, Text actionItem) {
    104                 byte[] keyBytes = Base64.getDecoder().decode(cursor.getText());
    105                 SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
    106                 List<String> data = actionItem.getData();
    107                 String topic = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(3)), key));
    108                 String message = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(4)), key));
    109                 Map<String, String> options = new HashMap<String, String>();
    110                 for (int i = 5; i < data.size(); i+=2) {
    111                         String k = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(i)), key));
    112                         String v = new String(org.expeditee.auth.sharing.Actions.DecryptSymmetric(Base64.getDecoder().decode(data.get(i + 1)), key));
    113                         options.put(k, v);
    114                 }
    115                 MailBay.addMessage(data.get(0), topic, message, options);
    116                 StandardGestureActions.Refresh();
    117         }
    118         public static void SetPWColleagues(String colleagueOne, String colleagueTwo) {
    119                 Colleagues.Colleague_One.set(colleagueOne);
    120                 Colleagues.Colleague_Two.set(colleagueTwo);
    121                 Colleagues.Colleague_One_Email.set("[email protected]");
    122                 Colleagues.Colleague_Two_Email.set("[email protected]");
    123         }
    124103       
    125104        private static String userbackup = "authadmin";
     
    128107                UserSettings.UserName.set(userbackup);
    129108                userbackup = backup;
     109        }
     110        //      End Debug Actions
     111       
     112        //      Start Misc Auth Actions
     113        /**
     114         * Action ran by user to read a message using a single use distributed Symmetric key
     115         * @param cursor The content on the cursor should be a text item whose content is the
     116         * Symmetric key to use, represented as a Base64 encoded string.
     117         * @param actionItem The action item will contain the encrypted message in its data.
     118         */
     119        public static void AuthOneOffSecureMessage(Text cursor, Text actionItem) {
     120                byte[] keyBytes = Base64.getDecoder().decode(cursor.getText());
     121                SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
     122                List<String> data = actionItem.getData();
     123                Mail.decryptOneOffSecureMessage(key, data);
     124                StandardGestureActions.Refresh();
    130125        }
    131126       
     
    166161        }
    167162       
     163        /**
     164         * Action used to navigate to multiuser1 (multiuser abilities) if authenticated and authentication1 (login) is not so.
     165         */
     166        public static void AuthGotoAccountManagement() {
     167                if (AuthenticatorBrowser.Authenticated) {
     168                        DisplayController.setCurrentFrame(FrameIO.LoadFrame("multiuser1"), false);
     169                } else {
     170                        DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), false);
     171                }
     172        }
     173       
     174        /**
     175         * Gets all items on a specified frame that contain the specified data.
     176         */
     177        public static Collection<Item> getByData(Frame frame, String data) {
     178                Collection<Item> allItems = frame.getAllItems();
     179                allItems.removeIf(i -> i.getData() == null || !i.hasData(data));
     180                return allItems;
     181        }
     182       
     183        /**
     184         * Gets all items on a specified frame that contains the specified content.
     185         */
     186        public static Collection<Item> getByContent(Frame frame, String content) {
     187                Collection<Item> allItems = frame.getAllItems();
     188                allItems.removeIf(i -> i.getText().compareTo(content) != 0);
     189                return allItems;
     190        }
     191        //      End Misc Auth Actions
     192       
     193        //      Start Regain Account Access Actions
     194        /**
     195         * Action ran by user to specify who their password colleagues are.  These are the
     196         * individuals who will be consulted if and when the user needs to regain access
     197         * to their account. 
     198         * @param colleagueOne
     199         * @param colleagueTwo
     200         */
     201        public static void AuthSetPWColleagues(String colleagueOne, String colleagueTwo) {
     202                Password.setPWColleagues(colleagueOne, colleagueTwo);
     203        }
     204       
     205        /**
     206         * Action ran by user to oblige with a request from colleague who has nominated the
     207         * user as a pw colleague.  Will email (not Expeditee mail) the colleague the password
     208         * share that the user has stored on their secrets frame.
     209         * @param colleagueName
     210         */
     211        public static void AuthEmailPasswordShare(String colleagueName) {
     212                Password.emailPasswordShare(colleagueName);
     213        }
     214       
     215        /**
     216         * Action ran by user to regain access to their account by providing:
     217         *      their username
     218         *      two password shares obtained from pw colleagues
     219         *      their desired new password
     220         */
     221        public static void AuthRegainAccountAccess() {
     222                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
     223                Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false,
     224                                AuthenticationTag.Username, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain,
     225                                AuthenticationTag.PasswordSliceOne, AuthenticationTag.PasswordSliceTwo);
     226                if (userdata.isPresent()) {
     227                        // Confirm new requested passwords match
     228                        Map<AuthenticationTag, String> userData = userdata.get();
     229                        if (!userData.get(AuthenticationTag.NewPassword).equals(userData.get(AuthenticationTag.NewPasswordAgain))) {
     230                                return;
     231                        }
     232                       
     233                        Password.regainAccountAccess(userData);
     234                }
     235        }
     236               
     237        /**
     238         * Actions used to generate and deliver an intergalactic number to a users public email
     239         * address after they have began the password recovery process.
     240         */
     241        public static void AuthDistributeIntergalacticNumber() {
     242                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
     243                Optional<Map<AuthenticationTag, String>> userdata =
     244                                AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
     245                if (userdata.isPresent()) {
     246                        Map<AuthenticationTag, String> userData = userdata.get();
     247                        String username = userData.get(AuthenticationTag.Username);
     248                        String email = getEmailFromUsername(username);
     249                        userData.put(AuthenticationTag.Email, email);
     250                        Password.generateAndDeliverIntergalacticNumber(userData);
     251                        MessageBay.displayMessage("A identity number has been sent to the email "
     252                                        + "associated with your account.  Enter it below to proceed.");
     253                }
     254        }
     255       
     256        /**
     257         * Action used by user to submit their intergalactic number along with their username
     258         * in order to confirm that they own the public email address registered to their account.
     259         * This is part of the process of recoverying access to an account.
     260         */
     261        public static void AuthSubmitIntergalacticNumber() {
     262                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
     263                Optional<Map<AuthenticationTag, String>> userdata =
     264                                AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
     265                                                AuthenticationTag.IntergalacticNumber);
     266                if (userdata.isPresent()) {
     267                        Password.confirmIntergalacticNumberAndAlertColleagues(userdata.get());
     268                }
     269        }
     270        //      End Regain Account Access Actions
     271       
     272        //      Start Create Account Actions
    168273        /**
    169274         * Action used to created a new user account.
     
    235340                }
    236341        }
    237        
     342        //      End Create Account Actions
     343       
     344        //      Start Account Login Actions
    238345        /**
    239346         * Action used to start authentication as a specified user. 
     
    258365        }
    259366       
     367        /**
     368         * Action used by the user to log out of their account.
     369         */
    260370        public static void AuthLogout() {
    261371                MessageBay.displayMessage(Authenticate.logout().toString());
    262372        }
    263        
     373        //      End Account Login Actions
     374       
     375        //      Start Change Access Actions
    264376        /**
    265377         * Action used to change the currently authenticated users password.
     
    295407                }
    296408        }
    297        
    298         public static void AuthGotoAccountManagement() {
    299                 if (AuthenticatorBrowser.Authenticated) {
    300                         DisplayController.setCurrentFrame(FrameIO.LoadFrame("multiuser1"), false);
    301                 } else {
    302                         DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), false);
    303                 }
    304         }
    305        
    306         public static void AuthDistributeIntergalacticNumber() {
    307                 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    308                 Optional<Map<AuthenticationTag, String>> userdata =
    309                                 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
    310                 if (userdata.isPresent()) {
    311                         Map<AuthenticationTag, String> userData = userdata.get();
    312                         String username = userData.get(AuthenticationTag.Username);
    313                         String email = getEmailFromUsername(username);
    314                         userData.put(AuthenticationTag.Email, email);
    315                         Password.generateAndDeliverIntergalacticNumber(userData);
    316                         MessageBay.displayMessage("A identity number has been sent to the email "
    317                                         + "associated with your account.  Enter it below to proceed.");
    318                 }
    319         }
    320        
    321         public static void AuthSubmitIntergalacticNumber() {
    322                 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
    323                 Optional<Map<AuthenticationTag, String>> userdata =
    324                                 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
    325                                                 AuthenticationTag.IntergalacticNumber);
    326                 if (userdata.isPresent()) {
    327                         Map<AuthenticationTag, String> tags = userdata.get();
    328                         String username = tags.get(AuthenticationTag.Username);
    329                         String intergalacticNumber = tags.get(AuthenticationTag.IntergalacticNumber);
    330                         boolean match = false;
    331                         try {
    332                                 match = AuthenticatorBrowser.getInstance().confirmIntergalaticNumber(username, intergalacticNumber);
    333                         } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | ClassNotFoundException
    334                                         | IOException | SQLException e) {
    335                                 e.printStackTrace();
    336                                 return;
    337                         }
    338                         if (!match) {
    339                                 MessageBay.errorMessage("The provided identity number does not match the one stored on file.");
    340                                 return;
    341                         }
    342                         String[] colleagues = getPasswordColleaguesFromUsername(username);
    343                         Password.confirmIntergalacticNumberAndAlertColleagues(userdata.get(), colleagues);
    344                 }
    345         }
    346        
     409        // End Change Access Actions
     410       
     411        // Start Private Helper Functions. 
     412        /**
     413         * Gets the public email address associated with the specified username.
     414         * @param username
     415         * @return
     416         */
    347417        private static String getEmailFromUsername(String username) {
    348418                Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
     
    374444                }
    375445        }
    376        
    377         private static String[] getPasswordColleaguesFromUsername(String username) {
    378                 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
    379                 Path credentialsFilePath = credentialsDirPath.resolve("pwcolleagues.inf");
    380                 String fileName = null;
    381                 if (credentialsFilePath.toFile().exists()) {
    382                         try (Scanner in = new Scanner(credentialsFilePath)) {
    383                                 fileName = in.nextLine();
    384                         } catch (IOException e) {
    385                                 MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
    386                                 return null;
    387                         }
    388                 } else {
    389                         MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
    390                         return null;
    391                 }
    392                
    393                 int number = Integer.parseInt(fileName.replace(".exp", ""));
    394                 Frame pwColleagueFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
    395                 Collection<Text> textItems = pwColleagueFrame.getTextItems();
    396                 textItems.removeIf(text -> !text.getText().startsWith("Colleague"));
    397                
    398                 String[] ret = new String[4];
    399                 Iterator<Text> it = textItems.iterator();
    400                 while(it.hasNext()) {
    401                         String content = it.next().getText().toLowerCase().trim();
    402                         if (content.contains("colleague_one:")) {
    403                                 ret[0] = content.replace("colleague_one:", "").trim();
    404                         } else if (content.contains("colleague_two:")) {
    405                                 ret[1] = content.replace("colleague_two:", "").trim();
    406                         } else if (content.contains("colleague_one_email:")) {
    407                                 ret[2] = content.replace("colleague_one_email:", "").trim();
    408                         } else if (content.contains("colleague_two_email:")) {
    409                                 ret[3] = content.replace("colleague_two_email:", "").trim();
    410                         }
    411                 }
    412                 return ret;
    413         }
    414        
     446        //      End Private Helper Functions.
     447       
     448        //      Start Future Functionality
    415449        public static void AuthShareFrameset() throws IOException {
    416450                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
     
    431465                }
    432466        }
    433 
    434         /**
    435          * Navigation action for progressing the process of recruiting colleagues to assist in password recovery.
    436          * Hides certain content that AuthSubmitPWCollegues goes onto show if it does not fail.
    437          */
    438         public static void AuthGotoColleagueSubmissionFrame() {
    439                 Frame destination = FrameIO.LoadFrame("authentication7");
    440                 DisplayController.setCurrentFrame(destination, true);
    441                 Collection<Item> toHide = getByData(destination, "ShowOnProgress");
    442                 for (Item i: toHide) {
    443                         i.setVisible(false);
    444                 }
     467       
     468        /*
     469         * Function to share a specified frameset.
     470         * Currently, this moves the frameset to the 'Shared By Me' directory and then relies on the user to use Google Drive functionality to share it appropriately.
     471         */
     472        private static void shareFrameset(Frame toShare) throws IOException {   
     473                File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
     474                File sourceDir = new File(toShare.getFramesetPath());
     475               
     476                if (destinationDir.exists()) {
     477                        MessageBay.errorMessage("A frameset by this name already exists.");
     478                        return;
     479                }
     480               
     481                destinationDir.mkdir();
     482                List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
     483                Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
     484               
     485                MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ".  Google Drive functionality can now be used to share it with colleagues.");
    445486        }
    446487       
     
    493534        }
    494535       
    495 //      public static void AuthSetupPasswordRecovery() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, IOException, SQLException, UnrecoverableEntryException {
    496 //              if (!UserSettings.Authenticated.get()) {
    497 //                      MessageBay.errorMessage("You must be logged in to perform this action.");
    498 //              } else if (!Authenticator.getInstance().hasRegisteredEmail(UserSettings.UserName.get())) {
    499 //                      Frame registerEmailFrame = FrameIO.LoadFrame("authentication4");
    500 //                      DisplayController.setCurrentFrame(registerEmailFrame, true);
    501 //              } else if (!Authenticator.getInstance().hasRequestedColleagues(UserSettings.UserName.get()) && Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) == null) {
    502 //                      Frame submitColleaguesFrame = FrameIO.LoadFrame("authentication5");
    503 //                      DisplayController.setCurrentFrame(submitColleaguesFrame, true);
    504 //              } else if (Authenticator.getInstance().hasRequestedColleagues(UserSettings.UserName.get()) && Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) == null) {
    505 //                      MessageBay.displayMessage("You have already nominated two colleagues to assist you in the process of password recovery and are awaiting their response."
    506 //                                      + "  You will be alerted on Expeditee startup when they have both responded.");
    507 //              } else if (Authenticator.getInstance().getColleagues(UserSettings.UserName.get()) != null) {
    508 //                      MessageBay.displayMessage("You have completed the Password Recovery Setup process, there is nothing more to do here.");
    509 //              }
    510 //      }
    511        
    512         public static void AuthConfirmPasswordColleagueRelationship(String colleagueName) {
    513                
    514         }
    515        
    516         public static void AuthDenyPasswordColleagueRelationship(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException,
    517                 KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
    518                 denyPasswordColleagueRelationship(colleagueName);
    519         }
    520        
    521         public static void AuthClearPWColleaguesNominated() {
    522                
    523         }
    524        
    525536        /*
    526          * Function to share a specified frameset.
    527          * Currently, this moves the frameset to the 'Shared By Me' directory and then relies on the user to use Google Drive functionality to share it appropriately.
    528          */
    529         private static void shareFrameset(Frame toShare) throws IOException {   
    530                 File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
    531                 File sourceDir = new File(toShare.getFramesetPath());
    532                
    533                 if (destinationDir.exists()) {
    534                         MessageBay.errorMessage("A frameset by this name already exists.");
    535                         return;
    536                 }
    537                
    538                 destinationDir.mkdir();
    539                 List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
    540                 Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
    541                
    542                 MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ".  Google Drive functionality can now be used to share it with colleagues.");
    543         }
    544        
    545         private static void denyPasswordColleagueRelationship(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
    546                 String time = org.expeditee.stats.Formatter.getDateTime();
    547                 String sender = UserSettings.UserName.get();
    548                 String message = "You have received a reply from " + sender + " reguarding your request for assistance.";
    549                 String message2 = "Unfortunately " + sender + " has indicated that they are unable to help you with your potential password recovery.";
    550                 Map<String, String> options = new HashMap<String, String>();
    551                 options.put("Clear Preview Colleague Nominations", "AuthClearPWColleaguesNominated");
    552                 MailEntry mail = new MailEntry(time, sender, colleagueName, message, message2, options);
    553                 Mail.sendMail(mail, colleagueName);
    554         }
    555        
     537         * Function to submit a request to specified contacts to be the current users pw colleagues.
     538         */
    556539        private static boolean submitPWColleagues(Map<AuthenticationTag, String> userData) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
    557540                String colleagueOne = userData.get(AuthenticationTag.ColleagueOne);
     
    581564                }
    582565        }
    583        
    584         public static void TickBox(final Text item) {
    585                 if (item.getBackgroundColor() != Colour.RED) {
    586                         item.setBackgroundColor(Colour.RED);
    587                 } else {
    588                         item.setBackgroundColor(Colour.GREEN);
    589                 }
    590         }
    591        
    592         /*
    593          * Gets all items on a specified frame that contain the specified data.
    594          */
    595         public static Collection<Item> getByData(final Frame frame, final String data) {
    596                 final Collection<Item> allItems = frame.getAllItems();
    597                 allItems.removeIf(i -> i.getData() == null || !i.hasData(data));
    598                 return allItems;
    599         }
    600        
    601         public static Collection<Item> getByContent(final Frame frame, final String content) {
    602                 final Collection<Item> allItems = frame.getAllItems();
    603                 allItems.removeIf(i -> i.getText().compareTo(content) != 0);
    604                 return allItems;
    605         }
     566        // End Future Functionality
    606567}
  • trunk/src/org/expeditee/auth/AuthenticatorBrowser.java

    r1362 r1363  
    4444
    4545import org.expeditee.actions.Actions;
     46import org.expeditee.auth.mail.Mail;
    4647import org.expeditee.core.Dimension;
    4748import org.expeditee.core.Point;
     
    7374        public static int CREDENTIALS_FRAME = -1;
    7475        public static int PASSWORD_RECOVERY_FRAME = -1;
     76        public static int SECRETS_FRAME = -1;
    7577        public static final String ADMINACCOUNT = "authadmin";
    7678        public static final String PROFILEENCRYPTIONLABEL = "Profile";
     
    107109                loadKeystore();
    108110                Actions.LoadMethods(org.expeditee.auth.Actions.class);
    109                 Actions.LoadMethods(org.expeditee.auth.sharing.Actions.class);
     111                Actions.LoadMethods(org.expeditee.encryption.Actions.class);
    110112
    111113                // Does the account Authentication.ADMINACCOUNT exist?
     
    351353                // generate intergalactic number
    352354                SecureRandom rand = new SecureRandom();
    353                 byte[] intergalacticNumberBytes = new byte[10];
     355                byte[] intergalacticNumberBytes = new byte[16];
    354356                rand.nextBytes(intergalacticNumberBytes);
    355357                String intergalacticNumber = Base64.getEncoder().encodeToString(intergalacticNumberBytes);
  • trunk/src/org/expeditee/auth/account/Authenticate.java

    r1359 r1363  
    2525import org.expeditee.auth.Actions;
    2626import org.expeditee.auth.AuthenticatorBrowser;
    27 import org.expeditee.auth.gui.MailBay;
     27import org.expeditee.auth.mail.gui.MailBay;
    2828import org.expeditee.auth.tags.AuthenticationTag;
    2929import org.expeditee.gui.Browser;
     
    4141public class Authenticate implements CryptographyConstants {
    4242
     43        /**
     44         * Given a username and password, potentially login. 
     45         * @param userdata
     46         * @return AuthenticationResult.SuccessLogin if login works, AuthenticationResult.ErrorLoginNobody or AuthenticationResult.ErrorLoginUsernamePasswordCombo otherwise.
     47         */
    4348        public static AuthenticationResult login(Map<AuthenticationTag, String> userdata) {
    4449                String username = userdata.get(AuthenticationTag.Username);
     
    7681                                        if(data != null && data.contains("MultiuserCredentials")) {
    7782                                                AuthenticatorBrowser.CREDENTIALS_FRAME = f.getNumber();
     83                                        } else if (data != null && data.contains("PasswordColleagues")) {
     84                                                AuthenticatorBrowser.PASSWORD_RECOVERY_FRAME = f.getNumber();
     85                                        } else if (data != null && data.contains("SecretsFrame")) {
     86                                                AuthenticatorBrowser.SECRETS_FRAME = f.getNumber();
    7887                                        }
    79                                 }
     88                                }
    8089                        }
    8190                       
     
    103112                                        byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
    104113                                        PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
    105                                         org.expeditee.auth.Mail.checkMail(key);
     114                                        org.expeditee.auth.mail.Mail.checkMail(key);
    106115                                } else {
    107116                                        res.additionalInfo.add("No private key present: your communication with other Expeditee users will be limited until this is resolved.");
     
    129138        }
    130139       
     140        /**
     141         * Logs out the current authenticated user.
     142         * @return AuthenticationResult.SuccessLogout to signal the logout has occured.
     143         */
    131144        public static AuthenticationResult logout() {
    132145                // Set user to nobody.
  • trunk/src/org/expeditee/auth/account/Create.java

    r1356 r1363  
    125125                return CreateResult.SuccessCreateAccount;
    126126        }
    127        
    128         public static CreateResult createAlternativeAccess(Map<AuthenticationTag, String> userdata) {
    129                 String username = userdata.get(AuthenticationTag.Username);
    130                 FrameIO.CreateFrame(username, null, "default1");
    131                 return null;
    132         }
    133                
     127                       
    134128        public enum CreateResult {
    135129                SuccessCreateAccount ("Account created."),
     
    193187                        FrameIO.migrateFrame(credentialsFrame, destinationFile);
    194188                        //      pwcolleagues.inf file.
    195                         String pwColleaguesPath = credentialsDir.getAbsolutePath() + File.separator + "pwcolleagues.inf";
    196                         File pwColleaguesFile = new File(pwColleaguesPath);
     189                        File pwColleaguesFile = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve("pwcolleagues.inf").toFile();
    197190                        pwColleaguesFile.createNewFile();
    198191                        out = new FileWriter(pwColleaguesFile);
     
    234227                        }
    235228                });
    236                 notifiers.put("settings.identity.passwordrecovery", frame -> {
     229                notifiers.put("settings.identity.passwordrecovery", frame -> {
     230                        frame.addToData("PasswordColleagues");
    237231                        AuthenticatorBrowser.PASSWORD_RECOVERY_FRAME = frame.getNumber();
    238232                });
    239                
     233                notifiers.put("settings.identity.secrets", frame -> {
     234                        frame.addToData("SecretsFrame");
     235                        AuthenticatorBrowser.SECRETS_FRAME = frame.getNumber();
     236                });
    240237               
    241238                // Create users profile
  • trunk/src/org/expeditee/auth/account/Password.java

    r1357 r1363  
    11package org.expeditee.auth.account;
    22
     3import java.io.File;
    34import java.io.FileNotFoundException;
    45import java.io.IOException;
     6import java.nio.file.Path;
     7import java.nio.file.Paths;
    58import java.security.KeyStoreException;
    69import java.security.NoSuchAlgorithmException;
     10import java.security.SecureRandom;
    711import java.security.cert.CertificateException;
    812import java.sql.SQLException;
     13import java.util.Base64;
     14import java.util.Collection;
     15import java.util.HashMap;
     16import java.util.Iterator;
    917import java.util.Map;
    1018import java.util.Properties;
     19import java.util.Scanner;
    1120
    1221import javax.crypto.SecretKey;
     22import javax.crypto.spec.SecretKeySpec;
    1323import javax.mail.Message;
    1424import javax.mail.MessagingException;
     
    1626import javax.mail.Session;
    1727import javax.mail.Transport;
     28import javax.mail.internet.AddressException;
    1829import javax.mail.internet.InternetAddress;
    1930import javax.mail.internet.MimeMessage;
    2031
    2132import org.expeditee.auth.AuthenticatorBrowser;
     33import org.expeditee.auth.mail.Mail;
     34import org.expeditee.auth.mail.Mail.MailEntry;
    2235import org.expeditee.auth.tags.AuthenticationTag;
    2336import org.expeditee.gui.DisplayController;
     37import org.expeditee.gui.Frame;
    2438import org.expeditee.gui.FrameIO;
    2539import org.expeditee.gui.MessageBay;
     40import org.expeditee.items.Text;
     41import org.expeditee.settings.UserSettings;
     42import org.expeditee.settings.identity.passwordrecovery.Colleagues;
     43import org.expeditee.settings.identity.secrets.KeyList;
     44import org.expeditee.stats.Formatter;
    2645import org.ngikm.cryptography.CryptographyConstants;
    2746
     47import com.codahale.shamir.Scheme;
     48
    2849public class Password implements CryptographyConstants {
    29         /*
    30          * Changes the recorded password for a user in the key store.
     50        /**
     51         * Changes the recorded password for a user in the key store; given the username signaling whose password to change, along with the existing and new password.
    3152         */
    3253        public static void changePassword(Map<AuthenticationTag, String> userdata) throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException {
     
    4566        }
    4667
     68        /**
     69         * Generates a intergalaictic number for a specified user and emails that number using the specified email.
     70         * @param userData
     71         */
    4772        public static void generateAndDeliverIntergalacticNumber(Map<AuthenticationTag, String> userData) {
    4873                String username = userData.get(AuthenticationTag.Username);
     
    5782                        sb.append("If it was you who made this request, the following string of characters is your intergalactic number: " + intergalacticNumber + nl);
    5883                       
    59                         // Establish properties for email.
    60                         Properties properties = System.getProperties();
    61                         properties.setProperty("mail.transport.protocol", "smtp");
    62                         properties.setProperty("mail.smtp.host", "smtp.gmail.com");
    63                         properties.setProperty("mail.smtp.port", "465");
    64                         properties.setProperty("mail.smtp.starttls.enable", "true");
    65                         properties.setProperty("mail.smtp.auth", "true");
    66                         properties.setProperty("mail.smtp.debug", "true");
    67                         properties.setProperty("mail.smtp.auth", "true");
    68                         properties.setProperty("mail.smtp.socketFactory.port", "465");
    69                         properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    70                         properties.setProperty("mail.smtp.socketFactory.fallback", "false");
    71                        
    72                         Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
    73                                 @Override
    74                                 protected PasswordAuthentication getPasswordAuthentication() {
    75                                         return new PasswordAuthentication("noreply.expeditee", "intergalacticnumber");
    76                                 };
    77                         });
    78                        
    79                         // construct email message
    80                         final MimeMessage message = new MimeMessage(session);
    81                         message.setFrom(new InternetAddress("[email protected]"));
    82                         message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
    83                         message.setSubject("Expeditee Password Recovery");
    84                         message.setText(sb.toString());
    85                        
    86                         // send email message
    87                         Transport.send(message);               
     84                        sendEmail(email, sb);           
    8885                } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | ClassNotFoundException
    8986                                | IOException | SQLException | MessagingException e) {
     
    9289        }
    9390       
    94         public static void confirmIntergalacticNumberAndAlertColleagues(Map<AuthenticationTag, String> userData, String[] colleagues) {
    95                 System.err.println("Colleague One: " + colleagues[0] + " @" + colleagues[2]);
    96                 System.err.println("Colleague Two: " + colleagues[1] + " @" + colleagues[3]);
     91        /**
     92         * Confirms that the specified intergalaictic number matches the one of file for the specified username.
     93         * Passing this test it then alerts the users pw colleagues through a one-off secure Expeditee message.
     94         * @param tags
     95         */
     96        public static void confirmIntergalacticNumberAndAlertColleagues(Map<AuthenticationTag, String> tags) {
     97                // Confirm intergalactic numbers match
     98                String username = tags.get(AuthenticationTag.Username);
     99                String intergalacticNumber = tags.get(AuthenticationTag.IntergalacticNumber);
     100                boolean match = false;
     101                try {
     102                        match = AuthenticatorBrowser.getInstance().confirmIntergalaticNumber(username, intergalacticNumber);
     103                } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | ClassNotFoundException
     104                                | IOException | SQLException e) {
     105                        e.printStackTrace();
     106                        return;
     107                }
     108                if (!match) {
     109                        MessageBay.errorMessage("The provided identity number does not match the one stored on file.");
     110                        return;
     111                }
     112               
     113                // Get colleagues to distribute messages too.
     114                String[] colleagues = getPasswordColleaguesFromUsername(username);
     115                //      Send secure message to colleague one
     116                String colleagueOne = colleagues[0];
     117                String time = Formatter.getDateTime();
     118                String topic = "Password Recovery for " + username;
     119                String message = "Your colleague " + username + " would like you to help them recover access to their account.";
     120                Map<String, String> options = new HashMap<String, String>();
     121                options.put("Provide assistance", "AuthEmailPasswordShare " + username);
     122                MailEntry mail = new MailEntry(time, username, colleagueOne, topic, message, options);
     123                Mail.sendOneOffMail(mail, colleagueOne, Base64.getDecoder().decode(intergalacticNumber));
     124               
     125                //      Send secure message to colleague two
     126                String colleagueTwo = colleagues[1];
     127                Mail.sendOneOffMail(mail, colleagueTwo, Base64.getDecoder().decode(intergalacticNumber));
     128               
     129                String nl = System.getProperty("line.separator");
     130                StringBuilder sb = new StringBuilder();
     131                sb.append("You are receiving this email because one of your Expeditee contacts has sent you a one-off secure message." + nl);
     132                sb.append("When you log into Expeditee and check your mail it will be there waiting for you." + nl);
     133                sb.append("You will need the following key to read this message: " + nl);
     134                sb.append(intergalacticNumber);
     135                try {
     136                        //      Send email with key to colleague one
     137                        String colleagueOneEmail = colleagues[2];
     138                        sendEmail(colleagueOneEmail, sb);
     139                        //      Send email with key to colleague two
     140                        String colleagueTwoEmail = colleagues[3];
     141                        sendEmail(colleagueTwoEmail, sb);
     142                } catch (MessagingException e) {
     143                        e.printStackTrace();
     144                }               
     145        }
     146       
     147        private static String[] getPasswordColleaguesFromUsername(String username) {
     148                Path credentialsFilePath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve("pwcolleagues.inf");
     149                String fileName = null;
     150                if (credentialsFilePath.toFile().exists()) {
     151                        try (Scanner in = new Scanner(credentialsFilePath)) {
     152                                fileName = in.nextLine();
     153                        } catch (IOException e) {
     154                                MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
     155                                return null;
     156                        }
     157                } else {
     158                        MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?");
     159                        return null;
     160                }
     161               
     162                int number = Integer.parseInt(fileName.replace(".exp", ""));
     163                Frame pwColleagueFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
     164                Collection<Text> textItems = pwColleagueFrame.getTextItems();
     165                textItems.removeIf(text -> !text.getText().startsWith("Colleague"));
     166               
     167                String[] ret = new String[4];
     168                Iterator<Text> it = textItems.iterator();
     169                while(it.hasNext()) {
     170                        String content = it.next().getText().toLowerCase().trim();
     171                        if (content.contains("colleague_one:")) {
     172                                ret[0] = content.replace("colleague_one:", "").trim();
     173                        } else if (content.contains("colleague_two:")) {
     174                                ret[1] = content.replace("colleague_two:", "").trim();
     175                        }
     176                }
     177                               
     178                // find colleague one email
     179                Path credentialsDirectoryPath = UserSettings.PublicAndPrivateResources
     180                                ? Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-" + username)
     181                                : Paths.get(FrameIO.PARENT_FOLDER);
     182                credentialsDirectoryPath = credentialsDirectoryPath.resolve("contacts").resolve(ret[0] + "-credentials");
     183                try (Scanner in = new Scanner(credentialsDirectoryPath.resolve("credentials.inf").toFile())) {
     184                        int parseInt = Integer.parseInt(in.nextLine().replace(".exp", ""));
     185                        Frame frame = FrameIO.LoadFrame(ret[0] + "-credentials" + parseInt, credentialsDirectoryPath.toAbsolutePath().getParent().toString() + File.separator);
     186                        textItems = frame.getTextItems();
     187                        textItems.removeIf(text -> !text.getText().startsWith("Email:"));
     188                        ret[2] = textItems.iterator().next().getText().replace("Email:", "").trim();
     189                } catch (FileNotFoundException e) {
     190                        MessageBay.errorMessage("You do not appear to have contact with your nominated password colleague: " + ret[0]);
     191                        return null;
     192                }
     193               
     194               
     195                // find colleague two email
     196                credentialsDirectoryPath = UserSettings.PublicAndPrivateResources
     197                                ? Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-" + username)
     198                                : Paths.get(FrameIO.PARENT_FOLDER);
     199                credentialsDirectoryPath = credentialsDirectoryPath.resolve("contacts").resolve(ret[1] + "-credentials");
     200                try (Scanner in = new Scanner(credentialsDirectoryPath.resolve("credentials.inf").toFile())) {
     201                        int parseInt = Integer.parseInt(in.nextLine().replace(".exp", ""));
     202                        Frame frame = FrameIO.LoadFrame(ret[1] + "-credentials" + parseInt, credentialsDirectoryPath.toAbsolutePath().getParent().toString() + File.separator);
     203                        textItems = frame.getTextItems();
     204                        textItems.removeIf(text -> !text.getText().startsWith("Email:"));
     205                        ret[3] = textItems.iterator().next().getText().replace("Email:", "").trim();
     206                } catch (FileNotFoundException e) {
     207                        MessageBay.errorMessage("You do not appear to have contact with your nominated password colleague: " + ret[1]);
     208                        return null;
     209                }
     210               
     211                return ret;
     212        }
     213       
     214
     215        public static void sendEmail(String email, StringBuilder sb) throws MessagingException, AddressException {
     216                // Establish properties for email.
     217                Properties properties = System.getProperties();
     218                properties.setProperty("mail.transport.protocol", "smtp");
     219                properties.setProperty("mail.smtp.host", "smtp.gmail.com");
     220                properties.setProperty("mail.smtp.port", "465");
     221                properties.setProperty("mail.smtp.starttls.enable", "true");
     222                properties.setProperty("mail.smtp.auth", "true");
     223                properties.setProperty("mail.smtp.debug", "true");
     224                properties.setProperty("mail.smtp.auth", "true");
     225                properties.setProperty("mail.smtp.socketFactory.port", "465");
     226                properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
     227                properties.setProperty("mail.smtp.socketFactory.fallback", "false");
     228               
     229                Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
     230                        @Override
     231                        protected PasswordAuthentication getPasswordAuthentication() {
     232                                return new PasswordAuthentication("noreply.expeditee", "intergalacticnumber");
     233                        };
     234                });
     235               
     236                // construct email message
     237                final MimeMessage message = new MimeMessage(session);
     238                message.setFrom(new InternetAddress("[email protected]"));
     239                message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
     240                message.setSubject("Expeditee Password Recovery");
     241                message.setText(sb.toString());
     242               
     243                // send email message
     244                Transport.send(message);
     245        }
     246
     247        public static void setPWColleagues(String colleagueOne, String colleagueTwo) {
     248                // Get needed text items.
     249                Frame pwRecoveryFrame = FrameIO.LoadFrame(UserSettings.UserName.get() + AuthenticatorBrowser.PASSWORD_RECOVERY_FRAME);
     250                Collection<Text> textItems = pwRecoveryFrame.getTextItems();
     251                textItems.removeIf(t -> !t.getText().toLowerCase().startsWith("colleague"));
     252               
     253                // Find colleague one and two text items.  Set appropriate values.
     254                Iterator<Text> it = textItems.iterator();
     255                while (it.hasNext()) {
     256                        Text text = it.next();
     257                        if (text.getText().toLowerCase().startsWith("colleague_one:")) {
     258                                text.setText("Colleague_one: " + colleagueOne);
     259                                Colleagues.Colleague_One.set(colleagueOne);
     260                        } else if (text.getText().toLowerCase().startsWith("colleague_two:")) {
     261                                text.setText("Colleague_two:" + colleagueTwo);
     262                                Colleagues.Colleague_Two.set(colleagueTwo);
     263                        }
     264                }
     265                FrameIO.ForceSaveFrame(pwRecoveryFrame);
     266               
     267                // Key to split and distribute
     268                String fullKey = KeyList.PersonalKey.get().getData().get(0);
     269                byte[] keyBytes = Base64.getDecoder().decode(fullKey);
     270               
     271                // Initialise Shamir
     272                int totalShares = 2;
     273                int requiredShares = 2;
     274                Scheme scheme = new Scheme(new SecureRandom(), totalShares, requiredShares);
     275               
     276                // Create shares
     277                Map<Integer, byte[]> shares = scheme.split(keyBytes);
     278                String colleagueOneShare = Base64.getEncoder().encodeToString(shares.get(1));
     279                String colleagueTwoShare = Base64.getEncoder().encodeToString(shares.get(2));
     280               
     281                // Distribute share zero to colleague one
     282                String time = org.expeditee.stats.Formatter.getDateTime();
     283                String sender = UserSettings.UserName.get();
     284                String topic = "Please help me secure my Expeditee account.";
     285                String message = "Run the below action to store a secret key that will help me recover access to my account should I ever loose it.";
     286                Map<String, String> options = new HashMap<String, String>();
     287                options.put("Store Secret Key for " + sender, "AuthAddSecretKey " + sender + "PersonalKeyShare " + colleagueOneShare);
     288                MailEntry mail = new MailEntry(time, sender, colleagueOne, topic, message, options);
     289                Mail.sendMail(mail, colleagueOne);
     290               
     291                // Distribute share one to colleague two
     292                options = new HashMap<String, String>();
     293                options.put("Store Secret Key for " + sender, "AuthAddSecretKey " + sender + "PersonalKeyShare " + colleagueTwoShare);
     294                mail = new MailEntry(time, sender, colleagueTwo, topic, message, options);
     295                Mail.sendMail(mail, colleagueTwo);
     296               
     297                MessageBay.displayMessage("PW Colleagues Set");
     298        }
     299
     300        public static void emailPasswordShare(String colleagueName) {
     301                Path credentialsDirectoryPath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueName + "-credentials");
     302                String colleagueEmail = null;
     303                try (Scanner in = new Scanner(credentialsDirectoryPath.resolve("credentials.inf").toFile())) {
     304                        int parseInt = Integer.parseInt(in.nextLine().replace(".exp", ""));
     305                        Frame frame = FrameIO.LoadFrame(colleagueName + "-credentials" + parseInt, credentialsDirectoryPath.toAbsolutePath().getParent().toString() + File.separator);
     306                        Collection<Text> textItems = frame.getTextItems();
     307                        textItems.removeIf(text -> !text.getText().startsWith("Email:"));
     308                        colleagueEmail = textItems.iterator().next().getText().replace("Email:", "").trim();
     309                } catch (FileNotFoundException e) {
     310                        MessageBay.errorMessage("You do not appear to have contact with: " + colleagueName);
     311                        return;
     312                }
     313               
     314                Frame secretsFrame = FrameIO.LoadFrame(UserSettings.UserName.get() + AuthenticatorBrowser.SECRETS_FRAME);
     315                Collection<Text> textItems = secretsFrame.getTextItems();
     316                textItems.removeIf(text -> !text.getText().toLowerCase().equals(colleagueName + "personalkeyshare"));
     317                String key = textItems.iterator().next().getData().get(0);
     318               
     319                String nl = System.getProperty("line.separator");
     320                StringBuilder sb = new StringBuilder();
     321                sb.append("In responce to your request for assistance regaining access to your Expeditee account, your colleague " + UserSettings.UserName.get() + " has provided you with the following key share:" + nl);
     322                sb.append(key + nl);
     323               
     324                try {
     325                        sendEmail(colleagueEmail, sb);
     326                } catch (MessagingException e) {
     327                        MessageBay.errorMessage("An error occured sending a email to your colleage " + colleagueName + " with the email " + colleagueEmail);
     328                }
     329        }
     330
     331        public static void regainAccountAccess(Map<AuthenticationTag, String> userData) {
     332                // Store shares in map
     333                Map<Integer, byte[]> contributingParts = new HashMap<Integer, byte[]>();
     334                contributingParts.put(1, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceOne)));
     335                contributingParts.put(2, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceTwo)));
     336               
     337                // initialise shamir
     338                int totalShares = 2;
     339                int requiredShares = 2;
     340                Scheme scheme = new Scheme(new SecureRandom(), totalShares, requiredShares);
     341               
     342                // perform joining
     343                byte[] join = scheme.join(contributingParts);
     344               
     345                try {
     346                        AuthenticatorBrowser.getInstance().putKey(userData.get(AuthenticationTag.Username), userData.get(AuthenticationTag.NewPassword), new SecretKeySpec(join, SymmetricAlgorithm));
     347                } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | ClassNotFoundException
     348                                | IOException | SQLException e) {
     349                        e.printStackTrace();
     350                }
     351               
     352                MessageBay.displayMessage("Your new password has been set.");
    97353        }
    98354}
  • trunk/src/org/expeditee/auth/mail/Mail.java

    r1362 r1363  
    1 package org.expeditee.auth;
     1package org.expeditee.auth.mail;
    22
    33import java.io.File;
     
    3636import javax.crypto.spec.SecretKeySpec;
    3737
    38 import org.expeditee.auth.gui.MailBay;
     38import org.expeditee.auth.AuthenticatorBrowser;
     39import org.expeditee.auth.mail.gui.MailBay;
     40import org.expeditee.encryption.Actions;
    3941import org.expeditee.gui.FrameIO;
    4042import org.expeditee.settings.UserSettings;
     
    5860        public static void sendOneOffMail(MailEntry mail, String colleagueName, byte[] key) {
    5961                // Ensure dead drop area is set up.
    60                 Path databaseFileDirPath = ensureDeadDrops(colleagueName);
     62                Path databaseFileDirPath = ensureDeadDrops(colleagueName, mail.sender);
    6163               
    6264                // Ensure the database file exists.
     
    136138        }
    137139       
     140        private static Path ensureDeadDrops(String colleagueName, String sender) {
     141                String me = sender.toLowerCase();
     142                String them = colleagueName.toLowerCase();
     143                Path parent = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-" + sender).resolve("deaddrops");
     144                Path databaseFileDirPath = parent.resolve(me + "+" + them);
     145                if (!databaseFileDirPath.toFile().exists()) {
     146                        databaseFileDirPath = parent.resolve(them + "+" + me);
     147                }
     148                return databaseFileDirPath;
     149        }
     150       
    138151        private static void sendMail(MailEntry mail, PublicKey key, Path databaseFile) {
    139152                try {
     
    209222                statement.close();
    210223                c.close();
     224                System.err.println("Message written to database: " + databaseFile.toString());
    211225        }
    212226               
     
    235249                sb.append("Read one-off secure message." + sep);
    236250                sb.append(mail.timestamp + sep);
    237                 sb.append(mail.sender + sep);
     251                sb.append(mail.sender.substring(1) + sep);
    238252                sb.append(mail.receiver + sep);
    239253                sb.append(mail.message + sep);
     
    368382                }
    369383        }
     384
     385        public static void decryptOneOffSecureMessage(SecretKey key, List<String> data) {
     386                byte[] topicBytes = Base64.getDecoder().decode(data.get(3));
     387                String topic = new String(org.expeditee.encryption.Actions.DecryptSymmetric(topicBytes, key));
     388                byte[] messageBytes = Base64.getDecoder().decode(data.get(4));
     389                String message = new String(org.expeditee.encryption.Actions.DecryptSymmetric(messageBytes, key));
     390                Map<String, String> options = new HashMap<String, String>();
     391                for (int i = 5; i < data.size(); i+=2) {
     392                        byte[] optionKeyBytes = Base64.getDecoder().decode(data.get(i));
     393                        String k = new String(org.expeditee.encryption.Actions.DecryptSymmetric(optionKeyBytes, key));
     394                        byte[] optionValueBytes = Base64.getDecoder().decode(data.get(i + 1));
     395                        String v = new String(org.expeditee.encryption.Actions.DecryptSymmetric(optionValueBytes, key));
     396                        options.put(k, v);
     397                }
     398                MailBay.addMessage(data.get(0), topic, message, options);
     399        }
    370400}
  • trunk/src/org/expeditee/auth/mail/gui/MailBay.java

    r1362 r1363  
    1 package org.expeditee.auth.gui;
     1package org.expeditee.auth.mail.gui;
    22
    33import java.util.LinkedList;
  • trunk/src/org/expeditee/auth/tags/AuthenticationTag.java

    r1346 r1363  
    1919        ColleagueTwo ("txtColleagueTwo", System.getProperty("user.colleague.two")),
    2020        Frameset ("txtFrameset", System.getProperty("user.toshare.frameset")),
    21         IntergalacticNumber ("txtIntergalacticNumber", System.getProperty("user.intergalacticnumber"));
     21        IntergalacticNumber ("txtIntergalacticNumber", System.getProperty("user.intergalacticnumber")),
     22        PasswordSliceOne ("txtPasswordPieceOne", System.getProperty("user.password.piece.one")),
     23        PasswordSliceTwo ("txtPasswordPieceTwo", System.getProperty("user.password.piece.two"));
    2224       
    2325        public String val;
  • trunk/src/org/expeditee/encryption/Actions.java

    r1362 r1363  
    1 package org.expeditee.auth.sharing;
     1package org.expeditee.encryption;
    22
    33import java.security.InvalidKeyException;
     
    1919import javax.crypto.spec.SecretKeySpec;
    2020
     21import org.expeditee.auth.AuthenticatorBrowser;
    2122import org.expeditee.gui.DisplayController;
    2223import org.expeditee.gui.Frame;
    2324import org.expeditee.gui.FrameIO;
    2425import org.expeditee.items.Text;
     26import org.expeditee.settings.UserSettings;
    2527import org.ngikm.cryptography.CryptographyConstants;
    2628
     
    190192                }
    191193        }
     194
     195        public static void AuthAddSecretKey(String name, String data) {
     196                Frame secretsFrame = FrameIO.LoadFrame(UserSettings.UserName.get() + AuthenticatorBrowser.SECRETS_FRAME);
     197                secretsFrame.addText(500, 500, name, null).addToData(data);
     198        }
    192199}
  • trunk/src/org/expeditee/gui/DisplayController.java

    r1314 r1363  
    2828import java.util.function.BooleanSupplier;
    2929
    30 import org.expeditee.auth.gui.MailBay;
     30import org.expeditee.auth.mail.gui.MailBay;
    3131import org.expeditee.core.Clip;
    3232import org.expeditee.core.Colour;
  • trunk/src/org/expeditee/gui/FrameIO.java

    r1357 r1363  
    5555import org.expeditee.auth.EncryptedExpReader;
    5656import org.expeditee.auth.EncryptedExpWriter;
    57 import org.expeditee.auth.gui.MailBay;
     57import org.expeditee.auth.mail.gui.MailBay;
    5858import org.expeditee.gio.EcosystemManager;
    5959import org.expeditee.io.Conversion;
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r1355 r1363  
    5555import org.expeditee.agents.InvalidFramesetNameException;
    5656import org.expeditee.auth.AuthenticatorBrowser;
    57 import org.expeditee.auth.gui.MailBay;
     57import org.expeditee.auth.mail.gui.MailBay;
    5858import org.expeditee.core.Colour;
    5959import org.expeditee.core.Point;
  • trunk/src/org/expeditee/settings/identity/passwordrecovery/Colleagues.java

    r1352 r1363  
    66        public static final StringSetting Colleague_One = new StringSetting("Your first password recovery colleague.", null);
    77        public static final StringSetting Colleague_Two = new StringSetting("Your second password recovery colleague.", null);
    8        
    9         public static final StringSetting Colleague_One_Email = new StringSetting("Your first password recovery colleagues public facing email.", null);
    10         public static final StringSetting Colleague_Two_Email = new StringSetting("Your second password recovery colleagues public facing email.", null);
    118}
Note: See TracChangeset for help on using the changeset viewer.