Skip to content

Commit

Permalink
Android: Fix #635: Temporary key expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
hvge committed Oct 8, 2024
1 parent 7b4191f commit 54e67bd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,4 +549,43 @@ public void onGetEciesEncryptorFailed(@NonNull Throwable t) {
});
assertNotNull(encryptor);
}

/*
@Test
public void testEciesTemporaryKeyExpiration() throws Exception {
// This test requires PAS configured for a very short temporary key lifespan.
activationHelper.createStandardActivation(true, null);
Boolean result = AsyncHelper.await(resultCatcher -> {
powerAuthSDK.fetchEncryptionKey(testHelper.getContext(), activationHelper.getValidAuthentication(), 1000, new IFetchEncryptionKeyListener() {
@Override
public void onFetchEncryptionKeySucceed(@NonNull byte[] encryptedEncryptionKey) {
resultCatcher.completeWithResult(true);
}
@Override
public void onFetchEncryptionKeyFailed(@NonNull Throwable t) {
resultCatcher.completeWithResult(false);
}
});
});
assertTrue(result);
Thread.sleep(15_000);
result = AsyncHelper.await(resultCatcher -> {
powerAuthSDK.fetchEncryptionKey(testHelper.getContext(), activationHelper.getValidAuthentication(), 1000, new IFetchEncryptionKeyListener() {
@Override
public void onFetchEncryptionKeySucceed(@NonNull byte[] encryptedEncryptionKey) {
resultCatcher.completeWithResult(true);
}
@Override
public void onFetchEncryptionKeyFailed(@NonNull Throwable t) {
resultCatcher.completeWithResult(false);
}
});
});
assertTrue(result);
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean containsKeyForEncryptor(int scope) {
lock.lock();
if (session.hasPublicKeyForEciesScope(scope)) {
final PublicKeyInfo publicKeyInfo = getPublicKeyInfoForScope(scope);
if (publicKeyInfo.expiration >= 0 && publicKeyInfo.expiration - EXPIRATION_THRESHOLD < timeService.getCurrentTime()) {
if (publicKeyInfo.expiration >= 0 && (timeService.getCurrentTime() < publicKeyInfo.expiration - EXPIRATION_THRESHOLD)) {
return true;
}
PowerAuthLog.d("Removing expired public key for ECIES encryptor " + scope);
Expand Down
2 changes: 1 addition & 1 deletion proj-xcode/PowerAuth2/private/PA2KeystoreService.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ - (BOOL) hasKeyForEncryptorScope:(PowerAuthCoreEciesEncryptorScope)encryptorScop
PA2PublicKeyInfo * pki = [self pkiForScope:encryptorScope];
NSTimeInterval expiration = pki.expiration;
keyIsSet = expiration >= 0.0;
keyIsExpired = expiration - PUBLIC_KEY_EXPIRATION_THRESHOLD < [_timeService currentTime];
keyIsExpired = [_timeService currentTime] >= expiration - PUBLIC_KEY_EXPIRATION_THRESHOLD;
if (keyIsExpired) {
pki.expiration = -1;
}
Expand Down

0 comments on commit 54e67bd

Please sign in to comment.