Skip to content

Commit

Permalink
Merge pull request #1668 from floccusaddon/fix/encryption-salt
Browse files Browse the repository at this point in the history
fix(GoogleDrive,WebDAV): Allow passing salt in file contents
  • Loading branch information
marcelklehr authored Jul 6, 2024
2 parents 20a2426 + 95b2bb6 commit af25b70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/lib/adapters/GoogleDrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class GoogleDriveAdapter extends CachingAdapter {

this.accessToken = await this.getAccessToken(this.server.refreshToken)

const fileList = await this.listFiles('name = ' + "'" + this.server.bookmark_file + "'")
const fileList = await this.listFiles(`name = '${this.server.bookmark_file}'`)
const file = fileList.files.filter(file => !file.trashed)[0]
if (file) {
this.fileId = file.id
Expand All @@ -234,7 +234,13 @@ export default class GoogleDriveAdapter extends CachingAdapter {

if (this.server.password) {
try {
xmlDocText = await Crypto.decryptAES(this.server.password, xmlDocText, this.server.bookmark_file)
try {
// TODO: Use this when encrypting
const json = JSON.parse(xmlDocText)
xmlDocText = await Crypto.decryptAES(this.server.password, json.ciphertext, json.salt)
} catch (e) {
xmlDocText = await Crypto.decryptAES(this.server.password, xmlDocText, this.server.bookmark_file)
}
} catch (e) {
if (xmlDocText.includes('<?xml version="1.0" encoding="UTF-8"?>')) {
// not encrypted, yet => noop
Expand Down
7 changes: 6 additions & 1 deletion src/lib/adapters/WebDav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ export default class WebDavAdapter extends CachingAdapter {

if (this.server.passphrase) {
try {
xmlDocText = await Crypto.decryptAES(this.server.passphrase, xmlDocText, this.server.bookmark_file)
try {
const json = JSON.parse(xmlDocText)
xmlDocText = await Crypto.decryptAES(this.server.passphrase, json.ciphertext, json.salt)
} catch (e) {
xmlDocText = await Crypto.decryptAES(this.server.passphrase, xmlDocText, this.server.bookmark_file)
}
} catch (e) {
if (xmlDocText.includes('<?xml version="1.0" encoding="UTF-8"?>') || xmlDocText.includes('<!DOCTYPE NETSCAPE-Bookmark-file-1>')) {
// not encrypted, yet => noop
Expand Down

0 comments on commit af25b70

Please sign in to comment.