Skip to content

Commit 9880ba2

Browse files
authored
Merge pull request #2025 from OPCFoundation/master
Merge master in release/1.4.371
2 parents 4d30ccb + ed8f07b commit 9880ba2

File tree

27 files changed

+577
-65
lines changed

27 files changed

+577
-65
lines changed

.github/workflows/buildandtest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ jobs:
4040
dotnet-version: ${{ matrix.dotnet-version }}
4141

4242
- name: Build
43-
run: dotnet build --force --framework ${{ matrix.framework }} --configuration ${{ matrix.configuration }} "UA Core Library.sln"
43+
run: dotnet build "UA Core Library.sln" --force --framework ${{ matrix.framework }} --configuration ${{ matrix.configuration }}
4444

4545
- name: Test
4646
# note: /p:CollectCoverage=true is only used to disable deterministc builds
47-
run: dotnet test --no-build --framework ${{ matrix.framework }} --logger trx --configuration ${{ matrix.configuration }} /p:CollectCoverage=true --collect:"XPlat Code Coverage" --settings ./Tests/coverlet.runsettings.xml --results-directory "TestResults-${{matrix.os}}-${{matrix.framework}}-${{matrix.configuration}}" "UA Core Library.sln"
47+
run: dotnet test "UA Core Library.sln" --no-build --framework ${{ matrix.framework }} --logger trx --configuration ${{ matrix.configuration }} /p:CollectCoverage=true --collect:"XPlat Code Coverage" --settings ./Tests/coverlet.runsettings.xml --results-directory "TestResults-${{matrix.os}}-${{matrix.framework}}-${{matrix.configuration}}"
4848

4949
- name: Upload test results
5050
uses: actions/upload-artifact@v3

Libraries/Opc.Ua.Client.ComplexTypes/TypeBuilder/AttributeExtensions.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static void StructureFieldAttribute(
158158

159159
// only unambigious built in types get the info,
160160
// IEncodeable types are handled by type property as BuiltInType.Null
161-
Int32 builtInType = (Int32)TypeInfo.GetBuiltInType(structureField.DataType);
161+
Int32 builtInType = (Int32)GetBuiltInType(structureField.DataType);
162162
if (builtInType > (Int32)BuiltInType.Null)
163163
{
164164
pi.Add(attributeType.GetProperty("BuiltInType"));
@@ -243,6 +243,50 @@ private static CustomAttributeBuilder DataContractAttributeBuilder(string Namesp
243243
});
244244
return builder;
245245
}
246+
247+
/// <summary>
248+
/// Convert a DataTypeId to a BuiltInType that can be used
249+
/// for the switch table in <see cref="BaseComplexType"/>.
250+
/// </summary>
251+
/// <remarks>
252+
/// As a prerequisite the complex type resolver found a
253+
/// valid .NET supertype that can be mapped to a BuiltInType.
254+
/// IEncodeable types are mapped to BuiltInType.Null.
255+
/// </remarks>
256+
/// <param name="datatypeId">The data type identifier.</param>
257+
/// <returns>An <see cref="BuiltInType"/> for <paramref name="datatypeId"/></returns>
258+
private static BuiltInType GetBuiltInType(NodeId datatypeId)
259+
{
260+
if (datatypeId.IsNullNodeId || datatypeId.NamespaceIndex != 0 ||
261+
datatypeId.IdType != Opc.Ua.IdType.Numeric)
262+
{
263+
return BuiltInType.Null;
264+
}
265+
266+
BuiltInType builtInType = (BuiltInType)Enum.ToObject(typeof(BuiltInType), datatypeId.Identifier);
267+
268+
if (builtInType <= BuiltInType.DiagnosticInfo || builtInType == BuiltInType.Enumeration)
269+
{
270+
return builtInType;
271+
}
272+
273+
// The special case is the internal treatment of Number, Integer and
274+
// UInteger types which are mapped to Variant, but they have an internal
275+
// representation in the BuiltInType enum, hence it needs the special handling
276+
// here to return the BuiltInType.Variant.
277+
// Other DataTypes which map directly to .NET types in
278+
// <see cref="TypeInfo.GetSystemType(BuiltInType, int)"/>
279+
// are handled in <see cref="TypeInfo.GetBuiltInType()"/>
280+
switch ((uint)builtInType)
281+
{
282+
// supertypes of numbers
283+
case DataTypes.Integer:
284+
case DataTypes.UInteger:
285+
case DataTypes.Number: return BuiltInType.Variant;
286+
}
287+
288+
return TypeInfo.GetBuiltInType(datatypeId);
289+
}
246290
#endregion Private Static Members
247291

248292
}

Libraries/Opc.Ua.Client.ComplexTypes/Types/BaseComplexType.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ private void EncodeProperty(IEncoder encoder, string name, PropertyInfo property
439439
case BuiltInType.Byte: encoder.WriteByte(name, (Byte)property.GetValue(this)); break;
440440
case BuiltInType.Int16: encoder.WriteInt16(name, (Int16)property.GetValue(this)); break;
441441
case BuiltInType.UInt16: encoder.WriteUInt16(name, (UInt16)property.GetValue(this)); break;
442-
case BuiltInType.Enumeration: encoder.WriteEnumerated(name, (Enum)property.GetValue(this)); break;
443442
case BuiltInType.Int32: encoder.WriteInt32(name, (Int32)property.GetValue(this)); break;
444443
case BuiltInType.UInt32: encoder.WriteUInt32(name, (UInt32)property.GetValue(this)); break;
445444
case BuiltInType.Int64: encoder.WriteInt64(name, (Int64)property.GetValue(this)); break;
@@ -460,6 +459,13 @@ private void EncodeProperty(IEncoder encoder, string name, PropertyInfo property
460459
case BuiltInType.DataValue: encoder.WriteDataValue(name, (DataValue)property.GetValue(this)); break;
461460
case BuiltInType.Variant: encoder.WriteVariant(name, (Variant)property.GetValue(this)); break;
462461
case BuiltInType.ExtensionObject: encoder.WriteExtensionObject(name, (ExtensionObject)property.GetValue(this)); break;
462+
case BuiltInType.Enumeration:
463+
if (propertyType.IsEnum)
464+
{
465+
encoder.WriteEnumerated(name, (Enum)property.GetValue(this));
466+
break;
467+
}
468+
goto case BuiltInType.Int32;
463469
default:
464470
if (typeof(IEncodeable).IsAssignableFrom(propertyType))
465471
{
@@ -535,7 +541,6 @@ private void DecodeProperty(IDecoder decoder, string name, PropertyInfo property
535541
case BuiltInType.Byte: property.SetValue(this, decoder.ReadByte(name)); break;
536542
case BuiltInType.Int16: property.SetValue(this, decoder.ReadInt16(name)); break;
537543
case BuiltInType.UInt16: property.SetValue(this, decoder.ReadUInt16(name)); break;
538-
case BuiltInType.Enumeration: property.SetValue(this, decoder.ReadEnumerated(name, propertyType)); break;
539544
case BuiltInType.Int32: property.SetValue(this, decoder.ReadInt32(name)); break;
540545
case BuiltInType.UInt32: property.SetValue(this, decoder.ReadUInt32(name)); break;
541546
case BuiltInType.Int64: property.SetValue(this, decoder.ReadInt64(name)); break;
@@ -563,6 +568,12 @@ private void DecodeProperty(IDecoder decoder, string name, PropertyInfo property
563568
}
564569
property.SetValue(this, decoder.ReadExtensionObject(name));
565570
break;
571+
case BuiltInType.Enumeration:
572+
if (propertyType.IsEnum)
573+
{
574+
property.SetValue(this, decoder.ReadEnumerated(name, propertyType)); break;
575+
}
576+
goto case BuiltInType.Int32;
566577
default:
567578
if (typeof(IEncodeable).IsAssignableFrom(propertyType))
568579
{

Libraries/Opc.Ua.Client/INodeCache.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public interface INodeCache : INodeTable, ITypeTable
5252
/// </summary>
5353
Node FetchNode(ExpandedNodeId nodeId);
5454

55+
/// <summary>
56+
/// Finds a set of nodes in the nodeset,
57+
/// fetches missing nodes from server.
58+
/// </summary>
59+
/// <param name="nodeIds">The node identifier collection.</param>
60+
IList<INode> Find(IList<ExpandedNodeId> nodeIds);
61+
5562
/// <summary>
5663
/// Fetches a node collection from the server and updates the cache.
5764
/// </summary>

Libraries/Opc.Ua.Client/NodeCache.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ public INode Find(ExpandedNodeId nodeId)
104104
}
105105
}
106106

107-
/// <summary>
108-
/// Finds a set of nodes in the nodeset,
109-
/// fetches missing nodes from server.
110-
/// </summary>
111-
/// <param name="nodeIds">The node identifier collection.</param>
107+
/// <inheritdoc/>
112108
public IList<INode> Find(IList<ExpandedNodeId> nodeIds)
113109
{
114110
// check for null.
@@ -650,6 +646,11 @@ public Node FetchNode(ExpandedNodeId nodeId)
650646
public IList<Node> FetchNodes(IList<ExpandedNodeId> nodeIds)
651647
{
652648
int count = nodeIds.Count;
649+
if (count == 0)
650+
{
651+
return new List<Node>();
652+
}
653+
653654
NodeIdCollection localIds = new NodeIdCollection(
654655
nodeIds.Select(nodeId => ExpandedNodeId.ToNodeId(nodeId, m_session.NamespaceUris)));
655656

@@ -770,6 +771,11 @@ public IList<INode> FindReferences(
770771
bool isInverse,
771772
bool includeSubtypes)
772773
{
774+
IList<INode> targets = new List<INode>();
775+
if (nodeIds.Count == 0 || referenceTypeIds.Count == 0)
776+
{
777+
return targets;
778+
}
773779
ExpandedNodeIdCollection targetIds = new ExpandedNodeIdCollection();
774780
IList<INode> sources = Find(nodeIds);
775781
foreach (INode source in sources)
@@ -792,7 +798,6 @@ public IList<INode> FindReferences(
792798
}
793799
}
794800

795-
IList<INode> targets = new List<INode>();
796801
IList<INode> result = Find(targetIds);
797802
foreach (INode target in result)
798803
{

Libraries/Opc.Ua.Configuration/ApplicationConfigurationBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ public IApplicationConfigurationBuilderServerSelected AddUnsecurePolicyNone(bool
247247
{
248248
if (addPolicy)
249249
{
250-
AddSecurityPolicies(false, false, true);
250+
var policies = ApplicationConfiguration.ServerConfiguration.SecurityPolicies;
251+
InternalAddPolicy(policies, MessageSecurityMode.None, SecurityPolicies.None);
251252
}
252253
return this;
253254
}

Libraries/Opc.Ua.Gds.Client.Common/GlobalDiscoveryServerClient.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void Disconnect()
318318
if (Session != null)
319319
{
320320
KeepAlive?.Invoke(Session, null);
321-
Session.Close();
321+
Session?.Close();
322322
Session = null;
323323
}
324324
}
@@ -334,8 +334,7 @@ private void Session_KeepAlive(ISession session, KeepAliveEventArgs e)
334334

335335
private void Session_SessionClosing(object sender, EventArgs e)
336336
{
337-
Session.Dispose();
338-
Session = null;
337+
Utils.LogInfo("The GDS Client session is closing.");
339338
}
340339

341340
/// <summary>

Libraries/Opc.Ua.Gds.Server.Common/CertificateGroup.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,13 @@ public virtual async Task<X509Certificate2> SigningRequestAsync(
256256
domainNames = domainNameList.ToArray();
257257
}
258258
}
259-
259+
260260
DateTime yesterday = DateTime.Today.AddDays(-1);
261261
using (var signingKey = await LoadSigningKeyAsync(Certificate, string.Empty).ConfigureAwait(false))
262262
{
263-
return CertificateFactory.CreateCertificate(
264-
application.ApplicationUri,
265-
null,
266-
info.Subject.ToString(true, (IDictionary)Org.BouncyCastle.Asn1.X509.X509Name.DefaultSymbols),
267-
domainNames)
263+
X500DistinguishedName subjectName = new X500DistinguishedName(info.Subject.GetEncoded());
264+
return CertificateBuilder.Create(subjectName)
265+
.AddExtension(new X509SubjectAltNameExtension(application.ApplicationUri, domainNames))
268266
.SetNotBefore(yesterday)
269267
.SetLifeTime(Configuration.DefaultCertificateLifetime)
270268
.SetHashAlgorithm(X509Utils.GetRSAHashAlgorithmName(Configuration.DefaultCertificateHashSize))

Libraries/Opc.Ua.Security.Certificates/Extensions/X509AuthorityKeyIdentifierExtension.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ byte[] subjectKeyIdentifier
9494
/// <summary>
9595
/// Build the X509 Authority Key extension.
9696
/// </summary>
97+
/// <remarks>
98+
/// A null value for one of the parameters indicates that the optional
99+
/// identifier can be ignored. Only keyId should be used for PKI use.
100+
/// </remarks>
97101
/// <param name="subjectKeyIdentifier">The subject key identifier as a byte array.</param>
98102
/// <param name="authorityName">The distinguished name of the issuer.</param>
99103
/// <param name="serialNumber">The serial number of the issuer certificate as little endian byte array.</param>
@@ -103,9 +107,6 @@ public X509AuthorityKeyIdentifierExtension(
103107
byte[] serialNumber
104108
)
105109
{
106-
if (subjectKeyIdentifier == null) throw new ArgumentNullException(nameof(subjectKeyIdentifier));
107-
if (authorityName == null) throw new ArgumentNullException(nameof(authorityName));
108-
if (serialNumber == null) throw new ArgumentNullException(nameof(serialNumber));
109110
m_issuer = authorityName;
110111
m_keyIdentifier = subjectKeyIdentifier;
111112
m_serialNumber = serialNumber;

Libraries/Opc.Ua.Security.Certificates/Org.BouncyCastle/CertificateBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public static byte[] CreateSigningRequest(
231231

232232
var pkcs10CertificationRequest = new Pkcs10CertificationRequest(
233233
signatureFactory,
234-
new CertificateFactoryX509Name(true, certificate.Subject),
234+
new CertificateFactoryX509Name(certificate.SubjectName),
235235
publicKey,
236236
attributes);
237237

@@ -262,14 +262,14 @@ private void CreateDefaults(IRandomGenerator random = null)
262262
/// <param name="cg">The cert generator</param>
263263
private void CreateMandatoryFields(X509V3CertificateGenerator cg)
264264
{
265-
m_subjectDN = new CertificateFactoryX509Name(SubjectName.Name);
265+
m_subjectDN = new CertificateFactoryX509Name(SubjectName);
266266
// subject and issuer DN, issuer of issuer for AKI
267267
m_issuerDN = null;
268268
m_issuerIssuerAKI = null;
269269
if (IssuerCAKeyCert != null)
270270
{
271-
m_issuerDN = new CertificateFactoryX509Name(IssuerCAKeyCert.Subject);
272-
m_issuerIssuerAKI = new CertificateFactoryX509Name(IssuerCAKeyCert.Issuer);
271+
m_issuerDN = new CertificateFactoryX509Name(IssuerCAKeyCert.SubjectName);
272+
m_issuerIssuerAKI = new CertificateFactoryX509Name(IssuerCAKeyCert.IssuerName);
273273
}
274274
else
275275
{

0 commit comments

Comments
 (0)