Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
seatunnel-web
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
宋勇
seatunnel-web
Commits
c527a8d8
提交
c527a8d8
authored
4月 24, 2024
作者:
胡伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opcua代码提交
上级
67dd7e4c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
124 行增加
和
0 行删除
+124
-0
KeyStoreLoader.java
...che/seatunnel/datasource/plugin/opcua/KeyStoreLoader.java
+118
-0
pom.xml
...rce/seatunnel-datasource-plugins/datasource-opcua/pom.xml
+5
-0
pom.xml
seatunnel-datasource/seatunnel-datasource-plugins/pom.xml
+1
-0
没有找到文件。
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/KeyStoreLoader.java
0 → 100644
浏览文件 @
c527a8d8
package
org
.
apache
.
seatunnel
.
datasource
.
plugin
.
opcua
;
/*
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
import
org.eclipse.milo.opcua.sdk.server.util.HostnameUtil
;
import
org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateBuilder
;
import
org.eclipse.milo.opcua.stack.core.util.SelfSignedCertificateGenerator
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.security.*
;
import
java.security.cert.X509Certificate
;
import
java.util.Arrays
;
import
java.util.regex.Pattern
;
class
KeyStoreLoader
{
private
static
final
Pattern
IP_ADDR_PATTERN
=
Pattern
.
compile
(
"^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"
);
private
static
final
String
CLIENT_ALIAS
=
"client-ai"
;
private
static
final
char
[]
PASSWORD
=
"password"
.
toCharArray
();
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
X509Certificate
[]
clientCertificateChain
;
private
X509Certificate
clientCertificate
;
private
KeyPair
clientKeyPair
;
KeyStoreLoader
load
(
Path
baseDir
,
String
endPoint
)
throws
Exception
{
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"PKCS12"
);
Path
serverKeyStore
=
baseDir
.
resolve
(
"example-client.pfx"
);
logger
.
info
(
"Loading KeyStore at {}"
,
serverKeyStore
);
if
(!
Files
.
exists
(
serverKeyStore
))
{
keyStore
.
load
(
null
,
PASSWORD
);
KeyPair
keyPair
=
SelfSignedCertificateGenerator
.
generateRsaKeyPair
(
2048
);
SelfSignedCertificateBuilder
builder
=
new
SelfSignedCertificateBuilder
(
keyPair
)
.
setCommonName
(
"Eclipse Milo Example Client"
)
.
setOrganization
(
"digitalpetri"
)
.
setOrganizationalUnit
(
"dev"
)
.
setLocalityName
(
"Folsom"
)
.
setStateName
(
"CA"
)
.
setCountryCode
(
"US"
)
.
setApplicationUri
(
endPoint
);
// .addDnsName("localhost")
// .addIpAddress("192.168.0.101");
// Get as many hostnames and IP addresses as we can listed in the certificate.
for
(
String
hostname
:
HostnameUtil
.
getHostnames
(
"0.0.0.0"
))
{
if
(
IP_ADDR_PATTERN
.
matcher
(
hostname
).
matches
())
{
builder
.
addIpAddress
(
hostname
);
}
else
{
builder
.
addDnsName
(
hostname
);
}
}
X509Certificate
certificate
=
builder
.
build
();
keyStore
.
setKeyEntry
(
CLIENT_ALIAS
,
keyPair
.
getPrivate
(),
PASSWORD
,
new
X509Certificate
[]
{
certificate
});
try
(
OutputStream
out
=
Files
.
newOutputStream
(
serverKeyStore
))
{
keyStore
.
store
(
out
,
PASSWORD
);
}
}
else
{
try
(
InputStream
in
=
Files
.
newInputStream
(
serverKeyStore
))
{
keyStore
.
load
(
in
,
PASSWORD
);
}
}
Key
clientPrivateKey
=
keyStore
.
getKey
(
CLIENT_ALIAS
,
PASSWORD
);
if
(
clientPrivateKey
instanceof
PrivateKey
)
{
clientCertificate
=
(
X509Certificate
)
keyStore
.
getCertificate
(
CLIENT_ALIAS
);
clientCertificateChain
=
Arrays
.
stream
(
keyStore
.
getCertificateChain
(
CLIENT_ALIAS
))
.
map
(
X509Certificate
.
class
::
cast
)
.
toArray
(
X509Certificate
[]::
new
);
PublicKey
serverPublicKey
=
clientCertificate
.
getPublicKey
();
clientKeyPair
=
new
KeyPair
(
serverPublicKey
,
(
PrivateKey
)
clientPrivateKey
);
}
return
this
;
}
X509Certificate
getClientCertificate
()
{
return
clientCertificate
;
}
public
X509Certificate
[]
getClientCertificateChain
()
{
return
clientCertificateChain
;
}
KeyPair
getClientKeyPair
()
{
return
clientKeyPair
;
}
}
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua/pom.xml
浏览文件 @
c527a8d8
...
...
@@ -60,6 +60,11 @@
<artifactId>
sdk-client
</artifactId>
<version>
0.6.8
</version>
</dependency>
<dependency>
<groupId>
org.eclipse.milo
</groupId>
<artifactId>
sdk-server
</artifactId>
<version>
0.6.8
</version>
</dependency>
</dependencies>
</project>
seatunnel-datasource/seatunnel-datasource-plugins/pom.xml
浏览文件 @
c527a8d8
...
...
@@ -56,6 +56,7 @@
<module>
datasource-xml
</module>
<module>
datasource-csv
</module>
<module>
datasource-excel
</module>
<module>
datasource-opcua-kepserver
</module>
</modules>
<build>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论