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

Last change on this file since 1492 was 1492, checked in by bnemhaus, 5 years ago

You cannot nominate yourself as one of your trusted colleagues for pw recovery.

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