You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by gs...@apache.org on 2022/05/31 00:24:23 UTC
[steve] branch trunk updated (c0a5fca -> 06f92bb)
This is an automated email from the ASF dual-hosted git repository.
gstein pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
from c0a5fca fix is_tampered() after some prior changes
new 36a0671 ensure cursors complete, to release locks
new 1cddc58 token inputs are human strings
new ec8a034 Fernet output is bytes. fix schema.
new 06f92bb implement recording of votes
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
v3/schema.sql | 2 +-
v3/steve/crypto.py | 4 ++--
v3/steve/db.py | 17 ++++++++++-------
v3/steve/election.py | 19 +++++++++++++++++++
4 files changed, 32 insertions(+), 10 deletions(-)
[steve] 02/04: token inputs are human strings
Posted by gs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
commit 1cddc581d837616f7728d67a6b872cb1759c3030
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon May 30 19:22:07 2022 -0500
token inputs are human strings
---
v3/steve/crypto.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/v3/steve/crypto.py b/v3/steve/crypto.py
index 7a07e69..6974937 100644
--- a/v3/steve/crypto.py
+++ b/v3/steve/crypto.py
@@ -40,9 +40,9 @@ def gen_opened_key(edata: bytes, salt: bytes) -> bytes:
return _hash(edata, salt)
-def gen_token(opened_key: bytes, value: bytes, salt: bytes) -> bytes:
+def gen_token(opened_key: bytes, value: str, salt: bytes) -> bytes:
"Generate a voter or issue token."
- return _hash(opened_key + value, salt)
+ return _hash(opened_key + value.encode(), salt)
### fix return type, to be a tuple
[steve] 01/04: ensure cursors complete, to release locks
Posted by gs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
commit 36a0671399f9b89180e19c68c98c17d09290e3c2
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon May 30 19:21:25 2022 -0500
ensure cursors complete, to release locks
---
v3/steve/db.py | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/v3/steve/db.py b/v3/steve/db.py
index 884dc93..3df4359 100644
--- a/v3/steve/db.py
+++ b/v3/steve/db.py
@@ -46,9 +46,6 @@ class DB:
self.conn = sqlite3.connect(fname, isolation_level=None)
self.conn.row_factory = row_factory
- # For fetching column names.
- self.name_cursor = self.conn.cursor()
-
# CURSOR : FACTORY
self.factories = { }
@@ -63,9 +60,13 @@ class DB:
assert query[:9].lower() == 'select * '
# Get all column names for TABLE.
- self.name_cursor.execute(f'select * from {table} limit 1')
- names = [ info[0] for info in self.name_cursor.description ]
- self.name_cursor.close() # we don't need the results
+ cur = self.conn.execute(f'select * from {table} limit 1')
+ names = [ info[0] for info in cur.description ]
+
+ # We don't need the results, but cannot leave the cursor hanging,
+ # as it establishes a lock on this table. This likely closes as
+ # this method exits, but let's not rely upon that.
+ cur.close()
# Create a factory for turning rows into namedtuples.
factory = collections.namedtuple(f'row_factory_{len(self.factories)}',
@@ -102,4 +103,6 @@ class NamedTupleCursor(sqlite3.Cursor):
def first_row(self, params=()):
"Helper method to fetch the first row of a query."
self.perform(params)
- return self.fetchone()
+ row = self.fetchone()
+ _ = self.fetchall() # run the cursor to completion; should be empty
+ return row
[steve] 03/04: Fernet output is bytes. fix schema.
Posted by gs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
commit ec8a0340a26576f94f12a6c14094773d688aed88
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon May 30 19:22:42 2022 -0500
Fernet output is bytes. fix schema.
---
v3/schema.sql | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/v3/schema.sql b/v3/schema.sql
index a77a152..dc3cef7 100644
--- a/v3/schema.sql
+++ b/v3/schema.sql
@@ -142,7 +142,7 @@ CREATE TABLE VOTES (
salt BLOB NOT NULL,
/* An encrypted form of the vote. */
- token TEXT NOT NULL
+ token BLOB NOT NULL
) STRICT;
[steve] 04/04: implement recording of votes
Posted by gs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
commit 06f92bbc752aee89dcded290c41c8c49827e0d74
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Mon May 30 19:23:34 2022 -0500
implement recording of votes
---
v3/steve/election.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/v3/steve/election.py b/v3/steve/election.py
index e8ef73e..2cc5b93 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -59,6 +59,8 @@ class Election:
'DELETE FROM ISSUES WHERE iid = ?')
self.c_delete_record = self.db.add_statement(
'DELETE FROM RECORD WHERE rid = ?')
+ self.c_add_vote = self.db.add_statement(
+ 'INSERT INTO VOTES VALUES (NULL, ?, ?, ?, ?)')
# Cursors for running queries.
self.q_metadata = self.db.add_query('metadata',
@@ -189,6 +191,23 @@ class Election:
self.c_delete_record.perform((rid,))
+ def add_vote(self, rid, iid, votestring):
+ "Add VOTESTRING as the (latest) vote by RID for IID."
+
+ md = self.q_metadata.first_row()
+ record = self.q_get_record.first_row((rid,))
+ issue = self.q_get_issue.first_row((iid,))
+
+ voter_token = crypto.gen_token(md.opened_key, rid, record.salt)
+ #print('VOTER:', rid, record.salt, voter_token)
+ issue_token = crypto.gen_token(md.opened_key, iid, issue.salt)
+ #print('ISSUE:', iid, issue.salt, issue_token)
+
+ salt, token = crypto.create_vote(voter_token, issue_token, votestring)
+ #print('SALT:', salt)
+ #print('TOKEN:', token)
+ self.c_add_vote.perform((voter_token, issue_token, salt, token))
+
def is_tampered(self):
# The Election should be open.