QuickOPC User's Guide and Reference
AssureOwnCertificate Method (_EasyUAClientServerApplication)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.Application.ComTypes Namespace > _EasyUAClientServerApplication Interface : AssureOwnCertificate Method
Assures presence of the own certificate the application is currently configured to use.
Syntax
'Declaration
 
Function AssureOwnCertificate( _
   ByVal createOwnCertificateArguments As Object _
) As Boolean
'Usage
 
Dim instance As _EasyUAClientServerApplication
Dim createOwnCertificateArguments As Object
Dim value As Boolean
 
value = instance.AssureOwnCertificate(createOwnCertificateArguments)
bool AssureOwnCertificate( 
   object createOwnCertificateArguments
)
bool AssureOwnCertificate( 
   Object^ createOwnCertificateArguments
) 

Parameters

createOwnCertificateArguments

Return Value

Returns true if a new certificate has been created. Returns false if an existing certificate was found and accepted as the current own certificate.
Exceptions
ExceptionDescription

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.

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.

Remarks

If the own certificate does not exist in the certificate store prior to the operation, the method creates it. Otherwise, the method also checks whether the instance certificate is present in the trusted peers certificate store, and if it is absent, it copies it there. This is in contrast to the CreateOwnCertificate method, which always creates a new certificate when successful.

Example

.NET

// Shows how to assure presence of the own application certificate, and display its thumbprint.

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 AssureOwnCertificate
    {
        public static void Main1()
        {
            // Obtain the application interface.
            EasyUAApplication application = EasyUAApplication.Instance;
            
            try
            {
                Console.WriteLine("Assuring presence of the own application certificate...");
                bool created = application.AssureOwnCertificate();

                Console.WriteLine(created
                    ? "A new certificate has been created."
                    : "An existing certificate has been found.");

                Console.WriteLine();
                Console.WriteLine("Finding the current application certificate...");
                IPkiCertificate pkiCertificate = application.FindOwnCertificate();

                Console.WriteLine();
                Console.WriteLine($"The thumbprint of the current 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, and display its thumbprint.

# 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...')
    created = IEasyUAClientServerApplicationExtension.AssureOwnCertificate(application)

    print('A new certificate has been created.' if created else 'An existing certificate has been found.')

    print()
    print('Finding the current application certificate...')
    pkiCertificate = IEasyUAClientServerApplicationExtension.FindOwnCertificate(application)

    print()
    print('The thumbprint of the current 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