Skip to content

Commit

Permalink
feat(nodes): Implement GatewayManager (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Nov 18, 2021
1 parent d14d29c commit c58e396
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import tech.relaycorp.relaynet.wrappers.asn1.ASN1Utils
import tech.relaycorp.relaynet.wrappers.x509.Certificate
import tech.relaycorp.relaynet.wrappers.x509.CertificateException

class CargoCollectionRequest(val cargoDeliveryAuthorization: Certificate) : EncryptedPayload() {
class CargoCollectionRequest(
val cargoDeliveryAuthorization: Certificate
) : GatewayEncryptedPayload() {
override fun serializePlaintext(): ByteArray {
val cdaASN1 = DEROctetString(cargoDeliveryAuthorization.serialize())
return ASN1Utils.serializeSequence(listOf(cdaASN1), false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import tech.relaycorp.relaynet.wrappers.asn1.ASN1Utils
/**
* Cargo message set.
*/
class CargoMessageSet(val messages: Array<ByteArray>) : EncryptedPayload() {
class CargoMessageSet(val messages: Array<ByteArray>) : GatewayEncryptedPayload() {
/**
* Serialize cargo message set.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package tech.relaycorp.relaynet.messages.payloads

abstract class GatewayEncryptedPayload : EncryptedPayload()
11 changes: 11 additions & 0 deletions src/main/kotlin/tech/relaycorp/relaynet/nodes/GatewayManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tech.relaycorp.relaynet.nodes

import tech.relaycorp.relaynet.keystores.PrivateKeyStore
import tech.relaycorp.relaynet.keystores.SessionPublicKeyStore
import tech.relaycorp.relaynet.messages.payloads.GatewayEncryptedPayload

class GatewayManager(
privateKeyStore: PrivateKeyStore,
sessionPublicKeyStore: SessionPublicKeyStore,
cryptoOptions: NodeCryptoOptions = NodeCryptoOptions(),
) : NodeManager<GatewayEncryptedPayload> (privateKeyStore, sessionPublicKeyStore, cryptoOptions)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tech.relaycorp.relaynet.nodes

import kotlin.test.assertEquals
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import tech.relaycorp.relaynet.ECDHCurve
import tech.relaycorp.relaynet.HashingAlgorithm
import tech.relaycorp.relaynet.SymmetricCipher
import tech.relaycorp.relaynet.utils.MockPrivateKeyStore
import tech.relaycorp.relaynet.utils.MockSessionPublicKeyStore

class GatewayManagerTest {
private val privateKeyStore = MockPrivateKeyStore()
private val sessionPublicKeyStore = MockSessionPublicKeyStore()

@Nested
inner class Constructor {
@Test
fun `Default crypto algorithms should be used by default`() {
val gatewayManager = GatewayManager(privateKeyStore, sessionPublicKeyStore)

assertEquals(NodeCryptoOptions(), gatewayManager.cryptoOptions)
}

@Test
fun `Custom crypto algorithms should be honored`() {
val options = NodeCryptoOptions(
ECDHCurve.P521,
SymmetricCipher.AES_256,
HashingAlgorithm.SHA512,
)
val gatewayManager = GatewayManager(privateKeyStore, sessionPublicKeyStore, options)

assertEquals(options, gatewayManager.cryptoOptions)
}
}
}

0 comments on commit c58e396

Please sign in to comment.