- Timestamp:
- 03/21/19 11:13:03 (5 years ago)
- Location:
- trunk/src/org/expeditee/auth
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/auth/Actions.java
r1256 r1263 48 48 import org.expeditee.auth.tags.Constants; 49 49 import org.expeditee.core.Colour; 50 import org.expeditee.gui.Browser; 50 51 import org.expeditee.gui.DisplayController; 51 52 import org.expeditee.gui.Frame; … … 473 474 String password = userdata.get(AuthenticationTag.Password); 474 475 476 if (username.equals(Browser.USER_NOBODY)) { 477 return; 478 } 479 475 480 SecretKey personalKey = Authenticator.getInstance().getSecretKey(username, password); 476 481 if (personalKey == null) { … … 493 498 // }); 494 499 495 496 // Load in and cache the profile frame using the personal key fetched from keystore. 497 // Reset the personal key once finished so that setting parsing can correctly set it. 498 FrameIO.ClearCache(); 499 Text personalKeyText = KeyList.PersonalKey.generateText(); 500 personalKeyText.setData(Base64.getEncoder().encodeToString(personalKey.getEncoded())); 501 KeyList.PersonalKey.setSetting(personalKeyText); 502 Frame oneFrame = FrameIO.LoadProfile(username); 503 for (int i = 1; i <= FrameIO.getLastNumber(username); i++) { 504 Frame f = FrameIO.LoadFrame(oneFrame.getFramesetName() + i); 505 if (f.getData() != null && f.getData().contains("MultiuserCredentials")) { 506 Authenticator.CREDENTIALS_FRAME = f.getNumber(); 507 } 500 Frame oneFrame = null; 501 if (!username.equals(Authenticator.ADMINACCOUNT)) { 502 // Load in and cache the profile frame using the personal key fetched from keystore. 503 // Reset the personal key once finished so that setting parsing can correctly set it. 504 FrameIO.ClearCache(); 505 Text personalKeyText = KeyList.PersonalKey.generateText(); 506 personalKeyText.setData(Base64.getEncoder().encodeToString(personalKey.getEncoded())); 507 KeyList.PersonalKey.setSetting(personalKeyText); 508 oneFrame = FrameIO.LoadProfile(username); 509 for (int i = 1; i <= FrameIO.getLastNumber(username); i++) { 510 Frame f = FrameIO.LoadFrame(oneFrame.getFramesetName() + i); 511 if (f.getData() != null && f.getData().contains("MultiuserCredentials")) { 512 Authenticator.CREDENTIALS_FRAME = f.getNumber(); 513 } 514 } 515 516 // Parse the settings frame to update the settings datastructure. 517 Text fakeLink = new Text("settings"); 518 fakeLink.setLink(oneFrame.getFramesetName() + "2"); 519 Settings.parseSettings(fakeLink); 520 521 // Update default folders. 522 UserSettings.setupDefaultFolders(); 523 524 // Check mail 525 MailBay.clear(); 526 Authenticator.getInstance().loadMailDatabase(); 527 Text keyItem = org.expeditee.settings.identity.secrets.KeyList.PrivateKey.get(); 528 if (keyItem.getData() != null) { 529 String keyEncoded = keyItem.getData().get(0); 530 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded); 531 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes)); 532 List<MailEntry> mailForLoggingInUser = Mail.getEntries(UserSettings.UserName.get(), key); 533 for (MailEntry mail: mailForLoggingInUser) { 534 MailBay.addMessage(mail.timestamp, mail.message, mail.message2, mail.options); 535 } 536 } 537 } else { 538 UserSettings.UserName.set(Authenticator.ADMINACCOUNT); 539 oneFrame = FrameIO.LoadFrame("multiuser1"); 508 540 } 509 541 510 // Parse the settings frame to update the settings datastructure.511 Text fakeLink = new Text("settings");512 fakeLink.setLink(oneFrame.getFramesetName() + "2");513 Settings.parseSettings(fakeLink);514 515 // Update default folders.516 UserSettings.setupDefaultFolders();517 518 // Check mail519 MailBay.clear();520 Authenticator.getInstance().loadMailDatabase();521 Text keyItem = org.expeditee.settings.identity.secrets.KeyList.PrivateKey.get();522 if (keyItem.getData() != null) {523 String keyEncoded = keyItem.getData().get(0);524 byte[] keyBytes = Base64.getDecoder().decode(keyEncoded);525 PrivateKey key = KeyFactory.getInstance(AsymmetricAlgorithm).generatePrivate(new PKCS8EncodedKeySpec(keyBytes));526 List<MailEntry> mailForLoggingInUser = Mail.getEntries(UserSettings.UserName.get(), key);527 for (MailEntry mail: mailForLoggingInUser) {528 MailBay.addMessage(mail.timestamp, mail.message, mail.message2, mail.options);529 }530 }531 532 542 Collection<Item> usernameFields = getByData(FrameIO.LoadFrame(Constants.FRAME_MULTIUSER1), "txtUsername"); 533 543 usernameFields.forEach(usernameField -> usernameField.setText(username)); -
trunk/src/org/expeditee/auth/Authenticator.java
r1259 r1263 65 65 // The frame number of the frame containing the current authenticated users public key. 66 66 public static int CREDENTIALS_FRAME = 13; 67 public static final String ADMINACCOUNT = "authadmin"; 67 68 68 69 public static boolean Authenticated = false; … … 73 74 private static final byte[] FALSE = "no".getBytes(); 74 75 private static final String KEYSTOREFILENAME = "keystore.ks" + File.separator; 75 76 76 77 private static Authenticator instance; 77 78 … … 81 82 } 82 83 83 private Authenticator() throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException { 84 private Authenticator() throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException { 84 85 UserSettings.setupDefaultFolders(); 85 86 … … 89 90 Actions.LoadMethods(org.expeditee.auth.sharing.Actions.class); 90 91 92 // Does the account Authentication.ADMINACCOUNT exist? 93 // If not then we have get the user to assign a password to it. 94 if (!keyStore.containsAlias(Authenticator.ADMINACCOUNT)) { 95 new File(FrameIO.PARENT_FOLDER).mkdirs(); 96 protectAdmin(); 97 } 98 91 99 // draw the window 92 100 GraphicsManager g = EcosystemManager.getGraphicsManager(); … … 119 127 // class load database classes 120 128 Class.forName("org.sqlite.JDBC"); 129 } 130 131 private void protectAdmin() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, 132 FileNotFoundException, IOException { 133 // Fetch desired password 134 Scanner in = new Scanner(System.in); 135 System.out.println("It appears you have not yet set up a password for the administration account on Expeditee."); 136 System.out.print("Please enter it now: "); 137 String password = in.nextLine(); 138 System.out.print("And again: "); 139 if (in.nextLine().equals(password)) { 140 // Register account. 141 putKey(ADMINACCOUNT, password, new SecretKeySpec("null".getBytes(), AsymmetricAlgorithm)); 142 in.close(); 143 } else { 144 in.close(); 145 System.out.println("Mismatched passwords, lets try that again."); 146 protectAdmin(); 147 } 121 148 } 122 149
Note:
See TracChangeset
for help on using the changeset viewer.