Giter Site home page Giter Site logo

clach04 / puren_tonbo Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 954 KB

Plain text notes Tombo (chi) alternative, also supports, ccrypt, GnuPG (OpenPGP, gpg), OpenSSL AES-256-CBC, AES-256 ZIP AE-1/AE-2 and VimCrypt encrypted files. Integrates with VIM. WIP

Home Page: https://pypi.org/project/puren-tonbo/

License: GNU Lesser General Public License v2.1

Python 95.24% Vim Script 1.51% Lua 3.25%
decryption encryption encryption-decryption vim vimcrypt zip aes aes-256 aes-ctr blowfish

puren_tonbo's Introduction

-- coding: utf-8 --

puren_tonbo

Pure Plain Text Notes... with optional encryption.

https://github.com/clach04/puren_tonbo/

IMPORTANT before using the optionally encryption features, ensure that it is legal in your country to use the specific encryption ciphers. Some countries have also have restrictions on import, export, and usage see http://www.cryptolaw.org/cls-sum.htm

Background

Plain text notes search/edit tool that supports encrypted files, formats:

プレーン トンボ Purēntonbo

平易 蜻蛉

Features

  • Plain text files notes (potentially with no formatting or in Markdown, reStructuredText, etc.)
  • Nested directories of notes
  • Supports reading and writing from/to encrypted files that are compatible with other formats/tools (there is no intention to create a new crypto format/algorithm in this tool)
  • Currently limited to local file system and stdin/out for files
  • Command line tools; ptcat and ptcipher to encrypt/decrypt and view plain text files
    • ptcipher - process raw binary files, controlled via command line and environment variables
    • ptcat - in addition to command line and environment variables, also has an (optional) config file and the concept of a root directory of notes
  • ptgrep - a grep, ack, ripgrep, silver-searcher, pss like tool that works on encrypted (and plain text) files
  • ptig an interactive grep like tool that can also view/edit
  • ptpyvim a vim-like editor that works on encrypted (and plain text) files

Getting Started

sudo apt-get install python-tk
sudo apt-get install ccrypt

Regular install

pip install "puren_tonbo[all]"

Without a source code checkout

Picking up the latest version

pip uninstall puren_tonbo ; python -m pip install --upgrade git+https://github.com/clach04/chi_io.git  git+https://github.com/clach04/puren_tonbo.git

# sanity check, and dump sample config to stdout
ptconfig
python -m puren_tonbo.tools.ptconfig

From a source code checkout

# pip uninstall puren_tonbo
# python -m pip install -r requirements.txt
# TODO requirements_optional.txt
python -m pip install -e .


# sanity check, and dump sample config to stdout
ptconfig
python -m puren_tonbo.tools.ptconfig

Examples

ptconfig
python -m puren_tonbo.tools.ptconfig

ptcat

ptcat  puren_tonbo/tests/data/aesop.txt
ptcat --list-formats
python -m puren_tonbo.tools.ptcat --note-root . puren_tonbo/tests/data/aesop.txt
python -m puren_tonbo.tools.ptcat --note-root . puren_tonbo/tests/data/aesop.chi
python -m puren_tonbo.tools.ptcat  puren_tonbo/tests/data/aesop.txt

ptcat -p password puren_tonbo/tests/data/aesop_linux_7z.aes256.zip
python -m puren_tonbo.tools.ptcat -p password puren_tonbo/tests/data/aesop_linux_7z.aes256.zip

ptgrep

A grep, ack, ripgrep, silver-searcher, pss like tool that works on encrypted (and plain text) files.

Has similar parameters for ease of switching.

Python 2.7 note for Windows. Non-ascii characters can cause Python exception/crashes UnicodeEncodeError when attempting to print Unicode characters, where as Python 3 does not. ptgrep implements a translation feature/hack which can be disabled (or tweaked) via the Operating System environment variable PTGREP_STDOUT_MODE. Valid options are disabled, utf8, and ascii:backslashreplace. For Python 2.7 under Microsoft Windows **only** (when neither PYTHONIOENCODINGnorPYTHONUTF8have been set)ascii:backslashreplaceis the default and works in a similar fashion toPYTHONIOENCODING`.

ptgrep better
ptgrep -i better
python -m puren_tonbo.tools.ptgrep -i better
python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -i better
python -m puren_tonbo.tools.ptgrep -e -p password Better
python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -e -p password Better

Find all instances of "king", case-insensitive (note; matches taking):

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -i king

Find all words "king", case-insensitive:

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -i -r \bking\b

find different words with regex

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data    -r "cruel|better"
python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -i -r "cruel|better"
python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data    -r "cru.l|b.tter"

find filenames with regex

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -y -r ^aesop

find filenames that have an ISO date in either dirname or filename

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -y -r "202[0-9]-[0-9][0-9]-[0-9][0-9]"

find filenames encrypted with regex

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -y -e -r ^aesop

find filenames ONLY encrypted with regex

python -m puren_tonbo.tools.ptgrep --note-root=puren_tonbo/tests/data -y -k -r ^aesop

ptig

Command line interactive search tool, that also supports viewing and editing. Relies on ptgrep, see PTGREP_STDOUT_MODE note.

Also see https://github.com/clach04/puren_tonbo/wiki/tool-ptig

ptig
python -m puren_tonbo.tools.ptig

Sample ptig session

$ ptig --note-root=puren_tonbo/tests/data
3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0]

Puren Tonbo puren_tonbo version 0.0.3.git
Formats:

              txt - RawFile - Raw file, no encryption support
               md - RawFile - Raw file, no encryption support
              chi - TomboBlowfish - Tombo Blowfish ECB (not recommended)
              gpg - GnuPG - gpg (GnuPG) symmetric 1.x and 2.x, does NOT uses keys
              asc - GnuPGascii - gpg (GnuPG) symmetric 1.x and 2.x, does NOT uses keys
              cpt - Ccrypt - ccrypt symmetric Rijndael
          aes.zip - ZipAES - AES-256 ZIP AE-1 DEFLATED (regular compression)
       aes256.zip - ZipAES - AES-256 ZIP AE-1 DEFLATED (regular compression)
           aeszip - ZipAES - AES-256 ZIP AE-1 DEFLATED (regular compression)
          old.zip - ZipAES - AES-256 ZIP AE-1 DEFLATED (regular compression)
openssl_aes256cbc_pbkdf2_10k - OpenSslEnc10k - OpenSSL 1.1.0 pbkdf2 iterations 10000 aes-256-cbc
 aes256stored.zip - ZipNoCompressionAES - AES-256 ZIP AE-1 STORED (uncompressed)
    oldstored.zip - ZipNoCompressionAES - AES-256 ZIP AE-1 STORED (uncompressed)
   aes256lzma.zip - ZipLzmaAES - AES-256 ZIP AE-1 LZMA
  aes256bzip2.zip - ZipBzip2AES - AES-256 ZIP AE-1 BZIP2
         vimcrypt - VimDecrypt - vimcrypt 1, 2, 3
        vimcrypt1 - VimDecrypt - vimcrypt 1, 2, 3
        vimcrypt2 - VimDecrypt - vimcrypt 1, 2, 3
        vimcrypt3 - VimDecrypt - vimcrypt 1, 2, 3

Libs:
        chi_io.implementation: using PyCrypto 3.15.0
        python-gnupg version: 0.5.0
        gpg version: (2, 2, 19)
        pyzipper version: 0.3.6

ptig: 🔎 rg better
Query time: 0.01 seconds
ptig: 🔎 set ic
ptig: 🔎 rg better
[1] puren_tonbo/tests/data/aesop.txt
7:Better no rule than cruel rule.
Query time: 0.01 seconds
ptig: 🔎 find ccrypt
[1] puren_tonbo/tests/data/aesop_win_ccrypt.cpt
Query time: 0.00 seconds
ptig: 🔎 f ccrypt
[1] puren_tonbo/tests/data/aesop_win_ccrypt.cpt
Query time: 0.00 seconds
ptig: 🔎 cat 0
Password for file aesop_win_ccrypt.cpt:
ptig: 🔎 set search_encrypted=True
ptig: 🔎 rg better
[1] puren_tonbo/tests/data/aesop.chi
7:Better no rule than cruel rule.
..... Truncated
[21] puren_tonbo/tests/data/aesop_win_winrar.aes256stored.zip
7:Better no rule than cruel rule.
Query time: 0.32 seconds
ptig: 🔎 help

Documented commands (type help <topic>):
========================================
EOF  c    config  edit  f     g     help  ptpyvim  quit     rg   ver      vi
bye  cat  e       exit  find  grep  info  pyvim    results  set  version  vim

ptig: 🔎 exit
Quitting...

ptig config

Config for ptig is the regular config file pt.json, with additional (optional) ptig section:

{
    "_version_created_with": "0.0.dev3",
    "codec": [
        "utf8",
        "cp1252"
    ],
    "default_encryption_ext": "chi",
    "default_text_ext": "txt",
    "note_root": "C:\\Users\\yourname\\tombo",
    "ptig": {
        "#init": ["set ic", "set enc"],
        "init": ["set ic"],
        "editor": "start scite",
        "editors": {
            "encscite": "C:\\programs\\encscite\\prog\\encscite.bat",
            "pttkview": "pttkview",
            "scite": "scite",
            "gvim": "gvim",
            "vim": "vim"
        },
        "file_browser": "explorer",
        "prompt": "ptig: ? ",
        "use_pager": false
    }
}

NOTE options for editor along with init which is a list of commands to issue on start up. For example, enabling case insensitive search. There is a commented out example which enables encrypted file search.

pttkview

A simple GUI viewer using the tk toolkit:

python -m puren_tonbo.tools.pttkview -h
pttkview -h

ptpyvim

If pyvim is available, ptpyvim wraps encryption/decryption support.

ptpyvim
python -m puren_tonbo.tools.ptpyvim

ptcipher

ptcipher is a tool for dealing with raw (binary, i.e. bytes rather than characters) files for encryption/decryption. All options are controlled via command line flag and operating system environment variables.

Assuming installed:

ptcipher -h

From source code checkout:

python -m puren_tonbo.tools.ptcipher -h
python2 -m puren_tonbo.tools.ptcipher -h
python3 -m puren_tonbo.tools.ptcipher -h

Quick demo:

ptcipher --password password --decrypt puren_tonbo/tests/data/aesop.chi
ptcipher --password password --decrypt puren_tonbo/tests/data/aesop_linux_7z.aes256.zip
python -m puren_tonbo.tools.ptcipher --password password --decrypt puren_tonbo/tests/data/aesop.chi

Tombo Blowfish CHI

Symmetric encryption/decryption from passphase.

Compatible with http://tombo.osdn.jp/En/ (and others, for example, Kumagusu on Android).

ptcipher -e -p test README.md -o README.chi

ptcipher -v -p test README.chi

The chi file can also be read/written by Tombo http://tombo.sourceforge.jp/En/ and clones

ccrypt CPT

Symmetric encryption/decryption from passphase.

Tested with ccrypt 1.11 and 1.10 (32-bit and 64-bit Intel x86/x64 and arm).

Requires a ccrypt binary, download from https://ccrypt.sourceforge.net/ (or debian apt). ccrypt binary/executable needs to be in the path or the environment variable CCRYPT_EXE needs to have the (full) path. NOTE Under Microsoft Windows, is the ccrypt.exe is in a path with spaces, do NOT use double quotes in the SET. Example: set CCRYPT_EXE=C:\3rd party bins\ccrypt.exe

python -m puren_tonbo.tools.ptcipher --password password puren_tonbo/tests/data/aesop_win_ccrypt.cpt
ptcipher --cipher=cpt -e -p test README.md -o README.cpt
python -m puren_tonbo.tools.ptcipher --cipher=cpt -e -p test README.md -o README.cpt

ccrypt -c README.cpt
ccrypt -c -K test README.cpt

OpenPGP - gpg / pgp

Symmetric encryption/decryption from passphase, key support not explictly implemented.

Requires a gpg binary, download from https://gnupg.org/download/

python -m puren_tonbo.tools.ptcipher --cipher=asc -e -p test README.md -o README.asc
python -m puren_tonbo.tools.ptcipher --cipher=gpg -e -p test README.md -o README.gpg

gpg  --pinentry-mode=loopback --decrypt  --passphrase test README.gpg

Also see encryptcli from https://github.com/evpo/EncryptPad/

OpenSSL 1.1.0 AES

OpenSSL 1.1.0+ compatible (with a very small subset of options).

ptcat --note-root=. puren_tonbo/tests/data/aesop_win.openssl_aes256cbc_pbkdf2_10k

Intended to allow decryption of files generated with OpenSSL 1.1.0 and vice-versa. Supported OpenSSL flags/formats:

openssl enc -e aes-256-cbc -salt -pbkdf2 -iter 10000 -in in_file -base64 -out out_file
openssl dec -d aes-256-cbc -salt -pbkdf2 -iter 10000 -in in_file -base64 -out out_file

echo hello| openssl enc -e aes-256-cbc -salt -pbkdf2 -iter 10000 -in - -base64 -out - -pass pass:password
echo hello| openssl enc -e -aes-256-cbc -in - -out - -salt -pbkdf2 -iter 10000  -pass pass:password

NOTE PBKDF2 iteration count of 10,000 is the default in OpenSSL 1.1.1 and is considered too few in 2023. Older versions of OpenSSL did not support; PBKDF2 (and ergo iterations) and salt and used a much weaker KDF.

Supports binary/raw and base64 encoded/ASCII armored files. ONLY supports aes-256-cbc with salt and pbkdf2 KDF with 10,000 interations.

AES-256 zip

Symmetric encryption/decryption from passphase.

ptcipher -e -p test README.md -o README.aes256.zip

ptcipher -p test README.aes256.zip

The aes256.zip file can also be read/written by 7-Zip, WinRAR, WinZIP, etc. that support AES zip files.

For example, 7z can read and write AES zip files:

7z a -tzip -mem=AES256 -ptest README.aes256.zip README.md
7z x -ptest README.aes256.zip

VimCrypt

Symmetric encryption/decryption from passphase.

NOTE not implemented in nvim / neovim.

In vim the easiest way to get the newest encryption mode/format, for a file:

vim -c ":setlocal cm=blowfish2"  test.vimcrypt3

then issue:

:X

will be prompted for password, can then edit/save as per normal.

To see encryption mode:

:setlocal cm?

ptcipher demo:

python -m puren_tonbo.tools.ptcipher -p test test.vimcrypt3

ptcat/ptcipher with text editors like vim

readonly pipe into editor

Quick and easy view/read ONLY of encrypted file with vim, without updating vim config.

NOTE call vim (or neovim) with options to set "private" mode:

  • - to read from stdin instead of a filename, avoid plaintext hitting the disk
  • -n turns off swap file - use memory only
  • -i turns off .viminfo

TODO disable undo file

  1. Use a pipe (cross platform)

       ptcat FILE | vim - -n -i "NONE"
    
  2. Use bash shell process substitution feature for editors that don't support stdin (Linux/Unix only, avoids directly calling mkfifo and cleaning up named pipes)

       scite < (ptcat FILE)
       ptcat FILE | scite /dev/stdin
       scite <(python -m puren_tonbo.tools.ptcat  puren_tonbo/tests/data/aesop.txt)
    

Puren Tonbo will prompt for passwords and the decrypted content should not hit the file system.

Option 1 can be used with other tools that take in stdin, option 2 can be used with any tool that takes in a filename.

Caution!

  • don't save the raw file
  • ensure now backup, swap, undo file, etc.. get created

https://vi.stackexchange.com/questions/6177/the-simplest-way-to-start-vim-in-private-mode

SciTE lua plugin

Tested with versions: v4.0.0, 4.1.5, and 5.3.5

See pt_scite.lua - read and write support (tested Windows). NOTE due to lua popen() any helpful error text/information is missing. Diagnosing failures can be difficult, even for trivial errors like directory/disk does not exist as this is not reported to the lua runtime. Also see SciTE Python plugin for read and write support with stderror support.

By default uses ptcipher in path, override via PTCIPHER_EXE environment variable.

Does NOT prompt for password, requires setting PT_PASSWORD environment variable or use of keyring.

Need to edit SciTEUser.properties:

  • Windows
    • %USERPROFILE%"\SciTEUser.properties or %APPDATA%\scite\SciTEUser.properties
  • Unix
    • ~/.SciTEUser.properties or $HOME/.SciTEUser.properties

Alternatively, launch scite, then open Options, Open User (or GLobal) Options File.

Windows NOTE to avoid a (typically black) CMD/Command window showing up use SciTE 4.4.4 or later and set create.hidden.console in SciTEUser.properties:

# https://groups.google.com/g/scite-interest/c/QOhizNSEejU/m/qXslloxnCgAJ
# SciTE 4.4.4 on Windows adds create.hidden.console option to stop console window flashing when Lua script calls os.execute or io.popen.
create.hidden.console=1
# TODO see if this can be set in lua code, to make config easier

SciTE lua install without extension manager

If not using a plugin extension manager can simply set pt_scite.lua as starting lua script. Edit SciTEUser.properties to set lua script:

...
ext.lua.startup.script=C:\code\py\puren_tonbo\pt_scite.lua
create.hidden.console=1
...

SciTE lua install with an extension manager

If using an extman like system:

...
# This is a simplified ExtMan
# requires each plugin/add-on to be "registered" or declared, white listed, etc.
ext.lua.startup.script=C:\code\scite\extman\parskorata_extman.lua
...

Then edit parskorata_extman.lua to add to end:

mgr:load_files{'pt_scite.lua'}

NOTE not needed with original full ExtMan.

SciTE Python plugin

See scite with Python README - read and write support, Windows only (needs polishing).

By default uses ptcipher in path, override via PTCIPHER_EXE environment variable.

Does NOT prompt for password, requires setting PT_PASSWORD environment variable.

vim plugin

Tested under Linux with vim 8.0 and 8.1. under x86, x64, and arm 32-bit.

See pt.vim - Linux/Unix/Cygwin only for now.

By default uses ptcipher in path, override via PTCIPHER_EXE environment variable.

Will prompt for password, which can be skipped by setting PT_PASSWORD environment variable.

vim demo

Assuming puren_tonbo has been installed and ptcipher is in the path (and in source code checkout):

vim -u pt.vim  puren_tonbo/tests/data/aesop.chi

And enter in the test password, password.

vim plugin install

As per example above, can use the -u parameter but this overrides existing settings.

Vim 8 supports plugins packs, to install:

vim plugin install linux/unix

If you do not already have any plugin packs, need to create directory, e.g.:

mkdir -p ~/.vim/pack/bundle/start/

Where bundle is user decided. For the rest of the documentation replace bundle with your directory name.

Install from checkout:

mkdir -p ~/.vim/pack/bundle/start/puren_tonbo/plugin/
cp pt.vim ~/.vim/pack/bundle/start/puren_tonbo/plugin/

Then can call vim without -u:

vim puren_tonbo/tests/data/aesop.chi
gvim puren_tonbo/tests/data/aesop.chi

vim plugin install Microsoft Windows

NOTE not working under Windows :-( Appear to be buffered files issues with vim/python interaction.

See linux notes, instead of ~/.vim use %USERPROFILE%\vimfiles (or $VIM_INSTALLATION_FOLDER\vimfiles)

mkdir %USERPROFILE%\vimfiles\pack\bundle\start\puren_tonbo\plugin
copy pt.vim %USERPROFILE%\vimfiles\pack\bundle\start\puren_tonbo\plugin

vim config notes

See https://vim.fandom.com/wiki/Encryption for how to configure vim with external tools for (view and edit) of encrypted files with autocmd. NOTE under Windows buffered IO can interfere with vim interactions. TODO consider using (OpenSSL) https://www.vim.org/scripts/script.php?script_id=2012 as a model for vim plugin (uses functions), also see:

Development and testing

Puren Tonbo is implemented in Python, with support for Python 3.x and 2.7.

Run test suite

python -m puren_tonbo.tests.testsuite
python -m puren_tonbo.tests.testsuite -v 2>&1 |grep -i skipped

High Level Overview

All encryption/decryption is file object based. Low level routines (EncryptedFile) use file-like objects, for in-memory encryption/decryption use BytesIO (see test suite, puren_tonbo/tests/testsuite.py).

There is also the note abstraction (FileSystemNotes) which is filename based.

Thanks

Thanks and kudos to:

puren_tonbo's People

Contributors

clach04 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

puren_tonbo's Issues

key file support

  1. PT (like Tombo, VimVry6, and AESZip) use a passphrase only (possibly with key derivation function) for encryption/decryption
  2. Many tools (like Opengpg, age, etc.) Use a key file (typically on disk, but not always) that is protected by a passphrase (typically, but not always) that maybe accessed via an agent or keyring. For:
    a. Symmetric encryption/decryption.
    b. Public/private key pair encryption/decryption.

Many tools transparently will handle 2.b. for decryption.
For 2.a and 2.b (for encryption) what would the work flow/UX be for an end user of PT?

refactor highlight API parameters

Instead of highlight prefix and postfix have two functions:

  1. Process hit
  2. Process non-hit

Would allow things like html escape.

Also use regex start/end character count to separate hits from non-hits.

install issue

readme instructions do work :-)

pip install with out dev mode appears to succeed but tools (and test suite) are missing.

(py3tmpvenv) pi@odroidxu4:~/py3tmpvenv$ ptconfig   
Traceback (most recent call last):
  File "/home/pi/py3tmpvenv/bin/ptconfig", line 11, in <module>
    load_entry_point('puren-tonbo===0.0.3.git', 'console_scripts', 'ptconfig')()
  File "/home/pi/py3tmpvenv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/pi/py3tmpvenv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/home/pi/py3tmpvenv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/home/pi/py3tmpvenv/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'puren_tonbo.tools'
(py3tmpvenv) pi@odroidxu4:~/py3tmpvenv$ python -m puren_tonbo.tools.ptconfig           
/home/pi/py3tmpvenv/bin/python: Error while finding module specification for 'puren_tonbo.tools.ptconfig' (ModuleNotFoundError: No module named 'puren_tonbo.tools')
(py3tmpvenv) pi@odroidxu4:~/py3tmpvenv$ which python
/home/pi/py3tmpvenv/bin/python
(py3tmpvenv) pi@odroidxu4:~/py3tmpvenv$ find /home/pi/py3tmpvenv/ -name puren\*
/home/pi/py3tmpvenv/lib/python3.8/site-packages/puren_tonbo
/home/pi/py3tmpvenv/lib/python3.8/site-packages/puren_tonbo-0.0.3.git.egg-info
(py3tmpvenv) pi@odroidxu4:~/py3tmpvenv$ ls /home/pi/py3tmpvenv/lib/python3.8/site-packages/puren_tonbo
__init__.py  __main__.py  mzipaes.py  __pycache__  _version.py  vimdecrypt.py

NOTE tools directory missing.

presumably setup.py needs to declare more directories (either as code, or as data).

This also means the following is not yet possible:

python3 -m venv py3tmpvenv
. py3tmpvenv/bin/activate
python -m pip install git+https://github.com/clach04/puren_tonbo.git
#python -m pip install 'puren_tonbo @ git+https://github.com/clach04/puren_tonbo.git'

ptgrep tasks/TODO

  1. ✅ bad password on command line should report which filename failure occurred on
  2. remove/fix all FIXME comments
  3. remove/fix all TODO comments
  4. ✅ test regex
  5. find filename (ONLY) search - FIXME
  6. ✅ encrypted ONLY search
  7. ✅ test case-(in)sensitive options
  8. test suite addition?
  9. docs/readme
  10. ✅ Sanity check tree with different passwords
  11. compare performance with tombogrep (password key derivation) - #93
  12. -v, --invert-match select non-matching lines support to match grep
  13. implement -L, --files-without-match print only names of FILEs containing no match as well
  14. context support
  15. Testsuite / unit test additions (and data) for search - also see #106

Any enhancements need to be evaluated for exposure in ptig - #48.

ptweb - web interface

Notes, requirements, and ideas.

Requirements

See PyTombo WebGrep

Web APIs

Client side UI

REST

Themes https://bootswatch.com/

Browser based editors

PyTombo

Old screenshots

webtombo_fts_cruel_suggestion

doc vim integration tips

installation

take a leaf out of https://github.com/itchyny/lightline.vim#vim-packages-since-vim-741528 install notes, install directly using git (with correct directory structure.

https://shapeshed.com/vim-packages/

integration with other tools

disable swap, history, etc.

nobackup, noswapfile, and nowritebackup 

from https://vim.fandom.com/wiki/Encryption

... When using an external program, be certain to turn off options like persistent undo (:help 'undofile'), backup files (:help 'backup'), swap files (:help 'swapfile'), and saving certain information like register contents to the .viminfo file (:help 'viminfo'), to prevent that the entire file or parts of the file are available on your disk unencrypted.

vimrc

https://www.sheep-thrills.net/transparantly_editing_encrypted_secrets_file.html

Using functions in auto groups (rather than directives/commands in the group). See https://www.vim.org/scripts/script.php?script_id=2012 which also handles multiple file extensions.

https://github.com/kurotych/ccryptor.nvim/blob/master/ftdetect/ccryptor.vim has a suggestion/demo for enabling markdown type for encrypted files based on extension.

search

https://github.com/ervandew/ag
Can use search history

problems

  • Microsoft Windows and vim issues with buffered IO.
  • #63

neovim

https://www.google.com/search?q=theprimeagen&ie=utf-8&oe=utf-8&client=firefox-b-1-m

ptcipher --cipher=CIPHER currently unused

Test case:

echo test | ptcipher -e -p test

or

echo test | ptcipher -e -p test --cipher=chi
echo test | ptcipher -e -p test --cipher=aes.zip

cipher flag should override filename lookup.

Error:

Encrypt/Decrypt problem. UnsupportedFile("no support for ''",)

text editor integration

https://www.texteditors.org/cgi-bin/wiki.pl

mixed gui and console / cli

Also see pyvim

console / cli

Also see #34 which was easy to integrate (albeit password IO TBD).

GUI

windows binary support

Build windows binaries removing the need for a local python installation.

pip/pipx installation works cross platform so not a high priority.

age passphrase encryption

Age and rage don't support env variables out of concerns for /proc leakage. Rage binary may be usable with pinentry.

pinentry

idea for note meta data

external meta data files

Similar tool to Tombo, Notepad by Dmitry Nazarov has support for labels and colors for note (icon) via ini files. NOTE Notepad implementation leaks labels for locked (filename extension for encrypted) files.

.notepad.ini

#
#Thu Mar 09 23:37:23 PST 2023
l7=L9
l6=L8
PasswordCreated=2023-03-10_07\:34\:32
l5=L7
l4=L6
l3=L5
l2=L4
l1=L3
l0=L10
b1=
b0=/
l9=Label1
l8=Label 2
EncrypedPassword=?????

Filename.ini

#
#Thu Mar 09 23:37:46 PST 2023
l1=Label1
color=0
l0=L10

https://diman169.ru/
https://play.google.com/store/apps/details?id=ru.diman169.notepad.lite&ref=note-apps files

yaml front matter

  • Cross ref

PurePyZipAES / mZipAES test suite fails TestBaseEncryptedZipNoCompressionPurePyZipAES.test_get_what_you_put_in

Pure Python AES-256 stored encryption creates bad zips that can not be opened. Pure Python AES-256 decryption is fine (as is pyzipper for both encryption and decryption).

python -m puren_tonbo.tests.testsuite -v  TestBaseEncryptedZipNoCompressionPurePyZipAES.test_get_what_you_put_in

results in:

test_get_what_you_put_in (__main__.TestBaseEncryptedZipNoCompressionPurePyZipAES) ...
about to write crc into zip meta 0xa55c1cb0
crc in zip meta 0xa55c1cb0
ERROR

======================================================================
ERROR: test_get_what_you_put_in (__main__.TestBaseEncryptedZipNoCompressionPurePyZipAES)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\code\py\puren_tonbo\puren_tonbo\tests\testsuite.py", line 124, in test_get_what_you_put_in
    self.check_get_what_you_put_in(self.test_data_bytes, self.test_password_bytes, self.pt_handler_class, decrypt_pt_handler_class)
  File "C:\code\py\puren_tonbo\puren_tonbo\tests\testsuite.py", line 79, in check_get_what_you_put_in
    result_data = handler.read_from(fileptr2)
  File "puren_tonbo\__init__.py", line 248, in read_from
    raise PurenTonboException(info)
puren_tonbo.PurenTonboException: BAD CRC-32 (actual) 0x49c1a598 != 0xa55c1cb0 (in zip meta)

----------------------------------------------------------------------
Ran 1 test in 0.009s

FAILED (errors=1)

plug-able encryption

PyTombo and original Tombo do not support alternative encryption systems/file-formats. Also see clach04/tombo#1

Puren Tonbo as of 2023-12-30 supports:

Crypto Support is static, currently there is no plugin/discovery mechanism see a0ad483 for an example of what is involved in adding new format support. See https://github.com/tibonihoo/yapsy

Ideas

The main aim of different encryption/file formats is compatibility to avoid lock-in and promote ease of transportation of data. The list below are existing formats. This project has no intent to create a new format/encryption-algorithm! Wish list, implementations in; Python (3 and 2), Javascript (for browser, ideally web crypto API), C (C++), and Java to allow cross-platform exchanges (e.g. with native Android), see clach04/tombo#1

key derivation functions

Not under consideration at this time

Short List

OpenPGP - gpg / pgp encryption support

  • update test to replace \r for one comparison and also compare regular canon - 3402626 and 6a27467

  • Test signature exploit https://blog.patternsinthevoid.net/pretty-bad-protocolpeople.html

  • implement encrypt ASC

  • implement decrypt ASC

  • implement encrypt gpg

  • implement decrypt gpg

  • manually test encrypt ASC

  • manually test decrypt ASC

  • manually test encrypt gpg

  • manually test decrypt gpg

  • testsuite encrypt ASC

  • testsuite decrypt ASC

  • testsuite encrypt gpg

  • testsuite decrypt gpg

    python -m puren_tonbo.tools.ptcipher --cipher=asc -e -p testpass puren_tonbo\tests\data\aesop.txt -o aesop_pt_win.asc
    python -m puren_tonbo.tools.ptcipher --cipher=gpg -e -p testpass puren_tonbo\tests\data\aesop.txt -o aesop_pt_win.gpg

Use gpg and https://github.com/evpo/EncryptPad to compare support and test.

ccrypt encryption support

ccrypt https://ccrypt.sourceforge.net/ fits in well with Tombo (and Puren Tonbo) approach of symmetric passphrase only (rather than key file).

There as no existing Python wrappers/modules (PyPi lists a package with that name BUT it's in no way related to https://ccrypt.sourceforge.net/).

TODO Build in exe wrapper support (potentially spin out later), rather than C extension/ctypes/cffi/etc.

Pre-built standalone exes are relatively easy to obtain. Under Debian/Ubuntu derivatives:

sudo apt install ccrypt

ptig enhancements

Ideas

  1. ✔️ Prompt (Cmd.prompt); search (🔎), unlocked (🔒), unlocked (🔓), 🔑 - fab8732 a797b42
  2. Improve set and unset password - created #42
  3. --Avoid need for password for text files - not an issue--
  4. Support external viewer and editor - created #43
  5. ✔️ PT_PASSWORD is env support c3ba13c
  6. ✔️Pager / $PAGER / less / more support for cat c48e035 - also see https://github.com/ipython/ipython/blob/57eaa12cb50c9a95213b9e155032e400b9424871/IPython/core/page.py#L57 for a built in option that is terminal size aware
  7. ✔️ ver alias for version 4551e22

add requirements

add enough requirements and setup.py so that ptcipher can be ran.

Requirements can specify git repo (so need for pypi for initial version).

ptpyvim / pyvim copy / paste usability issues

From #46

Under Windows with "version 3.0.3, prompt_toolkit 3.0.38", Paste from Windows/System Clipboard using either keyboard or mouse does not work. Using mouse to paste moves cursor.

Similar for Linux terminals, like lxterminal.

Fix implemented to disable mouse mode support in pyvim a885da9

Under Windows workaround, use the CMD top right menu to mark/copy and paste.

Disabling pyvim mouse support doesn't resolve but does help.

  • Better workaround, issuing set nomouse allows right click menu to come allowing both mark/copy and paste from right click which is faster/more-convenient to CMD menu. Keyboard paste still does not work

Possibly related:

Additional AES-256 zip testing ideas

  1. ✅ DONE #12 add a test to show compatibility between PurePyZipAES and ZipAES/ZipNoCompressionAES
  2. create AES-256 zip with WinZIP
  3. test lzma with real files created outside of Puren Tonbo
  4. test bzip2 with real files created outside of Puren Tonbo
  5. ✅ DONE create AES-256 zip with WinRAR
  6. ✅ DONE create AES-256 zip with 7z
  7. #8 0 issues with PurePyZipAES reading 7zip
  8. look at adding automated test to use external tool 7z, unzip, zip, rar, etc. to decrypt/test files created with:
    • PurePyZipAES
    • ZipNoCompressionPurePyZipAES
    • ZipAES
    • ZipNoCompressionAES

ptig enhancements/ todo

#19

  1. ☑️ in-progress ls - #67 and #36 directory browse
  2. Prompt change when search encrypted enabled #86
  3. ✅ Search only encrypted option for grep - #19 number 6
  4. ✔️ Caching find option, scan directory once and the in memory find for filenames instead of always hitting filesystem. Option to always hit filesystem also needed - #66
  5. ✔️ Add option to search the last result set (both titles and content). E.g. results find TERM, results rg TERM - #65
  6. ✔️ Open directory using native file explorer / browser (e.g. from results) #61
  7. tests #60
  8. ✔️ bookmarks support #68
  9. find -i -r options (reuse grep parser?)
  10. rg/grep -y should include encrypted files by default? (see 3 above -k implemented)
  11. run commands #87 - NOTE cmd2 has this builtin with no code changes required
  12. #107
  13. vim style quit? :q, :q!, :qa

PurePyZipAES / mZipAES returns None for unsupported (zip) files

Two issues:

  1. doesn't work - this is expected, flawed test. Test files where actaually using the old ZipCrypto format :-( 7z does not (as of 2023-02-12) support creating AE-1 nor AE-2 zip files, the only encrypted zip files 7z can create are the old format. It does support reading them, and of course writing 7z AES encrypted files

  2. when it fails get None back from FileSystemNotes - needs investigation, test case:

    python -m puren_tonbo.tests.testsuite -v TestFileSystemNotes.test_aesop_win_7z_old_zip_using_purepyzipaes
    python -m puren_tonbo.tools.ptcipher -d --cipher=aes256.zip -ppassword puren_tonbo\tests\data\aesop_win_7z.old.zip

plug-able filesystem

PyTombo supports:

  • pyfs
  • local - faster than pyfs local file system support

Puren Tonbo should too. Right now PT only supports local.

document known weaknesses

Known weaknesses and considerations.
Keywords; security, problems.

Some info in wiki:

Some info in #4

#25

PT stores unencrypted text in memory. If a memory dump is automatically taken after a system or application crash or some of the memory is saved to a swap file, the sensitive information will be present on the disk. Sometimes it is possible to configure an operating system not to use a dump and swap files.

PT stores unencrypted passwords in memory

vim script/plugin/auto command (as of

if $PT_PASSWORD == ""
) caches password.

Doc command line arg exposure.

Doc or link to each encryption implementation with quick overview and possible weaknesses (some notes in #4):

For shelling out, command with same name as real command at head is path could wrap real binary/script and log passwords and/or plain text.

https://www.reddit.com/r/crypto/comments/100b0ed/how_much_of_a_security_risk_is_it_to_expose_a/

WIP ptwebcp uses/allows GET parameters for password for convenience of debugging and testing. Leaks passwords to browser history.

integrate into pyvim

https://github.com/prompt-toolkit/pyvim

Semi related to #22

  1. ptpyvim; See if can import pyvim and monkey patch file IO, ideally with note tree API (rather than cypher API so as to allow future use of virtual file system).
  2. write a pyvim io backend, https://github.com/prompt-toolkit/pyvim/blob/master/pyvim/io/backends.py (also see 1 above).

Also see alternatives https://github.com/prompt-toolkit/pyvim#alternatives
#35

load from command line seems fine, as does saving.

Prompting for password experiments ONLY work when loading from command line (pre "gui" init?). Get coroutine errors (that are garbled):

    diff --git a/puren_tonbo/tools/ptpyvim.py b/puren_tonbo/tools/ptpyvim.py
    index cc386f0..aed8444 100644
    --- a/puren_tonbo/tools/ptpyvim.py
    +++ b/puren_tonbo/tools/ptpyvim.py
    @@ -21,6 +21,10 @@ from pyvim.io import FileIO, DirectoryIO, HttpIO, GZipFileIO
     from pyvim.io.backends import ENCODINGS, _auto_decode
     from pyvim.io import EditorIO

    +from prompt_toolkit import prompt
    +from prompt_toolkit.shortcuts import input_dialog
    +
    +
     import puren_tonbo


    @@ -87,8 +91,25 @@ class PureTonboFileIO(EditorIO):
             Read/decrypt file from disk.
             """
             #import web_pdb; web_pdb.set_trace()  # https://github.com/romanvm/python-web-pdb
    -        if not password:
    -            raise puren_tonbo.BadPassword('Missing password, set OS env PT_PASSWORD')
    +        global password
    +        while not password:
    +            #password = prompt('Enter password: ', is_password=True)
    +            password = input_dialog(
    +                title="Password dialog example",
    +                text="Please type your password:",
    +                password=True,
    +            ).run()
    +            #raise puren_tonbo.BadPassword('Missing password, set OS env PT_PASSWORD')
    +            """ this code works fine from command line, but :edit ... causes....
    +
    +
    +            `:e filename.chi` (or any file supported by PT) fails with:
    +
    +                ...\site-packages\pyvim\editor_buffer.py:112: RuntimeWarning: coroutine 'Application.run_async' was never awaited
    +                Cannot read 'test.chi': RuntimeError('This event loop is already running')
    +                Rtest.cha   ng: Enable tracemal    to get the object allocation traceback
    +
    +            """

Tools needed

This project has a lot of lofty goals. Some of which include re-implementing PyTombo for Python 3.x and 2.7 (without the need for legacy support).

Tools live in https://github.com/clach04/puren_tonbo/tree/main/puren_tonbo/tools

Ideally tools will support:

  • plug-able file system support - #3
  • plug-able encryption and file/format container system support - #4

pure python aes zip fails with 7z file TestFileSystemNotes.test_aesop_win_7z_aes256_zip_using_purepyzipaes

also all the 7z aes tests fail in Pyton 2.7.

python -m puren_tonbo.tests.testsuite -v  TestFileSystemNotes.test_aesop_win_7z_aes256_zip_using_purepyzipaes

======================================================================
ERROR: test_aesop_win_7z_aes256_zip_using_purepyzipaes (__main__.TestFileSystemNotes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\code\py\puren_tonbo\puren_tonbo\__init__.py", line 243, in read_from
    zf = mzipaes.MiniZipAE1Reader(file_object, self.key)
  File "C:\code\py\puren_tonbo\puren_tonbo\mzipaes.py", line 679, in __init__
    p.parse()
  File "C:\code\py\puren_tonbo\puren_tonbo\mzipaes.py", line 730, in parse
    raise UnsupportedFile("UNKNOWN AE PROTOCOL %r" % ((xh, ver, vendor),))
puren_tonbo.mzipaes.UnsupportedFile: UNKNOWN AE PROTOCOL (39169, 2, 17729)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\code\py\puren_tonbo\puren_tonbo\tests\testsuite.py", line 372, in test_aesop_win_7z_aes256_zip_using_purepyzipaes
    data = note_root.note_contents(test_note_filename, password, handler_class=puren_tonbo.PurePyZipAES)  # force usage of PurePyZipAES, for when pyzipper is available and the default
  File "C:\code\py\puren_tonbo\puren_tonbo\__init__.py", line 655, in note_contents
    plain_str = handler.read_from(in_file)
  File "C:\code\py\puren_tonbo\puren_tonbo\__init__.py", line 248, in read_from
    raise UnsupportedFile(info)
puren_tonbo.UnsupportedFile: UNKNOWN AE PROTOCOL (39169, 2, 17729)

----------------------------------------------------------------------
Ran 1 test in 0.004s

FAILED (errors=1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.