Skip to content

Commit 41fb9a0

Browse files
authored
Merge pull request #854 from nextcloud/artonge/chore/cleanups
chore: E2EE in browser cleanups
2 parents 2cb683d + 1988d0a commit 41fb9a0

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

js/end_to_end_encryption-files.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

js/end_to_end_encryption-files.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/MnemonicPromptDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const buttons = computed(() => [
5050
{{ t('end_to_end_encryption', 'The server could serve malicious source code to extract the secret that protects your files.') }}
5151

5252
<NcCheckboxRadioSwitch v-model="confirmToggle"
53-
required="true"
53+
:required="true"
5454
data-cy-e2ee-mnemonic-prompt="i_understand_the_risks"
5555
type="switch">
5656
{{ t('end_to_end_encryption', 'I understand the risks') }}

src/services/metadataUtils.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import { decryptWithAES, decryptWithRSA, exportAESKey, loadAESPrivateKey, sha256
1111

1212
/* eslint-disable jsdoc/require-jsdoc */
1313

14-
export async function getMetadataInfo(fileId: string, metadataPrivateKey: CryptoKey): Promise<MetadataInfo> {
15-
logger.debug('Getting metadata info', { fileId })
16-
return await decryptMetadataInfo(await getMetadata(fileId), metadataPrivateKey)
17-
}
18-
1914
export async function decryptMetadataInfo(metadata: Metadata, metadataPrivateKey: CryptoKey): Promise<MetadataInfo> {
2015
logger.debug('Decrypting metadata info', { metadata })
2116

@@ -29,12 +24,12 @@ export async function decryptMetadataInfo(metadata: Metadata, metadataPrivateKey
2924

3025
const metadataInfo = JSON.parse(await unzipBuffer(compressedMetadataInfo))
3126

32-
verifyMetadataInfo(metadataInfo, metadataPrivateKey)
27+
verifyMetadataKey(metadataInfo, metadataPrivateKey)
3328

3429
return metadataInfo
3530
}
3631

37-
export async function verifyMetadataInfo(metadataInfo: MetadataInfo, metadataPrivateKey: CryptoKey): Promise<void> {
32+
export async function verifyMetadataKey(metadataInfo: MetadataInfo, metadataPrivateKey: CryptoKey): Promise<void> {
3833
if (metadataInfo.keyChecksums === undefined) {
3934
return
4035
}

src/services/privateKeyUtils.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import logger from './logger.ts'
99
import type { PrivateKeyInfo } from '../models.ts'
1010
import { decryptWithAES, loadRSAPrivateKey } from './crypto.ts'
11-
import { base64ToBuffer, bufferToString } from './utils.ts'
12-
13-
const PEM_HEADER = '-----BEGIN PRIVATE KEY-----'
14-
const PEM_FOOTER = '-----END PRIVATE KEY-----'
11+
import { bufferToString, pemToBuffer } from './utils.ts'
1512

1613
export async function decryptPrivateKey(privateKeyInfo: PrivateKeyInfo, mnemonic: string): Promise<CryptoKey> {
1714
logger.debug('Decrypting private key', { privateKeyInfo, mnemonic })
@@ -24,7 +21,8 @@ export async function decryptPrivateKey(privateKeyInfo: PrivateKeyInfo, mnemonic
2421
{ iv: privateKeyInfo.iv, tagLength: 128 },
2522
)
2623

27-
return loadPemKey(atob(bufferToString(new Uint8Array(rawPrivateKey))))
24+
const pemKey = atob(bufferToString(new Uint8Array(rawPrivateKey)))
25+
return loadRSAPrivateKey(pemToBuffer(pemKey))
2826
}
2927

3028
async function mnemonicToPrivateKey(mnemonic: string, salt: Uint8Array): Promise<CryptoKey> {
@@ -49,16 +47,3 @@ async function mnemonicToPrivateKey(mnemonic: string, salt: Uint8Array): Promise
4947
['decrypt', 'encrypt'],
5048
)
5149
}
52-
53-
async function loadPemKey(pem: string): Promise<CryptoKey> {
54-
logger.debug('Loading PEM key', { pem })
55-
56-
const pemContents = pem
57-
.substring(
58-
PEM_HEADER.length,
59-
pem.length - PEM_FOOTER.length - 1,
60-
)
61-
.replace(/\n/g, '')
62-
63-
return loadRSAPrivateKey(base64ToBuffer(pemContents))
64-
}

src/services/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ export function bufferToHex(buffer: Uint8Array): string {
2424
export function base64ToBuffer(base64Str: string): Uint8Array {
2525
return stringToBuffer(atob(base64Str))
2626
}
27+
28+
const PEM_HEADER = '-----BEGIN PRIVATE KEY-----'
29+
const PEM_FOOTER = '-----END PRIVATE KEY-----'
30+
31+
export function pemToBuffer(pem: string): Uint8Array {
32+
const pemContents = pem
33+
.substring(
34+
PEM_HEADER.length,
35+
pem.length - PEM_FOOTER.length - 1,
36+
)
37+
.replace(/\n/g, '')
38+
39+
return base64ToBuffer(pemContents)
40+
}

0 commit comments

Comments
 (0)