Skip to content

Commit

Permalink
Throw readable error for bad api key read (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Jul 1, 2024
1 parent 9767a5e commit e26f500
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions srv/db/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defaultChars } from '../../common/characters'

const ALGO = 'aes-192-cbc'
const KEY = crypto.scryptSync(config.jwtSecret, 'salt', 24)
const KEY_LB = crypto.scryptSync(config.jwtSecret + '\n', 'salt', 24)
const KEY_LB = crypto.scryptSync(`${config.jwtSecret}\n`, 'salt', 24)

export function now() {
return new Date().toISOString()
Expand Down Expand Up @@ -36,8 +36,11 @@ export function decryptText(text: string) {
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8')
} catch (ex) {}

const decipher = crypto.createDecipheriv(ALGO, KEY_LB, Buffer.from(iv, 'hex'))
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8')
try {
const decipher = crypto.createDecipheriv(ALGO, KEY_LB, Buffer.from(iv, 'hex'))
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8')
} catch (ex) {}
throw new Error(`Could not read API key: Try re-entering your service API key.`)
}

export const STARTER_CHARACTER: AppSchema.Character = {
Expand Down

0 comments on commit e26f500

Please sign in to comment.