Giter VIP home page Giter VIP logo

kotlin-mbedtls's Introduction

Kotlin + mbedtls integration

Maven Central 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

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

<dependency>
    <groupId>io.github.open-coap</groupId>
    <artifactId>kotlin-mbedtls</artifactId>
    <version>[VERSION]</version>
</dependency>

DTLS client:

// 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<Boolean> = client.send("hello")
val receive: CompletableFuture<ByteBuffer> = 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

Build mbedtls binaries

Linux (x86_64):

./compileMbedtls.sh

Mac (intel and arm):

LDFLAGS='-arch x86_64 -arch arm64' CFLAGS='-O2 -arch x86_64 -arch arm64' DLEXT=dylib OSARCH=darwin ./compileMbedtls.sh

Windows

  • docker run -it -v$(pwd):/work --rm dockcross/windows-static-x64 sh -c "WINDOWS=1 LDFLAGS='-lws2_32 -lwinmm -lgdi32 -L. -static-libgcc' 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

kotlin-mbedtls's People

Contributors

akolosov-n avatar dependabot[bot] avatar github-actions[bot] avatar juhapekkaa avatar szysas avatar topiasjokiniemi-nordic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.