Assures presence of the own certificate pack the application is currently configured to use.
Assures presence of the own certificate pack the application is currently configured to use.
This method operates on certificates with certificate type Ids given by PackCertificateTypeIds.
The AssureOwnCertificatePack methods check if the application has its own application certificate pack (according to application configuration), and create the certificate pack if it is missing.
Returns
true
if a new certificate pack has been created. Returns
false
if an existing certificate pack was found and accepted as the current own certificate pack.
If the own certificate pack does not exist in the certificate store prior to the operation, the method creates it. Otherwise, the method also checks whether the instance certificates are present in the trusted peers certificate store, and if they are absent, it copies them there. This is in contrast to the CreateOwnCertificateOrCertificatePack method, which always creates new certificate(s) when successful.
Syntax
Return Value
Returns true
if a new certificate pack has been created. Returns false
if an existing certificate pack was found and accepted as the current own certificate pack.
Exceptions
Exception | Description |
System.Exception | An error has occurred during application execution. |
System.ArgumentNullException |
A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.
This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception. |
OpcLabs.EasyOpc.UA.OperationModel.UAException |
The OPC UA operation has failed. This operation exception in uniformly used to allow
common handling of various kinds of errors. The System.Exception.InnerException always contains
information about the actual error cause.
This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately. |
Example
// Shows how to assure presence of the own application certificate pack, and display default application certificate
// thumbprint.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.
using System;
using OpcLabs.BaseLib.Security.Cryptography.PkiCertificates;
using OpcLabs.EasyOpc.UA.Application;
using OpcLabs.EasyOpc.UA.Application.Extensions;
using OpcLabs.EasyOpc.UA.OperationModel;
namespace UADocExamples.Application._IEasyUAClientServerApplication
{
class AssureOwnCertificatePack
{
public static void Main1()
{
// Obtain the application interface.
EasyUAApplication application = EasyUAApplication.Instance;
try
{
Console.WriteLine("Assuring presence of the own application certificate pack...");
bool created = application.AssureOwnCertificatePack();
Console.WriteLine(created
? "A new certificate pack has been created."
: "An existing certificate pack has been found.");
Console.WriteLine();
Console.WriteLine("Finding the current default application certificate...");
IPkiCertificate pkiCertificate = application.FindOwnCertificate();
Console.WriteLine();
Console.WriteLine($"The thumbprint of the current default application certificate is: {pkiCertificate?.Thumbprint}");
}
catch (UAException uaException)
{
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
return;
}
}
}
}
' Shows how to assure presence of the own application certificate pack, and display default application certificate
' thumbprint.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.
Imports OpcLabs.BaseLib.Security.Cryptography.PkiCertificates
Imports OpcLabs.EasyOpc.UA.Application
Imports OpcLabs.EasyOpc.UA.Application.Extensions
Imports OpcLabs.EasyOpc.UA.OperationModel
Namespace Application._IEasyUAClientServerApplication
Friend Class AssureOwnCertificatePack
Public Shared Sub Main1()
' Obtain the application interface.
Dim application As EasyUAApplication = EasyUAApplication.Instance
Try
Console.WriteLine("Assuring presence of the own application certificate pack...")
Dim created As Boolean = application.AssureOwnCertificatePack()
Console.WriteLine(If(created,
"A new certificate pack has been created.",
"An existing certificate pack has been found."))
Console.WriteLine()
Console.WriteLine("Finding the current default application certificate...")
Dim pkiCertificate As IPkiCertificate = application.FindOwnCertificate()
Console.WriteLine()
Console.WriteLine($"The thumbprint of the current default application certificate is: {pkiCertificate?.Thumbprint}")
Catch uaException As UAException
Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
Exit Sub
End Try
End Sub
End Class
End Namespace
# Shows how to assure presence of the own application certificate pack, and display default application certificate
# thumbprint.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.Application import *
from OpcLabs.EasyOpc.UA.Application.Extensions import *
from OpcLabs.EasyOpc.UA.OperationModel import *
# Obtain the application interface.
application = EasyUAApplication.Instance
try:
print('Assuring presence of the own application certificate pack...')
created = IEasyUAClientServerApplicationExtension.AssureOwnCertificatePack(application)
print('A new certificate pack has been created.' if created else 'An existing certificate pack has been found.')
print()
print('Finding the current default application certificate...')
pkiCertificate = IEasyUAClientServerApplicationExtension.FindOwnCertificate(application)
print()
print('The thumbprint of the current default application certificate is: ',
None if pkiCertificate is None else pkiCertificate.Thumbprint,
sep='')
except UAException as uaException:
print('*** Failure: ' + uaException.GetBaseException().Message)
exit()
print()
print('Finished.')
Requirements
Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows
See Also