Example #1
0
        // Reads the leaf certificate, intermediate certificate and tenancyId from a known location
        protected void AutoDetectCertificatesUsingMetadataUrl()
        {
            logger.Info("Extracting the leaf certificate, tenantId and intermediate certificates");
            if (leafCertificateSupplier == null)
            {
                leafCertificateSupplier = new URLBasedX509CertificateSupplier(
                    GetMetadataResourceDetails(Constants.INSTANCE_CERT),
                    GetMetadataResourceDetails(Constants.PRIVATE_KEY_CERT),
                    null
                    );
                ((URLBasedX509CertificateSupplier)leafCertificateSupplier).Refresh();
            }

            if (String.IsNullOrEmpty(tenancyId))
            {
                tenancyId = AuthUtils.GetTenantIdFromCertificate(leafCertificateSupplier.GetCertificateAndKeyPair().Certificate);
                if (String.IsNullOrEmpty(tenancyId))
                {
                    throw new ArgumentNullException("TenancyId not found in the leaf certificate");
                }
                logger.Info($"Tenancy id is {tenancyId}");
            }

            if (intermediateCertificateSuppliers == null)
            {
                intermediateCertificateSuppliers = new HashSet <IX509CertificateSupplier>();
                var certificate = new URLBasedX509CertificateSupplier(
                    GetMetadataResourceDetails(Constants.INTERMEDIATE_KEY_CERT),
                    null,
                    null
                    );
                certificate.Refresh();
                intermediateCertificateSuppliers.Add(certificate);
            }
        }
 public X509FederationClient(
     string federationEndpoint,
     string tenancyId,
     IX509CertificateSupplier leafCertificateSupplier,
     ISessionKeySupplier sessionKeySupplier,
     HashSet <IX509CertificateSupplier> intermediateCertificateSuppliers)
     : this(
         federationEndpoint,
         tenancyId,
         leafCertificateSupplier,
         sessionKeySupplier,
         intermediateCertificateSuppliers,
         DEFAULT_PURPOSE)
 {
 }
 public X509FederationClient(
     string federationEndpoint,
     string tenancyId,
     IX509CertificateSupplier leafCertificateSupplier,
     ISessionKeySupplier sessionKeySupplier,
     HashSet <IX509CertificateSupplier> intermediateCertificateSuppliers,
     string purpose)
 {
     this.federationEndpoint               = federationEndpoint;
     this.leafCertificateSupplier          = leafCertificateSupplier ?? throw new NullReferenceException();
     this.sessionKeySupplier               = sessionKeySupplier ?? throw new NullReferenceException();
     this.intermediateCertificateSuppliers = intermediateCertificateSuppliers;
     this.tenancyId            = tenancyId ?? throw new NullReferenceException();
     this.securityTokenAdapter = new SecurityTokenAdapter(null);
     this.purpose = purpose ?? throw new NullReferenceException();
 }