Skip to content

jhalbrecht/XamarinFormsMqttSample

Repository files navigation

Mqtt Sample for Xamarin.forms

Built with PrismLibrary/Prism

See the wiki for documentation.

  • 6/2/2021 Converted from M2MqttDotNetCore to chkr1011/MQTTnet Still using an older version of Xamarin forms. Once a new releas of Uno / Xamarin / Avalonia / Maui releases, the dust settles and I understand a bit I'll update the ui :-) I've striped out many of the old projects as they disract from the intent of this repository MqttChatApp demonstrating mqtt connection including TLS.

  • 3/15/2019 Works on my machine! CA signed server certificate. Tested on iot.eclipse.org and my own letsncrypt secured mosquitto broker.

  • 3/14/2019 Although I've been initally going down a self signed client certificate path, I'm switching my efforts to making the cocnnection on a mosquitto broker secured with a LetsEncrypt certificate or other CA signed server certificate.

  • 2/25/2019 MqttSample retired in favor of MqttChatApp

Why?

There seems to be a real lack of a sample for my specific scenario of connecting a xamarin.forms application to a mosquitto broker in a secure way. There are lot's of examples of unsecured mqtt apps. Many people are running mosquitto brokers unsecured facing the internet. I've begun to take security in my applications seriously.

I'm using this repository to learn how to secure my Xamarin.Forms applications with for example a Let's Encrypt cerfificate. In a real world way!

Goal

Goal of the project is to demonstrate how to secure a XamarinForms app with TLS to connect to a Mosquitto broker.

Learn best practices / real world way(s) to install and use certificates in mobile apps supported by Xamarin.Forms UWP, android and ios

In the headlines

  • iot growth
  • iot security (lack of)

I've been unable to locate a sample demonstrating a secure connecton. I feel that this is an important topic to discuss and provide solution examples.

Qs about Goal...

  • Is there a platform way to;
    • access certs?
    • add new certs?

Mqtt Sammple running

In the screenshot you'll see the syntax for mosquitto_pub from the command line configured with the Mqtt Sample app settings.

See Wiki/ScreenShots for additional page images

Resources

Reading

Help me find some great and current reading material. Maybe some videos? Again; Looking for real world examples of how to handle installing certificartes in the mobile apps UWP, Android and IOS. And then how to access them. Properly.

Gotchas

Unlikley

  • If you configure DNS nameserver to return a hostname on a NATed ip address this code will bomb.

Totally unOrganized - but in one place! :-)

https://code.msdn.microsoft.com/windowsapps/M2Mqtt-MQTT-client-library-ac6d3858/view/Discussions

https://stackoverflow.com/questions/18462064/associate-a-private-key-with-the-x509certificate2-class-in-net

How to create a certificate request with CertEnroll and .NET (C#) https://blogs.msdn.microsoft.com/alejacma/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c/

SSL Certificate Formats https://www.tutorialsteacher.com/https/ssl-certificate-format

Survival guides - TLS/SSL and SSL (X.509) Certificates http://www.zytrax.com/tech/survival/ssl.html

adrenalinehit/mqtt-subscriber.cs https://gist.github.com/adrenalinehit/ccfeba90264a02fb629f

Sign server and client certificates

https://jamielinux.com/docs/openssl-certificate-authority/sign-server-and-client-certificates.html

OpenSSL Certificate Authority https://jamielinux.com/docs/openssl-certificate-authority/

Associate a private key with the X509Certificate2 class in .net https://stackoverflow.com/questions/18462064/associate-a-private-key-with-the-x509certificate2-class-in-net

Important warnings about selfsigning https://mosquitto.org/man/mosquitto-tls-7.html

Possible useful sample

// https://gist.github.com/adrenalinehit/a4e2684a0b3b0a49b48e

https://docs.microsoft.com/en-us/dotnet/api/system.net.security.remotecertificatevalidationcallback?redirectedfrom=MSDN&view=netframework-4.7.2

https://www.bevywise.com/blog/creating-ssl-certificate-secure-mqtt-communication/

https://paolopatierno.wordpress.com/2013/10/10/mqtt-su-ssltls-con-la-libreria-m2mqtt-ed-il-broker-mosquitto/

Self-Signed Certificates and Xamarin.Android https://dotnetdevaddict.co.za/2015/07/31/self-signed-certificates-and-xamarin-android/comment-page-1/

This has some clues

eclipse/paho.mqtt.m2mqtt#67

How to create and import Self Signed Certificate to Android Device

https://hackernoon.com/the-most-promising-internet-of-things-trends-for-2018-10a852ccd189

About

An example mqtt client to demonstrate TLS connection to Mosquitto broker.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages