This commit is contained in:
Daniel Lugo 2022-01-22 17:32:13 -04:00
parent 319f104acf
commit 5ea87c67c9

View file

@ -454,14 +454,25 @@ module.exports = async (
let { publicKey, deviceId } = req.body let { publicKey, deviceId } = req.body
if (Buffer.isBuffer(accessSecret)) { if (Buffer.isBuffer(accessSecret)) {
publicKey = await ECCrypto.decrypt(accessSecret, publicKey) logger.info('Will decrypt public key and device ID for key exchange.')
deviceId = await ECCrypto.decrypt(accessSecret, deviceId)
publicKey = await ECCrypto.decrypt(
accessSecret,
ECC.convertToEncryptedMessage(publicKey)
)
deviceId = await ECCrypto.decrypt(
accessSecret,
ECC.convertToEncryptedMessage(deviceId)
)
publicKey = publicKey.toString('utf8')
deviceId = deviceId.toString('utf8')
} }
if (typeof publicKey !== 'string' || !publicKey) { if (typeof publicKey !== 'string' || !publicKey) {
return res.status(400).json({ return res.status(500).json({
field: 'publicKey', field: 'publicKey',
message: 'Please provide a valid public key' errorMessage: 'Please provide a valid public key'
}) })
} }
@ -471,9 +482,9 @@ module.exports = async (
deviceId deviceId
) )
) { ) {
return res.status(400).json({ return res.status(500).json({
field: 'deviceId', field: 'deviceId',
message: 'Please provide a valid device ID' errorMessage: 'Please provide a valid device ID'
}) })
} }
@ -486,7 +497,8 @@ module.exports = async (
logger.error(err) logger.error(err)
return res.status(401).json({ return res.status(401).json({
field: 'unknown', field: 'unknown',
message: err message: err,
errorMessage: err.message || err
}) })
} }
}) })
@ -615,7 +627,7 @@ module.exports = async (
try { try {
const health = await checkHealth() const health = await checkHealth()
const walletInitialized = await walletExists() const walletInitialized = await walletExists()
const { alias, password } = req.body const { alias, pass } = req.body
const lndUp = health.LNDStatus.success const lndUp = health.LNDStatus.success
const walletUnlocked = health.LNDStatus.walletStatus === 'unlocked' const walletUnlocked = health.LNDStatus.walletStatus === 'unlocked'
const { authorization = '' } = req.headers const { authorization = '' } = req.headers
@ -636,14 +648,14 @@ module.exports = async (
GunDB.logoff() GunDB.logoff()
} }
const publicKey = await GunDB.authenticate(alias, password) const publicKey = await GunDB.authenticate(alias, pass)
if (!publicKey) { if (!publicKey) {
throw new Error('Invalid alias/password combination') throw new Error('Invalid alias/password combination')
} }
if (!walletUnlocked) { if (!walletUnlocked) {
await unlockWallet(password) await unlockWallet(pass)
} }
if (walletUnlocked && !authorization && !allowUnlockedLND) { if (walletUnlocked && !authorization && !allowUnlockedLND) {