Node.js https.get或https.request中的Kerberos身份验证

问题描述 投票:15回答:4

我正在尝试编写一个简单的脚本,该脚本从内部网络上的工具请求一些数据。这是代码:

#!/usr/bin/node

var https = require('https');
var fs = require('fs');

var options = {
  host: '<link>',
  port: 443,
  path: '<path>',
  auth: 'username:password',
  ca: [fs.readFileSync('../.cert/newca.crt')]
};

https.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
  res.on('data', function (d) {
    console.log('BODY: ' + d);
  });
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});

现在的问题是,我该如何使用Kerberos票证进行身份验证,而不是以纯文本格式提供auth:中的凭据?

javascript node.js https kerberos
4个回答
3
投票

用Paul Scheltema的答案,您需要从操作系统的深度获取票证数据。您(或代表您的模块)必须使用GSS-API才能由Active Directory生成票证数据。

Chrome中存在这种机制,但似乎它没有包含在Node.js(仅Chrome中的javascript引擎中,因此您可能需要添加一个模块,例如:

要安装/编译这样的模块,您可能需要安装Visual Studio。


要设置环境,-在所有计算机上,必须在端口88(Kerberos)和53(dns)上启用tcp和udp。-在Windows Server上,Active Directory必须正在运行(ldap,dns,kdc)-在https://www.npmjs.org/package/passport-kerberos页上,他们使用术语REALM。这是域的名称,大写字母


6
投票

来自http://docs.oracle.com/cd/E24191_01/common/tutorials/authn_kerberos_service.html

用于消息级标准的客户端令牌位置:Kerberos服务票证可以在Authorization HTTP标头中发送,也可以在在邮件本身内部,例如元件。或者,它可以包含在消息中属性。选择以下选项之一:

所以您提供票证而不是您的用户名:密码

或者您可以如下所述将信息放入消息正文中或作为消息属性

var request = https.request(options, function(resource) {
  var chunks = [];
   resource.on('data', function (chunk) {
     chunks.push(chunk);
   });
   resource.on('end', function () {
     var data = chunks.join('');
     console.log(data);
   });
}

request.on('error',...)
request.send('<body-with-ticket>');
request.end();

编辑:

“”部分是我在哪里使用票证的示例,将其放入多字型正文中并发送,或者使用WWW-Authenticate标头发送该票证

例如将其添加到https.request上的选项

options = {
    host: 'hostname',
    port: 443, 
    'WWW-Authenticate': 'Negotiate ' + ticketdata
};

google上有一些很好的图表,说明其工作原理:https://developers.google.com/search-appliance/kb/secure/kerberos-diagram


5
投票

我已经使用0.0.12版的“ kerberos”模块来完成此工作。我用工作示例创建了一个要点:

https://gist.github.com/dmansfield/c75817dcacc2393da0a7

基本上,您使用三种方法来获取“授权”标题数据:

  • authGSSClientInit,它需要服务名称,例如[email protected]
  • authGSSClientStep,它需要存在凭据缓存(在Linux上,您可以通过执行“ kinit”获得此凭据,并可以通过“ klist”进行验证),并实际上将您需要的base64内容还给您(无需开头的“ Negotiate”字符串)
  • authGSSClientClean,将释放所有分配的内存结构

然后您创建一个“ Authorization”标头(如上图所示,不是WWW-Authenticate,这是服务器发回的内容,它应该可以工作。

注意:通常,Web浏览器请求资源,在响应中返回WWW-Authenticate:Negotiate标头,然后返回401,然后使用“ Authorization”标头中提供的票证数据重新请求资源。每个资源都会发生两步舞。我不确定这是否意味着什么。


0
投票

如果在Windows上,则可以使用SSPI界面。它通过项目node-expose-sspi在Node上公开。

SSPI接口允许您使用SSO(NTLM和Kerberos)编写任何客户端或服务器。

https://github.com/jlguenego/node-expose-sspi

注意:我是node-expose-sspi的作者。

© www.soinside.com 2019 - 2024. All rights reserved.