0

我正在努力(几天以来)通过 ssl 在 as400 上连接到我们的 db2 数据库。对于使用 jaydebeapi 的数据库连接并使用安全连接访问数据库,我需要通过 jpype 函数将 trustStore 位置和 trustStore 密码附加到 JVM。这是我到目前为止所做的一个片段:

import jaydebeapi
import os
import jpype
import pandas as pd
from credentials_getter import get_db2_credentials


class i5Connection:
    def __init__(self, user, password):
        if jpype.isJVMStarted():
            print("already started!")

        filepath_script = os.path.dirname(os.path.abspath(__file__))
        ssl_trust_store_location = filepath_script + "/database/java-certs.jks"

        jar = filepath_script + '/database/jt400.jar'
        jvm_path = jpype.getDefaultJVMPath()
        jpype.startJVM(jvm_path,
                       '-Djava.class.path=%s' % jar,
                       '-Djavax.net.ssl.trustStore=%s' % ssl_trust_store_location +
                       '-Djavax.net.ssl.trustStorePassword=pw')

        connection_string = 'jdbc:as400://172.17.0.1/library'

        print(connection_string)

        self.conn = jaydebeapi.connect('com.ibm.as400.access.AS400JDBCDriver',
                                       connection_string,
                                       {'user': user,
                                        'password': password,
                                        'secure': 'true'},
                                       filepath_script + '/database/jt400.jar')

现在我遇到以下错误消息:

jpype._jexception.java.sql.SQLExceptionPyRaisable: java.sql.SQLException: The application requester cannot establish the connection. (PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target)

如果我从 startJVM 调用中删除 trustStoreLocation、密码和 jaydebeapi 调用的安全参数,它可以工作(没有加密) 谁能告诉我我做错了什么?是否有我还没有找到的好的 ibm 文档?

编辑:我找到了解决方法:我刚刚通过 keytool 手动将证书保存到 cacert:如何将现有的 Java 密钥库 (.jks) 文件导入 Java 安装? 不是真正的解决方案,但如果有人也被卡住了,希望对您有所帮助......

4

1 回答 1

0

这不是 JayDeBeApi 解决方案,但我可以使用 Python 连接到 HANA,并在 Mac 和 Windows 上使用此解决方案进行加密连接。

于 2021-04-21T20:09:50.140 回答