Skip to content

Commit 3bc64d1

Browse files
authored
Fix #881: Update documentation for MAC tokens (#882)
1 parent 0a6c74e commit 3bc64d1

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

docs/MAC-Token-Based-Authentication.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Creating a quick, low-value payment from an iPhone app.
2525

2626
## Creating a Token
2727

28-
In order to create a new token, the client application must call a PowerAuth Standard RESTful API endpoint `/pa/v3/token/create`.
28+
In order to create a new token, the client application must call a PowerAuth Standard RESTful API endpoint `/pa/v4/token/create`.
2929

3030
This endpoint must be called with a standard PowerAuth authentication code. It can be any type of authentication code - 1FA or 2FA. The token then implicitly carries the information about the authentication code it was issued with. Using the PowerAuth authentication code assures the authenticity and integrity of the data sent during the request.
3131

@@ -37,8 +37,8 @@ The decrypted response data payload contains the following raw response format:
3737

3838
```json
3939
{
40-
"tokenId": "d6561669-34d6-4fee-8913-89477687a5cb",
41-
"tokenSecret": "VqAXEhziiT27lxoqREjtcQ=="
40+
"tokenId": "d6561669-34d6-4fee-8913-89477687a5cb",
41+
"tokenSecret": "VqAXEhziiT27lxoqREjtcQ=="
4242
}
4343
```
4444

@@ -48,30 +48,32 @@ The client stores both `token_id` and `token_secret` in a suitable local storage
4848

4949
## Using the Tokens
5050

51-
When using MAC Token-Based Authentication, the authentication of the RESTful API calls is achieved by computing a `token_digest` digest value on the client side that can be later validated on the server side. The algorithms for calculation and verification of the digest are, in principle, the same.
51+
When using MAC Token-Based Authentication, the authentication of the RESTful API calls is achieved by computing a `token_digest` value on the client side that can be later validated on the server side. The algorithms for calculation and verification of the digest are, in principle, the same.
5252

53-
The `token_digest` value is computed using the following algorithm:
53+
The `token_digest` value is computed from the following input:
5454

55-
```java
56-
// '$timestamp' is a Unix timestamp in milliseconds (to achieve the required time
57-
// precision) converted to a string and then to byte[] using UTF-8
58-
// encoding
59-
// '$version' is the protocol version, represented as UTF-8 bytes of the version string
60-
long timestamp = Time.getTimestamp();
61-
byte[] timestamp_bytes = ByteUtils.encode(String.valueOf(timestamp));
62-
63-
// '$nonce' value is 16B of random data
64-
byte[] nonce = Generator.randomBytes(16);
55+
- `nonce` – 16 bytes of random data
56+
- `timestamp`Unix timestamp in milliseconds, converted to UTF-8 bytes from a string value
57+
- `version` – protocol version (for example `"4.0"`)
58+
- `token_secret` – 16 random bytes associated with the token
59+
60+
The binary input for the MAC is constructed as:
61+
62+
```
63+
nonce + "&" + timestamp + "&" + version
64+
```
6565

66-
// '$nonce' is concatenated to '$timestamp' and '$version' using '&' character:
67-
// $nonce + '&' + $timestamp + '&' + $version
68-
byte[] data = ByteUtils.concat(nonce, ByteUtils.encode("&"), timestamp_bytes, ByteUtils.encode("&"), version);
66+
### Protocol Version 4.0
6967

70-
// 'token_secret' is 16B of random data
71-
SecretKey key = KeyConversion.secretKeyFromBytes(token_secret);
68+
For version **4.0**, the digest is computed using **KMAC256** with a custom string `PA4DIGEST`:
7269

73-
// Compute the digest using HMAC-SHA256
74-
byte[] token_digest = Mac.hmacSha256(key, data)
70+
```java
71+
byte[] timestamp = String.valueOf(System.currentTimeMillis()).getBytes(StandardCharsets.UTF_8);
72+
byte[] nonce = Generator.randomBytes(16);
73+
byte[] version = "4.0".getBytes(StandardCharsets.UTF_8);
74+
byte[] data = ByteUtils.concat(nonce, "&".getBytes(StandardCharsets.UTF_8), timestamp, "&".getBytes(StandardCharsets.UTF_8), version);
75+
SecretKey key = convertBytesToSharedSecretKey(token_secret);
76+
byte[] token_digest = Kmac.kmac256(key, data, "PA4DIGEST".getBytes(StandardCharsets.UTF_8));
7577
```
7678

7779
In order to use the token authentication with the RESTful API call, you need to set the following HTTP header to the request:
@@ -81,26 +83,26 @@ X-PowerAuth-Token: PowerAuth token_id="${TOKEN_ID}"
8183
token_digest="${TOKEN_DIGEST}"
8284
nonce="${NONCE}"
8385
timestamp="${TIMESTAMP}"
84-
version="3.2"
86+
version="4.0"
8587
```
8688

8789
Transport representation of the HTTP header properties is following:
8890

8991
- `token_id` - Identifier of the token, as is - UUID level 4.
90-
- `token_digest` - Digest value computed using `token_secret`, `nonce`, and `timestamp`, Base64 encoded.
92+
- `token_digest` - Digest value computed using `token_secret`, `nonce`, `timestamp`, and `version`, Base64 encoded.
9193
- `nonce` - Random cryptographic nonce, 16B long, Base64 encoded.
9294
- `timestamp` - Current timestamp in a Unix timestamp format (in milliseconds, to achieve required time precision), represented as a string value.
9395
- `version` - Protocol version.
9496

9597
## Token Removal
9698

97-
You can remove a token with a given ID anytime by sending a signed request to the PowerAuth Standard RESTful API endpoint `/pa/v3/token/remove`:
99+
You can remove a token with a given ID anytime by sending a signed request to the PowerAuth Standard RESTful API endpoint `/pa/v4/token/remove`:
98100

99101
```json
100102
{
101-
"requestObject": {
102-
"tokenId": "d6561669-34d6-4fee-8913-89477687a5cb"
103-
}
103+
"requestObject": {
104+
"tokenId": "d6561669-34d6-4fee-8913-89477687a5cb"
105+
}
104106
}
105107
```
106108

@@ -110,8 +112,8 @@ If the authentication code validation is successful and after validating that th
110112

111113
```json
112114
{
113-
"requestObject": {
114-
"tokenId": "d6561669-34d6-4fee-8913-89477687a5cb"
115-
}
115+
"requestObject": {
116+
"tokenId": "d6561669-34d6-4fee-8913-89477687a5cb"
117+
}
116118
}
117119
```

docs/Temporary-Encryption-Keys.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The client app should process the response by verifying the signature and checki
6868
Besides [End-to-End Encryption](./End-To-End-Encryption.md) itself, the introduction of temporary encryption key impacts all use-cases that implicitly rely on data encryption, such as:
6969

7070
- New activations (using all supported methods)
71-
- Obtaining and changing activation name from the mobile app.
71+
- Obtaining and changing activation name from the mobile app
7272
- Secure Vault
7373
- MAC-based Tokens
7474
- Obtaining User Info

0 commit comments

Comments
 (0)