Search in sources :

Example 21 with SecurityPolicy

use of org.eclipse.milo.opcua.stack.core.security.SecurityPolicy in project vantiq-extension-sources by Vantiq.

the class Connection method runCertTest.

public void runCertTest(List<String> certList, boolean expectFailure) throws Exception {
    List<EndpointDescription> eps = exampleServer.getServer().getEndpointDescriptions();
    EnumSet<MessageSecurityMode> serverMsgModes = EnumSet.noneOf(MessageSecurityMode.class);
    EnumSet<SecurityPolicy> serverSecPols = EnumSet.noneOf(SecurityPolicy.class);
    for (EndpointDescription ep : eps) {
        if (ep.getEndpointUrl().startsWith("opc.tpc")) {
            // At present, these are all we test
            serverSecPols.add(SecurityPolicy.fromUri(ep.getSecurityPolicyUri()));
            serverMsgModes.add(ep.getSecurityMode());
        }
    }
    // If expecting failure, act as if async so we can catch exceptions
    boolean runSync = expectFailure;
    // Below, we'll traverse the valid combinations.  None's must be paired and are tested elsewhere
    for (SecurityPolicy secPol : serverSecPols) {
        if (!secPol.equals(SecurityPolicy.None)) {
            for (MessageSecurityMode msgSec : serverMsgModes) {
                if (!msgSec.equals(MessageSecurityMode.None)) {
                    // Defaults tested in *Upw test...
                    for (String certKey : certList) {
                        log.info("Attempting sync connection using [{}, {}] using certificate: '{}'", secPol, msgSec, certKey);
                        makeConnection(runSync, secPol.getUri(), msgSec.toString(), OpcConstants.CONFIG_IDENTITY_CERTIFICATE, certKey, true);
                        log.info("Attempting async connection using [{}, {}] using certificate: '{}'", secPol, msgSec, certKey);
                        makeConnection(true, secPol.getUri(), msgSec.toString(), OpcConstants.CONFIG_IDENTITY_CERTIFICATE, certKey, true);
                    }
                }
            }
        }
    }
}
Also used : MessageSecurityMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MessageSecurityMode) SecurityPolicy(org.eclipse.milo.opcua.stack.core.security.SecurityPolicy) EndpointDescription(org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription)

Aggregations

SecurityPolicy (org.eclipse.milo.opcua.stack.core.security.SecurityPolicy)21 UaException (org.eclipse.milo.opcua.stack.core.UaException)14 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)14 EndpointDescription (org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription)13 X509Certificate (java.security.cert.X509Certificate)12 MessageSecurityMode (org.eclipse.milo.opcua.stack.core.types.enumerated.MessageSecurityMode)11 KeyPair (java.security.KeyPair)7 List (java.util.List)5 SecurityAlgorithm (org.eclipse.milo.opcua.stack.core.security.SecurityAlgorithm)5 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)5 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)5 ByteBuf (io.netty.buffer.ByteBuf)4 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)4 ServerSecureChannel (org.eclipse.milo.opcua.stack.core.channel.ServerSecureChannel)4 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)4 Test (org.junit.Test)4 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)3 ByteBuffer (java.nio.ByteBuffer)3 PrivateKey (java.security.PrivateKey)3 ArrayList (java.util.ArrayList)3