Update kotlin to 1.9.10, update library versions, use latest libsodium stable, clean up Deps, remove deprecated targets, change PasswordHash str related functions to use String

This commit is contained in:
Ugljesa Jovanovic 2023-09-23 11:54:02 +02:00
parent b32821e13e
commit 194994f5b2
No known key found for this signature in database
GPG Key ID: 5884AC34A0EC67DB
14 changed files with 76 additions and 123 deletions

View File

@ -1,10 +1,27 @@
## Descriptive changelog
(All dates are DD.MM.YYYY)
#### 0.8.9-SNAPSHOT - Current development snapshot
#### 0.9.1-SNAPSHO - current development snapshot
#### 0.9.0-SNAPSHOT - 23.9.2023
- Breaking changes:
- PasswordHash.str now returns String
- PasswordHash.strNeedsRehash and PasswordHash.strVerify now take String type for `passwordHash` parameter
- Update to latest stable build of libsodium
- Update to kotlin 1.9.10
- Targets deprecated by kotlin 1.9.10 and therefore removed from this library:
- iosArm32
- watchosX86
- wasm32
- mingwX86
- linuxArm32Hfp
#### 0.8.9-SNAPSHOT - 26.3.2023
- Update to latest stable build of libsodium
- Update to kotlin 1.8.10
#### 0.8.8 - 9.10.2022
- Fix for missing mingw target in published library modules.xml (#29)

View File

@ -17,6 +17,12 @@
buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
classpath("com.android.tools.build:gradle:7.2.2")
classpath ("org.jetbrains.dokka:dokka-gradle-plugin:1.8.20")
}
repositories {
mavenCentral()
google()

View File

@ -15,16 +15,14 @@
*/
object Versions {
val kotlinCoroutines = "1.7.0-Beta"
val kotlin = "1.9.0"
val kotlinSerialization = "1.5.0"
val kotlinCoroutines = "1.7.3"
val kotlin = "1.9.10"
val kotlinSerialization = "1.6.0"
val kotlinSerializationPlugin = kotlin
val nodePlugin = "1.3.0"
val dokkaPlugin = kotlin
val taskTreePlugin = "1.5"
val kotlinBigNumVersion = "0.3.7"
val jna = "5.13.0"
val kotlinPoet = "1.6.0"
val sampleLibsodiumBindings = "0.8.8-SNAPSHOT"
val ktor = "1.3.2"
val timber = "4.7.1"
@ -61,27 +59,14 @@ object Deps {
object Js {
object JsVersions {
val react = "17.0.2-pre.218-kotlin-1.5.21"
val reactNpm = "17.0.2"
val styled = "5.3.0-pre.218-kotlin-1.5.21"
val styledNpm = "5.3.0"
}
val stdLib = "stdlib-js"
val test = "test-js"
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Versions.kotlinCoroutines}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:${Versions.kotlinSerialization}"
val ktorClient = "io.ktor:ktor-client-js:${Versions.ktor}"
val ktorClientSerialization = "io.ktor:ktor-client-serialization-js:${Versions.ktor}"
val ktorClientWebSockets = "io.ktor:ktor-client-websockets-js:${Versions.ktor}"
object Npm {
val libsodium = Pair("libsodium-wrappers-sumo", "0.7.9")
//val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "file:${getProjectPath()}/multiplatform-crypto-delegated/libsodium-wrappers-sumo-0.7.6.tgz")
val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.9")
val libsodiumWrappers = Pair("libsodium-wrappers-sumo", "0.7.13")
}
@ -92,13 +77,10 @@ object Deps {
val test = "test"
val testJUnit = "test-junit"
val reflection = "reflect"
val coroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}"
val coroutinesjdk8 = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${Versions.kotlinCoroutines}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.kotlinSerialization}"
val coroutinesTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.kotlinCoroutines}"
val kotlinPoet = "com.squareup:kotlinpoet:${Versions.kotlinPoet}"
val resourceLoader = "com.goterl:resource-loader:${Versions.resourceLoader}"
object Delegated {
@ -119,9 +101,7 @@ object Deps {
object Android {
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.kotlinCoroutines}"
val ktorClientOkHttp = "io.ktor:ktor-client-okhttp:${Versions.ktor}"
val ktorClient = "io.ktor:ktor-client-android:${Versions.ktor}"
val ktorClientSerialization = "io.ktor:ktor-client-serialization-jvm:${Versions.ktor}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.kotlinSerialization}"
val timber = "com.jakewharton.timber:timber:${Versions.timber}"
val jna = "net.java.dev.jna:jna:${Versions.jna}@aar"
@ -135,7 +115,6 @@ object Deps {
object AndroidPluginConfiguration {
val sdkVersion = 31
val targetVersion = 31
val minVersion = 24
}

View File

@ -1656,17 +1656,17 @@ launch-editor@^2.6.0:
picocolors "^1.0.0"
shell-quote "^1.7.3"
libsodium-sumo@^0.7.0:
version "0.7.9"
resolved "https://registry.yarnpkg.com/libsodium-sumo/-/libsodium-sumo-0.7.9.tgz#dff3d6144849e30d9b9a7bf628d28243f1c49102"
integrity sha512-DcfJ57zlSlcmQU4s8KOX78pT0zKx5S9RLi0oyDuoIgm4K95+VNSaOidK/y9lUK4lxft14PtTPjoBy8tmLk1TDQ==
libsodium-sumo@^0.7.13:
version "0.7.13"
resolved "https://registry.yarnpkg.com/libsodium-sumo/-/libsodium-sumo-0.7.13.tgz#533b97d2be44b1277e59c1f9f60805978ac5542d"
integrity sha512-zTGdLu4b9zSNLfovImpBCbdAA4xkpkZbMnSQjP8HShyOutnGjRHmSOKlsylh1okao6QhLiz7nG98EGn+04cZjQ==
libsodium-wrappers-sumo@0.7.9:
version "0.7.9"
resolved "https://registry.yarnpkg.com/libsodium-wrappers-sumo/-/libsodium-wrappers-sumo-0.7.9.tgz#d15a346870c8e339baf1518f06b0ddccfa1e1046"
integrity sha512-XLgLkqY973PngrRElbjOH0y7bJKYEfMWVpWPmW5iuhBjO6zXvHYQWtN52MVEeie/h98ZXN1Aw9BE+GzxQVAfLg==
libsodium-wrappers-sumo@0.7.13:
version "0.7.13"
resolved "https://registry.yarnpkg.com/libsodium-wrappers-sumo/-/libsodium-wrappers-sumo-0.7.13.tgz#a33aea845a0bb56db067548f04feba28c730ab8e"
integrity sha512-lz4YdplzDRh6AhnLGF2Dj2IUj94xRN6Bh8T0HLNwzYGwPehQJX6c7iYVrFUPZ3QqxE0bqC+K0IIqqZJYWumwSQ==
dependencies:
libsodium-sumo "^0.7.0"
libsodium-sumo "^0.7.13"
loader-runner@^4.2.0:
version "4.3.0"

View File

@ -17,9 +17,7 @@
@file:Suppress("UnstableApiUsage")
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
import org.jetbrains.dokka.Platform
plugins {
kotlin(PluginsDeps.multiplatform)
@ -74,20 +72,12 @@ kotlin {
}
}
linuxArm32Hfp() {
binaries {
staticLib {
}
}
}
}
runningOnMacos {
iosX64()
iosArm64()
iosArm32()
iosSimulatorArm64()
macosX64()
@ -99,13 +89,11 @@ kotlin {
watchosArm64()
watchosArm32()
watchosX86()
watchosSimulatorArm64()
}
runningOnWindows {
mingwX64()
mingwX86()
}

View File

@ -56,10 +56,10 @@ version = ReleaseInfo.bindingsVersion
val ideaActive = isInIdea()
println("Idea active: $ideaActive")
android {
compileSdkVersion(AndroidPluginConfiguration.sdkVersion)
compileSdk = AndroidPluginConfiguration.sdkVersion
defaultConfig {
minSdkVersion(AndroidPluginConfiguration.minVersion)
targetSdkVersion(AndroidPluginConfiguration.sdkVersion)
minSdk = AndroidPluginConfiguration.minVersion
targetSdk = AndroidPluginConfiguration.sdkVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
@ -83,7 +83,7 @@ android {
kotlin {
val hostOsName = getHostOsName()
android() {
androidTarget() {
publishLibraryVariants("release", "debug")
}
@ -93,7 +93,7 @@ kotlin {
println("Configuring Linux X86-64 targets")
js(IR) {
js {
browser {
testTask {
useKarma {
@ -133,15 +133,6 @@ kotlin {
}
}
}
// Linux 32 is using target-sysroot-2-raspberrypi which is missing getrandom and explicit_bzero in stdlib
// so konanc can't build klib because getrandom missing will cause sodium_misuse()
// ld.lld: error: undefined symbol: explicit_bzero
// >>> referenced by utils.c
// >>> libsodium_la-utils.o:(sodium_memzero) in archive /tmp/included11051337748775083797/libsodium.a
//
// ld.lld: error: undefined symbol: getrandom
// >>> referenced by randombytes_sysrandom.c
// >>> libsodium_la-randombytes_sysrandom.o:(_randombytes_linux_getrandom) in archive /tmp/included11051337748775083797/libsodium.a
}
}
@ -171,13 +162,7 @@ kotlin {
}
}
}
iosArm32() {
binaries {
framework {
optimized = true
}
}
}
iosSimulatorArm64() {
binaries {
framework {
@ -237,13 +222,7 @@ kotlin {
}
}
}
watchosX86() {
binaries {
framework {
optimized = true
}
}
}
watchosSimulatorArm64() {
binaries {
framework {
@ -351,9 +330,6 @@ kotlin {
""
}
)
val linux32Bit = setOf(
"" // "linuxArm32Hfp"
)
//iosArm32, iosArm64, iosX64, macosX64, metadata, tvosArm64, tvosX64, watchosArm32, watchosArm64, watchosX86
val macos64Bit = setOf(
@ -377,10 +353,10 @@ kotlin {
)
val watchosArm = setOf(
"watchosArm32", "watchosArm64"
"watchosArm64"
)
val watchosSimulator = setOf(
"watchosX86", "watchosSimulatorArm64"
"watchosSimulatorArm64"
)
targets.withType<KotlinNativeTarget> {
@ -408,14 +384,7 @@ kotlin {
)
}
}
if (linux32Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(
createWorkaroundNativeMainSourceSet(
this@withType.name,
nativeDependencies
)
)
}
if (macos64Bit.contains(this@withType.name)) {
defaultSourceSet.dependsOn(
createWorkaroundNativeMainSourceSet(
@ -640,10 +609,6 @@ kotlin {
dependsOn(commonMain)
}
val watchosX86Main by getting {
dependsOn(commonMain)
}
val watchosArm64Main by getting {
dependsOn(commonMain)
}

View File

@ -55,7 +55,7 @@ expect object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray
fun str(password: String, opslimit: ULong, memlimit: Int): String
/**
* Check if a password verification string str matches the parameters opslimit and memlimit, and the current default algorithm.
@ -63,13 +63,13 @@ expect object PasswordHash {
* The function returns 0 if the parameters already match the given ones.
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
fun strNeedsRehash(passwordHash: UByteArray, opslimit: ULong, memlimit: Int): Int
fun strNeedsRehash(passwordHash: String, opslimit: ULong, memlimit: Int): Int
/**
* his function verifies that str is a valid password verification string (as generated by crypto_pwhash_str()) for passwd whose length is passwdlen.
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
fun strVerify(passwordHash: UByteArray, password: String): Boolean
fun strVerify(passwordHash: String, password: String): Boolean
}

View File

@ -44,7 +44,7 @@ class PasswordHashTest {
crypto_pwhash_OPSLIMIT_MIN,
crypto_pwhash_MEMLIMIT_MIN
)
println("Hashed password for storage: ${hashedPassword.toHexString()}")
println("Hashed password for storage: ${hashedPassword}")
assertTrue {
PasswordHash.strVerify(

View File

@ -45,7 +45,7 @@ actual object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
if (opslimit > UInt.MAX_VALUE) {
throw RuntimeException("Javascript doesnt support more than ${UInt.MAX_VALUE} for opslimit")
}
@ -53,7 +53,7 @@ actual object PasswordHash {
password.encodeToUByteArray().toUInt8Array(),
opslimit.toUInt(),
memlimit.toUInt()
).encodeToUByteArray()
)
}
/**
@ -63,7 +63,7 @@ actual object PasswordHash {
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
actual fun strNeedsRehash(
passwordHash: UByteArray,
passwordHash: String,
opslimit: ULong,
memlimit: Int
): Int {
@ -72,7 +72,7 @@ actual object PasswordHash {
}
return if (
getSodium().crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray().decodeToString(),
passwordHash,
opslimit.toUInt(),
memlimit.toUInt()
)
@ -88,9 +88,9 @@ actual object PasswordHash {
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
actual fun strVerify(passwordHash: String, password: String): Boolean {
return getSodium().crypto_pwhash_str_verify(
passwordHash.asByteArray().decodeToString(),
passwordHash,
password.encodeToUByteArray().toUInt8Array()
)
}

View File

@ -1108,7 +1108,7 @@ interface JnaLibsodiumInterface : Library {
// int crypto_pwhash_str_needs_rehash(const char str[crypto_pwhash_STRBYTES],
// unsigned long long opslimit, size_t memlimit)
fun crypto_pwhash_str_needs_rehash(
output: ByteArray,
output: String,
opslimit: Long,
memlimit: Long
) : Int
@ -1116,7 +1116,7 @@ interface JnaLibsodiumInterface : Library {
// const char * const passwd,
// unsigned long long passwdlen)
fun crypto_pwhash_str_verify(
hash: ByteArray,
hash: String,
password: String,
passwordLength: Long
) : Int

View File

@ -1,7 +1,6 @@
package com.ionspin.kotlin.crypto.pwhash
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
import com.sun.jna.NativeLong
actual object PasswordHash {
/**
@ -46,7 +45,7 @@ actual object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
val output = ByteArray(crypto_pwhash_STRBYTES)
sodiumJna.crypto_pwhash_str(
output,
@ -55,7 +54,7 @@ actual object PasswordHash {
opslimit.toLong(),
memlimit.toLong()
)
return output.asUByteArray()
return output.decodeToString()
}
/**
@ -65,12 +64,12 @@ actual object PasswordHash {
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
actual fun strNeedsRehash(
passwordHash: UByteArray,
passwordHash: String,
opslimit: ULong,
memlimit: Int
): Int {
return sodiumJna.crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray(),
passwordHash,
opslimit.toLong(),
memlimit.toLong()
)
@ -81,9 +80,9 @@ actual object PasswordHash {
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
actual fun strVerify(passwordHash: String, password: String): Boolean {
val result = sodiumJna.crypto_pwhash_str_verify(
passwordHash.asByteArray(),
passwordHash,
password,
password.length.toLong()
)

View File

@ -4,7 +4,6 @@ import com.ionspin.kotlin.crypto.util.toPtr
import kotlinx.cinterop.addressOf
import kotlinx.cinterop.convert
import kotlinx.cinterop.pin
import kotlinx.cinterop.toCValues
import libsodium.crypto_pwhash
import libsodium.crypto_pwhash_str
import libsodium.crypto_pwhash_str_needs_rehash
@ -61,7 +60,7 @@ actual object PasswordHash {
* and other data stores. No extra information has to be stored in order to verify the password.
* The function returns 0 on success and -1 if it didn't complete successfully.
*/
actual fun str(password: String, opslimit: ULong, memlimit: Int): UByteArray {
actual fun str(password: String, opslimit: ULong, memlimit: Int): String {
val output = ByteArray(crypto_pwhash_STRBYTES)
val outputPinned = output.pin()
crypto_pwhash_str(
@ -73,7 +72,7 @@ actual object PasswordHash {
)
outputPinned.unpin()
return output.asUByteArray()
return output.decodeToString()
}
/**
@ -83,12 +82,12 @@ actual object PasswordHash {
* It returns -1 on error. If it happens, applications may want to compute a correct hash the next time the user logs in.
*/
actual fun strNeedsRehash(
passwordHash: UByteArray,
passwordHash: String,
opslimit: ULong,
memlimit: Int
): Int {
val result = crypto_pwhash_str_needs_rehash(
passwordHash.asByteArray().toCValues(),
passwordHash,
opslimit,
memlimit.convert()
)
@ -102,9 +101,9 @@ actual object PasswordHash {
* str has to be zero-terminated.
* It returns 0 if the verification succeeds, and -1 on error.
*/
actual fun strVerify(passwordHash: UByteArray, password: String): Boolean {
actual fun strVerify(passwordHash: String, password: String): Boolean {
val result = crypto_pwhash_str_verify(
passwordHash.asByteArray().toCValues(),
passwordHash,
password,
password.length.convert()
)

View File

@ -55,7 +55,7 @@ kotlin {
"windows" -> mingwX64("native")
}
}
android()
androidTarget()
runningOnLinuxx86_64 {
jvm()
js(IR) {

@ -1 +1 @@
Subproject commit 0c5ac65576f67c41cb72802d46d5f12394ea48d6
Subproject commit ac6d3909eb0cf3d211b8137c6408ca64dd7b97b3