Changeset 1500
- Timestamp:
- 01/20/20 15:04:45 (4 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/auth/account/Password.java
r1482 r1500 35 35 import org.expeditee.auth.tags.AuthenticationTag; 36 36 import org.expeditee.encryption.CryptographyConstants; 37 import org.expeditee.encryption.io.EncryptedExpReader; 37 38 import org.expeditee.gui.DisplayController; 38 39 import org.expeditee.gui.Frame; … … 336 337 337 338 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) { 338 343 // Store shares in map 339 344 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 343 353 // initialise shamir 344 354 int totalShares = 2; 345 355 int requiredShares = 2; 346 356 Scheme scheme = new Scheme(new SecureRandom(), totalShares, requiredShares); 347 357 348 358 // perform joining 349 359 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 } 354 376 } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | ClassNotFoundException 355 377 | IOException | SQLException e) { 356 378 e.printStackTrace(); 357 379 } 358 359 MessageBay.displayMessage("Your new password has been set.");360 380 } 361 381 } -
trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java
r1461 r1500 2 2 3 3 import java.io.BufferedReader; 4 import java.io.File; 4 5 import java.io.FileInputStream; 5 6 import java.io.FileReader; … … 77 78 return true; 78 79 } 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 } 79 98 } 80 99 … … 326 345 } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException 327 346 | 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())); 329 349 return null; 330 350 } … … 337 357 super(in); 338 358 } 339 359 340 360 @Override 341 361 /**
Note:
See TracChangeset
for help on using the changeset viewer.