Skip to content

Commit 7f8f4b6

Browse files
committed
Fix #158 - unable to share on iOS 18.3.x
1 parent a46ab04 commit 7f8f4b6

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "share-note",
33
"name": "Share Note",
4-
"version": "1.1.3",
4+
"version": "1.2.0",
55
"minAppVersion": "0.15.0",
66
"description": "Instantly share a note, with the full theme and content exactly like you see in Reading View. Data is shared encrypted by default, and only you and the person you send it to have the key.",
77
"author": "Alan Grainger",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "share-note",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"description": "Instantly share a note, with the full theme and content exactly like you see in Reading View. Data is shared encrypted by default, and only you and the person you send it to have the key.",
55
"main": "main.js",
66
"scripts": {

src/crypto.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ function _getAesGcmKey (secret: ArrayBuffer): Promise<CryptoKey> {
4949
return window.crypto.subtle.importKey(
5050
'raw',
5151
secret,
52-
{ name: 'AES-GCM', length: 256 },
52+
{
53+
name: 'AES-GCM',
54+
length: 256
55+
},
5356
false,
5457
['encrypt', 'decrypt']
5558
)
@@ -69,7 +72,6 @@ export async function encryptString (plaintext: string, existingKey?: string): P
6972
} else {
7073
key = await _generateKey(window.crypto.getRandomValues(new Uint8Array(64)))
7174
}
72-
const iv = new Uint8Array(1)
7375
const aesKey = await _getAesGcmKey(key)
7476

7577
const ciphertext = []
@@ -79,9 +81,11 @@ export async function encryptString (plaintext: string, existingKey?: string): P
7981
while (index * chunkSize < length) {
8082
const plaintextChunk = plaintext.slice(index * chunkSize, (index + 1) * chunkSize)
8183
const encodedText = new TextEncoder().encode(plaintextChunk)
82-
iv[0] = index & 0xFF
8384
const bufCiphertext: ArrayBuffer = await window.crypto.subtle.encrypt(
84-
{ name: 'AES-GCM', iv },
85+
{
86+
name: 'AES-GCM',
87+
iv: indexToIv(index)
88+
},
8589
aesKey,
8690
encodedText
8791
)
@@ -100,16 +104,17 @@ export async function decryptString (encryptedData: EncryptedString) {
100104
name: 'AES-GCM',
101105
length: 256
102106
}, false, ['decrypt'])
103-
const iv = new Uint8Array(1)
104107

105108
const plaintext = []
106109

107110
for (let index = 0; index < encryptedData.ciphertext.length; index++) {
108111
const ciphertextChunk = encryptedData.ciphertext[index]
109-
iv[0] = index & 0xFF
110112
const ciphertextBuf = base64ToArrayBuffer(ciphertextChunk)
111113
const plaintextChunk = await window.crypto.subtle
112-
.decrypt({ name: 'AES-GCM', iv }, aesKey, ciphertextBuf)
114+
.decrypt({
115+
name: 'AES-GCM',
116+
iv: indexToIv(index)
117+
}, aesKey, ciphertextBuf)
113118
plaintext.push(new TextDecoder().decode(plaintextChunk))
114119
}
115120
return plaintext.join('')
@@ -138,3 +143,15 @@ export async function sha1 (data: string | ArrayBuffer) {
138143
export async function shortHash (text: string) {
139144
return (await sha256(text)).slice(0, 32)
140145
}
146+
147+
/**
148+
* Take an integer index and return the corresponding IV
149+
*/
150+
function indexToIv (int: number) {
151+
const iv = new Uint8Array(12)
152+
for (let i = 0; i < iv.length; i++) {
153+
iv[i] = int % 256
154+
int = Math.floor(int / 256)
155+
}
156+
return iv
157+
}

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"1.1.0": "0.15.0",
2323
"1.1.1": "0.15.0",
2424
"1.1.2": "0.15.0",
25-
"1.1.3": "0.15.0"
25+
"1.1.3": "0.15.0",
26+
"1.2.0": "0.15.0"
2627
}

0 commit comments

Comments
 (0)