gpt4 book ai didi

node.js - 覆盖低级 node.js 模块

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:28 25 4
gpt4 key购买 nike

Amazon S3 允许静态网站托管,但要求存储桶名称必须与您的域名匹配。这意味着您的存储桶名称将类似于:mydomain.com。 Amazon S3 还为 *.s3.amazonaws.com 提供通配符 SSL 证书。根据 TLS 规则,这意味着 com.s3.amazonaws.com 包含在证书中,但 mybucket.com.s3.amazonaws.com 不包含。 Node 应用程序,如 Knox连接到 *.com.s3.amazonaws.com 的用户应该真的能够信任该证书,即使它违反了 TLS 规则,因为 knox 库是一个“封闭系统”:它只连接到亚马逊属性(property)。

Node模块https依赖于tls.jstls.js有这个功能:

function checkServerIdentity(host, cert) {
...
// "The client SHOULD NOT attempt to match a presented identifier in
// which the wildcard character comprises a label other than the
// left-most label (e.g., do not match bar.*.example.net)."
// RFC6125
if (!wildcards && /*/.test(host) || /[.*].**/.test(host) ||
/*/.test(host) && !/*.*..+..+/.test(host)) {
return /$./;
}

这将正确返回“证书不匹配”错误。上层 Knox 模块是否可以覆盖 checkServerIdentity 函数,该函数向下几层并且不由 Knox 直接调用?我知道如何覆盖我需要的库中的函数,但不知道这些库包含的库。

最佳答案

模块有一个全局缓存,这意味着您覆盖的任何函数都将被所有其他模块修改。我认为您可以自己包含 tls 并修补 checkServerIdentity:

// main.jsvar tls = require('tls'),    mod = require('./mod.js');tls.checkServerIdentity = function (host, cert) {  return true;};mod.test();
// mod.jsvar tls = require('tls');exports.test = function () {  console.log(tls.checkServerIdentity()); // true};

关于node.js - 覆盖低级 node.js 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15837904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com