diff --git a/lib/types/tunnelbroker/peer-to-peer-message-types.js b/lib/types/tunnelbroker/peer-to-peer-message-types.js index 4d2861575..2eca4b313 100644 --- a/lib/types/tunnelbroker/peer-to-peer-message-types.js +++ b/lib/types/tunnelbroker/peer-to-peer-message-types.js @@ -1,118 +1,129 @@ // @flow import type { TInterface, TUnion } from 'tcomb'; import t from 'tcomb'; import { tShape, tString, tUserID } from '../../utils/validation-utils.js'; import { type EncryptedData, encryptedDataValidator } from '../crypto-types.js'; import { signedDeviceListValidator, type SignedDeviceList, } from '../identity-service-types.js'; export type SenderInfo = { +userID: string, +deviceID: string, }; const senderInfoValidator: TInterface = tShape({ userID: tUserID, deviceID: t.String, }); export const peerToPeerMessageTypes = Object.freeze({ OUTBOUND_SESSION_CREATION: 'OutboundSessionCreation', ENCRYPTED_MESSAGE: 'EncryptedMessage', REFRESH_KEY_REQUEST: 'RefreshKeyRequest', QR_CODE_AUTH_MESSAGE: 'QRCodeAuthMessage', DEVICE_LIST_UPDATED: 'DeviceListUpdated', MESSAGE_PROCESSED: 'MessageProcessed', + IDENTITY_DEVICE_LIST_UPDATED: 'IdentityDeviceListUpdated', }); export type OutboundSessionCreation = { +type: 'OutboundSessionCreation', +senderInfo: SenderInfo, +encryptedData: EncryptedData, +sessionVersion: number, }; export const outboundSessionCreationValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.OUTBOUND_SESSION_CREATION), senderInfo: senderInfoValidator, encryptedData: encryptedDataValidator, sessionVersion: t.Number, }); export type EncryptedMessage = { +type: 'EncryptedMessage', +senderInfo: SenderInfo, +encryptedData: EncryptedData, }; export const encryptedMessageValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.ENCRYPTED_MESSAGE), senderInfo: senderInfoValidator, encryptedData: encryptedDataValidator, }); export type RefreshKeyRequest = { +type: 'RefreshKeyRequest', +deviceID: string, +numberOfKeys: number, }; export const refreshKeysRequestValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.REFRESH_KEY_REQUEST), deviceID: t.String, numberOfKeys: t.Number, }); export type QRCodeAuthMessage = { +type: 'QRCodeAuthMessage', +encryptedContent: string, }; export const qrCodeAuthMessageValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.QR_CODE_AUTH_MESSAGE), encryptedContent: t.String, }); export type DeviceListUpdated = { +type: 'DeviceListUpdated', +userID: string, +signedDeviceList?: SignedDeviceList, }; export const deviceListUpdatedValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.DEVICE_LIST_UPDATED), userID: tUserID, signedDeviceList: t.maybe(signedDeviceListValidator), }); export type MessageProcessed = { +type: 'MessageProcessed', +messageID: string, +deviceID: string, }; export const messageProcessedValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.MESSAGE_PROCESSED), messageID: t.String, deviceID: t.String, }); +export type IdentityDeviceListUpdated = { + +type: 'IdentityDeviceListUpdated', +}; +export const identityDeviceListUpdatedValidator: TInterface = + tShape({ + type: tString(peerToPeerMessageTypes.IDENTITY_DEVICE_LIST_UPDATED), + }); + export type PeerToPeerMessage = | OutboundSessionCreation | EncryptedMessage | RefreshKeyRequest | QRCodeAuthMessage | DeviceListUpdated - | MessageProcessed; + | MessageProcessed + | IdentityDeviceListUpdated; export const peerToPeerMessageValidator: TUnion = t.union([ outboundSessionCreationValidator, encryptedMessageValidator, refreshKeysRequestValidator, qrCodeAuthMessageValidator, deviceListUpdatedValidator, messageProcessedValidator, + identityDeviceListUpdatedValidator, ]); diff --git a/shared/tunnelbroker_messages/src/messages/device_list_updated.rs b/shared/tunnelbroker_messages/src/messages/device_list_updated.rs new file mode 100644 index 000000000..5ec64978d --- /dev/null +++ b/shared/tunnelbroker_messages/src/messages/device_list_updated.rs @@ -0,0 +1,7 @@ +//! Messages sent from Identity to device informing that device list was updated. + +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, PartialEq, Debug)] +#[serde(tag = "type", rename_all = "camelCase")] +pub struct IdentityDeviceListUpdated {} diff --git a/shared/tunnelbroker_messages/src/messages/mod.rs b/shared/tunnelbroker_messages/src/messages/mod.rs index 5d7367f4b..46f6574fa 100644 --- a/shared/tunnelbroker_messages/src/messages/mod.rs +++ b/shared/tunnelbroker_messages/src/messages/mod.rs @@ -1,50 +1,54 @@ //! Messages sent between Tunnelbroker and a device. +pub mod device_list_updated; pub mod keys; pub mod message_receive_confirmation; pub mod message_to_device; pub mod message_to_device_request; pub mod message_to_device_request_status; pub mod session; +pub use device_list_updated::*; pub use keys::*; pub use message_receive_confirmation::*; pub use message_to_device::*; pub use message_to_device_request::*; pub use message_to_device_request_status::*; pub use session::*; pub use websocket_messages::{ ConnectionInitializationResponse, ConnectionInitializationStatus, Heartbeat, }; use serde::{Deserialize, Serialize}; // This file defines types and validation for messages exchanged // with the Tunnelbroker. The definitions in this file should remain in sync // with the structures defined in the corresponding // JavaScript file at `lib/types/tunnelbroker/messages.js`. // If you edit the definitions in one file, // please make sure to update the corresponding definitions in the other. #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum Messages { ConnectionInitializationMessage(ConnectionInitializationMessage), ConnectionInitializationResponse(ConnectionInitializationResponse), AnonymousInitializationMessage(AnonymousInitializationMessage), // MessageToDeviceRequestStatus must be placed before MessageToDeviceRequest. // This is due to serde's pattern matching behavior where it prioritizes // the first matching pattern it encounters. MessageToDeviceRequestStatus(MessageToDeviceRequestStatus), MessageToDeviceRequest(MessageToDeviceRequest), MessageToDevice(MessageToDevice), MessageReceiveConfirmation(MessageReceiveConfirmation), Heartbeat(Heartbeat), + IdentityDeviceListUpdated(IdentityDeviceListUpdated), } #[derive(Serialize, Deserialize, Debug)] #[serde(untagged)] pub enum PeerToPeerMessages { RefreshKeysRequest(RefreshKeyRequest), + IdentityDeviceListUpdated(IdentityDeviceListUpdated), }