using System.Security.Cryptography.X509Certificates;
namespace dk.nsi.seal.Federation
{
public abstract class Federation
{
public ICertificationAuthority CertificationAuthority { get; }
/**
* Construct an instance of Federation
*
* @param certificationAuthority the CA used in the federation
*/
protected Federation(ICertificationAuthority certificationAuthority) => CertificationAuthority = certificationAuthority;
/**
* Returns true if the passed certificate is a valid certificate issued to the STS of the federation and false
* otherwise.
*
* @param certificate
* the certificate to check.
*/
public bool IsValidSTSCertificate(X509Certificate2 certificate) =>
SubjectDistinguishedNameMatches(new Oces3DistinguishedName(certificate.Subject)) && CertificationAuthority.IsValid(certificate);
/**
* Returns true if the passed subjectDistinguishedName matches an STS of the federation and false
* otherwise.
*
* @param subjectDistinguishedName
* the subjectDistinguishedName to check.
*/
protected abstract bool SubjectDistinguishedNameMatches(Oces3DistinguishedName subjectDistinguishedName);
/**
* Returns true if the passed certificate is a valid certificate issued by the CA of the federation and false
* otherwise.
*
* @param certificate
* the certificate to check.
*/
public bool IsValidCertificate(X509Certificate2 certificate) => CertificationAuthority.IsValid(certificate);
/**
* Returns a combined result containing the result of a corresponding isValidCertificate call and the timestamp
* for the revocation check involved.
*
* @param certificate to be checked.
* @return the combined result.
*/
public CertificateStatus GetCertificateStatus(X509Certificate2 certificate)
{
return CertificationAuthority.GetCertificateStatus(certificate);
}
}
}