Search in sources :

Example 1 with SignedIdentityToken

use of org.eclipse.milo.opcua.sdk.client.api.identity.SignedIdentityToken in project milo by eclipse.

the class SessionFsmFactory method activateSession.

@SuppressWarnings("Duplicates")
private static CompletableFuture<OpcUaSession> activateSession(FsmContext<State, Event> ctx, OpcUaClient client, CreateSessionResponse csr) {
    UaStackClient stackClient = client.getStackClient();
    try {
        EndpointDescription endpoint = client.getConfig().getEndpoint();
        ByteString csrNonce = csr.getServerNonce();
        SignedIdentityToken signedIdentityToken = client.getConfig().getIdentityProvider().getIdentityToken(endpoint, csrNonce);
        UserIdentityToken userIdentityToken = signedIdentityToken.getToken();
        SignatureData userTokenSignature = signedIdentityToken.getSignature();
        ActivateSessionRequest request = new ActivateSessionRequest(client.newRequestHeader(csr.getAuthenticationToken()), buildClientSignature(client.getConfig(), csrNonce), new SignedSoftwareCertificate[0], new String[0], ExtensionObject.encode(client.getStaticSerializationContext(), userIdentityToken), userTokenSignature);
        LOGGER.debug("[{}] Sending ActivateSessionRequest...", ctx.getInstanceId());
        return stackClient.sendRequest(request).thenApply(ActivateSessionResponse.class::cast).thenCompose(asr -> {
            ByteString asrNonce = asr.getServerNonce();
            // TODO check for repeated nonce?
            OpcUaSession session = new OpcUaSession(csr.getAuthenticationToken(), csr.getSessionId(), client.getConfig().getSessionName().get(), csr.getRevisedSessionTimeout(), csr.getMaxRequestMessageSize(), csr.getServerCertificate(), csr.getServerSoftwareCertificates());
            session.setServerNonce(asrNonce);
            return completedFuture(session);
        });
    } catch (Exception ex) {
        return failedFuture(ex);
    }
}
Also used : SignatureData(org.eclipse.milo.opcua.stack.core.types.structured.SignatureData) OpcUaSession(org.eclipse.milo.opcua.sdk.client.OpcUaSession) ActivateSessionRequest(org.eclipse.milo.opcua.stack.core.types.structured.ActivateSessionRequest) UaStackClient(org.eclipse.milo.opcua.stack.client.UaStackClient) ByteString(org.eclipse.milo.opcua.stack.core.types.builtin.ByteString) SignedIdentityToken(org.eclipse.milo.opcua.sdk.client.api.identity.SignedIdentityToken) EndpointDescription(org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription) UserIdentityToken(org.eclipse.milo.opcua.stack.core.types.structured.UserIdentityToken) CertificateEncodingException(java.security.cert.CertificateEncodingException) UaException(org.eclipse.milo.opcua.stack.core.UaException)

Aggregations

CertificateEncodingException (java.security.cert.CertificateEncodingException)1 OpcUaSession (org.eclipse.milo.opcua.sdk.client.OpcUaSession)1 SignedIdentityToken (org.eclipse.milo.opcua.sdk.client.api.identity.SignedIdentityToken)1 UaStackClient (org.eclipse.milo.opcua.stack.client.UaStackClient)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 ByteString (org.eclipse.milo.opcua.stack.core.types.builtin.ByteString)1 ActivateSessionRequest (org.eclipse.milo.opcua.stack.core.types.structured.ActivateSessionRequest)1 EndpointDescription (org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription)1 SignatureData (org.eclipse.milo.opcua.stack.core.types.structured.SignatureData)1 UserIdentityToken (org.eclipse.milo.opcua.stack.core.types.structured.UserIdentityToken)1