diff --git a/.editorconfig b/.editorconfig index 0f5cbac9..aec9a137 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/lib/build.gradle b/lib/build.gradle index f365c5a5..d1b0da87 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -121,7 +121,7 @@ dokkaHtml.configure { ktlint { verbose = true android = true - version = "0.43.2" + version = "0.50.0" } afterEvaluate { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStore.kt b/lib/src/main/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStore.kt index 4f2394ff..bcaed7f9 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStore.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStore.kt @@ -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, @@ -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 { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/Awala.kt b/lib/src/main/java/tech/relaycorp/awaladroid/Awala.kt index 5c4ce251..e463e8e7 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/Awala.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/Awala.kt @@ -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 @@ -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 @@ -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 { @@ -51,7 +51,7 @@ public object Awala { androidPrivateKeyStore, fileSessionPublicKeystore, fileCertificateStore, - HandleGatewayCertificateChange(androidPrivateKeyStore) + HandleGatewayCertificateChange(androidPrivateKeyStore), ) coroutineScope { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/AwalaContext.kt b/lib/src/main/java/tech/relaycorp/awaladroid/AwalaContext.kt index 7a7fcd63..20cc9a8c 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/AwalaContext.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/AwalaContext.kt @@ -16,5 +16,5 @@ internal data class AwalaContext( val privateKeyStore: PrivateKeyStore, val sessionPublicKeyStore: SessionPublicKeyStore, val certificateStore: CertificateStore, - val handleGatewayCertificateChange: HandleGatewayCertificateChange + val handleGatewayCertificateChange: HandleGatewayCertificateChange, ) diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt b/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt index d044ead1..7e97367e 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/GatewayClientImpl.kt @@ -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 @@ -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. @@ -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 @@ -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, ) } } @@ -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) @@ -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, ) } @@ -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 } @@ -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) { @@ -178,7 +177,7 @@ internal constructor( logger.log( Level.SEVERE, "Could not bind to gateway to receive new messages", - exp + exp, ) return@withContext } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/background/GatewayCertificateChangeBroadcastReceiver.kt b/lib/src/main/java/tech/relaycorp/awaladroid/background/GatewayCertificateChangeBroadcastReceiver.kt index 442eedbb..c22e3367 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/background/GatewayCertificateChangeBroadcastReceiver.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/background/GatewayCertificateChangeBroadcastReceiver.kt @@ -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() { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/background/IncomingParcelBroadcastReceiver.kt b/lib/src/main/java/tech/relaycorp/awaladroid/background/IncomingParcelBroadcastReceiver.kt index 67903421..c56d7560 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/background/IncomingParcelBroadcastReceiver.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/background/IncomingParcelBroadcastReceiver.kt @@ -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() { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/background/ServiceInteractor.kt b/lib/src/main/java/tech/relaycorp/awaladroid/background/ServiceInteractor.kt index 06ee8a9e..6d29508c 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/background/ServiceInteractor.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/background/ServiceInteractor.kt @@ -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 @@ -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")) } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/common/Keys.kt b/lib/src/main/java/tech/relaycorp/awaladroid/common/Keys.kt index 13af152f..6878e965 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/common/Keys.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/common/Keys.kt @@ -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) diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ChannelManager.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ChannelManager.kt index e1566b9e..d7122998 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ChannelManager.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ChannelManager.kt @@ -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 = @@ -38,7 +38,7 @@ internal class ChannelManager( with(sharedPreferences.edit()) { putStringSet( firstPartyEndpoint.nodeId, - originalValue + mutableListOf(thirdPartyEndpointNodeId) + originalValue + mutableListOf(thirdPartyEndpointNodeId), ) commit() } @@ -57,7 +57,7 @@ internal class ChannelManager( } suspend fun delete( - thirdPartyEndpoint: ThirdPartyEndpoint + thirdPartyEndpoint: ThirdPartyEndpoint, ) { withContext(coroutineContext) { sharedPreferences.all.forEach { (key, value) -> @@ -85,7 +85,7 @@ internal class ChannelManager( withContext(coroutineContext) { return@withContext sharedPreferences.getStringSet( firstPartyEndpoint.nodeId, - emptySet() + emptySet(), ) ?: emptySet() } } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt index d58d27f7..840dc776 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpoint.kt @@ -1,9 +1,5 @@ package tech.relaycorp.awaladroid.endpoint -import java.security.PrivateKey -import java.security.PublicKey -import java.time.ZonedDateTime -import java.util.logging.Level import tech.relaycorp.awaladroid.Awala import tech.relaycorp.awaladroid.AwaladroidException import tech.relaycorp.awaladroid.GatewayProtocolException @@ -24,6 +20,10 @@ import tech.relaycorp.relaynet.wrappers.generateRSAKeyPair import tech.relaycorp.relaynet.wrappers.nodeId import tech.relaycorp.relaynet.wrappers.x509.Certificate import tech.relaycorp.relaynet.wrappers.x509.CertificateException +import java.security.PrivateKey +import java.security.PublicKey +import java.time.ZonedDateTime +import java.util.logging.Level /** * An endpoint owned by the current instance of the app. @@ -51,11 +51,11 @@ internal constructor( @Throws(CertificateException::class) public suspend fun issueAuthorization( thirdPartyEndpoint: ThirdPartyEndpoint, - expiryDate: ZonedDateTime + expiryDate: ZonedDateTime, ): ByteArray = issueAuthorization( thirdPartyEndpoint.identityKey, - expiryDate + expiryDate, ) /** @@ -64,7 +64,7 @@ internal constructor( @Throws(CertificateException::class) public suspend fun issueAuthorization( thirdPartyEndpointPublicKeySerialized: ByteArray, - expiryDate: ZonedDateTime + expiryDate: ZonedDateTime, ): ByteArray { val thirdPartyEndpointPublicKey = deserializePDAGranteePublicKey(thirdPartyEndpointPublicKeySerialized) @@ -74,20 +74,20 @@ internal constructor( @Throws(CertificateException::class) private suspend fun issueAuthorization( thirdPartyEndpointPublicKey: PublicKey, - expiryDate: ZonedDateTime + expiryDate: ZonedDateTime, ): ByteArray { val pda = issueDeliveryAuthorization( subjectPublicKey = thirdPartyEndpointPublicKey, issuerPrivateKey = identityPrivateKey, validityEndDate = expiryDate, - issuerCertificate = identityCertificate + issuerCertificate = identityCertificate, ) val deliveryAuth = CertificationPath(pda, pdaChain) val context = Awala.getContextOrThrow() val sessionKeyPair = context.endpointManager.generateSessionKeyPair( nodeId, - thirdPartyEndpointPublicKey.nodeId + thirdPartyEndpointPublicKey.nodeId, ) val connParams = PrivateEndpointConnParams( @@ -104,7 +104,7 @@ internal constructor( */ @Throws(CertificateException::class) public suspend fun authorizeIndefinitely( - thirdPartyEndpoint: ThirdPartyEndpoint + thirdPartyEndpoint: ThirdPartyEndpoint, ): ByteArray = authorizeIndefinitely(thirdPartyEndpoint.identityKey) @@ -113,7 +113,7 @@ internal constructor( */ @Throws(CertificateException::class) public suspend fun authorizeIndefinitely( - thirdPartyEndpointPublicKeySerialized: ByteArray + thirdPartyEndpointPublicKeySerialized: ByteArray, ): ByteArray { val thirdPartyEndpointPublicKey = deserializePDAGranteePublicKey(thirdPartyEndpointPublicKeySerialized) @@ -134,14 +134,14 @@ internal constructor( } private fun deserializePDAGranteePublicKey( - thirdPartyEndpointPublicKeySerialized: ByteArray + thirdPartyEndpointPublicKeySerialized: ByteArray, ): PublicKey { val thirdPartyEndpointPublicKey = try { thirdPartyEndpointPublicKeySerialized.deserializeRSAPublicKey() } catch (exc: KeyException) { throw AuthorizationIssuanceException( "PDA grantee public key is not a valid RSA public key", - exc + exc, ) } return thirdPartyEndpointPublicKey @@ -164,7 +164,7 @@ internal constructor( identityPrivateKey, registration.privateNodeCertificate, listOf(registration.gatewayCertificate), - registration.gatewayInternetAddress + registration.gatewayInternetAddress, ) val gatewayId = registration.gatewayCertificate.subjectId @@ -189,12 +189,12 @@ internal constructor( for (thirdPartyEndpointAddress in thirdPartyEndpointAddresses) { val thirdPartyEndpoint = ThirdPartyEndpoint.load( this@FirstPartyEndpoint.nodeId, - thirdPartyEndpointAddress + thirdPartyEndpointAddress, ) if (thirdPartyEndpoint == null) { logger.log( Level.INFO, - "Ignoring missing third-party endpoint $thirdPartyEndpointAddress" + "Ignoring missing third-party endpoint $thirdPartyEndpointAddress", ) break } @@ -240,7 +240,7 @@ internal constructor( keyPair.private, registration.privateNodeCertificate, listOf(registration.gatewayCertificate), - registration.gatewayInternetAddress + registration.gatewayInternetAddress, ) try { @@ -258,7 +258,7 @@ internal constructor( registration.privateNodeCertificate, listOf(registration.gatewayCertificate), ), - gatewayId + gatewayId, ) } catch (exc: KeyStoreBackendException) { throw PersistenceException("Failed to save certificate", exc) @@ -291,7 +291,7 @@ internal constructor( ?: throw PersistenceException("Failed to load gateway address for endpoint") val certificatePath = try { context.certificateStore.retrieveLatest( - nodeId, gatewayNodeId + nodeId, gatewayNodeId, ) ?: return null } catch (exc: KeyStoreBackendException) { @@ -300,7 +300,7 @@ internal constructor( val internetAddress: String = context.storage.internetAddress.get() ?: throw PersistenceException( - "Failed to load gateway internet address for endpoint" + "Failed to load gateway internet address for endpoint", ) return FirstPartyEndpoint( diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/HandleGatewayCertificateChange.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/HandleGatewayCertificateChange.kt index c786c01f..9b210e9c 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/HandleGatewayCertificateChange.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/HandleGatewayCertificateChange.kt @@ -4,7 +4,7 @@ import tech.relaycorp.relaynet.keystores.PrivateKeyStore import tech.relaycorp.relaynet.wrappers.nodeId internal class HandleGatewayCertificateChange( - private val privateKeyStore: PrivateKeyStore + private val privateKeyStore: PrivateKeyStore, ) { suspend operator fun invoke() { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointData.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointData.kt index 9be918f7..43e0ed95 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointData.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointData.kt @@ -1,7 +1,5 @@ package tech.relaycorp.awaladroid.endpoint -import java.nio.ByteBuffer -import java.security.PublicKey import org.bson.BSONException import org.bson.BsonBinary import org.bson.BsonBinaryReader @@ -10,6 +8,8 @@ import org.bson.io.BasicOutputBuffer import tech.relaycorp.awaladroid.storage.persistence.PersistenceException import tech.relaycorp.relaynet.pki.CertificationPath import tech.relaycorp.relaynet.wrappers.deserializeRSAPublicKey +import java.nio.ByteBuffer +import java.security.PublicKey internal data class PrivateThirdPartyEndpointData( val identityKey: PublicKey, @@ -24,7 +24,7 @@ internal data class PrivateThirdPartyEndpointData( w.writeStartDocument() w.writeBinaryData( "identity_key", - BsonBinary(identityKey.encoded) + BsonBinary(identityKey.encoded), ) w.writeBinaryData("pda_path", BsonBinary(pdaPath.serialize())) w.writeString("internet_address", internetGatewayAddress) @@ -58,7 +58,7 @@ internal data class PrivateThirdPartyEndpointData( } catch (exp: BSONException) { throw PersistenceException( "Could not deserialize PrivateThirdPartyEndpoint", - exp + exp, ) } } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointData.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointData.kt index 6850cbb8..48b6f265 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointData.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointData.kt @@ -1,7 +1,5 @@ package tech.relaycorp.awaladroid.endpoint -import java.nio.ByteBuffer -import java.security.PublicKey import org.bson.BSONException import org.bson.BsonBinary import org.bson.BsonBinaryReader @@ -9,6 +7,8 @@ import org.bson.BsonBinaryWriter import org.bson.io.BasicOutputBuffer import tech.relaycorp.awaladroid.storage.persistence.PersistenceException import tech.relaycorp.relaynet.wrappers.deserializeRSAPublicKey +import java.nio.ByteBuffer +import java.security.PublicKey internal data class PublicThirdPartyEndpointData( val internetAddress: String, @@ -23,7 +23,7 @@ internal data class PublicThirdPartyEndpointData( w.writeString("internet_address", internetAddress) w.writeBinaryData( "identity_key", - BsonBinary(identityKey.encoded) + BsonBinary(identityKey.encoded), ) w.writeEndDocument() } @@ -41,7 +41,7 @@ internal data class PublicThirdPartyEndpointData( r.readStartDocument() PublicThirdPartyEndpointData( r.readString("internet_address"), - r.readBinaryData("identity_key").data.deserializeRSAPublicKey() + r.readBinaryData("identity_key").data.deserializeRSAPublicKey(), ).also { r.readEndDocument() } @@ -49,7 +49,7 @@ internal data class PublicThirdPartyEndpointData( } catch (exp: BSONException) { throw PersistenceException( "Could not deserialize PublicThirdPartyEndpoint", - exp + exp, ) } } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificates.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificates.kt index 51c8c1e2..2e35f620 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificates.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificates.kt @@ -1,14 +1,14 @@ package tech.relaycorp.awaladroid.endpoint -import java.time.ZonedDateTime -import kotlin.time.Duration.Companion.days import tech.relaycorp.relaynet.keystores.PrivateKeyStore import tech.relaycorp.relaynet.wrappers.nodeId import tech.relaycorp.relaynet.wrappers.x509.Certificate +import java.time.ZonedDateTime +import kotlin.time.Duration.Companion.days internal class RenewExpiringCertificates( private val privateKeyStore: PrivateKeyStore, - private val firstPartyEndpointLoader: suspend (String) -> FirstPartyEndpoint? + private val firstPartyEndpointLoader: suspend (String) -> FirstPartyEndpoint?, ) { suspend operator fun invoke() { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ThirdPartyEndpoint.kt b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ThirdPartyEndpoint.kt index b6f84899..877c665c 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ThirdPartyEndpoint.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/endpoint/ThirdPartyEndpoint.kt @@ -1,6 +1,5 @@ package tech.relaycorp.awaladroid.endpoint -import java.security.PublicKey import tech.relaycorp.awaladroid.Awala import tech.relaycorp.awaladroid.AwaladroidException import tech.relaycorp.awaladroid.SetupPendingException @@ -13,13 +12,14 @@ import tech.relaycorp.relaynet.messages.Recipient import tech.relaycorp.relaynet.pki.CertificationPathException import tech.relaycorp.relaynet.wrappers.nodeId import tech.relaycorp.relaynet.wrappers.x509.Certificate +import java.security.PublicKey /** * An endpoint owned by a different instance of this app, or a different app in the same service. */ public sealed class ThirdPartyEndpoint( internal val identityKey: PublicKey, - public val internetAddress: String + public val internetAddress: String, ) : Endpoint(identityKey.nodeId) { internal val recipient: Recipient @@ -40,7 +40,7 @@ public sealed class ThirdPartyEndpoint( @Throws(PersistenceException::class) internal suspend fun load( firstPartyAddress: String, - thirdPartyId: String + thirdPartyId: String, ): ThirdPartyEndpoint? = PublicThirdPartyEndpoint.load(thirdPartyId) ?: PrivateThirdPartyEndpoint.load(thirdPartyId, firstPartyAddress) @@ -58,7 +58,7 @@ public class PrivateThirdPartyEndpoint internal constructor( identityKey: PublicKey, internal val pda: Certificate, internal val pdaChain: List, - internetAddress: String + internetAddress: String, ) : ThirdPartyEndpoint(identityKey, internetAddress) { private val storageKey = "${firstPartyEndpointAddress}_$nodeId" @@ -82,14 +82,14 @@ public class PrivateThirdPartyEndpoint internal constructor( val pdaSubjectAddress = deliveryAuth.leafCertificate.subjectId if (pdaSubjectAddress != firstPartyEndpointAddress) { throw InvalidAuthorizationException( - "PDA subject ($pdaSubjectAddress) is not first-party endpoint" + "PDA subject ($pdaSubjectAddress) is not first-party endpoint", ) } val pdaIssuerAddress = deliveryAuth.certificateAuthorities.first().subjectId if (pdaIssuerAddress != nodeId) { throw InvalidAuthorizationException( - "PDA issuer ($pdaIssuerAddress) is not third-party endpoint" + "PDA issuer ($pdaIssuerAddress) is not third-party endpoint", ) } @@ -97,7 +97,7 @@ public class PrivateThirdPartyEndpoint internal constructor( val data = PrivateThirdPartyEndpointData( identityKey, deliveryAuth, - connectionParams.internetGatewayAddress + connectionParams.internetGatewayAddress, ) context.storage.privateThirdParty.set(storageKey, data) } @@ -109,7 +109,7 @@ public class PrivateThirdPartyEndpoint internal constructor( @Throws(PersistenceException::class, SetupPendingException::class) public suspend fun load( thirdPartyAddress: String, - firstPartyAddress: String + firstPartyAddress: String, ): PrivateThirdPartyEndpoint? { val key = "${firstPartyAddress}_$thirdPartyAddress" val storage = Awala.getContextOrThrow().storage @@ -135,7 +135,7 @@ public class PrivateThirdPartyEndpoint internal constructor( SetupPendingException::class, ) public suspend fun import( - connectionParamsSerialized: ByteArray + connectionParamsSerialized: ByteArray, ): PrivateThirdPartyEndpoint { val context = Awala.getContextOrThrow() @@ -153,7 +153,7 @@ public class PrivateThirdPartyEndpoint internal constructor( context.privateKeyStore.retrieveIdentityKey(firstPartyAddress) } catch (exc: MissingKeyException) { throw UnknownFirstPartyEndpointException( - "First-party endpoint $firstPartyAddress is not registered" + "First-party endpoint $firstPartyAddress is not registered", ) } @@ -174,7 +174,7 @@ public class PrivateThirdPartyEndpoint internal constructor( val data = PrivateThirdPartyEndpointData( params.identityKey, pdaPath, - params.internetGatewayAddress + params.internetGatewayAddress, ) context.storage.privateThirdParty.set(endpoint.storageKey, data) @@ -192,7 +192,7 @@ public class PrivateThirdPartyEndpoint internal constructor( */ public class PublicThirdPartyEndpoint internal constructor( internetAddress: String, - identityKey: PublicKey + identityKey: PublicKey, ) : ThirdPartyEndpoint(identityKey, internetAddress) { @Throws(PersistenceException::class, SetupPendingException::class) @@ -225,7 +225,7 @@ public class PublicThirdPartyEndpoint internal constructor( SetupPendingException::class, ) public suspend fun import( - connectionParamsSerialized: ByteArray + connectionParamsSerialized: ByteArray, ): PublicThirdPartyEndpoint { val context = Awala.getContextOrThrow() val connectionParams = try { @@ -241,8 +241,8 @@ public class PublicThirdPartyEndpoint internal constructor( peerNodeId, PublicThirdPartyEndpointData( connectionParams.internetAddress, - connectionParams.identityKey - ) + connectionParams.identityKey, + ), ) context.sessionPublicKeyStore.save( connectionParams.sessionKey, diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/IncomingMessage.kt b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/IncomingMessage.kt index f09854bc..aed33586 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/IncomingMessage.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/IncomingMessage.kt @@ -1,6 +1,5 @@ package tech.relaycorp.awaladroid.messaging -import java.util.logging.Level import tech.relaycorp.awaladroid.Awala import tech.relaycorp.awaladroid.SetupPendingException import tech.relaycorp.awaladroid.common.Logging.logger @@ -18,6 +17,7 @@ import tech.relaycorp.relaynet.keystores.MissingKeyException import tech.relaycorp.relaynet.messages.InvalidMessageException import tech.relaycorp.relaynet.messages.Parcel import tech.relaycorp.relaynet.wrappers.cms.EnvelopedDataException +import java.util.logging.Level /** * An incoming service message. @@ -33,7 +33,7 @@ public class IncomingMessage internal constructor( public val content: ByteArray, public val senderEndpoint: ThirdPartyEndpoint, public val recipientEndpoint: FirstPartyEndpoint, - public val ack: suspend () -> Unit + public val ack: suspend () -> Unit, ) : Message() { internal companion object { @@ -50,7 +50,7 @@ public class IncomingMessage internal constructor( internal suspend fun build(parcel: Parcel, ack: suspend () -> Unit): IncomingMessage? { val recipientEndpoint = FirstPartyEndpoint.load(parcel.recipient.id) ?: throw UnknownFirstPartyEndpointException( - "Unknown first-party endpoint ${parcel.recipient.id}" + "Unknown first-party endpoint ${parcel.recipient.id}", ) val sender = ThirdPartyEndpoint.load( @@ -59,7 +59,7 @@ public class IncomingMessage internal constructor( ) ?: throw UnknownThirdPartyEndpointException( "Unknown third-party endpoint " + "${parcel.senderCertificate.subjectId} " + - "for first-party endpoint ${parcel.recipient.id}" + "for first-party endpoint ${parcel.recipient.id}", ) val context = Awala.getContextOrThrow() @@ -68,7 +68,7 @@ public class IncomingMessage internal constructor( context.endpointManager.unwrapMessagePayload(parcel) } catch (e: MissingKeyException) { throw UnknownThirdPartyEndpointException( - "Missing third-party endpoint session keys" + "Missing third-party endpoint session keys", ) } if (serviceMessage.type == PDA_PATH_TYPE) { @@ -81,7 +81,7 @@ public class IncomingMessage internal constructor( content = serviceMessage.content, senderEndpoint = sender, recipientEndpoint = recipientEndpoint, - ack = ack + ack = ack, ) } @@ -93,7 +93,7 @@ public class IncomingMessage internal constructor( if (senderEndpoint is PublicThirdPartyEndpoint) { logger.info( "Ignoring connection params from public endpoint ${senderEndpoint.nodeId} " + - "(${senderEndpoint.internetAddress})" + "(${senderEndpoint.internetAddress})", ) return } @@ -122,7 +122,7 @@ public class IncomingMessage internal constructor( } logger.info( "Updated connection params from ${senderEndpoint.nodeId} for " + - recipientEndpoint.nodeId + recipientEndpoint.nodeId, ) } } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/OutgoingMessage.kt b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/OutgoingMessage.kt index 097026d4..5dff00ef 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/OutgoingMessage.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/OutgoingMessage.kt @@ -1,7 +1,5 @@ package tech.relaycorp.awaladroid.messaging -import java.time.Duration -import java.time.ZonedDateTime import tech.relaycorp.awaladroid.Awala import tech.relaycorp.awaladroid.endpoint.FirstPartyEndpoint import tech.relaycorp.awaladroid.endpoint.PrivateThirdPartyEndpoint @@ -11,6 +9,8 @@ import tech.relaycorp.relaynet.issueEndpointCertificate import tech.relaycorp.relaynet.messages.Parcel import tech.relaycorp.relaynet.messages.payloads.ServiceMessage import tech.relaycorp.relaynet.wrappers.x509.Certificate +import java.time.Duration +import java.time.ZonedDateTime /** * An outgoing service message. @@ -56,7 +56,7 @@ private constructor( senderEndpoint: FirstPartyEndpoint, recipientEndpoint: ThirdPartyEndpoint, parcelExpiryDate: ZonedDateTime = maxExpiryDate(), - parcelId: ParcelId = ParcelId.generate() + parcelId: ParcelId = ParcelId.generate(), ): OutgoingMessage { val message = OutgoingMessage( senderEndpoint, @@ -72,7 +72,7 @@ private constructor( private suspend fun buildParcel( serviceMessageType: String, - serviceMessageContent: ByteArray + serviceMessageContent: ByteArray, ): Parcel { val serviceMessage = ServiceMessage(serviceMessageType, serviceMessageContent) val endpointManager = Awala.getContextOrThrow().endpointManager @@ -88,7 +88,7 @@ private constructor( messageId = parcelId.value, creationDate = parcelCreationDate, ttl = ttl, - senderCertificateChain = getSenderCertificateChain() + senderCertificateChain = getSenderCertificateChain(), ) } @@ -103,7 +103,7 @@ private constructor( senderEndpoint.identityCertificate.subjectPublicKey, senderEndpoint.identityPrivateKey, validityStartDate = parcelCreationDate, - validityEndDate = parcelExpiryDate + validityEndDate = parcelExpiryDate, ) private fun getSenderCertificateChain(): Set = diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ParcelId.kt b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ParcelId.kt index bb3a6da3..5b122040 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ParcelId.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ParcelId.kt @@ -15,7 +15,7 @@ import java.util.UUID */ public class ParcelId internal constructor( - public val value: String + public val value: String, ) { public companion object { /** diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ReceiveMessages.kt b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ReceiveMessages.kt index fff75465..55df5a82 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ReceiveMessages.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/ReceiveMessages.kt @@ -1,6 +1,5 @@ package tech.relaycorp.awaladroid.messaging -import java.util.logging.Level import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow import kotlinx.coroutines.flow.flatMapLatest @@ -26,15 +25,16 @@ import tech.relaycorp.relaynet.ramf.InvalidPayloadException import tech.relaycorp.relaynet.ramf.RAMFException import tech.relaycorp.relaynet.wrappers.cms.EnvelopedDataException import tech.relaycorp.relaynet.wrappers.nodeId +import java.util.logging.Level internal class ReceiveMessages( - private val pdcClientBuilder: () -> PDCClient = { PoWebClient.initLocal(Awala.POWEB_PORT) } + private val pdcClientBuilder: () -> PDCClient = { PoWebClient.initLocal(Awala.POWEB_PORT) }, ) { @Throws( ReceiveMessageException::class, GatewayProtocolException::class, - PersistenceException::class + PersistenceException::class, ) fun receive(): Flow = getNonceSigners() @@ -66,7 +66,7 @@ internal class ReceiveMessages( ?: return@flatMap emptyList() context.certificateStore.retrieveAll( nodeId, - privateGatewayId + privateGatewayId, ).map { Signer( it.leafCertificate, @@ -102,13 +102,13 @@ internal class ReceiveMessages( } catch (exp: EnvelopedDataException) { parcelCollection.disregard( "Failed to decrypt parcel; sender might have used wrong key", - exp + exp, ) return@mapNotNull null } catch (exp: InvalidPayloadException) { parcelCollection.disregard( "Incoming parcel did not encapsulate a valid service message", - exp + exp, ) return@mapNotNull null } diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/SendMessage.kt b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/SendMessage.kt index 8e353eb7..4acc09a3 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/messaging/SendMessage.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/messaging/SendMessage.kt @@ -1,6 +1,5 @@ package tech.relaycorp.awaladroid.messaging -import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import tech.relaycorp.awaladroid.Awala @@ -12,16 +11,17 @@ import tech.relaycorp.relaynet.bindings.pdc.PDCClient import tech.relaycorp.relaynet.bindings.pdc.RejectedParcelException import tech.relaycorp.relaynet.bindings.pdc.ServerException import tech.relaycorp.relaynet.bindings.pdc.Signer +import kotlin.coroutines.CoroutineContext internal class SendMessage( private val pdcClientBuilder: () -> PDCClient = { PoWebClient.initLocal(Awala.POWEB_PORT) }, - private val coroutineContext: CoroutineContext = Dispatchers.IO + private val coroutineContext: CoroutineContext = Dispatchers.IO, ) { @Throws( SendMessageException::class, RejectedMessageException::class, - GatewayProtocolException::class + GatewayProtocolException::class, ) suspend fun send(message: OutgoingMessage) { withContext(coroutineContext) { @@ -33,8 +33,8 @@ internal class SendMessage( message.parcel.serialize(senderPrivateKey), Signer( message.senderEndpoint.identityCertificate, - senderPrivateKey - ) + senderPrivateKey, + ), ) } } catch (e: ServerException) { diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/storage/StorageImpl.kt b/lib/src/main/java/tech/relaycorp/awaladroid/storage/StorageImpl.kt index d37e1f06..c8b2f78a 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/storage/StorageImpl.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/storage/StorageImpl.kt @@ -1,16 +1,16 @@ package tech.relaycorp.awaladroid.storage import androidx.annotation.VisibleForTesting -import java.nio.charset.Charset import tech.relaycorp.awaladroid.endpoint.PrivateThirdPartyEndpointData import tech.relaycorp.awaladroid.endpoint.PublicThirdPartyEndpointData import tech.relaycorp.awaladroid.storage.persistence.Persistence import tech.relaycorp.awaladroid.storage.persistence.PersistenceException +import java.nio.charset.Charset // TODO: Test internal class StorageImpl constructor( - persistence: Persistence + persistence: Persistence, ) { private val ascii = Charset.forName("ASCII") @@ -18,7 +18,7 @@ constructor( persistence = persistence, prefix = "gateway_id_", serializer = { address: String -> address.toByteArray(ascii) }, - deserializer = { addressSerialized: ByteArray -> addressSerialized.toString(ascii) } + deserializer = { addressSerialized: ByteArray -> addressSerialized.toString(ascii) }, ) internal val internetAddress: SingleModule = SingleModule( @@ -27,21 +27,21 @@ constructor( serializer = { internetAddress: String -> internetAddress.toByteArray(ascii) }, deserializer = { internetAddressSerialized: ByteArray -> internetAddressSerialized.toString(ascii) - } + }, ) internal val publicThirdParty: Module = Module( persistence = persistence, prefix = "public_third_party_", serializer = PublicThirdPartyEndpointData::serialize, - deserializer = PublicThirdPartyEndpointData::deserialize + deserializer = PublicThirdPartyEndpointData::deserialize, ) internal val privateThirdParty: Module = Module( persistence = persistence, prefix = "private_third_party_", serializer = PrivateThirdPartyEndpointData::serialize, - deserializer = PrivateThirdPartyEndpointData::deserialize + deserializer = PrivateThirdPartyEndpointData::deserialize, ) internal open class Module( @@ -49,7 +49,7 @@ constructor( @get:VisibleForTesting internal val prefix: String, private val serializer: (T) -> ByteArray, - private val deserializer: (ByteArray) -> T + private val deserializer: (ByteArray) -> T, ) { @Throws(PersistenceException::class) @@ -79,7 +79,7 @@ constructor( persistence: Persistence, prefix: String, serializer: (T) -> ByteArray, - deserializer: (ByteArray) -> T + deserializer: (ByteArray) -> T, ) : Module(persistence, prefix, serializer, deserializer) { @Throws(PersistenceException::class) diff --git a/lib/src/main/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistence.kt b/lib/src/main/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistence.kt index ed094ecf..06236d76 100644 --- a/lib/src/main/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistence.kt +++ b/lib/src/main/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistence.kt @@ -1,15 +1,15 @@ package tech.relaycorp.awaladroid.storage.persistence +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import java.io.File import java.io.IOException import kotlin.coroutines.CoroutineContext -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext internal class DiskPersistence( private val fileDir: String, private val coroutineContext: CoroutineContext = Dispatchers.IO, - private val rootFolder: String = "awaladroid" + private val rootFolder: String = "awaladroid", ) : Persistence { @Suppress("BlockingMethodInNonBlockingContext") diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStoreTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStoreTest.kt index 4d5552d3..6fe6d06c 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStoreTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/AndroidPrivateKeyStoreTest.kt @@ -1,6 +1,5 @@ package tech.relaycorp.awaladroid -import java.io.File import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Before @@ -12,6 +11,7 @@ import tech.relaycorp.awala.keystores.file.FileKeystoreRoot import tech.relaycorp.awaladroid.test.FakeAndroidKeyStore import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath +import java.io.File @RunWith(RobolectricTestRunner::class) public class AndroidPrivateKeyStoreTest { diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/AwalaTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/AwalaTest.kt index 8aa2c8c4..70c931b2 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/AwalaTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/AwalaTest.kt @@ -3,9 +3,6 @@ package tech.relaycorp.awaladroid import android.content.Context import com.nhaarman.mockitokotlin2.spy import com.nhaarman.mockitokotlin2.verify -import java.io.File -import java.time.Duration -import java.time.ZonedDateTime import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest @@ -26,6 +23,9 @@ import tech.relaycorp.relaynet.issueEndpointCertificate import tech.relaycorp.relaynet.pki.CertificationPath import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.wrappers.nodeId +import java.io.File +import java.time.Duration +import java.time.ZonedDateTime @RunWith(RobolectricTestRunner::class) public class AwalaTest { @@ -106,7 +106,7 @@ public class AwalaTest { certificateStore.retrieveLatest( expiringCertificate.subjectId, expiringCertificate.issuerCommonName, - ) + ), ) // Retry until expiration @@ -116,7 +116,7 @@ public class AwalaTest { advanceUntilIdle() certificateStore.retrieveLatest( KeyPairSet.PRIVATE_ENDPOINT.public.nodeId, - KeyPairSet.PRIVATE_GW.private.nodeId + KeyPairSet.PRIVATE_GW.private.nodeId, ) ?: return@runTest } throw AssertionError("Expired certificate not deleted") diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/GatewayClientImplTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/GatewayClientImplTest.kt index c983b012..c93e9fd0 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/GatewayClientImplTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/GatewayClientImplTest.kt @@ -8,7 +8,6 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import java.time.ZonedDateTime import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.flow @@ -40,6 +39,7 @@ import tech.relaycorp.relaynet.testing.pdc.MockPDCClient import tech.relaycorp.relaynet.testing.pdc.RegisterNodeCall import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath +import java.time.ZonedDateTime @RunWith(RobolectricTestRunner::class) internal class GatewayClientImplTest : MockContextTestCase() { @@ -51,8 +51,11 @@ internal class GatewayClientImplTest : MockContextTestCase() { private val receiveMessages = mock() override val gatewayClient = GatewayClientImpl( - coroutineScope.coroutineContext, { serviceInteractor }, { pdcClient }, sendMessage, - receiveMessages + coroutineScope.coroutineContext, + { serviceInteractor }, + { pdcClient }, + sendMessage, + receiveMessages, ) // Binding @@ -64,7 +67,7 @@ internal class GatewayClientImplTest : MockContextTestCase() { verify(serviceInteractor).bind( Awala.GATEWAY_SYNC_ACTION, Awala.GATEWAY_PACKAGE, - Awala.GATEWAY_SYNC_COMPONENT + Awala.GATEWAY_SYNC_COMPONENT, ) } @@ -113,7 +116,7 @@ internal class GatewayClientImplTest : MockContextTestCase() { .bind( Awala.GATEWAY_PRE_REGISTER_ACTION, Awala.GATEWAY_PACKAGE, - Awala.GATEWAY_PRE_REGISTER_COMPONENT + Awala.GATEWAY_PRE_REGISTER_COMPONENT, ) verify(serviceInteractor) .bind(Awala.GATEWAY_SYNC_ACTION, Awala.GATEWAY_PACKAGE, Awala.GATEWAY_SYNC_COMPONENT) @@ -167,7 +170,7 @@ internal class GatewayClientImplTest : MockContextTestCase() { private fun buildPnra() = PrivateNodeRegistrationAuthorization( ZonedDateTime.now().plusDays(1), - PDACertPath.PRIVATE_GW.serialize() + PDACertPath.PRIVATE_GW.serialize(), ) private fun buildAuthorizationReplyMessage(): Message { @@ -237,7 +240,7 @@ internal class GatewayClientImplTest : MockContextTestCase() { .bind( eq(Awala.GATEWAY_SYNC_ACTION), eq(Awala.GATEWAY_PACKAGE), - eq(Awala.GATEWAY_SYNC_COMPONENT) + eq(Awala.GATEWAY_SYNC_COMPONENT), ) verify(serviceInteractor) .unbind() diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/ChannelManagerTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/ChannelManagerTest.kt index 5cefed01..e1db3154 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/ChannelManagerTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/ChannelManagerTest.kt @@ -17,7 +17,7 @@ internal class ChannelManagerTest { private val androidContext = RuntimeEnvironment.getApplication() private val sharedPreferences = androidContext.getSharedPreferences( "channel-test", - Context.MODE_PRIVATE + Context.MODE_PRIVATE, ) private val firstPartyEndpoint = FirstPartyEndpointFactory.build() @@ -42,7 +42,7 @@ internal class ChannelManagerTest { fun create_non_existing() = runTest { assertEquals( null, - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) val manager = ChannelManager(coroutineContext) { sharedPreferences } @@ -50,7 +50,7 @@ internal class ChannelManagerTest { assertEquals( setOf(thirdPartyEndpoint.nodeId), - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -63,7 +63,7 @@ internal class ChannelManagerTest { assertEquals( setOf(thirdPartyEndpoint.nodeId), - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -76,7 +76,7 @@ internal class ChannelManagerTest { assertEquals( setOf(thirdPartyEndpoint.nodeId), - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -88,7 +88,7 @@ internal class ChannelManagerTest { assertEquals( null, - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -101,7 +101,7 @@ internal class ChannelManagerTest { assertEquals( null, - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -112,7 +112,7 @@ internal class ChannelManagerTest { with(sharedPreferences.edit()) { putStringSet( firstPartyEndpoint.nodeId, - mutableSetOf(unrelatedThirdPartyEndpointAddress) + mutableSetOf(unrelatedThirdPartyEndpointAddress), ) apply() } @@ -121,7 +121,7 @@ internal class ChannelManagerTest { assertEquals( mutableSetOf(unrelatedThirdPartyEndpointAddress), - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -132,7 +132,7 @@ internal class ChannelManagerTest { with(sharedPreferences.edit()) { putStringSet( firstPartyEndpoint.nodeId, - mutableSetOf(unrelatedThirdPartyEndpointAddress, thirdPartyEndpoint.nodeId) + mutableSetOf(unrelatedThirdPartyEndpointAddress, thirdPartyEndpoint.nodeId), ) apply() } @@ -141,7 +141,7 @@ internal class ChannelManagerTest { assertEquals( setOf(unrelatedThirdPartyEndpointAddress), - sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null) + sharedPreferences.getStringSet(firstPartyEndpoint.nodeId, null), ) } @@ -152,7 +152,7 @@ internal class ChannelManagerTest { with(sharedPreferences.edit()) { putString( firstPartyEndpoint.nodeId, - malformedValue + malformedValue, ) apply() } @@ -161,7 +161,7 @@ internal class ChannelManagerTest { assertEquals( malformedValue, - sharedPreferences.getString(firstPartyEndpoint.nodeId, null) + sharedPreferences.getString(firstPartyEndpoint.nodeId, null), ) } @@ -172,7 +172,7 @@ internal class ChannelManagerTest { with(sharedPreferences.edit()) { putInt( firstPartyEndpoint.nodeId, - malformedValue + malformedValue, ) apply() } @@ -181,7 +181,7 @@ internal class ChannelManagerTest { assertEquals( malformedValue, - sharedPreferences.getInt(firstPartyEndpoint.nodeId, 0) + sharedPreferences.getInt(firstPartyEndpoint.nodeId, 0), ) } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpointTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpointTest.kt index ad367e7f..f83ca4b3 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpointTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/FirstPartyEndpointTest.kt @@ -9,8 +9,6 @@ import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyZeroInteractions import com.nhaarman.mockitokotlin2.whenever -import java.security.PublicKey -import java.time.ZonedDateTime import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest import nl.altindag.log.LogCaptor @@ -41,6 +39,8 @@ import tech.relaycorp.relaynet.testing.keystores.MockPrivateKeyStore import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath import tech.relaycorp.relaynet.wrappers.nodeId +import java.security.PublicKey +import java.time.ZonedDateTime internal class FirstPartyEndpointTest : MockContextTestCase() { @Test @@ -70,8 +70,8 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { PrivateNodeRegistration( PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW, - internetGatewayAddress - ) + internetGatewayAddress, + ), ) val endpoint = FirstPartyEndpoint.register() @@ -81,12 +81,12 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { assertEquals(endpoint.identityPrivateKey, identityPrivateKey) val identityCertificatePath = certificateStore.retrieveLatest( endpoint.identityCertificate.subjectId, - PDACertPath.PRIVATE_GW.subjectId + PDACertPath.PRIVATE_GW.subjectId, ) assertEquals(PDACertPath.PRIVATE_ENDPOINT, identityCertificatePath!!.leafCertificate) verify(storage.gatewayId).set( endpoint.nodeId, - PDACertPath.PRIVATE_GW.subjectId + PDACertPath.PRIVATE_GW.subjectId, ) verify(storage.internetAddress).set(internetGatewayAddress) } @@ -103,15 +103,15 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { PrivateNodeRegistration( newCertificate, PDACertPath.PRIVATE_GW, - "" - ) + "", + ), ) endpoint.reRegister() val identityCertificatePath = certificateStore.retrieveLatest( endpoint.identityPrivateKey.nodeId, - PDACertPath.PRIVATE_GW.subjectId + PDACertPath.PRIVATE_GW.subjectId, ) assertEquals(newCertificate, identityCertificatePath!!.leafCertificate) } @@ -142,14 +142,14 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { PrivateNodeRegistration( PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW, - "" - ) + "", + ), ) val savingException = Exception("Oh noes") setAwalaContext( Awala.getContextOrThrow().copy( - privateKeyStore = MockPrivateKeyStore(savingException = savingException) - ) + privateKeyStore = MockPrivateKeyStore(savingException = savingException), + ), ) val exception = assertThrows(PersistenceException::class.java) { @@ -169,14 +169,14 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { PrivateNodeRegistration( PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW, - "" - ) + "", + ), ) val savingException = Exception("Oh noes") setAwalaContext( Awala.getContextOrThrow().copy( - certificateStore = MockCertificateStore(savingException = savingException) - ) + certificateStore = MockCertificateStore(savingException = savingException), + ), ) val exception = assertThrows(PersistenceException::class.java) { @@ -216,8 +216,8 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { fun load_withKeystoreError(): Unit = runTest { setAwalaContext( Awala.getContextOrThrow().copy( - privateKeyStore = MockPrivateKeyStore(retrievalException = Exception("Oh noes")) - ) + privateKeyStore = MockPrivateKeyStore(retrievalException = Exception("Oh noes")), + ), ) whenever(storage.gatewayId.get()) .thenReturn(PDACertPath.PRIVATE_GW.subjectId) @@ -268,8 +268,8 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { val retrievalException = Exception("Oh noes") setAwalaContext( Awala.getContextOrThrow().copy( - certificateStore = MockCertificateStore(retrievalException = retrievalException) - ) + certificateStore = MockCertificateStore(retrievalException = retrievalException), + ), ) val exception = assertThrows(PersistenceException::class.java) { @@ -300,7 +300,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { val authorization = firstPartyEndpoint.issueAuthorization( KeyPairSet.PDA_GRANTEE.public.encoded, - expiryDate + expiryDate, ) validateAuthorization(authorization, firstPartyEndpoint, expiryDate) @@ -315,7 +315,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { runBlocking { firstPartyEndpoint.issueAuthorization( "This is not a key".toByteArray(), - expiryDate + expiryDate, ) } } @@ -349,7 +349,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { eq(firstPartyEndpoint), argThat { encoded.asList() == KeyPairSet.PDA_GRANTEE.public.encoded.asList() - } + }, ) } @@ -360,7 +360,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { val exception = assertThrows(AuthorizationIssuanceException::class.java) { runBlocking { firstPartyEndpoint.authorizeIndefinitely( - "This is not a key".toByteArray() + "This is not a key".toByteArray(), ) } } @@ -392,7 +392,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { verify(gatewayClient, never()).sendMessage(any()) assertTrue( - logCaptor.infoLogs.contains("Ignoring missing third-party endpoint $missingAddress") + logCaptor.infoLogs.contains("Ignoring missing third-party endpoint $missingAddress"), ) } @@ -411,7 +411,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { assertEquals(firstPartyEndpoint, outgoingMessage.senderEndpoint) assertEquals( channel.thirdPartyEndpoint.nodeId, - outgoingMessage.recipientEndpoint.nodeId + outgoingMessage.recipientEndpoint.nodeId, ) // Verify the PDA val (serviceMessage) = @@ -422,7 +422,7 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { pdaPath.validate() assertEquals( channel.thirdPartyEndpoint.identityKey, - pdaPath.leafCertificate.subjectPublicKey + pdaPath.leafCertificate.subjectPublicKey, ) assertEquals(firstPartyEndpoint.pdaChain, pdaPath.certificateAuthorities) assertEquals(pdaPath.leafCertificate.expiryDate, outgoingMessage.parcelExpiryDate) @@ -445,18 +445,18 @@ internal class FirstPartyEndpointTest : MockContextTestCase() { private fun validateAuthorization( paramsSerialized: ByteArray, firstPartyEndpoint: FirstPartyEndpoint, - expiryDate: ZonedDateTime + expiryDate: ZonedDateTime, ) { val params = PrivateEndpointConnParams.deserialize(paramsSerialized) assertEquals( firstPartyEndpoint.publicKey, - params.identityKey + params.identityKey, ) assertEquals( firstPartyEndpoint.internetAddress, - params.internetGatewayAddress + params.internetGatewayAddress, ) val authorization = params.deliveryAuth @@ -464,15 +464,15 @@ private fun validateAuthorization( val pda = authorization.leafCertificate assertEquals( KeyPairSet.PDA_GRANTEE.public.encoded.asList(), - pda.subjectPublicKey.encoded.asList() + pda.subjectPublicKey.encoded.asList(), ) assertEquals( 2, - pda.getCertificationPath(emptyList(), listOf(PDACertPath.PRIVATE_ENDPOINT)).size + pda.getCertificationPath(emptyList(), listOf(PDACertPath.PRIVATE_ENDPOINT)).size, ) assertSameDateTime( expiryDate, - pda.expiryDate + pda.expiryDate, ) // PDA chain diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointTest.kt index fb8b3b9b..e065d49d 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PrivateThirdPartyEndpointTest.kt @@ -5,8 +5,6 @@ import com.nhaarman.mockitokotlin2.argThat import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import java.time.ZonedDateTime -import java.util.UUID import kotlinx.coroutines.test.runTest import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals @@ -27,6 +25,8 @@ import tech.relaycorp.relaynet.testing.pki.PDACertPath import tech.relaycorp.relaynet.wrappers.generateRSAKeyPair import tech.relaycorp.relaynet.wrappers.nodeId import tech.relaycorp.relaynet.wrappers.x509.CertificateException +import java.time.ZonedDateTime +import java.util.UUID internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { private val thirdPartyEndpointCertificate = issueEndpointCertificate( @@ -68,10 +68,10 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { KeyPairSet.PRIVATE_ENDPOINT.public, CertificationPath( PDACertPath.PDA, - listOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW) + listOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW), ), internetGatewayAddress, - ) + ), ) val firstAddress = UUID.randomUUID().toString() val thirdAddress = UUID.randomUUID().toString() @@ -94,8 +94,8 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { assertNull( PrivateThirdPartyEndpoint.load( UUID.randomUUID().toString(), - UUID.randomUUID().toString() - ) + UUID.randomUUID().toString(), + ), ) } @@ -105,27 +105,27 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { val deliveryAuth = CertificationPath( pda, - listOf(thirdPartyEndpointCertificate) + listOf(thirdPartyEndpointCertificate), ) val paramsSerialized = serializeConnectionParams(deliveryAuth) val endpoint = PrivateThirdPartyEndpoint.import(paramsSerialized) assertEquals( firstPartyEndpoint.nodeId, - endpoint.firstPartyEndpointAddress + endpoint.firstPartyEndpointAddress, ) assertEquals( KeyPairSet.PDA_GRANTEE.public.nodeId, - endpoint.nodeId + endpoint.nodeId, ) assertEquals( KeyPairSet.PDA_GRANTEE.public, - endpoint.identityKey + endpoint.identityKey, ) assertEquals(pda, endpoint.pda) assertArrayEquals( arrayOf(thirdPartyEndpointCertificate), - endpoint.pdaChain.toTypedArray() + endpoint.pdaChain.toTypedArray(), ) verify(storage.privateThirdParty).set( @@ -135,7 +135,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { this.pdaPath.leafCertificate == pda && this.pdaPath.certificateAuthorities == deliveryAuth.certificateAuthorities && this.internetGatewayAddress == internetGatewayAddress - } + }, ) assertEquals(sessionKey, sessionPublicKeystore.retrieve(endpoint.nodeId)) @@ -151,7 +151,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { } catch (exception: UnknownFirstPartyEndpointException) { assertEquals( "First-party endpoint ${firstPartyCert.subjectId} is not registered", - exception.message + exception.message, ) return@runTest } @@ -167,19 +167,19 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { val unrelatedCertificate = issueEndpointCertificate( unrelatedKeyPair.public, unrelatedKeyPair.private, - ZonedDateTime.now().plusDays(1) + ZonedDateTime.now().plusDays(1), ) val invalidPDA = issueDeliveryAuthorization( subjectPublicKey = firstPartyEndpoint.identityCertificate.subjectPublicKey, issuerPrivateKey = unrelatedKeyPair.private, validityEndDate = ZonedDateTime.now().plusDays(1), - issuerCertificate = unrelatedCertificate + issuerCertificate = unrelatedCertificate, ) val pdaPath = CertificationPath( invalidPDA, - listOf(thirdPartyEndpointCertificate) + listOf(thirdPartyEndpointCertificate), ) val paramsSerialized = serializeConnectionParams(pdaPath) try { @@ -235,7 +235,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { KeyPairSet.PDA_GRANTEE.private, now.minusSeconds(1), thirdPartyEndpointCertificate, - now.minusSeconds(2) + now.minusSeconds(2), ) val pdaPath = CertificationPath(expiredPDA, listOf(thirdPartyEndpointCertificate)) @@ -257,7 +257,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { val identityKey = KeyPairSet.PRIVATE_ENDPOINT.public val pdaPath = CertificationPath( pda, - listOf(PDACertPath.PRIVATE_GW, PDACertPath.INTERNET_GW) + listOf(PDACertPath.PRIVATE_GW, PDACertPath.INTERNET_GW), ) val dataSerialized = PrivateThirdPartyEndpointData( identityKey, @@ -270,7 +270,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { assertEquals(pda, data.pdaPath.leafCertificate) assertEquals( listOf(PDACertPath.PRIVATE_GW, PDACertPath.INTERNET_GW), - data.pdaPath.certificateAuthorities + data.pdaPath.certificateAuthorities, ) assertEquals(internetGatewayAddress, data.internetGatewayAddress) } @@ -363,7 +363,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { KeyPairSet.PDA_GRANTEE.public, deliveryAuth, thirdPartyEndpoint.internetAddress, - ) + ), ) } @@ -392,7 +392,7 @@ internal class PrivateThirdPartyEndpointTest : MockContextTestCase() { private fun makeConnectionParams( thirdPartyEndpoint: PrivateThirdPartyEndpoint, - deliveryAuth: CertificationPath + deliveryAuth: CertificationPath, ) = PrivateEndpointConnParams( thirdPartyEndpoint.identityKey, thirdPartyEndpoint.internetAddress, diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointTest.kt index c8a20864..47c6b300 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/PublicThirdPartyEndpointTest.kt @@ -3,7 +3,6 @@ package tech.relaycorp.awaladroid.endpoint import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import java.util.UUID import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals import org.junit.Assert.assertNull @@ -16,6 +15,7 @@ import tech.relaycorp.relaynet.SessionKeyPair import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath import tech.relaycorp.relaynet.wrappers.nodeId +import java.util.UUID internal class PublicThirdPartyEndpointTest : MockContextTestCase() { private val internetAddress = "example.org" @@ -50,8 +50,8 @@ internal class PublicThirdPartyEndpointTest : MockContextTestCase() { .thenReturn( PublicThirdPartyEndpointData( internetAddress, - KeyPairSet.PDA_GRANTEE.public - ) + KeyPairSet.PDA_GRANTEE.public, + ), ) val endpoint = PublicThirdPartyEndpoint.load(id)!! @@ -71,7 +71,7 @@ internal class PublicThirdPartyEndpointTest : MockContextTestCase() { val connectionParams = NodeConnectionParams( internetAddress, KeyPairSet.PDA_GRANTEE.public, - SessionKeyPair.generate().sessionKey + SessionKeyPair.generate().sessionKey, ) val thirdPartyEndpoint = PublicThirdPartyEndpoint.import(connectionParams.serialize()) @@ -82,8 +82,8 @@ internal class PublicThirdPartyEndpointTest : MockContextTestCase() { PDACertPath.PDA.subjectId, PublicThirdPartyEndpointData( connectionParams.internetAddress, - connectionParams.identityKey - ) + connectionParams.identityKey, + ), ) sessionPublicKeystore.retrieve(thirdPartyEndpoint.nodeId) } @@ -92,7 +92,7 @@ internal class PublicThirdPartyEndpointTest : MockContextTestCase() { fun import_invalidConnectionParams() = runTest { try { PublicThirdPartyEndpoint.import( - "malformed".toByteArray() + "malformed".toByteArray(), ) } catch (exception: InvalidThirdPartyEndpoint) { assertEquals("Connection params serialization is malformed", exception.message) @@ -123,7 +123,7 @@ internal class PublicThirdPartyEndpointTest : MockContextTestCase() { ownSessionKeyPair.privateKey, ownSessionKeyPair.sessionKey.keyId, firstPartyEndpoint.nodeId, - thirdPartyEndpoint.nodeId + thirdPartyEndpoint.nodeId, ) val peerSessionKey = SessionKeyPair.generate().sessionKey sessionPublicKeystore.save(peerSessionKey, thirdPartyEndpoint.nodeId) diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificatesTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificatesTest.kt index 936be4f4..3e3d4afb 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificatesTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/endpoint/RenewExpiringCertificatesTest.kt @@ -4,13 +4,13 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.never import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import java.time.ZonedDateTime import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import tech.relaycorp.relaynet.issueEndpointCertificate import tech.relaycorp.relaynet.keystores.PrivateKeyStore import tech.relaycorp.relaynet.testing.pki.KeyPairSet +import java.time.ZonedDateTime internal class RenewExpiringCertificatesTest() { @@ -47,7 +47,7 @@ internal class RenewExpiringCertificatesTest() { val expiringCert = issueEndpointCertificate( KeyPairSet.PRIVATE_ENDPOINT.public, KeyPairSet.PRIVATE_GW.private, - certExpiryDate + certExpiryDate, ) whenever(firstPartyEndpoint.identityCertificate).thenReturn(expiringCert) return firstPartyEndpoint diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/IncomingMessageTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/IncomingMessageTest.kt index 30a54fca..134610a0 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/IncomingMessageTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/IncomingMessageTest.kt @@ -5,7 +5,6 @@ import com.nhaarman.mockitokotlin2.argThat import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.never import com.nhaarman.mockitokotlin2.verify -import java.time.ZonedDateTime import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runTest import nl.altindag.log.LogCaptor @@ -36,6 +35,7 @@ import tech.relaycorp.relaynet.testing.keystores.MockPrivateKeyStore import tech.relaycorp.relaynet.testing.keystores.MockSessionPublicKeyStore import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath +import java.time.ZonedDateTime internal class IncomingMessageTest : MockContextTestCase() { private val thirdPartyEndpointCertificate = issueEndpointCertificate( @@ -56,14 +56,14 @@ internal class IncomingMessageTest : MockContextTestCase() { val parcel = Parcel( recipient = Recipient( channel.firstPartyEndpoint.nodeId, - channel.firstPartyEndpoint.nodeId + channel.firstPartyEndpoint.nodeId, ), payload = thirdPartyEndpointManager.wrapMessagePayload( serviceMessage, channel.firstPartyEndpoint.nodeId, - channel.thirdPartyEndpoint.nodeId + channel.thirdPartyEndpoint.nodeId, ), - senderCertificate = PDACertPath.PDA + senderCertificate = PDACertPath.PDA, ) val message = IncomingMessage.build(parcel) {} @@ -130,8 +130,8 @@ internal class IncomingMessageTest : MockContextTestCase() { assertTrue( logCaptor.infoLogs.contains( "Ignoring connection params from public endpoint ${thirdPartyEndpoint.nodeId} " + - "(${thirdPartyEndpoint.internetAddress})" - ) + "(${thirdPartyEndpoint.internetAddress})", + ), ) } @@ -153,8 +153,8 @@ internal class IncomingMessageTest : MockContextTestCase() { assertTrue( logCaptor.infoLogs.contains( "Ignoring malformed connection params for ${channel.firstPartyEndpoint.nodeId} " + - "from ${channel.thirdPartyEndpoint.nodeId}" - ) + "from ${channel.thirdPartyEndpoint.nodeId}", + ), ) } @@ -186,8 +186,8 @@ internal class IncomingMessageTest : MockContextTestCase() { assertTrue( logCaptor.infoLogs.contains( "Ignoring invalid connection params for ${channel.firstPartyEndpoint.nodeId} " + - "from ${channel.thirdPartyEndpoint.nodeId}" - ) + "from ${channel.thirdPartyEndpoint.nodeId}", + ), ) } @@ -217,8 +217,8 @@ internal class IncomingMessageTest : MockContextTestCase() { assertTrue( logCaptor.infoLogs.contains( "Updated connection params from ${thirdPartyEndpoint.nodeId} for " + - channel.firstPartyEndpoint.nodeId - ) + channel.firstPartyEndpoint.nodeId, + ), ) verify(storage.privateThirdParty).set( eq("${channel.firstPartyEndpoint.nodeId}_${thirdPartyEndpoint.nodeId}"), @@ -233,7 +233,7 @@ internal class IncomingMessageTest : MockContextTestCase() { private fun makeConnParams( channel: EndpointChannel, - deliveryAuth: CertificationPath + deliveryAuth: CertificationPath, ) = PrivateEndpointConnParams( channel.thirdPartyEndpoint.identityKey, channel.thirdPartyEndpoint.internetAddress, @@ -256,25 +256,25 @@ internal class IncomingMessageTest : MockContextTestCase() { ) return EndpointManager( thirdPartyPrivateKeyStore, - thirdPartySessionPublicKeyStore + thirdPartySessionPublicKeyStore, ) } private suspend fun encryptConnectionParams( channel: EndpointChannel, - params: PrivateEndpointConnParams + params: PrivateEndpointConnParams, ): ByteArray = encryptParcelPayload(channel, params.serialize()) private suspend fun encryptParcelPayload( channel: EndpointChannel, - plaintext: ByteArray + plaintext: ByteArray, ): ByteArray { val thirdPartyEndpointManager = makeThirdPartyEndpointManager(channel) val pdaPathServiceMessage = makePDAPathMessage(plaintext) return thirdPartyEndpointManager.wrapMessagePayload( pdaPathServiceMessage, channel.firstPartyEndpoint.nodeId, - channel.thirdPartyEndpoint.nodeId + channel.thirdPartyEndpoint.nodeId, ) } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/OutgoingMessageTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/OutgoingMessageTest.kt index 5dbb2b0b..881738b5 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/OutgoingMessageTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/OutgoingMessageTest.kt @@ -1,9 +1,5 @@ package tech.relaycorp.awaladroid.messaging -import java.time.Duration -import java.time.ZonedDateTime -import kotlin.math.abs -import kotlin.random.Random import kotlinx.coroutines.test.runTest import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals @@ -15,6 +11,10 @@ import tech.relaycorp.awaladroid.test.MessageFactory import tech.relaycorp.awaladroid.test.MockContextTestCase import tech.relaycorp.awaladroid.test.RecipientAddressType import tech.relaycorp.awaladroid.test.assertSameDateTime +import java.time.Duration +import java.time.ZonedDateTime +import kotlin.math.abs +import kotlin.random.Random internal class OutgoingMessageTest : MockContextTestCase() { @@ -37,7 +37,7 @@ internal class OutgoingMessageTest : MockContextTestCase() { val difference = Duration.between( message.parcel.expiryDate, - message.parcel.creationDate.plusDays(180) + message.parcel.creationDate.plusDays(180), ) assertTrue(abs(difference.toDays()) == 0L) } @@ -52,7 +52,7 @@ internal class OutgoingMessageTest : MockContextTestCase() { Random.Default.nextBytes(10), senderEndpoint, recipientEndpoint, - parcelExpiryDate + parcelExpiryDate, ) val differenceSeconds = @@ -72,7 +72,7 @@ internal class OutgoingMessageTest : MockContextTestCase() { assertEquals(message.recipientEndpoint.nodeId, message.parcel.recipient.id) assertEquals( recipientPublicEndpoint.internetAddress, - message.parcel.recipient.internetAddress + message.parcel.recipient.internetAddress, ) assertEquals(message.parcelId.value, message.parcel.id) assertSameDateTime(message.parcelCreationDate, message.parcel.creationDate) @@ -127,7 +127,7 @@ internal class OutgoingMessageTest : MockContextTestCase() { assertEquals(message.recipientEndpoint.nodeId, message.parcel.recipient.id) assertEquals( message.recipientEndpoint.internetAddress, - message.parcel.recipient.internetAddress + message.parcel.recipient.internetAddress, ) assertEquals(message.parcelId.value, message.parcel.id) assertSameDateTime(message.parcelCreationDate, message.parcel.creationDate) @@ -142,7 +142,7 @@ internal class OutgoingMessageTest : MockContextTestCase() { assertEquals( (message.recipientEndpoint as PrivateThirdPartyEndpoint).pda, - message.parcel.senderCertificate + message.parcel.senderCertificate, ) } @@ -154,7 +154,7 @@ internal class OutgoingMessageTest : MockContextTestCase() { assertArrayEquals( (message.recipientEndpoint as PrivateThirdPartyEndpoint).pdaChain.toTypedArray(), - message.parcel.senderCertificateChain.toTypedArray() + message.parcel.senderCertificateChain.toTypedArray(), ) } } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/ReceiveMessagesTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/ReceiveMessagesTest.kt index 19bb9e1e..c064619e 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/ReceiveMessagesTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/ReceiveMessagesTest.kt @@ -1,6 +1,5 @@ package tech.relaycorp.awaladroid.messaging -import java.time.ZonedDateTime import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.toCollection @@ -29,6 +28,7 @@ import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath import tech.relaycorp.relaynet.wrappers.generateECDHKeyPair import tech.relaycorp.relaynet.wrappers.nodeId +import java.time.ZonedDateTime internal class ReceiveMessagesTest : MockContextTestCase() { @@ -99,13 +99,13 @@ internal class ReceiveMessagesTest : MockContextTestCase() { val invalidParcel = Parcel( recipient = Recipient(KeyPairSet.PRIVATE_ENDPOINT.public.nodeId), payload = "".toByteArray(), - senderCertificate = PDACertPath.PRIVATE_ENDPOINT + senderCertificate = PDACertPath.PRIVATE_ENDPOINT, ) var ackWasCalled = false val parcelCollection = ParcelCollection( parcelSerialized = invalidParcel.serialize(KeyPairSet.PRIVATE_ENDPOINT.private), trustedCertificates = emptyList(), // sender won't be trusted - ack = { ackWasCalled = true } + ack = { ackWasCalled = true }, ) val collectParcelsCall = CollectParcelsCall(Result.success(flowOf(parcelCollection))) pdcClient = MockPDCClient(collectParcelsCall) @@ -125,7 +125,7 @@ internal class ReceiveMessagesTest : MockContextTestCase() { val parcelCollection = ParcelCollection( parcelSerialized = "1234".toByteArray(), trustedCertificates = emptyList(), - ack = { ackWasCalled = true } + ack = { ackWasCalled = true }, ) val collectParcelsCall = CollectParcelsCall(Result.success(flowOf(parcelCollection))) pdcClient = MockPDCClient(collectParcelsCall) @@ -187,11 +187,11 @@ internal class ReceiveMessagesTest : MockContextTestCase() { PublicThirdPartyEndpointData( channel.thirdPartyEndpoint.nodeId, channel.thirdPartyEndpoint.identityKey, - ) + ), ) val parcelPayload = serviceMessage.encrypt( channel.firstPartySessionKeyPair.sessionKey.copy( - publicKey = generateECDHKeyPair().public // Invalid encryption key + publicKey = generateECDHKeyPair().public, // Invalid encryption key ), channel.thirdPartySessionKeyPair, ) @@ -199,7 +199,7 @@ internal class ReceiveMessagesTest : MockContextTestCase() { recipient = Recipient(PDACertPath.PRIVATE_ENDPOINT.subjectId), payload = parcelPayload, senderCertificate = PDACertPath.PDA, - senderCertificateChain = setOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW) + senderCertificateChain = setOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW), ) var ackWasCalled = false val parcelCollection = parcel.toParcelCollection { ackWasCalled = true } @@ -213,8 +213,8 @@ internal class ReceiveMessagesTest : MockContextTestCase() { assertTrue(ackWasCalled) assertTrue( logCaptor.warnLogs.contains( - "Failed to decrypt parcel; sender might have used wrong key" - ) + "Failed to decrypt parcel; sender might have used wrong key", + ), ) } @@ -227,7 +227,7 @@ internal class ReceiveMessagesTest : MockContextTestCase() { PublicThirdPartyEndpointData( channel.thirdPartyEndpoint.nodeId, channel.thirdPartyEndpoint.identityKey, - ) + ), ) val parcel = Parcel( recipient = Recipient(PDACertPath.PRIVATE_ENDPOINT.subjectId), @@ -236,7 +236,7 @@ internal class ReceiveMessagesTest : MockContextTestCase() { channel.thirdPartySessionKeyPair, ), senderCertificate = PDACertPath.PDA, - senderCertificateChain = setOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW) + senderCertificateChain = setOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW), ) var ackWasCalled = false val parcelCollection = parcel.toParcelCollection { ackWasCalled = true } @@ -250,8 +250,8 @@ internal class ReceiveMessagesTest : MockContextTestCase() { assertTrue(ackWasCalled) assertTrue( logCaptor.warnLogs.contains( - "Incoming parcel did not encapsulate a valid service message" - ) + "Incoming parcel did not encapsulate a valid service message", + ), ) } @@ -266,14 +266,14 @@ internal class ReceiveMessagesTest : MockContextTestCase() { issuerPrivateKey = KeyPairSet.PRIVATE_ENDPOINT.private, issuerCertificate = PDACertPath.PRIVATE_ENDPOINT, validityStartDate = ZonedDateTime.now().minusDays(1), - validityEndDate = ZonedDateTime.now().plusDays(1) + validityEndDate = ZonedDateTime.now().plusDays(1), ), - senderCertificateChain = setOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW) + senderCertificateChain = setOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW), ) private fun Parcel.toParcelCollection(ack: suspend () -> Unit = {}) = ParcelCollection( parcelSerialized = serialize(KeyPairSet.PDA_GRANTEE.private), trustedCertificates = listOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW), - ack = ack + ack = ack, ) } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/SendMessageTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/SendMessageTest.kt index bd634513..7db90a83 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/messaging/SendMessageTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/messaging/SendMessageTest.kt @@ -49,7 +49,7 @@ internal class SendMessageTest : MockContextTestCase() { val signer = deliverParcelCall.arguments!!.deliverySigner assertEquals( message.senderEndpoint.identityCertificate.subjectId, - signer.certificate.subjectId + signer.certificate.subjectId, ) } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/storage/StorageImplTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/storage/StorageImplTest.kt index 357786cc..dff7c501 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/storage/StorageImplTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/storage/StorageImplTest.kt @@ -5,8 +5,6 @@ import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import java.nio.charset.Charset -import java.util.UUID import kotlinx.coroutines.test.runTest import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertTrue @@ -17,6 +15,8 @@ import tech.relaycorp.awaladroid.storage.persistence.Persistence import tech.relaycorp.relaynet.pki.CertificationPath import tech.relaycorp.relaynet.testing.pki.KeyPairSet import tech.relaycorp.relaynet.testing.pki.PDACertPath +import java.nio.charset.Charset +import java.util.UUID internal class StorageImplTest { @@ -28,7 +28,7 @@ internal class StorageImplTest { val charset = Charset.forName("ASCII") storage.gatewayId.testGet( PDACertPath.PRIVATE_GW.subjectId.toByteArray(charset), - PDACertPath.PRIVATE_GW.subjectId + PDACertPath.PRIVATE_GW.subjectId, ) storage.gatewayId.testSet( PDACertPath.PRIVATE_GW.subjectId, @@ -43,7 +43,7 @@ internal class StorageImplTest { KeyPairSet.PRIVATE_ENDPOINT.public, CertificationPath( PDACertPath.PDA, - listOf(PDACertPath.PRIVATE_GW) + listOf(PDACertPath.PRIVATE_GW), ), "gateway.com", ) @@ -65,7 +65,7 @@ internal class StorageImplTest { fun publicThirdParty() = runTest { val data = PublicThirdPartyEndpointData( "example.org", - KeyPairSet.INTERNET_GW.public + KeyPairSet.INTERNET_GW.public, ) val rawData = data.serialize() @@ -81,7 +81,7 @@ internal class StorageImplTest { private suspend fun StorageImpl.Module.testGet( rawData: ByteArray, expectedOutput: T, - equalityCheck: ((T, T) -> Boolean) = Any::equals + equalityCheck: ((T, T) -> Boolean) = Any::equals, ) { val key = UUID.randomUUID().toString() whenever(persistence.get(any())).thenReturn(rawData) @@ -89,13 +89,13 @@ internal class StorageImplTest { verify(persistence).get(eq("$prefix$key")) assertTrue( "expected $expectedOutput, got $output", - equalityCheck(expectedOutput, output) + equalityCheck(expectedOutput, output), ) } private suspend fun StorageImpl.Module.testSet( data: T, - expectedRawData: ByteArray + expectedRawData: ByteArray, ) { val key = UUID.randomUUID().toString() set(key, data) @@ -125,20 +125,20 @@ internal class StorageImplTest { private suspend fun StorageImpl.SingleModule.testGet( rawData: ByteArray, expectedOutput: T, - equalityCheck: ((T, T) -> Boolean) = Any::equals + equalityCheck: ((T, T) -> Boolean) = Any::equals, ) { whenever(persistence.get(any())).thenReturn(rawData) val output = get()!! verify(persistence).get(eq("${prefix}base")) assertTrue( "expected $expectedOutput, got $output", - equalityCheck(expectedOutput, output) + equalityCheck(expectedOutput, output), ) } private suspend fun StorageImpl.SingleModule.testSet( data: T, - expectedRawData: ByteArray + expectedRawData: ByteArray, ) { set(data) verify(persistence).set(eq("${prefix}base"), eq(expectedRawData)) diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistenceTest.kt b/lib/src/test/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistenceTest.kt index 483c5cfc..deab9606 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistenceTest.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/storage/persistence/DiskPersistenceTest.kt @@ -1,8 +1,5 @@ package tech.relaycorp.awaladroid.storage.persistence -import java.io.File -import java.nio.charset.Charset -import kotlin.io.path.createTempDirectory import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest @@ -14,6 +11,9 @@ import org.junit.Assert.assertThrows import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test +import java.io.File +import java.nio.charset.Charset +import kotlin.io.path.createTempDirectory internal class DiskPersistenceTest { private val coroutineScope = TestScope() @@ -21,13 +21,14 @@ internal class DiskPersistenceTest { private lateinit var filesDir: String private lateinit var subject: DiskPersistence + @Before fun initDiskPersistence(): Unit = runBlocking { filesDir = createTempDirectory("rootDir").toString() subject = DiskPersistence( filesDir, coroutineScope.coroutineContext, - rootFolder + rootFolder, ) } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/test/AssertUtils.kt b/lib/src/test/java/tech/relaycorp/awaladroid/test/AssertUtils.kt index 29ce8df2..f9bbc3d9 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/test/AssertUtils.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/test/AssertUtils.kt @@ -1,8 +1,8 @@ package tech.relaycorp.awaladroid.test +import org.junit.Assert import java.time.Duration import java.time.ZonedDateTime -import org.junit.Assert internal fun assertSameDateTime(date1: ZonedDateTime, date2: ZonedDateTime) = Assert.assertTrue(Duration.between(date1, date2).seconds < 2) diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/test/FakeAndroidKeyStore.kt b/lib/src/test/java/tech/relaycorp/awaladroid/test/FakeAndroidKeyStore.kt index 0c1ed70d..6510315d 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/test/FakeAndroidKeyStore.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/test/FakeAndroidKeyStore.kt @@ -62,14 +62,14 @@ public object FakeAndroidKeyStore { alias: String?, key: Key?, password: CharArray?, - chain: Array? + chain: Array?, ): Unit = wrapped.setKeyEntry(alias, key, password, chain) override fun engineSetKeyEntry( alias: String?, key: ByteArray?, - chain: Array? + chain: Array?, ): Unit = wrapped.setKeyEntry(alias, key, chain) override fun engineStore(stream: OutputStream?, password: CharArray?): Unit = diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/test/MessageFactory.kt b/lib/src/test/java/tech/relaycorp/awaladroid/test/MessageFactory.kt index e5c9b398..853670a2 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/test/MessageFactory.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/test/MessageFactory.kt @@ -18,6 +18,6 @@ internal object MessageFactory { type = serviceMessage.type, content = serviceMessage.content, senderEndpoint = ThirdPartyEndpointFactory.buildPublic(), - recipientEndpoint = FirstPartyEndpointFactory.build() + recipientEndpoint = FirstPartyEndpointFactory.build(), ) {} } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/test/MockContextTestCase.kt b/lib/src/test/java/tech/relaycorp/awaladroid/test/MockContextTestCase.kt index 5a07a57e..ba24a4eb 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/test/MockContextTestCase.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/test/MockContextTestCase.kt @@ -47,8 +47,8 @@ internal abstract class MockContextTestCase { privateKeyStore, sessionPublicKeystore, certificateStore, - handleGatewayCertificateChange - ) + handleGatewayCertificateChange, + ), ) } @@ -62,7 +62,7 @@ internal abstract class MockContextTestCase { fun unsetContext(): Unit = unsetAwalaContext() protected suspend fun createEndpointChannel( - thirdPartyEndpointType: RecipientAddressType + thirdPartyEndpointType: RecipientAddressType, ): EndpointChannel { val firstPartyEndpoint = createFirstPartyEndpoint() @@ -103,7 +103,7 @@ internal abstract class MockContextTestCase { certificateStore.save( CertificationPath( certificate, - firstPartyEndpoint.identityCertificateChain + firstPartyEndpoint.identityCertificateChain, ), certificate.issuerCommonName, ) @@ -117,11 +117,11 @@ internal abstract class MockContextTestCase { } else { storage.gatewayId.set( firstPartyEndpoint.nodeId, - certificate.issuerCommonName + certificate.issuerCommonName, ) storage.internetAddress.set( - gatewayAddress + gatewayAddress, ) } @@ -131,7 +131,7 @@ internal abstract class MockContextTestCase { private suspend fun createThirdPartyEndpoint( thirdPartyEndpointType: RecipientAddressType, sessionKey: SessionKey, - firstPartyEndpoint: FirstPartyEndpoint + firstPartyEndpoint: FirstPartyEndpoint, ): ThirdPartyEndpoint { val thirdPartyEndpoint: ThirdPartyEndpoint when (thirdPartyEndpointType) { @@ -139,36 +139,36 @@ internal abstract class MockContextTestCase { thirdPartyEndpoint = ThirdPartyEndpointFactory.buildPrivate() val authBundle = CertificationPath( PDACertPath.PDA, - listOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW) + listOf(PDACertPath.PRIVATE_ENDPOINT, PDACertPath.PRIVATE_GW), ) whenever( storage.privateThirdParty.get( - "${firstPartyEndpoint.nodeId}_${thirdPartyEndpoint.nodeId}" - ) + "${firstPartyEndpoint.nodeId}_${thirdPartyEndpoint.nodeId}", + ), ).thenReturn( PrivateThirdPartyEndpointData( KeyPairSet.PDA_GRANTEE.public, authBundle, thirdPartyEndpoint.internetAddress, - ) + ), ) } else -> { thirdPartyEndpoint = ThirdPartyEndpointFactory.buildPublic() whenever( - storage.publicThirdParty.get(thirdPartyEndpoint.nodeId) + storage.publicThirdParty.get(thirdPartyEndpoint.nodeId), ).thenReturn( PublicThirdPartyEndpointData( thirdPartyEndpoint.internetAddress, - thirdPartyEndpoint.identityKey - ) + thirdPartyEndpoint.identityKey, + ), ) } } sessionPublicKeystore.save( sessionKey, - thirdPartyEndpoint.nodeId + thirdPartyEndpoint.nodeId, ) return thirdPartyEndpoint } diff --git a/lib/src/test/java/tech/relaycorp/awaladroid/test/ThirdPartyEndpointFactory.kt b/lib/src/test/java/tech/relaycorp/awaladroid/test/ThirdPartyEndpointFactory.kt index 5346c0f3..01030422 100644 --- a/lib/src/test/java/tech/relaycorp/awaladroid/test/ThirdPartyEndpointFactory.kt +++ b/lib/src/test/java/tech/relaycorp/awaladroid/test/ThirdPartyEndpointFactory.kt @@ -11,7 +11,7 @@ internal object ThirdPartyEndpointFactory { fun buildPublic(): PublicThirdPartyEndpoint { return PublicThirdPartyEndpoint( internetAddress, - KeyPairSet.PDA_GRANTEE.public + KeyPairSet.PDA_GRANTEE.public, ) }