/** * Set authentication mode to PLAIN for SAS. * * @param transport The transport to set the SSL context to * @throws TransportException if setSslDomain throws IOException */ @Override protected void setSslDomain(Transport transport) throws TransportException { if (transport == null) { // Codes_SRS_AMQPSDEVICEAUTHENTICATIONX509_12_006: [The function shall throw IllegalArgumentException if any of the input parameter is null.] throw new IllegalArgumentException("Input parameter transport cannot be null."); } SslDomain domain = null; try { // Codes_SRS_AMQPSDEVICEAUTHENTICATIONX509_12_010: [The function shall call the prototype class makeDomain function with the sslContext.] domain = makeDomain(this.deviceClientConfig.getAuthenticationProvider().getSSLContext()); } catch (IOException e) { logger.LogDebug("setSslDomain has thrown exception: %s", e.getMessage()); throw new TransportException(e); } // Codes_SRS_AMQPSDEVICEAUTHENTICATIONX509_12_011: [The function shall set the domain on the transport.] transport.ssl(domain); }
/** * Create domain from the SSLContext, set the sasl mechanism to * ANONYMUS and set domain on the transport * * @param transport Proton-J Transport object * @throws TransportException if Proton throws IOException */ @Override protected void setSslDomain(Transport transport) throws TransportException { // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_011: [The function shall set get the sasl layer from the transport.] Sasl sasl = transport.sasl(); // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_012: [The function shall set the sasl mechanism to PLAIN.] sasl.setMechanisms("ANONYMOUS"); // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_013: [The function shall set the SslContext on the domain.] SslDomain domain = null; try { domain = makeDomain(this.deviceClientConfig.getAuthenticationProvider().getSSLContext()); } catch (IOException e) { logger.LogDebug("setSslDomain has thrown exception: %s", e.getMessage()); throw new TransportException(e); } // Codes_SRS_AMQPSDEVICEAUTHENTICATIONCBS_12_014: [The function shall set the domain on the transport.] transport.ssl(domain); }
/** * Event handler for the connection bound event * @param event The proton event object */ @Override public void onConnectionBound(Event event) { // Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_010: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token] // Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_011: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport] Transport transport = event.getConnection().getTransport(); if (transport != null) { if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) { WebSocketImpl webSocket = new WebSocketImpl(); webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null); ((TransportInternal)transport).addTransportLayer(webSocket); } Sasl sasl = transport.sasl(); sasl.plain(this.userName, this.sasToken); SslDomain domain = makeDomain(SslDomain.Mode.CLIENT); domain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER); Ssl ssl = transport.ssl(domain); } }
/** * Event handler for the connection bound event. Sets Sasl authentication and proper authentication mode. * @param event The Proton Event object. */ @Override public void onConnectionBound(Event event) { // Codes_SRS_AMQPSIOTHUBCONNECTION_15_030: [The event handler shall get the Transport (Proton) object from the event.] Transport transport = event.getConnection().getTransport(); if(transport != null){ if (this.useWebSockets) { WebSocketImpl webSocket = new WebSocketImpl(); webSocket.configure(this.hostName, webSocketPath, 0, webSocketSubProtocol, null, null); ((TransportInternal)transport).addTransportLayer(webSocket); } // Codes_SRS_AMQPSIOTHUBCONNECTION_15_031: [The event handler shall set the SASL_PLAIN authentication on the transport using the given user name and sas token.] Sasl sasl = transport.sasl(); sasl.plain(this.userName, this.sasToken); SslDomain domain = makeDomain(SslDomain.Mode.CLIENT); transport.ssl(domain); } synchronized (openLock) { openLock.notifyLock(); } }
@Override public void onConnectionBound(Event event) { logger.LogDebug("Entered in method %s", logger.getMethodName()); Transport transport = event.getConnection().getTransport(); if (transport != null) { if (this.saslListener != null) { //Calling sasl here adds a transport layer for handling sasl negotiation transport.sasl().setListener(this.saslListener); } if (this.useWebSockets) { WebSocketImpl webSocket = new WebSocketImpl(); webSocket.configure(this.hostName, WEB_SOCKET_PATH, 0, WEB_SOCKET_SUB_PROTOCOL, null, null); ((TransportInternal)transport).addTransportLayer(webSocket); } try { SslDomain domain = makeDomain(); transport.ssl(domain); } catch (IOException e) { logger.LogDebug("onConnectionBound has thrown exception while creating ssl context: %s", e.getMessage()); } } logger.LogDebug("Exited from method %s", logger.getMethodName()); }
@Override public void onConnectionBound(Event event) { // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token] // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport] Transport transport = event.getConnection().getTransport(); if (transport != null) { if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) { WebSocketImpl webSocket = new WebSocketImpl(); webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null); ((TransportInternal)transport).addTransportLayer(webSocket); } Sasl sasl = transport.sasl(); sasl.plain(this.userName, this.sasToken); SslDomain domain = makeDomain(SslDomain.Mode.CLIENT); domain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER); try { // Need the base trusted certs for IotHub in our ssl context. IotHubSSLContext handles that domain.setSslContext(new IotHubSSLContext().getSSLContext()); } catch (Exception e) { this.savedException = e; } Ssl ssl = transport.ssl(domain); } }
domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER); Ssl ssl = transport.ssl(domain);
Ssl ssl = transport.ssl(domain);
sasl.done(Sasl.SaslOutcome.PN_SASL_OK); transport.ssl(ctx.getDomain()); connection.open();