You have reached the legacy GHI Electronics, LLC website, for the new website please visit here. For the new forum please visit here.

You must be logged in to reply.

Page 1 of 3 out of 22 messages.

[Question] Need a working HTTPS WebClient

Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Has anyone managed to get https working with the webclient?
I can get http to work but otherwise no look.

I've tried:
https://www.ghielectronics.com/community/codeshare/entry/614

http://netmftoolbox.codeplex.com/SourceControl/latest#Samples/Visual C#/Web client/Program.cs

I'm using a Fez Spider with an ethernet_JD11 module.

If anyone has any help I would greatly appreciate it.



#edit second link not showing
netmftoolbox.codeplex.com/SourceControl/latest#Samples/Visual C#/Web client/Program.cs
Reply #1 — Posted 4yr ago (modified)
by JPenny1993 | Newbie | 226 exp
Reply #1 — Posted 4yr ago (modified)
by JPenny1993 | Newbie | 226 exp
Thanks for the sample code, but I'm still struggling with https

using the sample code, it gets an exception when trying to get a response in PrintHttpData()

The exception is as follows:
#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####
#### Message:
#### Microsoft.SPOT.Net.Security.SslNative::SecureClientInit [IP: 0000] ####
#### Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0051] ####
#### Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsClient [IP: 000c] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 023d] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0043] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### PrototypeBasestation.wc::getRequest [IP: 0026] ####
#### PrototypeBasestation.Program::timer_Tick [IP: 0017] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type 'System.NotSupportedException' occurred in Microsoft.SPOT.Net.Security.dll
A first chance exception of type 'System.NotSupportedException' occurred in System.Net.Security.dll
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00d3] ####
#### PrototypeBasestation.wc::getRequest [IP: 0026] ####
#### PrototypeBasestation.Program::timer_Tick [IP: 0017] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll


// Root CA Certificate needed to validate HTTPS servers.
            byte[] ca = Resource1.GetBytes(
                Resource1.BinaryResources.VerisignCA);

            X509Certificate[] caCerts =
                new X509Certificate[] { new X509Certificate(ca) };

            // Initialize the default webproxy to be used by all 
            // HttpWebRequests.
            // Change the proxy address to fit your environment.
            HttpWebRequest.DefaultWebProxy = new WebProxy();
                //new WebProxy("itgproxy.dns.microsoft.com", true);

            // Test SSL connection with no certificate verification
            PrintHttpData("https://www.google.com/accounts/ManageAccount/", null);

            // Read from secure webpages by using the Verisign Root CA 
            // certificate that is stored in the Resource1.resx file.
            PrintHttpData("https://www.google.com/accounts/ManageAccount/",
                caCerts);
...

public static void PrintHttpData(string url, X509Certificate[] caCerts)
        {
            // Create an HTTP Web request.
            HttpWebRequest request =
                HttpWebRequest.Create(url) as HttpWebRequest;

            // Assign the certificates. The value must not be null if the
            // connection is HTTPS.
            request.HttpsAuthentCerts = caCerts;

            // Set request.KeepAlive to use a persistent connection. 
            request.KeepAlive = true;

            // Get a response from the server.
            WebResponse resp = null;

            try
            {
                resp = request.GetResponse(); //HTTPS exception occurs here
            }
            catch (Exception e)
            {
                Debug.Print("Exception in HttpWebRequest.GetResponse(): " +
                    e.ToString());
            }
            ...
        }
Reply #2 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Reply #2 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
My board is a Fez Spider with .NetMF v4.2

I'm not sure how to do that.
Reply #3 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Reply #3 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
I don't have fez config, but I do have MFDeploy.
When I try and update ssl its responds:

"Failure - Device {0} is invalid or not responding"
Reply #4 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Reply #4 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Starting to get somewhere.
I uninstalled all the old drivers and installed the latest sdk.
i used fez config to update the firmware and update the ssl.

I now get a webpage response from https with no certificate.

but i get an exception from https with a certificate:

#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.Security.SslNative::SecureConnect [IP: 0000] ####
#### Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0060] ####
#### Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsClient [IP: 000c] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 023d] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0043] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### PrototypeBasestation.WebClient::getRequest [IP: 003e] ####
#### PrototypeBasestation.Program::timer_Tick [IP: 0034] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.Security.dll
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.Net.Security.dll
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
#### PrototypeBasestation.WebClient::getRequest [IP: 003e] ####
#### PrototypeBasestation.Program::timer_Tick [IP: 0034] ####
#### Gadgeteer.Timer::dt_Tick [IP: 0018] ####
#### Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll
Reply #5 — Posted 4yr ago
by James_ghielectroncs | Employee
Reply #5 — Posted 4yr ago
by James_ghielectroncs | Employee
JPenny1993 says:

Starting to get somewhere.
I uninstalled all the old drivers and installed the latest sdk.
i used fez config to update the firmware and update the ssl.

I now get a webpage response from https with no certificate.

but i get an exception from https with a certificate:

Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
Message:
Microsoft.SPOT.Net.Security.SslNative::SecureConnect [IP: 0000] ####
Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0060] ####
Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsClient [IP: 000c] ####
System.Net.HttpWebRequest::EstablishConnection [IP: 023d] ####
System.Net.HttpWebRequest::SubmitRequest [IP: 0043] ####
System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
PrototypeBasestation.WebClient::getRequest [IP: 003e] ####
PrototypeBasestation.Program::timer_Tick [IP: 0034] ####
Gadgeteer.Timer::dt_Tick [IP: 0018] ####
Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
Microsoft.SPOT.Dispatcher: TongueushFrameImpl [IP: 0054] ####
Microsoft.SPOT.Dispatcher: TongueushFrame [IP: 001a] ####
Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
Gadgeteer.Program::Run [IP: 0020] ####
SocketException ErrorCode = 1
SocketException ErrorCode = 1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.Security.dll
SocketException ErrorCode = 1
SocketException ErrorCode = 1
SocketException ErrorCode = 1
SocketException ErrorCode = 1
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.Net.Security.dll
SocketException ErrorCode = 1
SocketException ErrorCode = 1
Exception System.Net.WebException - 0x00000000 (1) ####
Message:
System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
PrototypeBasestation.WebClient::getRequest [IP: 003e] ####
PrototypeBasestation.Program::timer_Tick [IP: 0034] ####
Gadgeteer.Timer::dt_Tick [IP: 0018] ####
Microsoft.SPOT.DispatcherTimer::FireTick [IP: 0010] ####
Microsoft.SPOT.Dispatcher: TongueushFrameImpl [IP: 0054] ####
Microsoft.SPOT.Dispatcher: TongueushFrame [IP: 001a] ####
Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
Gadgeteer.Program::Run [IP: 0020] ####
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll

This type of issue can pop up when using an invalid SSL Cert. The certification they include in the examples expired some months ago if I recall, so you will need to use a certificate other than what is included in Microsoft's SSL example.
Reply #6 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Reply #6 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Okay,
So I tried importing some roots certificate from http://www.symantec.com/page.jsp?id=roots and didn't get anywhere.

Since it's Google in general which I'm wishing to connect to;
I tried using an exported base64format.cer from Google https.
More specifically "GeoTrust Global CA"

I still seem to be getting the same error.

Is there any further instruction you can give me of how to update the certificate?

Thank you.
Reply #7 — Posted 4yr ago
by Brett | Superhuman | 125,590 exp
Reply #7 — Posted 4yr ago
by Brett | Superhuman | 125,590 exp
I don't really understand what you're attempting to do. I'm pretty sure that this is how this works: to access a HTTPS source from your device, you don't need a cert on your device, you would need to verify the cert the server presented was valid.... and if you want to offer an HTTPS connection from a browser to your device you need a valid cert.
Reply #8 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Reply #8 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
ssl isn't something I've done before.

Looking at the sample code provided in
C:\Users\{username}\Documents\Microsoft .NET Micro Framework 4.2\Samples\HttpClient

it has a verisignCA.cer in the resources

at the moment I'm trying to do
// Root CA Certificate needed to validate HTTPS servers.
byte[] ca = Resources.GetBytes(Resources.BinaryResources.VerisignCA);
X509Certificate[] caCerts = new X509Certificate[] { new X509Certificate(ca) };
...

PrintHttpData("https://www.google.com/accounts/ManageAccount/", caCerts);


It fails most likely with the exception I gave previously because the cert is out of date.
I'm now trying to update that cert so that it is valid.

then hopefully it won't crash when it gets to this part of the code
PrintHttpData(string url, X509Certificate[] caCerts )
{
...
   try
   {
      resp = request.GetResponse(); //crashes here with https 
   }
   catch (Exception e)
   {
      Debug.Print(e.Message + "\n");
      Debug.Print("Exception in HttpWebRequest.GetResponse(): " + e.ToString());
    }
...
Reply #9 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
Reply #9 — Posted 4yr ago
by JPenny1993 | Newbie | 226 exp
James says:

JPenny1993 says:
Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
Message:
Microsoft.SPOT.Net.Security.SslNative::SecureConnect [IP: 0000] ####
Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0060] ####
Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsClient [IP: 000c] ####
System.Net.HttpWebRequest::EstablishConnection [IP: 023d] ####
System.Net.HttpWebRequest::SubmitRequest [IP: 0043] ####
System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
...
A first chance exception of type 'System.Net.WebException' occurred in System.Http.dll

This type of issue can pop up when using an invalid SSL Cert. The certification they include in the examples expired some months ago if I recall, so you will need to use a certificate other than what is included in Microsoft's SSL example.

Please can some explain how to do this correctly for a fez spider as I can't seem to get it right.
The SSL Certs seem to work fine when you test the sample with the emulator, but not with my device.

Page 1 of 3 out of 22 messages.

You must be logged in to reply.