Opc.Ua.CertificateValidator.Match C# (CSharp) Method

Match() private method

Returns true if the certificate matches the criteria.
private Match ( X509Certificate2 certificate, string subjectName, string serialNumber, string authorityKeyId ) : bool
certificate System.Security.Cryptography.X509Certificates.X509Certificate2
subjectName string
serialNumber string
authorityKeyId string
return bool
        private bool Match(
            X509Certificate2 certificate,
            string subjectName,
            string serialNumber,
            string authorityKeyId)
        {
            // check for null.
            if (certificate == null)
            {
                return false;
            }

            // check for subject name match.
            if (!Utils.CompareDistinguishedName(certificate.SubjectName.Name, subjectName))
            {
                return false;
            }

            // check for serial number match.
            if (!String.IsNullOrEmpty(serialNumber))
            {
                if (certificate.SerialNumber != serialNumber)
                {
                    return false;
                }
            }

            // check for authority key id match.
            if (!String.IsNullOrEmpty(authorityKeyId))
            {
                X509SubjectKeyIdentifierExtension subjectKeyId = FindSubjectKeyIdentifierExtension(certificate);

                if (subjectKeyId != null)
                {
                    if (subjectKeyId.SubjectKeyIdentifier != authorityKeyId)
                    {
                        return false;
                    }
                }
            }

            // found match.
            return true;
        }