Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ public void changePinCode(Context context, String oldPin, String newPin)
injectEncrypter();
}

/**
* Removes the pin code if one exists.
* @param context android context
*/
public void removePinCode(Context context) {
encryptionProvider.removePinCode(context);
}

private void injectEncrypter()
{
fileAccess.setEncrypter(encryptionProvider.getEncrypter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public interface EncryptionProvider
*/
void createPinCode(Context context, String pin);

/**
* Removes the pin code if one exists.
*
* @param context android context
*/
void removePinCode(Context context);

/**
* Changes the pin code if the old pin provided matches
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public void changePinCode(Context context, String oldPin, String newPin)
throw new RuntimeException(PIN_CODE_ERROR_MSG);
}

@Override
public void removePinCode(Context context)
{
throw new RuntimeException(PIN_CODE_ERROR_MSG);
}

@Override
public boolean needsAuth(Context context, PinCodeConfig codeConfig)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public void changePinCode(Context context, String oldPin, String newPin)
}
}

public void removePinCode(Context context) {
removePassphrase(context);
}

private void initWithMasterKey(AesCbcWithIntegrity.SecretKeys masterKey)
{
encrypter = createEncrypter(masterKey);
Expand Down Expand Up @@ -136,13 +140,26 @@ public boolean passphraseExists(Context context)
return masterKeyFile.exists();
}

public void removePassphrase(Context context) {
if (passphraseExists(context)) {
removeMasterKeyFile(context);
}
}

@NonNull
private File createMasterKeyFile(Context context)
{
File secure = createSecureDirectory(context);
return new File(secure, "__encrypted");
}

private void removeMasterKeyFile(Context context) {
File masterKeyFile = createMasterKeyFile(context);
if (masterKeyFile.exists()) {
masterKeyFile.delete();
}
}

@NonNull
private File createSaltFile(Context context)
{
Expand Down