aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbleichen <bleichen@google.com>2023-02-20 08:19:08 -0800
committerCharles Lee <ckl@google.com>2023-02-27 16:44:39 -0800
commitf38fca6eae15455e829e7defa6259e3145a56832 (patch)
treed04d4173b8f2ceb74b64a11edb798b4b016c3f39
parentbbbfa86f883e348d9f0c01838475a352d52d3984 (diff)
downloadwycheproof-f38fca6eae15455e829e7defa6259e3145a56832.tar.gz
Replacing test case with JSON serialization.
All other test vectors use a flattened representation. (i.e. three base64 encoded strings separated with '.') The libraries tested so far only accept flattened representations. Other representations allow additional options. Hence testing such representations will be done with new test vector files. NOKEYCHECK=True PiperOrigin-RevId: 510999148
-rw-r--r--java/com/google/security/wycheproof/jose4j/JsonWebSignatureTest.java13
-rw-r--r--testvectors/json_web_signature_test.json13
2 files changed, 2 insertions, 24 deletions
diff --git a/java/com/google/security/wycheproof/jose4j/JsonWebSignatureTest.java b/java/com/google/security/wycheproof/jose4j/JsonWebSignatureTest.java
index a486393..185bc6a 100644
--- a/java/com/google/security/wycheproof/jose4j/JsonWebSignatureTest.java
+++ b/java/com/google/security/wycheproof/jose4j/JsonWebSignatureTest.java
@@ -126,7 +126,7 @@ public class JsonWebSignatureTest {
String privateJwk = testGroup.getAsJsonObject("private").toString();
JsonObject publicJwk = testGroup.getAsJsonObject("public");
- String jws = getFlattenedString(testCase, "jws");
+ String jws = testCase.get("jws").getAsString();
boolean expectedResult = testCase.get("result").getAsString().equals("valid");
// Verification is done with the public key if it exists (or the secret key if not).
@@ -145,17 +145,6 @@ public class JsonWebSignatureTest {
}
}
- /** Reads the JWS/JWE field either in compact or JSON serialization form. */
- private static String getFlattenedString(JsonObject jsonObject, String fieldName) {
- JsonElement element = jsonObject.get(fieldName);
- if (element.isJsonPrimitive()) {
- // This is a compact representation of the JWE/JWS.
- return element.getAsString();
- }
- // This is a JSON representation of the JWE/JWS.
- return element.toString();
- }
-
/**
* Returns whether or not the payload verifies with the given key.
*
diff --git a/testvectors/json_web_signature_test.json b/testvectors/json_web_signature_test.json
index abed1b4..c0afad1 100644
--- a/testvectors/json_web_signature_test.json
+++ b/testvectors/json_web_signature_test.json
@@ -140,18 +140,7 @@
{
"tcId": 17,
"comment": "rejectsValidJsonSerialization",
- "jws": {
- "payload": "Zm9v",
- "signatures": [
- {
- "protected": "eyJhbGciOiJIUzI1NiIsImtpZCI6ImtpZC1hZXMtc2lnbiJ9",
- "header": {
- "unknown": "untrustworthy"
- },
- "signature": "TD37p4c_0jmreSrBSDmE0F3mYSPtkZ3WrSyI5wb_KTg"
- }
- ]
- },
+ "jws": "{\"payload\":\"Zm9v\",\"signatures\":[{\"protected\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6ImtpZC1hZXMtc2lnbiJ9\",\"header\":{\"unknown\":\"untrustworthy\"},\"signature\":\"TD37p4c_0jmreSrBSDmE0F3mYSPtkZ3WrSyI5wb_KTg\"}",
"result": "invalid",
"flags": [
"JsonSerialization"