source: trunk/src/org/expeditee/auth/Actions.java@ 1386

Last change on this file since 1386 was 1386, checked in by bln4, 5 years ago
File size: 28.0 KB
Line 
1package org.expeditee.auth;
2
3import java.awt.Desktop;
4import java.io.File;
5import java.io.FileNotFoundException;
6import java.io.IOException;
7import java.net.URI;
8import java.net.URISyntaxException;
9import java.net.URL;
10import java.nio.file.Files;
11import java.nio.file.Path;
12import java.nio.file.Paths;
13import java.nio.file.StandardCopyOption;
14import java.security.InvalidKeyException;
15import java.security.KeyFactory;
16import java.security.KeyStoreException;
17import java.security.NoSuchAlgorithmException;
18import java.security.PrivateKey;
19import java.security.PublicKey;
20import java.security.SecureRandom;
21import java.security.cert.CertificateException;
22import java.security.spec.InvalidKeySpecException;
23import java.security.spec.PKCS8EncodedKeySpec;
24import java.sql.SQLException;
25import java.text.ParseException;
26import java.util.Base64;
27import java.util.Collection;
28import java.util.HashMap;
29import java.util.List;
30import java.util.Map;
31import java.util.Optional;
32import java.util.Random;
33import java.util.Scanner;
34import java.util.stream.Collectors;
35
36import javax.crypto.BadPaddingException;
37import javax.crypto.IllegalBlockSizeException;
38import javax.crypto.NoSuchPaddingException;
39import javax.crypto.SecretKey;
40import javax.crypto.spec.SecretKeySpec;
41
42import org.expeditee.agents.ExistingFramesetException;
43import org.expeditee.agents.InvalidFramesetNameException;
44import org.expeditee.auth.account.Authenticate;
45import org.expeditee.auth.account.Authenticate.AuthenticationResult;
46import org.expeditee.auth.account.Create;
47import org.expeditee.auth.account.Create.CreateResult;
48import org.expeditee.auth.account.Password;
49import org.expeditee.auth.mail.Mail;
50import org.expeditee.auth.mail.Mail.MailEntry;
51import org.expeditee.auth.mail.gui.MailBay;
52import org.expeditee.auth.tags.AuthenticationTag;
53import org.expeditee.gio.gesture.StandardGestureActions;
54import org.expeditee.gui.DisplayController;
55import org.expeditee.gui.Frame;
56import org.expeditee.gui.FrameIO;
57import org.expeditee.gui.MessageBay;
58import org.expeditee.items.Item;
59import org.expeditee.items.Text;
60import org.expeditee.settings.UserSettings;
61import org.expeditee.settings.identity.secrets.KeyList;
62import org.expeditee.stats.Formatter;
63import org.ngikm.cryptography.CryptographyConstants;
64
65public class Actions implements CryptographyConstants {
66
67 // Start Debug Actions
68 public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException {
69 String time = org.expeditee.stats.Formatter.getDateTime();
70 String sender = UserSettings.UserName.get();
71 String topic = "Test Message";
72 String message = "This is a test message.";
73 Map<String, String> options = new HashMap<String, String>();
74 options.put("Neat", "Beep");
75 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
76 Mail.sendMail(mail, colleagueName);
77 MessageBay.displayMessage("Test message sent.");
78 }
79
80 public static void SendTestMessageHemi(String param) {
81 String time = Formatter.getDateTime();
82 String sender = UserSettings.UserName.get();
83 String recipient = param.split(" ")[0];
84 String message = param.split(" ")[1];
85 Map<String, String> options = new HashMap<String, String>();
86 options.put("Accept", "beep");
87 options.put("Reject", "beep");
88 MailEntry mail = new MailEntry(time, sender, recipient, "Have a key", message, options);
89 Mail.sendMail(mail, recipient);
90 MessageBay.displayMessage("Test message sent.");
91 }
92
93 public static void SendTestOneOffMessage(String colleagueName) {
94 String time = Formatter.getDateTime();
95 String sender = UserSettings.UserName.get();
96 String topic = "Test Message";
97 String message = "This is a test message.";
98 Map<String, String> options = new HashMap<String, String>();
99 options.put("Neat", "Beep");
100 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);
101 Random rand = new SecureRandom();
102 byte[] key = new byte[16];
103 rand.nextBytes(key);
104 System.out.println(Base64.getEncoder().encodeToString(key));
105 Mail.sendOneOffMail(mail, colleagueName, key);
106 }
107
108 private static String userbackup = "authadmin";
109 public static void ToggleAuth() {
110 String backup = UserSettings.UserName.get();
111 UserSettings.UserName.set(userbackup);
112 userbackup = backup;
113 }
114 // End Debug Actions
115
116 // Start Misc Auth Actions
117 /**
118 * Action ran by user to read a message using a single use distributed Symmetric key
119 * @param cursor The content on the cursor should be a text item whose content is the
120 * Symmetric key to use, represented as a Base64 encoded string.
121 * @param actionItem The action item will contain the encrypted message in its data.
122 */
123 public static void AuthOneOffSecureMessage(Text cursor, Text actionItem) {
124 byte[] keyBytes = Base64.getDecoder().decode(cursor.getText());
125 SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm);
126 List<String> data = actionItem.getData();
127 Mail.decryptOneOffSecureMessage(key, data);
128 StandardGestureActions.Refresh();
129 }
130
131 /**
132 * Display Expeditee Mail
133 * @throws IOException
134 * @throws SQLException
135 * @throws ClassNotFoundException
136 * @throws CertificateException
137 * @throws NoSuchAlgorithmException
138 * @throws FileNotFoundException
139 * @throws KeyStoreException
140 * @throws ParseException
141 * @throws InvalidKeySpecException
142 * @throws BadPaddingException
143 * @throws IllegalBlockSizeException
144 * @throws NoSuchPaddingException
145 * @throws InvalidKeyException
146 */
147 public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
148 if (!AuthenticatorBrowser.isAuthenticated()) return;
149 if (!DisplayController.isMailMode()) {
150 MailBay.ensureLink();
151 Mail.clear();
152 String keyEncoded = KeyList.PrivateKey.get().getData().get(0);
153 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);
154 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
155 Mail.checkMail(key);
156 }
157 DisplayController.ToggleMailMode();
158 }
159
160 /**
161 * Action used to navigate the authorised user back to their desktop.
162 */
163 public static void AuthGoToDesktop() {
164 if (AuthenticatorBrowser.Authenticated) {
165 DisplayController.setCurrentFrame(FrameIO.LoadFrame(UserSettings.HomeFrame.get()), true);
166 } else {
167 MessageBay.displayMessage("Please Login to proceed to your home frame.");
168 DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), true);
169 }
170 }
171
172 /**
173 * Action used to navigate to multiuser1 (multiuser abilities) if authenticated and authentication1 (login) is not so.
174 */
175 public static void AuthGotoAccountManagement() {
176 if (AuthenticatorBrowser.Authenticated) {
177 DisplayController.setCurrentFrame(FrameIO.LoadFrame("multiuser1"), true);
178 } else {
179 MessageBay.displayMessage("Please Login to proceed to account managment.");
180 DisplayController.setCurrentFrame(FrameIO.LoadFrame("authentication1"), true);
181 }
182 }
183
184 /**
185 * Gets all items on a specified frame that contain the specified data.
186 */
187 public static Collection<Item> getByData(Frame frame, String data) {
188 Collection<Item> allItems = frame.getAllItems();
189 allItems.removeIf(i -> i.getData() == null || !i.hasData(data));
190 return allItems;
191 }
192
193 /**
194 * Gets all items on a specified frame that contains the specified content.
195 */
196 public static Collection<Item> getByContent(Frame frame, String content) {
197 Collection<Item> allItems = frame.getAllItems();
198 allItems.removeIf(i -> i.getText().compareTo(content) != 0);
199 return allItems;
200 }
201 // End Misc Auth Actions
202
203 // Start Making Contacts Actions
204 public static void AuthDistributeContactDetails() {
205 MessageBay.displayMessage(
206 "To receive directions on distributing your contact details to someone, attach their username to your cursor and run this action again."
207 );
208 }
209 public static String AuthDistributeContactDetails(String username) {
210 StringBuilder sb = new StringBuilder();
211 String nl = System.getProperty("line.separator");
212 String me = UserSettings.UserName.get();
213 Path profilePath = Paths.get(FrameIO.PROFILE_PATH).resolve(me);
214 try {
215 Desktop.getDesktop().open(profilePath.toFile());
216 sb.append("1. We have opened your profile directory for you. Tab to it and right click on the " + me + "-credentials directory." + nl);
217 } catch (IOException e) {
218 sb.append("1. Open your profile directory (" + profilePath + ") and right click on the " + me + "-credentials directory." + nl);
219 }
220
221 sb.append("2. Click on 'Share with Google Drive'." + nl);
222 sb.append("3. Enter " + username + "'s in the text box." + nl);
223 sb.append("4. Click on the button to the right of the text box in order to set the share to 'View Only'." + nl);
224 sb.append("5. Optionally add a note for " + username + " to read. Click the send button.");
225
226 return sb.toString();
227 }
228 public static void AuthAddContactDetails() {
229 MessageBay.displayMessage("If a user has sent their contact details to you, running this action again with their username attached to your cursor will display instructions to adding those details to your contacts directory.");
230 }
231 public static String AuthAddContactDetails(String username) {
232 StringBuilder sb = new StringBuilder();
233 String nl = System.getProperty("line.separator");
234 String me = UserSettings.UserName.get();
235 String driveSharedWithMeString = "https://drive.google.com/drive/shared-with-me";
236 try {
237 URI driveSharedWithMeURL = new URL(driveSharedWithMeString).toURI();
238 Desktop.getDesktop().browse(driveSharedWithMeURL);
239 sb.append("1. We have opened Google Drive to the 'Shared With Me' page in your browser. Right click on " + username + "-credentials and click on 'Add To My Drive'." + nl);
240 } catch (IOException | URISyntaxException e) {
241 sb.append("1. Open your web browser to " + driveSharedWithMeString + ". Right click on " + username + "-credentials and click on 'Add To My Drive'." + nl);
242 }
243
244 sb.append("2. Click organise and navigate the dialog to resources-" + me + "/contacts and click the 'Move Here' button to relocate your copy of " + username + "'s credentials folder.");
245
246 return sb.toString();
247 }
248 // End Making Contacts Actions
249
250 // Start Regain Account Access Actions
251 /**
252 * Action used to start the process of formalising the password recovery process.
253 * @throws SQLException
254 * @throws IOException
255 * @throws ClassNotFoundException
256 * @throws CertificateException
257 * @throws NoSuchAlgorithmException
258 * @throws FileNotFoundException
259 * @throws KeyStoreException
260 * @throws InvalidKeySpecException
261 */
262 public static void AuthSubmitTrustedUsersPasswordRecovery() throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
263 Frame currentFrame = DisplayController.getCurrentFrame();
264 Collection<Text> textItems = currentFrame.getTextItems();
265
266 if (!AuthenticatorBrowser.Authenticated) {
267 MessageBay.errorMessage("You must be logged in to perform this action.");
268 return;
269 }
270
271 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.TrustedUserOne, AuthenticationTag.TrustedUserTwo);
272 if (userdata.isPresent()) {
273 Map<AuthenticationTag, String> userData = userdata.get();
274 String colleagueOne = userData.get(AuthenticationTag.TrustedUserOne);
275 String colleagueTwo = userData.get(AuthenticationTag.TrustedUserTwo);
276 AuthSubmitTrustedUsersPasswordRecovery(colleagueOne, colleagueTwo);
277// Path colleagueOnePath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueOne + "-credentials");
278// Path colleagueTwoPath = Paths.get(FrameIO.CONTACTS_PATH).resolve(colleagueTwo + "-credentials");
279// if (!colleagueOnePath.toFile().exists()) {
280// MessageBay.errorMessage("Your nominated trusted user: " + colleagueOne + " must exist in your contacts.");
281// } else if (!colleagueTwoPath.toFile().exists()) {
282// MessageBay.errorMessage("Your nominated trusted user: " + colleagueTwo + " must exist in your contacts.");
283// } else {
284// userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
285// boolean success = submitTrustedUsersPasswordRecovery(userData);
286// if (success) {
287// Collection<Item> toShow = getByData(currentFrame, "ShowOnProgress");
288// for (Item i: toShow) {
289// i.setVisible(true);
290// }
291// currentFrame.change();
292// MessageBay.displayMessage("-------Messages sent-------");
293// }
294// FrameIO.SaveFrame(currentFrame);
295// DisplayController.requestRefresh(false);
296// }
297 }
298 }
299
300 /**
301 * Action ran by user to specify who their password colleagues are. These are the
302 * individuals who will be consulted if and when the user needs to regain access
303 * to their account.
304 * @param colleagueOne
305 * @param colleagueTwo
306 */
307 public static void AuthSubmitTrustedUsersPasswordRecovery(String colleagueOne, String colleagueTwo) {
308 Password.setPWColleagues(colleagueOne, colleagueTwo);
309 }
310
311 /**
312 * Action ran by user to oblige with a request from colleague who has nominated the
313 * user as a pw colleague. Will email (not Expeditee mail) the colleague the password
314 * share that the user has stored on their secrets frame.
315 * @param colleagueName
316 */
317 public static void AuthEmailPasswordShare(String colleagueName) {
318 Password.emailPasswordShare(colleagueName);
319 }
320
321 /**
322 * Action ran by user to regain access to their account by providing:
323 * their username
324 * two password shares obtained from pw colleagues
325 * their desired new password
326 */
327 public static void AuthRegainAccountAccess() {
328 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
329 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false,
330 AuthenticationTag.Username, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain,
331 AuthenticationTag.PasswordSliceOne, AuthenticationTag.PasswordSliceTwo);
332 if (userdata.isPresent()) {
333 // Confirm new requested passwords match
334 Map<AuthenticationTag, String> userData = userdata.get();
335 if (!userData.get(AuthenticationTag.NewPassword).equals(userData.get(AuthenticationTag.NewPasswordAgain))) {
336 MessageBay.errorMessage("The passwords you have provided do not match.");
337 return;
338 }
339
340 Password.regainAccountAccess(userData);
341 }
342 }
343
344 /**
345 * Actions used to generate and deliver an intergalactic number to a users public email
346 * address after they have began the password recovery process.
347 */
348 public static void AuthDistributeIntergalacticNumber() {
349 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
350 Optional<Map<AuthenticationTag, String>> userdata =
351 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
352 if (userdata.isPresent()) {
353 Map<AuthenticationTag, String> userData = userdata.get();
354 String username = userData.get(AuthenticationTag.Username);
355 String email = getEmailFromUsername(username);
356 userData.put(AuthenticationTag.Email, email);
357 Password.generateAndDeliverIntergalacticNumber(userData);
358 MessageBay.displayMessage("A identity number has been sent to the email "
359 + "associated with your account. Enter it below to proceed.");
360 }
361 }
362
363 /**
364 * Action used by user to submit their intergalactic number along with their username
365 * in order to confirm that they own the public email address registered to their account.
366 * This is part of the process of recoverying access to an account.
367 */
368 public static void AuthSubmitIntergalacticNumber() {
369 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
370 Optional<Map<AuthenticationTag, String>> userdata =
371 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username,
372 AuthenticationTag.IntergalacticNumber);
373 if (userdata.isPresent()) {
374 Password.confirmIntergalacticNumberAndAlertTrustedUsers(userdata.get());
375 }
376 }
377 // End Regain Account Access Actions
378
379 // Start Create Account Actions
380 /**
381 * Action used to created a new user account.
382 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
383 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
384 * @throws SQLException
385 * @throws IOException
386 * @throws ExistingFramesetException
387 * @throws InvalidFramesetNameException
388 * @throws ClassNotFoundException
389 * @throws FileNotFoundException
390 * @throws CertificateException
391 * @throws NoSuchAlgorithmException
392 * @throws KeyStoreException
393 * @throws BadPaddingException
394 * @throws IllegalBlockSizeException
395 * @throws NoSuchPaddingException
396 * @throws InvalidKeySpecException
397 * @throws InvalidKeyException
398 * @throws ParseException
399 * @throws Exception
400 */
401 public static void AuthCreateAccount() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, ClassNotFoundException, InvalidFramesetNameException, ExistingFramesetException, IOException, SQLException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, ParseException {
402 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
403 Optional<Map<AuthenticationTag, String>> userdata =
404 AuthenticationTag.fetchUserData(textItems, false,
405 AuthenticationTag.Username,
406 AuthenticationTag.Password,
407 AuthenticationTag.PasswordAgain,
408 AuthenticationTag.Email,
409 AuthenticationTag.EmailAgain);
410
411 if (userdata.isPresent()) {
412 Map<AuthenticationTag, String> userData = userdata.get();
413
414 // A profile already existing with 'username' means an account cannot be created with that username.
415 if (FrameIO.getProfilesList().contains(userData.get(AuthenticationTag.Username))) {
416 MessageBay.errorMessage("A Expeditee profile with this username already exists, please choose another.");
417 return;
418 }
419
420 // The chosen username must be a valid frameset name.
421 if (!FrameIO.isValidFramesetName(userData.get(AuthenticationTag.Username))) {
422 MessageBay.errorMessage("The provided username must begin and end with a letter and contain only letters and numbers inbetween, please choose another.");
423 return;
424 }
425
426 // The passwords provided must match
427 if (userData.get(AuthenticationTag.Password).compareTo(userData.get(AuthenticationTag.PasswordAgain)) != 0) {
428 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
429 return;
430 }
431
432 // The emails provided must match
433 if (userData.get(AuthenticationTag.Email).compareTo(userData.get(AuthenticationTag.EmailAgain)) != 0) {
434 MessageBay.errorMessage("The provided emails do not match, please fix this and try again.");
435 return;
436 }
437
438 CreateResult result = Create.createAccount(userData);
439 if (result == CreateResult.SuccessCreateAccount) {
440 Authenticate.login(userData);
441 AuthenticatorBrowser.Authenticated = true;
442 } else {
443 MessageBay.errorMessage(result.toString());
444 }
445 } else {
446 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
447 }
448 }
449 // End Create Account Actions
450
451 // Start Account Login Actions
452 /**
453 * Action used to start authentication as a specified user.
454 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
455 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
456 * @throws Exception
457 */
458 public static void AuthLogin() {
459 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
460 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);
461 if (userdata.isPresent()) {
462 AuthenticationResult result = Authenticate.login(userdata.get());
463 if (result == AuthenticationResult.SuccessLogin) {
464 MessageBay.displayMessage(result.toString());
465 AuthenticatorBrowser.Authenticated = true;
466 } else {
467 MessageBay.errorMessage(result.toString());
468 }
469 } else {
470 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
471 }
472 }
473
474 /**
475 * Action used by the user to log out of their account.
476 */
477 public static void AuthLogout() {
478 MessageBay.displayMessage(Authenticate.logout().toString());
479 }
480 // End Account Login Actions
481
482 // Start Change Access Actions
483 /**
484 * Action used to change the currently authenticated users password.
485 * Attempts to use content from text items on frame, will default to java properties if they cannot be found.
486 * Will fail if it cannot find content from text items on frame and all required java properties are not present.
487 * Will fail if no user is currently logged in.
488 * @throws IOException
489 * @throws CertificateException
490 * @throws FileNotFoundException
491 * @throws KeyStoreException
492 * @throws NoSuchAlgorithmException
493 * @throws SQLException
494 * @throws ClassNotFoundException
495 */
496 public static void AuthChangePassword() throws NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, IOException, ClassNotFoundException, SQLException {
497 final Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
498
499 if (!AuthenticatorBrowser.Authenticated) {
500 MessageBay.errorMessage("You must be logged in to perform this action.");
501 } else {
502 final Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Password, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain);
503 if (userdata.isPresent()) {
504 final Map<AuthenticationTag, String> userData = userdata.get();
505 if (userData.get(AuthenticationTag.NewPassword).compareTo(userData.get(AuthenticationTag.NewPasswordAgain)) != 0) {
506 MessageBay.errorMessage("The provided passwords do not match, please fix this and try again.");
507 } else {
508 userData.put(AuthenticationTag.Username, UserSettings.UserName.get());
509 Password.changePassword(userData);
510 }
511 } else {
512 MessageBay.errorMessage("Please fill out all the supplied text boxes.");
513 }
514 }
515 }
516 // End Change Access Actions
517
518 // Start Private Helper Functions.
519 /**
520 * Gets the public email address associated with the specified username.
521 * @param username
522 * @return
523 */
524 private static String getEmailFromUsername(String username) {
525 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
526 Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
527 String fileName = null;
528 if (credentialsFilePath.toFile().exists()) {
529 try (Scanner in = new Scanner(credentialsFilePath)) {
530 fileName = in.nextLine();
531 } catch (IOException e) {
532 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
533 return null;
534 }
535 } else {
536 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
537 return null;
538 }
539
540 int number = Integer.parseInt(fileName.replace(".exp", ""));
541 Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
542 Collection<Text> textItems = credentialsFrame.getTextItems();
543 textItems.removeIf(text -> !text.getText().startsWith("Email: "));
544 if (textItems.isEmpty()) {
545 MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
546 return null;
547 } else {
548 Text emailText = textItems.iterator().next();
549 String email = emailText.getText().replace("Email: ", "");
550 return email;
551 }
552 }
553 // End Private Helper Functions.
554
555 // Start Future Functionality
556 public static void AuthShareFrameset() throws IOException {
557 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
558
559 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Frameset);
560 if (userdata.isPresent()) {
561 Map<AuthenticationTag, String> userData = userdata.get();
562 FrameIO.SuspendCache();
563 Frame toShare = FrameIO.LoadFrame(userData.get(AuthenticationTag.Frameset) + 1);
564 FrameIO.ResumeCache();
565
566 if (toShare == null) {
567 MessageBay.errorMessage("Insufficient information provided to complete this action.");
568 return;
569 }
570
571 shareFrameset(toShare);
572 }
573 }
574
575 /*
576 * Function to share a specified frameset.
577 * 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.
578 */
579 private static void shareFrameset(Frame toShare) throws IOException {
580 File destinationDir = new File(FrameIO.SHARED_FRAMESETS_PATH + File.separator + toShare.getFramesetName());
581 File sourceDir = new File(toShare.getFramesetPath());
582
583 if (destinationDir.exists()) {
584 MessageBay.errorMessage("A frameset by this name already exists.");
585 return;
586 }
587
588 destinationDir.mkdir();
589 List<Path> files = Files.walk(sourceDir.toPath()).collect(Collectors.toList());
590 Files.move(files.get(0), destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE);
591
592 MessageBay.displayMessage("The frameset " + toShare.getFramesetName() + " has been moved to " + destinationDir + ". Google Drive functionality can now be used to share it with colleagues.");
593 }
594
595 /*
596 * Function to submit a request to specified contacts to be the current users pw colleagues.
597 */
598 @SuppressWarnings("unused")
599 private static boolean submitTrustedUsersPasswordRecovery(Map<AuthenticationTag, String> userData) throws InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, FileNotFoundException, CertificateException, ClassNotFoundException, IOException, SQLException {
600 String colleagueOne = userData.get(AuthenticationTag.TrustedUserOne);
601 String colleagueTwo = userData.get(AuthenticationTag.TrustedUserTwo);
602 PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueOne);
603 PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(colleagueTwo);
604 if (colleagueOneKey == null) {
605 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);
606 return false;
607 } else if (colleagueTwoKey == null) {
608 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueTwo);
609 return false;
610 } else {
611 String time = org.expeditee.stats.Formatter.getDateTime();
612 String sender = userData.get(AuthenticationTag.Username);
613 String topic = "You have received a request for cooperation from your colleague " + sender;
614 String message = "Should " + sender + " forget their password, they would like your help recoverying it.";
615 Map<String, String> arguments = new HashMap<String, String>();
616 arguments.put("I agree to assist " + sender + " if they loose access to their account.", "AuthConfirmPasswordColleagueRelationship " + sender);
617 arguments.put("I wish to excuse myself from this responsibility.", "AuthDenyPasswordColleagueRelationship " + sender);
618 MailEntry mail = new MailEntry(time, sender, colleagueOne, topic, message, arguments);
619 Mail.sendMail(mail, colleagueOne);
620 mail = new MailEntry(time, sender, colleagueTwo, topic, message, arguments);
621 Mail.sendMail(mail, colleagueTwo);
622 AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get());
623 return true;
624 }
625 }
626 // End Future Functionality
627}
Note: See TracBrowser for help on using the repository browser.