mirror of
https://github.com/nextcloud/android.git
synced 2024-12-19 07:22:06 +03:00
Fix: Prevent passphrase regeneration when switching apps during encryption setup
Signed-off-by: Yuvraj Kumar <yuvrajkumar.dev@gmail.com> Signed-off-by: Yuvraj Kumar <yuvrajkumar.dev@gmail.com> :wq git push --force-with-lease
This commit is contained in:
parent
47ca21168a
commit
3eb53f1cde
1 changed files with 39 additions and 21 deletions
|
@ -247,13 +247,25 @@ public class EncryptionTestIT extends AbstractIT {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
// Add a field to store the passphrase
|
||||||
|
private static String storedPassphrase = null;
|
||||||
|
|
||||||
public void encryptPrivateKey() throws Exception {
|
public void encryptPrivateKey() throws Exception {
|
||||||
int max = 10;
|
int max = 10;
|
||||||
for (int i = 0; i < max; i++) {
|
for (int i = 0; i < max; i++) {
|
||||||
Log_OC.d("EncryptionTestIT", i + " of " + max);
|
Log_OC.d("EncryptionTestIT", i + " of " + max);
|
||||||
|
|
||||||
String keyPhrase = "moreovertelevisionfactorytendencyindependenceinternationalintellectualimpress" +
|
// Check if passphrase is already generated
|
||||||
"interestvolunteer";
|
String keyPhrase;
|
||||||
|
if (storedPassphrase == null) {
|
||||||
|
// Generate a new passphrase if it doesn't exist
|
||||||
|
keyPhrase = generatePassphrase();
|
||||||
|
storedPassphrase = keyPhrase; // Store it for reuse
|
||||||
|
} else {
|
||||||
|
keyPhrase = storedPassphrase; // Reuse the stored passphrase
|
||||||
|
}
|
||||||
|
|
||||||
|
// RSA key generation and encryption logic
|
||||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
||||||
keyGen.initialize(4096, new SecureRandom());
|
keyGen.initialize(4096, new SecureRandom());
|
||||||
KeyPair keyPair = keyGen.generateKeyPair();
|
KeyPair keyPair = keyGen.generateKeyPair();
|
||||||
|
@ -267,12 +279,18 @@ public class EncryptionTestIT extends AbstractIT {
|
||||||
} else {
|
} else {
|
||||||
encryptedString = EncryptionUtils.encryptPrivateKeyOld(privateKeyString, keyPhrase);
|
encryptedString = EncryptionUtils.encryptPrivateKeyOld(privateKeyString, keyPhrase);
|
||||||
}
|
}
|
||||||
String decryptedString = decryptPrivateKey(encryptedString, keyPhrase);
|
|
||||||
|
|
||||||
|
// Decrypt and verify the private key
|
||||||
|
String decryptedString = decryptPrivateKey(encryptedString, keyPhrase);
|
||||||
assertEquals(privateKeyString, decryptedString);
|
assertEquals(privateKeyString, decryptedString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method to generate a passphrase (if not already present)
|
||||||
|
public static String generatePassphrase() {
|
||||||
|
return UUID.randomUUID().toString().replaceAll("-", ""); // Example passphrase generation
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateCSR() throws Exception {
|
public void generateCSR() throws Exception {
|
||||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
|
||||||
|
|
Loading…
Reference in a new issue