{"record":{"id":"87f94edf3b89a9a3","repo":"signalapp/Signal-Server","slug":"could-not-interpret-key-bytes-as-a-public-key","errorCode":null,"errorMessage":"Could not interpret key bytes as a public key","messagePattern":"Could not interpret key bytes as a public key","errorType":"validation","errorClass":"JsonParseException","httpStatus":400,"severity":"error","filePath":"service/src/main/java/org/whispersystems/textsecuregcm/util/AbstractPublicKeyDeserializer.java","lineNumber":38,"sourceCode":"  public K deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {\n    final byte[] publicKeyBytes;\n\n    try {\n      publicKeyBytes = Base64.getDecoder().decode(parser.getValueAsString());\n    } catch (final IllegalArgumentException e) {\n      Metrics.counter(invalidKeyCounterName, REASON_TAG_NAME, \"illegal-base64\").increment();\n      throw new JsonParseException(parser, \"Could not parse public key as a base64-encoded value\", e);\n    }\n\n    if (publicKeyBytes.length == 0) {\n      return null;\n    }\n\n    try {\n      return deserializePublicKey(publicKeyBytes);\n    } catch (final InvalidKeyException e) {\n      Metrics.counter(invalidKeyCounterName, REASON_TAG_NAME, \"invalid-key\").increment();\n      throw new JsonParseException(parser, \"Could not interpret key bytes as a public key\", e);\n    }\n  }\n\n  protected abstract K deserializePublicKey(final byte[] publicKeyBytes) throws InvalidKeyException;\n}\n","sourceCodeStart":20,"sourceCodeEnd":44,"githubUrl":"https://github.com/signalapp/Signal-Server/blob/100ab61c82627582c867d19e1c0561ba2781e927/service/src/main/java/org/whispersystems/textsecuregcm/util/AbstractPublicKeyDeserializer.java#L20-L44","documentation":"Thrown when the Base64 decoding succeeds but the resulting bytes cannot be interpreted as a valid public key by the subclass's deserializePublicKey (e.g., libsignal raises InvalidKeyException for malformed or wrong-length key material). The failure is counted under an 'invalid-key' reason tag and rethrown as a JsonParseException, failing deserialization of the JSON field.","triggerScenarios":"Thrown at service/src/main/java/org/whispersystems/textsecuregcm/util/AbstractPublicKeyDeserializer.java:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the decoded bytes are a valid serialized public key in the format expected by libsignal (e.g. 33-byte CURVE25519 encoding)","Confirm the client sends a complete, uncorrupted key (no truncation or byte mangling)","Check that the key type byte matches the expected key type before deserializing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"100ab61c82627582c867d19e1c0561ba2781e927","analyzedAt":"2026-09-09T13:29:47.883Z","contentChangedAt":"2026-09-09T13:29:47.883Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}