Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Upgrade ktlint to v0.50 #324

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# http://editorconfig.org
root = true

[*.{kt,kts}]
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

[*]
charset = utf-8
end_of_line = lf
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ dokkaHtml.configure {
ktlint {
verbose = true
android = true
version = "0.43.2"
version = "0.50.0"
}

afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package tech.relaycorp.awaladroid
import android.content.Context
import androidx.security.crypto.EncryptedFile
import androidx.security.crypto.MasterKey
import java.io.File
import tech.relaycorp.awala.keystores.file.FileKeystoreRoot
import tech.relaycorp.awala.keystores.file.FilePrivateKeyStore
import java.io.File

internal class AndroidPrivateKeyStore(
root: FileKeystoreRoot,
Expand All @@ -20,7 +20,7 @@ internal class AndroidPrivateKeyStore(
context,
file,
masterKey,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB,
).build()

private val masterKey by lazy {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/java/tech/relaycorp/awaladroid/Awala.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tech.relaycorp.awaladroid

import android.content.Context
import java.io.File
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import tech.relaycorp.awala.keystores.file.FileCertificateStore
Expand All @@ -15,6 +14,7 @@ import tech.relaycorp.awaladroid.endpoint.RenewExpiringCertificates
import tech.relaycorp.awaladroid.storage.StorageImpl
import tech.relaycorp.awaladroid.storage.persistence.DiskPersistence
import tech.relaycorp.relaynet.nodes.EndpointManager
import java.io.File

public object Awala {
internal const val POWEB_PORT = 13276
Expand Down Expand Up @@ -42,7 +42,7 @@ public object Awala {
this.context = AwalaContext(
StorageImpl(DiskPersistence(context.filesDir.path.toString())),
GatewayClientImpl(
serviceInteractorBuilder = { ServiceInteractor(context) }
serviceInteractorBuilder = { ServiceInteractor(context) },
),
EndpointManager(androidPrivateKeyStore, fileSessionPublicKeystore),
ChannelManager {
Expand All @@ -51,7 +51,7 @@ public object Awala {
androidPrivateKeyStore,
fileSessionPublicKeystore,
fileCertificateStore,
HandleGatewayCertificateChange(androidPrivateKeyStore)
HandleGatewayCertificateChange(androidPrivateKeyStore),
)

coroutineScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ internal data class AwalaContext(
val privateKeyStore: PrivateKeyStore,
val sessionPublicKeyStore: SessionPublicKeyStore,
val certificateStore: CertificateStore,
val handleGatewayCertificateChange: HandleGatewayCertificateChange
val handleGatewayCertificateChange: HandleGatewayCertificateChange,
)
31 changes: 15 additions & 16 deletions lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package tech.relaycorp.awaladroid

import java.security.KeyPair
import java.util.logging.Level
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
Expand All @@ -28,6 +22,12 @@ import tech.relaycorp.relaynet.bindings.pdc.PDCClient
import tech.relaycorp.relaynet.bindings.pdc.ServerException
import tech.relaycorp.relaynet.messages.control.PrivateNodeRegistration
import tech.relaycorp.relaynet.messages.control.PrivateNodeRegistrationRequest
import java.security.KeyPair
import java.util.logging.Level
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

/**
* Private gateway client.
Expand All @@ -39,7 +39,7 @@ internal constructor(
private val pdcClientBuilder: () -> PDCClient =
{ PoWebClient.initLocal(port = Awala.POWEB_PORT) },
private val sendMessage: SendMessage = SendMessage(),
private val receiveMessages: ReceiveMessages = ReceiveMessages()
private val receiveMessages: ReceiveMessages = ReceiveMessages(),
) {

// Gateway
Expand All @@ -59,12 +59,12 @@ internal constructor(
bind(
Awala.GATEWAY_SYNC_ACTION,
Awala.GATEWAY_PACKAGE,
Awala.GATEWAY_SYNC_COMPONENT
Awala.GATEWAY_SYNC_COMPONENT,
)
} catch (exp: ServiceInteractor.BindFailedException) {
throw GatewayBindingException(
"Failed binding to Awala Gateway for registration",
exp
exp,
)
}
}
Expand All @@ -86,12 +86,11 @@ internal constructor(

@Throws(
RegistrationFailedException::class,
GatewayProtocolException::class
GatewayProtocolException::class,
)
internal suspend fun registerEndpoint(keyPair: KeyPair): PrivateNodeRegistration =
withContext(coroutineContext) {
try {

val preAuthSerialized = preRegister()
val request = PrivateNodeRegistrationRequest(keyPair.public, preAuthSerialized)
val requestSerialized = request.serialize(keyPair.private)
Expand All @@ -117,14 +116,14 @@ internal constructor(
@Throws(
ServiceInteractor.BindFailedException::class,
ServiceInteractor.SendFailedException::class,
GatewayProtocolException::class
GatewayProtocolException::class,
)
private suspend fun preRegister(): ByteArray {
val interactor = serviceInteractorBuilder().apply {
bind(
Awala.GATEWAY_PRE_REGISTER_ACTION,
Awala.GATEWAY_PACKAGE,
Awala.GATEWAY_PRE_REGISTER_COMPONENT
Awala.GATEWAY_PRE_REGISTER_COMPONENT,
)
}

Expand All @@ -134,7 +133,7 @@ internal constructor(
if (replyMessage.what != REGISTRATION_AUTHORIZATION) {
interactor.unbind()
cont.resumeWithException(
GatewayProtocolException("Pre-registration failed, received wrong reply")
GatewayProtocolException("Pre-registration failed, received wrong reply"),
)
return@sendMessage
}
Expand All @@ -150,7 +149,7 @@ internal constructor(
GatewayBindingException::class,
GatewayProtocolException::class,
SendMessageException::class,
RejectedMessageException::class
RejectedMessageException::class,
)
public suspend fun sendMessage(message: OutgoingMessage) {
if (gwServiceInteractor == null) {
Expand Down Expand Up @@ -178,7 +177,7 @@ internal constructor(
logger.log(
Level.SEVERE,
"Could not bind to gateway to receive new messages",
exp
exp,
)
return@withContext
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package tech.relaycorp.awaladroid.background
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import tech.relaycorp.awaladroid.Awala
import kotlin.coroutines.CoroutineContext

internal class GatewayCertificateChangeBroadcastReceiver : BroadcastReceiver() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package tech.relaycorp.awaladroid.background
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import tech.relaycorp.awaladroid.Awala
import kotlin.coroutines.CoroutineContext

internal class IncomingParcelBroadcastReceiver : BroadcastReceiver() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import android.os.Looper
import android.os.Message
import android.os.Messenger
import android.os.RemoteException
import tech.relaycorp.awaladroid.common.Logging.logger
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import tech.relaycorp.awaladroid.common.Logging.logger

internal class ServiceInteractor(
private val context: Context
private val context: Context,
) {

private var serviceConnection: ServiceConnection? = null
Expand Down Expand Up @@ -66,14 +66,14 @@ internal class ServiceInteractor(
val intent = Intent(action).apply {
component = ComponentName(
packageName,
componentName
componentName,
)
}

val bindWasSuccessful = context.bindService(
intent,
serviceConnection,
Context.BIND_AUTO_CREATE
Context.BIND_AUTO_CREATE,
)
if (!bindWasSuccessful) cont.resumeWithException(BindFailedException("Binding failed"))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/tech/relaycorp/awaladroid/common/Keys.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package tech.relaycorp.awaladroid.common

import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.security.KeyFactory
import java.security.KeyPair
import java.security.PrivateKey
import java.security.PublicKey
import java.security.interfaces.RSAPrivateCrtKey
import java.security.spec.RSAPublicKeySpec
import org.bouncycastle.jce.provider.BouncyCastleProvider

internal fun PrivateKey.toKeyPair(): KeyPair =
KeyPair(toPublicKey(), this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package tech.relaycorp.awaladroid.endpoint

import android.content.SharedPreferences
import java.security.PublicKey
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import tech.relaycorp.relaynet.wrappers.nodeId
import java.security.PublicKey
import kotlin.coroutines.CoroutineContext

internal class ChannelManager(
internal val coroutineContext: CoroutineContext = Dispatchers.IO,
sharedPreferencesGetter: () -> SharedPreferences
sharedPreferencesGetter: () -> SharedPreferences,
) {
internal val sharedPreferences by lazy(sharedPreferencesGetter)

suspend fun create(
firstPartyEndpoint: FirstPartyEndpoint,
thirdPartyEndpoint: ThirdPartyEndpoint
thirdPartyEndpoint: ThirdPartyEndpoint,
) {
create(firstPartyEndpoint, thirdPartyEndpoint.nodeId)
}

suspend fun create(
firstPartyEndpoint: FirstPartyEndpoint,
thirdPartyEndpointPublicKey: PublicKey
thirdPartyEndpointPublicKey: PublicKey,
) {
create(firstPartyEndpoint, thirdPartyEndpointPublicKey.nodeId)
}

private suspend fun create(
firstPartyEndpoint: FirstPartyEndpoint,
thirdPartyEndpointNodeId: String
thirdPartyEndpointNodeId: String,
) {
withContext(coroutineContext) {
val originalValue =
Expand All @@ -38,7 +38,7 @@ internal class ChannelManager(
with(sharedPreferences.edit()) {
putStringSet(
firstPartyEndpoint.nodeId,
originalValue + mutableListOf(thirdPartyEndpointNodeId)
originalValue + mutableListOf(thirdPartyEndpointNodeId),
)
commit()
}
Expand All @@ -57,7 +57,7 @@ internal class ChannelManager(
}

suspend fun delete(
thirdPartyEndpoint: ThirdPartyEndpoint
thirdPartyEndpoint: ThirdPartyEndpoint,
) {
withContext(coroutineContext) {
sharedPreferences.all.forEach { (key, value) ->
Expand Down Expand Up @@ -85,7 +85,7 @@ internal class ChannelManager(
withContext(coroutineContext) {
return@withContext sharedPreferences.getStringSet(
firstPartyEndpoint.nodeId,
emptySet()
emptySet(),
) ?: emptySet()
}
}
Loading
Loading