Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
ad983b30
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
ad983b30
编写于
4月 27, 2021
作者:
L
lightclient
提交者:
GitHub
4月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmd/puppeth: add support for authentication via ssh agent (#22634)
上级
85a0bab6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
24 deletion
+38
-24
cmd/puppeth/ssh.go
cmd/puppeth/ssh.go
+38
-24
未找到文件。
cmd/puppeth/ssh.go
浏览文件 @
ad983b30
...
...
@@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/terminal"
)
...
...
@@ -43,6 +44,8 @@ type sshClient struct {
logger
log
.
Logger
}
const
EnvSSHAuthSock
=
"SSH_AUTH_SOCK"
// dial establishes an SSH connection to a remote node using the current user and
// the user's configured private RSA key. If that fails, password authentication
// is fallen back to. server can be a string like user:identity@server:port.
...
...
@@ -79,38 +82,49 @@ func dial(server string, pubkey []byte) (*sshClient, error) {
if
username
==
""
{
username
=
user
.
Username
}
// Configure the supported authentication methods (private key and password)
var
auths
[]
ssh
.
AuthMethod
path
:=
filepath
.
Join
(
user
.
HomeDir
,
".ssh"
,
identity
)
if
buf
,
err
:=
ioutil
.
ReadFile
(
path
);
err
!=
nil
{
log
.
Warn
(
"No SSH key, falling back to passwords"
,
"path"
,
path
,
"err"
,
err
)
// Configure the supported authentication methods (ssh agent, private key and password)
var
(
auths
[]
ssh
.
AuthMethod
conn
net
.
Conn
)
if
conn
,
err
=
net
.
Dial
(
"unix"
,
os
.
Getenv
(
EnvSSHAuthSock
));
err
!=
nil
{
log
.
Warn
(
"Unable to dial SSH agent, falling back to private keys"
,
"err"
,
err
)
}
else
{
key
,
err
:=
ssh
.
ParsePrivateKey
(
buf
)
if
err
!=
nil
{
fmt
.
Printf
(
"What's the decryption password for %s? (won't be echoed)
\n
>"
,
path
)
blob
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
fmt
.
Println
(
)
if
err
!=
nil
{
log
.
Warn
(
"Couldn't read password"
,
"err"
,
err
)
}
key
,
err
:=
ssh
.
ParsePrivateKey
WithPassphrase
(
buf
,
blob
)
client
:=
agent
.
NewClient
(
conn
)
auths
=
append
(
auths
,
ssh
.
PublicKeysCallback
(
client
.
Signers
))
}
if
err
!=
nil
{
path
:=
filepath
.
Join
(
user
.
HomeDir
,
".ssh"
,
identity
)
if
buf
,
err
:=
ioutil
.
ReadFile
(
path
);
err
!=
nil
{
log
.
Warn
(
"No SSH key, falling back to passwords"
,
"path"
,
path
,
"err"
,
err
)
}
else
{
key
,
err
:=
ssh
.
ParsePrivateKey
(
buf
)
if
err
!=
nil
{
log
.
Warn
(
"Failed to decrypt SSH key, falling back to passwords"
,
"path"
,
path
,
"err"
,
err
)
fmt
.
Printf
(
"What's the decryption password for %s? (won't be echoed)
\n
>"
,
path
)
blob
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
fmt
.
Println
()
if
err
!=
nil
{
log
.
Warn
(
"Couldn't read password"
,
"err"
,
err
)
}
key
,
err
:=
ssh
.
ParsePrivateKeyWithPassphrase
(
buf
,
blob
)
if
err
!=
nil
{
log
.
Warn
(
"Failed to decrypt SSH key, falling back to passwords"
,
"path"
,
path
,
"err"
,
err
)
}
else
{
auths
=
append
(
auths
,
ssh
.
PublicKeys
(
key
))
}
}
else
{
auths
=
append
(
auths
,
ssh
.
PublicKeys
(
key
))
}
}
else
{
auths
=
append
(
auths
,
ssh
.
PublicKeys
(
key
))
}
}
auths
=
append
(
auths
,
ssh
.
PasswordCallback
(
func
()
(
string
,
error
)
{
fmt
.
Printf
(
"What's the login password for %s at %s? (won't be echoed)
\n
> "
,
username
,
server
)
blob
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
auths
=
append
(
auths
,
ssh
.
PasswordCallback
(
func
()
(
string
,
error
)
{
fmt
.
Printf
(
"What's the login password for %s at %s? (won't be echoed)
\n
> "
,
username
,
server
)
blob
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
fmt
.
Println
()
return
string
(
blob
),
err
}))
fmt
.
Println
()
return
string
(
blob
),
err
}))
}
// Resolve the IP address of the remote server
addr
,
err
:=
net
.
LookupHost
(
hostname
)
if
err
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录