https://github.com/carlonzo/ukey2-kmp
google/ukey2 port to Kotlin Multiplatform
https://github.com/carlonzo/ukey2-kmp
kmp kotlin-multiplatform ukey2
Last synced: about 2 months ago
JSON representation
google/ukey2 port to Kotlin Multiplatform
- Host: GitHub
- URL: https://github.com/carlonzo/ukey2-kmp
- Owner: carlonzo
- License: mit
- Created: 2023-06-05T05:15:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T12:19:32.000Z (about 2 months ago)
- Last Synced: 2025-04-14T17:18:54.643Z (about 2 months ago)
- Topics: kmp, kotlin-multiplatform, ukey2
- Language: Kotlin
- Homepage:
- Size: 143 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ukey2 for KMP
This is a port of [google/ukey2](https://github.com/google/ukey2) library to support Kotlin MultiplatformHandshake and Device to Device communication is ported and tested against the C++ test from the original library
## Integration
You can add the dependency to your project by adding the following lines to your Gradle build file.
The library is available on Maven Central and you can add the coordinates to your commonMain source set.
### Gradle
```kotlin
repositories {
mavenCentral()
}dependencies {
implementation("com.carlonzo.ukey2:ukey2-kmp:")
}
```### Supported platforms
The project currently supports the following platforms:
* JVM
* iOS (iosArm64, iosSimulatorArm64)
* macosArm64## Usage
To create a new handshake session, use the following code:### Client
```kotlin
val client = Ukey2Handshake.forInitiator(HandshakeCipher.P256_SHA512)// Message 1 (Client Init)
var handshakeMessage = client.getNextHandshakeMessage()
sendMessageToServer(handshakeMessage)// Message 2 (Server Init)
handshakeMessage = receiveMessageFromServer()
client.parseHandshakeMessage(handshakeMessage)// Message 3 (Client Finish)
handshakeMessage = client.getNextHandshakeMessage()
sendMessageToServer(handshakeMessage)// Get the auth string to show to the user for confirmation
val clientAuthString = client.getVerificationString(STRING_LENGTH)
showStringToUser(clientAuthString)
// Once verified using a different channel, finish the handshake
client.verifyHandshake()
// Retrieve the connection context used to encrypt messages between client and server
val connection = client.toConnectionContext()
```### Server
```kotlin
val server = Ukey2Handshake.forResponder(HandshakeCipher.P256_SHA512)
// Message 1 (Client Init)
var handshakeMessage = receiveMessageFromClient()
server.parseHandshakeMessage(handshakeMessage)
// Message 2 (Server Init)
handshakeMessage = server.getNextHandshakeMessage()
sendMessageToServer(handshakeMessage)
// Message 3 (Client Finish)
handshakeMessage = receiveMessageFromClient()
server.parseHandshakeMessage(handshakeMessage)
// Get the auth string
val serverAuthString = server.getVerificationString(STRING_LENGTH)
showStringToUser(serverAuthString)
// Using out-of-band channel, verify auth string, then call:
server.verifyHandshake()// Retrieve the connection context used to encrypt messages between client and server
val connection = server.toConnectionContext()
```## Development
### Testing
To run the tests against the official C++ implementation, you will need to build the C++ library using the Bazel command from the ukey2 root:
```bash
bazel build //src/main/cpp:ukey2_shell
```and change the path of the binary wrapper pointed by `BINARY_PATH` in `src/jvmTest/kotlin/Ukey2ShellCppWrapper.kt` to the correct path of the `ukey2_shell` binary.
It should be `/bazel-bin/src/main/cpp/ukey2_shell`Then you can run the tests using the following command:
```bash
./gradlew test
```