Changeset 1504 for trunk/src/org/expeditee/auth/Actions.java
- Timestamp:
- 01/29/20 13:20:24 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/auth/Actions.java
r1494 r1504 9 9 import java.nio.file.StandardCopyOption; 10 10 import java.security.InvalidKeyException; 11 import java.security.KeyFactory;12 11 import java.security.KeyStoreException; 13 12 import java.security.NoSuchAlgorithmException; 14 import java.security.PrivateKey;15 13 import java.security.PublicKey; 16 14 import java.security.SecureRandom; 17 15 import java.security.cert.CertificateException; 18 16 import java.security.spec.InvalidKeySpecException; 19 import java.security.spec.PKCS8EncodedKeySpec;20 17 import java.sql.SQLException; 21 18 import java.text.ParseException; 22 19 import java.util.Base64; 23 20 import java.util.Collection; 21 import java.util.Date; 24 22 import java.util.HashMap; 25 23 import java.util.List; … … 57 55 import org.expeditee.items.Text; 58 56 import org.expeditee.settings.UserSettings; 59 import org.expeditee.settings.identity.secrets.KeyList;60 import org.expeditee.stats.Formatter;61 57 62 58 public class Actions implements CryptographyConstants { 63 64 // 65 public static void SendTestMessage(String colleagueName) throws InvalidKeySpecException, NoSuchAlgorithmException, FileNotFoundException, KeyStoreException, CertificateException, ClassNotFoundException, IOException, SQLException{66 String time = org.expeditee.stats.Formatter.getDateTime();59 60 // Start Debug Actions 61 public static void SendTestMessage(String recipient) { 62 String time = Mail.FORMAT.format(new Date()); 67 63 String sender = UserSettings.UserName.get(); 68 64 String topic = "Test Message"; … … 70 66 Map<String, String> options = new HashMap<String, String>(); 71 67 options.put("Neat", "Beep"); 72 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options); 73 Mail.sendMail(mail, colleagueName); 68 Mail mailClient = MailBay.getMailClient(); 69 Mail.MailEntry mail = mailClient.new MailEntry(time, sender, recipient, topic, message, options); 70 mailClient.sendMail(mail, recipient); 74 71 MessageBay.displayMessage("Test message sent."); 75 72 } 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(); 73 74 public static void CheckMailTest() { 75 List<Mail.MailEntry> mail = MailBay.getMailClient().checkMail(); 76 for (Mail.MailEntry entry: mail) { 77 MessageBay.displayMessage(entry.toString()); 78 } 79 MessageBay.displayMessage(mail.size() + " new mail since last run."); 80 } 81 82 public static void SendTestOneOffMessage(String recipient) { 83 String time = Mail.FORMAT.format(new Date()); 92 84 String sender = UserSettings.UserName.get(); 93 85 String topic = "Test Message"; … … 95 87 Map<String, String> options = new HashMap<String, String>(); 96 88 options.put("Neat", "Beep"); 97 MailEntry mail = new MailEntry(time, sender, colleagueName, topic, message, options);89 98 90 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); 91 byte[] keyBytes = new byte[16]; 92 rand.nextBytes(keyBytes); 93 SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 94 System.out.println(Base64.getEncoder().encodeToString(keyBytes)); 95 96 Mail mailClient = MailBay.getMailClient(); 97 Mail.MailEntry mail = mailClient.new MailEntry(time, sender, recipient, topic, message, options); 98 mailClient.sendOneOffMail(mail, recipient, key); 103 99 MessageBay.displayMessage("Test message sent."); 104 100 } … … 114 110 115 111 // Start Misc Auth Actions 112 public static void CheckForNewMail() { 113 MailBay.checkMail(); 114 } 115 116 116 /** 117 117 * Action ran by user to read a message using a single use distributed Symmetric key … … 124 124 SecretKey key = new SecretKeySpec(keyBytes, SymmetricAlgorithm); 125 125 List<String> data = actionItem.getData(); 126 Mail .decryptOneOffSecureMessage(key, data);126 MailBay.decryptOneOffSecureMessage(key, data); 127 127 StandardGestureActions.Refresh(); 128 128 } … … 146 146 public static void ToggleBay() throws KeyStoreException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException, IOException, ParseException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { 147 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 } 148 //if (!DisplayController.isMailMode()) { 149 // MailBayV2.checkMail(); 150 //} 156 151 DisplayController.ToggleMailMode(); 157 152 } … … 558 553 @SuppressWarnings("unused") 559 554 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);555 String trustedUserOne = userData.get(AuthenticationTag.TrustedUserOne); 556 String trustedUserTwo = userData.get(AuthenticationTag.TrustedUserTwo); 557 PublicKey colleagueOneKey = AuthenticatorBrowser.getInstance().getPublicKey(trustedUserOne); 558 PublicKey colleagueTwoKey = AuthenticatorBrowser.getInstance().getPublicKey(trustedUserTwo); 564 559 if (colleagueOneKey == null) { 565 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueOne);560 MessageBay.errorMessage("Unable to get public key for colleague: " + trustedUserOne); 566 561 return false; 567 562 } else if (colleagueTwoKey == null) { 568 MessageBay.errorMessage("Unable to get public key for colleague: " + colleagueTwo);563 MessageBay.errorMessage("Unable to get public key for colleague: " + trustedUserTwo); 569 564 return false; 570 565 } else { 571 String time = org.expeditee.stats.Formatter.getDateTime();566 String time = Mail.FORMAT.format(new Date()); 572 567 String sender = userData.get(AuthenticationTag.Username); 573 568 String topic = "You have received a request for cooperation from your colleague " + sender; … … 576 571 arguments.put("I agree to assist " + sender + " if they loose access to their account.", "AuthConfirmPasswordColleagueRelationship " + sender); 577 572 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); 573 Mail outbox = MailBay.getMailClient(); 574 MailEntry mail = outbox.new MailEntry(time, sender, trustedUserOne, topic, message, arguments); 575 outbox.sendMail(mail, trustedUserOne); 576 mail = outbox.new MailEntry(time, sender, trustedUserTwo, topic, message, arguments); 577 outbox.sendMail(mail, trustedUserTwo); 582 578 AuthenticatorBrowser.getInstance().markRequestedColleagues(UserSettings.UserName.get()); 583 579 return true;
Note:
See TracChangeset
for help on using the changeset viewer.