Пример #1
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);
            }
        }
Пример #2
0
 public MqttProtocolHead(
     ISettingsProvider settingsProvider,
     X509Certificate tlsCertificate,
     IMqttConnectionProvider mqttConnectionProvider,
     IAuthenticator authenticator,
     IClientCredentialsFactory clientCredentialsFactory,
     ISessionStatePersistenceProvider sessionProvider,
     IWebSocketListenerRegistry webSocketListenerRegistry,
     IByteBufferAllocator byteBufferAllocator,
     IProductInfoStore productInfoStore,
     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.sslProtocols = sslProtocols;
 }
Пример #3
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,
     Option <IWebProxy> proxy,
     IProductInfoStore productInfoStore)
 {
     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);
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.closeOnIdleTimeout         = closeOnIdleTimeout;
     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));
 }
Пример #4
0
 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));
 }
Пример #5
0
 public EventsLinkHandler(
     IIdentity identity,
     IReceivingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     IProductInfoStore productInfoStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
 {
 }
 public ModuleMessageLinkHandler(
     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)
 {
 }
Пример #7
0
 public DeviceIdentityProvider(
     IAuthenticator authenticator,
     IClientCredentialsFactory clientCredentialsFactory,
     IProductInfoStore productInfoStore,
     bool clientCertAuthAllowed)
 {
     this.authenticator            = Preconditions.CheckNotNull(authenticator, nameof(authenticator));
     this.clientCredentialsFactory = Preconditions.CheckNotNull(clientCredentialsFactory, nameof(clientCredentialsFactory));
     this.productInfoStore         = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
     this.clientCertAuthAllowed    = clientCertAuthAllowed;
     this.remoteCertificate        = Option.None <X509Certificate2>();
     this.remoteCertificateChain   = new List <X509Certificate2>();
 }
Пример #8
0
 protected SendingLinkHandler(
     IIdentity identity,
     ISendingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     IProductInfoStore productInfoStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
 {
     Preconditions.CheckArgument(!link.IsReceiver, $"Link {requestUri} cannot send");
     this.SendingAmqpLink = link;
 }
Пример #9
0
 public TestSendingLinkHandler(
     IIdentity identity,
     ISendingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     QualityOfService qualityOfService,
     IProductInfoStore productInfoStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
 {
     this.QualityOfService = qualityOfService;
 }
Пример #10
0
 protected ReceivingLinkHandler(
     IIdentity identity,
     IReceivingAmqpLink link,
     Uri requestUri,
     IDictionary <string, string> boundVariables,
     IConnectionHandler connectionHandler,
     IMessageConverter <AmqpMessage> messageConverter,
     IProductInfoStore productInfoStore)
     : base(identity, link, requestUri, boundVariables, connectionHandler, messageConverter, productInfoStore)
 {
     Preconditions.CheckArgument(link.IsReceiver, $"Link {requestUri} cannot receive");
     this.ReceivingLink        = link;
     this.sendMessageProcessor = new ActionBlock <AmqpMessage>(this.ProcessMessageAsync);
 }
Пример #11
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)
        {
            productInfoStore = productInfoStore ?? Mock.Of <IProductInfoStore>();
            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, 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);
        }