diff --git a/Libraries/Opc.Ua.Gds.Server.Common/CertificateGroup.cs b/Libraries/Opc.Ua.Gds.Server.Common/CertificateGroup.cs index 46560e4165..292273bdf2 100644 --- a/Libraries/Opc.Ua.Gds.Server.Common/CertificateGroup.cs +++ b/Libraries/Opc.Ua.Gds.Server.Common/CertificateGroup.cs @@ -286,6 +286,16 @@ public virtual async Task CreateCACertificateAsync( string subjectName ) { + // validate new subjectName matches the previous subject + // TODO: An issuer may modify the subject of the CA certificate, + // but then the configuration must be updated too! + // NOTE: not a strict requirement here for ASN.1 byte compare + if (!X509Utils.CompareDistinguishedName(subjectName, SubjectName)) + { + throw new ArgumentException("SubjectName provided does not match the SubjectName property of the CertificateGroup \n" + + "CA Certificate is not created until the subjectName " + SubjectName + " is provided", subjectName); + } + DateTime yesterday = DateTime.Today.AddDays(-1); X509Certificate2 newCertificate = CertificateFactory.CreateCertificate(subjectName) .SetNotBefore(yesterday)