NotSupportedException when using HTTPS

Hi all!

In the new version of my Text-To-Speech library for .NET Micro Framework, I have implemented the new token based access system as requested by Microsoft Translator Service.

To obtain the token, it is necessary to make a POST request to an HTTPS address. When I try to get the request stream associated with the WebRequest, a NotSupportedException is raised.

Here is the code that causes the issue:


WebRequest webRequest = WebRequest.Create(DatamarketAccessUri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.UTF8.GetBytes(requestDetails);
webRequest.ContentLength = bytes.Length;
 
using (Stream outputStream = webRequest.GetRequestStream())
       outputStream.Write(bytes, 0, bytes.Length);

DatamarketAccessUri is “https://datamarket.accesscontrol.windows.net/v2/OAuth2-13”.

Could anyone help me solve the problem?

Thanks in advance.

What device?

FEZ Spider, firmware 4.1.8.0 and the last version of SDK (downloaded today).

Using SSL required you to go in mfdeploy and update the seed IIRC

Could you tell me how to perform this update?

Thank you very much!

Hi!

I have tried with this command of MFDeploy:

Target->Manage Device Keys->Update SSL Seed function.

But I’m still getting the NotSupportedException:


 #### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (8) ####

    #### 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: 0246] ####
    #### System.Net.HttpWebRequest::SubmitRequest [IP: 0013] ####
    #### System.Net.HttpWebRequest::GetRequestStream [IP: 0008] ####
    #### MicroTranslatorService.Speech.AdmAuthentication::HttpPost [IP: 0027] ####
    #### MicroTranslatorService.Speech.AdmAuthentication::GetAccessToken [IP: 000b] ####
    #### MicroTranslatorService.Speech.SpeechSynthesizer::UpdateToken [IP: 005f] ####
    #### MicroTranslatorService.Speech.SpeechSynthesizer::GetSpeakStream [IP: 0037] ####
    #### MicroTranslatorService.Speech.SpeechThread::GetSpeakBytes [IP: 0013] ####

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

A first chance exception of type 'System.NotSupportedException' occurred in System.Http.dll

There was an error: Exception was thrown: System.NotSupportedException

The thread '<No Name>' (0x8) has exited with code 0 (0x0).

Very strange. I haven’t done much SSL myself do I am not exactly sure.

Hi,

I have a similar problem as Marco.
My fez spider need to connect to my Azure Service Bus over HTTPS by using the REST api of Azure, i made a service identity in my ACS so I can get the token without handling with certificates. But i set the live time of the token to the max live time (9999 sec). Next i made a console application to get these token. It writes the token to a txt file. Next I made a other console application to test if these way is working. Result is my console application to get the message from the service bus (with hard coded token) is working well. But when i do this in my fez spider, I get these “System.NotSupportedException”.

code of my console app thats working well

//make a webclient
WebClient webClient = new WebClient();
//give the token for authorization in the header
webClient.Headers[HttpRequestHeader.Authorization] = token;

string fullAddress = "https://kdgthesis.servicebus.windows.net/robot0" + "/messages/head" + "?timeout=60";

byte[] resp = webClient.UploadData(fullAddress, "DELETE", new byte[0]);
string responseStr = Encoding.UTF8.GetString(resp);
                
Console.WriteLine(responseStr);

and the code that I use in my fez Spider


String serviceBusAddress = "https://kdgthesis.servicebus.windows.net/";
String queueName = "robot0";
...
WebRequest webRequest = WebRequest.Create(serviceBusAddress + queueName + "/messages/head" + "?timeout=60");
webRequest.ContentLength = 0;
webRequest.Headers.Add("Authorization", token);
webRequest.Method = "DELETE";

WebResponse response = webRequest.GetResponse();

Can someone explane or help me?

greets Carlo

Did you “update SSL seed” using MFDeploy?

Yes I did the MFDeploy thing. I also tried the solution of andre.marschalek but with no success. I don’t know how to get the .pem file (certificate). I found something in MFDeploy that creates me a .key. How to use this .key file? Do I need to convert it to a .pem file? Sorry for the questions but i have no experience with certificates or HTTPS.

Is it really necessary to use certificates? Because In ACS I set it to use Password instead of X.509 certificate. Whit that password I create a token and with the token i can send a http request to get a service bus message. Thats the way it goes in my console application. But in my fez spider it just wont work.

thanks for your replay

I intermittently got my SSL calls working by updating the SSL Seed as GUS had said. After the first call or 2 I start getting exceptions. Is there still some bugs with the SSL functionality??? Also, I’m not using a root certification file to validate the legitimacy of the target webserver as I couldn’t get that to work.