有关解决方案,请参阅下文
它昨天工作,但我不知道发生了什么事.
NPM没有安装包.主机名/ IP地址与证书的altnames不匹配:
主持人:registry.npmjs.org.不在证书的altnames中:DNS:a.sni.fastly.net,DNS:a.sni.global-ssl.fastly.net
这就是我想要做的事情:
>> ROOT: } npm install
up to date in 1.797s
>> ROOT: } npm install express-messages
npm ERR! request to https://registry.npmjs.org/express-messages failed, reason: Hostname/IP doesn't match certificate's altnames: "Host: registry.npmjs.org. is not in the cert's altnames: DNS:a.sni.fastly.net, DNS:a.sni.global-ssl.fastly.net"
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/prashant/.npm/_logs/2018-09-01T11_54_09_205Z-debug.log
>> ROOT: }
Run Code Online (Sandbox Code Playgroud)
我已经阅读了所有可以找到的文章/问题,并且还重新安装了Node.js和npm,但之后我也遇到了同样的问题.
操作系统:macOS v10.12(Sierra)(16A323)
日志
0 info it worked if it ends with ok
1 verbose cli [ …Run Code Online (Sandbox Code Playgroud) 所以,我今天早些时候遇到了一个问题,我写的客户端是在node禁止,因为我连接的服务器使用的是自签名证书.所以,我去了,并像任何不知情的开发人员那样rejectUnauthorized: false为我的tls.connect命令添加了选项.
我现在的问题是,这对我来说意味着什么?我的TLS连接是否只是一个可能是TLS连接的vanilla TCP连接?写这个作为TLS流完全没用吗?
更重要的是,该服务器,您知道具有自签名证书的服务器吗?我的流在这里和那里之间是否真的加密了?
我正在尝试使用带有自签名证书的Node.js 0.8.8创建TLS服务器/客户端设置.
基本的服务器代码看起来像
var tlsServer = tls.createServer({
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem')
}, function (connection) {
// [...]
});
tlsServer.listen(3000);
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试连接到此服务器时,我使用以下代码:
var connection = tls.connect({
host: '192.168.178.31',
port: 3000,
rejectUnauthorized: true,
ca: [ fs.readFileSync('server-cert.pem') ]
}, function () {
console.log(connection.authorized);
console.log(connection.authorizationError);
console.log(connection.getPeerCertificate());
});
Run Code Online (Sandbox Code Playgroud)
如果我删除该行
ca: [ fs.readFileSync('server-cert.pem') ]
Run Code Online (Sandbox Code Playgroud)
从客户端代码,Node.js抛出一个错误告诉我DEPTH_ZERO_SELF_SIGNED_CERT.据我了解,这是因为它是一个自签名证书,没有其他方信任该证书.
如果我删除
rejectUnauthorized: true,
Run Code Online (Sandbox Code Playgroud)
同样,错误消失了 - 但是connection.authorized等于false有效意味着我的连接没有加密.无论如何,使用getPeerCertificate()我可以访问服务器发送的证书.由于我想强制执行加密连接,我知道我可能不会删除此行.
现在我读到我可以使用该ca属性来指定我希望Node.js信任的任何CA. TLS模块的文档意味着它足以将服务器证书添加到ca阵列,然后一切都应该没问题.
如果我这样做,这个错误就消失了,但我得到了一个新错误:
Hostname/IP doesn't match certificate's altnames
Run Code Online (Sandbox Code Playgroud)
对我而言,这意味着CA现在基本上是可信的,因此现在没问题,但证书是为我使用的主机之外的其他主机制作的.
我使用创建了证书
$ …Run Code Online (Sandbox Code Playgroud) 我的设置目前看起来像:
API Gateway --- ALB --- ECS Cluster --- NodeJS Applications
|
-- Lambda
Run Code Online (Sandbox Code Playgroud)
我还在API网关上设置了自定义域名(更新:我使用了默认的API网关链接并遇到了同样的问题,我认为这不是自定义域名问题)
当ECS集群中的1个服务通过API网关调用另一个服务时,我得到了
主机名/ IP与证书的altnames不匹配:"Host:someid.ap-southeast-1.elb.amazonaws.com.不在证书的altnames中:DNS:*.execute-api.ap-southeast-1.amazonaws. COM"
为什么是这样?
UPDATE
我注意到当我启动调用API网关的本地服务器时,我收到类似的错误:
{
"error": "Hostname/IP doesn't match certificate's altnames: \"Host: localhost. is not in the cert's altnames: DNS:*.execute-api.ap-southeast-1.amazonaws.com\""
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试禁用HTTPS检查:
const response = await axios({
method: req.method,
url,
baseURL,
params: req.params,
query: req.query,
data: body || req.body,
headers: req.headers,
httpsAgent: new https.Agent({
: false // <<=== HERE!
})
})
Run Code Online (Sandbox Code Playgroud)
我得到了这个......
{
"message": "Forbidden"
}
Run Code Online (Sandbox Code Playgroud)
当我直接在Postman上调用底层API网关URL时,它工作......不知何故,它让我想起了CORS,服务器似乎阻止了我的服务器localhost或ECS/ELB访问我的API网关?
它可能很令人困惑,所以我尝试的总结:
rejectUnauthorized: false …https amazon-web-services node.js amazon-elb aws-api-gateway
我正在尝试使用nodemailer从我的应用程序发送电子邮件.
我的设置如下:
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transporter = nodemailer.createTransport(smtpTransport ({
host: 'smtp.companyname.dk',
secureConnection: true,
port: 587,
auth: {
user: 'support@companyname.dk',
pass: '****'
}
}));
var mailOptions = {
from: 'Olaf <ob@companyname.dk>',
to: 'john@test.dk',
subject: 'This is a test ',
text: 'Hello world ',
html: '<b>Hello world </b>'
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
});
Run Code Online (Sandbox Code Playgroud)
运行此后,它给我以下错误:
{ [Error: Hostname/IP doesn't match certificate's altnames: "Host: smtp.companyname.dk. is not in the …Run Code Online (Sandbox Code Playgroud) 我正在写一些节点代码来进行服务器端登录Facebook.我非常接近它完全正常运行,但我遇到麻烦,要求auth_code.我认为这可能与Facebook应用程序设置有关,Site URL但我尝试过的任何工作都没有.我正在使用节点版本0.8.14.
这是我要求的代码:
options =
host: 'graph.facebook.com'
port: 443
path: "/oauth/access_token?" + qs.stringify(
client_id: app_id
redirect_uri: my_url
client_secret: app_secret
code: vars.code)
https.get(options, (face_res)->
console.log face_res
)
Run Code Online (Sandbox Code Playgroud)
在face_res我得到几个像这样的对象:
authorizationError: 'Hostname/IP doesn\'t match certificate\'s altnames'
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏
我的端点上有一个反向代理,如下所示:
var express = require('express');
var app = express();
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
var serverOne = 'https://idena.navarra.es/ogc/wms?';
app.all('/idena', function (req, res) {
apiProxy.web(req, res, {target: serverOne});
});
app.listen(3000, function () {
console.log('Working!');
});
Run Code Online (Sandbox Code Playgroud)
当/idena收到请求时,服务器会抛出如下异常:
错误 [ERR_TLS_CERT_ALTNAME_INVALID]:主机名/IP 与证书的替代名称不匹配:主机:本地主机。不在证书的 altnames: DNS:idena.navarra.es, DNS: www.idena.navarra.es at Object.checkServerIdentity (tls.js:235:17) at TLSSocket.onConnectSecure (_tls_wrap.js:1061:27)在 TLSSocket.emit (events.js:189:13) 在 TLSSocket._finishInit (_tls_wrap.js:633:8)
我该如何解决这个问题?猜测是由于https但不知道如何避免这种情况,谢谢!
我想使用nodemailer从应用程序发送电子邮件,我的代码如下所示:
var smtpTransport = nodemailer.createTransport(smtpTransport({
pool: true,
host: 'smtp.myemailserver.com',
port: 587,
auth: {
user: 'user@myDomain.com',
pass: '******'
}
}));
var mailOptions = {
from: 'user@myDomain.com',
to: 'user2@gmail.com',
subject: 'test ',
text: 'Hello world ',
html: '<b>Hello world </b>'
};
smtpTransport.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
});
Run Code Online (Sandbox Code Playgroud)
但我得到我无法弄清的错误:
[Error: Hostname/IP doesn't match certificate's altnames: "Host: smtp.myemailserver.com. is not in the cert's altnames: DNS:secure.emailsrvr.com, DNS:www.secure.myemailserver.com"]
reason: 'Host: smtp.myemailserverr.com. is not in the cert\'s altnames: DNS:secure.myemailserver.com, DNS:www.myemailserver.com', …Run Code Online (Sandbox Code Playgroud) node.js ×7
javascript ×4
ssl ×3
express ×2
nodemailer ×2
amazon-elb ×1
coffeescript ×1
csr ×1
email ×1
facebook ×1
http-proxy ×1
https ×1
macos ×1
openssl ×1