true
if the credentials are acceptable, otherwise
16 | * false
.
17 | */
18 | boolean authenticate(String userName, String password);
19 |
20 | /**
21 | * The realm value to be used in the request for proxy authentication
22 | * ("Proxy-Authenticate" header). Returning null will cause the string
23 | * "Restricted Files" to be used by default.
24 | *
25 | * @return
26 | */
27 | String getRealm();
28 | }
29 |
--------------------------------------------------------------------------------
/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/helpers/proxy/SslEngineSource.java:
--------------------------------------------------------------------------------
1 | package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy;
2 |
3 | import javax.net.ssl.SSLEngine;
4 |
5 | /**
6 | * Source for {@link SSLEngine}s.
7 | */
8 | public interface SslEngineSource {
9 |
10 | /**
11 | * Returns an {@link SSLEngine} to use for a server connection from
12 | * LittleProxy to the client.
13 | *
14 | * @return
15 | */
16 | SSLEngine newSslEngine();
17 |
18 | /**
19 | * Returns an {@link SSLEngine} to use for a client connection from
20 | * LittleProxy to the upstream server. *
21 | *
22 | * Note: Peer information is needed to send the server_name extension in
23 | * handshake with Server Name Indication (SNI).
24 | *
25 | * @param peerHost
26 | * to start a client connection to the server.
27 | * @param peerPort
28 | * to start a client connection to the server.
29 | * @return
30 | */
31 | SSLEngine newSslEngine(String peerHost, int peerPort);
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/helpers/proxy/TransportProtocol.java:
--------------------------------------------------------------------------------
1 | package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy;
2 |
3 | /**
4 | * Enumeration of transport protocols supported by LittleProxy.
5 | */
6 | public enum TransportProtocol {
7 | TCP, UDT
8 | }
--------------------------------------------------------------------------------
/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/helpers/proxy/UnknownTransportProtocolException.java:
--------------------------------------------------------------------------------
1 | package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy;
2 |
3 | /**
4 | * This exception indicates that the system was asked to use a TransportProtocol that it didn't know how to handle.
5 | */
6 | public class UnknownTransportProtocolException extends RuntimeException {
7 | private static final long serialVersionUID = 1L;
8 |
9 | public UnknownTransportProtocolException(TransportProtocol transportProtocol) {
10 | super(String.format("Unknown TransportProtocol: %1$s", transportProtocol));
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/helpers/proxy/extras/SelfSignedMitmManager.java:
--------------------------------------------------------------------------------
1 | package tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.extras;
2 |
3 | import io.netty.handler.codec.http.HttpRequest;
4 | import tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy.MitmManager;
5 |
6 | import javax.net.ssl.SSLEngine;
7 | import javax.net.ssl.SSLSession;
8 |
9 | /**
10 | * {@link MitmManager} that uses self-signed certs for everything.
11 | */
12 | public class SelfSignedMitmManager implements MitmManager
13 | {
14 | SelfSignedSslEngineSource selfSignedSslEngineSource =
15 | new SelfSignedSslEngineSource(true);
16 |
17 | @Override
18 | public SSLEngine serverSslEngine(String peerHost, int peerPort) {
19 | return selfSignedSslEngineSource.newSslEngine(peerHost, peerPort);
20 | }
21 |
22 | @Override
23 | public SSLEngine serverSslEngine() {
24 | return selfSignedSslEngineSource.newSslEngine();
25 | }
26 |
27 | @Override
28 | public SSLEngine clientSslEngineFor(HttpRequest httpRequest, SSLSession serverSslSession) {
29 | return selfSignedSslEngineSource.newSslEngine();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/iot-e2e-tests/common/src/test/java/tests/integration/com/microsoft/azure/sdk/iot/helpers/proxy/readme.md:
--------------------------------------------------------------------------------
1 | The code within this directory is a copy of the [LittleProxy](https://github.com/adamfisk/LittleProxy)
2 | library that has fallen out of maintenence. Some small modifications made to accomodate more
3 | recent dependency versions of Guava since this library has security vulenerabilities otherwise.
4 |
5 | The code within this directory will not be published in any manner and is only used for test purposes.
--------------------------------------------------------------------------------
/iot-e2e-tests/common/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | status = error
2 | name = Log4j2PropertiesConfig
3 |
4 | appenders = console
5 |
6 | appender.console.type = Console
7 | appender.console.name = LogToConsole
8 | appender.console.layout.type = PatternLayout
9 | appender.console.layout.pattern = %d %p (%t) [%c] - %m%n
10 |
11 | # Uncomment these lines to log from everything, including SDK and tests. LittleProxy and Netty make a lot
12 | # of logs though, so leaving this commented out and just printing SDK and test logs instead.
13 | #rootLogger.level = debug
14 | #rootLogger.appenderRefs = stdout
15 | #rootLogger.appenderRef.stdout.ref = LogToConsole
16 |
17 | # Log levels for the test HTTP proxy
18 | logger.testproxy.name = tests.integration.com.microsoft.azure.sdk.iot.helpers.proxy
19 | logger.testproxy.level = INFO
20 |
21 | # Log test logs at this level
22 | logger.tests.name = tests.integration.com.microsoft.azure.sdk.iot
23 | logger.tests.level = DEBUG
24 |
25 | logger.sdk.name = com.microsoft.azure.sdk.iot
26 | logger.sdk.level = INFO
27 |
28 | # Logs from this class in particular don't add anything helpful for us
29 | logger.retry.name = com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter
30 | logger.retry.level = ERROR
31 |
32 |
--------------------------------------------------------------------------------
/iot-e2e-tests/docker/haproxy/errors/400.http:
--------------------------------------------------------------------------------
1 | HTTP/1.0 400 Bad request
2 | Cache-Control: no-cache
3 | Connection: close
4 | Content-Type: text/html
5 |
6 | The client is connected, and ready to be used.
11 | */ 12 | CONNECTED, 13 | 14 | /** 15 | * The device or module is disconnected. 16 | *Inspect the associated {@link com.microsoft.azure.sdk.iot.device.IotHubConnectionStatusChangeReason} returned (and exception thrown, if any), and take appropriate action.
17 | */ 18 | DISCONNECTED, 19 | 20 | /** 21 | * The device or module is attempting to reconnect. 22 | *The client is attempting to recover the connection. Do NOT close or open the client instance when it is retrying.
23 | */ 24 | DISCONNECTED_RETRYING 25 | } -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/NoRetry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) Microsoft. All rights reserved. 4 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | * 6 | */ 7 | 8 | package com.microsoft.azure.sdk.iot.device.transport; 9 | 10 | import lombok.extern.slf4j.Slf4j; 11 | 12 | /** 13 | * Represents a retry policy that performs no retries. 14 | */ 15 | @Slf4j 16 | public class NoRetry implements RetryPolicy 17 | { 18 | public NoRetry() 19 | { 20 | log.info("NOTE: A new instance of NoRetry has been created, the client will not perform any retries on disconnect."); 21 | } 22 | /** 23 | * Always says to not retry. 24 | * 25 | * @param currentRetryCount the number of retries for the given operation 26 | * @param lastException the last exception encountered 27 | * @return the retry decision. 28 | */ 29 | public RetryDecision getRetryDecision(int currentRetryCount, TransportException lastException) 30 | { 31 | return new RetryDecision(false, 0); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/ProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport; 7 | 8 | /** 9 | * Exception class that covers all exceptions that occur within transport protocol communication. For example, if a 10 | * amqp:connection:forced exception is given by AMQP. 11 | */ 12 | public class ProtocolException extends TransportException 13 | { 14 | public ProtocolException() 15 | { 16 | super(); 17 | } 18 | 19 | public ProtocolException(String message) 20 | { 21 | super(message); 22 | } 23 | 24 | public ProtocolException(String message, Throwable cause) 25 | { 26 | super(message, cause); 27 | } 28 | 29 | public ProtocolException(Throwable cause) 30 | { 31 | super(cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/RetryPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) Microsoft. All rights reserved. 4 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 5 | * 6 | */ 7 | package com.microsoft.azure.sdk.iot.device.transport; 8 | 9 | /** 10 | * An interface for the retry policy. 11 | */ 12 | public interface RetryPolicy 13 | { 14 | /** 15 | * Determines whether the operation should be retried and the interval until the next retry. 16 | * 17 | * @param currentRetryCount the number of retries for the given operation 18 | * @param lastException the latest exception explaining why the retry is happening. This exception is guaranteed to 19 | * be retryable. In the event of a terminal exception occurring, this API will not be called. 20 | * Looking at this exception allows you to prevent retry on certain retryable exceptions, but 21 | * does not allow you to retry exceptions that are terminal. 22 | * @return the retry decision. 23 | */ 24 | RetryDecision getRetryDecision(int currentRetryCount, TransportException lastException); 25 | } -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/AmqpsMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.amqps; 7 | 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import org.apache.qpid.proton.amqp.transport.DeliveryState; 11 | import org.apache.qpid.proton.engine.Delivery; 12 | import org.apache.qpid.proton.message.impl.MessageImpl; 13 | 14 | /** 15 | * Extension of the QPID-Proton-J MessageImpl class which implements the Message interface. Adds a Delivery object as a 16 | * private member variable and adds a new ACK_TYPE enum. Adds the ability to easily acknowledge a single message. 17 | */ 18 | public class AmqpsMessage extends MessageImpl 19 | { 20 | @Getter 21 | @Setter 22 | private Delivery delivery; 23 | 24 | /** 25 | * Sends acknowledgement of this message using the provided ACK_TYPE. 26 | * 27 | * @param ackType acknowledgement type to send 28 | */ 29 | public void acknowledge(DeliveryState ackType) 30 | { 31 | delivery.disposition(ackType); 32 | delivery.settle(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/AmqpsSendResult.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.sdk.iot.device.transport.amqps; 2 | 3 | import lombok.Getter; 4 | 5 | import java.nio.charset.StandardCharsets; 6 | 7 | public class AmqpsSendResult 8 | { 9 | private static final int failedDeliveryTag = -1; 10 | 11 | @Getter 12 | private final boolean deliverySuccessful; 13 | @Getter 14 | private final int deliveryTag; 15 | 16 | /** 17 | * Create a return value object containing the delivery status and the delivery hash 18 | * 19 | */ 20 | AmqpsSendResult() 21 | { 22 | this.deliverySuccessful = false; 23 | this.deliveryTag = failedDeliveryTag; 24 | } 25 | 26 | AmqpsSendResult(byte[] deliveryTag) 27 | { 28 | this.deliverySuccessful = true; 29 | this.deliveryTag = Integer.parseInt(new String(deliveryTag, StandardCharsets.UTF_8)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/AuthenticationMessageCallback.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.sdk.iot.device.transport.amqps; 2 | 3 | import org.apache.qpid.proton.amqp.transport.DeliveryState; 4 | import org.apache.qpid.proton.reactor.Reactor; 5 | 6 | interface AuthenticationMessageCallback 7 | { 8 | DeliveryState handleAuthenticationResponseMessage(int status, String description, Reactor reactor); 9 | } 10 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/ReactorRunnerStateCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | package com.microsoft.azure.sdk.iot.device.transport.amqps; 5 | 6 | /** 7 | * Callback for all Reactor level events that our AMQP code should handle 8 | */ 9 | interface ReactorRunnerStateCallback 10 | { 11 | /** 12 | * Executed when the proton-j reactor closed unexpectedly. For example, if the reactor encountered a runtime 13 | * exception and threw a handler exception at the ReactorRunner class. 14 | */ 15 | void onReactorClosedUnexpectedly(); 16 | } 17 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/SubscriptionType.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.sdk.iot.device.transport.amqps; 2 | 3 | enum SubscriptionType 4 | { 5 | DESIRED_PROPERTIES_SUBSCRIPTION 6 | } 7 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/AmqpDecodeErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when a amqp:decode-error is encountered over an AMQP connection 12 | * 13 | For additional details, see this link 14 | */ 15 | public class AmqpDecodeErrorException extends ProtocolException 16 | { 17 | public static final String errorCode = "amqp:decode-error"; 18 | 19 | public AmqpDecodeErrorException() 20 | { 21 | super(); 22 | } 23 | 24 | public AmqpDecodeErrorException(String message) 25 | { 26 | super(message); 27 | } 28 | 29 | public AmqpDecodeErrorException(String message, Throwable cause) 30 | { 31 | super(message, cause); 32 | } 33 | 34 | public AmqpDecodeErrorException(Throwable cause) 35 | { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/AmqpIllegalStateException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when a amqp:illegal-state error is encountered over an AMQP connection 12 | * 13 | For additional details, see this link 14 | */ 15 | public class AmqpIllegalStateException extends ProtocolException 16 | { 17 | public static final String errorCode = "amqp:illegal-state"; 18 | 19 | public AmqpIllegalStateException() 20 | { 21 | super(); 22 | } 23 | 24 | public AmqpIllegalStateException(String message) 25 | { 26 | super(message); 27 | } 28 | 29 | public AmqpIllegalStateException(String message, Throwable cause) 30 | { 31 | super(message, cause); 32 | } 33 | 34 | public AmqpIllegalStateException(Throwable cause) 35 | { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/AmqpInvalidFieldException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when a amqp:invalid-field error is encountered over an AMQP connection 12 | * 13 | For additional details, see this link 14 | */ 15 | public class AmqpInvalidFieldException extends ProtocolException 16 | { 17 | public static final String errorCode = "amqp:invalid-field"; 18 | 19 | public AmqpInvalidFieldException() 20 | { 21 | super(); 22 | } 23 | 24 | public AmqpInvalidFieldException(String message) 25 | { 26 | super(message); 27 | } 28 | 29 | public AmqpInvalidFieldException(String message, Throwable cause) 30 | { 31 | super(message, cause); 32 | } 33 | 34 | public AmqpInvalidFieldException(Throwable cause) 35 | { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/AmqpLinkCreationConflict.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 2 | 3 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 4 | 5 | public class AmqpLinkCreationConflict extends ProtocolException 6 | { 7 | public static final String errorCode = "com.microsoft:link-creation-conflict"; 8 | 9 | public AmqpLinkCreationConflict() 10 | { 11 | super(); 12 | this.isRetryable = true; 13 | } 14 | 15 | public AmqpLinkCreationConflict(String message) 16 | { 17 | super(message); 18 | this.isRetryable = true; 19 | } 20 | 21 | public AmqpLinkCreationConflict(String message, Throwable cause) 22 | { 23 | super(message, cause); 24 | this.isRetryable = true; 25 | } 26 | 27 | public AmqpLinkCreationConflict(Throwable cause) 28 | { 29 | super(cause); 30 | this.isRetryable = true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/AmqpNotAllowedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when a amqp:not-allowed error is encountered over an AMQP connection 12 | * 13 | For additional details, see this link 14 | */ 15 | public class AmqpNotAllowedException extends ProtocolException 16 | { 17 | public static final String errorCode = "amqp:not-allowed"; 18 | 19 | public AmqpNotAllowedException() 20 | { 21 | super(); 22 | } 23 | 24 | public AmqpNotAllowedException(String message) 25 | { 26 | super(message); 27 | } 28 | 29 | public AmqpNotAllowedException(String message, Throwable cause) 30 | { 31 | super(message, cause); 32 | } 33 | 34 | public AmqpNotAllowedException(Throwable cause) 35 | { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/AmqpNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when a amqp:not-found error is encountered over an AMQP connection 12 | * 13 | For additional details, see this link 14 | */ 15 | public class AmqpNotFoundException extends ProtocolException 16 | { 17 | public static final String errorCode = "amqp:not-found"; 18 | 19 | public AmqpNotFoundException() 20 | { 21 | super(); 22 | } 23 | 24 | public AmqpNotFoundException(String message) 25 | { 26 | super(message); 27 | } 28 | 29 | public AmqpNotFoundException(String message, Throwable cause) 30 | { 31 | super(message, cause); 32 | } 33 | 34 | public AmqpNotFoundException(Throwable cause) 35 | { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/exceptions/ProtonIOException.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.sdk.iot.device.transport.amqps.exceptions; 2 | 3 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 4 | 5 | public class ProtonIOException extends ProtocolException 6 | { 7 | public static final String errorCode = "proton:io"; 8 | 9 | public ProtonIOException() 10 | { 11 | super(); 12 | this.isRetryable = true; 13 | } 14 | 15 | public ProtonIOException(String message) 16 | { 17 | super(message); 18 | this.isRetryable = true; 19 | } 20 | 21 | public ProtonIOException(String message, Throwable cause) 22 | { 23 | super(message, cause); 24 | this.isRetryable = true; 25 | } 26 | 27 | public ProtonIOException(Throwable cause) 28 | { 29 | super(cause); 30 | this.isRetryable = true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/amqps/package-info.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** AMQPS IoT Hub transport and communication classes. */ 5 | package com.microsoft.azure.sdk.iot.device.transport.amqps; -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/HttpsMethod.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.device.transport.https; 5 | 6 | /** The HTTPS request method (i.e. GET). */ 7 | public enum HttpsMethod 8 | { 9 | GET, POST, PUT, DELETE 10 | } 11 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/BadFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class BadFormatException extends IotHubServiceException 12 | { 13 | public BadFormatException() 14 | { 15 | super(); 16 | } 17 | 18 | public BadFormatException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public BadFormatException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public BadFormatException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | 33 | @Override 34 | public IotHubStatusCode getStatusCode() 35 | { 36 | return IotHubStatusCode.BAD_FORMAT; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/HubOrDeviceIdNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class HubOrDeviceIdNotFoundException extends IotHubServiceException 12 | { 13 | public HubOrDeviceIdNotFoundException() 14 | { 15 | super(); 16 | } 17 | 18 | public HubOrDeviceIdNotFoundException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public HubOrDeviceIdNotFoundException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public HubOrDeviceIdNotFoundException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | 33 | @Override 34 | public IotHubStatusCode getStatusCode() 35 | { 36 | return IotHubStatusCode.NOT_FOUND; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/PreconditionFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class PreconditionFailedException extends IotHubServiceException 12 | { 13 | public PreconditionFailedException() 14 | { 15 | super(); 16 | } 17 | 18 | public PreconditionFailedException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public PreconditionFailedException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public PreconditionFailedException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | 33 | @Override 34 | public IotHubStatusCode getStatusCode() 35 | { 36 | return IotHubStatusCode.PRECONDITION_FAILED; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/QuotaExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class QuotaExceededException extends IotHubServiceException 12 | { 13 | public QuotaExceededException() 14 | { 15 | super(); 16 | } 17 | 18 | public QuotaExceededException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public QuotaExceededException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public QuotaExceededException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | 33 | @Override 34 | public IotHubStatusCode getStatusCode() 35 | { 36 | return IotHubStatusCode.QUOTA_EXCEEDED; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/RequestEntityTooLargeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class RequestEntityTooLargeException extends IotHubServiceException 12 | { 13 | public RequestEntityTooLargeException() 14 | { 15 | super(); 16 | } 17 | 18 | public RequestEntityTooLargeException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public RequestEntityTooLargeException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public RequestEntityTooLargeException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | 33 | @Override 34 | public IotHubStatusCode getStatusCode() 35 | { 36 | return IotHubStatusCode.REQUEST_ENTITY_TOO_LARGE; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/ServerBusyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class ServerBusyException extends IotHubServiceException 12 | { 13 | public ServerBusyException() 14 | { 15 | super(); 16 | this.isRetryable = true; 17 | } 18 | 19 | public ServerBusyException(String message) 20 | { 21 | super(message); 22 | this.isRetryable = true; 23 | } 24 | 25 | public ServerBusyException(String message, Throwable cause) 26 | { 27 | super(message, cause); 28 | this.isRetryable = true; 29 | } 30 | 31 | public ServerBusyException(Throwable cause) 32 | { 33 | super(cause); 34 | this.isRetryable = true; 35 | } 36 | 37 | @Override 38 | public IotHubStatusCode getStatusCode() 39 | { 40 | return IotHubStatusCode.SERVER_BUSY; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/ServiceUnknownException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 9 | 10 | public class ServiceUnknownException extends IotHubServiceException 11 | { 12 | public ServiceUnknownException() 13 | { 14 | super(); 15 | } 16 | 17 | public ServiceUnknownException(String message) 18 | { 19 | super(message); 20 | } 21 | 22 | public ServiceUnknownException(String message, Throwable cause) 23 | { 24 | super(message, cause); 25 | } 26 | 27 | public ServiceUnknownException(Throwable cause) 28 | { 29 | super(cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/ThrottledException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class ThrottledException extends IotHubServiceException 12 | { 13 | public ThrottledException() 14 | { 15 | super(); 16 | this.isRetryable = true; 17 | } 18 | 19 | public ThrottledException(String message) 20 | { 21 | super(message); 22 | this.isRetryable = true; 23 | } 24 | 25 | public ThrottledException(String message, Throwable cause) 26 | { 27 | super(message, cause); 28 | this.isRetryable = true; 29 | } 30 | 31 | public ThrottledException(Throwable cause) 32 | { 33 | super(cause); 34 | this.isRetryable = true; 35 | } 36 | 37 | @Override 38 | public IotHubStatusCode getStatusCode() 39 | { 40 | return IotHubStatusCode.THROTTLED; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/exceptions/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.https.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.IotHubStatusCode; 9 | import com.microsoft.azure.sdk.iot.device.transport.IotHubServiceException; 10 | 11 | public class UnauthorizedException extends IotHubServiceException 12 | { 13 | public UnauthorizedException() 14 | { 15 | super(); 16 | } 17 | 18 | public UnauthorizedException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public UnauthorizedException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public UnauthorizedException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | 33 | @Override 34 | public IotHubStatusCode getStatusCode() 35 | { 36 | return IotHubStatusCode.UNAUTHORIZED; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/https/package-info.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** HTTPS IoT Hub transport and communication classes. */ 5 | package com.microsoft.azure.sdk.iot.device.transport.https; -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/MqttMessageListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.mqtt; 7 | 8 | interface MqttMessageListener 9 | { 10 | void onMessageArrived(int messageId); 11 | } 12 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/exceptions/MqttUnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.mqtt.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when an MQTT Connection Return code of 0x05 is encountered when opening an MQTT connection 12 | * 13 | * 14 | * MQTT Connect Return Code Documentation 15 | */ 16 | public class MqttUnauthorizedException extends ProtocolException 17 | { 18 | public MqttUnauthorizedException() 19 | { 20 | super(); 21 | } 22 | 23 | public MqttUnauthorizedException(String message) 24 | { 25 | super(message); 26 | } 27 | 28 | public MqttUnauthorizedException(String message, Throwable cause) 29 | { 30 | super(message, cause); 31 | } 32 | 33 | public MqttUnauthorizedException(Throwable cause) 34 | { 35 | super(cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/mqtt/exceptions/MqttUnexpectedErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.transport.mqtt.exceptions; 7 | 8 | import com.microsoft.azure.sdk.iot.device.transport.ProtocolException; 9 | 10 | /** 11 | * This exception is thrown when an unrecognized MQTT Connection code is returned when opening an MQTT connection 12 | * 13 | * 14 | * MQTT Connect Return Code Documentation 15 | */ 16 | public class MqttUnexpectedErrorException extends ProtocolException 17 | { 18 | public MqttUnexpectedErrorException() 19 | { 20 | super(); 21 | } 22 | 23 | public MqttUnexpectedErrorException(String message) 24 | { 25 | super(message); 26 | } 27 | 28 | public MqttUnexpectedErrorException(String message, Throwable cause) 29 | { 30 | super(message, cause); 31 | } 32 | 33 | public MqttUnexpectedErrorException(Throwable cause) 34 | { 35 | super(cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/package-info.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** 5 | * A transport for sending and receiving IoT Hub messages, along with supporting 6 | * functionality. 7 | */ 8 | package com.microsoft.azure.sdk.iot.device.transport; -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/DesiredPropertiesCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | package com.microsoft.azure.sdk.iot.device.twin; 5 | 6 | /** 7 | * The callback to be executed each time the client receives a desired property update from the service. 8 | */ 9 | public interface DesiredPropertiesCallback 10 | { 11 | /** 12 | * The callback to be executed each time the client receives a desired property update from the service. 13 | * 14 | * @param twin A {@link Twin} instance containing the updated desired properties. 15 | * @param context The context that was provided for this callback in 16 | * {@link com.microsoft.azure.sdk.iot.device.InternalClient#subscribeToDesiredPropertiesAsync(DesiredPropertiesCallback, Object, SubscriptionAcknowledgedCallback, Object)} 17 | */ 18 | void onDesiredPropertiesUpdated(Twin twin, Object context); 19 | } 20 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/DeviceOperations.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.device.twin; 5 | 6 | public enum DeviceOperations 7 | { 8 | DEVICE_OPERATION_TWIN_GET_REQUEST, 9 | DEVICE_OPERATION_TWIN_GET_RESPONSE, 10 | DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_REQUEST, 11 | DEVICE_OPERATION_TWIN_UPDATE_REPORTED_PROPERTIES_RESPONSE, 12 | DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_REQUEST, 13 | DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE, 14 | DEVICE_OPERATION_TWIN_UNSUBSCRIBE_DESIRED_PROPERTIES_REQUEST, 15 | DEVICE_OPERATION_TWIN_UNSUBSCRIBE_DESIRED_PROPERTIES_RESPONSE, 16 | DEVICE_OPERATION_METHOD_SUBSCRIBE_REQUEST, 17 | DEVICE_OPERATION_METHOD_SUBSCRIBE_RESPONSE, 18 | DEVICE_OPERATION_METHOD_RECEIVE_REQUEST, 19 | DEVICE_OPERATION_METHOD_SEND_RESPONSE, 20 | DEVICE_OPERATION_UNKNOWN 21 | } 22 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/GetTwinCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | package com.microsoft.azure.sdk.iot.device.twin; 5 | 6 | import com.microsoft.azure.sdk.iot.device.exceptions.IotHubClientException; 7 | 8 | /** 9 | * The callback to be executed when the service responds to a getTwin request with the current twin. 10 | */ 11 | public interface GetTwinCallback 12 | { 13 | /** 14 | * The callback to be executed when the service responds to a getTwin request with the current twin. 15 | * @param twin The current twin. 16 | * @param context The context that was provided for this callback in 17 | * {@link com.microsoft.azure.sdk.iot.device.InternalClient#getTwinAsync(GetTwinCallback, Object)}. 18 | */ 19 | void onTwinReceived(Twin twin, IotHubClientException clientException, Object context); 20 | } 21 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/MethodCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.device.twin; 5 | 6 | /** 7 | * The callback to be executed each time a direct method is invoked on this client. 8 | */ 9 | public interface MethodCallback 10 | { 11 | /** 12 | * The 13 | * @param methodName The name of the method being invoked. 14 | * @param methodPayload The payload of the method being invoked. May be null 15 | * @param context The context set when subscribing to direct methods. Will be null if no context was set when subscribing. 16 | * @return The direct method response to deliver to the process that invoked this method. May not be null. 17 | */ 18 | DirectMethodResponse onMethodInvoked(String methodName, DirectMethodPayload methodPayload, Object context); 19 | } 20 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/ReportedPropertiesUpdateResponse.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.sdk.iot.device.twin; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | /** 7 | * The response fields for a reported properties update request. 8 | */ 9 | @AllArgsConstructor 10 | public class ReportedPropertiesUpdateResponse 11 | { 12 | /** 13 | * The new version of the reported properties after a successful reported properties update. If the client updating 14 | * its reported properties is connected to Edgehub instead of IoT Hub, then this version won't change since Edgehub 15 | * does not apply this reported properties update immediately. 16 | */ 17 | @Getter 18 | private final Integer version; 19 | } 20 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/SubscriptionAcknowledgedCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | package com.microsoft.azure.sdk.iot.device.twin; 5 | 6 | import com.microsoft.azure.sdk.iot.device.exceptions.IotHubClientException; 7 | 8 | /** 9 | * Callback to be executed when the request to subscribe to desired properties has been acknowledged by the service. 10 | */ 11 | public interface SubscriptionAcknowledgedCallback 12 | { 13 | /** 14 | * The callback that is executed when the request to subscribe to desired properties or direct methodshas been 15 | * acknowledged by the service. 16 | * @param context The context that was provided for this callback in 17 | * {@link com.microsoft.azure.sdk.iot.device.InternalClient#subscribeToDesiredPropertiesAsync(DesiredPropertiesCallback, Object, SubscriptionAcknowledgedCallback, Object)} 18 | * or in {@link com.microsoft.azure.sdk.iot.device.InternalClient#subscribeToMethodsAsync(MethodCallback, Object, SubscriptionAcknowledgedCallback, Object)}. 19 | */ 20 | void onSubscriptionAcknowledged(IotHubClientException exception, Object context); 21 | } 22 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/twin/Tools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.twin; 7 | 8 | /** 9 | * Collection of static helper functions 10 | */ 11 | class Tools 12 | { 13 | /** 14 | * Helper function to check if the input string is null or empty 15 | * 16 | * @param value The string to check 17 | * @return The value true if the input string is empty or null 18 | */ 19 | static Boolean isNullOrEmpty(String value) 20 | { 21 | boolean retVal; 22 | 23 | if (value == null) 24 | retVal = true; 25 | else 26 | retVal = value.length() == 0; 27 | 28 | return retVal; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/main/resources/iothub-device-client.properties: -------------------------------------------------------------------------------- 1 | artifactId=${project.artifactId} 2 | groupId=${project.groupId} 3 | version=${project.version} 4 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/auth/IotHubX509SoftwareIotHubAuthenticationProviderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.auth; 7 | 8 | /** 9 | * Unit tests for IotHubX509SoftwareAuthenticationProvider.java 10 | * Methods: 100% 11 | * Lines: 100% 12 | */ 13 | public class IotHubX509SoftwareIotHubAuthenticationProviderTest 14 | { 15 | } 16 | 17 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/hsm/parser/ErrorResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.hsm.parser; 7 | 8 | import mockit.Deencapsulation; 9 | import org.junit.Test; 10 | 11 | import static junit.framework.TestCase.assertEquals; 12 | 13 | public class ErrorResponseTest 14 | { 15 | // Tests_SRS_HTTPHSMERRORRESPONSE_34_001: [This function shall return the saved message.] 16 | @Test 17 | public void getMessageWorks() 18 | { 19 | //arrange 20 | String expectedMessage = "some error message"; 21 | ErrorResponse errorResponse = new ErrorResponse(); 22 | Deencapsulation.setField(errorResponse, "message", expectedMessage); 23 | 24 | //act 25 | String actualMessage = errorResponse.getMessage(); 26 | 27 | //assert 28 | assertEquals(expectedMessage, actualMessage); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/hsm/parser/SignResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.device.hsm.parser; 7 | 8 | import mockit.Deencapsulation; 9 | import org.junit.Test; 10 | 11 | import static junit.framework.TestCase.assertEquals; 12 | 13 | public class SignResponseTest 14 | { 15 | // Tests_SRS_HTTPHSMSIGNRESPONSE_34_001: [This function shall return the saved digest.] 16 | @Test 17 | public void getDigestWorks() 18 | { 19 | //arrange 20 | String expectedDigest = "some digest"; 21 | SignResponse response = new SignResponse(); 22 | Deencapsulation.setField(response, "digest", expectedDigest); 23 | 24 | //act 25 | String actualDigest = response.getDigest(); 26 | 27 | //assert 28 | assertEquals(expectedDigest, actualDigest); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/RetryDecisionTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.device.transport; 5 | 6 | import org.junit.Test; 7 | import static org.junit.Assert.*; 8 | 9 | public class RetryDecisionTest 10 | { 11 | // Tests_SRS_RETRYDECISION_28_001: [The constructor shall save the duration and getRetryDecision] 12 | // Tests_SRS_RETRYDECISION_28_002: [The function shall return the value of getRetryDecision] 13 | // Tests_SRS_RETRYDECISION_28_003: [The function shall return the value of duration] 14 | @Test 15 | public void constructorSavesParameters() 16 | { 17 | //act 18 | final RetryDecision retryDecisionTest = new RetryDecision(true, 10); 19 | 20 | // assert 21 | assertTrue(retryDecisionTest.shouldRetry()); 22 | assertEquals(10, retryDecisionTest.getDuration()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /iothub/device/iot-device-samples/android-sample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 |For now, the provisioning service supports {@link TpmAttestation} or {@link X509Attestation}. 10 | * 11 | * @see Device Enrollment 12 | */ 13 | public abstract class Attestation 14 | { 15 | // Abstract class fully implemented by the child. 16 | } 17 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/configs/AttestationMechanismType.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.provisioning.service.configs; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * Type of Device Provisioning Service attestation mechanism. 10 | * 11 | * @see Device Enrollment 12 | */ 13 | public enum AttestationMechanismType 14 | { 15 | @SerializedName("none") // There is no valid scenario for `NONE` Attestation Mechanism Type. 16 | NONE, 17 | 18 | @SerializedName("tpm") 19 | TPM, 20 | 21 | @SerializedName("x509") 22 | X509, 23 | 24 | @SerializedName("symmetricKey") 25 | SYMMETRIC_KEY, 26 | } 27 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/configs/BulkOperationMode.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.provisioning.service.configs; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * The Device Provisioning Service bulk operation modes. 10 | * 11 | * @see Device Enrollment 12 | */ 13 | @SuppressWarnings("unused") // used by reflection during json serialization/deserialization 14 | public enum BulkOperationMode 15 | { 16 | @SerializedName("create") 17 | CREATE, 18 | 19 | @SerializedName("update") 20 | UPDATE, 21 | 22 | @SerializedName("updateIfMatchETag") 23 | UPDATE_IF_MATCH_ETAG, 24 | 25 | @SerializedName("delete") 26 | DELETE 27 | } 28 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/configs/CustomAllocationDefinition.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.provisioning.service.configs; 5 | 6 | import com.google.gson.annotations.Expose; 7 | import com.google.gson.annotations.SerializedName; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | 11 | import java.io.Serializable; 12 | 13 | public class CustomAllocationDefinition implements Serializable 14 | { 15 | // the webhook url for allocation requests 16 | private static final String WEBHOOK_URL_TAG = "webhookUrl"; 17 | @Expose 18 | @SerializedName(WEBHOOK_URL_TAG) 19 | @Getter 20 | @Setter 21 | private String webhookUrl; 22 | 23 | // the API version of the provisioning service types (such as IndividualEnrollment) sent in the custom allocation request. 24 | private static final String API_VERSION_TAG = "apiVersion"; 25 | @Expose 26 | @SerializedName(API_VERSION_TAG) 27 | @Getter 28 | @Setter 29 | private String apiVersion; 30 | } 31 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/configs/EnrollmentStatus.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.provisioning.service.configs; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * The Device Provisioning Service enrollment status. 12 | * 13 | * @see Device Enrollment 14 | */ 15 | public enum EnrollmentStatus implements Serializable 16 | { 17 | @SerializedName("unassigned") 18 | UNASSIGNED, 19 | 20 | @SerializedName("assigning") 21 | ASSIGNING, 22 | 23 | @SerializedName("assigned") 24 | ASSIGNED, 25 | 26 | @SerializedName("failed") 27 | FAILED, 28 | 29 | @SerializedName("disabled") 30 | DISABLED, 31 | } 32 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/configs/ProvisioningStatus.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | package com.microsoft.azure.sdk.iot.provisioning.service.configs; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * The Device Provisioning Service provisioning status. 12 | * 13 | * @see Device Enrollment 14 | */ 15 | public enum ProvisioningStatus implements Serializable 16 | { 17 | @SerializedName("enabled") 18 | ENABLED, 19 | 20 | @SerializedName("disabled") 21 | DISABLED, 22 | } 23 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientBadFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create bad message format exception 10 | * 11 | *
The body of the Http request is not valid; for example, it cannot be parsed, or the object cannot be validated. 12 | *
HTTP status code 400. 13 | */ 14 | public class ProvisioningServiceClientBadFormatException extends ProvisioningServiceClientBadUsageException 15 | { 16 | public ProvisioningServiceClientBadFormatException() 17 | { 18 | super(); 19 | } 20 | 21 | public ProvisioningServiceClientBadFormatException(String message) 22 | { 23 | super("Bad message format!" + (((message == null) || message.isEmpty()) ? "" : " " + message)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientInternalServerErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create internal server error exception 10 | * 11 | *
An internal error occurred. 12 | *
HTTP status code 500. 13 | */ 14 | public class ProvisioningServiceClientInternalServerErrorException extends ProvisioningServiceClientTransientException 15 | { 16 | public ProvisioningServiceClientInternalServerErrorException() 17 | { 18 | super(); 19 | } 20 | 21 | public ProvisioningServiceClientInternalServerErrorException(String message) 22 | { 23 | super("Internal server error!" + (((message == null) || message.isEmpty()) ? "" : " " + message)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create Device Provisioning Service not found exception 10 | * 11 | *
The Device Provisioning Service instance, or a resource (e.g. an enrollment) does not exist. 12 | *
HTTP status code 404. 13 | */ 14 | public class ProvisioningServiceClientNotFoundException extends ProvisioningServiceClientBadUsageException 15 | { 16 | public ProvisioningServiceClientNotFoundException() 17 | { 18 | super(); 19 | } 20 | 21 | public ProvisioningServiceClientNotFoundException(String message) 22 | { 23 | super("Device Provisioning Service not found!" + (((message == null) || message.isEmpty()) ? "" : " " + message)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientPreconditionFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create precondition failed exception 10 | * 11 | *
The ETag in the request does not match the ETag of the existing resource, as per RFC7232. 12 | *
HTTP status code 412. 13 | */ 14 | public class ProvisioningServiceClientPreconditionFailedException extends ProvisioningServiceClientBadUsageException 15 | { 16 | public ProvisioningServiceClientPreconditionFailedException() 17 | { 18 | super(); 19 | } 20 | 21 | public ProvisioningServiceClientPreconditionFailedException(String message) 22 | { 23 | super("Precondition failed!" + (((message == null) || message.isEmpty()) ? "" : " " + message)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientServiceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * This is the subset of the Device Provisioning Service exceptions for the exceptions reported by the Service. 10 | */ 11 | public class ProvisioningServiceClientServiceException extends ProvisioningServiceClientException 12 | { 13 | public ProvisioningServiceClientServiceException() 14 | { 15 | super(); 16 | } 17 | 18 | public ProvisioningServiceClientServiceException(String message) 19 | { 20 | super(((message == null) || message.isEmpty()) ? "Device Provisioning Service error!" : message); 21 | } 22 | 23 | public ProvisioningServiceClientServiceException(String message, Throwable cause) 24 | { 25 | super((((message == null) || message.isEmpty()) ? "Device Provisioning Service error!" : message), cause); 26 | } 27 | 28 | public ProvisioningServiceClientServiceException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientTooManyRequestsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create too many requests exception 10 | * 11 | *
Operations are being throttled by the service. For specific service limits, see IoT Hub Device Provisioning 12 | * Service limits. 13 | *
HTTP status code 429. 14 | */ 15 | public class ProvisioningServiceClientTooManyRequestsException extends ProvisioningServiceClientBadUsageException 16 | { 17 | public ProvisioningServiceClientTooManyRequestsException() 18 | { 19 | super(); 20 | } 21 | 22 | public ProvisioningServiceClientTooManyRequestsException(String message) 23 | { 24 | super("Too many requests (throttled)!" + (((message == null) || message.isEmpty()) ? "" : " " + message)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientTransportException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create transport exception 10 | */ 11 | public class ProvisioningServiceClientTransportException extends ProvisioningServiceClientException 12 | { 13 | public ProvisioningServiceClientTransportException() 14 | { 15 | super(); 16 | } 17 | 18 | public ProvisioningServiceClientTransportException(String message) 19 | { 20 | super(message); 21 | } 22 | 23 | public ProvisioningServiceClientTransportException(String message, Throwable cause) 24 | { 25 | super(message, cause); 26 | } 27 | 28 | public ProvisioningServiceClientTransportException(Throwable cause) 29 | { 30 | super(cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/exceptions/ProvisioningServiceClientUnathorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Microsoft. All rights reserved. 3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | */ 5 | 6 | package com.microsoft.azure.sdk.iot.provisioning.service.exceptions; 7 | 8 | /** 9 | * Create unauthorized exception 10 | * 11 | *
The authorization token cannot be validated; for example, it is expired or does not apply to the 12 | * request’s URI. This error code is also returned to devices as part of the TPM attestation flow. 13 | *
HTTP status code 401
14 | */
15 | public class ProvisioningServiceClientUnathorizedException extends ProvisioningServiceClientBadUsageException
16 | {
17 | public ProvisioningServiceClientUnathorizedException()
18 | {
19 | super();
20 | }
21 |
22 | public ProvisioningServiceClientUnathorizedException(String message)
23 | {
24 | super("Unauthorized!" + (((message == null) || message.isEmpty()) ? "" : " " + message));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/transport/https/HttpMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved.
3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 | */
5 |
6 | package com.microsoft.azure.sdk.iot.provisioning.service.transport.https;
7 |
8 | /**
9 | * An HTTPS message. An HTTPS message is distinguished from a plain IoT Hub
10 | * message by its property names, which are prefixed with 'iothub-app-';
11 | * and by the explicit specification of a content-type.
12 | */
13 | public interface HttpMessage
14 | {
15 | /**
16 | * Gets the message body.
17 | * @return The message body.
18 | */
19 | byte[] getBody();
20 |
21 | /**
22 | * Gets the content type string.
23 | * @return The message content-type.
24 | */
25 | String getContentType();
26 | }
27 |
--------------------------------------------------------------------------------
/provisioning/provisioning-service-client/src/main/java/com/microsoft/azure/sdk/iot/provisioning/service/transport/https/HttpMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Microsoft. All rights reserved.
3 | * Licensed under the MIT license. See LICENSE file in the project root for full license information.
4 | */
5 |
6 | package com.microsoft.azure.sdk.iot.provisioning.service.transport.https;
7 |
8 | /** The HTTPS request method (i.e. GET). */
9 | public enum HttpMethod
10 | {
11 | GET, POST, PUT, DELETE, PATCH
12 | }
13 |
--------------------------------------------------------------------------------
/provisioning/provisioning-service-client/src/main/resources/provisioning-service-client.properties:
--------------------------------------------------------------------------------
1 | artifactId=${project.artifactId}
2 | groupId=${project.groupId}
3 | version=${project.version}
4 |
--------------------------------------------------------------------------------
/provisioning/provisioning-tools/tpm-simulator/Microsoft.Devices.Tpm.TcpEmulator.0.0.1.nuspec:
--------------------------------------------------------------------------------
1 |
2 |