commit
1e0a89d457
3 changed files with 15 additions and 6 deletions
|
|
@ -325,9 +325,9 @@ class Mediator {
|
||||||
const deviceId = socket.handshake.query['x-shockwallet-device-id']
|
const deviceId = socket.handshake.query['x-shockwallet-device-id']
|
||||||
socket.on(eventName, data => {
|
socket.on(eventName, data => {
|
||||||
try {
|
try {
|
||||||
// if (nonEncryptedEvents.includes(eventName)) {
|
if (Encryption.isNonEncrypted(eventName)) {
|
||||||
// return cb(data)
|
return cb(data)
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return cb(data)
|
return cb(data)
|
||||||
|
|
@ -350,7 +350,8 @@ class Mediator {
|
||||||
console.error('Unknown Device', error)
|
console.error('Unknown Device', error)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if(typeof data === 'string'){
|
console.log('Emitting Data...', data)
|
||||||
|
if (typeof data === 'string') {
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
}
|
}
|
||||||
console.log('Event:', eventName)
|
console.log('Event:', eventName)
|
||||||
|
|
@ -378,6 +379,11 @@ class Mediator {
|
||||||
},
|
},
|
||||||
emit: (eventName, data) => {
|
emit: (eventName, data) => {
|
||||||
try {
|
try {
|
||||||
|
if (Encryption.isNonEncrypted(eventName)) {
|
||||||
|
socket.emit(eventName, data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const deviceId = socket.handshake.query['x-shockwallet-device-id']
|
const deviceId = socket.handshake.query['x-shockwallet-device-id']
|
||||||
const authorized = Encryption.isAuthorizedDevice({ deviceId })
|
const authorized = Encryption.isAuthorizedDevice({ deviceId })
|
||||||
const encryptedMessage = authorized
|
const encryptedMessage = authorized
|
||||||
|
|
|
||||||
|
|
@ -327,7 +327,7 @@ module.exports = async (
|
||||||
try {
|
try {
|
||||||
const { publicKey, deviceId } = req.body;
|
const { publicKey, deviceId } = req.body;
|
||||||
|
|
||||||
if (!publicKey || publicKey.length < 600) {
|
if (!publicKey) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
field: 'publicKey',
|
field: 'publicKey',
|
||||||
message: "Please provide a valid public key"
|
message: "Please provide a valid public key"
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,10 @@ const { Buffer } = require('buffer')
|
||||||
const APIKeyPair = new Map()
|
const APIKeyPair = new Map()
|
||||||
const authorizedDevices = new Map()
|
const authorizedDevices = new Map()
|
||||||
|
|
||||||
|
const nonEncryptedEvents = ['ping', 'disconnect']
|
||||||
|
|
||||||
const Encryption = {
|
const Encryption = {
|
||||||
|
isNonEncrypted: event => nonEncryptedEvents.includes(event),
|
||||||
encryptKey: ({ deviceId, message }) => {
|
encryptKey: ({ deviceId, message }) => {
|
||||||
if (!authorizedDevices.has(deviceId)) {
|
if (!authorizedDevices.has(deviceId)) {
|
||||||
throw { field: 'deviceId', message: 'Unknown Device ID' }
|
throw { field: 'deviceId', message: 'Unknown Device ID' }
|
||||||
|
|
@ -87,7 +90,7 @@ const Encryption = {
|
||||||
Crypto.generateKeyPair(
|
Crypto.generateKeyPair(
|
||||||
'rsa',
|
'rsa',
|
||||||
{
|
{
|
||||||
modulusLength: 4096,
|
modulusLength: 2048,
|
||||||
privateKeyEncoding: {
|
privateKeyEncoding: {
|
||||||
type: 'pkcs1',
|
type: 'pkcs1',
|
||||||
format: 'pem'
|
format: 'pem'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue