plugmate-secure-http-client.ino
Illustrates secure outgoing network access from the isolated PlugMate environment, using the host's connectivity via the USB-C channel.
PlugMate has no internal modem; it uses the host's network. This code uses standard HttpsURLConnection. Ensure the host client is allowed to share the connection. The PlugOS firewall blocks unauthorized ports by default. Root certificates are managed by the hardened Android 14 OS.
plugmate-secure-http-client.ino
package com.trustkernel.plugmate.demo
import java.net.HttpURLConnection
import java.net.URL
import javax.net.ssl.HttpsURLConnection
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManagerFactory
import java.security.KeyStore
import java.io.BufferedReader
import java.io.InputStreamReader
object SecureNetworkDemo {
/**
* Effectue une GET HTTPS vers une API sécurisée.
* Le trafic est chiffré TLS et passe par le tunnel USB-C vers l'hôte.
*/
fun fetchSecureData(apiUrl: String): String? {
var connection: HttpURLConnection? = null
return try {
val url = URL(apiUrl)
connection = url.openConnection() as HttpsURLConnection
// Configuration TLS standard (Android 14 gère les CA système)
connection.requestMethod = "GET"
connection.connectTimeout = 5000
connection.readTimeout = 5000
val responseCode = connection.responseCode
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader(InputStreamReader(connection.inputStream)).use { reader ->
val response = StringBuilder()
var line: String?
while (reader.readLine().also { line = it } != null) {
response.append(line)
}
response.toString()
}
} else {
null
}
} catch (e: Exception) {
e.printStackTrace()
null
} finally {
connection?.disconnect()
}
}
}