Skip to content

Commit

Permalink
Android: Tests fully compatibility with 1.5+ PowerAuth Servers
Browse files Browse the repository at this point in the history
  • Loading branch information
hvge committed Jun 6, 2024
1 parent d6f8725 commit eec9714
Show file tree
Hide file tree
Showing 33 changed files with 2,152 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public interface Execution<TResult> {
* Start your asynchronous operation. Your implementation get a {@link ResultCatcher} object
* that allows you report result of the operation once it completes its execution.
*
* @param resultCatcher A result catcher that allows you report the result of the asynchronous operation.
* @param resultCatcher A result catcher that allows you to report the result of the asynchronous operation.
* @throws Exception In case of failure.
*/
void execute(@NonNull ResultCatcher<TResult> resultCatcher) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public interface PowerAuthServerApi {
* Get information about activation.
*
* @param activationId Activation identifier.
* @param challenge Optional challenge, required for acquiring V3.1 {@code encryptedStatusBlob}.
* @param challenge Optional challenge, required for acquiring V3.1+ {@code encryptedStatusBlob}.
* @return {@link ActivationDetail} object.
* @throws Exception In case of failure.
*/
Expand All @@ -272,10 +272,11 @@ public interface PowerAuthServerApi {
* @param tokenDigest Token digest.
* @param nonce Nonce in Base64 encoding.
* @param timestamp Timestamp used for calculate token.
* @param protocolVersion Protocol version, required for server 1.5+.
* @return {@link TokenInfo} object in case of success.
* @throws Exception In case of failure.
*/
@NonNull TokenInfo validateToken(@NonNull String tokenId, @NonNull String tokenDigest, @NonNull String nonce, long timestamp) throws Exception;
@NonNull TokenInfo validateToken(@NonNull String tokenId, @NonNull String tokenDigest, @NonNull String nonce, long timestamp, @NonNull String protocolVersion) throws Exception;

// Signatures

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.getlime.security.powerauth.integration.support.model.Application;
import io.getlime.security.powerauth.integration.support.model.ApplicationDetail;
import io.getlime.security.powerauth.integration.support.model.ApplicationVersion;
import io.getlime.security.powerauth.integration.support.model.ProtocolVersion;
import io.getlime.security.powerauth.networking.ssl.HttpClientSslNoValidationStrategy;
import io.getlime.security.powerauth.sdk.PowerAuthAuthenticationHelper;
import io.getlime.security.powerauth.sdk.PowerAuthClientConfiguration;
Expand Down Expand Up @@ -483,6 +484,6 @@ private PowerAuthTestHelper(
* @return Expected protocol version for HTTP headers.
*/
public @NonNull String getProtocolVersionForHeader() {
return testConfig.getServerVersion().maxProtocolVersion.versionForHeader;
return ProtocolVersion.V3_1.versionForHeader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.getlime.security.powerauth.integration.support.model.ServerVersion;
import io.getlime.security.powerauth.integration.support.v10.PowerAuthClientV3_ServerV10;
import io.getlime.security.powerauth.integration.support.v13.PowerAuthClientV3_ServerV13;
import io.getlime.security.powerauth.integration.support.v15.PowerAuthClientV3_ServerV15;

/**
* The {@code PowerAuthClientFactory} provides client that communicate with PowerAuth Server API,
Expand All @@ -40,12 +41,13 @@ public class PowerAuthClientFactory {
*/
public PowerAuthServerApi createApiClient(@NonNull PowerAuthTestConfig testConfig) throws Exception {
PowerAuthServerApi api = null;
if (testConfig.getServerVersion().numericVersion >= ServerVersion.V1_0_0.numericVersion &&
testConfig.getServerVersion().numericVersion <= ServerVersion.V1_2_5.numericVersion) {
final int numVer = testConfig.getServerVersion().numericVersion;
if (numVer >= ServerVersion.V1_0_0.numericVersion && numVer < ServerVersion.V1_3_0.numericVersion) {
api = new PowerAuthClientV3_ServerV10(testConfig.getServerApiUrl(), testConfig.getAuthorizationHeaderValue(), ServerVersion.V1_0_0, ServerVersion.V1_2_5);
} else if (testConfig.getServerVersion().numericVersion >= ServerVersion.V1_3_0.numericVersion &&
testConfig.getServerVersion().numericVersion <= ServerVersion.LATEST.numericVersion) {
api = new PowerAuthClientV3_ServerV13(testConfig.getServerApiUrl(), testConfig.getAuthorizationHeaderValue(), ServerVersion.V1_3_0, null);
} else if (numVer >= ServerVersion.V1_3_0.numericVersion && numVer < ServerVersion.V1_5_0.numericVersion) {
api = new PowerAuthClientV3_ServerV13(testConfig.getServerApiUrl(), testConfig.getAuthorizationHeaderValue(), ServerVersion.V1_3_0, ServerVersion.V1_4_0);
} else if (numVer >= ServerVersion.V1_5_0.numericVersion && numVer <= ServerVersion.LATEST.numericVersion) {
api = new PowerAuthClientV3_ServerV15(testConfig.getServerApiUrl(), testConfig.getAuthorizationHeaderValue(), ServerVersion.V1_5_0, null);
}
if (api == null) {
throw new Exception("Missing implementation for server API, for server version " + testConfig.getServerVersion().version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ApplicationVersion {
private String applicationVersionName;
private String applicationKey;
private String applicationSecret;
private String mobileSdkConfig;
private boolean supported;

public String getApplicationVersionId() {
Expand Down Expand Up @@ -63,4 +64,12 @@ public boolean isSupported() {
public void setSupported(boolean supported) {
this.supported = supported;
}

public String getMobileSdkConfig() {
return mobileSdkConfig;
}

public void setMobileSdkConfig(String mobileSdkConfig) {
this.mobileSdkConfig = mobileSdkConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public enum ProtocolVersion {
V3_1(31, "3.1"),
V3_2(32, "3.2");

public int version;
public String versionForHeader;
public final int version;
public final String versionForHeader;

ProtocolVersion(int version, String versionForHeader) {
this.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public enum ServerVersion {
V1_2_5("1.2.5", 1002005, ProtocolVersion.V3_1),
V1_3_0("1.3", 1003000, ProtocolVersion.V3_1),
V1_4_0("1.4", 1004000, ProtocolVersion.V3_1),
// Server 1.5+ supports V3.2, but this SDK supports V3.1 only
V1_5_0("1.5", 1005000, ProtocolVersion.V3_1),
V1_6_0("1.6", 1006000, ProtocolVersion.V3_1),
V1_7_0("1.7", 1007000, ProtocolVersion.V3_1),
V1_8_0("1.8", 1008000, ProtocolVersion.V3_1),
V1_5_0("1.5", 1005000, ProtocolVersion.V3_2),
V1_6_0("1.6", 1006000, ProtocolVersion.V3_2),
V1_7_0("1.7", 1007000, ProtocolVersion.V3_2),
V1_8_0("1.8", 1008000, ProtocolVersion.V3_2),

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public ActivationDetail getActivationDetail(@NonNull Activation activation) thro

@NonNull
@Override
public TokenInfo validateToken(@NonNull String tokenId, @NonNull String tokenDigest, @NonNull String nonce, long timestamp) throws Exception {
public TokenInfo validateToken(@NonNull String tokenId, @NonNull String tokenDigest, @NonNull String nonce, long timestamp, @NonNull String protocolVersion) throws Exception {
final ValidateTokenEndpoint.Request request = new ValidateTokenEndpoint.Request();
request.setTokenId(tokenId);
request.setTokenDigest(tokenDigest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public ActivationDetail getActivationDetail(@NonNull Activation activation) thro

@NonNull
@Override
public TokenInfo validateToken(@NonNull String tokenId, @NonNull String tokenDigest, @NonNull String nonce, long timestamp) throws Exception {
public TokenInfo validateToken(@NonNull String tokenId, @NonNull String tokenDigest, @NonNull String nonce, long timestamp, @NonNull String protocolVersion) throws Exception {
final ValidateTokenEndpoint.Request request = new ValidateTokenEndpoint.Request();
request.setTokenId(tokenId);
request.setTokenDigest(tokenDigest);
Expand Down
Loading

0 comments on commit eec9714

Please sign in to comment.