セキュリティ対応のOPC UAクライアントの作成
OPC UAの中核機能の一つはセキュリティのサポートであり、これにより、暗号による暗号化および署名されたプロトコル、ユーザー認証および認可のサポートが実現されます。
これを機能させるには、各アプリケーションインスタンス(プログラムのインストール)が、独自のApplication Instance Certificate とそれに対応する秘密鍵を保有している必要があります。
アプリケーションは、独自に自己署名証明書を生成する(Qt OPC UA のX509サポートを参照)、OPC UA GDSを使用して認証局から取得する、あるいはユーザーが手動で作成した証明書を設定する、といった方法のいずれかを選択できます。
UAアプリケーションの設定
クライアントがセキュアな接続を利用できるようにするには、以下の設定が重要です。
- 正しいアプリケーション ID を設定すること
m_identity = m_pkiConfig.applicationIdentity(); - SDK が証明書、秘密鍵、信頼リストなどを見つけられるように、PKI の場所を設定すること。
例えば、「Qt OPC UA Viewer」のサンプルコードを参照してください:
voidMainWindow::setupPkiConfiguration() { constQDir pkidir= 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")); constQStringList toCreate={ 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 のビューア例を参照してください。
クライアントがサーバー証明書を受け入れたら、再度接続を試みてください。この時点で、サーバーがクライアント証明書を拒否する場合があります。これは、汎用エラーコード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.