Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(FirstPartyEndpoint): Expose third-party node id when authorising #354

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal constructor(
issueAuthorization(
thirdPartyEndpoint.identityKey,
expiryDate,
)
).auth

/**
* Issue a PDA for a third-party endpoint using its public key.
Expand All @@ -66,7 +66,7 @@ internal constructor(
public suspend fun issueAuthorization(
thirdPartyEndpointPublicKeySerialized: ByteArray,
expiryDate: ZonedDateTime,
): ByteArray {
): ThirdPartyEndpointAuth {
val thirdPartyEndpointPublicKey =
deserializePDAGranteePublicKey(thirdPartyEndpointPublicKeySerialized)
return issueAuthorization(thirdPartyEndpointPublicKey, expiryDate)
Expand All @@ -76,7 +76,7 @@ internal constructor(
private suspend fun issueAuthorization(
thirdPartyEndpointPublicKey: PublicKey,
expiryDate: ZonedDateTime,
): ByteArray {
): ThirdPartyEndpointAuth {
val pda = issueDeliveryAuthorization(
subjectPublicKey = thirdPartyEndpointPublicKey,
issuerPrivateKey = identityPrivateKey,
Expand All @@ -97,7 +97,8 @@ internal constructor(
deliveryAuth,
sessionKeyPair.sessionKey,
)
return connParams.serialize()
val authSerialized = connParams.serialize()
return ThirdPartyEndpointAuth(thirdPartyEndpointPublicKey.nodeId, authSerialized)
}

/**
Expand All @@ -107,15 +108,15 @@ internal constructor(
public suspend fun authorizeIndefinitely(
thirdPartyEndpoint: ThirdPartyEndpoint,
): ByteArray =
authorizeIndefinitely(thirdPartyEndpoint.identityKey)
authorizeIndefinitely(thirdPartyEndpoint.identityKey).auth

/**
* Issue a PDA for a third-party endpoint (using its public key) and renew it indefinitely.
*/
@Throws(CertificateException::class)
public suspend fun authorizeIndefinitely(
thirdPartyEndpointPublicKeySerialized: ByteArray,
): ByteArray {
): ThirdPartyEndpointAuth {
val thirdPartyEndpointPublicKey =
deserializePDAGranteePublicKey(thirdPartyEndpointPublicKeySerialized)
return authorizeIndefinitely(thirdPartyEndpointPublicKey)
Expand All @@ -124,7 +125,7 @@ internal constructor(
@Throws(CertificateException::class)
private suspend fun authorizeIndefinitely(
thirdPartyEndpointPublicKey: PublicKey,
): ByteArray {
): ThirdPartyEndpointAuth {
val authorization =
issueAuthorization(thirdPartyEndpointPublicKey, identityCertificate.expiryDate)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tech.relaycorp.awaladroid.endpoint

/**
* Parcel delivery authorization for a third-party endpoint.
*/
public class ThirdPartyEndpointAuth(
/**
* Id of the third-party endpoint.
*/
public val endpointId: String,

/**
* The authorization serialized.
*/
public val auth: ByteArray,
)
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,19 @@ internal class FirstPartyEndpointTest : MockContextTestCase() {
}
}

private fun validateAuthorization(
auth: ThirdPartyEndpointAuth,
firstPartyEndpoint: FirstPartyEndpoint,
expiryDate: ZonedDateTime,
) {
assertEquals(
auth.endpointId,
KeyPairSet.PDA_GRANTEE.public.nodeId,
)

validateAuthorization(auth.auth, firstPartyEndpoint, expiryDate)
}

private fun validateAuthorization(
paramsSerialized: ByteArray,
firstPartyEndpoint: FirstPartyEndpoint,
Expand Down
Loading