Skip to content

Commit

Permalink
fix(Channel): Output RAMF recipient Internet address when known (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored May 24, 2023
1 parent 04304ab commit 526af30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
32 changes: 29 additions & 3 deletions src/lib/nodes/channels/Channel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { arrayBufferFrom, CRYPTO_OIDS, reSerializeCertificate } from '../../_tes
import { SessionEnvelopedData } from '../../crypto/cms/envelopedData';
import { generateRSAKeyPair } from '../../crypto/keys/generation';
import { MockKeyStoreSet } from '../../keyStores/testMocks';
import { Recipient } from '../../messages/Recipient';
import { issueGatewayCertificate } from '../../pki/issuance';
import { StubMessage, StubPayload } from '../../ramf/_test_utils';
import { NodeError } from '../errors';
import { getIdFromIdentityKey } from '../../crypto/keys/digest';
import { StubNode } from '../_test_utils';
import { StubEndpoint, StubEndpointChannel, StubNode } from '../_test_utils';
import { Peer } from '../peer';
import { StubNodeChannel } from './_test_utils';
import { CertificationPath } from '../../pki/CertificationPath';
Expand Down Expand Up @@ -252,6 +251,33 @@ describe('getOutboundRAMFRecipient', () => {
test('Id should be output', () => {
const channel = new StubNodeChannel(node, peer, deliveryAuthPath, KEY_STORES);

expect(channel.getOutboundRAMFRecipient()).toEqual<Recipient>({ id: peer.id });
const recipient = channel.getOutboundRAMFRecipient();
expect(recipient.id).toBe(peer.id);
});

test('Internet address should not be output if peer is private', () => {
const channel = new StubNodeChannel(node, peer, deliveryAuthPath, KEY_STORES);

const recipient = channel.getOutboundRAMFRecipient();
expect(recipient.internetAddress).toBeUndefined();
});

test('Internet address should be output if peer has one', () => {
const endpoint = new StubEndpoint(
node.id,
node.identityKeyPair,
node.keyStores,
node.cryptoOptions,
);
const internetAddress = 'example.com';
const channel = new StubEndpointChannel(
endpoint,
{ ...peer, internetAddress },
deliveryAuthPath,
KEY_STORES,
);

const recipient = channel.getOutboundRAMFRecipient();
expect(recipient.internetAddress).toBe(internetAddress);
});
});
2 changes: 1 addition & 1 deletion src/lib/nodes/channels/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ export abstract class Channel<
}

public getOutboundRAMFRecipient(): Recipient {
return { id: this.peer.id };
return { id: this.peer.id, internetAddress: this.peer.internetAddress };
}
}
7 changes: 0 additions & 7 deletions src/lib/nodes/channels/PrivateInternetGatewayChannel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ beforeEach(() => {
);
});

test('getOutboundRAMFRecipient should return Internet address of Internet gateway', async () => {
expect(channel.getOutboundRAMFRecipient()).toEqual<Recipient>({
id: internetGateway.id,
internetAddress: INTERNET_GATEWAY_INTERNET_ADDRESS,
});
});

describe('Endpoint registration', () => {
const GATEWAY_DATA = arrayBufferFrom('the gw data');
const EXPIRY_DATE = setMilliseconds(addDays(new Date(), 1), 0);
Expand Down
12 changes: 0 additions & 12 deletions src/lib/nodes/channels/PrivateInternetGatewayChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PrivateNodeRegistration } from '../../bindings/gsc/PrivateNodeRegistrat
import { PrivateNodeRegistrationAuthorization } from '../../bindings/gsc/PrivateNodeRegistrationAuthorization';
import { CargoCollectionAuthorization } from '../../messages/CargoCollectionAuthorization';
import { CargoCollectionRequest } from '../../messages/payloads/CargoCollectionRequest';
import { Recipient } from '../../messages/Recipient';
import { issueEndpointCertificate, issueGatewayCertificate } from '../../pki/issuance';
import { PrivateGatewayChannel } from './PrivateGatewayChannel';

Expand All @@ -15,15 +14,6 @@ const OUTBOUND_CARGO_TTL_DAYS = 14;
* Channel between a private gateway (the node) and its Internet gateway (the peer).
*/
export class PrivateInternetGatewayChannel extends PrivateGatewayChannel<string> {
override getOutboundRAMFRecipient(): Recipient {
return {
...super.getOutboundRAMFRecipient(),
internetAddress: this.peer.internetAddress,
};
}

//region Private endpoint registration

/**
* Generate a `PrivateNodeRegistrationAuthorization` with the `gatewayData` and `expiryDate`.
*
Expand Down Expand Up @@ -75,8 +65,6 @@ export class PrivateInternetGatewayChannel extends PrivateGatewayChannel<string>
return registration.serialize();
}

//endregion

public async generateCCA(): Promise<ArrayBuffer> {
const now = new Date();
const startDate = subMinutes(now, CLOCK_DRIFT_TOLERANCE_MINUTES);
Expand Down

0 comments on commit 526af30

Please sign in to comment.