예제 #1
0
        /// <summary>
        /// Create application configuration for client
        /// </summary>
        /// <returns></returns>
        private ApplicationConfiguration CreateApplicationConfiguration(
            TimeSpan operationTimeout, TimeSpan sessionTimeout)
        {
            // mitigation for bug in .NET Core 2.1
            var effectiveAppCertStoreType = _configuration.AppCertStoreType;
            var effectiveOwnCertPath      = _configuration.OwnCertPath;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                effectiveAppCertStoreType = CertificateStoreType.X509Store;
                effectiveOwnCertPath      = _configuration.OwnCertX509StorePathDefault;
            }

            var applicationConfiguration = new ApplicationConfiguration {
                ApplicationName       = "Azure IIoT OPC Twin Client Services",
                ApplicationType       = Opc.Ua.ApplicationType.Client,
                ApplicationUri        = "urn:" + Utils.GetHostName() + ":Azure:IIoTOpcTwin",
                CertificateValidator  = new CertificateValidator(),
                SecurityConfiguration = new SecurityConfiguration {
                    ApplicationCertificate = new CertificateIdentifier {
                        StoreType   = effectiveAppCertStoreType,
                        StorePath   = effectiveOwnCertPath,
                        SubjectName = "Azure IIoT OPC Twin"
                    },
                    TrustedPeerCertificates = new CertificateTrustList {
                        StoreType = CertificateStoreType.Directory,
                        StorePath = _configuration.TrustedCertPath
                    },
                    TrustedIssuerCertificates = new CertificateTrustList {
                        StoreType = CertificateStoreType.Directory,
                        StorePath = _configuration.IssuerCertPath
                    },
                    RejectedCertificateStore = new CertificateTrustList {
                        StoreType = CertificateStoreType.Directory,
                        StorePath = _configuration.RejectedCertPath
                    },
                    NonceLength = 32,
                    AutoAcceptUntrustedCertificates = _configuration.AutoAcceptUntrustedCertificates,
                    RejectSHA1SignedCertificates    = false,
                    AddAppCertToTrustedStore        = false,
                    MinimumCertificateKeySize       = 1024
                },
                TransportConfigurations = new TransportConfigurationCollection(),
                TransportQuotas         = TransportQuotaConfigEx.DefaultTransportQuotas(),
                ClientConfiguration     = new ClientConfiguration {
                    DefaultSessionTimeout = (int)sessionTimeout.TotalMilliseconds
                }
            };

            applicationConfiguration.TransportQuotas.OperationTimeout = (int)operationTimeout.TotalMilliseconds;
            return(applicationConfiguration);
        }
예제 #2
0
            /// <summary>
            /// Create server configuration
            /// </summary>
            /// <param name="ports"></param>
            /// <returns></returns>
            public static ApplicationConfiguration CreateServerConfiguration(
                IEnumerable <int> ports, string pkiRootPath)
            {
                var extensions = new List <object> {
                    new MemoryBuffer.MemoryBufferConfiguration {
                        Buffers = new MemoryBuffer.MemoryBufferInstanceCollection {
                            new MemoryBuffer.MemoryBufferInstance {
                                Name     = "UInt32",
                                TagCount = 10000,
                                DataType = "UInt32"
                            },
                            new MemoryBuffer.MemoryBufferInstance {
                                Name     = "Double",
                                TagCount = 100,
                                DataType = "Double"
                            },
                        }
                    },

                    /// ...
                };

                if (string.IsNullOrEmpty(pkiRootPath))
                {
                    pkiRootPath = "pki";
                }
                return(new ApplicationConfiguration {
                    ApplicationName = "UA Core Sample Server",
                    ApplicationType = ApplicationType.Server,
                    ApplicationUri = $"urn:{Utils.GetHostName()}:OPCFoundation:CoreSampleServer",
                    Extensions = new XmlElementCollection(
                        extensions.Select(XmlElementEx.SerializeObject)),

                    ProductUri = "http://opcfoundation.org/UA/SampleServer",
                    SecurityConfiguration = new SecurityConfiguration {
                        ApplicationCertificate = new CertificateIdentifier {
                            StoreType = CertificateStoreType.Directory,
                            StorePath = $"{pkiRootPath}/own",
                            SubjectName = "UA Core Sample Server",
                        },
                        TrustedPeerCertificates = new CertificateTrustList {
                            StoreType = CertificateStoreType.Directory,
                            StorePath = $"{pkiRootPath}/trusted",
                        },
                        TrustedIssuerCertificates = new CertificateTrustList {
                            StoreType = CertificateStoreType.Directory,
                            StorePath = $"{pkiRootPath}/issuer",
                        },
                        RejectedCertificateStore = new CertificateTrustList {
                            StoreType = CertificateStoreType.Directory,
                            StorePath = $"{pkiRootPath}/rejected",
                        },
                        MinimumCertificateKeySize = 1024,
                        RejectSHA1SignedCertificates = false,
                        AutoAcceptUntrustedCertificates = true,
                        AddAppCertToTrustedStore = true
                    },
                    TransportConfigurations = new TransportConfigurationCollection(),
                    TransportQuotas = TransportQuotaConfigEx.DefaultTransportQuotas(),
                    ServerConfiguration = new ServerConfiguration {
                        // Sample server specific
                        ServerProfileArray = new StringCollection {
                            "Standard UA Server Profile",
                            "Data Access Server Facet",
                            "Method Server Facet"
                        },
                        ServerCapabilities = new StringCollection {
                            "DA"
                        },
                        SupportedPrivateKeyFormats = new StringCollection {
                            "PFX", "PEM"
                        },

                        NodeManagerSaveFile = "nodes.xml",
                        DiagnosticsEnabled = false,
                        ShutdownDelay = 5,

                        // No op
                        MinRequestThreadCount = 3,
                        MaxRequestThreadCount = 100,
                        MaxQueuedRequestCount = 2000,

                        // Runtime configuration
                        BaseAddresses = new StringCollection(ports
                                                             .Distinct()
                                                             .Select(p => $"opc.tcp://localhost:{p}/UA/SampleServer")),

                        SecurityPolicies = new ServerSecurityPolicyCollection {
                            new ServerSecurityPolicy {
                                SecurityMode = MessageSecurityMode.Sign,
                                SecurityPolicyUri = SecurityPolicies.Basic256Sha256,
                            },
                            new ServerSecurityPolicy {
                                SecurityMode = MessageSecurityMode.SignAndEncrypt,
                                SecurityPolicyUri = SecurityPolicies.Basic256Sha256,
                            },
                            new ServerSecurityPolicy {
                                SecurityMode = MessageSecurityMode.None,
                                SecurityPolicyUri = SecurityPolicies.None
                            }
                        },
                        UserTokenPolicies = new UserTokenPolicyCollection {
                            new UserTokenPolicy {
                                TokenType = UserTokenType.Anonymous,
                                SecurityPolicyUri = SecurityPolicies.None,
                            },
                            new UserTokenPolicy {
                                TokenType = UserTokenType.UserName
                            },
                            new UserTokenPolicy {
                                TokenType = UserTokenType.Certificate
                            }
                        },

                        MaxSessionCount = 100,
                        MinSessionTimeout = 10000,
                        MaxSessionTimeout = 3600000,
                        MaxBrowseContinuationPoints = 10,
                        MaxQueryContinuationPoints = 10,
                        MaxHistoryContinuationPoints = 100,
                        MaxRequestAge = 600000,
                        MinPublishingInterval = 100,
                        MaxPublishingInterval = 3600000,
                        PublishingResolution = 50,
                        MaxSubscriptionLifetime = 3600000,
                        MaxMessageQueueSize = 100,
                        MaxNotificationQueueSize = 100,
                        MaxNotificationsPerPublish = 1000,
                        MinMetadataSamplingInterval = 1000,
                        MaxPublishRequestCount = 20,
                        MaxSubscriptionCount = 100,
                        MaxEventQueueSize = 10000,
                        MinSubscriptionLifetime = 10000,

                        // Do not register with LDS
                        MaxRegistrationInterval = 0, // TODO
                        RegistrationEndpoint = null
                    },
                    TraceConfiguration = new TraceConfiguration {
                        TraceMasks = 1
                    }
                });
            }