mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
mic & mac calculation
thanks to @alexander-albers! see https://github.com/schildbach/public-transport-enabler/issues/187#issuecomment-357436079
This commit is contained in:
parent
904f890442
commit
6f958e14be
2 changed files with 16 additions and 6 deletions
|
@ -28,6 +28,7 @@ const id = x => x
|
||||||
const defaultProfile = {
|
const defaultProfile = {
|
||||||
salt: null,
|
salt: null,
|
||||||
addChecksum: false,
|
addChecksum: false,
|
||||||
|
addMicMac: false,
|
||||||
|
|
||||||
transformReqBody: id,
|
transformReqBody: id,
|
||||||
transformReq: id,
|
transformReq: id,
|
||||||
|
|
|
@ -26,15 +26,24 @@ const request = (profile, data) => {
|
||||||
query: {}
|
query: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (profile.addChecksum) {
|
if (profile.addChecksum || profile.addMicMac) {
|
||||||
if (!Buffer.isBuffer(profile.salt)) {
|
if (!Buffer.isBuffer(profile.salt)) {
|
||||||
throw new Error('profile.salt must be a Buffer.')
|
throw new Error('profile.salt must be a Buffer.')
|
||||||
}
|
}
|
||||||
const checksum = md5(Buffer.concat([
|
if (profile.addChecksum) {
|
||||||
Buffer.from(req.body, 'utf8'),
|
const checksum = md5(Buffer.concat([
|
||||||
profile.salt
|
Buffer.from(req.body, 'utf8'),
|
||||||
]))
|
profile.salt
|
||||||
req.query.checksum = checksum.toString('hex')
|
]))
|
||||||
|
req.query.checksum = checksum.toString('hex')
|
||||||
|
}
|
||||||
|
if (profile.addMicMac) {
|
||||||
|
const mic = md5(Buffer.from(req.body, 'utf8'))
|
||||||
|
req.query.mic = mic.toString('hex')
|
||||||
|
|
||||||
|
const mac = md5(Buffer.concat([mic, profile.salt]))
|
||||||
|
req.query.mac = mac.toString('hex')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = profile.endpoint +'?' + stringify(req.query)
|
const url = profile.endpoint +'?' + stringify(req.query)
|
||||||
|
|
Loading…
Add table
Reference in a new issue