Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getEncryptedVars (data) {
const utf16Data = iconv.encode(data, 'utf16')
const keyBuf = crypto.createHash('sha256').update('abcdefghijk').digest()
const ivBuf = Buffer.from('MTCSTA0000000009')
const cipher = crypto.createCipheriv('aes-256-cbc', keyBuf, ivBuf)
const buf1 = cipher.update(utf16Data)
const buf2 = cipher.final()
const encBuf = Buffer.concat([buf1, buf2])
// We need to encrypt the keyBuf and ivBuf with the public key of the recipient
const encKeyBuf = crypto.publicEncrypt(recipientFakePublicKey, keyBuf)
const encIvBuf = crypto.publicEncrypt(recipientFakePublicKey, ivBuf)
// Create a signature: a signed hash of the encrypted data using the senders private keyBuf
const sign = crypto.createSign('RSA-SHA1')
sign.write(encBuf)
sign.end()
const signatureB64 = sign.sign(senderFakePrivateKey, 'base64')
function toBuffer(buf, charset) {
if (buf == null || Buffer.isBuffer(buf)) {
return buf;
}
buf += '';
if (charset && typeof charset === 'string' && !UTF8_RE.test(charset)) {
try {
charset = charset.toLowerCase();
if (charset === 'base64') {
return Buffer.from(buf, 'base64');
}
return iconv.encode(buf, charset);
} catch (e) {}
}
return Buffer.from(buf);
}
export function encode(string, encoding = 'utf8') {
if (encoding === 'utf8') return Buffer.from(string, 'utf8')
if (!iconv.encodingExists(encoding))
throw new Error(`Encoding does not exist: "${encoding}"`)
return iconv.encode(string, encoding)
}
export default function adjustEncoding(config) {
const input = fs.readFileSync(config.input);
const inputFileEncoding = getEncoding(input);
const output = fs.readFileSync(config.output.js);
const outputFileEncoding = getEncoding(output);
const sourceContent = iconv.decode(output, outputFileEncoding);
const content = iconv.encode(sourceContent, inputFileEncoding);
fs.writeFileSync(config.output.js, content);
}
function encode(text, useCesu8) {
return (useCesu8) ?
iconv.encode(text, 'cesu8') :
new Buffer(text, 'utf-8');
}
this.getDoorSysBuffer = function() {
var up = self.client.user.properties;
var now = moment();
var secLevel = self.client.user.getLegacySecurityLevel().toString();
// :TODO: fix time remaining
// :TODO: fix default protocol -- user prop: transfer_protocol
return iconv.encode( [
'COM1:', // "Comm Port - COM0: = LOCAL MODE"
'57600', // "Baud Rate - 300 to 38400" (Note: set as 57600 instead!)
'8', // "Parity - 7 or 8"
self.client.node.toString(), // "Node Number - 1 to 99"
'57600', // "DTE Rate. Actual BPS rate to use. (kg)"
'Y', // "Screen Display - Y=On N=Off (Default to Y)"
'Y', // "Printer Toggle - Y=On N=Off (Default to Y)"
'Y', // "Page Bell - Y=On N=Off (Default to Y)"
'Y', // "Caller Alarm - Y=On N=Off (Default to Y)"
up.real_name || self.client.user.username, // "User Full Name"
up.location || 'Anywhere', // "Calling From"
'123-456-7890', // "Home Phone"
'123-456-7890', // "Work/Data Phone"
'NOPE', // "Password" (Note: this is never given out or even stored plaintext)
secLevel, // "Security Level"
up.login_count.toString(), // "Total Times On"
function convertIconvLite(str, to, from) {
if (to === 'UTF-8') {
return iconvLite.decode(str, from);
} else if (from === 'UTF-8') {
return iconvLite.encode(str, to);
} else {
return iconvLite.encode(iconvLite.decode(str, from), to);
}
}
Client.prototype.methodCall = function methodCall(method, params, callback) {
var buff = Iconv.encode(Serializer.serializeMethodCall(method, params), 'ISO-8859-1')
, transport = this.isSecure ? https : http
, options = this.options
options.headers['Content-Length'] = buff.length
options.headers['Content-Type'] = 'text/xml; charset=iso-8859-1'
this.headersProcessors.composeRequest(options.headers)
var request = transport.request(options, function(response) {
if (response.statusCode == 404) {
callback(new Error('Not Found'));
}
else {
this.headersProcessors.parseResponse(response.headers)
var deserializer = new Deserializer(options.responseEncoding)
deserializer.deserializeMethodResponse(response, callback)
}
function writeParam(out, val, encoding) {
let param = Buffer.isEncoding(encoding)
? Buffer.from(val, encoding)
: Iconv.encode(val, encoding);
out.writeLengthCoded(param.length);
out.writeBuffer(param, 0, param.length);
}