Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
suliangchun
dbeaver
提交
7d7eaedf
D
dbeaver
项目概览
suliangchun
/
dbeaver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dbeaver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7d7eaedf
编写于
9月 21, 2020
作者:
S
Serge Rider
提交者:
GitHub
9月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9829 from dbeaver/jsch-openssh-key#5845
#5845 Try to use system 'ssh-keygen'
上级
cb4ba5aa
894e8ff6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
11 deletion
+79
-11
plugins/org.jkiss.dbeaver.net.ssh.jsch/src/org/jkiss/dbeaver/model/net/ssh/SSHImplementationJsch.java
...rg/jkiss/dbeaver/model/net/ssh/SSHImplementationJsch.java
+79
-11
未找到文件。
plugins/org.jkiss.dbeaver.net.ssh.jsch/src/org/jkiss/dbeaver/model/net/ssh/SSHImplementationJsch.java
浏览文件 @
7d7eaedf
...
...
@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.model.net.ssh;
import
com.jcraft.jsch.*
;
import
org.jkiss.dbeaver.DBException
;
import
org.jkiss.dbeaver.Log
;
import
org.jkiss.dbeaver.model.DBPDataSourceContainer
;
import
org.jkiss.dbeaver.model.net.DBWHandlerConfiguration
;
import
org.jkiss.dbeaver.model.net.ssh.SSHConstants.AuthType
;
import
org.jkiss.dbeaver.model.runtime.DBRProgressMonitor
;
...
...
@@ -27,9 +28,12 @@ import org.jkiss.dbeaver.utils.GeneralUtils;
import
org.jkiss.dbeaver.utils.RuntimeUtils
;
import
org.jkiss.utils.CommonUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.*
;
import
java.lang.reflect.InvocationTargetException
;
import
java.nio.file.Files
;
import
java.nio.file.StandardCopyOption
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
* SSH tunnel
...
...
@@ -51,15 +55,10 @@ public class SSHImplementationJsch extends SSHImplementationAbstract {
String
autoTypeString
=
CommonUtils
.
toString
(
configuration
.
getProperty
(
SSHConstants
.
PROP_AUTH_TYPE
));
AuthType
authType
=
CommonUtils
.
isEmpty
(
autoTypeString
)
?
(
privKeyFile
==
null
?
AuthType
.
PASSWORD
:
AuthType
.
PUBLIC_KEY
)
:
CommonUtils
.
valueOf
(
AuthType
.
class
,
autoTypeString
,
AuthType
.
PASSWORD
);
(
privKeyFile
==
null
?
AuthType
.
PASSWORD
:
AuthType
.
PUBLIC_KEY
)
:
CommonUtils
.
valueOf
(
AuthType
.
class
,
autoTypeString
,
AuthType
.
PASSWORD
);
if
(
authType
==
AuthType
.
PUBLIC_KEY
)
{
if
(!
CommonUtils
.
isEmpty
(
configuration
.
getPassword
()))
{
jsch
.
addIdentity
(
privKeyFile
.
getAbsolutePath
(),
configuration
.
getPassword
());
}
else
{
jsch
.
addIdentity
(
privKeyFile
.
getAbsolutePath
());
}
addIdentityKey
(
monitor
,
configuration
.
getDataSource
(),
privKeyFile
,
configuration
.
getPassword
());
}
else
if
(
authType
==
AuthType
.
AGENT
)
{
log
.
debug
(
"Creating identityRepository"
);
IdentityRepository
identityRepository
=
new
DBeaverIdentityRepository
(
this
,
getAgentData
());
...
...
@@ -151,6 +150,75 @@ public class SSHImplementationJsch extends SSHImplementationAbstract {
}
}
private
void
addIdentityKey
(
DBRProgressMonitor
monitor
,
DBPDataSourceContainer
dataSource
,
File
key
,
String
password
)
throws
IOException
,
JSchException
{
String
header
;
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
key
)))
{
header
=
reader
.
readLine
();
}
/*
* This code is a workaround for JSCH because it cannot load
* newer private keys produced by ssh-keygen, so we need
* to convert it to the older format manually. This
* algorithm will fail if the 'ssh-keygen' cannot be found (#5845)
*/
if
(
header
.
equals
(
"-----BEGIN OPENSSH PRIVATE KEY-----"
))
{
log
.
debug
(
"Attempting to convert unsupported key"
);
File
dir
=
DBWorkbench
.
getPlatform
().
getTempFolder
(
monitor
,
"openssh-pkey"
);
File
tmp
=
new
File
(
dir
,
dataSource
.
getId
()
+
".pem"
);
Files
.
copy
(
key
.
toPath
(),
tmp
.
toPath
(),
StandardCopyOption
.
COPY_ATTRIBUTES
,
StandardCopyOption
.
REPLACE_EXISTING
);
Process
process
=
new
ProcessBuilder
()
.
command
(
"ssh-keygen"
,
"-p"
,
"-m"
,
"PEM"
,
"-f"
,
tmp
.
getAbsolutePath
(),
"-q"
,
"-N"
,
'"'
+
(
CommonUtils
.
isEmpty
(
password
)
?
""
:
password
)
+
'"'
)
.
start
();
try
{
if
(!
process
.
waitFor
(
5000
,
TimeUnit
.
MILLISECONDS
))
{
process
.
destroyForcibly
();
}
int
status
=
process
.
exitValue
();
if
(
status
!=
0
)
{
String
message
;
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getErrorStream
())))
{
message
=
reader
.
lines
().
collect
(
Collectors
.
joining
(
"\n"
));
}
throw
new
IOException
(
"Specified private key cannot be converted:\n"
+
message
);
}
addIdentityKey0
(
tmp
,
password
);
}
catch
(
InterruptedException
e
)
{
throw
new
IOException
(
e
);
}
finally
{
if
(!
tmp
.
delete
())
{
log
.
debug
(
"Failed to delete private key file"
);
}
}
}
else
{
addIdentityKey0
(
key
,
password
);
}
}
private
void
addIdentityKey0
(
File
key
,
String
password
)
throws
JSchException
{
if
(!
CommonUtils
.
isEmpty
(
password
))
{
jsch
.
addIdentity
(
key
.
getAbsolutePath
(),
password
);
}
else
{
jsch
.
addIdentity
(
key
.
getAbsolutePath
());
}
}
private
class
UIUserInfo
implements
UserInfo
,
UIKeyboardInteractive
{
DBWHandlerConfiguration
configuration
;
...
...
@@ -191,7 +259,7 @@ public class SSHImplementationJsch extends SSHImplementationAbstract {
@Override
public
String
[]
promptKeyboardInteractive
(
String
destination
,
String
name
,
String
instruction
,
String
[]
prompt
,
boolean
[]
echo
)
{
log
.
debug
(
"JSCH keyboard interactive auth"
);
return
new
String
[]
{
configuration
.
getPassword
()
}
;
return
new
String
[]
{
configuration
.
getPassword
()
}
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录