-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ID store in a file #81
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
16bdbb4
Initial implementation of idstore file where keys can be stored durin…
26672a5
Cleanup memoryview and other handles after decryption, avoids mmap cl…
94b657b
Disable Bandit warning on import subprocess, which is useless because…
8cb1399
Add a contextmanager for printing and clearing console messages.
7981e40
ID store implemented for covert dec, plenty of cleanup. Use xdg confi…
69fd584
Use tty.status for cleaner code.
8ec1cf7
idfilename is now a variable, not a function
d6c6e1a
Do not use user HOME dir for tests.
0de0b8c
Fix config dir name
eb2c396
Make signature block encryption use X25519 keys, avoiding any depende…
abfe0d4
Fix tests for the changed signatures.
11ad5bb
Allow using local IDs as peers. Display unlocking key/id on covert dec.
fdf098c
Hack to show ID names on signatures.
0a80d67
Updated signature messages
3c7bdb5
Refactor path and configdir handling to covert.path.
8b49f51
covert id subcommand implemented.
91a55dd
Fix changed signature message in tests.
64ac296
Use XDG datadir instead of config dir for idstore.
bbc67d5
Draft implementation of Signal Double Ratchet for PFS. Not functional…
c9c2237
Ratchet working in principle.
ba93ede
Merge branch 'main' into idstore
a80d8cd
Fixes and additional tests to ratchet code.
b0416dc
100 % coverage on ratchet.
2c5dd4a
Some tests for idstore management commands.
1e2056c
ID store enc/dec tests.
9154e0d
Double Ratchet with public key handshakes to forward secrecy. Operati…
96adedb
Change variable name.
11a49c7
Update specs with general ratchet operation.
c6246d1
Setting of keys and fixes to covert id subcommand.
d10c5fe
Ratchet info on id command.
cf66baf
Fix a typo in ratchet store. Print current conversation id in CLI dec…
ae4d519
Ratchet end-to-end tests.
c8fc51e
Increased test coverage, minor fixes.
b66ac66
Remove example idstore structure from source.
55f4d02
Addn test
4ead68c
Rewritten CLI help handling and ID store help.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
import mmap | ||
from collections import deque | ||
from concurrent.futures import ThreadPoolExecutor | ||
from contextlib import suppress | ||
from contextlib import contextmanager, suppress | ||
from hashlib import sha512 | ||
from secrets import token_bytes | ||
|
||
from nacl.exceptions import CryptoError | ||
|
||
from covert import chacha, pubkey | ||
from covert import chacha, pubkey, ratchet | ||
from covert.cryptoheader import Header, encrypt_header | ||
from covert.elliptic import xed_sign, xed_verify | ||
from covert.util import noncegen | ||
|
@@ -17,14 +17,16 @@ | |
|
||
def decrypt_file(auth, f, archive): | ||
b = BlockStream() | ||
b.decrypt_init(f) | ||
if not b.header.key: | ||
for a in auth: | ||
with suppress(CryptoError): | ||
b.authenticate(a) | ||
break | ||
yield from b.decrypt_blocks() | ||
b.verify_signatures(archive) | ||
with b.decrypt_init(f): | ||
if not b.header.key: | ||
for a in auth: | ||
with suppress(CryptoError): | ||
b.authenticate(a) | ||
break | ||
# In case auth is a generator, close it immediately (otherwise would be delayed) | ||
if hasattr(auth, "close"): auth.close() | ||
yield from b.decrypt_blocks() | ||
b.verify_signatures(archive) | ||
|
||
class BlockStream: | ||
def __init__(self): | ||
|
@@ -33,17 +35,23 @@ def __init__(self): | |
self.workers = 8 | ||
self.executor = ThreadPoolExecutor(max_workers=self.workers) | ||
self.blkhash = None | ||
self.file = None | ||
self.ciphertext = None | ||
self.q = collections.deque() | ||
self.pos = 0 # Current position within self.ciphertext; queued for decryption, not decoded | ||
self.end = 0 | ||
|
||
|
||
def authenticate(self, anykey): | ||
"""Attempt decryption using secret key or password hash""" | ||
if isinstance(anykey, pubkey.Key): | ||
if isinstance(anykey, ratchet.Ratchet): | ||
self.header.try_ratchet(anykey) | ||
elif isinstance(anykey, pubkey.Key): | ||
self.header.try_key(anykey) | ||
else: | ||
self.header.try_pass(anykey) | ||
|
||
@contextmanager | ||
def decrypt_init(self, f): | ||
self.pos = 0 | ||
if hasattr(f, "__len__"): | ||
|
@@ -58,6 +66,14 @@ def decrypt_init(self, f): | |
self.end = 0 | ||
size = self._read(1024) | ||
self.header = Header(self.ciphertext[:size]) | ||
try: | ||
yield | ||
finally: | ||
self.ciphertext.release() | ||
self.ciphertext = None | ||
self.file = None | ||
self.pos = self.end = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is more clear to zero these variables on separate lines. |
||
|
||
|
||
def _add_to_queue(self, p, extlen, aad=None): | ||
pos, end = p, p + extlen | ||
|
@@ -140,7 +156,7 @@ def verify_signatures(self, a): | |
a.signatures = [] | ||
# Signature verification | ||
if a.index.get('s'): | ||
signatures = [pubkey.Key(edpk=k) for k in a.index['s']] | ||
signatures = [pubkey.Key(pk=k) for k in a.index['s']] | ||
for key in signatures: | ||
sz = self._read(self.end - self.pos + 80) | ||
if sz < 80: | ||
|
@@ -156,7 +172,7 @@ def verify_signatures(self, a): | |
continue | ||
try: | ||
xed_verify(key.pk, self.blkhash, signature) | ||
a.signatures.append((True, key, 'Signature verified')) | ||
a.signatures.append((True, key, 'Signed by')) | ||
except CryptoError: | ||
a.signatures.append((False, key, 'Forged signature')) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, decrypt.py:DecryptView class should call decrypt_init() inside a with statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no decrypt.py or DecryptView class, and decrypt_init() is called within two
with
statements in blockstream.py and cli.py. Also, this does not seem relevant to this PR.