Provide the ability to configure security with a X509Certificate object

Apr 23, 2012 at 2:10 PM
Edited Apr 23, 2012 at 2:12 PM

Hi,

We configure the server in code using the CertificateConfig object. This object only allows for a FilePath configuration. 

We've extended CertificateConfig with the following property:

 

    X509Certificate Certificate { get; }

And change CertificateManager to look like this:

 

internal static X509Certificate Initialize(ICertificateConfig cerConfig)
        {
            X509Certificate cert;

            //Handle a certificate from the store first
            if (cerConfig.Certificate == null)
            {
                //To keep compatible with website hosting
                string filePath;

                if (Path.IsPathRooted(cerConfig.FilePath))
                    filePath = cerConfig.FilePath;
                else
                {
                    filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, cerConfig.FilePath);
                }

                cert = new X509Certificate2(filePath, cerConfig.Password);
                
            }
            else
            {
                cert=  cerConfig.Certificate;
            }

            return cert;
        }

 

 

However, I think it would be better that SuperSocket did it out of the box.

What do you think?

Thanks

Coordinator
Apr 23, 2012 at 2:14 PM

In v1.5, SuperSocket will provide the function loading certificate from certificate store instead.

Coordinator
Apr 23, 2012 at 2:37 PM

I did an improvement just now, you can override the new created protected method GetCertificate() in AppServer class to provide your own certificate.

http://supersocket.codeplex.com/SourceControl/changeset/changes/76675#mainline%2fSocketBase%2fAppServerBase.cs