Skip to content

Commit db288ce

Browse files
committed
Add implicit assertion to test vectors for v3/v4.
1 parent 4063c1a commit db288ce

6 files changed

Lines changed: 120 additions & 12 deletions

File tree

paseto/src/main/kotlin/net/aholbrook/paseto/TokenService.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ internal class PublicTokenService internal constructor(
218218
private val json: Json = Json { explicitNulls = false },
219219
) : TokenService {
220220
override fun encode(token: Token, implicitAssertion: String): String {
221-
// TODO expand service-test-vectors for v4 with implicit assertions
222221
if (implicitAssertion.isNotEmpty() && !paseto.supportsImplicitAssertion) {
223222
throw ImplicitAssertionsNotSupportedException(paseto.version)
224223
}
@@ -239,7 +238,6 @@ internal class PublicTokenService internal constructor(
239238
}
240239

241240
override fun decode(token: String, footer: Footer?, implicitAssertion: String): Token {
242-
// TODO expand service-test-vectors for v4 with implicit assertions
243241
if (implicitAssertion.isNotEmpty() && !paseto.supportsImplicitAssertion) {
244242
throw ImplicitAssertionsNotSupportedException(paseto.version)
245243
}

paseto/src/test/kotlin/net/aholbrook/paseto/ServiceTestVectorsTests.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ class ServiceTestVectorsTests {
8686
val currentTime = expected.notBefore ?: expected.issuedAt
8787

8888
val actual = when (vector.mode) {
89-
"local" -> localService(version, vector, currentTime).encode(expected)
90-
"public" -> publicService(version, vector, currentTime).encode(expected)
89+
"local" -> localService(version, vector, currentTime)
90+
.encode(expected, vector.implicitAssertion ?: "")
91+
92+
"public" -> publicService(version, vector, currentTime)
93+
.encode(expected, vector.implicitAssertion ?: "")
94+
9195
else -> error("Unsupported mode: ${vector.mode}")
9296
}
9397

9498
if (version == Version.V1 && vector.mode == "public") {
9599
val decoded = publicService(version, vector, currentTime)
96-
.decode(actual, expected.footer)
100+
.decode(actual, expected.footer, vector.implicitAssertion ?: "")
97101
decoded shouldBe expected
98102
} else {
99103
actual shouldBe vector.token
@@ -106,10 +110,10 @@ class ServiceTestVectorsTests {
106110

107111
val actual = when (vector.mode) {
108112
"local" -> localService(version, vector, currentTime)
109-
.decode(vector.token, expected.footer)
113+
.decode(vector.token, expected.footer, vector.implicitAssertion ?: "")
110114

111115
"public" -> publicService(version, vector, currentTime)
112-
.decode(vector.token, expected.footer)
116+
.decode(vector.token, expected.footer, vector.implicitAssertion ?: "")
113117

114118
else -> error("Unsupported mode: ${vector.mode}")
115119
}

paseto/src/test/resources/service-test-vectors/v3.json

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,57 @@
263263
"kid": "key-1"
264264
},
265265
"token": "v3.public.e30IsoJvLCjwqnypFfAJ64AVYIggDbuTAxFLkhO_xiSeGzj3UTgj6wnWZfGU76TzaKQYaw52sz4lz1MfuYB9B-Qr06bptljULigj8DHgypEU7cwnkurayW3FSHS0iIbelEs.eyJraWQiOiJrZXktMSJ9"
266+
},
267+
{
268+
"name": "TV_IA_1_V3_LOCAL",
269+
"mode": "local",
270+
"nonce": "d892e66e5ef2185186b161adbcefc1283157e5c90dbdae4d5db1cc481e2889fd",
271+
"key": "3236753cafb041c87c87fe8f4fbe7303b5c22f61fd447c5d3e5bf9e4d6f9e327",
272+
"payload": {},
273+
"implicit-assertion": "ia-test-v3-local",
274+
"token": "v3.local.2JLmbl7yGFGGsWGtvO_BKDFX5ckNva5NXbHMSB4oif16n-fFEYhD372dSNJtElDhjFSOwazuCICsAzxUQIxOcVF88FziBYtOPGplAsh5svIcHQ"
275+
},
276+
{
277+
"name": "TV_IA_1_V3_LOCAL_WITH_FOOTER",
278+
"mode": "local",
279+
"nonce": "d892e66e5ef2185186b161adbcefc1283157e5c90dbdae4d5db1cc481e2889fd",
280+
"key": "3236753cafb041c87c87fe8f4fbe7303b5c22f61fd447c5d3e5bf9e4d6f9e327",
281+
"payload": {},
282+
"footer": {
283+
"kid": "key-1"
284+
},
285+
"implicit-assertion": "ia-test-v3-local-footer",
286+
"token": "v3.local.2JLmbl7yGFGGsWGtvO_BKDFX5ckNva5NXbHMSB4oif16n_zzuTDEx4RIUbVVrTwqM5H35Qrrsh6YPgBgUdiPxZ6dsYETX9tscmWYUE6nuH5KsQ.eyJraWQiOiJrZXktMSJ9"
287+
},
288+
{
289+
"name": "TV_IA_1_V3_PUBLIC",
290+
"mode": "public",
291+
"public-key": "039bd37f93bd00b144b991b91bd2937c59273ea3db9b564a084856842e645c2ff4c669754899a0b1f516972db997151952",
292+
"secret-key": "1dd0e1156bbe26b2000b7ea251824076b1ece4796fca6eaa93306f65b6c1772d5d42ab60b62c610e901e7a7b6cbf7a47",
293+
"payload": {},
294+
"implicit-assertion": "ia-test-v3-public",
295+
"token": "v3.public.e31WZerO5IER3p7wvtUE7Q6OhWZWK2iTpFryxHgPgEvOGuPohV5D1bbO5SMm4qcGsT9yyF59eloLIOoDc68lGWSoCnZ9udBa4g9BTTm2BFFpWd_ZCmzFfvEX6oKPsvKGU3U"
296+
},
297+
{
298+
"name": "TV_IA_1_V3_PUBLIC_WITH_FOOTER",
299+
"mode": "public",
300+
"public-key": "039bd37f93bd00b144b991b91bd2937c59273ea3db9b564a084856842e645c2ff4c669754899a0b1f516972db997151952",
301+
"secret-key": "1dd0e1156bbe26b2000b7ea251824076b1ece4796fca6eaa93306f65b6c1772d5d42ab60b62c610e901e7a7b6cbf7a47",
302+
"payload": {},
303+
"footer": {
304+
"kid": "key-1"
305+
},
306+
"implicit-assertion": "ia-test-v3-public-footer",
307+
"token": "v3.public.e32c4HpYQsWYJH3nZi6tinWelK_3-3hk2cykxnqoKRl7JBE7hdiP26g45H9s_rWYyY15c-9VaykOxXw0mD5ADdRzQ445trmlgzIEjjUs0u6ITdeUPIaxFVpUFuMYlh0rIs8.eyJraWQiOiJrZXktMSJ9"
308+
},
309+
{
310+
"name": "TV_IA_NULL_V3_LOCAL",
311+
"mode": "local",
312+
"nonce": "d892e66e5ef2185186b161adbcefc1283157e5c90dbdae4d5db1cc481e2889fd",
313+
"key": "3236753cafb041c87c87fe8f4fbe7303b5c22f61fd447c5d3e5bf9e4d6f9e327",
314+
"payload": {},
315+
"implicit-assertion": null,
316+
"token": "v3.local.2JLmbl7yGFGGsWGtvO_BKDFX5ckNva5NXbHMSB4oif16n4_8721k4U0NIDG-eUwWjXhaqLfq9PM251pvIEu38c_Tww7CH9YATBWX2VB-EOP4MA"
266317
}
267318
]
268-
}
319+
}

paseto/src/test/resources/service-test-vectors/v4.json

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,57 @@
263263
"kid": "key-1"
264264
},
265265
"token": "v4.public.e30dIki_CWNjVyAgAolgKwksBFK53XcCBttt51UhiqSavDFEABNl-ioet3HVQDTnZetqJZTm7y5yrqRvoeVeOmQD.eyJraWQiOiJrZXktMSJ9"
266+
},
267+
{
268+
"name": "TV_IA_1_V4_LOCAL",
269+
"mode": "local",
270+
"nonce": "3e2e599e3631b0e43595be4a31d4d615b7cb11b78d0b9d1bf703eb90ec2c0bba",
271+
"key": "21a438bd432da3e9f87ec1a2e42136b77c1ec57fb5acfeb80fac8c9589ce066f",
272+
"payload": {},
273+
"implicit-assertion": "ia-test-v4-local",
274+
"token": "v4.local.Pi5ZnjYxsOQ1lb5KMdTWFbfLEbeNC50b9wPrkOwsC7rWgAUbvteusd1WHY8LTuC5g9M3XJlDuV48rxIwC5yz8BMM"
275+
},
276+
{
277+
"name": "TV_IA_1_V4_LOCAL_WITH_FOOTER",
278+
"mode": "local",
279+
"nonce": "3e2e599e3631b0e43595be4a31d4d615b7cb11b78d0b9d1bf703eb90ec2c0bba",
280+
"key": "21a438bd432da3e9f87ec1a2e42136b77c1ec57fb5acfeb80fac8c9589ce066f",
281+
"payload": {},
282+
"footer": {
283+
"kid": "key-1"
284+
},
285+
"implicit-assertion": "ia-test-v4-local-footer",
286+
"token": "v4.local.Pi5ZnjYxsOQ1lb5KMdTWFbfLEbeNC50b9wPrkOwsC7rWgB4IAgGbX32Zn_RBZDFPICTlIqYV4Z0F5MflWIn7D_Em.eyJraWQiOiJrZXktMSJ9"
287+
},
288+
{
289+
"name": "TV_IA_1_V4_PUBLIC",
290+
"mode": "public",
291+
"public-key": "968ca16429daed891fc74a34f1998968e9fc3b4172b2b8eefe01c11821abbe5c",
292+
"secret-key": "737c0470b4e9b7ca8b0ee1403e41d8083b2ba76c44d48581468270f0b74fd647968ca16429daed891fc74a34f1998968e9fc3b4172b2b8eefe01c11821abbe5c",
293+
"payload": {},
294+
"implicit-assertion": "ia-test-v4-public",
295+
"token": "v4.public.e33z8Z_SKTvH9EWzHle5ni6iqC5tyJpQReq6gGsNiopcSYNnep19KYwF9dwQOPUdUWpsJFnm-3ydEPYkHe2pJJ4A"
296+
},
297+
{
298+
"name": "TV_IA_1_V4_PUBLIC_WITH_FOOTER",
299+
"mode": "public",
300+
"public-key": "968ca16429daed891fc74a34f1998968e9fc3b4172b2b8eefe01c11821abbe5c",
301+
"secret-key": "737c0470b4e9b7ca8b0ee1403e41d8083b2ba76c44d48581468270f0b74fd647968ca16429daed891fc74a34f1998968e9fc3b4172b2b8eefe01c11821abbe5c",
302+
"payload": {},
303+
"footer": {
304+
"kid": "key-1"
305+
},
306+
"implicit-assertion": "ia-test-v4-public-footer",
307+
"token": "v4.public.e31b3quiFqZW2AzqqYXYEQ-pnGe5FhpNzDiWUTm7iB6RyTKvIxf6lnkGJ1Gha-puM_3-xKqwkHchFrFQRTvUQl8P.eyJraWQiOiJrZXktMSJ9"
308+
},
309+
{
310+
"name": "TV_IA_NULL_V4_LOCAL",
311+
"mode": "local",
312+
"nonce": "3e2e599e3631b0e43595be4a31d4d615b7cb11b78d0b9d1bf703eb90ec2c0bba",
313+
"key": "21a438bd432da3e9f87ec1a2e42136b77c1ec57fb5acfeb80fac8c9589ce066f",
314+
"payload": {},
315+
"implicit-assertion": null,
316+
"token": "v4.local.Pi5ZnjYxsOQ1lb5KMdTWFbfLEbeNC50b9wPrkOwsC7rWgEhFA8BaCSmjB8wc6kE3pYHagpgK0q051d2Pwf-ZY16U"
266317
}
267318
]
268-
}
319+
}

paseto/src/testFixtures/kotlin/net/aholbrook/paseto/ServiceTestVectorFixtures.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ data class ServiceTestVector(
3131
val secretKey: String? = null,
3232
val payload: JsonObject,
3333
val footer: JsonElement? = null,
34+
@SerialName("implicit-assertion")
35+
val implicitAssertion: String? = null,
3436
val token: String,
3537
)
3638

vector-gen/src/main/kotlin/net/aholbrook/paseto/vectorgen/Main.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ class GenerateCommand : CliktCommand(name = "vector-gen") {
120120
}
121121

122122
val token = tokenFromVector(vector)
123+
val implicitAssertion = vector.implicitAssertion ?: ""
123124
val encoded = withTestNonce(nonce) {
124125
val service = tokenService(pasetoVersion ?: inputVersion, Purpose.Local { key.copy() }) {
125126
rules {
126127
issuedInPast = null
127128
notExpired = null
128129
}
129130
}
130-
val encoded = service.encode(token)
131-
service.decode(encoded)
131+
val encoded = service.encode(token, implicitAssertion)
132+
service.decode(encoded, implicitAssertion = implicitAssertion)
132133
encoded
133134
}
134135

@@ -169,14 +170,15 @@ class GenerateCommand : CliktCommand(name = "vector-gen") {
169170
}
170171

171172
val token = tokenFromVector(vector)
173+
val implicitAssertion = vector.implicitAssertion ?: ""
172174
val encoded = withTestNonce(vector.nonce?.toByteArray()) {
173175
val service = tokenService(pasetoVersion ?: inputVersion, Purpose.Public { keyPair.copy() }) {
174176
rules {
175177
issuedInPast = null
176178
notExpired = null
177179
}
178180
}
179-
service.encode(token)
181+
service.encode(token, implicitAssertion)
180182
}
181183

182184
return vector.copy(

0 commit comments

Comments
 (0)