https://github.com/open-coap/kotlin-mbedtls
Kotlin wrapper of mbedtls also for java
https://github.com/open-coap/kotlin-mbedtls
cid dtls dtls12 iot java jvm kotlin mbedtls netty
Last synced: 4 months ago
JSON representation
Kotlin wrapper of mbedtls also for java
- Host: GitHub
- URL: https://github.com/open-coap/kotlin-mbedtls
- Owner: open-coap
- License: apache-2.0
- Created: 2022-03-28T14:44:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2026-03-05T11:54:03.000Z (4 months ago)
- Last Synced: 2026-03-05T15:42:26.969Z (4 months ago)
- Topics: cid, dtls, dtls12, iot, java, jvm, kotlin, mbedtls, netty
- Language: Kotlin
- Homepage:
- Size: 15.9 MB
- Stars: 13
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
Kotlin + mbedtls integration
==========================

[](LICENSE)
Integration with mbedtls library to provide DTLS protocol into jvm ecosystem.
## Features:
- Precompiled mbedtls binaries for
- linux (x64)
- macos (intel and arm)
- windows (x64)
- DTLS 1.2 client and server modes
- DTLS 1.2 CID support (RFC 9146)
- Storing and restoring sessions
- Certificate and PSK authentication
- Micrometer integration
- Netty integration (client and server)
## Usage:
**Gradle**
```kotlin
dependencies {
implementation("io.github.open-coap:kotlin-mbedtls:[VERSION]")
// optional modules:
implementation("io.github.open-coap:kotlin-mbedtls-metrics:[VERSION]")
implementation("io.github.open-coap:kotlin-mbedtls-netty:[VERSION]")
}
```
**Maven**
```xml
io.github.open-coap
kotlin-mbedtls
[VERSION]
```
DTLS client:
```kotlin
// create mbedtls SSL configuration with PSK credentials
val conf: SslConfig = SslConfig.client(
PskAuth(
pskId = "device-007",
pskSecret = byteArrayOf(0x01, 0x02)
)
)
// create client and initiate handshake
val client: DtlsTransmitter = DtlsTransmitter
.connect(InetSocketAddress(InetAddress.getLocalHost(), 1_5684), conf, 6001)
.get(10, TimeUnit.SECONDS)
// send and receive packets
val sendResult: CompletableFuture = client.send("hello")
val receive: CompletableFuture = client.receive(timeout = Duration.ofSeconds(2))
// . . .
// optionally, it is possible to save session before closing client, it could be later reloaded
// note: after saving session, it is not possible to is client
val storedSession: ByteArray = client.saveSession()
client.close()
// close SSL configuration:
// - make sure to close it before GC to avoid native memory leak
// - close it only after client is closed
conf.close()
```
## Supported OS
Precompiled:
- Linux (x86-64)
- Apple Mac (intel and arm)
- Windows (x86-64)
## Development
### Useful commands
- `./gradlew build -i` compile and test
- `./gradlew publishToMavenLocal` publish artifact to local maven repository
- `./gradlew currentVersion` show current version
- `./gradlew ktlintFormat` format kotlin files
- `./gradlew release` create next tag in Git and push to origin
- `./gradlew currentVersion` print current version
- `./gradlew dependencyUpdates` determine which dependencies have updates
- `./gradlew useLatestVersions` update dependencies to the latest available versions
- `./gradlew jmh` run benchmarks
- `./gradlew :kotlin-mbedtls:jmh -PjmhIncludes=benchmark.SslContextBenchmark.handshake_cert_ecdhe_ecdsa_with_aes_128_gcm` run specific benchmark
### Build mbedtls binaries
Linux (x86_64):
`./compileMbedtls.sh`
Mac (intel and arm):
`DLEXT=dylib OSARCH=darwin CMAKE_EXTRA='-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64' ./compileMbedtls.sh`
Windows
- `docker run -it -v$(pwd):/work --rm dockcross/windows-static-x64 \
sh -c "apt-get update && apt-get install -y python3-venv && \
WINDOWS=1 \
CMAKE_EXTRA='-DCMAKE_C_FLAGS=-D__USE_MINGW_ANSI_STDIO=0' \
DLEXT=dll \
OSARCH=win32-x86-64 \
./compileMbedtls.sh"`
Cross compiling for linux (x86_64):
- `docker run -it -v$(pwd):/work --rm dockcross/linux-x86_64-full ./compileMbedtls.sh`