Search in sources :

Example 1 with UaRuntimeException

use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project netxms by netxms.

the class ServerConnection method getNodeValue.

/**
 * Get value of given node, connecting to server as necessary
 *
 * @param name node symbolic name
 * @return node value or null to indicate unsupported node
 * @throws Exception
 */
public synchronized String getNodeValue(String name) throws Exception {
    connect();
    NodeId nodeId;
    try {
        nodeId = NodeId.parse(name);
    } catch (UaRuntimeException e) {
        Platform.writeDebugLog(6, String.format("OPCUA: error parsing node ID \"%s\"", name));
        return null;
    }
    try {
        return readNodeValue(nodeId);
    } catch (ExecutionException e) {
        return handleExecutionException(e, () -> {
            return readNodeValue(nodeId);
        });
    } catch (Exception e) {
        Platform.writeDebugLog(6, String.format("OPCUA: exception in getNodeValue(%s) call for %s (%s)", name, url, e.getMessage()));
        Platform.writeDebugLog(6, "OPCUA:   ", e);
        return null;
    }
}
Also used : UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) ExecutionException(java.util.concurrent.ExecutionException) UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) UaServiceFaultException(org.eclipse.milo.opcua.stack.core.UaServiceFaultException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with UaRuntimeException

use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project netxms by netxms.

the class ServerConnection method writeNode.

/**
 * @param node
 * @param value
 * @return
 * @throws Exception
 */
public boolean writeNode(String node, String value) throws Exception {
    connect();
    NodeId nodeId;
    try {
        nodeId = NodeId.parse(node);
    } catch (UaRuntimeException e) {
        Platform.writeDebugLog(6, String.format("OPCUA: error parsing node ID \"%s\"", node));
        return false;
    }
    try {
        return writeNodeValue(nodeId, value);
    } catch (ExecutionException e) {
        return handleExecutionException(e, () -> {
            return writeNodeValue(nodeId, value);
        });
    } catch (Exception e) {
        Platform.writeDebugLog(6, String.format("OPCUA: exception in writeNode(%s,%s) call for %s (%s)", node, value, url, e.getMessage()));
        Platform.writeDebugLog(6, "OPCUA:   ", e);
        return false;
    }
}
Also used : UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) ExecutionException(java.util.concurrent.ExecutionException) UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) UaServiceFaultException(org.eclipse.milo.opcua.stack.core.UaServiceFaultException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with UaRuntimeException

use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project milo by eclipse.

the class PShaUtil method createKey.

private static byte[] createKey(String transformation, byte[] secret, byte[] seed, int offset, int length) {
    try {
        Mac mac = Mac.getInstance(transformation);
        byte[] tempBytes = hash(transformation, secret, seed, mac, offset + length);
        byte[] key = new byte[length];
        System.arraycopy(tempBytes, offset, key, 0, key.length);
        return key;
    } catch (Exception e) {
        throw new UaRuntimeException(StatusCodes.Bad_InternalError, e);
    }
}
Also used : UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) Mac(javax.crypto.Mac) UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException)

Example 4 with UaRuntimeException

use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project milo by eclipse.

the class ExpandedNodeId method parse.

/**
 * Parse {@code s} into an {@link ExpandedNodeId}.
 *
 * @param s the String to parse.
 * @return an {@link ExpandedNodeId}.
 * @throws UaRuntimeException if parsing fails.
 */
public static ExpandedNodeId parse(String s) {
    try {
        String[] parts = s.split(";");
        NodeId nodeId = NodeId.parse(parts[parts.length - 1]);
        UInteger serverIndex = UInteger.MIN;
        UShort namespaceIndex = UShort.MIN;
        String namespaceUri = null;
        Object identifier = nodeId.getIdentifier();
        for (String part : parts) {
            String[] ss = part.split("=", 2);
            if ("svr".equals(ss[0])) {
                serverIndex = uint(Integer.parseInt(ss[1]));
            } else if ("ns".equals(ss[0])) {
                namespaceIndex = ushort(Integer.parseInt(ss[1]));
            } else if ("nsu".equals(ss[0])) {
                namespaceUri = ss[1];
            }
        }
        return new ExpandedNodeId(namespaceIndex, namespaceUri, identifier, serverIndex);
    } catch (Throwable t) {
        throw new UaRuntimeException(StatusCodes.Bad_NodeIdInvalid, t);
    }
}
Also used : UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) UShort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort)

Example 5 with UaRuntimeException

use of org.eclipse.milo.opcua.stack.core.UaRuntimeException in project milo by eclipse.

the class SessionManager method getServerSignature.

private SignatureData getServerSignature(SecurityPolicy securityPolicy, KeyPair keyPair, ByteString clientNonce, ByteString clientCertificate) throws UaException {
    if (securityPolicy == SecurityPolicy.None) {
        return new SignatureData(null, null);
    } else {
        try {
            SecurityAlgorithm algorithm = securityPolicy.getAsymmetricSignatureAlgorithm();
            byte[] data = Bytes.concat(clientCertificate.bytes(), clientNonce.bytes());
            byte[] signature = SignatureUtil.sign(algorithm, keyPair.getPrivate(), ByteBuffer.wrap(data));
            return new SignatureData(algorithm.getUri(), ByteString.of(signature));
        } catch (UaRuntimeException e) {
            throw new UaException(StatusCodes.Bad_SecurityChecksFailed);
        }
    }
}
Also used : SignatureData(org.eclipse.milo.opcua.stack.core.types.structured.SignatureData) UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) UaException(org.eclipse.milo.opcua.stack.core.UaException) SecurityAlgorithm(org.eclipse.milo.opcua.stack.core.security.SecurityAlgorithm)

Aggregations

UaRuntimeException (org.eclipse.milo.opcua.stack.core.UaRuntimeException)11 UaException (org.eclipse.milo.opcua.stack.core.UaException)4 X509Certificate (java.security.cert.X509Certificate)3 UaServiceFaultException (org.eclipse.milo.opcua.stack.core.UaServiceFaultException)3 ByteBuf (io.netty.buffer.ByteBuf)2 File (java.io.File)2 KeyPair (java.security.KeyPair)2 ExecutionException (java.util.concurrent.ExecutionException)2 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)2 OpcUaServerConfig (org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfig)2 ErrorMessage (org.eclipse.milo.opcua.stack.core.channel.messages.ErrorMessage)2 DefaultCertificateManager (org.eclipse.milo.opcua.stack.core.security.DefaultCertificateManager)2 DefaultTrustListManager (org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager)2 DateTime (org.eclipse.milo.opcua.stack.core.types.builtin.DateTime)2 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)2 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)2 BuildInfo (org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo)2 SelfSignedHttpsCertificateBuilder (org.eclipse.milo.opcua.stack.core.util.SelfSignedHttpsCertificateBuilder)2 EndpointConfiguration (org.eclipse.milo.opcua.stack.server.EndpointConfiguration)2 DefaultServerCertificateValidator (org.eclipse.milo.opcua.stack.server.security.DefaultServerCertificateValidator)2