Skip to content

Commit

Permalink
use cryptography instead of pycryptodome, since it feels more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Oct 14, 2024
1 parent 63257cc commit ea8e42e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ jobs:
./dist/jimmy-cli* test/data/test_data/obsidian/test_1 --format obsidian --include-notes-with-tags "*"
./dist/jimmy-cli* test/data/test_data/obsidian/test_1 --format obsidian --include-notes "Second sample note" "Sample note"
./dist/jimmy-cli* test/data/test_data/bear/test_1/backup.bear2bk --format bear
./dist/jimmy-cli* test/data/test_data/colornote/test_1/colornote-20241014.backup --format colornote --password 1234
2 changes: 1 addition & 1 deletion docs/formats/colornote.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ This page describes how to convert notes from ColorNote to Markdown.

1. Export as described [at the website](https://www.colornote.com/faq-question/what-is-device-backup/)
2. [Install jimmy](../index.md#installation)
3. Convert to Markdown. Example: `jimmy-cli-linux colornote-20241013.backup --format colornote`
3. Convert to Markdown. Example: `jimmy-cli-linux colornote-20241013.backup --format colornote --password 1234`
4. [Import to your app](../import_instructions.md)
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
beautifulsoup4==4.12.3
cryptography==43.0.1
enlighten==1.12.4
markdown==3.7
platformdirs==4.3.3
puremagic==1.27
pycryptodomex==3.21.0
pypandoc==1.13
pyparsing==3.1.2
python-frontmatter==1.1.0
Expand Down
14 changes: 10 additions & 4 deletions src/formats/colornote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pathlib import Path
import struct

from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import unpad
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding

import common
import converter
Expand All @@ -21,8 +21,14 @@ def decrypt(salt: bytes, password: bytes, ciphertext: bytes) -> bytes:
# https://github.com/olejorgenb/ColorNote-backup-decryptor/blob/61e105d6f13b2cd22b5141b6334bb098617665e1/src/ColorNoteBackupDecrypt.java
key = hashlib.md5(password + salt).digest()
iv = hashlib.md5(key + password + salt).digest()
decoder = AES.new(key, AES.MODE_CBC, iv)
return unpad(decoder.decrypt(ciphertext), 16)

cipher = Cipher(algorithms.AES128(key), modes.CBC(iv))
decryptor = cipher.decryptor()
plaintext_padded = decryptor.update(ciphertext) + decryptor.finalize()

unpadder = padding.PKCS7(cipher.algorithm.block_size).unpadder()
plaintext = unpadder.update(plaintext_padded) + unpadder.finalize()
return plaintext


class Converter(converter.BaseConverter):
Expand Down

0 comments on commit ea8e42e

Please sign in to comment.