Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [milo-dev] migrate to 0.36

Thomas,

To filter on MessageSecuritiyMode just add another filter to the stream:
EndpointDescription endpoint = endpoints.stream()
.filter(e -> e.getSecurityPolicyUri().equals(securityPolicy.getUri()))
.filter(e -> e.getSecurityMode() == MessageSecurityMode.SignAndEncrypt) // filter a MessageSecurityMode here
.filter(clientExample.endpointFilter())
.findFirst()
.orElseThrow(() -> new Exception("no desired endpoints returned"));

I don't really understand what you were doing in the second question. What version are you upgrading from? It might be easiest to just wait for the 0.4 release where all the structures have toString() implementations.

On Tue, Dec 17, 2019 at 12:31 AM Thomas Haber <thomas@xxxxxxx> wrote:

Hi all,

for impulse 2 I've been working on migrating to milo 0.36 and have 2 questions:

1) Security Mode

I have a security mode and security polivy

// security
    public static final int SECURITY_NONE = 0;
    public static final int SECURITY_SIGN = 1;
    public static final int SECURITY_SIGN_ENCRYPT = 2;
    public static final String[] SECURITY_OPTIONS = { "None", "Sign", "Sign and Encrypt" };
    public int securityMode = SECURITY_NONE;
    public static final int POLICY_Basic128Rsa15 = 0;
    public static final int POLICY_Basic256 = 1;
    public static final int POLICY_Basic256Sha256 = 2;
    public static final int POLICY_NONE = 3;
    public static final String[] POLICY_OPTIONS = { "Basic128Rsa15", "Basic256", "Basic256Sha256", "None" };
    public int securityPolicy = POLICY_Basic128Rsa15;


In the previous release I compared both for getting the endpoint.

In the latest examples, just the policy is used:


        // Endpoint
        List<EndpointDescription> endpoints = null;
        try {
            endpoints = DiscoveryClient.getEndpoints(adapter.server).get();
        } catch (Throwable ex) {

            // try the explicit discovery endpoint as well
            String discoveryUrl = adapter.server;

            if (!discoveryUrl.endsWith("/")) {
                discoveryUrl += "/";
            }
            discoveryUrl += "discovery";

            logger.info("Trying explicit discovery URL: {}", discoveryUrl);
            endpoints = DiscoveryClient.getEndpoints(discoveryUrl).get();
        }

        // determine end point
        EndpointDescription endpoint = null;
        if (endpoint == null)
            endpoint = endpoints.stream().filter(e -> e.getSecurityPolicyUri().equals(securityPolicy.getUri())).findFirst()
                    .orElseThrow(() -> new Exception("No desired endpoints returned"));



How do i apply the security mode ? Is it done by passing public/private keys or not ?

        OpcUaClientConfig config = OpcUaClientConfig.builder().setApplicationName(LocalizedText.english(adapter.applicationName))
                .setApplicationUri(adapter.applicationUri).setProductUri(adapter.productUri).setCertificate(certificate).setKeyPair(clientKeyPair)


2) EncoderDelegate / DelegateRegistry for converting data values to String

In previous version I used the EncoderDelegate / DelegateRegistry to transform a UaSerializable to String. I dont find this anymore. How is it done now ?

    static public String valToString(Object value, int maxSize) {
        if (value != null && value.getClass().isArray()) {
            String combined = "";
            for (int n = 0; n < Array.getLength(value); n++) {
                combined += (combined.isEmpty() ? "" : "; ");
                String val = valToString(Array.get(value, n));
                if (val != null) {
                    combined += val;
                }
            }
            return combined;
        } else if (value instanceof DateTime)
            value = ((DateTime) value).getJavaDate().toString();
        else if (value instanceof ByteString)
            value = ((ByteString) value).toString();
        else if (value instanceof LocalizedText)
            value = ((LocalizedText) value).getText();
        else if (value instanceof QualifiedName)
            value = ((QualifiedName) value).toParseableString();
        else if (value instanceof NodeId)
            value = ((NodeId) value).toParseableString();
        else if (value instanceof ExpandedNodeId)
            value = ((ExpandedNodeId) value).toParseableString();
        else if (value instanceof UUID)
            value = ((UUID) value).toString();
        else if (value instanceof XmlElement)
            value = ((XmlElement) value).getFragment();
        else if (value instanceof StatusCode)
            value = ((StatusCode) value).isGood() ? "Good" : ((StatusCode) value).isBad() ? "Bad" : "Uncertain";
        else if (value instanceof Boolean)
            value = ((Boolean) value).toString();

        else if (value instanceof UaSerializable) {
            final StringBuilder writer = new StringBuilder();
            writer.append('{');
             EncoderDelegate<Object> delegate = DelegateRegistry.getInstance().getEncoder(value);
             delegate.encode(value, new UaEncoder() {
           
             private void append(String field, String valueOf) {
             if (writer.length() > 1)
             writer.append(';');
             writer.append(field);
             writer.append('=');
             writer.append(valueOf);
             }
           
             @Override
             public void encodeBoolean(String field, Boolean value) throws UaSerializationException {
             append(field, valToString(value));
             }
           
             @Override
             public void encodeSByte(String field, Byte value) throws UaSerializationException {
             append(field, valToString(value));
           
             }


...

thanks,

thomas




_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev

Back to the top