Merge pull request #135 from shocknet/fix/auth-token
auth token in header for GET + skip hook cuz routes.js not pretty
This commit is contained in:
commit
e00c54f312
1 changed files with 30 additions and 19 deletions
|
|
@ -99,7 +99,7 @@ module.exports = async (
|
||||||
success: true
|
success: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const checkHealth = async () => {
|
const checkHealth = async () => {
|
||||||
logger.info('Getting service status...')
|
logger.info('Getting service status...')
|
||||||
|
|
@ -202,7 +202,7 @@ module.exports = async (
|
||||||
message: sanitizeLNDError(err.message)
|
message: sanitizeLNDError(err.message)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Hack to check whether or not a wallet exists
|
// Hack to check whether or not a wallet exists
|
||||||
const walletExists = async () => {
|
const walletExists = async () => {
|
||||||
|
|
@ -263,32 +263,43 @@ module.exports = async (
|
||||||
logger.error('Unknown Device')
|
logger.error('Unknown Device')
|
||||||
return res.status(401).json(error)
|
return res.status(401).json(error)
|
||||||
}
|
}
|
||||||
|
if (!req.body.encryptionKey && !req.body.iv && !req.headers["x-shock-encryption-token"]){
|
||||||
if (
|
|
||||||
req.method === 'GET' ||
|
|
||||||
req.method === 'DELETE' ||
|
|
||||||
(!req.body.encryptionKey && !req.body.iv)
|
|
||||||
) {
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
let encryptedToken,encryptedKey,IV,data
|
||||||
|
if(req.method === 'GET' || req.method === 'DELETE'){
|
||||||
|
if(req.headers["x-shock-encryption-token"]){
|
||||||
|
encryptedToken = req.headers["x-shock-encryption-token"]
|
||||||
|
encryptedKey =req.headers["x-shock-encryption-key"]
|
||||||
|
IV =req.headers["x-shock-encryption-iv"]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
encryptedToken = req.body.token
|
||||||
|
encryptedKey = req.body.encryptionKey
|
||||||
|
IV = req.body.iv
|
||||||
|
data = req.body.data
|
||||||
|
}
|
||||||
const decryptedKey = Encryption.decryptKey({
|
const decryptedKey = Encryption.decryptKey({
|
||||||
deviceId,
|
deviceId,
|
||||||
message: req.body.encryptionKey
|
message: encryptedKey
|
||||||
})
|
})
|
||||||
const decryptedMessage = Encryption.decryptMessage({
|
if(data){
|
||||||
message: req.body.data,
|
const decryptedMessage = Encryption.decryptMessage({
|
||||||
key: decryptedKey,
|
message: data,
|
||||||
iv: req.body.iv
|
key: decryptedKey,
|
||||||
})
|
iv: IV
|
||||||
const decryptedToken = req.body.token
|
})
|
||||||
|
req.body = JSON.parse(decryptedMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
const decryptedToken = encryptedToken
|
||||||
? Encryption.decryptMessage({
|
? Encryption.decryptMessage({
|
||||||
message: req.body.token,
|
message: encryptedToken,
|
||||||
key: decryptedKey,
|
key: decryptedKey,
|
||||||
iv: req.body.iv
|
iv: IV
|
||||||
})
|
})
|
||||||
: null
|
: null
|
||||||
req.body = JSON.parse(decryptedMessage)
|
|
||||||
|
|
||||||
if (decryptedToken) {
|
if (decryptedToken) {
|
||||||
req.headers.authorization = decryptedToken
|
req.headers.authorization = decryptedToken
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue