Skip to content

Commit 922fb2d

Browse files
committed
fix: add supersuper fileserver for testing
1 parent a86f529 commit 922fb2d

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

ts/session/apis/file_server_api/FileServerApi.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export const uploadFileToFsWithOnionV4 = async (
3535
}
3636

3737
// TODO: remove this once QA is done
38-
const target = process.env.POTATO_FS ? 'POTATO' : 'DEFAULT';
38+
const target = process.env.POTATO_FS
39+
? 'POTATO'
40+
: process.env.SUPER_DUPER_FS
41+
? 'SUPER_DUPER'
42+
: 'DEFAULT';
3943

4044
const result = await OnionSending.sendBinaryViaOnionV4ToFileServer({
4145
abortSignal: new AbortController().signal,

ts/session/apis/file_server_api/FileServerTarget.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ type FileServerConfigType = {
1414

1515
// not exported/included in the SERVER_HOSTS as this is for testing only
1616
const POTATO_FS_HOST = 'potatofiles.getsession.org';
17+
const SUPER_DUPER_FS_HOST = 'superduperfiles.oxen.io';
1718

18-
const FILE_SERVERS: Record<'DEFAULT' | 'POTATO', FileServerConfigType> = {
19+
const FILE_SERVERS: Record<'DEFAULT' | 'POTATO' | 'SUPER_DUPER', FileServerConfigType> = {
1920
DEFAULT: {
2021
url: `http://${SERVER_HOSTS.DEFAULT_FILE_SERVER}`,
2122
xPk: '09324794aa9c11948189762d198c618148e9136ac9582068180661208927ef34',
@@ -24,11 +25,16 @@ const FILE_SERVERS: Record<'DEFAULT' | 'POTATO', FileServerConfigType> = {
2425
},
2526
POTATO: {
2627
url: `http://${POTATO_FS_HOST}`,
27-
// potato has different keys than the default
2828
edPk: 'ff86dcd4b26d1bfec944c59859494248626d6428efc12168749d65a1b92f5e28',
2929
xPk: 'fc097b06821c98a2db75ce02e521cef5fd9d3446e42e81d843c4c8c4e9260f48',
3030
extraFeatures: [FS_FEATURES.fsExtend],
3131
},
32+
SUPER_DUPER: {
33+
url: `http://${SUPER_DUPER_FS_HOST}`,
34+
edPk: '929e33ded05e653fec04b49645117f51851f102a947e04806791be416ed76602',
35+
xPk: '16d6c60aebb0851de7e6f4dc0a4734671dbf80f73664c008596511454cb6576d',
36+
extraFeatures: [FS_FEATURES.fsExtend],
37+
},
3238
};
3339

3440
const FILE_SERVER_TARGETS = Object.keys(FILE_SERVERS) as Array<FILE_SERVER_TARGET_TYPE>;
@@ -55,6 +61,11 @@ function fileUrlToFileTarget(url: string): FILE_SERVER_TARGET_TYPE {
5561
return 'POTATO';
5662
}
5763
break;
64+
case 'SUPER_DUPER':
65+
if (parsedUrl.host.includes(SUPER_DUPER_FS_HOST)) {
66+
return 'SUPER_DUPER';
67+
}
68+
break;
5869
case 'DEFAULT':
5970
if (parsedUrl.host.includes(SERVER_HOSTS.DEFAULT_FILE_SERVER)) {
6071
return 'DEFAULT';

ts/session/utils/Attachments.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ type UploadParams = {
2323
* Explicit padding is only needed for the legacy encryption, as libsession deterministic encryption already pads the data.
2424
*/
2525
shouldPad?: boolean;
26-
/**
27-
* When using the deterministic encryption, this is the seed used to generate the encryption key (libsession encrypt)
28-
* When not using the deterministic encryption, this is used as the encryption key (legacy encrypt)
29-
*/
30-
encryptionKey: Uint8Array;
3126
};
3227

3328
export interface RawPreview {
@@ -80,17 +75,18 @@ async function uploadToFileServer(params: UploadParams): Promise<AttachmentPoint
8075
'Using deterministic encryption for attachment upload: ',
8176
attachment.fileName
8277
);
78+
const seed = await UserUtils.getUserEd25519Seed();
8379
const encryptedContent = await MultiEncryptWrapperActions.attachmentEncrypt({
8480
allowLarge: false,
85-
seed: params.encryptionKey,
81+
seed,
8682
data: new Uint8Array(attachment.data),
8783
domain: 'attachment',
8884
});
8985
pointer.key = encryptedContent.encryptionKey;
9086
attachmentData = encryptedContent.encryptedData;
9187
} else {
9288
// this is the legacy attachment encryption
93-
pointer.key = new Uint8Array(params.encryptionKey);
89+
pointer.key = new Uint8Array(crypto.randomBytes(64));
9490
const iv = new Uint8Array(crypto.randomBytes(16));
9591

9692
const dataToEncrypt = !shouldPad ? attachment.data : addAttachmentPadding(attachment.data);
@@ -115,15 +111,10 @@ async function uploadToFileServer(params: UploadParams): Promise<AttachmentPoint
115111
export async function uploadAttachmentsToFileServer(
116112
attachments: Array<Attachment>
117113
): Promise<Array<AttachmentPointerWithUrl>> {
118-
const encryptionKey = window.sessionFeatureFlags.useDeterministicEncryption
119-
? await UserUtils.getUserEd25519Seed()
120-
: crypto.randomBytes(32);
121-
122114
const promises = (attachments || []).map(async attachment =>
123115
uploadToFileServer({
124116
attachment,
125117
shouldPad: true,
126-
encryptionKey,
127118
})
128119
);
129120

@@ -140,13 +131,9 @@ export async function uploadLinkPreviewToFileServer(
140131
}
141132
return preview as any;
142133
}
143-
const encryptionKey = window.sessionFeatureFlags.useDeterministicEncryption
144-
? await UserUtils.getUserEd25519Seed()
145-
: crypto.randomBytes(32);
146134

147135
const image = await uploadToFileServer({
148136
attachment: preview.image,
149-
encryptionKey,
150137
});
151138
return {
152139
...preview,

ts/util/crypto/attachmentsEncrypter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ export async function encryptAttachment(
103103
}
104104

105105
if (keys.byteLength !== 64) {
106-
throw new Error('Got invalid length attachment keys');
106+
throw new Error(`Got invalid length attachment keys: ${keys.byteLength}`);
107107
}
108108
if (iv.byteLength !== 16) {
109-
throw new Error('Got invalid length attachment iv');
109+
throw new Error(`Got invalid length attachment iv: ${iv.byteLength}`);
110110
}
111111
const aesKey = keys.slice(0, 32);
112112
const macKey = keys.slice(32, 64);

0 commit comments

Comments
 (0)