Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are developing an Azure webjob that needs to communicate to several servers, each one of them demanding a separate SSL connection. We have our certificates stored in an external server and load them at runtime together with the corresponding SSL connection settings. When we invoke the X509Certificate2 constructor in order to add it to the X509CertificateCollection, the webjob gets stopped with exit code -1073740940 and its status becomes "PendingRestart". Our guess is that the X509Certificate2 class is not compatible with webjobs, but we cannot find any hint on how to tackle this issue.

C#
private X509CertificateCollection GetClientCertificates(byte[] sslCertificateBytes)
            {
                log_?.OnEvent($"{nameof(SSLStreamFactory)} function {nameof(GetClientCertificates)} started");
                X509CertificateCollection result = new X509Certificate2Collection();
                log_?.OnEvent($"{nameof(X509CertificateCollection)} {nameof(result)} construction successfull");
                try
                {
                    if (sslCertificateBytes != null)
                    {
                        log_?.OnEvent($"{nameof(sslCertificateBytes)}  enumerable != null");
                        result.Add(new X509Certificate2(sslCertificateBytes, socketSettings_.CertificatePassword));
                        log_?.OnEvent($"result.Add successful");
                    }
                    else if (!string.IsNullOrEmpty(socketSettings_.CertificatePath))
                    {
                        log_?.OnEvent($"{nameof(socketSettings_.CertificatePath)} != null");
                        result = new X509Certificate2Collection();
                        log_?.OnEvent($"{nameof(X509CertificateCollection)} {nameof(result)} construction successfull");
                        var clientCert = StreamFactory.LoadCertificate(socketSettings_.CertificatePath, socketSettings_.CertificatePassword, log_);
                        log_?.OnEvent($"{nameof(StreamFactory.LoadCertificate)} function ended");
                        if (clientCert != null)
                        {
                            result.Add(clientCert);
                            log_?.OnEvent($"result.Add successful");
                        }
                    }
                }
                catch (Exception ex)
                {
                    log_?.OnEvent($"{nameof(SSLStreamFactory)} function {nameof(GetClientCertificates)} raised exception: {ex.Message}");
                    throw;
                }
                log_?.OnEvent($"{nameof(SSLStreamFactory)} function {nameof(GetClientCertificates)} ended");
                return result;
            }


What I have tried:

We are looking for an answer in the internet without any result.
Posted
Updated 24-Mar-17 4:27am

1 solution

This article explains how to do it:


[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900