Home > Projects > Arduino Programmer Projects > Add SSL Certificates To MKR1000

Add SSL Certificates To MKR1000

Summary of Add SSL Certificates To MKR1000


This guide explains how to install custom SSL certificates on an Arduino MKR1000 using a graphical user interface (GUI) to connect to HTTPS sites. The process involves uploading a specific firmware sketch via the Arduino IDE, then using a standalone GUI tool to fetch and upload the certificate from a target website directly to the board's WiFi module. Note that this method overwrites existing certificates on the device.

Parts used in the Install SSL Certificate on MKR1000:

  • Arduino MKR1000
  • Arduino IDE
  • Arduino Firmware updater
  • WiFi101 FirmwareUpdater GUI
  • Firmware updater sketch
  • USB cable

Cannot connect to your favourite https site with your MKR1000? Follow this guide to install SSL certificate in a easy way using the GUI.

Add SSL Certificates To MKR1000

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Firmware updater

Story

Code

/*
  FirmwareUpdate.h - Firmware Updater for WiFi101 / WINC1500.
  Copyright (c) 2015 Arduino LLC.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <WiFi101.h>
#include <spi_flash/include/spi_flash.h>

typedef struct __attribute__((__packed__)) {
  uint8_t command;
  uint32_t address;
  uint32_t arg1;
  uint16_t payloadLength;

  // payloadLenght bytes of data follows...
} UartPacket;

static const int MAX_PAYLOAD_SIZE = 1024;

#define CMD_READ_FLASH        0x01
#define CMD_WRITE_FLASH       0x02
#define CMD_ERASE_FLASH       0x03
#define CMD_MAX_PAYLOAD_SIZE  0x50
#define CMD_HELLO             0x99

void setup() {
  Serial.begin(115200);

  nm_bsp_init();
  if (m2m_wifi_download_mode() != M2M_SUCCESS) {
    Serial.println(F("Failed to put the WiFi module in download mode"));
    while (true)
      ;
  }
}

void receivePacket(UartPacket *pkt, uint8_t *payload) {
  // Read command
  uint8_t *p = reinterpret_cast<uint8_t *>(pkt);
  uint16_t l = sizeof(UartPacket);
  while (l > 0) {
    int c = Serial.read();
    if (c == -1)
      continue;
    *p++ = c;
    l--;
  }

  // Convert parameters from network byte order to cpu byte order
  pkt->address = fromNetwork32(pkt->address);
  pkt->arg1 = fromNetwork32(pkt->arg1);
  pkt->payloadLength = fromNetwork16(pkt->payloadLength);

  // Read payload
  l = pkt->payloadLength;
  while (l > 0) {
    int c = Serial.read();
    if (c == -1)
      continue;
    *payload++ = c;
    l--;
  }
}

// Allocated statically so the compiler can tell us
// about the amount of used RAM
static UartPacket pkt;
static uint8_t payload[MAX_PAYLOAD_SIZE];

void loop() {
  receivePacket(&pkt, payload);

  if (pkt.command == CMD_HELLO) {
    if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788)
      Serial.print("v10000");
  }

  if (pkt.command == CMD_MAX_PAYLOAD_SIZE) {
    uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE);
    Serial.write(reinterpret_cast<uint8_t *>(&res), sizeof(res));
  }

  if (pkt.command == CMD_READ_FLASH) {
    uint32_t address = pkt.address;
    uint32_t len = pkt.arg1;
    if (spi_flash_read(payload, address, len) != M2M_SUCCESS) {
      Serial.println("ER");
    } else {
      Serial.write(payload, len);
      Serial.print("OK");
    }
  }

  if (pkt.command == CMD_WRITE_FLASH) {
    uint32_t address = pkt.address;
    uint32_t len = pkt.payloadLength;
    if (spi_flash_write(payload, address, len) != M2M_SUCCESS) {
      Serial.print("ER");
    } else {
      Serial.print("OK");
    }
  }

  if (pkt.command == CMD_ERASE_FLASH) {
    uint32_t address = pkt.address;
    uint32_t len = pkt.arg1;
    if (spi_flash_erase(address, len) != M2M_SUCCESS) {
      Serial.print("ER");
    } else {
      Serial.print("OK");
    }
  }
}

Quick Solutions to Questions related to Install SSL Certificate on MKR1000:

  • How do I upload an SSL certificate to my MKR1000?
    You can use the WiFi101 FirmwareUpdater GUI after uploading the Firmware updater sketch to the board.
  • Can I update the certificate without external executables if I have IDE 1.6.10 or newer?
    No, the article states that starting from version 1.6.10, the uploader is built into the IDE, but the guide specifically demonstrates using the external GUI for this task.
  • Does the procedure overwrite existing certificates on the board?
    Yes, the procedure uploads only the selected certificates and will overwrite any others currently on the board.
  • What should I do if I need a different certificate later?
    You must repeat the guide and select the proper certificate you need during the process.
  • Where can I download the firmware updater GUI?
    The GUI can be downloaded from the GitHub releases page for arduino-libraries/WiFi101-FirmwareUpdater.
  • Which operating systems are supported by the GUI?
    The available versions are for Linux, Windows, and OSX.
  • What is the first step after connecting the MKR1000 via USB?
    You must open the Arduino IDE and upload the Firmware updater sketch found under Example -> Wifi101.
  • How do I specify the website for the certificate?
    Type the website name into section 1 of the main program window and press fetch.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top