public async Task <CertificateGroupConfigurationCollection> GetCertificateConfigurationGroupsAsync(string baseStorePath)
        {
            var groups = await _opcServiceClient.GetCertificateGroupsConfigurationAsync().ConfigureAwait(false);

            var groupCollection = new CertificateGroupConfigurationCollection();

            foreach (var group in groups.Groups)
            {
                var newGroup = new CertificateGroupConfiguration()
                {
                    Id = group.Name,
                    CertificateType            = group.CertificateType,
                    SubjectName                = group.SubjectName,
                    BaseStorePath              = baseStorePath + Path.DirectorySeparatorChar + group.Name,
                    DefaultCertificateHashSize = (ushort)group.DefaultCertificateHashSize,
                    DefaultCertificateKeySize  = (ushort)group.DefaultCertificateKeySize,
                    DefaultCertificateLifetime = (ushort)group.DefaultCertificateLifetime,
                    CACertificateHashSize      = (ushort)group.IssuerCACertificateHashSize,
                    CACertificateKeySize       = (ushort)group.IssuerCACertificateKeySize,
                    CACertificateLifetime      = (ushort)group.IssuerCACertificateLifetime
                };
                groupCollection.Add(newGroup);
            }
            return(groupCollection);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the node manager.
        /// </summary>
        public GlobalDiscoveryServiceNodeManager(IServerInternal server, ApplicationConfiguration applicationConfiguration,
                                                 IApplicationsDatabase database, ICertificateRequest request, ICertificateGroup certificateGroup, bool autoApprove = false)
            : base(server, applicationConfiguration)
        {
            NamespaceUris = new List <string> {
                $"http://{Dns.GetHostName()}/GDS/Default", Namespaces.OpcUaGds
            };
            _nextNodeId = 0;
            SystemContext.NodeIdFactory = this;
            _defaultSubjectNameContext  = "CN=" + applicationConfiguration.ApplicationName + ", DC=" + Dns.GetHostName();
            _certificateGroupConfigurationCollection = new CertificateGroupConfigurationCollection();

            //Authorities Certificates Store Path
            string directoryName = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);

            if (string.IsNullOrEmpty(directoryName))
            {
                return;
            }
            string authoritiesStorePathDirectory = Path.Combine(directoryName, "pki\\authoritie");

            if (!Directory.Exists(authoritiesStorePathDirectory))
            {
                Directory.CreateDirectory(authoritiesStorePathDirectory);
            }
            _authoritiesStorePath = authoritiesStorePathDirectory;
            //Application Certificates Store Path
            string applicationCertificatesStorePathDirectory = Path.Combine(directoryName, "pki\\applications");

            if (!Directory.Exists(applicationCertificatesStorePathDirectory))
            {
                Directory.CreateDirectory(applicationCertificatesStorePathDirectory);
            }
            _applicationCertificatesStorePath = applicationCertificatesStorePathDirectory;
            //Base Certificates Store Path
            string baseCertificateGroupStorePathDirectory = Path.Combine(directoryName, "pki\\CA\\default");

            if (!Directory.Exists(baseCertificateGroupStorePathDirectory))
            {
                Directory.CreateDirectory(baseCertificateGroupStorePathDirectory);
            }
            _certificateGroupConfigurationCollection.Add(new CertificateGroupConfiguration {
                Id = "Default",
                CertificateType            = "RsaSha256ApplicationCertificateType",
                SubjectName                = _defaultSubjectNameContext,
                BaseStorePath              = baseCertificateGroupStorePathDirectory,
                DefaultCertificateLifetime = 12,
                DefaultCertificateKeySize  = 2048,
                DefaultCertificateHashSize = 256,
                CACertificateLifetime      = 60,
                CACertificateKeySize       = 2048,
                CACertificateHashSize      = 256
            });
            _knownHostNames = new StringCollection();

            _defaultApplicationGroupId = ExpandedNodeId.ToNodeId(ObjectIds.Directory_CertificateGroups_DefaultApplicationGroup, Server.NamespaceUris);
            _defaultHttpsGroupId       = ExpandedNodeId.ToNodeId(ObjectIds.Directory_CertificateGroups_DefaultHttpsGroup, Server.NamespaceUris);
            _defaultUserTokenGroupId   = ExpandedNodeId.ToNodeId(ObjectIds.Directory_CertificateGroups_DefaultUserTokenGroup, Server.NamespaceUris);

            _autoApprove             = autoApprove;
            _database                = database;
            _request                 = request;
            _certificateGroupFactory = certificateGroup;
            _certificateGroups       = new Dictionary <NodeId, CertificateGroup>();

            try
            {
                ServerOnNetwork[] results = _database.QueryServers(0, 5, null, null, null, null, out DateTime _);
                Utils.Trace($"QueryServers Returned: {results.Length} records");
                foreach (ServerOnNetwork result in results)
                {
                    Utils.Trace($"Server Found at {result.DiscoveryUrl}");
                }
            }
            catch (Exception e)
            {
                Utils.Trace($"Could not connect to the Database! Exception:\r\n{e.InnerException}");
                Utils.Trace("Initialize Database tables!");
                _database.Initialize();
                Utils.Trace("Database Initialized!");
            }
            Server.MessageContext.Factory.AddEncodeableTypes(typeof(ObjectIds).GetTypeInfo().Assembly);
        }