Fork of github.com/did-method-plc/did-method-plc

Prevent signature malleability (#54)

* prevent padding on signatures

* bump @atproto/crypto

* added test for padded sig

Changed files
+18 -6
packages
+1 -1
packages/lib/package.json
···
},
"dependencies": {
"@atproto/common": "0.3.0",
-
"@atproto/crypto": "0.2.2",
+
"@atproto/crypto": "0.3.0",
"@ipld/dag-cbor": "^7.0.3",
"axios": "^1.3.4",
"multiformats": "^9.6.4",
+3
packages/lib/src/operations.ts
···
op: t.CompatibleOpOrTombstone,
): Promise<string> => {
const { sig, ...opData } = op
+
if (sig.endsWith('=')) {
+
throw new InvalidSignatureError(op)
+
}
const sigBytes = uint8arrays.fromString(sig, 'base64url')
const dataBytes = new Uint8Array(cbor.encode(opData))
for (const didKey of allowedDidKeys) {
+9
packages/lib/tests/data.test.ts
···
import { check, cidForCbor } from '@atproto/common'
import { P256Keypair, Secp256k1Keypair } from '@atproto/crypto'
+
import * as ui8 from 'uint8arrays'
import {
GenesisHashError,
ImproperOperationError,
···
it('does not allow operations from the signingKey', async () => {
const op = await operations.updateHandleOp(lastOp(), signingKey, 'at://bob')
+
expect(data.validateOperationLog(did, [...ops, op])).rejects.toThrow(
+
InvalidSignatureError,
+
)
+
})
+
+
it('does not allow padded signatures', async () => {
+
const op = await operations.updateHandleOp(lastOp(), signingKey, 'at://bob')
+
op.sig = ui8.toString(ui8.fromString(op.sig, 'base64url'), 'base64urlpad')
expect(data.validateOperationLog(did, [...ops, op])).rejects.toThrow(
InvalidSignatureError,
)
+1 -1
packages/server/package.json
···
},
"dependencies": {
"@atproto/common": "0.3.0",
-
"@atproto/crypto": "0.2.2",
+
"@atproto/crypto": "0.3.0",
"@did-plc/lib": "*",
"axios": "^1.3.4",
"cors": "^2.8.5",
+4 -4
yarn.lock
···
multiformats "^9.6.4"
pino "^8.6.1"
-
"@atproto/crypto@0.2.2":
-
version "0.2.2"
-
resolved "https://registry.yarnpkg.com/@atproto/crypto/-/crypto-0.2.2.tgz#9832dda885512a36401d24f95990489f521593ef"
-
integrity sha512-yepwM6pLPw/bT7Nl0nfDw251yVDpuhc0llOgD8YdCapUAH7pIn4dBcMgXiA9UzQaHA7OC9ByO5IdGPrMN/DmZw==
+
"@atproto/crypto@0.3.0":
+
version "0.3.0"
+
resolved "https://registry.yarnpkg.com/@atproto/crypto/-/crypto-0.3.0.tgz#a79e05a85129810755f3456e9d419b49824407d7"
+
integrity sha512-bhcxRTL4fgRY2YX/St0x4o0oDUp18QIPD7ek+7v8UKA0HpsCGQYbo8w9d9hUvwwty5X5p00cYF2tbggUWaPy7A==
dependencies:
"@noble/curves" "^1.1.0"
"@noble/hashes" "^1.3.1"