Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.handleRequest = function (done, body) {
var sig = SharedAccessSignature.parse(config.sharedAccessSignature);
if (config.host === 'bad') { // bad host
done(new Error('getaddrinfo ENOTFOUND bad'));
}
else if (sig.skn === 'bad') { // bad policy
done(createError());
}
else {
var cmpSig = SharedAccessSignature.create(sig.sr, sig.skn, 'bad', sig.se).toString();
if (config.sharedAccessSignature === cmpSig) { // bad key
done(createError());
}
else { // ok
done(null, body, new Response(204));
}
}
};
}
export function create(host: string, deviceId: string, key: string, expiry: string | number): SharedAccessSignature {
/*Codes_SRS_NODE_DEVICE_SAS_05_004: [ shall be the URL-encoded value of deviceId.]*/
const uri = encodeUriComponentStrict(host + '/devices/' + deviceId);
/*Codes_SRS_NODE_DEVICE_SAS_05_003: [The create method shall return the result of calling azure-iot-common.SharedAccessSignature.create with following arguments:
resourceUri - host + '%2Fdevices%2F' +
keyName - null
key - key
expiry - expiry]*/
return SharedAccessSignature.create(uri, null, key, expiry);
}
create: function create(host, policy, key, expiry) {
/*Codes_SRS_NODE_IOTHUB_SAS_05_003: [The create method shall return the result of calling azure-iot-common.SharedAccessSignature.create with following arguments:
resourceUri - host
keyName - policy
key - key
expiry - expiry]*/
return Base.create(host, policy, key, expiry);
},
parse: function parse(source) {
protected _sign(resourceUri: string, expiry: number, callback: (err: Error, signature?: string) => void): void {
callback(null, SharedAccessSignature.create(resourceUri, this._credentials.sharedAccessKeyName, this._credentials.sharedAccessKey, expiry).toString());
}
function calPasswd(connectionString) {
var se = Math.round(new Date().getTime() / 1000) + 24 * 3600;
var uri = encodeUriComponentStrict(connectionString['HostName'] + '/devices/' + connectionString['DeviceId']);
return SharedAccessSignature.create(uri, null, connectionString['SharedAccessKey'], se).toString();
}
export function create(host: string, policy: string, key: string, expiry: string | number): SharedAccessSignature {
/*Codes_SRS_NODE_IOTHUB_SAS_05_003: [The create method shall return the result of calling azure-iot-common.SharedAccessSignature.create with following arguments:
resourceUri - host
keyName - policy
key - key
expiry - expiry]*/
return SharedAccessSignature.create(host, policy, key, expiry);
}