Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed public ECIES encryptor construction #634

Merged
merged 2 commits into from
Oct 3, 2024
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 @@ -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
Loading