Beispiel #1
0
 public OpcVaultLoginCredentials(
     OpcVaultApiOptions opcVaultOptions,
     OpcVaultAzureADOptions azureADOptions)
 {
     this.opcVaultOptions = opcVaultOptions;
     this.azureADOptions  = azureADOptions;
 }
 public CertificateRequestController(
     OpcVaultApiOptions opcVaultOptions,
     AzureADOptions azureADOptions,
     ITokenCacheService tokenCacheService) :
     base(opcVaultOptions, azureADOptions, tokenCacheService)
 {
 }
Beispiel #3
0
        async void OnLoginButtonClicked(object sender, EventArgs args)
        {
            //var response = await DependencyService.Get<IAuthService>().Authenticate(Settings.TenantId, Settings.graphResourceUri, Settings.clientId, Settings.returnUri, Settings.ClientSecret);

            var opcVaultOptions = new OpcVaultApiOptions();
            var azureADOptions  = new OpcVaultAzureADOptions();

            using (var cts = new CancellationTokenSource())
            {
                var Settings = await ConfigurationManager.Instance.GetAsync(cts.Token);

                opcVaultOptions.BaseAddress = Settings.AppServiceURL;
                opcVaultOptions.ResourceId  = Settings.graphResourceUri;
                azureADOptions.ClientId     = Settings.clientId;
                azureADOptions.ClientSecret = Settings.ClientSecret;
                azureADOptions.Authority    = Settings.commonAuthority;
                azureADOptions.TenantId     = Settings.TenantId;
            }



            var       serviceClient         = new OpcVaultLoginCredentials(opcVaultOptions, azureADOptions);
            IOpcVault opcVaultServiceClient = new Microsoft.Azure.IIoT.OpcUa.Api.Vault.OpcVault(new Uri(opcVaultOptions.BaseAddress), serviceClient);

            //var opcVaultHandler = new OpcVaultClientHandler(opcVaultServiceClient);
            //Application.Current.MainPage = new XamarinClient.XAML.BasePage(opcVaultServiceClient);
            Application.Current.MainPage = new BasePage(opcVaultServiceClient);
        }
Beispiel #4
0
 public Startup(IConfiguration configuration)
 {
     Configuration   = configuration;
     OpcVaultOptions = new OpcVaultApiOptions();
     Configuration.Bind("OpcVault", OpcVaultOptions);
     AzureADOptions = new AzureADOptions();
     Configuration.Bind("AzureAD", AzureADOptions);
 }
 public DownloadController(
     OpcVaultApiOptions opcVaultOptions,
     AzureADOptions azureADOptions,
     ITokenCacheService tokenCacheService)
 {
     _opcVaultOptions   = opcVaultOptions;
     _azureADOptions    = azureADOptions;
     _tokenCacheService = tokenCacheService;
 }
 public CertificateGroupController(
     OpcVaultApiOptions opcVaultOptions,
     AzureADOptions azureADOptions,
     ITokenCacheService tokenCacheService)
 {
     this._opcVaultOptions   = opcVaultOptions;
     this._azureADOptions    = azureADOptions;
     this._tokenCacheService = tokenCacheService;
 }
 public OpcVaultLoginCredentials(
     OpcVaultApiOptions opcVaultOptions,
     AzureADOptions azureADOptions,
     ITokenCacheService tokenCacheService,
     ClaimsPrincipal claimsPrincipal)
 {
     this.opcVaultOptions   = opcVaultOptions;
     this.azureADOptions    = azureADOptions;
     this.tokenCacheService = tokenCacheService;
     this.claimsPrincipal   = claimsPrincipal;
 }
        public void Run(
            OpcVaultApiOptions opcVaultOptions,
            OpcVaultAzureADOptions azureADOptions)
        {
            try
            {
                exitCode = ExitCode.ErrorServerNotStarted;
                ConsoleGlobalDiscoveryServer(opcVaultOptions, azureADOptions).Wait();
                Console.WriteLine("Server started. Press Ctrl-C to exit...");
                exitCode = ExitCode.ErrorServerRunning;
            }
            catch (Exception ex)
            {
                Utils.Trace("ServiceResultException:" + ex.Message);
                Console.WriteLine("Exception: {0}", ex.Message);
                exitCode = ExitCode.ErrorServerException;
                return;
            }

            ManualResetEvent quitEvent = new ManualResetEvent(false);

            try
            {
                Console.CancelKeyPress += (sender, eArgs) =>
                {
                    quitEvent.Set();
                    eArgs.Cancel = true;
                };
            }
            catch
            {
            }

            // wait for timeout or Ctrl-C
            quitEvent.WaitOne();

            if (server != null)
            {
                Console.WriteLine("Server stopped. Waiting for exit...");

                using (OpcVaultGlobalDiscoveryServer _server = server)
                {
                    // Stop status thread
                    server = null;
                    status.Wait();
                    // Stop server and dispose
                    _server.Stop();
                }
            }

            exitCode = ExitCode.Ok;
        }
        public static int Main(string[] args)
        {
            Console.WriteLine(Name);

            // command line options
            bool showHelp        = false;
            var  opcVaultOptions = new OpcVaultApiOptions();
            var  azureADOptions  = new OpcVaultAzureADOptions();

            Mono.Options.OptionSet options = new Mono.Options.OptionSet {
                { "v|vault=", "OpcVault Url", g => opcVaultOptions.BaseAddress = g },
                { "r|resource=", "OpcVault Resource Id", r => opcVaultOptions.ResourceId = r },
                { "c|clientid=", "AD Client Id", c => azureADOptions.ClientId = c },
                { "s|secret=", "AD Client Secret", s => azureADOptions.ClientSecret = s },
                { "a|authority=", "Authority", a => azureADOptions.Authority = a },
                { "t|tenantid=", "Tenant Id", t => azureADOptions.TenantId = t },
                { "h|help", "show this message and exit", h => showHelp = h != null },
            };

            try
            {
                IList <string> extraArgs = options.Parse(args);
                foreach (string extraArg in extraArgs)
                {
                    Console.WriteLine("Error: Unknown option: {0}", extraArg);
                    showHelp = true;
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                showHelp = true;
            }

            if (showHelp)
            {
                Console.WriteLine("Usage: dotnet Microsoft.Azure.IIoT.OpcUa.Modules.Vault.dll [OPTIONS]");
                Console.WriteLine();

                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return((int)ExitCode.ErrorInvalidCommandLine);
            }

            var server = new VaultGlobalDiscoveryServer();

            server.Run(opcVaultOptions, azureADOptions);

            return((int)VaultGlobalDiscoveryServer.ExitCode);
        }
        private async Task ConsoleGlobalDiscoveryServer(
            OpcVaultApiOptions opcVaultOptions,
            OpcVaultAzureADOptions azureADOptions)
        {
            ApplicationInstance.MessageDlg = new ApplicationMessageDlg();
            ApplicationInstance application = new ApplicationInstance
            {
                ApplicationName   = Program.Name,
                ApplicationType   = ApplicationType.Server,
                ConfigSectionName = "Microsoft.Azure.IIoT.OpcUa.Modules.Vault"
            };

            // load the application configuration.
            ApplicationConfiguration config = await application.LoadApplicationConfiguration(false);

            // check the application certificate.
            bool haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, 0);

            if (!haveAppCertificate)
            {
                throw new Exception("Application instance certificate invalid!");
            }

            if (!config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
            {
                config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
            }

            // get the DatabaseStorePath configuration parameter.
            GlobalDiscoveryServerConfiguration opcVaultConfiguration = config.ParseExtension <GlobalDiscoveryServerConfiguration>();

            // extract appId and vault name from database storage path
            string[] keyVaultConfig = opcVaultConfiguration.DatabaseStorePath?.Split(',');
            if (keyVaultConfig != null)
            {
                if (String.IsNullOrEmpty(opcVaultOptions.BaseAddress))
                {
                    // try configuration using XML config
                    opcVaultOptions.BaseAddress = keyVaultConfig[0];
                }

                if (String.IsNullOrEmpty(opcVaultOptions.ResourceId))
                {
                    if (keyVaultConfig.Length > 1 && !String.IsNullOrEmpty(keyVaultConfig[1]))
                    {
                        opcVaultOptions.ResourceId = keyVaultConfig[1];
                    }
                }

                if (String.IsNullOrEmpty(azureADOptions.ClientId))
                {
                    if (keyVaultConfig.Length > 2 && !String.IsNullOrEmpty(keyVaultConfig[2]))
                    {
                        azureADOptions.ClientId = keyVaultConfig[2];
                    }
                }

                if (String.IsNullOrEmpty(azureADOptions.ClientSecret))
                {
                    if (keyVaultConfig.Length > 3 && !String.IsNullOrEmpty(keyVaultConfig[3]))
                    {
                        azureADOptions.ClientSecret = keyVaultConfig[3];
                    }
                }

                if (String.IsNullOrEmpty(azureADOptions.TenantId))
                {
                    if (keyVaultConfig.Length > 4 && !String.IsNullOrEmpty(keyVaultConfig[4]))
                    {
                        azureADOptions.TenantId = keyVaultConfig[4];
                    }
                }

                if (String.IsNullOrEmpty(azureADOptions.Authority))
                {
                    if (keyVaultConfig.Length > 5 && !String.IsNullOrEmpty(keyVaultConfig[5]))
                    {
                        azureADOptions.Authority = keyVaultConfig[5];
                    }
                }
            }

            var       serviceClient         = new OpcVaultLoginCredentials(opcVaultOptions, azureADOptions);
            IOpcVault opcVaultServiceClient = new Microsoft.Azure.IIoT.OpcUa.Api.Vault.OpcVault(new Uri(opcVaultOptions.BaseAddress), serviceClient);
            var       opcVaultHandler       = new OpcVaultClientHandler(opcVaultServiceClient);

            // read configurations from OpcVault secret
            opcVaultConfiguration.CertificateGroups = await opcVaultHandler.GetCertificateConfigurationGroupsAsync(opcVaultConfiguration.BaseCertificateGroupStorePath);

            UpdateGDSConfigurationDocument(config.Extensions, opcVaultConfiguration);

            var certGroup = new OpcVaultCertificateGroup(opcVaultHandler);
            var requestDB = new OpcVaultCertificateRequest(opcVaultServiceClient);
            var appDB     = new OpcVaultApplicationsDatabase(opcVaultServiceClient);

            requestDB.Initialize();
            // for UNITTEST set auto approve true
            server = new OpcVaultGlobalDiscoveryServer(appDB, requestDB, certGroup, false);

            // start the server.
            await application.Start(server);

            // print endpoint info
            var endpoints = application.Server.GetEndpoints().Select(e => e.EndpointUrl).Distinct();

            foreach (var endpoint in endpoints)
            {
                Console.WriteLine(endpoint);
            }

            // start the status thread
            status = Task.Run(new Action(StatusThread));

            // print notification on session events
            server.CurrentInstance.SessionManager.SessionActivated += EventStatus;
            server.CurrentInstance.SessionManager.SessionClosing   += EventStatus;
            server.CurrentInstance.SessionManager.SessionCreated   += EventStatus;
        }