Skip to content

Commit

Permalink
fix(Parcel collection): Convert handshake messages to ASN.1 DER (#65)
Browse files Browse the repository at this point in the history
Because ProtoBuf was a royal pain in the neck.
  • Loading branch information
gnarea authored Oct 20, 2020
1 parent 21af21b commit ef0c79f
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 280 deletions.
28 changes: 1 addition & 27 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
ext.kotlinVersion = '1.4.10'
ext.protobufVersion = '3.13.0'
ext.protobufGradleVersion = '0.8.13'
ext.kotlinCoroutinesVersion = '1.3.8'
ext.ktorVersion = '1.4.1'
ext.okhttpVersion = '4.9.0'
Expand All @@ -16,7 +14,6 @@ plugins {
id('maven-publish')
id("com.diffplug.gradle.spotless") version "3.27.1"
id('jacoco')
id("com.google.protobuf") version "$protobufGradleVersion"
id('idea')
}

Expand All @@ -33,7 +30,7 @@ dependencies {

implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")

api('tech.relaycorp:relaynet:1.36.5')
api('tech.relaycorp:relaynet:1.37.0')
implementation('tech.relaycorp:relaynet-testing:1.0.0')

// Handshake nonce signatures
Expand All @@ -48,11 +45,6 @@ dependencies {
testImplementation("com.squareup.okio:okio:2.9.0")
testImplementation("org.awaitility:awaitility:4.0.3")

// Protobuf
implementation("com.google.protobuf:protobuf-gradle-plugin:$protobufGradleVersion")
implementation("com.google.protobuf:protobuf-java:$protobufVersion")
implementation("com.google.protobuf:protobuf-java-util:$protobufVersion")

testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0")
Expand Down Expand Up @@ -80,10 +72,6 @@ tasks.withType(KotlinCompile).all {
}
}

protobuf {
protoc { artifact = "com.google.protobuf:protoc:$protobufVersion" }
}

tasks.dokka {
outputFormat = "html"
outputDirectory = "$buildDir/docs/api"
Expand Down Expand Up @@ -147,20 +135,6 @@ spotless {
}
}

// Workaround for https://github.com/google/protobuf-gradle-plugin/issues/391
configurations {
"compileProtoPath" {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, "java-runtime"))
}
}
"testCompileProtoPath" {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, "java-runtime"))
}
}
}

gradleEnterprise {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
Expand Down
13 changes: 2 additions & 11 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user manual at https://docs.gradle.org/6.1.1/userguide/multi_project_builds.html
*/

rootProject.name = "poweb"

plugins {
id("com.gradle.enterprise").version("3.3.4")
}

rootProject.name = "poweb"
13 changes: 6 additions & 7 deletions src/main/kotlin/tech/relaycorp/poweb/PoWebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import okhttp3.OkHttpClient
import tech.relaycorp.poweb.handshake.Challenge
import tech.relaycorp.poweb.handshake.InvalidChallengeException
import tech.relaycorp.poweb.handshake.Response
import tech.relaycorp.relaynet.bindings.pdc.NonceSigner
import tech.relaycorp.relaynet.bindings.pdc.ParcelCollection
import tech.relaycorp.relaynet.bindings.pdc.StreamingMode
import tech.relaycorp.relaynet.messages.InvalidMessageException
import tech.relaycorp.relaynet.messages.control.HandshakeChallenge
import tech.relaycorp.relaynet.messages.control.HandshakeResponse
import tech.relaycorp.relaynet.messages.control.ParcelDelivery
import tech.relaycorp.relaynet.messages.control.PrivateNodeRegistration
import tech.relaycorp.relaynet.wrappers.x509.Certificate
Expand Down Expand Up @@ -313,12 +312,12 @@ public class PoWebClient internal constructor(
private suspend fun DefaultClientWebSocketSession.handshake(nonceSigners: Array<NonceSigner>) {
val challengeRaw = incoming.receive()
val challenge = try {
Challenge.deserialize(challengeRaw.readBytes())
} catch (exc: InvalidChallengeException) {
HandshakeChallenge.deserialize(challengeRaw.readBytes())
} catch (exc: InvalidMessageException) {
close(CloseReason(CloseReason.Codes.VIOLATED_POLICY, ""))
throw ServerBindingException("Server sent an invalid handshake challenge", exc)
}
val nonceSignatures = nonceSigners.map { it.sign(challenge.nonce) }.toTypedArray()
val response = Response(nonceSignatures)
val nonceSignatures = nonceSigners.map { it.sign(challenge.nonce) }.toList()
val response = HandshakeResponse(nonceSignatures)
outgoing.send(Frame.Binary(true, response.serialize()))
}
24 changes: 0 additions & 24 deletions src/main/kotlin/tech/relaycorp/poweb/handshake/Challenge.kt

This file was deleted.

This file was deleted.

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/kotlin/tech/relaycorp/poweb/handshake/Response.kt

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/proto/poweb-handshake.proto

This file was deleted.

11 changes: 5 additions & 6 deletions src/test/kotlin/tech/relaycorp/poweb/ParcelCollectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import tech.relaycorp.poweb.handshake.InvalidChallengeException
import tech.relaycorp.poweb.websocket.ActionSequence
import tech.relaycorp.poweb.websocket.ChallengeAction
import tech.relaycorp.poweb.websocket.CloseConnectionAction
Expand All @@ -24,6 +23,7 @@ import tech.relaycorp.relaynet.bindings.pdc.NonceSigner
import tech.relaycorp.relaynet.bindings.pdc.StreamingMode
import tech.relaycorp.relaynet.issueEndpointCertificate
import tech.relaycorp.relaynet.messages.InvalidMessageException
import tech.relaycorp.relaynet.messages.control.HandshakeResponse
import tech.relaycorp.relaynet.messages.control.NonceSignature
import tech.relaycorp.relaynet.wrappers.generateRSAKeyPair
import java.nio.charset.Charset
Expand Down Expand Up @@ -95,7 +95,7 @@ class ParcelCollectionTest : WebSocketTestCase() {
}

assertEquals("Server sent an invalid handshake challenge", exception.message)
assertTrue(exception.cause is InvalidChallengeException)
assertTrue(exception.cause is InvalidMessageException)
}

awaitForConnectionClosure()
Expand Down Expand Up @@ -130,9 +130,7 @@ class ParcelCollectionTest : WebSocketTestCase() {
awaitForConnectionClosure()

assertEquals(1, listener!!.receivedMessages.size)
val response = tech.relaycorp.poweb.handshake.Response.deserialize(
listener!!.receivedMessages.first()
)
val response = HandshakeResponse.deserialize(listener!!.receivedMessages.first())
val nonceSignatures = response.nonceSignatures
val signature1 = NonceSignature.deserialize(nonceSignatures[0])
assertEquals(nonce.asList(), signature1.nonce.asList())
Expand Down Expand Up @@ -401,7 +399,8 @@ class ParcelCollectionTest : WebSocketTestCase() {
val certificate = issueEndpointCertificate(
keyPair.public,
keyPair.private,
ZonedDateTime.now().plusDays(1))
ZonedDateTime.now().plusDays(1)
)
return NonceSigner(certificate, keyPair.private)
}
}
49 changes: 0 additions & 49 deletions src/test/kotlin/tech/relaycorp/poweb/handshake/ChallengeTest.kt

This file was deleted.

103 changes: 0 additions & 103 deletions src/test/kotlin/tech/relaycorp/poweb/handshake/ResponseTest.kt

This file was deleted.

Loading

0 comments on commit ef0c79f

Please sign in to comment.