Skip to content

Change report from Azbil Corporation. #2991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Stack/Opc.Ua.Core/Security/Certificates/CertificateIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,61 @@ public async Task<X509Certificate2> Find(bool needPrivateKey, string application
return certificate;
}

/// <summary>
/// Azbil: Finds a certificate within the validity period in a store.
/// </summary>
/// <remarks>The certificate type is used to match the signature and public key type. And check also validity period.</remarks>
/// <param name="needPrivateKey">if set to <c>true</c> the returned certificate must contain the private key.</param>
/// <param name="dateTime">The time to check the validity period.</param>
/// <returns>An instance of the <see cref="X509Certificate2"/> that is embedded by this instance or find it in
/// the selected store pointed out by the <see cref="StorePath"/> using selected <see cref="SubjectName"/> or if specified applicationUri.</returns>
public async Task<X509Certificate2> Find(bool needPrivateKey, DateTime dateTime)
{
X509Certificate2 certificate = null;

// check if the entire certificate has been specified.
if (m_certificate != null && (!needPrivateKey || m_certificate.HasPrivateKey))
{
certificate = m_certificate;
}
else
{
// open store.
using (ICertificateStore store = CertificateStoreIdentifier.CreateStore(StoreType))
{
store.Open(StorePath);

X509Certificate2Collection collection = await store.Enumerate().ConfigureAwait(false);

certificate = Find(collection, m_thumbprint, m_subjectName, needPrivateKey);

if (certificate != null)
{
if (certificate.NotBefore <= dateTime
&& dateTime <= certificate.NotAfter)
{
m_certificate = certificate;

if (needPrivateKey && this.StoreType == CertificateStoreType.Directory)
{
var message = new StringBuilder();
message.AppendLine("Loaded a certificate with private key from the directory store.");
Utils.Trace(Utils.TraceMasks.Information, message.ToString());
}
}
}
}
}

// use the single instance in the certificate cache.
if (needPrivateKey)
{
certificate = m_certificate = CertificateFactory.Load(certificate, true);
}

return certificate;
}

/// <summary>
/// Returns a display name for a certificate.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Stack/Opc.Ua.Core/Types/Encoders/BinaryEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ public void WriteString(string fieldName, string value)
/// </summary>
public void WriteDateTime(string fieldName, DateTime value)
{
value = Utils.ToOpcUaUniversalTime(value);
// Azbil: Comment out the line below to unify the time zone of DateTime handled in requests and responses to UTC.
//value = Utils.ToOpcUaUniversalTime(value);

Copy link
Contributor

@mregen mregen Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should not be removed. It makes sure only UTC normalized timestamps are sent over the wire. If there is a timestamp off, there is maybe an application error, that a DateTime is created without Utc kind.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment. I understand that my coding regarding DateTime class was insufficient. I agree.

long ticks = value.Ticks;

Expand Down