2

I'm developing a android app that hosts a web server using the HttpListener class.

But i need to host it using a SSL certificate, I have read somewhere that you need to place the certificate in a special directory on the android device.

But i have lost the link that specified exactly where.

So does any one know how to get HTTPS to work on Xamarin Android with the HttpListener class?

Edit: I have tired to store a .cer and .pvk file under Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".mono", "httplistener") as suggested in HttpListener with HTTPS on MonoTouch but when i try to access the url i get no answer, if i change to http i at least get a answer.

I found the following source code on github, https://github.com/mono/mono/blob/3f779475e3fc982e312212d5dbbd86515eddfc0c/mcs/class/System/System.Net/HttpListener.Mono.cs#L73

But it just eats any exception that occures so there is no way to figure out if anything goes wrong!

Peter
  • 33,550
  • 33
  • 138
  • 185
  • Possible duplicate of [HttpListener with HTTPS on MonoTouch](https://stackoverflow.com/questions/13379963/httplistener-with-https-on-monotouch) – Nicolas Dusart Dec 14 '17 at 08:18
  • @NicolasDusart correct me if im wrong but `MonoTouch` is for iOS not android. – Peter Dec 14 '17 at 08:38
  • 1
    did you ever manage to get it to work? – Nir B. Oct 24 '18 at 14:49
  • I gave up and switched to a web socket server instead. – Peter Oct 24 '18 at 14:50
  • I have recently implemented HTTPListener and allow communication over LAN as well by add firewall rule. There is no any input required, everything is handled by C# code. I have shared full code of the solution here: https://stackoverflow.com/a/58149405/983548 – Habib Sheikh Sep 28 '19 at 21:13

1 Answers1

0

You've not indicated what you're calling the file itself, looking at the mono code for System.Net.HttpListener the file itself must be {port number}.cer, i.e. 443.cer if you were to listen on 443.

string dirname = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string path = Path.Combine(dirname, ".mono");
path = Path.Combine(path, "httplistener");
string cert_file = Path.Combine(path, String.Format("{0}.cer", port));

https://github.com/mono/mono/blob/3f779475e3fc982e312212d5dbbd86515eddfc0c/mcs/class/System/System.Net/HttpListener.Mono.cs#L64

Mark Rawson
  • 116
  • 4