From 290418d9b924aae4480617720fb678857cb77bf7 Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Wed, 25 Oct 2023 12:59:45 +0200 Subject: [PATCH 1/2] feat: create use case for getting e2ei certificate (WPB-3214) (#2129) * feat: create use case for getting e2ei certificate * chore: detekt * chore: add missing documentation * chore: address comments * chore: detekt * chore: add empty line * chore: add missing unit test * chore: detekt * chore: address comments * chore: cleanup --------- Co-authored-by: Mojtaba Chenani --- gradle/libs.versions.toml | 4 + logic/build.gradle.kts | 1 + .../feature/e2ei/CertificateStatusChecker.kt | 28 ++++ .../feature/e2ei/PemCertificateDecoder.kt | 31 +++++ .../feature/e2ei/PlatformX509Certificate.kt | 20 +++ .../feature/e2ei/X509CertificateGenerator.kt | 28 ++++ .../feature/e2ei/CertificateStatusChecker.kt | 36 +++++ .../feature/e2ei/PemCertificateDecoder.kt | 42 ++++++ .../feature/e2ei/PlatformX509Certificate.kt | 24 ++++ .../feature/e2ei/X509CertificateGenerator.kt | 37 +++++ .../data/e2ei/E2eiCertificateRepository.kt | 33 +++++ .../kalium/logic/feature/UserSessionScope.kt | 4 +- .../logic/feature/e2ei/CertificateStatus.kt | 24 ++++ .../feature/e2ei/CertificateStatusChecker.kt | 24 ++++ .../logic/feature/e2ei/E2eiCertificate.kt | 25 ++++ .../feature/e2ei/PemCertificateDecoder.kt | 27 ++++ .../feature/e2ei/PlatformX509Certificate.kt | 20 +++ .../feature/e2ei/X509CertificateGenerator.kt | 24 ++++ .../e2ei/{ => usecase}/EnrollE2EIUseCase.kt | 2 +- .../e2ei/usecase/GetE2EICertificateUseCase.kt | 54 ++++++++ .../kalium/logic/feature/user/UserScope.kt | 15 +- .../wire/kalium/logic/util/E2eiExtensions.kt | 31 +++++ .../e2ei/EnrollE2EICertificateUseCaseTest.kt | 2 + .../e2ei/GetE2eiCertificateUseCaseTest.kt | 115 +++++++++++++++ .../e2ei/CertificateStatusCheckerTest.kt | 52 +++++++ .../feature/e2ei/PemCertificateDecoderTest.kt | 131 ++++++++++++++++++ .../receiver/asset/AssetMessageHandlerTest.kt | 1 - 27 files changed, 829 insertions(+), 6 deletions(-) create mode 100644 logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt create mode 100644 logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt create mode 100644 logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt create mode 100644 logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt create mode 100644 logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt create mode 100644 logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt create mode 100644 logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt create mode 100644 logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/E2eiCertificateRepository.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatus.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/E2eiCertificate.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt rename logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/{ => usecase}/EnrollE2EIUseCase.kt (99%) create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetE2EICertificateUseCase.kt create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/util/E2eiExtensions.kt create mode 100644 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/GetE2eiCertificateUseCaseTest.kt create mode 100644 logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusCheckerTest.kt create mode 100644 logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoderTest.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ebaa9590510..4c1582ad678 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -55,6 +55,7 @@ faker = "1.14.0" robolectric = "4.9" stately = "2.0.0-rc3" micrometer = "1.11.3" +bouncy-castle = "1.70" [plugins] # Home-made convention plugins @@ -192,3 +193,6 @@ jna = { module = "net.java.dev.jna:jna", version.ref = "jna" } # logging kermit = { module = "co.touchlab:kermit", version.ref = "kermit" } micrometer = { module = "io.micrometer:micrometer-registry-prometheus", version.ref = "micrometer" } + +# bouncy castle +bouncy-castle = { module = "org.bouncycastle:bcprov-jdk15on", version.ref = "bouncy-castle" } diff --git a/logic/build.gradle.kts b/logic/build.gradle.kts index eb435d41d15..f64c16871bd 100644 --- a/logic/build.gradle.kts +++ b/logic/build.gradle.kts @@ -96,6 +96,7 @@ kotlin { dependencies { implementation(libs.jna) implementation(libs.coreCryptoJvm) + implementation(libs.bouncy.castle) } } val jvmTest by getting diff --git a/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt new file mode 100644 index 00000000000..dca61f435c1 --- /dev/null +++ b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt @@ -0,0 +1,28 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +actual interface CertificateStatusChecker { + actual fun status(notAfterTimestamp: Long): CertificateStatus +} + +actual class CertificateStatusCheckerImpl : CertificateStatusChecker { + override fun status(notAfterTimestamp: Long): CertificateStatus { + TODO("Not yet implemented") + } +} diff --git a/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt new file mode 100644 index 00000000000..321f41490e6 --- /dev/null +++ b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt @@ -0,0 +1,31 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +actual interface PemCertificateDecoder { + actual fun decode(certificate: String): E2eiCertificate +} + +actual class PemCertificateDecoderImpl actual constructor( + private val x509CertificateGenerator: X509CertificateGenerator, + private val certificateStatusChecker: CertificateStatusChecker +) : PemCertificateDecoder { + override fun decode(certificate: String): E2eiCertificate { + TODO("Not yet implemented") + } +} diff --git a/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt new file mode 100644 index 00000000000..f81a3f122c3 --- /dev/null +++ b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt @@ -0,0 +1,20 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +actual class PlatformX509Certificate diff --git a/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt new file mode 100644 index 00000000000..2dd38fba90a --- /dev/null +++ b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt @@ -0,0 +1,28 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +actual interface X509CertificateGenerator { + actual fun generate(certificateByteArray: ByteArray): PlatformX509Certificate +} + +actual class X509CertificateGeneratorImpl : X509CertificateGenerator { + override fun generate(certificateByteArray: ByteArray): PlatformX509Certificate { + TODO("Not yet implemented") + } +} diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt new file mode 100644 index 00000000000..661bc3372ad --- /dev/null +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt @@ -0,0 +1,36 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import java.util.Date + +actual interface CertificateStatusChecker { + actual fun status(notAfterTimestamp: Long): CertificateStatus +} + +actual class CertificateStatusCheckerImpl : CertificateStatusChecker { + override fun status(notAfterTimestamp: Long): CertificateStatus { + // TODO check for revoked from coreCrypto when API is ready + + val current = Date() + println("current timestap is ${current.time}") + if (current.time >= notAfterTimestamp) + return CertificateStatus.EXPIRED + return CertificateStatus.VALID + } +} diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt new file mode 100644 index 00000000000..25fcbfc38d7 --- /dev/null +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt @@ -0,0 +1,42 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import com.wire.kalium.logic.util.serialNumber + +actual interface PemCertificateDecoder { + actual fun decode(certificate: String): E2eiCertificate +} + +actual class PemCertificateDecoderImpl actual constructor( + private val x509CertificateGenerator: X509CertificateGenerator, + private val certificateStatusChecker: CertificateStatusChecker +) : PemCertificateDecoder { + override fun decode(certificate: String): E2eiCertificate { + x509CertificateGenerator.generate(certificate.toByteArray()).also { + return E2eiCertificate( + issuer = it.value.issuerX500Principal.name, + status = certificateStatusChecker.status(it.value.notAfter.time), + serialNumber = it.value.serialNumber.toString(BASE_16).serialNumber(), + certificateDetail = certificate + ) + } + } +} + +private const val BASE_16 = 16 diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt new file mode 100644 index 00000000000..b0343e59986 --- /dev/null +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt @@ -0,0 +1,24 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import java.security.cert.X509Certificate + +actual class PlatformX509Certificate( + val value: X509Certificate +) diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt new file mode 100644 index 00000000000..44a49d2b2c2 --- /dev/null +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt @@ -0,0 +1,37 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import java.io.ByteArrayInputStream +import java.security.cert.CertificateFactory +import java.security.cert.X509Certificate + +actual interface X509CertificateGenerator { + actual fun generate(certificateByteArray: ByteArray): PlatformX509Certificate +} + +actual class X509CertificateGeneratorImpl : X509CertificateGenerator { + override fun generate(certificateByteArray: ByteArray): PlatformX509Certificate { + return PlatformX509Certificate( + CertificateFactory.getInstance(TYPE) + .generateCertificate(ByteArrayInputStream(certificateByteArray)) as X509Certificate + ) + } +} + +private const val TYPE = "X.509" diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/E2eiCertificateRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/E2eiCertificateRepository.kt new file mode 100644 index 00000000000..d04ecbed8d3 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/E2eiCertificateRepository.kt @@ -0,0 +1,33 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.data.e2ei + +import com.wire.kalium.logic.E2EIFailure +import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.functional.Either + +interface E2eiCertificateRepository { + fun getE2eiCertificate(clientId: ClientId): Either +} + +class E2eiCertificateRepositoryImpl : E2eiCertificateRepository { + override fun getE2eiCertificate(clientId: ClientId): Either { + // TODO get certificate from CoreCrypto + return Either.Left(E2EIFailure(Exception())) + } +} diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 6238ec052c6..b5f99acf6ab 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -188,8 +188,8 @@ import com.wire.kalium.logic.feature.conversation.mls.OneOnOneMigratorImpl import com.wire.kalium.logic.feature.conversation.mls.OneOnOneResolver import com.wire.kalium.logic.feature.conversation.mls.OneOnOneResolverImpl import com.wire.kalium.logic.feature.debug.DebugScope -import com.wire.kalium.logic.feature.e2ei.EnrollE2EIUseCase -import com.wire.kalium.logic.feature.e2ei.EnrollE2EIUseCaseImpl +import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCase +import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCaseImpl import com.wire.kalium.logic.feature.featureConfig.SyncFeatureConfigsUseCase import com.wire.kalium.logic.feature.featureConfig.SyncFeatureConfigsUseCaseImpl import com.wire.kalium.logic.feature.featureConfig.handler.AppLockConfigHandler diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatus.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatus.kt new file mode 100644 index 00000000000..09fbddbb79d --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatus.kt @@ -0,0 +1,24 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +enum class CertificateStatus { + REVOKED, + EXPIRED, + VALID +} diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt new file mode 100644 index 00000000000..3650b4d04d8 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusChecker.kt @@ -0,0 +1,24 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +expect interface CertificateStatusChecker { + fun status(notAfterTimestamp: Long): CertificateStatus +} + +expect class CertificateStatusCheckerImpl() : CertificateStatusChecker diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/E2eiCertificate.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/E2eiCertificate.kt new file mode 100644 index 00000000000..e109f09f428 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/E2eiCertificate.kt @@ -0,0 +1,25 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +data class E2eiCertificate( + val issuer: String = "", + val status: CertificateStatus = CertificateStatus.EXPIRED, + val serialNumber: String = "", + val certificateDetail: String = "" +) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt new file mode 100644 index 00000000000..fe46b545584 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoder.kt @@ -0,0 +1,27 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +expect interface PemCertificateDecoder { + fun decode(certificate: String): E2eiCertificate +} + +expect class PemCertificateDecoderImpl( + x509CertificateGenerator: X509CertificateGenerator = X509CertificateGeneratorImpl(), + certificateStatusChecker: CertificateStatusChecker = CertificateStatusCheckerImpl() +) : PemCertificateDecoder diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt new file mode 100644 index 00000000000..02bdd26be72 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/PlatformX509Certificate.kt @@ -0,0 +1,20 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +expect class PlatformX509Certificate diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt new file mode 100644 index 00000000000..f3365a2b7c4 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/X509CertificateGenerator.kt @@ -0,0 +1,24 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +expect interface X509CertificateGenerator { + fun generate(certificateByteArray: ByteArray): PlatformX509Certificate +} + +expect class X509CertificateGeneratorImpl : X509CertificateGenerator diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EIUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/EnrollE2EIUseCase.kt similarity index 99% rename from logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EIUseCase.kt rename to logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/EnrollE2EIUseCase.kt index 7c67b6a92e4..a144f91d0fc 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EIUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/EnrollE2EIUseCase.kt @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ -package com.wire.kalium.logic.feature.e2ei +package com.wire.kalium.logic.feature.e2ei.usecase import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.E2EIFailure diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetE2EICertificateUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetE2EICertificateUseCase.kt new file mode 100644 index 00000000000..179f048a829 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/e2ei/usecase/GetE2EICertificateUseCase.kt @@ -0,0 +1,54 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei.usecase + +import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.e2ei.E2eiCertificateRepository +import com.wire.kalium.logic.feature.e2ei.E2eiCertificate +import com.wire.kalium.logic.feature.e2ei.PemCertificateDecoder +import com.wire.kalium.logic.functional.fold + +/** + * This use case is used to get the e2ei certificate + */ +interface GetE2eiCertificateUseCase { + operator fun invoke(clientId: ClientId): GetE2EICertificateUseCaseResult +} + +class GetE2eiCertificateUseCaseImpl( + private val e2eiCertificateRepository: E2eiCertificateRepository, + private val pemCertificateDecoder: PemCertificateDecoder +) : GetE2eiCertificateUseCase { + override operator fun invoke(clientId: ClientId): GetE2EICertificateUseCaseResult = + e2eiCertificateRepository.getE2eiCertificate(clientId).fold( + { + GetE2EICertificateUseCaseResult.Failure.NotActivated + }, + { + val certificate = pemCertificateDecoder.decode(it) + GetE2EICertificateUseCaseResult.Success(certificate) + } + ) +} + +sealed class GetE2EICertificateUseCaseResult { + class Success(val certificate: E2eiCertificate) : GetE2EICertificateUseCaseResult() + sealed class Failure : GetE2EICertificateUseCaseResult() { + data object NotActivated : Failure() + } +} diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UserScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UserScope.kt index a0cad86fe92..2381ac7adf4 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UserScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/UserScope.kt @@ -22,6 +22,7 @@ import com.wire.kalium.logic.configuration.server.ServerConfigRepository import com.wire.kalium.logic.data.asset.AssetRepository import com.wire.kalium.logic.data.connection.ConnectionRepository import com.wire.kalium.logic.data.e2ei.E2EIRepository +import com.wire.kalium.logic.data.e2ei.E2eiCertificateRepositoryImpl import com.wire.kalium.logic.data.id.QualifiedIdMapper import com.wire.kalium.logic.data.properties.UserPropertyRepository import com.wire.kalium.logic.data.publicuser.SearchUserRepository @@ -41,8 +42,11 @@ import com.wire.kalium.logic.feature.asset.GetAvatarAssetUseCaseImpl import com.wire.kalium.logic.feature.auth.ValidateUserHandleUseCase import com.wire.kalium.logic.feature.auth.ValidateUserHandleUseCaseImpl import com.wire.kalium.logic.feature.conversation.GetAllContactsNotInConversationUseCase -import com.wire.kalium.logic.feature.e2ei.EnrollE2EIUseCase -import com.wire.kalium.logic.feature.e2ei.EnrollE2EIUseCaseImpl +import com.wire.kalium.logic.feature.e2ei.PemCertificateDecoderImpl +import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCase +import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCaseImpl +import com.wire.kalium.logic.feature.e2ei.usecase.GetE2eiCertificateUseCase +import com.wire.kalium.logic.feature.e2ei.usecase.GetE2eiCertificateUseCaseImpl import com.wire.kalium.logic.feature.message.MessageSender import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCase import com.wire.kalium.logic.feature.publicuser.GetAllContactsUseCaseImpl @@ -103,8 +107,15 @@ class UserScope internal constructor( userRepository, qualifiedIdMapper ) + + private val e2eiCertificateRepository by lazy { E2eiCertificateRepositoryImpl() } + private val pemCertificateDecoderImpl by lazy { PemCertificateDecoderImpl() } val getPublicAsset: GetAvatarAssetUseCase get() = GetAvatarAssetUseCaseImpl(assetRepository, userRepository) val enrollE2EI: EnrollE2EIUseCase get() = EnrollE2EIUseCaseImpl(e2EIRepository) + val getE2EICertificate: GetE2eiCertificateUseCase get() = GetE2eiCertificateUseCaseImpl( + e2eiCertificateRepository = e2eiCertificateRepository, + pemCertificateDecoder = pemCertificateDecoderImpl + ) val deleteAsset: DeleteAssetUseCase get() = DeleteAssetUseCaseImpl(assetRepository) val setUserHandle: SetUserHandleUseCase get() = SetUserHandleUseCase(accountRepository, validateUserHandleUseCase, syncManager) val getAllKnownUsers: GetAllContactsUseCase get() = GetAllContactsUseCaseImpl(userRepository) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/util/E2eiExtensions.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/util/E2eiExtensions.kt new file mode 100644 index 00000000000..b068fdef4b6 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/util/E2eiExtensions.kt @@ -0,0 +1,31 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +package com.wire.kalium.logic.util + +/** + * This extension function is used to format the serial number of the certificate. + * output will be in the format of 2 bytes separated by a colon. + * e.g. 01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F:10 + */ +fun String.serialNumber() = this.chunked(CHUNK_SIZE) + .joinToString(SEPARATOR) + .uppercase() + +private const val CHUNK_SIZE = 2 +private const val SEPARATOR = ":" diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EICertificateUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EICertificateUseCaseTest.kt index 07ea421d279..c7e69aaf8da 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EICertificateUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/EnrollE2EICertificateUseCaseTest.kt @@ -23,6 +23,8 @@ import com.wire.kalium.cryptography.NewAcmeAuthz import com.wire.kalium.cryptography.NewAcmeOrder import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.data.e2ei.E2EIRepository +import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCase +import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCaseImpl import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.util.shouldFail import com.wire.kalium.logic.util.shouldSucceed diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/GetE2eiCertificateUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/GetE2eiCertificateUseCaseTest.kt new file mode 100644 index 00000000000..4ecd7435c19 --- /dev/null +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/e2ei/GetE2eiCertificateUseCaseTest.kt @@ -0,0 +1,115 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import com.wire.kalium.logic.E2EIFailure +import com.wire.kalium.logic.data.e2ei.E2eiCertificateRepository +import com.wire.kalium.logic.feature.e2ei.usecase.GetE2eiCertificateUseCaseImpl +import com.wire.kalium.logic.functional.Either +import io.mockative.Mock +import io.mockative.any +import io.mockative.classOf +import io.mockative.given +import io.mockative.mock +import io.mockative.once +import io.mockative.verify +import kotlin.test.Test +import kotlin.test.assertEquals +import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.feature.e2ei.usecase.GetE2EICertificateUseCaseResult + +class GetE2eiCertificateUseCaseTest { + + @Test + fun givenRepositoryReturnsFailure_whenRunningUseCase_thenReturnNotActivated() { + val (arrangement, getE2eiCertificateUseCase) = Arrangement() + .withRepositoryFailure() + .arrange() + + val result = getE2eiCertificateUseCase.invoke(CLIENT_ID) + + verify(arrangement.e2eiCertificateRepository) + .function(arrangement.e2eiCertificateRepository::getE2eiCertificate) + .with(any()) + .wasInvoked(once) + + assertEquals(GetE2EICertificateUseCaseResult.Failure.NotActivated, result) + } + + @Test + fun givenRepositoryReturnsValidCertificateString_whenRunningUseCase_thenReturnCertificate() { + val (arrangement, getE2eiCertificateUseCase) = Arrangement() + .withRepositoryValidCertificate() + .withDecodeSuccess() + .arrange() + + val result = getE2eiCertificateUseCase.invoke(CLIENT_ID) + + verify(arrangement.e2eiCertificateRepository) + .function(arrangement.e2eiCertificateRepository::getE2eiCertificate) + .with(any()) + .wasInvoked(once) + + verify(arrangement.pemCertificateDecoder) + .function(arrangement.pemCertificateDecoder::decode) + .with(any()) + .wasInvoked(once) + + assertEquals(true, result is GetE2EICertificateUseCaseResult.Success) + } + + class Arrangement { + + @Mock + val e2eiCertificateRepository = mock(classOf()) + + @Mock + val pemCertificateDecoder = mock(classOf()) + + fun arrange() = this to GetE2eiCertificateUseCaseImpl( + e2eiCertificateRepository = e2eiCertificateRepository, + pemCertificateDecoder = pemCertificateDecoder + ) + + fun withRepositoryFailure() = apply { + given(e2eiCertificateRepository) + .function(e2eiCertificateRepository::getE2eiCertificate) + .whenInvokedWith(any()) + .thenReturn(Either.Left(E2EIFailure(Exception()))) + } + + fun withRepositoryValidCertificate() = apply { + given(e2eiCertificateRepository) + .function(e2eiCertificateRepository::getE2eiCertificate) + .whenInvokedWith(any()) + .thenReturn(Either.Right("certificate")) + } + + fun withDecodeSuccess() = apply { + given(pemCertificateDecoder) + .function(pemCertificateDecoder::decode) + .whenInvokedWith(any()) + .thenReturn(e2eiCertificate) + } + } + + companion object { + val CLIENT_ID = ClientId("client-id") + val e2eiCertificate = E2eiCertificate("certificate") + } +} diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusCheckerTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusCheckerTest.kt new file mode 100644 index 00000000000..dcd33e61de9 --- /dev/null +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/CertificateStatusCheckerTest.kt @@ -0,0 +1,52 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import org.junit.Test +import kotlin.test.assertEquals + +class CertificateStatusCheckerTest { + + @Test + fun givenOldTimestamp_whenCheckingTheStatus_thenReturnExpired() { + val timestamp: Long = 1666681915000 // Tuesday, 25 October 2022 07:11:55 + val (_, certificateStatusChecker) = Arrangement() + .arrange() + + val result = certificateStatusChecker.status(timestamp) + + assertEquals(CertificateStatus.EXPIRED, result) + } + + @Test + fun givenFutureTimestamp_whenCheckingTheStatus_thenReturnValid() { + val timestamp = 4822355515000 // Sunday, 25 October 2122 07:11:55 + + val (_, certificateStatusChecker) = Arrangement() + .arrange() + + val result = certificateStatusChecker.status(timestamp) + + assertEquals(CertificateStatus.VALID, result) + } + + class Arrangement { + + fun arrange() = this to CertificateStatusCheckerImpl() + } +} \ No newline at end of file diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoderTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoderTest.kt new file mode 100644 index 00000000000..1561b06e9c0 --- /dev/null +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/e2ei/PemCertificateDecoderTest.kt @@ -0,0 +1,131 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.e2ei + +import io.mockative.Mock +import io.mockative.any +import io.mockative.classOf +import io.mockative.given +import io.mockative.mock +import io.mockative.once +import io.mockative.verify +import org.junit.Test +import java.security.cert.CertificateException +import kotlin.test.assertEquals + +class PemCertificateDecoderTest { + + @Test + fun givenAValidCertificate_whenDecodingIt_thenReturnCertificateObject() { + val expectedCertificate = E2eiCertificate( + issuer = "CN=wire Intermediate CA,O=wire", + status = CertificateStatus.VALID, + serialNumber = "60:88:F6:3E:97:4F:2E:AB:50:5C:C9:B1:D1:39:97:BA", + certificateDetail = validPemCertificateString + ) + val (arrangement, pemCertificateDecoder) = Arrangement() + .withCertificate(validPemCertificateString) + .withValidStatus() + .arrange() + + val result = pemCertificateDecoder.decode(validPemCertificateString) + + verify(arrangement.x509CertificateGeneratorMock) + .function(arrangement.x509CertificateGeneratorMock::generate) + .with(any()) + .wasInvoked(once) + + assertEquals(expectedCertificate, result) + } + + @Test(expected = CertificateException::class) + fun givenAnInValidCertificate_whenDecodingIt_thenThrowCertificateException() { + val (_, pemCertificateDecoder) = Arrangement() + .withCertificate(invalidPemCertificateString) + .withValidStatus() + .arrange() + + pemCertificateDecoder.decode(invalidPemCertificateString) + } + + class Arrangement { + + @Mock + val x509CertificateGeneratorMock = mock(classOf()) + + @Mock + val certificateStatusChecker = mock(classOf()) + + fun arrange() = this to PemCertificateDecoderImpl( + x509CertificateGeneratorMock, + certificateStatusChecker + ) + + fun withCertificate(certificateString: String) = apply { + val platformCertificate = createPlatformX509Certificate(certificateString) + given(x509CertificateGeneratorMock) + .function(x509CertificateGeneratorMock::generate) + .whenInvokedWith(any()) + .thenReturn(platformCertificate) + } + + fun withValidStatus() = apply { + given(certificateStatusChecker) + .function(certificateStatusChecker::status) + .whenInvokedWith(any()) + .thenReturn(CertificateStatus.VALID) + } + + private fun createPlatformX509Certificate(certificateString: String): PlatformX509Certificate { + val x509CertificateGenerator = X509CertificateGeneratorImpl() + + return x509CertificateGenerator.generate(certificateString.toByteArray()) + } + } + + companion object { + const val validPemCertificateString = "-----BEGIN CERTIFICATE-----\n" + + "MIICNDCCAdqgAwIBAgIQYIj2PpdPLqtQXMmx0TmXujAKBggqhkjOPQQDAjAuMQ0w\n" + + "CwYDVQQKEwR3aXJlMR0wGwYDVQQDExR3aXJlIEludGVybWVkaWF0ZSBDQTAeFw0y\n" + + "MzEwMDIxNTIyMjJaFw0yMzEyMzExNTIyMjJaMDMxFzAVBgNVBAoTDmVsbmEud2ly\n" + + "ZS5saW5rMRgwFgYDVQQDEw9Nb2p0YWJhIENoZW5hbmkwKjAFBgMrZXADIQAonK3u\n" + + "cLIUnWP+8iG2GdabCWmzfiHTgXMncNx/r064LKOCAQIwgf8wDgYDVR0PAQH/BAQD\n" + + "AgeAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUhVb7\n" + + "GEXzaKxm3yiNEV0DOd78LBcwHwYDVR0jBBgwFoAUADMwoCFunlLkYO2SQbOAUOIL\n" + + "VCowZQYDVR0RBF4wXIZBaW06d2lyZWFwcD1JRzlZdnp1V1FJS1VhUmsxMkY1Q0lR\n" + + "Lzk1MzIxOGU2OGE2MzY0MWZAZWxuYS53aXJlLmxpbmuGF2ltOndpcmVhcHA9bW9q\n" + + "dGFiYV93aXJlMCcGDCsGAQQBgqRkxihAAQQXMBUCAQYEDmdvb2dsZS1hbmRyb2lk\n" + + "BAAwCgYIKoZIzj0EAwIDSAAwRQIhAJORy8WUjP8spjxlCCNOCAQrPIUbl6BTQGtv\n" + + "FhJqP3UrAiAC4mbuQ6BlVmiovCzqP1YbiaGimvBEm/XTwtWJE6wM0A==\n" + + "-----END CERTIFICATE-----\n" + + "-----BEGIN CERTIFICATE-----\n" + + "MIIBuDCCAV6gAwIBAgIQUJ8AHZqe79OeFVEPkdtQrDAKBggqhkjOPQQDAjAmMQ0w\n" + + "CwYDVQQKEwR3aXJlMRUwEwYDVQQDEwx3aXJlIFJvb3QgQ0EwHhcNMjMwNDE3MDkw\n" + + "ODQxWhcNMzMwNDE0MDkwODQxWjAuMQ0wCwYDVQQKEwR3aXJlMR0wGwYDVQQDExR3\n" + + "aXJlIEludGVybWVkaWF0ZSBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABB9p\n" + + "iYVv5ik10pwkOGdwVI6F6a8YKk9Ro/CqahPcTfefhOhL/M5RxzWmi2oW75mW6WKr\n" + + "tG94D45Ur6yfNclLspmjZjBkMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAG\n" + + "AQH/AgEAMB0GA1UdDgQWBBQAMzCgIW6eUuRg7ZJBs4BQ4gtUKjAfBgNVHSMEGDAW\n" + + "gBR40ZJlSIKIjEI/4ZMwgV3X5CB7tDAKBggqhkjOPQQDAgNIADBFAiEA5VT2B38E\n" + + "9EunvJiLRCG9baeeMq4Yn1LwOT10cXdUIIICIEnDUrd2XW69YnUIPF3bEHln3oKt\n" + + "wje0yUIA61GMpqNz\n" + + "-----END CERTIFICATE-----" + + const val invalidPemCertificateString = "dsverlkerkvekvkadxjwencwejjk" + } +} diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt index 309d50d52c3..dd82921898c 100644 --- a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt @@ -48,7 +48,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.Test -@OptIn(ExperimentalCoroutinesApi::class) class AssetMessageHandlerTest { @Test From 98883fd54b4a44fecb0f70bb1053ee0a79bff08c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:00:15 +0000 Subject: [PATCH 2/2] chore(deps): bump codecov/codecov-action from 2 to 3 (#2161) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 2 to 3. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v2...v3) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yamil Medina --- .github/workflows/gradle-jvm-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-jvm-tests.yml b/.github/workflows/gradle-jvm-tests.yml index 26cca892399..d783fad54a4 100644 --- a/.github/workflows/gradle-jvm-tests.yml +++ b/.github/workflows/gradle-jvm-tests.yml @@ -84,7 +84,7 @@ jobs: **/build/test-results/**/*.xml - name: Upload Test Report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 with: files: "build/reports/kover/report.xml"