【问题标题】:What's a reasonably secure way to store credentials at rest for use in a screen scraping application?什么是一种相当安全的方式来存储静态凭据以用于屏幕抓取应用程序?
【发布时间】:2014-02-09 20:22:05
【问题描述】:

凭借 PhantomJS,CasperJS 允许您指定在应用程序启动时加载的 JSON 文件。我将凭据存储在此文件中,这比将其硬编码在源文件中要好一些:

var json = require('testfile.json');

var username = json['username'];
var mykey = json['mykey'];

我的凭据仍然以纯文本形式存储在服务器上,我想远离它。此过程将是自动化的,因此我无法在每次运行时通过命令行参数传递凭据,也不想将参数存储在 Windows 任务计划程序中。什么是静态存储这些信息的安全方法?

【问题讨论】:

  • 严格意义上来说并不安全,但是将信息存储为环境变量呢?这些值仍然可以在注册表中使用,但这比将它们放在文本文件中要好一些。

标签: node.js security phantomjs casperjs


【解决方案1】:

使用本页列出的功能:http://lollyrock.com/articles/nodejs-encryption/

我能够根据自己的需要构建以下概念证明:

var crypto = require('crypto');

var algorithm = 'aes256';
var password = 'correcthorsestaplebattery';
var string = "Something I\'d like to encrypt, like maybe login credentials for a site I need to                 scrape.";

console.log('\n\nText: ' + string);

var encrypted = encrypt(new Buffer(string, "utf8"), algorithm, password);

console.log('\n\nEncrypted: ' + encrypted);

var decrypted = decrypt(encrypted, algorithm, password).toString('utf8');

console.log('\n\nDecrypted: ' + decrypted);

// check to prove 2-way encryption works
console.log('\n\nAre they the same before and after crypto? ');
console.log(decrypted == string);


function encrypt(buffer, algorithm, password){
    var cipher = crypto.createCipher(algorithm,password)
    var crypted = Buffer.concat([cipher.update(buffer),cipher.final()]);
    return crypted;
}

function decrypt(buffer, algorithm, password){
    var decipher = crypto.createDecipher(algorithm,password)
    var dec = Buffer.concat([decipher.update(buffer) , decipher.final()]);
    return dec;
}

这使用 AES256,它应该与 2 路加密一样安全,尽管我还不够先进,无法评论实现。反正比纯文本好。

由此,您可以轻松地将输出写入文件而不是控制台,如图所示。只要你只是解析一个包含 JSON 的文件,你只需要在解释它之前添加解密的步骤。

我希望这会有所帮助。

【讨论】:

  • 这不适用于纯 PhantomJS,因为它具有与 node.js 不同的运行时并且没有加密模块。虽然,PhantomJS 可以通过 node.js 的桥接运行。另一件事是,与普通凭据相比,这真的会更好吗?如果密钥/密码在驱动器上的某个地方,那么这只是一种奇特的混淆方式。如果确实使用网桥来运行 PhantomJS,则很可能可以从网络接口嗅探凭据,因为网桥处理通过网络进行的通信。
  • 我说它更好,因为它至少可以混淆。我只是想演示如何使加密工作;我提示用户输入密钥/密码以进行加密。这将解决他的问题,因为凭据解密可以在它自己的最小进程中运行,并在需要时返回解密的信息。但这并不能解决嗅探问题,根据信息的敏感程度,这可能是致命的。我会争辩说,有了这个漏洞,它仍然比使用纯文本更安全,因为即使是不熟练的人也可以访问这些凭据。
猜你喜欢
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-27
  • 2014-04-16
  • 2020-09-16
  • 1970-01-01
相关资源
最近更新 更多