Compare commits
14
Commits
186db7478a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e71ff35e14 | ||
|
|
eb9158d3e1 | ||
|
|
12ff5ed3cb | ||
|
|
e17f5a8dd5 | ||
|
|
b4b08f2e17 | ||
|
|
aeda210bc5 | ||
|
|
09622f8226 | ||
|
|
c39c9ec71e | ||
|
|
2acf7218b4 | ||
|
|
f1b8488707 | ||
|
|
8a2bbb3e33 | ||
|
|
c87a0cf24c | ||
|
|
c8020e9200 | ||
|
|
3334a967b1 |
No files matched your search
@@ -13,20 +13,12 @@ attack surfaces, bugs and other issues and you shouldn't use it in production un
|
||||
|
||||
#### Gradle
|
||||
```kotlin
|
||||
implementation("com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.9.2")
|
||||
```
|
||||
|
||||
#### Snapshot builds
|
||||
```kotlin
|
||||
repositories {
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
|
||||
}
|
||||
implementation("com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:0.9.3-SNAPSHOT")
|
||||
|
||||
implementation("net.sergeych:multiplatform-crypto-libsodium-bindings:0.9.6")
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach
|
||||
@@ -146,7 +138,7 @@ Currently supported native platforms (Apple Silicon is supported since 0.8.5) :
|
||||
Android .so files come from running dist-build scripts in libsodium which you can find in the libsodium submodule
|
||||
Java Linux Arm/X86_64 and Mac so and dylib are the same as produced by multiplatform builds, also based on the same submodule commit
|
||||
Java Windows dll is from https://download.libsodium.org/libsodium/releases/libsodium-1.0.19-stable-msvc.zip
|
||||
Javascript is from libsodium-wrappers-sumo npm package version 0.7.13 (https://github.com/jedisct1/libsodium.js)
|
||||
Javascript and WebAssembly is from libsodium-wrappers-sumo npm package version 0.7.13 (https://github.com/jedisct1/libsodium.js)
|
||||
|
||||
### TODO:
|
||||
- Improve documentation
|
||||
@@ -156,7 +148,7 @@ Javascript is from libsodium-wrappers-sumo npm package version 0.7.13 (https://g
|
||||
- Find a better way of fetching Konan dependencies than having a dummy project.
|
||||
|
||||
### Building
|
||||
Clone the git, init the submodule and run `./gradlew build`. Note that current build settings are such that only linux builds `js` target.
|
||||
Clone the git, init the submodule and run `./gradlew build`. Note that current build settings are such that only linux builds `js` and `wasmJs` targets.
|
||||
|
||||
#### Notes for Github runners:
|
||||
- At the moment all runners need to have android sdk present even though not all are building Android build
|
||||
|
||||
+2
-4
@@ -36,13 +36,11 @@ allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
|
||||
}
|
||||
}
|
||||
|
||||
group = "com.ionspin.kotlin"
|
||||
group = ReleaseInfo.group
|
||||
|
||||
|
||||
apply {
|
||||
|
||||
@@ -36,8 +36,8 @@ object Versions {
|
||||
}
|
||||
|
||||
object ReleaseInfo {
|
||||
val group = "com.ionspin.kotlin"
|
||||
val bindingsVersion = "0.9.4-SNAPSHOT"
|
||||
val group = "net.sergeych"
|
||||
val bindingsVersion = "0.9.8-SNAPSHOT"
|
||||
}
|
||||
|
||||
object Deps {
|
||||
@@ -54,7 +54,7 @@ object Deps {
|
||||
|
||||
val apiProject = ":multiplatform-crypto-api"
|
||||
|
||||
val libsodiumBindings = "com.ionspin.kotlin:multiplatform-crypto-libsodium-bindings:${Versions.sampleLibsodiumBindings}"
|
||||
val libsodiumBindings = "net.sergeych:multiplatform-crypto-libsodium-bindings:${Versions.sampleLibsodiumBindings}"
|
||||
|
||||
val kodein = "org.kodein.di:kodein-di:${Versions.kodeinVersion}"
|
||||
}
|
||||
@@ -142,4 +142,3 @@ object PluginsDeps {
|
||||
val kotlinAndroid = "kotlin-android"
|
||||
val kapt = "kotlin-kapt"
|
||||
}
|
||||
|
||||
@@ -33,22 +33,11 @@ plugins {
|
||||
|
||||
}
|
||||
|
||||
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
val sonatypePassword: String? by project
|
||||
|
||||
val sonatypeUsername: String? by project
|
||||
|
||||
val sonatypePasswordEnv: String? = System.getenv()["SONATYPE_PASSWORD"]
|
||||
val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"]
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
|
||||
|
||||
}
|
||||
group = ReleaseInfo.group
|
||||
@@ -139,14 +128,14 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
if (ideaActive.not()) {
|
||||
// if (ideaActive.not()) {
|
||||
linuxArm64() {
|
||||
binaries {
|
||||
staticLib {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -339,11 +328,11 @@ kotlin {
|
||||
"linuxX64"
|
||||
)
|
||||
val linuxArm64Bit = setOf(
|
||||
if (ideaActive.not()) {
|
||||
// if (ideaActive.not()) {
|
||||
"linuxArm64"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
// } else {
|
||||
// ""
|
||||
// }
|
||||
)
|
||||
|
||||
//iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64
|
||||
@@ -382,14 +371,8 @@ kotlin {
|
||||
defaultSourceSet.dependsOn(nativeMain)
|
||||
}
|
||||
if (linuxArm64Bit.contains(this@withType.name)) {
|
||||
defaultSourceSet.dependsOn(
|
||||
createWorkaroundNativeMainSourceSet(
|
||||
this@withType.name,
|
||||
nativeDependencies
|
||||
)
|
||||
)
|
||||
defaultSourceSet.dependsOn(nativeMain)
|
||||
|
||||
this@withType.compilations.getByName("main") {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(projectRef.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
compilerOpts.add("-I${projectRef.rootDir}/sodiumWrapper/static-arm64/include/")
|
||||
@@ -398,7 +381,6 @@ kotlin {
|
||||
"-include-binary", "${projectRef.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (macos64Bit.contains(this@withType.name)) {
|
||||
defaultSourceSet.dependsOn(
|
||||
@@ -817,26 +799,21 @@ publishing {
|
||||
|
||||
}
|
||||
}
|
||||
val mavenToken by lazy {
|
||||
File("${System.getProperty("user.home")}/.gitea_token").readText()
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
|
||||
url = uri(sonatypeStaging)
|
||||
credentials {
|
||||
username = sonatypeUsername ?: sonatypeUsernameEnv ?: ""
|
||||
password = sonatypePassword ?: sonatypePasswordEnv ?: ""
|
||||
credentials(HttpHeaderCredentials::class) {
|
||||
name = "Authorization"
|
||||
value = mavenToken
|
||||
}
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "snapshot"
|
||||
url = uri(sonatypeSnapshots)
|
||||
credentials {
|
||||
username = sonatypeUsername ?: sonatypeUsernameEnv ?: ""
|
||||
password = sonatypePassword ?: sonatypePasswordEnv ?: ""
|
||||
url = uri("https://gitea.sergeych.net/api/packages/SergeychWorks/maven")
|
||||
authentication {
|
||||
create("Authorization", HttpHeaderAuthentication::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
@@ -3,6 +3,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.box.BoxKeyPair
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
@@ -13,6 +14,8 @@ import org.khronos.webgl.Uint8Array
|
||||
@JsNonModule
|
||||
external object JsSodiumInterface {
|
||||
|
||||
val ready: Promise<dynamic>
|
||||
|
||||
|
||||
@JsName("crypto_generichash")
|
||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||
|
||||
+2
-20
@@ -2,12 +2,6 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodiumLoaded
|
||||
import com.ionspin.kotlin.crypto.sodiumLoaded
|
||||
import ext.libsodium._libsodiumPromise
|
||||
import ext.libsodium.crypto_generichash
|
||||
import ext.libsodium.crypto_hash_sha256
|
||||
import ext.libsodium.crypto_hash_sha256_init
|
||||
import ext.libsodium.crypto_hash_sha512
|
||||
import ext.libsodium.sodium_init
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
/**
|
||||
@@ -17,20 +11,9 @@ import kotlin.coroutines.suspendCoroutine
|
||||
*/
|
||||
object JsSodiumLoader {
|
||||
|
||||
class _EmitJsSodiumFunction {
|
||||
init {
|
||||
println(::crypto_generichash)
|
||||
println(::crypto_hash_sha256)
|
||||
println(::crypto_hash_sha512)
|
||||
println(::crypto_hash_sha256_init)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
suspend fun load() = suspendCoroutine { continuation ->
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<dynamic> {
|
||||
sodium_init()
|
||||
JsSodiumInterface.ready.then<dynamic> {
|
||||
sodiumLoaded = true
|
||||
continuation.resumeWith(Result.success(Unit))
|
||||
}.catch { e ->
|
||||
@@ -43,8 +26,7 @@ object JsSodiumLoader {
|
||||
|
||||
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<dynamic> {
|
||||
sodium_init()
|
||||
JsSodiumInterface.ready.then<dynamic> {
|
||||
sodiumLoaded = true
|
||||
doneCallback.invoke()
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
@file:JsModule("libsodium-sumo")
|
||||
@file:JsNonModule
|
||||
package ext.libsodium
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-May-2020
|
||||
*/
|
||||
|
||||
@JsName("ready")
|
||||
external val _libsodiumPromise : Promise<dynamic>
|
||||
|
||||
@JsName("_sodium_init")
|
||||
external fun sodium_init() : Int
|
||||
|
||||
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
|
||||
external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256_init(): dynamic
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
@@ -16,7 +17,9 @@ external object JsSodium: JsAny {
|
||||
}
|
||||
|
||||
@JsModule("libsodium-wrappers-sumo")
|
||||
external object JsSodiumInterface: JsAny {
|
||||
external interface JsSodiumInterface: JsAny {
|
||||
val ready: Promise<JsAny?>
|
||||
|
||||
@JsName("crypto_generichash")
|
||||
fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array, key: Uint8Array): Uint8Array
|
||||
|
||||
|
||||
+2
-15
@@ -2,7 +2,6 @@ package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodiumLoaded
|
||||
import com.ionspin.kotlin.crypto.sodiumLoaded
|
||||
import ext.libsodium.*
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
/**
|
||||
@@ -12,20 +11,9 @@ import kotlin.coroutines.suspendCoroutine
|
||||
*/
|
||||
object JsSodiumLoader {
|
||||
|
||||
class _EmitJsSodiumFunction {
|
||||
init {
|
||||
println(::crypto_generichash)
|
||||
println(::crypto_hash_sha256)
|
||||
println(::crypto_hash_sha512)
|
||||
println(::crypto_hash_sha256_init)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
suspend fun load(): Unit = suspendCoroutine { continuation ->
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<JsAny?> {
|
||||
sodium_init()
|
||||
JsSodium.default.ready.then<JsAny?> {
|
||||
sodiumLoaded = true
|
||||
continuation.resumeWith(Result.success(Unit))
|
||||
null
|
||||
@@ -45,8 +33,7 @@ object JsSodiumLoader {
|
||||
|
||||
fun loadWithCallback(doneCallback: () -> (Unit)) {
|
||||
if (!getSodiumLoaded()) {
|
||||
_libsodiumPromise.then<JsAny?> {
|
||||
sodium_init()
|
||||
JsSodium.default.ready.then<JsAny?> {
|
||||
sodiumLoaded = true
|
||||
doneCallback.invoke()
|
||||
null
|
||||
|
||||
+2
@@ -38,6 +38,8 @@ actual object SecretStream {
|
||||
ciphertext: UByteArray,
|
||||
associatedData: UByteArray
|
||||
): DecryptedDataAndTag {
|
||||
// crypto_secretstream_xchacha20poly1305_pull JavaScript realization returns either 0
|
||||
// or DecryptedDataAndTagType object, therefore if 0 is returned an identifying exception is thrown
|
||||
try {
|
||||
val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
|
||||
state, ciphertext.toUInt8Array(), associatedData.toUInt8Array()
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
@file:JsModule("libsodium-sumo")
|
||||
package ext.libsodium
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import kotlin.js.Promise
|
||||
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-May-2020
|
||||
*/
|
||||
|
||||
@JsName("ready")
|
||||
external val _libsodiumPromise : Promise<JsAny?>
|
||||
|
||||
@JsName("_sodium_init")
|
||||
external fun sodium_init() : Int
|
||||
|
||||
external fun crypto_generichash(hashLength: Int, inputMessage: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256(message: Uint8Array) : Uint8Array
|
||||
external fun crypto_hash_sha512(message: Uint8Array) : Uint8Array
|
||||
|
||||
external fun crypto_hash_sha256_init(): JsAny
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
//package com.ionspin.kotlin.crypto.debug
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class TestTest {
|
||||
@Test
|
||||
fun wasmSymbolsTest() {
|
||||
assertEquals(42, 42)
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.ionspin.kotlin.crypto.debug
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class WasmSymbolsTest {
|
||||
@Test
|
||||
fun wasmSymbolsTest() {
|
||||
assertEquals(42, 42)
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven("https://gitea.sergeych.net/api/packages/YoungBlood/maven")
|
||||
|
||||
}
|
||||
group = "com.ionspin.kotlin"
|
||||
group = "net.sergeych"
|
||||
version = "0.1.0-SNAPSHOT"
|
||||
|
||||
val ideaActive = System.getProperty("idea.active") == "true"
|
||||
|
||||
Reference in new issue
Block a user