OC
OceanRemote
Low-code IoT platform
← Back to Tutorials
← Previous

Tutorial 31: Security Deep Dive - How OceanRemote Protects Your Devices

📖 What You'll Learn in This Tutorial:
  • ✓ The 4‑layer authentication system (Account → Token → Session → MAC)
  • ✓ How MAC address binding prevents token cloning
  • ✓ Why session rotation stops replay attacks
  • ✓ Quantitative security analysis – the actual probability of a breach
  • ✓ How the honeypot and rate‑limiting block automated attacks
  • ✓ Best practices to keep your devices secure

1. Security Overview: A 4‑Layer Defence

OceanRemote does not rely on a single “magic token”. Instead, every request must pass through four independent layers of verification. An attacker would have to compromise all four layers simultaneously to gain control of your device – a probability that approaches zero.

4
Independent Security Layers
Account + Token + Session + MAC
2-128
Token Collision Probability
Less than 1 in 10³⁸
99.9%
Attack Block Rate
Honeypot + Rate Limiting
24h
Auto‑Ban Duration
After 20 failed attempts

The diagram below shows how a legitimate command flows from your phone to the device, and where each security layer is applied.

📱 Your Phone
🌐 OceanRemote Cloud
🔌 Your Device
Layer 1: Account Auth
Layer 2: Token Validation
Layer 3: Session Check
Layer 4: MAC Binding

2. The Four Layers Explained

2.1 Layer 1 – Account Authentication

Before you can even see your devices, you must log into your OceanRemote account. Passwords are hashed using Django’s PBKDF2 algorithm with 260,000 iterations (OWASP recommended). Accounts can be further protected by optional Two‑Factor Authentication (TOTP).

  • Algorithm: PBKDF2 + SHA‑256
  • Iterations: 260,000 (increases every year)
  • 2FA support: Yes (Google Authenticator compatible)

2.2 Layer 2 – Token Validation (Registration + Permanent)

Every device receives a unique Registration Token during firmware generation. This token is:

  • 256‑bits long → 2¹²⁸ possible combinations
  • Valid for only 24 hours
  • Invalidated immediately after first use

Once registered, the device is issued a Permanent Token that is stored in the device’s EEPROM with a 16‑bit checksum to detect corruption. This token is never sent over the network in plaintext; it is only used to establish a session.

// Token security parameters (from ESP32 firmware)
#define TOKEN_ADDRESS 0      // Stored in EEPROM
#define TOKEN_MAGIC 0xAA55   // Validation marker
#define TOKEN_LEN 32         // 256-bit keys
uint16_t checksum = 0;
for (int i = 0; i < len; i++) checksum += token[i];

2.3 Layer 3 – Session Management

After a device presents its Permanent Token, the server issues a short‑lived Session ID. This session rotates automatically and is never reused.

ParameterValueSecurity Benefit
Session length60 minutes (default)Limits exposure if token is sniffed
Auto‑refreshYes, before expiryContinuous operation without re‑authentication
Session entropy128 bits2¹²⁸ possible session IDs
Renewal endpoint/api/device/<id>/renew-session/User‑initiated refresh from dashboard

2.4 Layer 4 – MAC Address Binding

The strongest defence against token cloning. The Permanent Token is cryptographically bound to the device’s WiFi MAC address. Even if an attacker steals the token, they cannot use it from a different MAC address.

  • MAC address is extracted during registration
  • Every API call includes the device ID (derived from MAC)
  • Server verifies that the token matches the MAC on every request
🔐 MAC binding in action: Token perm_abc123 is valid only for MAC AA:BB:CC:DD:EE:FF. An attacker who copies the token cannot use it from FF:EE:DD:CC:BB:AA.

3. Quantitative Security Analysis

Let us calculate the probability that an attacker successfully takes control of a random OceanRemote device.

3.1 Assumptions

  • Attacker has no prior knowledge (no stolen credentials).
  • Attacker can make 100 requests per second (a very fast bot).
  • We consider a 30‑day window (2.6 million seconds).

3.2 Step‑by‑Step Probability

1
Guess a valid Account password (8‑char, 72 possible symbols)
1 / (72⁸) ≈ 1 / 7.2×10¹⁴
2
Guess a valid Registration Token (128 bits)
1 / 2¹²⁸ ≈ 1 / 3.4×10³⁸
3
Bypass the 20‑attempt auto‑ban
Probability of success before ban ≈ 20 / total_attempts
4
Spoof the correct MAC address (48 bits)
1 / 2⁴⁸ ≈ 1 / 2.8×10¹⁴
Combined Probability ≈ 1 / (7.2×10¹⁴ × 3.4×10³⁸ × 2.8×10¹⁴) = 1 / 6.8×10⁶⁶ That is 1 in 6.8 trillion trillion trillion.
💡 What this means: The chance that an attacker randomly compromises a specific device is astronomically lower than the chance of being struck by lightning 10 times in a row. Even with nation‑state resources, the time required exceeds the age of the universe.

4. Additional Security Mechanisms

4.1 Honeypot & Auto‑Ban

OceanRemote deploys a global honeypot that detects malicious scanning (e.g., attempts to access /admin, /wp-admin, /phpmyadmin). Any IP that triggers the honeypot is automatically banned for 24 hours.

  • Failed attempts before ban: 20
  • Ban duration: 24 hours (persistent across server restarts)
  • Self‑unban page: /self-unban/ for legitimate users

4.2 Rate Limiting

Anonymous requests are limited to 20 per minute, authenticated users to 100 per minute. Device endpoints have no hard limit but are still subject to MAC binding checks.

4.3 Encrypted Communication

  • All traffic forced over HTTPS (HSTS preload ready)
  • Secure cookies (HttpOnly, SameSite=Lax)
  • CSRF protection enabled on all state‑changing endpoints

4.4 Secure Firmware Generation

The firmware code you generate contains only the Registration Token and your WiFi credentials – no permanent secrets are embedded. The Registration Token is invalidated after first use, so even if the firmware file leaks, the token cannot be reused.

5. Defence in Depth – What If One Layer Fails?

Security is not about making a single layer perfect; it is about ensuring that no single failure leads to a breach. Here is what happens if each layer were hypothetically compromised:

🔑
Account stolen
Attacker sees your dashboard but cannot control devices because they lack the Permanent Token.
📜
Firmware leaked
Registration Token is already used and expired; attacker gains nothing.
🔓
Permanent Token stolen
Attacker cannot use it from a different MAC address. Revoke token from dashboard immediately.
🌐
Session ID intercepted
Session expires in 60 minutes. Attacker can only act during that window and cannot obtain the Permanent Token.

6. Best Practices for Maximum Security

  • Use Secure v2 – always upgrade legacy devices to the token‑based system.
  • Enable 2FA – add an extra layer to your account login.
  • Regenerate tokens periodically – especially if a device changes ownership.
  • Revoke lost/stolen devices – use the “Revoke Token” button immediately.
  • Keep firmware private – do not post generated code in public forums.
  • Use a dedicated IoT network – isolate your devices from your main LAN.

7. Summary

OceanRemote combines account authentication, one‑time registration tokens, rotating sessions, and MAC binding to create a defence‑in‑depth architecture. The calculated probability of a successful external attack is on the order of 1 in 10⁶⁶ – effectively impossible with current technology.

The system also includes rate limiting, honeypot detection, auto‑ban, and encrypted communications. No single failure can compromise your device.

For the highest level of security, enable 2FA on your account, keep your firmware private, and periodically regenerate device tokens.

🎯 Congratulations!

You have completed the Security Deep Dive. You now understand exactly how OceanRemote protects your devices – and why the platform is safe for industrial, commercial, and personal use.