Exemple #1
0
 public CloudConnectionProvider(
     IMessageConverterProvider messageConverterProvider,
     int connectionPoolSize,
     IClientProvider clientProvider,
     Option <UpstreamProtocol> upstreamProtocol,
     ITokenProvider edgeHubTokenProvider,
     IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
     ICredentialsCache credentialsCache,
     IIdentity edgeHubIdentity,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     bool useServerHeartbeat,
     Option <IWebProxy> proxy,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore)
 {
     Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.transportSettings        = GetTransportSettings(upstreamProtocol, connectionPoolSize, proxy, useServerHeartbeat);
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.closeOnIdleTimeout         = closeOnIdleTimeout;
     this.useServerHeartbeat         = useServerHeartbeat;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
     this.credentialsCache           = Preconditions.CheckNotNull(credentialsCache, nameof(credentialsCache));
     this.edgeHubIdentity            = Preconditions.CheckNotNull(edgeHubIdentity, nameof(edgeHubIdentity));
     this.operationTimeout           = operationTimeout;
     this.productInfoStore           = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
     this.modelIdStore               = Preconditions.CheckNotNull(modelIdStore, nameof(modelIdStore));
 }
Exemple #2
0
        protected LinkHandler(
            IIdentity identity,
            IAmqpLink link,
            Uri requestUri,
            IDictionary <string, string> boundVariables,
            IConnectionHandler connectionHandler,
            IMessageConverter <AmqpMessage> messageConverter,
            IProductInfoStore productInfoStore,
            IModelIdStore modelIdStore)
        {
            this.Identity         = Preconditions.CheckNotNull(identity, nameof(identity));
            this.MessageConverter = Preconditions.CheckNotNull(messageConverter, nameof(messageConverter));
            this.BoundVariables   = Preconditions.CheckNotNull(boundVariables, nameof(boundVariables));
            this.Link             = Preconditions.CheckNotNull(link, nameof(link));
            this.LinkUri          = Preconditions.CheckNotNull(requestUri, nameof(requestUri));
            this.Link.SafeAddClosed(this.OnLinkClosed);
            this.connectionHandler = Preconditions.CheckNotNull(connectionHandler, nameof(connectionHandler));
            this.productInfoStore  = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
            this.modelIdStore      = Preconditions.CheckNotNull(modelIdStore, nameof(modelIdStore));

            string clientVersion = null;

            if (this.Link.Settings?.Properties?.TryGetValue(IotHubAmqpProperty.ClientVersion, out clientVersion) ?? false)
            {
                this.ClientVersion = Option.Maybe(clientVersion);
            }

            string modelId = null;

            if (this.Link.Settings?.Properties?.TryGetValue(IotHubAmqpProperty.ModelId, out modelId) ?? false)
            {
                this.ModelId = Option.Maybe(modelId);
            }
        }
 public MqttWebSocketListener(
     Settings settings,
     MessagingBridgeFactoryFunc messagingBridgeFactoryFunc,
     IAuthenticator authenticator,
     IClientCredentialsFactory clientCredentialsFactory,
     Func <ISessionStatePersistenceProvider> sessionProviderFactory,
     IEventLoopGroup workerGroup,
     IByteBufferAllocator byteBufferAllocator,
     bool autoRead,
     int mqttDecoderMaxMessageSize,
     bool clientCertAuthAllowed,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore)
 {
     this.settings = Preconditions.CheckNotNull(settings, nameof(settings));
     this.messagingBridgeFactoryFunc = Preconditions.CheckNotNull(messagingBridgeFactoryFunc, nameof(messagingBridgeFactoryFunc));
     this.authenticator            = Preconditions.CheckNotNull(authenticator, nameof(authenticator));
     this.clientCredentialsFactory = Preconditions.CheckNotNull(clientCredentialsFactory, nameof(clientCredentialsFactory));
     this.sessionProviderFactory   = Preconditions.CheckNotNull(sessionProviderFactory, nameof(sessionProviderFactory));
     this.workerGroup               = Preconditions.CheckNotNull(workerGroup, nameof(workerGroup));
     this.byteBufferAllocator       = Preconditions.CheckNotNull(byteBufferAllocator, nameof(byteBufferAllocator));
     this.autoRead                  = autoRead;
     this.mqttDecoderMaxMessageSize = mqttDecoderMaxMessageSize;
     this.clientCertAuthAllowed     = clientCertAuthAllowed;
     this.productInfoStore          = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
     this.modelIdStore              = Preconditions.CheckNotNull(modelIdStore, nameof(modelIdStore));
 }
 public MqttProtocolHead(
     ISettingsProvider settingsProvider,
     X509Certificate tlsCertificate,
     IMqttConnectionProvider mqttConnectionProvider,
     IAuthenticator authenticator,
     IClientCredentialsFactory clientCredentialsFactory,
     ISessionStatePersistenceProvider sessionProvider,
     IWebSocketListenerRegistry webSocketListenerRegistry,
     IByteBufferAllocator byteBufferAllocator,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore,
     bool clientCertAuthAllowed,
     SslProtocols sslProtocols)
 {
     this.settingsProvider          = Preconditions.CheckNotNull(settingsProvider, nameof(settingsProvider));
     this.tlsCertificate            = Preconditions.CheckNotNull(tlsCertificate, nameof(tlsCertificate));
     this.mqttConnectionProvider    = Preconditions.CheckNotNull(mqttConnectionProvider, nameof(mqttConnectionProvider));
     this.authenticator             = Preconditions.CheckNotNull(authenticator, nameof(authenticator));
     this.clientCredentialsFactory  = Preconditions.CheckNotNull(clientCredentialsFactory, nameof(clientCredentialsFactory));
     this.sessionProvider           = Preconditions.CheckNotNull(sessionProvider, nameof(sessionProvider));
     this.webSocketListenerRegistry = Preconditions.CheckNotNull(webSocketListenerRegistry, nameof(webSocketListenerRegistry));
     this.byteBufferAllocator       = Preconditions.CheckNotNull(byteBufferAllocator);
     this.clientCertAuthAllowed     = clientCertAuthAllowed;
     this.productInfoStore          = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
     this.modelIdStore = Preconditions.CheckNotNull(modelIdStore, nameof(modelIdStore));
     this.sslProtocols = sslProtocols;
 }
 public EventsLinkHandler(
     IIdentity identity,
     IReceivingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore, modelIdStore)
 {
 }
 public TestSendingLinkHandler(
     IIdentity identity,
     ISendingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     QualityOfService qualityOfService,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore, modelIdStore)
 {
     this.QualityOfService = qualityOfService;
 }
 protected SendingLinkHandler(
     IIdentity identity,
     ISendingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore, modelIdStore)
 {
     Preconditions.CheckArgument(!link.IsReceiver, $"Link {requestUri} cannot send");
     this.SendingAmqpLink = link;
 }
 protected ReceivingLinkHandler(
     IIdentity identity,
     IReceivingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore, modelIdStore)
 {
     Preconditions.CheckArgument(link.IsReceiver, $"Link {requestUri} cannot receive");
     this.ReceivingLink        = link;
     this.sendMessageProcessor = new ActionBlock <AmqpMessage>(this.ProcessMessageAsync);
 }
 public DeviceIdentityProvider(
     IAuthenticator authenticator,
     IClientCredentialsFactory clientCredentialsFactory,
     IProductInfoStore productInfoStore,
     IModelIdStore modelIdStore,
     bool clientCertAuthAllowed)
 {
     this.authenticator            = Preconditions.CheckNotNull(authenticator, nameof(authenticator));
     this.clientCredentialsFactory = Preconditions.CheckNotNull(clientCredentialsFactory, nameof(clientCredentialsFactory));
     this.productInfoStore         = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
     this.modelIdStore             = Preconditions.CheckNotNull(modelIdStore, nameof(modelIdStore));
     this.clientCertAuthAllowed    = clientCertAuthAllowed;
     this.remoteCertificate        = Option.None <X509Certificate2>();
     this.remoteCertificateChain   = new List <X509Certificate2>();
 }
Exemple #10
0
        static async Task <IClientCredentials> GetClientCredentials(string iotHubHostName, string deviceId, string userName, string token, bool isCertAuthAllowed = false, string productInfo = "", X509Certificate2 certificate = null, IList <X509Certificate2> chain = null, IProductInfoStore productInfoStore = null, IModelIdStore modelIdStore = null)
        {
            productInfoStore = productInfoStore ?? Mock.Of <IProductInfoStore>();
            modelIdStore     = modelIdStore ?? Mock.Of <IModelIdStore>();
            var authenticator = Mock.Of <IAuthenticator>(a => a.AuthenticateAsync(It.IsAny <IClientCredentials>()) == Task.FromResult(true));
            var factory       = new ClientCredentialsFactory(new IdentityProvider(iotHubHostName), productInfo);
            var credentialIdentityProvider = new DeviceIdentityProvider(authenticator, factory, productInfoStore, modelIdStore, isCertAuthAllowed);

            if (certificate != null && chain != null)
            {
                credentialIdentityProvider.RegisterConnectionCertificate(certificate, chain);
            }

            IDeviceIdentity deviceIdentity = await credentialIdentityProvider.GetAsync(deviceId, userName, token, null);

            Assert.NotNull(deviceIdentity);
            IClientCredentials clientCredentials = (deviceIdentity as ProtocolGatewayIdentity)?.ClientCredentials;

            return(clientCredentials);
        }