forked from OPCFoundation/UA-.NETStandard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationConfiguration.cs
More file actions
2903 lines (2613 loc) · 106 KB
/
ApplicationConfiguration.cs
File metadata and controls
2903 lines (2613 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 1996-2022 The OPC Foundation. All rights reserved.
The source code in this file is covered under a dual-license scenario:
- RCL: for OPC Foundation Corporate Members in good-standing
- GPL V2: everybody else
RCL license terms accompanied with this source code. See http://opcfoundation.org/License/RCL/1.00/
GNU General Public License as published by the Free Software Foundation;
version 2 of the License are accompanied with this source code. See http://opcfoundation.org/License/GPLv2
This source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Extensions.Logging;
using Opc.Ua.Bindings;
using Opc.Ua.Security;
namespace Opc.Ua
{
/// <summary>
/// Stores the configurable configuration information for a UA application.
/// </summary>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public partial class ApplicationConfiguration
{
/// <summary>
/// The default constructor.
/// </summary>
public ApplicationConfiguration()
{
Initialize();
}
/// <summary>
/// The default constructor.
/// </summary>
public ApplicationConfiguration(ITelemetryContext telemetry)
{
Initialize(telemetry);
Initialize();
}
/// <summary>
/// The constructor from a template.
/// </summary>
public ApplicationConfiguration(ApplicationConfiguration template)
{
ApplicationName = template.ApplicationName;
ApplicationType = template.ApplicationType;
ApplicationUri = template.ApplicationUri;
DiscoveryServerConfiguration = template.DiscoveryServerConfiguration;
m_securityConfiguration = template.m_securityConfiguration;
m_transportConfigurations = template.m_transportConfigurations;
ServerConfiguration = template.ServerConfiguration;
ClientConfiguration = template.ClientConfiguration;
DisableHiResClock = template.DisableHiResClock;
CertificateValidator = template.CertificateValidator;
TransportQuotas = template.TransportQuotas;
TraceConfiguration = template.TraceConfiguration;
m_extensions = template.m_extensions;
m_extensionObjects = template.m_extensionObjects;
SourceFilePath = template.SourceFilePath;
m_properties = template.m_properties;
m_telemetry = template.m_telemetry;
m_logger = template.m_logger;
}
/// <summary>
/// Sets private members to default values.
/// </summary>
private void Initialize()
{
SourceFilePath = null;
m_securityConfiguration = new SecurityConfiguration();
m_transportConfigurations = [];
DisableHiResClock = false;
m_properties = [];
m_extensionObjects = [];
CertificateValidator ??= new CertificateValidator(m_telemetry);
m_logger ??= m_telemetry.CreateLogger<ApplicationConfiguration>();
}
/// <summary>
/// Initialize telemetry context - after loading
/// </summary>
/// <param name="telemetry">The telemetry context to use to create obvservability instruments</param>
internal void Initialize(ITelemetryContext telemetry)
{
m_telemetry = telemetry;
m_logger = telemetry.CreateLogger<ApplicationConfiguration>();
CertificateValidator = new CertificateValidator(m_telemetry);
}
/// <summary>
/// Initializes the object during deserialization.
/// </summary>
/// <param name="context">The context.</param>
[OnDeserializing]
public void Initialize(StreamingContext context)
{
m_telemetry = AmbientMessageContext.Telemetry;
Initialize();
}
/// <summary>
/// Gets an object used to synchronize access to the properties dictionary.
/// </summary>
/// <value>
/// The object used to synchronize access to the properties dictionary.
/// </value>
public object PropertiesLock => m_properties;
/// <summary>
/// Gets a dictionary used to save state associated with the application.
/// </summary>
/// <value>
/// The dictionary used to save state associated with the application.
/// </value>
public IDictionary<string, object> Properties => m_properties;
/// <summary>
/// Storage for decoded extensions of the application.
/// Used by ParseExtension if no matching XmlElement is found.
/// </summary>
public IList<object> ExtensionObjects => m_extensionObjects;
/// <summary>
/// A descriptive name for the application (not necessarily unique).
/// </summary>
/// <value>The name of the application.</value>
[DataMember(IsRequired = true, EmitDefaultValue = false, Order = 0)]
public string ApplicationName { get; set; }
/// <summary>
/// A unique identifier for the application instance.
/// </summary>
/// <value>The application URI.</value>
[DataMember(IsRequired = true, EmitDefaultValue = false, Order = 1)]
public string ApplicationUri { get; set; }
/// <summary>
/// A unique identifier for the product.
/// </summary>
/// <value>The product URI.</value>
[DataMember(IsRequired = false, Order = 2)]
public string ProductUri { get; set; }
/// <summary>
/// The type of application.
/// </summary>
/// <value>The type of the application.</value>
[DataMember(IsRequired = true, Order = 3)]
public ApplicationType ApplicationType { get; set; }
/// <summary>
/// The security configuration for the application.
/// </summary>
/// <value>The security configuration.</value>
[DataMember(IsRequired = false, EmitDefaultValue = true, Order = 4)]
public SecurityConfiguration SecurityConfiguration
{
get => m_securityConfiguration;
set => m_securityConfiguration = value ?? new SecurityConfiguration();
}
/// <summary>
/// The transport configuration for the application.
/// </summary>
/// <value>The transport configurations.</value>
[DataMember(IsRequired = false, EmitDefaultValue = true, Order = 5)]
public TransportConfigurationCollection TransportConfigurations
{
get => m_transportConfigurations;
set => m_transportConfigurations = value ?? [];
}
/// <summary>
/// The quotas that are used at the transport layer.
/// </summary>
/// <value>The transport quotas.</value>
[DataMember(IsRequired = false, EmitDefaultValue = true, Order = 6)]
public TransportQuotas TransportQuotas { get; set; }
/// <summary>
/// Additional configuration for server applications.
/// </summary>
/// <value>The server configuration.</value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 7)]
public ServerConfiguration ServerConfiguration { get; set; }
/// <summary>
/// Additional configuration for client applications.
/// </summary>
/// <value>The client configuration.</value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 8)]
public ClientConfiguration ClientConfiguration { get; set; }
/// <summary>
/// Additional configuration of the discovery server.
/// </summary>
/// <value>The discovery server configuration.</value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 9)]
public DiscoveryServerConfiguration DiscoveryServerConfiguration { get; set; }
/// <summary>
/// A bucket to store additional application specific configuration data.
/// </summary>
/// <value>The extensions.</value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 10)]
public XmlElementCollection Extensions
{
get => m_extensions;
set => m_extensions = value;
}
/// <summary>
/// Configuration of the trace and information about log file
/// </summary>
/// <value>The trace configuration.</value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 11)]
public TraceConfiguration TraceConfiguration { get; set; }
/// <summary>
/// Disabling / enabling high resolution clock
/// </summary>
/// <value><c>true</c> if high resolution clock is disabled; otherwise, <c>false</c>.</value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 12)]
public bool DisableHiResClock { get; set; }
private ITelemetryContext m_telemetry;
private ILogger m_logger;
private SecurityConfiguration m_securityConfiguration;
private TransportConfigurationCollection m_transportConfigurations;
private XmlElementCollection m_extensions;
private List<object> m_extensionObjects;
private Dictionary<string, object> m_properties;
}
/// <summary>
/// Specifies various limits that apply to the transport or secure channel layers.
/// </summary>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public class TransportQuotas
{
/// <summary>
/// The default constructor.
/// </summary>
public TransportQuotas()
{
Initialize();
}
/// <summary>
/// Sets private members to default values.
/// </summary>
private void Initialize()
{
// encoding limits
MaxMessageSize = DefaultEncodingLimits.MaxMessageSize;
MaxStringLength = DefaultEncodingLimits.MaxStringLength;
MaxByteStringLength = DefaultEncodingLimits.MaxByteStringLength;
MaxArrayLength = DefaultEncodingLimits.MaxArrayLength;
MaxEncodingNestingLevels = DefaultEncodingLimits.MaxEncodingNestingLevels;
MaxDecoderRecoveries = DefaultEncodingLimits.MaxDecoderRecoveries;
// message limits
MaxBufferSize = TcpMessageLimits.DefaultMaxBufferSize;
OperationTimeout = TcpMessageLimits.DefaultOperationTimeout;
ChannelLifetime = TcpMessageLimits.DefaultChannelLifetime;
SecurityTokenLifetime = TcpMessageLimits.DefaultSecurityTokenLifeTime;
}
/// <summary>
/// Initializes the object during deserialization.
/// </summary>
/// <param name="context">The context.</param>
[OnDeserializing]
public void Initialize(StreamingContext context)
{
Initialize();
}
/// <summary>
/// The default timeout to use when sending requests (in milliseconds).
/// </summary>
/// <value>The operation timeout.</value>
[DataMember(IsRequired = false, Order = 0)]
public int OperationTimeout { get; set; }
/// <summary>
/// The maximum length of string encoded in a message body.
/// </summary>
/// <value>The max length of the string.</value>
[DataMember(IsRequired = false, Order = 1)]
public int MaxStringLength { get; set; }
/// <summary>
/// The maximum length of a byte string encoded in a message body.
/// </summary>
/// <value>The max length of the byte string.</value>
[DataMember(IsRequired = false, Order = 2)]
public int MaxByteStringLength { get; set; }
/// <summary>
/// The maximum length of an array encoded in a message body.
/// </summary>
/// <value>The max length of the array.</value>
[DataMember(IsRequired = false, Order = 3)]
public int MaxArrayLength { get; set; }
/// <summary>
/// The maximum length of a message body.
/// </summary>
/// <value>The max size of the message.</value>
[DataMember(IsRequired = false, Order = 4)]
public int MaxMessageSize { get; set; }
/// <summary>
/// The maximum size of the buffer to use when sending messages.
/// </summary>
/// <value>The max size of the buffer.</value>
[DataMember(IsRequired = false, Order = 5)]
public int MaxBufferSize { get; set; }
/// <summary>
/// The maximum nesting level accepted while encoding or decoding objects.
/// </summary>
[DataMember(IsRequired = false, Order = 6)]
public int MaxEncodingNestingLevels { get; set; }
/// <summary>
/// The number of times the decoder can recover from a decoder error
/// of an IEncodeable before throwing a decoder error.
/// </summary>
[DataMember(IsRequired = false, Order = 7)]
public int MaxDecoderRecoveries { get; set; }
/// <summary>
/// The lifetime of a secure channel (in milliseconds).
/// </summary>
/// <value>The channel lifetime.</value>
[DataMember(IsRequired = false, Order = 8)]
public int ChannelLifetime { get; set; }
/// <summary>
/// The lifetime of a security token (in milliseconds).
/// </summary>
/// <value>The security token lifetime.</value>
[DataMember(IsRequired = false, Order = 9)]
public int SecurityTokenLifetime { get; set; }
}
/// <summary>
/// Specifies parameters used for tracing.
/// </summary>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public class TraceConfiguration
{
/// <summary>
/// The default constructor.
/// </summary>
public TraceConfiguration()
{
Initialize();
}
/// <summary>
/// Sets private members to default values.
/// </summary>
private void Initialize()
{
OutputFilePath = null;
DeleteOnLoad = false;
}
/// <summary>
/// Initializes the object during deserialization.
/// </summary>
/// <param name="context">The context.</param>
[OnDeserializing]
public void Initialize(StreamingContext context)
{
Initialize();
}
/// <summary>
/// The output file used to log the trace information.
/// </summary>
/// <value>The output file path.</value>
[DataMember(IsRequired = false, Order = 0)]
public string OutputFilePath { get; set; }
/// <summary>
/// Whether the existing log file should be deleted when the application configuration is loaded.
/// </summary>
/// <value><c>true</c> if existing log file should be deleted when the application configuration is loaded; otherwise, <c>false</c>.</value>
[DataMember(IsRequired = false, Order = 1)]
public bool DeleteOnLoad { get; set; }
/// <summary>
/// The masks used to select what is written to the output
/// Masks supported by the trace feature:
/// - Do not output any messages -None = 0x0;
/// - Output error messages - Error = 0x1;
/// - Output informational messages - Information = 0x2;
/// - Output stack traces - StackTrace = 0x4;
/// - Output basic messages for service calls - Service = 0x8;
/// - Output detailed messages for service calls - ServiceDetail = 0x10;
/// - Output basic messages for each operation - Operation = 0x20;
/// - Output detailed messages for each operation - OperationDetail = 0x40;
/// - Output messages related to application initialization or shutdown - StartStop = 0x80;
/// - Output messages related to a call to an external system - ExternalSystem = 0x100;
/// - Output messages related to security. - Security = 0x200;
/// </summary>
/// <value>The trace masks.</value>
[DataMember(IsRequired = false, Order = 2)]
public int TraceMasks { get; set; }
}
/// <summary>
/// Specifies the configuration information for a transport protocol
/// </summary>
/// <remarks>
/// Each application is allows to have one transport configure per protocol type.
/// </remarks>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public class TransportConfiguration
{
/// <summary>
/// The default constructor.
/// </summary>
public TransportConfiguration()
{
}
/// <summary>
/// The default constructor.
/// </summary>
/// <param name="urlScheme">The URL scheme.</param>
/// <param name="type">The type.</param>
public TransportConfiguration(string urlScheme, Type type)
{
UriScheme = urlScheme;
TypeName = type.AssemblyQualifiedName;
}
/// <summary>
/// The URL prefix used by the application (http, opc.tcp, net.tpc, etc.).
/// </summary>
/// <value>The URI scheme.</value>
[DataMember(IsRequired = true, EmitDefaultValue = false, Order = 0)]
public string UriScheme { get; set; }
/// <summary>
/// The name of the class that defines the binding for the transport.
/// </summary>
/// <value>The name of the type.</value>
/// <remarks>
/// <para>
/// This can be any instance of the System.ServiceModel.Channels.Binding class
/// that implements these constructors:
/// </para>
/// <para>
/// XxxBinding(EndpointDescription description, EndpointConfiguration configuration);
/// XxxBinding(IList{EndpointDescription} descriptions, EndpointConfiguration configuration)
/// XxxBinding(EndpointConfiguration configuration)
/// </para>
/// </remarks>
[DataMember(IsRequired = true, EmitDefaultValue = false, Order = 1)]
public string TypeName { get; set; }
}
/// <summary>
/// A collection of TransportConfiguration objects.
/// </summary>
[CollectionDataContract(
Name = "ListOfTransportConfiguration",
Namespace = Namespaces.OpcUaConfig,
ItemName = "TransportConfiguration"
)]
public class TransportConfigurationCollection : List<TransportConfiguration>
{
/// <summary>
/// Initializes an empty collection.
/// </summary>
public TransportConfigurationCollection()
{
}
/// <summary>
/// Initializes the collection from another collection.
/// </summary>
/// <param name="collection">A collection of values to add to this new collection</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="collection"/> is null.
/// </exception>
public TransportConfigurationCollection(IEnumerable<TransportConfiguration> collection)
: base(collection)
{
}
/// <summary>
/// Initializes the collection with the specified capacity.
/// </summary>
/// <param name="capacity">The capacity.</param>
public TransportConfigurationCollection(int capacity)
: base(capacity)
{
}
}
/// <summary>
/// A class that defines a group of security policies supported by the server.
/// </summary>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public class ServerSecurityPolicy
{
/// <summary>
/// The default constructor.
/// </summary>
public ServerSecurityPolicy()
{
Initialize();
}
/// <summary>
/// Sets private members to default values.
/// </summary>
private void Initialize()
{
SecurityMode = MessageSecurityMode.SignAndEncrypt;
SecurityPolicyUri = SecurityPolicies.Basic256Sha256;
}
/// <summary>
/// Initializes the object during deserialization.
/// </summary>
/// <param name="context">The context.</param>
[OnDeserializing]
public void Initialize(StreamingContext context)
{
Initialize();
}
/// <summary>
/// Obsolete version of CalculateSecurityLevel that does not take a logger.
/// </summary>
[Obsolete("Use CalculateSecurityLevel(MessageSecurityMode mode, string policyUri, ILogger logger) instead.")]
public static byte CalculateSecurityLevel(
MessageSecurityMode mode,
string policyUri)
{
return SecuredApplication.CalculateSecurityLevel(mode, policyUri);
}
/// <summary>
/// Calculates the security level, given the security mode and policy
/// Invalid and none is discouraged
/// Just signing is always weaker than any use of encryption
/// </summary>
public static byte CalculateSecurityLevel(
MessageSecurityMode mode,
string policyUri,
ILogger logger)
{
return SecuredApplication.CalculateSecurityLevel(mode, policyUri, logger);
}
/// <summary>
/// Specifies whether the messages are signed and encrypted or simply signed
/// </summary>
/// <value>The security mode.</value>
[DataMember(IsRequired = false, Order = 1)]
public MessageSecurityMode SecurityMode { get; set; }
/// <summary>
/// The security policy to use.
/// </summary>
/// <value>The security policy URI.</value>
[DataMember(IsRequired = false, Order = 2)]
public string SecurityPolicyUri { get; set; }
}
/// <summary>
/// A collection of ServerSecurityPolicy objects.
/// </summary>
[CollectionDataContract(
Name = "ListOfServerSecurityPolicy",
Namespace = Namespaces.OpcUaConfig,
ItemName = "ServerSecurityPolicy"
)]
public class ServerSecurityPolicyCollection : List<ServerSecurityPolicy>
{
/// <summary>
/// Initializes an empty collection.
/// </summary>
public ServerSecurityPolicyCollection()
{
}
/// <summary>
/// Initializes the collection from another collection.
/// </summary>
/// <param name="collection">A collection of values to add to this new collection</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="collection"/> is null.
/// </exception>
public ServerSecurityPolicyCollection(IEnumerable<ServerSecurityPolicy> collection)
: base(collection)
{
}
/// <summary>
/// Initializes the collection with the specified capacity.
/// </summary>
/// <param name="capacity">The capacity.</param>
public ServerSecurityPolicyCollection(int capacity)
: base(capacity)
{
}
}
/// <summary>
/// The security configuration for the application.
/// </summary>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public partial class SecurityConfiguration
{
/// <summary>
/// The default constructor.
/// </summary>
public SecurityConfiguration()
{
Initialize();
}
/// <summary>
/// Sets private members to default values.
/// </summary>
private void Initialize()
{
m_applicationCertificates = [];
m_trustedIssuerCertificates = new CertificateTrustList();
m_trustedPeerCertificates = new CertificateTrustList();
NonceLength = 32;
MaxRejectedCertificates = 5;
AutoAcceptUntrustedCertificates = false;
RejectSHA1SignedCertificates = true;
RejectUnknownRevocationStatus = false;
MinimumCertificateKeySize = CertificateFactory.DefaultKeySize;
AddAppCertToTrustedStore = true;
SendCertificateChain = true;
SuppressNonceValidationErrors = false;
IsDeprecatedConfiguration = false;
}
/// <summary>
/// Initializes the object during deserialization.
/// </summary>
[OnDeserializing]
public void Initialize(StreamingContext context)
{
Initialize();
}
/// <summary>
/// The application instance certificate.
/// Kept for backward compatibility with configuration files which only support RSA certificates.
/// </summary>
/// <value>The application certificate.</value>
/// <remarks>
/// This certificate must contain the application uri.
/// For servers, URLs for each supported protocol must also be present.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 0)]
public CertificateIdentifier ApplicationCertificate
{
get
{
if (m_applicationCertificates.Count > 0)
{
return m_applicationCertificates[0];
}
return null;
}
set
{
if (m_applicationCertificates.Count > 0)
{
if (value == null)
{
m_applicationCertificates.RemoveAt(0);
}
else
{
m_applicationCertificates[0] = value;
}
}
else
{
m_applicationCertificates.Add(value);
}
SupportedSecurityPolicies = BuildSupportedSecurityPolicies();
m_applicationCertificates[0].CertificateType = ObjectTypeIds
.RsaSha256ApplicationCertificateType;
IsDeprecatedConfiguration = true;
}
}
/// <summary>
/// The application instance certificates in use for the application.
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 1)]
public CertificateIdentifierCollection ApplicationCertificates
{
get => m_applicationCertificates;
set
{
if (value == null || value.Count == 0)
{
m_applicationCertificates = new CertificateIdentifierCollection();
return;
}
var newCertificates = new CertificateIdentifierCollection(value);
// Remove unsupported certificate types
for (int i = newCertificates.Count - 1; i >= 0; i--)
{
if (!Utils.IsSupportedCertificateType(newCertificates[i].CertificateType))
{
// TODO: Log when ITelemetry instance is available
newCertificates.RemoveAt(i);
}
}
// Remove any duplicates based on thumbprint
// Only perform duplicate detection if we have actual loaded certificates
for (int i = 0; i < newCertificates.Count; i++)
{
for (int j = newCertificates.Count - 1; j > i; j--)
{
bool isDuplicate = false;
// Only check for duplicates if both certificates are actually loaded
if (newCertificates[i].Certificate != null && newCertificates[j].Certificate != null)
{
// Compare by actual certificate thumbprint
isDuplicate = newCertificates[i].Certificate.Thumbprint.Equals(
newCertificates[j].Certificate.Thumbprint,
StringComparison.OrdinalIgnoreCase);
}
// If certificates aren't loaded yet, compare by explicit thumbprint configuration
else if (!string.IsNullOrEmpty(newCertificates[i].Thumbprint) &&
!string.IsNullOrEmpty(newCertificates[j].Thumbprint))
{
isDuplicate = newCertificates[i].Thumbprint.Equals(
newCertificates[j].Thumbprint,
StringComparison.OrdinalIgnoreCase);
}
if (isDuplicate)
{
newCertificates.RemoveAt(j);
}
}
}
m_applicationCertificates = newCertificates;
SupportedSecurityPolicies = BuildSupportedSecurityPolicies();
}
}
/// <summary>
/// The store containing any additional issuer certificates.
/// </summary>
[DataMember(IsRequired = true, EmitDefaultValue = false, Order = 2)]
public CertificateTrustList TrustedIssuerCertificates
{
get => m_trustedIssuerCertificates;
set => m_trustedIssuerCertificates = value ?? new CertificateTrustList();
}
/// <summary>
/// The trusted certificate store.
/// </summary>
[DataMember(IsRequired = true, EmitDefaultValue = false, Order = 4)]
public CertificateTrustList TrustedPeerCertificates
{
get => m_trustedPeerCertificates;
set => m_trustedPeerCertificates = value ?? new CertificateTrustList();
}
/// <summary>
/// The length of nonce in the CreateSession service.
/// </summary>
/// <value>
/// The length of nonce in the CreateSession service.
/// </value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 6)]
public int NonceLength { get; set; }
/// <summary>
/// A store where invalid certificates can be placed for later review by the administrator.
/// </summary>
/// <value>
/// A store where invalid certificates can be placed for later review by the administrator.
/// </value>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 7)]
public CertificateStoreIdentifier RejectedCertificateStore { get; set; }
/// <summary>
/// Gets or sets a value indicating how many certificates are kept
/// in the rejected store before the oldest is removed.
/// </summary>
/// <remarks>
/// This value can be set by applications.
/// The number of certificates to keep in the rejected store before it is updated.
/// <see langword="0"/> to keep all rejected certificates.
/// A negative number to keep no history.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 8)]
public int MaxRejectedCertificates { get; set; }
/// <summary>
/// Gets or sets a value indicating whether untrusted certificates should be automatically accepted.
/// </summary>
/// <remarks>
/// This flag can be set to by servers that allow anonymous clients or use user credentials for authentication.
/// It can be set by clients that connect to URLs specified in configuration rather than with user entry.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 9)]
public bool AutoAcceptUntrustedCertificates { get; set; }
/// <summary>
/// Gets or sets a directory which contains files representing users roles.
/// </summary>
[DataMember(Order = 10)]
public string UserRoleDirectory { get; set; }
/// <summary>
/// Gets or sets a value indicating whether SHA-1 signed certificates are accepted.
/// </summary>
/// <remarks>
/// This flag can be set to false by servers that accept SHA-1 signed certificates.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 11)]
public bool RejectSHA1SignedCertificates { get; set; }
/// <summary>
/// Gets or sets a value indicating whether certificates with unavailable revocation lists are not accepted.
/// </summary>
/// <remarks>
/// This flag can be set to true by servers that must have a revocation list for each CA (even if empty).
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 12)]
public bool RejectUnknownRevocationStatus { get; set; }
/// <summary>
/// Gets or sets a value indicating which minimum certificate key strength is accepted.
/// The value is ignored for certificates with a ECDSA signature.
/// </summary>
/// <remarks>
/// This value can be set to 1024, 2048 or 4096 by servers
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 13)]
public ushort MinimumCertificateKeySize { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the Validator skips the full chain validation
/// for already validated or accepted certificates.
/// </summary>
/// <remarks>
/// This flag can be set to true by applications.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 14)]
public bool UseValidatedCertificates { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the application cert should be copied to the trusted store.
/// </summary>
/// <remarks>
/// It is useful for client/server applications running on the same host and sharing the cert store to autotrust.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 15)]
public bool AddAppCertToTrustedStore { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the application should send the complete certificate chain.
/// </summary>
/// <remarks>
/// If set to true the complete certificate chain will be sent for CA signed certificates.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 16)]
public bool SendCertificateChain { get; set; }
/// <summary>
/// The store containing additional user issuer certificates.
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 17)]
public CertificateTrustList UserIssuerCertificates
{
get => m_userIssuerCertificates;
set => m_userIssuerCertificates = value ?? new CertificateTrustList();
}
/// <summary>
/// The store containing trusted user certificates.
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 18)]
public CertificateTrustList TrustedUserCertificates
{
get => m_trustedUserCertificates;
set => m_trustedUserCertificates = value ?? new CertificateTrustList();
}
/// <summary>
/// The store containing additional Https issuer certificates.
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 19)]
public CertificateTrustList HttpsIssuerCertificates
{
get => m_httpsIssuerCertificates;
set => m_httpsIssuerCertificates = value ?? new CertificateTrustList();
}
/// <summary>
/// The store containing trusted Https certificates.
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 20)]
public CertificateTrustList TrustedHttpsCertificates
{
get => m_trustedHttpsCertificates;
set => m_trustedHttpsCertificates = value ?? new CertificateTrustList();
}
/// <summary>
/// Gets or sets a value indicating whether the server nonce validation errors should be suppressed.
/// </summary>
/// <remarks>
/// Allows client interoperability with legacy servers which do not comply with the specification for nonce usage.
/// If set to true the server nonce validation errors are suppressed.
/// Please set this flag to true only in close and secured networks since it can cause security vulnerabilities.
/// </remarks>
[DataMember(IsRequired = false, EmitDefaultValue = false, Order = 21)]
public bool SuppressNonceValidationErrors { get; set; }
/// <summary>
/// The type of Configuration (deprecated or not)
/// </summary>
public bool IsDeprecatedConfiguration { get; set; }
private CertificateIdentifierCollection m_applicationCertificates;
private CertificateTrustList m_trustedIssuerCertificates;
private CertificateTrustList m_trustedPeerCertificates;
private CertificateTrustList m_httpsIssuerCertificates;
private CertificateTrustList m_trustedHttpsCertificates;
private CertificateTrustList m_userIssuerCertificates;
private CertificateTrustList m_trustedUserCertificates;
}
/// <summary>
/// A class that defines a group of sampling rates supported by the server.
/// </summary>
[DataContract(Namespace = Namespaces.OpcUaConfig)]
public class SamplingRateGroup
{
/// <summary>
/// The default constructor.
/// </summary>
public SamplingRateGroup()
{
Initialize();
}
/// <summary>
/// Creates a group with the specified settings.
/// </summary>
/// <param name="start">The start.</param>
/// <param name="increment">The increment.</param>
/// <param name="count">The count.</param>
public SamplingRateGroup(int start, int increment, int count)
{
Start = start;
Increment = increment;
Count = count;
}
/// <summary>
/// Sets private members to default values.
/// </summary>
private void Initialize()
{