WildernessLabs / Netduino_SDK

32 stars 21 forks source link

SSL Doesn't Work #2

Open bryancostanich opened 7 years ago

bryancostanich commented 7 years ago

Seems to be a cert issue.

https://blog.devmobile.co.nz/2015/07/21/netduino-3-wifi-azure-service-bus-client-certificate-issue/

bryancostanich commented 7 years ago

Repro:

using System;
using System.Net;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Net.NetworkInformation;

namespace devMobile.N3WifiCertQuery
{
   public class Program
   {
      public static void Main()
      {
         // Wait for Network address if DHCP
         NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
         if (networkInterface.IsDhcpEnabled)
         {
            Debug.Print(" Waiting for IP address ");
            while (NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress == IPAddress.Any.ToString())
            {
               Debug.Print(".");
               Thread.Sleep(250);
            }
         }

         // Display network config for debugging
         Debug.Print("Network configuration");
         Debug.Print(" Network interface type: " + networkInterface.NetworkInterfaceType.ToString());
         Debug.Print(" MAC Address: " + BytesToHexString(networkInterface.PhysicalAddress));
         Debug.Print(" DHCP enabled: " + networkInterface.IsDhcpEnabled.ToString());
         Debug.Print(" Dynamic DNS enabled: " + networkInterface.IsDynamicDnsEnabled.ToString());
         Debug.Print(" IP Address: " + networkInterface.IPAddress.ToString());
         Debug.Print(" Subnet Mask: " + networkInterface.SubnetMask.ToString());
         Debug.Print(" Gateway: " + networkInterface.GatewayAddress.ToString());

         foreach (string dnsAddress in networkInterface.DnsAddresses)
         {
            Debug.Print(" DNS Server: " + dnsAddress.ToString());
         }
         Debug.Print("");

         /* 
           Baseline check with google
           GeoTrust Global -> Google Internet Authority G2
         */
         Debug.Print("https://www.google.co.nz");
         try
         {
            using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://www.google.co.nz"))
            {
               request.Method = "GET";
               request.KeepAlive = false;
               request.Timeout = 5000;
               request.ReadWriteTimeout = 5000;
               request.KeepAlive = false;

               using (var response = (HttpWebResponse)request.GetResponse())
               {
                  Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
               }
               Debug.Print("Success");
            }
         }
         catch (Exception ex)
         {
            Debug.Print(ex.ToString());
         }

         /* 
          * Go Daddy Class2 certication authority->Go Daddy root certificate authority G2-> Go Daddy Secure certificate authority G2 
         DNS Name=*.wordpress.com
         DNS Name=wordpress.com
         */
         Debug.Print("https://wordpress.wordpress.com/");
         try
         {
            using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://wordpress.wordpress.com/"))
            {
               //request.Proxy = proxy; 
               request.Method = "GET";
               request.KeepAlive = false;
               request.Timeout = 5000;
               request.ReadWriteTimeout = 5000;
               request.KeepAlive = false;

               using (var response = (HttpWebResponse)request.GetResponse())
               {
                  Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
               }
               Debug.Print("Success");
            }
         }
         catch (Exception ex)
         {
            Debug.Print(ex.ToString());
         }

         /*
         Digicert Baltimore -> Microsoft IT SSL SHA2
          * 
         DNS Name=*.servicebus.windows.net
         DNS Name=servicebus.windows.net
         */
         Debug.Print(@"https://orchardtelemetry.servicebus.windows.net/");
         try
         {
            using (HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://orchardtelemetry.servicebus.windows.net/"))
            {
               //request.Proxy = proxy; 
               request.Method = "GET";
               request.KeepAlive = false;
               request.Timeout = 5000;
               request.ReadWriteTimeout = 5000;
               request.KeepAlive = false;

               using (var response = (HttpWebResponse)request.GetResponse())
               {
                  Debug.Print("HTTP Status:" + response.StatusCode + " : " + response.StatusDescription);
               }
               Debug.Print("Success");
            }
         }
         catch (Exception ex)
         {
            Debug.Print( ex.ToString());
         }
      }

      public static string BytesToHexString(byte[] bytes)
      {
         string hexString = string.Empty;

         // Create a character array for hexidecimal conversion.
         const string hexChars = "0123456789ABCDEF";

         // Loop through the bytes.
         for (byte b = 0; b < bytes.Length; b++)
         {
            if (b > 0)
               hexString += "-";

            // Grab the top 4 bits and append the hex equivalent to the return string.        
            hexString += hexChars[bytes[b] >> 4];

            // Mask off the upper 4 bits to get the rest of it.
            hexString += hexChars[bytes[b] & 0x0F];
         }

         return hexString;
      }
   }
}