Exception while accessing a HTTPS url

Hi,
I’m trying to write some code to download a binary file from Azure Storage (blob). I’ve grabbed the certificate and added this to the resources as mentioned in the TLS sample code:

        var certificates = TyranntResources.GetBytes(TyranntResources.BinaryResources.msstoragecert);

        X509Certificate[] certx509 = new X509Certificate[] { new X509Certificate(certificates) };
        int read = 0, total = 0;
        byte[] result = new byte[512];
        string resultString = "";

        try
        {
            using (var req = HttpWebRequest.Create(url) as HttpWebRequest)
            {
                req.Method = "GET";
                req.KeepAlive = false;
                req.HttpsAuthentCerts = certx509;
                req.ReadWriteTimeout = 2000;

                using (var res = req.GetResponse() as HttpWebResponse)

When it runs the GetResponse, I get the following exception:

#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####
#### Message: 
#### GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::AuthenticateAsClient [IP: 0000] ####
#### System.Net.Security.SslStream::AuthenticateAsClient [IP: 0016] ####
#### System.Net.Security.SslStream::AuthenticateAsClient [IP: 0009] ####
#### System.Net.Security.SslStream::AuthenticateAsClient [IP: 0008] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 0251] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### TyranntIot.Io.NetworkIo::HTTPGETString [IP: 005b] ####
#### TyranntIot.Game.Setup::GetIcon [IP: 0009] ####
#### TyranntIot.Program::Main [IP: 013f] ####
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message: 
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### TyranntIot.Io.NetworkIo::HTTPGETString [IP: 005b] ####
#### TyranntIot.Game.Setup::GetIcon [IP: 0009] ####
#### TyranntIot.Program::Main [IP: 013f] ####

Exception thrown: ‘System.Net.WebException’ in GHIElectronics.TinyCLR.Networking.Http.dll

I’m assuming that I’ve mucked up something with the certificate. Any ideas?

Thanks,

Jas

I get almost the exact same error when I try to connect to Azure IoT when my Shared Access Signature (SAS) is not correct.
How is your storage account authorized?

@skeller I’ve currently got it set up as anonymous read access. (I can curl the file without any SAS) I think its the https certificate that I’m having a problem with.

On bottom of the page will show you how to get the certificate that needed for TinyCLR.

TLS (ghielectronics.com)

Hi, in my Azure Storage application I used ‘BaltimoreCyberTrustRoot.crt’.
If you don’t find it somewhere on Azure, you can grab it from my application.
[AzureDataSender_SC20260/AzureDataSender_SC20260/Resources at master · -https://github.com/RoSchmi/AzureDataSender_SC20260/tree/master/AzureDataSender_SC20260/Resources

1 Like

Hi @Dat_Tran, Thanks for the help. I’ve pulled the certificate from the blob storage in the browser (Its different now with both Chrome and Edge to the images on that page)
cert

And that is the file I’m using to create the certificate which loads successfully from resources:

    var certificates = TyranntResources.GetBytes(TyranntResources.BinaryResources.msstoragecert);
    X509Certificate[] certx509 = new X509Certificate[] { new X509Certificate(certificates) };

But I still get the error when trying to access the file via https.

Thanks @RoSchmi. I’ve tried with that cert and it now connects.

2 Likes