Changeset 1263 for trunk


Ignore:
Timestamp:
03/21/19 11:13:03 (5 years ago)
Author:
bln4
Message:

When starting Authenticator mode and the authadmin account has not been registered, have the user register it.

Location:
trunk/src/org/expeditee/auth
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/Actions.java

    r1256 r1263  
    4848import org.expeditee.auth.tags.Constants;
    4949import org.expeditee.core.Colour;
     50import org.expeditee.gui.Browser;
    5051import org.expeditee.gui.DisplayController;
    5152import org.expeditee.gui.Frame;
     
    473474                String password = userdata.get(AuthenticationTag.Password);
    474475               
     476                if (username.equals(Browser.USER_NOBODY)) {
     477                        return;
     478                }
     479               
    475480                SecretKey personalKey = Authenticator.getInstance().getSecretKey(username, password);
    476481                if (personalKey == null) {
     
    493498//              });
    494499
    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");
    508540                }
    509541                               
    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 mail
    519                 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                
    532542                Collection<Item> usernameFields = getByData(FrameIO.LoadFrame(Constants.FRAME_MULTIUSER1), "txtUsername");
    533543                usernameFields.forEach(usernameField -> usernameField.setText(username));
  • trunk/src/org/expeditee/auth/Authenticator.java

    r1259 r1263  
    6565        // The frame number of the frame containing the current authenticated users public key.
    6666        public static int CREDENTIALS_FRAME = 13;
     67        public static final String ADMINACCOUNT = "authadmin";
    6768       
    6869        public static boolean Authenticated = false;
     
    7374        private static final byte[] FALSE = "no".getBytes();
    7475        private static final String KEYSTOREFILENAME = "keystore.ks" + File.separator;
    75        
     76               
    7677        private static Authenticator instance;
    7778       
     
    8182        }
    8283       
    83         private Authenticator() throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException {   
     84        private Authenticator() throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, ClassNotFoundException, SQLException {                   
    8485                UserSettings.setupDefaultFolders();
    8586                       
     
    8990                Actions.LoadMethods(org.expeditee.auth.sharing.Actions.class);
    9091
     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               
    9199                // draw the window
    92100                GraphicsManager g = EcosystemManager.getGraphicsManager();
     
    119127                // class load database classes
    120128                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                }
    121148        }
    122149               
Note: See TracChangeset for help on using the changeset viewer.