fixed authentication on non-windows platforms

This commit is contained in:
CaramelKat
2020-05-14 23:10:56 -05:00
committed by Jay
parent 9600c24e8e
commit 2b2c3c1ecc
7 changed files with 79 additions and 83 deletions

View File

@@ -2,6 +2,7 @@
"http": {
"port": 8080
},
"secret": "b213a890ac28739a0fc0e47f034308c1",
"mongoose": {
"uri": "mongodb://localhost:27017",
"database": "Miiverse",

View File

@@ -17,7 +17,7 @@ logger.info('[MIIVERSE] Creating \'discovery\' subdomain');
router.use(subdomain('discovery.olv', discovery));
logger.info('[MIIVERSE] Creating \'api\' subdomain');
router.use(subdomain('api.olv', api));
router.use(subdomain('d551f9ba', api));
router.use(subdomain('f2d99ded', api));
logger.info('[MIIVERSE] Importing middleware');

View File

@@ -62,9 +62,6 @@ router.post('/', upload.none(), async function (req, res, next) {
catch (e)
{
console.error(e);
}
finally
{
res.set("Content-Type", "application/xml");
res.statusCode = 400;
response = {

File diff suppressed because one or more lines are too long

View File

@@ -2,6 +2,7 @@ const crypto = require('crypto');
const NodeRSA = require('node-rsa');
const fs = require('fs-extra');
const database = require('../database');
const config = require('../config.json');
const xmlParser = require('xml2json');
const request = require("request");
const moment = require('moment');
@@ -58,10 +59,12 @@ let methods = {
return out;
},
processServiceToken: function(token) {
console.log(token);
let B64token = Buffer.from(token, 'base64');
console.log(B64token);
let decryptedToken = this.decryptToken(B64token);
let PID = decryptedToken.readUInt32LE(0x2);
return PID;
console.log(decryptedToken);
return decryptedToken.readUInt32LE(0x2);
},
@@ -87,7 +90,7 @@ let methods = {
const cryptoOptions = {
private_key: fs.readFileSync(`${cryptoPath}/private.pem`),
hmac_secret: fs.readFileSync(`${cryptoPath}/secret.key`)
hmac_secret: config.secret
};
const privateKey = new NodeRSA(cryptoOptions.private_key, 'pkcs1-private-pem', {
@@ -110,10 +113,12 @@ let methods = {
let decryptedBody = decipher.update(encryptedBody);
decryptedBody = Buffer.concat([decryptedBody, decipher.final()]);
console.log("secret: " + cryptoOptions.hmac_secret);
const hmac = crypto.createHmac('sha1', cryptoOptions.hmac_secret).update(decryptedBody);
const calculatedSignature = hmac.digest();
const calculatedSignature = hmac.digest();
console.log(calculatedSignature);
console.log(signature);
if (!calculatedSignature.equals(signature)) {
console.log('Token signature did not match');
return null;