Skip to content

Commit

Permalink
Apple: 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 eec9714 commit cd251ba
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ - (BOOL) validateTokenHeader:(PowerAuthAuthorizationHttpHeader*)header
validationRequest.tokenDigest = parsedHeader[@"token_digest"];
validationRequest.nonce = parsedHeader[@"nonce"];
validationRequest.timestamp = parsedHeader[@"timestamp"];
validationRequest.protocolVersion = parsedHeader[@"version"];
PATSTokenValidationResponse * validationResponse = [_testServerApi validateTokenRequest:validationRequest];
XCTAssertTrue(validationResponse.tokenValid == expectedResult);
if (expectedResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ - (BOOL) validateConnection
return NO;
}
_testServerConfig.serverApiVersion = [_rest applyServerVersion:systemStatus.version];
_testServerConfig.serverMaxProtovolVersion = PATSProtoVer(_testServerConfig.serverApiVersion);
_serverVersion = _testServerConfig.serverApiVersion;

NSArray<PATSApplication*>* applicationList = [self getApplicationList];
Expand Down Expand Up @@ -346,7 +347,12 @@ - (BOOL) verifyECDSASignature:(NSString*)activationId data:(NSData*)data signatu
- (PATSTokenValidationResponse*) validateTokenRequest:(PATSTokenValidationRequest*)request
{
[self checkForValidConnection];
NSArray * params = @[ request.tokenIdentifier, request.tokenDigest, request.nonce, request.timestamp ];
NSArray * params;
if (_testServerConfig.serverMaxProtovolVersion == PATS_P32) {
params = @[ request.tokenIdentifier, request.tokenDigest, request.nonce, request.timestamp, request.protocolVersion];
} else {
params = @[ request.tokenIdentifier, request.tokenDigest, request.nonce, request.timestamp];
}
return [_rest request:@"TokenValidate" params:params];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef NS_ENUM(int, PowerAuthProtocolVersion) {
PATS_P2, // V2 crypto
PATS_P3, // V3 crypto
PATS_P31, // V3.1 crypto
PATS_P32, // V3.2 crypto
};

/**
Expand Down Expand Up @@ -74,6 +75,10 @@ extern PowerAuthProtocolVersion PATSProtoVer(PowerAuthTestServerVersion serverVe
"V2" is the default value. Loaded after the connection to server is established.
*/
@property (nonatomic, assign) PowerAuthTestServerVersion serverApiVersion;
/**
Maximum supported protocol version.
*/
@property (nonatomic, assign) PowerAuthProtocolVersion serverMaxProtovolVersion;
/**
A name for application, which will be used on the PA2 server.
Default value is @"AutomaticTest-IOS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ + (instancetype) loadFromJsonFile:(NSString *)path

PowerAuthProtocolVersion PATSProtoVer(PowerAuthTestServerVersion serverVer)
{
if (serverVer >= PATS_V1_5) {
return PATS_P32;
}
return PATS_P31;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ extern NSString * PATSActivationOtpValidationEnumToString(PATSActivationOtpValid

@interface PATSTokenValidationRequest : NSObject

@property (nonatomic, strong) NSString * protocolVersion;
@property (nonatomic, strong) NSString * tokenIdentifier;
@property (nonatomic, strong) NSString * tokenDigest;
@property (nonatomic, strong) NSString * nonce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
"applicationName"
],
"response": {
"class": "array",
"arrayClass": {
"class": "PATSApplication",
"properties": {
"applicationId": { "class" : "string" },
"applicationName": { "class" : "string" }
}
"class": "PATSApplication",
"properties": {
"applicationId": { "class" : "string" },
"applicationName": { "class" : "string" }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
"applicationId"
],
"response": {
"class": "array",
"arrayClass": {
"class": "PATSApplication",
"properties": {
"applicationId": { "class" : "string" },
"applicationName": { "class" : "string", "key" : "applicationId" }
}
"class": "PATSApplication",
"properties": {
"applicationId": { "class" : "string" },
"applicationName": { "class" : "string", "key" : "applicationId" }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"path": "/rest/v3/token/validate",
"parameters": [
"tokenId",
"tokenDigest",
"nonce",
"timestamp"
],
"response": {
"class": "PATSTokenValidationResponse",
"properties": {
"tokenValid": { "class" : "bool" },
"activationId": { "class" : "string" },
"userId": { "class" : "string" },
"applicationId": { "class" : "string" },
"signatureType": { "class" : "string" }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"path": "/rest/v3/token/validate",
"parameters": [
"tokenId",
"tokenDigest",
"nonce",
"timestamp",
"protocolVersion"
],
"response": {
"class": "PATSTokenValidationResponse",
"properties": {
"tokenValid": { "class" : "bool" },
"activationId": { "class" : "string" },
"userId": { "class" : "string" },
"applicationId": { "class" : "string" },
"signatureType": { "class" : "string" }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
"GetApplicationDetail": "GetApplicationDetail_v10",
"CreateApplicationVersion": "CreateApplicationVersion_v10",
"SupportApplicationVersion": "SupportApplicationVersion_v10",
"UnsupportApplicationVersion": "UnsupportApplicationVersion_v10"
"UnsupportApplicationVersion": "UnsupportApplicationVersion_v10",
"TokenValidate": "TokenValidate_v10"
},
"v13": {
"GetApplicationList": "GetApplicationList_v13",
"CreateApplication": "CreateApplication_v13",
"GetApplicationDetail": "GetApplicationDetail_v13",
"CreateApplicationVersion": "CreateApplicationVersion_v13",
"SupportApplicationVersion": "SupportApplicationVersion_v13",
"UnsupportApplicationVersion": "UnsupportApplicationVersion_v13"
"UnsupportApplicationVersion": "UnsupportApplicationVersion_v13",
"TokenValidate": "TokenValidate_v10"
},
"v15": { "#base": "v13",
"GetApplicationDetail": "GetApplicationDetail_v15",
"CreateApplicationVersion": "CreateApplicationVersion_v15"
"CreateApplicationVersion": "CreateApplicationVersion_v15",
"TokenValidate": "TokenValidate_v15"
}
}
}

0 comments on commit cd251ba

Please sign in to comment.