セキュリティ対応OPC UAクライアントの作成
OPC UAのコア機能の1つは、セキュリティのサポートです。つまり、暗号化され署名されたプロトコル、ユーザー認証、認可がサポートされています。
この機能を実現するためには、各アプリケーション・インスタンス(プログラムのインストール)が独自のApplication Instance Certificate 、それに応じた秘密鍵を持つ必要があります。
アプリケーションは、自分で自己署名証明書を生成するか(Qt OPC UA X509サポートを参照)、OPC UA GDSを使用して認証局から証明書を取得するか、または単にユーザーが手動で作成した証明書で構成することができます。
UAアプリケーションの設定
クライアントが安全な接続を使用できるようにするには、以下のことが重要です。
- 正しいアプリケーションIDを設定する
m_identity = m_pkiConfig.applicationIdentity();
- SDKが証明書、秘密鍵、トラストリストなどを見つけられるように、PKIの場所を設定する。
たとえば、Qt OPC UA Viewer Exampleのコードを参照:
voidMainWindow::setupPkiConfiguration() {constQDirpkidir=QDir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+ "/pki");if(!pkidir.exists()&& !copyDirRecursively(":/pki",pkidir.path())) qFatal("Could not set up directory %s!", qUtf8Printable(pkidir.path())); m_pkiConfig.setClientCertificateFile(pkidir.absoluteFilePath("own/certs/opcuaviewer.der")); m_pkiConfig.setPrivateKeyFile(pkidir.absoluteFilePath("own/private/opcuaviewer.pem")); m_pkiConfig.setTrustListDirectory(pkidir.absoluteFilePath("trusted/certs")); m_pkiConfig.setRevocationListDirectory(pkidir.absoluteFilePath("trusted/crl")); m_pkiConfig.setIssuerListDirectory(pkidir.absoluteFilePath("issuers/certs")); m_pkiConfig.setIssuerRevocationListDirectory(pkidir.absoluteFilePath("issuers/crl"));constQStringListtoCreate={ m_pkiConfig.issuerListDirectory(),m_pkiConfig.issuerRevocationListDirectory() };for(constQString&dir: toCreate) {if(!QDir().mkpath(dir)) qFatal("Could not create directory %s!", qUtf8Printable(dir)); } }
この例では、Qtリソースシステムから、事前に設定された自己証明書と信頼済み証明書をファイルシステム内の書き込み可能な場所に展開します。残りの発行者(失効)リスト用のディレクトリは手動で作成します。
最初の接続
初めて接続するとき、クライアントはサーバ証明書を信頼する必要があります。
クライアントは証明書の警告(証明書の詳細)を表示し、証明書を信頼リストに保存できるようにする必要があります。例については、Qt OPC UA Viewer Exampleを参照のこと。
クライアントがサーバ証明書を受け入れたら、再度接続を試みることができる。このとき、サーバはクライアントの証明書を拒否することがあります。これは、一般的なエラー・コードBadSecurityChecksFailed で示されます。サーバーは通常、拒否された証明書を特別なフォルダ(rejected )に保存します。管理者は、これらを信頼リストに移動して、クライアントを信頼することができます。これにより、手動でクライアント証明書をサーバー・マシンにコピーする必要がなくなります。
サーバーがクライアントを信頼すると、すぐにセキュリティで接続できるようになります。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.