-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from patrickfav/feat-32-password-obfuscate
Improve user password memory protection and add derived password cache
- Loading branch information
Showing
19 changed files
with
574 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
armadillo/src/androidTest/java/at/favre/lib/armadillo/DerivedPasswordCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package at.favre.lib.armadillo; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.security.SecureRandom; | ||
|
||
import at.favre.lib.bytes.Bytes; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
import static junit.framework.TestCase.assertNull; | ||
|
||
public class DerivedPasswordCacheTest { | ||
|
||
private DerivedPasswordCache cache; | ||
private char[] pw; | ||
private byte[] salt; | ||
|
||
@Before | ||
public void setUp() { | ||
cache = new DerivedPasswordCache.Default(true, new SecureRandom()); | ||
pw = Bytes.random(12).encodeBase64Url().toCharArray(); | ||
salt = Bytes.random(16).array(); | ||
} | ||
|
||
@Test | ||
public void get() { | ||
Bytes val = Bytes.random(128); | ||
cache.put(salt, pw, val.copy().array()); | ||
assertEquals(val, Bytes.wrapNullSafe(cache.get(salt, pw))); | ||
assertEquals(val, Bytes.wrapNullSafe(cache.get(salt, pw))); | ||
|
||
cache.wipe(); | ||
|
||
assertNull(cache.get(salt, pw)); | ||
} | ||
|
||
@Test | ||
public void getWhileDisabled() { | ||
cache = new DerivedPasswordCache.Default(false, new SecureRandom()); | ||
cache.put(salt, pw, Bytes.random(128).array()); | ||
assertNull(cache.get(salt, pw)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.