节点 ssh2 服务器不接受 Objective-Git/libgit2 SSH 连接
Node ssh2 server not accepting Objective-Git/libgit2 SSH connection
我正在尝试使用密钥对通过 SSH 将 Objective-Git/libgit2 应用程序连接到远程 运行 mscdex 的节点 ssh2 服务器。
libgit2 应用程序可以连接到服务器上的sshd
并实现推送。它正在实施 libgit2 的 git_cred_ssh_key_new
,然后是 git_remote_connect
.
但是,当应用程序尝试连接到 ssh2 服务器时,服务器接受 ssh-userauth
服务,但在 ssh-connection
服务中,方法类型是 'none',而不是'publickey'.
或者,当我使用 git(而不是通过 libgit2 的应用程序)连接到 ssh2 服务器时,ssh2 服务器接受 ssh-connection
服务并实现方法类型'publickey'.
所以,我不确定问题出在哪里:在 'publickey' 方法类型的 libgit2 实现中,或者 ssh2 服务器落入方法类型 'none'.
非常感谢任何指点或帮助。谢谢。
ssh2 服务器(示例服务器):
new ssh2.Server({
hostKeys: [fs.readFileSync('/Users/almccann/Sites/thenewpop/ssh2server/host_rsa')],
debug: function (cfg) {
console.log('debug', cfg);
}
}, function(client) {
console.log('Client connected!');
client.on('authentication', function(ctx) {
// ctx.method === 'none', no ctx.key
if (ctx.method === 'publickey'
&& ctx.key.algo === pubKey.fulltype
&& buffersEqual(ctx.key.data, pubKey.public)) {
if (ctx.signature) {
var verifier = crypto.createVerify(ctx.sigAlgo);
verifier.update(ctx.blob);
if (verifier.verify(pubKey.publicOrig, ctx.signature))
ctx.accept();
else
ctx.reject();
} else {
ctx.accept();
}
} else
ctx.reject();
}).on('ready', function() {
console.log('Client authenticated!');
}).on('end', function() {
console.log('Client disconnected');
});
})
.listen(22, '127.0.0.1', function() {
console.log('Listening on port ' + this.address().port);
});
none
身份验证方法基本上顾名思义,它只是一种允许客户端访问服务器而无需提供任何类型的凭据或其他信息的身份验证方法。这就是为什么在那种情况下没有 ctx.key
。
大多数服务器在拒绝身份验证方法时会将有效的身份验证方法中继回客户端,但这不是必需的(尽管某些客户端专门依赖于此,这实际上是一件坏事)。假设 ssh 客户端 是 期待这个列表,你可以做这样的事情来表示你只接受 publickey
身份验证:
client.on('authentication', function(ctx) {
if (ctx.method === 'publickey'
&& ctx.key.algo === pubKey.fulltype
&& buffersEqual(ctx.key.data, pubKey.public)) {
if (ctx.signature) {
var verifier = crypto.createVerify(ctx.sigAlgo);
verifier.update(ctx.blob);
if (verifier.verify(pubKey.publicOrig, ctx.signature))
ctx.accept();
else
ctx.reject();
} else {
ctx.accept();
}
} else
ctx.reject(['publickey']); // <==============
});
我正在尝试使用密钥对通过 SSH 将 Objective-Git/libgit2 应用程序连接到远程 运行 mscdex 的节点 ssh2 服务器。
libgit2 应用程序可以连接到服务器上的sshd
并实现推送。它正在实施 libgit2 的 git_cred_ssh_key_new
,然后是 git_remote_connect
.
但是,当应用程序尝试连接到 ssh2 服务器时,服务器接受 ssh-userauth
服务,但在 ssh-connection
服务中,方法类型是 'none',而不是'publickey'.
或者,当我使用 git(而不是通过 libgit2 的应用程序)连接到 ssh2 服务器时,ssh2 服务器接受 ssh-connection
服务并实现方法类型'publickey'.
所以,我不确定问题出在哪里:在 'publickey' 方法类型的 libgit2 实现中,或者 ssh2 服务器落入方法类型 'none'.
非常感谢任何指点或帮助。谢谢。
ssh2 服务器(示例服务器):
new ssh2.Server({
hostKeys: [fs.readFileSync('/Users/almccann/Sites/thenewpop/ssh2server/host_rsa')],
debug: function (cfg) {
console.log('debug', cfg);
}
}, function(client) {
console.log('Client connected!');
client.on('authentication', function(ctx) {
// ctx.method === 'none', no ctx.key
if (ctx.method === 'publickey'
&& ctx.key.algo === pubKey.fulltype
&& buffersEqual(ctx.key.data, pubKey.public)) {
if (ctx.signature) {
var verifier = crypto.createVerify(ctx.sigAlgo);
verifier.update(ctx.blob);
if (verifier.verify(pubKey.publicOrig, ctx.signature))
ctx.accept();
else
ctx.reject();
} else {
ctx.accept();
}
} else
ctx.reject();
}).on('ready', function() {
console.log('Client authenticated!');
}).on('end', function() {
console.log('Client disconnected');
});
})
.listen(22, '127.0.0.1', function() {
console.log('Listening on port ' + this.address().port);
});
none
身份验证方法基本上顾名思义,它只是一种允许客户端访问服务器而无需提供任何类型的凭据或其他信息的身份验证方法。这就是为什么在那种情况下没有 ctx.key
。
大多数服务器在拒绝身份验证方法时会将有效的身份验证方法中继回客户端,但这不是必需的(尽管某些客户端专门依赖于此,这实际上是一件坏事)。假设 ssh 客户端 是 期待这个列表,你可以做这样的事情来表示你只接受 publickey
身份验证:
client.on('authentication', function(ctx) {
if (ctx.method === 'publickey'
&& ctx.key.algo === pubKey.fulltype
&& buffersEqual(ctx.key.data, pubKey.public)) {
if (ctx.signature) {
var verifier = crypto.createVerify(ctx.sigAlgo);
verifier.update(ctx.blob);
if (verifier.verify(pubKey.publicOrig, ctx.signature))
ctx.accept();
else
ctx.reject();
} else {
ctx.accept();
}
} else
ctx.reject(['publickey']); // <==============
});