Changeset 1500 for trunk


Ignore:
Timestamp:
01/20/20 15:04:45 (4 years ago)
Author:
bnemhaus
Message:

org.expeditee.auth.account.Password =>
org.expeditee.encryption.EncryptedExpReader =>

When performing account recovery, the username of the account you are trying to recover now actually needs to match the recovered key.
Also, the order that the password pieces are entered no longer matters.

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

Legend:

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

    r1482 r1500  
    3535import org.expeditee.auth.tags.AuthenticationTag;
    3636import org.expeditee.encryption.CryptographyConstants;
     37import org.expeditee.encryption.io.EncryptedExpReader;
    3738import org.expeditee.gui.DisplayController;
    3839import org.expeditee.gui.Frame;
     
    336337
    337338        public static void regainAccountAccess(Map<AuthenticationTag, String> userData) {
     339                regainAccountAccess(userData, false);
     340        }
     341       
     342        private static void regainAccountAccess(Map<AuthenticationTag, String> userData, boolean isAttemptTwo) {
    338343                // Store shares in map
    339344                Map<Integer, byte[]> contributingParts = new HashMap<Integer, byte[]>();
    340                 contributingParts.put(1, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceOne)));
    341                 contributingParts.put(2, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceTwo)));
    342                
     345                if (isAttemptTwo) {
     346                        contributingParts.put(1, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceTwo)));
     347                        contributingParts.put(2, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceOne)));
     348                } else {
     349                        contributingParts.put(1, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceOne)));
     350                        contributingParts.put(2, Base64.getDecoder().decode(userData.get(AuthenticationTag.PasswordSliceTwo)));
     351                }
     352
    343353                // initialise shamir
    344354                int totalShares = 2;
    345355                int requiredShares = 2;
    346356                Scheme scheme = new Scheme(new SecureRandom(), totalShares, requiredShares);
    347                
     357
    348358                // perform joining
    349359                byte[] join = scheme.join(contributingParts);
    350                
    351                 try {
    352                         // TODO: YIKES!  We can currently change anyone's password!
    353                         AuthenticatorBrowser.getInstance().putKey(userData.get(AuthenticationTag.Username), userData.get(AuthenticationTag.NewPassword), new SecretKeySpec(join, SymmetricAlgorithm));
     360
     361                try {
     362                        String username = userData.get(AuthenticationTag.Username);
     363                        SecretKey key = new SecretKeySpec(join, SymmetricAlgorithm);
     364                        String filePathCheck = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve("1.exp").toAbsolutePath()
     365                                        .toString();
     366                        if (EncryptedExpReader.isAccessibleExpediteeFile(filePathCheck, key)) {
     367                                AuthenticatorBrowser.getInstance().putKey(username, userData.get(AuthenticationTag.NewPassword), key);
     368                                MessageBay.displayMessage("Your new password has been set.");
     369                        } else {
     370                                if (isAttemptTwo) {
     371                                        MessageBay.displayMessage("Invalid information given for changing password for " + username);
     372                                } else {
     373                                        regainAccountAccess(userData, true);
     374                                }
     375                        }
    354376                } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | ClassNotFoundException
    355377                                | IOException | SQLException e) {
    356378                        e.printStackTrace();
    357379                }
    358                
    359                 MessageBay.displayMessage("Your new password has been set.");
    360380        }
    361381}
  • trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java

    r1461 r1500  
    22
    33import java.io.BufferedReader;
     4import java.io.File;
    45import java.io.FileInputStream;
    56import java.io.FileReader;
     
    7778                        return true;
    7879                }
     80        }       
     81       
     82        public static boolean isAccessibleExpediteeFile(String path, SecretKey key) throws IOException {
     83                try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"))) {
     84                        String firstLine = in.readLine();
     85                        if (firstLine == null) return false;           
     86                       
     87                        if (firstLine.startsWith(ENCRYPTED_EXP_FLAG)) {
     88                                String secondLine = in.readLine();
     89                                byte[] toDecrypt = Base64.getDecoder().decode(secondLine);
     90                                byte[] decrypted = DecryptSymmetric(toDecrypt, key);
     91                                return decrypted != null;
     92                        } else {
     93                                // Not encrypted.  Returns false because the caller of this
     94                                // function is asking if this key is used to decrypt this file.
     95                                return false;
     96                        }
     97                }
    7998        }
    8099       
     
    326345                } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
    327346                                | IllegalBlockSizeException | BadPaddingException e) {
    328                         e.printStackTrace();
     347                        //e.printStackTrace();
     348                        System.err.println("Failed to decrypt '" + new String(toDecrypt) + "' with key " + new String(key.getEncoded()));
    329349                        return null;
    330350                }
     
    337357                        super(in);
    338358                }
    339                
     359                               
    340360                @Override
    341361                /**
Note: See TracChangeset for help on using the changeset viewer.