I have the following request handler:
//app.ts:
app.use(express.json());
app.use(express.raw());
app.use(express.urlencoded({ extended: false }));
apr.use(routeHandler);
// routeHandler.ts:
(req: Request, res: Response) => {
const {digest} = req.query;
freshDigest = crypto.createHash('sha256').update(req.body).digest('hex');
if(digest !== freshDigest) throw ValidationError('digest mismatch');
}
Then I use the following curl command to post an application/octet-stream
onto the route
curl
-H'Content-Type: application/octet-stream'
-XPOST \
-v \
"localhost:port/v2/path/to/route/?digest=sha256:$(sha256sum /path/to.file.html|cut -d' ' -f1)" \
-d@/path/to.file.html.html \
-H'Authorization: Bearer REDACTED'
The file may be any type, tarball, text, etc, just posting some bytes onto the API.
The digest provided by sha256sum (and openssl dgst -sha256) differ from node's crypto digest.
Is there anything that I misuse?
Thank you
Well, the issue was that cURL should send the data as binary, i.e.
--data-binary @/path/to/file
Then the checksums would match.