[impl] Offline activation request
This commit is contained in:
parent
f42e70df27
commit
db63daf633
@ -1,9 +1,11 @@
|
|||||||
const apiV1 = require('./apiV1-controller')
|
const apiV1 = require('./apiV1-controller')
|
||||||
|
const temp = require('./temp-controller')
|
||||||
const products = require('./products-controller')
|
const products = require('./products-controller')
|
||||||
const login = require('./login-controller')
|
const login = require('./login-controller')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
apiV1,
|
apiV1,
|
||||||
|
temp,
|
||||||
products,
|
products,
|
||||||
login
|
login
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/controllers/temp-controller.js
Normal file
36
src/controllers/temp-controller.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
const base32 = require('hi-base32')
|
||||||
|
const crypto = require('crypto')
|
||||||
|
const { parseOfflinePreactivationRequest } = require('../lib/generateLicenseFile')
|
||||||
|
|
||||||
|
|
||||||
|
function checkRequestString(requestString) {
|
||||||
|
if (requestString !== null && typeof requestString === 'string') {
|
||||||
|
if (requestString.length > 0) {
|
||||||
|
return (requestString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error('Invalid request string')
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
async generateNewLicense(ctx) {
|
||||||
|
const licenseNum = base32.encode(crypto.randomBytes(15))
|
||||||
|
const licenseNumNice = licenseNum.match(/.{4}/g).join('-')
|
||||||
|
ctx.body = '<html><body>' +
|
||||||
|
`License for client: <pre>${licenseNumNice}</pre>` +
|
||||||
|
'SQL command to insert license into database with 2 licensed modules <strong>ccengine</strong> (windows app) and <strong>cndata</strong> (CN data): <pre>' +
|
||||||
|
`Insert Into License (productId, licenseNum, customerId) Values ('coc', '${licenseNum}', '123456');\n` +
|
||||||
|
`Insert Into LicensedModule (productId, licenseNum, moduleId) Values ('coc', '${licenseNum}', 'ccengine');\n` +
|
||||||
|
`Insert Into LicensedModule (productId, licenseNum, moduleId) Values ('coc', '${licenseNum}', 'cndata');\n` +
|
||||||
|
'</pre>' +
|
||||||
|
'</body></html>';
|
||||||
|
},
|
||||||
|
|
||||||
|
async parseOfflineActivationRequest(ctx) {
|
||||||
|
const { body } = ctx.request
|
||||||
|
|
||||||
|
ctx.body = await parseOfflinePreactivationRequest(checkRequestString(body.requestString))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -39,3 +39,34 @@ exports.generateLicenseFile = async function (activationId, productId, systemPar
|
|||||||
console.log(output.toString('hex'));
|
console.log(output.toString('hex'));
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.parseOfflinePreactivationRequest = async function (activationRequest) {
|
||||||
|
const beginTag = "-BEGIN ACTIVATION REQUEST-----"
|
||||||
|
let beginPos = activationRequest.indexOf(beginTag)
|
||||||
|
if (beginPos < 0) {
|
||||||
|
throw "Invalid activation request format"
|
||||||
|
}
|
||||||
|
beginPos = beginPos + beginTag.length;
|
||||||
|
activationRequest = activationRequest.substring(beginPos)
|
||||||
|
|
||||||
|
const endTag = "-----END ACTIVATION REQUEST-"
|
||||||
|
let endPos = activationRequest.indexOf(endTag)
|
||||||
|
if (endPos < 0) {
|
||||||
|
throw "Invalid activation request format"
|
||||||
|
}
|
||||||
|
const data = activationRequest.substring(0, endPos)
|
||||||
|
|
||||||
|
const buff = Buffer.from(data, 'base64');
|
||||||
|
|
||||||
|
const algorithm = 'aes-256-gcm';
|
||||||
|
const password = Buffer.from('e73db572349005f1c41979baf8166a0900745119fa096b9c3efbcee11ddd8b88', 'hex');
|
||||||
|
const decipher = crypto.createDecipheriv(algorithm, password, buff.subarray(0, 16))
|
||||||
|
decipher.setAuthTag(buff.subarray(-16))
|
||||||
|
let decrypted = decipher.update(buff.subarray(16, -16))
|
||||||
|
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
||||||
|
console.log(decrypted)
|
||||||
|
const inflateRaw = denodeify(zlib.inflateRaw)
|
||||||
|
const decompressed = await inflateRaw(decrypted);
|
||||||
|
console.log(JSON.stringify(JSON.parse(decompressed.toString()), null, 4))
|
||||||
|
return JSON.parse(decompressed.toString('utf-8'));
|
||||||
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ const backend = new Router()
|
|||||||
|
|
||||||
const apiV1 = require('./apiV1-router')
|
const apiV1 = require('./apiV1-router')
|
||||||
api.use(apiV1)
|
api.use(apiV1)
|
||||||
|
const temp = require('./temp-router')
|
||||||
|
|
||||||
const products = require('./products-router')
|
const products = require('./products-router')
|
||||||
const login = require('./login-router')
|
const login = require('./login-router')
|
||||||
@ -13,21 +14,7 @@ backend.use(products)
|
|||||||
backend.use(login)
|
backend.use(login)
|
||||||
|
|
||||||
router.use('/api', api.routes())
|
router.use('/api', api.routes())
|
||||||
|
router.use('/temp', temp)
|
||||||
router.use('/backend', backend.routes())
|
router.use('/backend', backend.routes())
|
||||||
|
|
||||||
const base32 = require('hi-base32')
|
|
||||||
const crypto = require('crypto')
|
|
||||||
router.get('/temp/generate-new-license', async function(ctx) {
|
|
||||||
const licenseNum = base32.encode(crypto.randomBytes(15))
|
|
||||||
const licenseNumNice = licenseNum.match(/.{4}/g).join('-')
|
|
||||||
ctx.body = '<html><body>' +
|
|
||||||
`License for client: <pre>${licenseNumNice}</pre>` +
|
|
||||||
'SQL command to insert license into database with 2 licensed modules <strong>ccengine</strong> (windows app) and <strong>cndata</strong> (CN data): <pre>' +
|
|
||||||
`Insert Into License (productId, licenseNum, customerId) Values ('coc', '${licenseNum}', '123456');\n` +
|
|
||||||
`Insert Into LicensedModule (productId, licenseNum, moduleId) Values ('coc', '${licenseNum}', 'ccengine');\n` +
|
|
||||||
`Insert Into LicensedModule (productId, licenseNum, moduleId) Values ('coc', '${licenseNum}', 'cndata');\n` +
|
|
||||||
'</pre>' +
|
|
||||||
'</body></html>'
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|||||||
8
src/routes/temp-router.js
Normal file
8
src/routes/temp-router.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const Router = require('koa-router')
|
||||||
|
const ctrl = require('controllers').temp
|
||||||
|
const router = new Router()
|
||||||
|
|
||||||
|
router.get('/generate-new-license', ctrl.generateNewLicense);
|
||||||
|
router.get('/parse-offline-activation-request', ctrl.parseOfflineActivationRequest);
|
||||||
|
|
||||||
|
module.exports = router.routes()
|
||||||
9
test/testOffineActivationRequest.js
Normal file
9
test/testOffineActivationRequest.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const { parseOfflinePreactivationRequest} = require('../src/lib/generateLicenseFile')
|
||||||
|
|
||||||
|
parseOfflinePreactivationRequest(`-----BEGIN ACTIVATION REQUEST-----
|
||||||
|
8o4j86i3bfbWkHQ/quJGsjdjeDwkdaKFQb7L/+7nxueACWZ/x3msv8pt8iEbDoSX
|
||||||
|
i/MDZ5TRgav6Xw/bNl2K4uWvyBsHjnIn8+M3oxCVtxkLbXyOzdJfKrbls616mIUP
|
||||||
|
FiiQzW1Pa9P7L2ebXAPTDFe4v5OWyGRFfcrFvDMeK570KT4Ol/xwIE/obRF8WhXe
|
||||||
|
x2vr
|
||||||
|
-----END ACTIVATION REQUEST-----`).then(() => 0)
|
||||||
|
.catch((reason) => console.log(reason))
|
||||||
Loading…
Reference in New Issue
Block a user