summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLena Biliaieva <lena.biliaieva@qt.io>2023-12-15 17:06:00 +0100
committerLena Biliaieva <lena.biliaieva@qt.io>2023-12-20 16:21:08 +0100
commit9d261156f2ea820604518fcbe0a8574f3ed3c7fb (patch)
tree714b0360d8fafd2f9c2134bdf5e5936bf6714acc
parent7cae7a714e24b141222bd84db5096f10e7ec44ef (diff)
Review QtOpcUa X509 Support Ex: Review documentation
Remove "Example" from the title. Update documentation with the more detailed description. Update example names at QDoc config file. Task-number: QTBUG-119845 Pick-to: 6.7 Change-Id: I64a69fd79e20687234b438d2c1d411b566c4b93d Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
-rw-r--r--examples/opcua/x509/doc/x509.qdoc24
-rw-r--r--examples/opcua/x509/main.cpp10
-rw-r--r--src/opcua/doc/qtopcua.qdocconf4
3 files changed, 35 insertions, 3 deletions
diff --git a/examples/opcua/x509/doc/x509.qdoc b/examples/opcua/x509/doc/x509.qdoc
index a3d61b2..c709688 100644
--- a/examples/opcua/x509/doc/x509.qdoc
+++ b/examples/opcua/x509/doc/x509.qdoc
@@ -4,10 +4,32 @@
/*!
\example x509
\ingroup qtopcua-examples
- \title Qt OPC UA X509 Support Example
+ \title Qt OPC UA X509 Support
\examplecategory {Data Processing & I/O}
\brief Shows how to generate keys and certificate signing requests.
This example shows how client applications can generate their own self-signed certificate
or generate a certificate signing request.
+
+ \section1 Generating RSA key
+ At first, an RSA key is generated:
+ \snippet x509/main.cpp 0
+
+ The private key can be saved to a file for further usage:
+ \snippet x509/main.cpp 1
+
+ \section1 Generating certificate signing requests
+
+ Next, a certificate signing request is created. It is also necessary to set the subject
+ of the certificate and add all the extensions needed for OPC UA.
+ \snippet x509/main.cpp 2
+
+ Now there are two options: \br
+
+ 1. When you need to get your certificate signing request signed by a certificate authority,
+ you have to use the request data.
+ \snippet x509/main.cpp 3
+
+ 2. When there is no certificate authority, you have to self-sign the request.
+ \snippet x509/main.cpp 4
*/
diff --git a/examples/opcua/x509/main.cpp b/examples/opcua/x509/main.cpp
index cc505d4..21aaf7f 100644
--- a/examples/opcua/x509/main.cpp
+++ b/examples/opcua/x509/main.cpp
@@ -18,18 +18,23 @@ int main(int argc, char **argv)
Q_UNUSED(argv);
// Generate RSA Key
+ //! [0]
QOpcUaKeyPair key;
key.generateRsaKey(QOpcUaKeyPair::RsaKeyStrength::Bits2048);
+ //! [0]
// Save private key to file
+ //! [1]
QByteArray keyData = key.privateKeyToByteArray(QOpcUaKeyPair::Cipher::Unencrypted, QString());
QFile keyFile(u"privateKey.pem"_s);
keyFile.open(QFile::WriteOnly);
keyFile.write(keyData);
keyFile.close();
+ //! [1]
// Create a certificate signing request
+ //! [2]
QOpcUaX509CertificateSigningRequest csr;
// Set the subject of the certificate
@@ -40,6 +45,7 @@ int main(int argc, char **argv)
dn.setEntry(QOpcUaX509DistinguishedName::Type::StateOrProvinceName, u"Berlin"_s);
dn.setEntry(QOpcUaX509DistinguishedName::Type::OrganizationName, u"The Qt Company"_s);
csr.setSubject(dn);
+ //! [2]
// The subject alternative name extension is needed for OPC UA
QOpcUaX509ExtensionSubjectAlternativeName *san = new QOpcUaX509ExtensionSubjectAlternativeName;
@@ -77,10 +83,14 @@ int main(int argc, char **argv)
// 2. When there is no certificate authority you have to self-sign the request.
// Option 1
+ //! [3]
QByteArray certificateSigningRequestData = csr.createRequest(key);
+ //! [3]
// Option 2
+ //! [4]
QByteArray selfSignedCertificateData = csr.createSelfSignedCertificate(key);
+ //! [4]
return 0;
}
diff --git a/src/opcua/doc/qtopcua.qdocconf b/src/opcua/doc/qtopcua.qdocconf
index a3e7774..d7008b8 100644
--- a/src/opcua/doc/qtopcua.qdocconf
+++ b/src/opcua/doc/qtopcua.qdocconf
@@ -49,10 +49,10 @@ navigation.qmltypespage = "Qt OPC UA QML Types"
examplesinstallpath = opcua
# Add a generic thumbnail to an example that has none
-manifestmeta.thumbnail.names += "QtOpcUa/Qt OPC UA X509 Support Example"
+manifestmeta.thumbnail.names += "QtOpcUa/Qt OPC UA X509 Support"
# Highlighted examples in Data Processing & IO category
-manifestmeta.highlighted.names = "QtOpcUa/Waterpump Example"
+manifestmeta.highlighted.names = "QtOpcUa/Water Pump"
depends += \
qtcore \