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

Last change on this file since 1494 was 1494, checked in by bnemhaus, 4 years ago

Preperation for David's presentation.

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