Skip to content

Commit

Permalink
Merge pull request #634 from /issues/633-unavailable-keystore-service
Browse files Browse the repository at this point in the history
Fixed public ECIES encryptor construction
  • Loading branch information
hvge authored Oct 3, 2024
2 parents e5791d6 + 5b6b965 commit c396c7a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.google.gson.reflect.TypeToken;
import io.getlime.security.powerauth.core.EciesEncryptor;
import io.getlime.security.powerauth.networking.client.JsonSerialization;
import io.getlime.security.powerauth.networking.response.*;
import org.junit.After;
Expand Down Expand Up @@ -506,4 +507,46 @@ public void onJwtSignatureFailed(@NonNull Throwable t) {
boolean result = testHelper.getServerApi().verifyEcdsaSignature(activationHelper.getActivation().getActivationId(), jwtSignedDatasBase64, jwtSignatureBase64, "JOSE");
assertTrue(result);
}

@Test
public void testEciesEncryptors() throws Exception {
EciesEncryptor encryptor = AsyncHelper.await(resultCatcher -> {
powerAuthSDK.getEciesEncryptorForApplicationScope(new IGetEciesEncryptorListener() {
@Override
public void onGetEciesEncryptorSuccess(@NonNull EciesEncryptor encryptor) {
resultCatcher.completeWithResult(encryptor);
}

@Override
public void onGetEciesEncryptorFailed(@NonNull Throwable t) {
resultCatcher.completeWithError(t);
}
});
});
assertNotNull(encryptor);

// Now create activation
activationHelper.createStandardActivation(true, null);
final ActivationHelper.HelperState activationHelperState = activationHelper.getHelperState();

// Now re-instantiate PowerAuthSDK (e.g. with no-EEK in configuration)
testHelper = new PowerAuthTestHelper.Builder().build(true);
powerAuthSDK = testHelper.getSharedSdk();
activationHelper = new ActivationHelper(testHelper, activationHelperState);

encryptor = AsyncHelper.await(resultCatcher -> {
powerAuthSDK.getEciesEncryptorForApplicationScope(new IGetEciesEncryptorListener() {
@Override
public void onGetEciesEncryptorSuccess(@NonNull EciesEncryptor encryptor) {
resultCatcher.completeWithResult(encryptor);
}

@Override
public void onGetEciesEncryptorFailed(@NonNull Throwable t) {
resultCatcher.completeWithError(t);
}
});
});
assertNotNull(encryptor);
}
}
2 changes: 1 addition & 1 deletion proj-xcode/PowerAuth2/PowerAuthSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ @implementation PowerAuthSDK (E2EE)
- (id<PowerAuthOperationTask>) eciesEncryptorWithScope:(PowerAuthCoreEciesEncryptorScope)scope
callback:(void (^)(PowerAuthCoreEciesEncryptor *, NSError *))callback
{
return [_keystoreService createKeyForEncryptorScope:scope callback:^(NSError * error) {
return [[self keystoreService] createKeyForEncryptorScope:scope callback:^(NSError * error) {
PowerAuthCoreEciesEncryptor * encryptor;
if (!error) {
encryptor = [self eciesEncryptorWithScope:scope error:&error];
Expand Down
32 changes: 32 additions & 0 deletions proj-xcode/PowerAuth2IntegrationTests/PowerAuthSDKDefaultTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1363,4 +1363,36 @@ - (void) testJwtSignature
XCTAssertTrue(result);
}

#pragma mark - ECIES

- (void) testEncryptorCreation
{
CHECK_TEST_CONFIG();

PowerAuthCoreEciesEncryptor * encryptor = [AsyncHelper synchronizeAsynchronousBlock:^(AsyncHelper *waiting) {
[_sdk eciesEncryptorForApplicationScopeWithCallback:^(PowerAuthCoreEciesEncryptor * _Nullable encryptor, NSError * _Nullable error) {
XCTAssertNil(error);
[waiting reportCompletion:encryptor];
}];
}];
XCTAssertNotNil(encryptor);

PowerAuthSdkActivation * activation = [_helper createActivation:YES];
if (!activation) {
return;
}

// Re-create SDK to reset internal objects
_sdk = [_helper reCreateSdkInstanceWithConfiguration:nil keychainConfiguration:nil clientConfiguration:nil];
XCTAssertTrue(_sdk.hasValidActivation);

encryptor = [AsyncHelper synchronizeAsynchronousBlock:^(AsyncHelper *waiting) {
[_sdk eciesEncryptorForApplicationScopeWithCallback:^(PowerAuthCoreEciesEncryptor * _Nullable encryptor, NSError * _Nullable error) {
XCTAssertNil(error);
[waiting reportCompletion:encryptor];
}];
}];
XCTAssertNotNil(encryptor);
}

@end

0 comments on commit c396c7a

Please sign in to comment.