Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/wireapp/kalium into feat…
Browse files Browse the repository at this point in the history
…/e2ei/rotate-conversation-with-e2ei-certificate
  • Loading branch information
mchenani committed Oct 25, 2023
2 parents f33b52c + 98883fd commit 21d76ce
Show file tree
Hide file tree
Showing 28 changed files with 830 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle-jvm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
1 change: 1 addition & 0 deletions logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ kotlin {
dependencies {
implementation(libs.jna)
implementation(libs.coreCryptoJvm)
implementation(libs.bouncy.castle)
}
}
val jvmTest by getting
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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<E2EIFailure, String>
}

class E2eiCertificateRepositoryImpl : E2eiCertificateRepository {
override fun getE2eiCertificate(clientId: ClientId): Either<E2EIFailure, String> {
// TODO get certificate from CoreCrypto
return Either.Left(E2EIFailure(Exception()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 21d76ce

Please sign in to comment.