Skip to content

Commit

Permalink
feat(FirstPartyEndpoint): Expose third-party node id when authorising (
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Oct 29, 2023
1 parent 0c8033e commit e965f63
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
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

0 comments on commit e965f63

Please sign in to comment.