Skip to content
Snippets Groups Projects
Commit 3340cf7f authored by Quoc Huy Nguyen Dinh's avatar Quoc Huy Nguyen Dinh
Browse files

Update uploadCsHandler to use the original imageHash as storage key allow...

Update uploadCsHandler to use the original imageHash as storage key allow detection of images already stored
parent f1c008bf
No related branches found
No related tags found
1 merge request!6uploadCsHandler to detect duplicates
......@@ -231,22 +231,29 @@ export async function uploadCsHandler(ctx: KoaContext) {
.update(fileData)
.digest()
// extra check if client manges to lie about the content-length
// extra check if client manages to lie about the content-length
APIError.assert((file.stream as any).truncated !== true,
APIError.Code.PayloadTooLarge)
const imageHash = createHash('sha256')
// Expecting the signature to be based on the integrity checksum of the image
const expectedSignature = createHash('sha256')
.update('ImageSigningChallenge')
.update(fileHash)
.digest()
// Used to generate the image storage key
const imageHash = createHash('sha256')
.update('ImageSigningChallenge')
.update(fileData)
.digest()
const [account] = await rpcClient.database.getAccounts([ctx.params['username']])
APIError.assert(account, APIError.Code.NoSuchAccount)
let validSignature = false
let publicKey
try {
publicKey = signature.recover(imageHash).toString()
publicKey = signature.recover(expectedSignature).toString()
} catch (cause) {
throw new APIError({code: APIError.Code.InvalidSignature, cause})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment