public static SelfSignedCertificate Create(string name, string password, DateTime start, DateTime expire, string containerName)
 {
     SelfSignedCertificate certificate = new SelfSignedCertificate(password, containerName);
     certificate.GenerateKeys();
     certificate.CreateCertContext(name, start, expire);
     certificate.GetX509Certificate();
     return certificate;
 }
        public static SelfSignedCertificate Create(string name, string password, DateTime start, DateTime expire, string containerName)
        {
            SelfSignedCertificate certificate = new SelfSignedCertificate(password, containerName);

            certificate.GenerateKeys();
            certificate.CreateCertContext(name, start, expire);
            certificate.GetX509Certificate();
            return(certificate);
        }
            public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
            {
                ServiceModelSecurityTokenRequirement requirement = tokenRequirement as ServiceModelSecurityTokenRequirement;

                if (requirement == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenRequirement");
                }
                if (this.IsX509TokenRequirement(requirement))
                {
                    X509CertificateValidator validator;
                    if (this.IsForConnectionValidator(requirement))
                    {
                        SecurityTokenProvider provider = null;
                        if (this.ssc != null)
                        {
                            provider = new X509SecurityTokenProvider(this.ssc.GetX509Certificate());
                        }
                        else if (this.delegateManager != null)
                        {
                            requirement.Properties[SecurityTokenRequirement.PeerAuthenticationMode] = SecurityMode.Transport;
                            requirement.TransportScheme = "net.p2p";
                            provider = this.delegateManager.CreateSecurityTokenProvider(tokenRequirement);
                        }
                        else if (this.credential.Certificate != null)
                        {
                            provider = new X509SecurityTokenProvider(this.credential.Certificate);
                        }
                        if ((provider == null) && (this.mode == PeerAuthenticationMode.Password))
                        {
                            this.ssc = this.parent.GetCertificate();
                            provider = new X509SecurityTokenProvider(this.ssc.GetX509Certificate());
                        }
                        return(provider);
                    }
                    if (this.delegateManager != null)
                    {
                        requirement.TransportScheme = "net.p2p";
                        requirement.Properties[SecurityTokenRequirement.PeerAuthenticationMode] = SecurityMode.Message;
                        return(this.delegateManager.CreateSecurityTokenProvider(tokenRequirement));
                    }
                    if (!this.credential.MessageSenderAuthentication.TryGetCertificateValidator(out validator))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("TokenType");
                    }
                    return(new PeerX509TokenProvider(validator, this.credential.Certificate));
                }
                if (!this.IsPasswordTokenRequirement(requirement))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("TokenType");
                }
                return(this.GetPasswordTokenProvider());
            }
Exemplo n.º 4
0
 internal SelfSignedCertificate GetCertificate()
 {
     if (this.ssc == null)
     {
         lock (ThisLock)
         {
             if (ssc == null)
             {
                 ssc = SelfSignedCertificate.Create("CN=" + Guid.NewGuid().ToString(), this.Password);
             }
         }
     }
     return(ssc);
 }
 public static SelfSignedCertificate Create(
                             string name,
                             string password,
                             DateTime start,
                             DateTime expire,
                             string containerName)
 {
     SelfSignedCertificate cert = new SelfSignedCertificate(password, containerName);
     cert.GenerateKeys();
     cert.CreateCertContext(name, start, expire);
     cert.GetX509Certificate();
     Fx.Assert(cert.cert != null, "CertContext could not be created");
     return cert;
 }
        public static SelfSignedCertificate Create(
            string name,
            string password,
            DateTime start,
            DateTime expire,
            string containerName)
        {
            SelfSignedCertificate cert = new SelfSignedCertificate(password, containerName);

            cert.GenerateKeys();
            cert.CreateCertContext(name, start, expire);
            cert.GetX509Certificate();
            Fx.Assert(cert.cert != null, "CertContext could not be created");
            return(cert);
        }
 public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
 {
     ServiceModelSecurityTokenRequirement requirement = tokenRequirement as ServiceModelSecurityTokenRequirement;
     if (requirement == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenRequirement");
     }
     if (this.IsX509TokenRequirement(requirement))
     {
         X509CertificateValidator validator;
         if (this.IsForConnectionValidator(requirement))
         {
             SecurityTokenProvider provider = null;
             if (this.ssc != null)
             {
                 provider = new X509SecurityTokenProvider(this.ssc.GetX509Certificate());
             }
             else if (this.delegateManager != null)
             {
                 requirement.Properties[SecurityTokenRequirement.PeerAuthenticationMode] = SecurityMode.Transport;
                 requirement.TransportScheme = "net.p2p";
                 provider = this.delegateManager.CreateSecurityTokenProvider(tokenRequirement);
             }
             else if (this.credential.Certificate != null)
             {
                 provider = new X509SecurityTokenProvider(this.credential.Certificate);
             }
             if ((provider == null) && (this.mode == PeerAuthenticationMode.Password))
             {
                 this.ssc = this.parent.GetCertificate();
                 provider = new X509SecurityTokenProvider(this.ssc.GetX509Certificate());
             }
             return provider;
         }
         if (this.delegateManager != null)
         {
             requirement.TransportScheme = "net.p2p";
             requirement.Properties[SecurityTokenRequirement.PeerAuthenticationMode] = SecurityMode.Message;
             return this.delegateManager.CreateSecurityTokenProvider(tokenRequirement);
         }
         if (!this.credential.MessageSenderAuthentication.TryGetCertificateValidator(out validator))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("TokenType");
         }
         return new PeerX509TokenProvider(validator, this.credential.Certificate);
     }
     if (!this.IsPasswordTokenRequirement(requirement))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("TokenType");
     }
     return this.GetPasswordTokenProvider();
 }