refactor; rename classes and methods

This commit is contained in:
2025-03-10 09:26:55 -05:00
parent c1ca01eb93
commit 571268b86a
15 changed files with 160 additions and 160 deletions

View File

@@ -2,7 +2,7 @@ from jinja2 import Environment, FileSystemLoader
import os
from src.nkode_api import NKodeAPI
from src.models import NKodePolicy, KeypadSize, EncipheredNKode
from src.user_cipher_keys import UserCipherKeys
from src.user_cipher_keys import UserCipher
from src.utils import list_to_matrix, matrix_transpose, xor_lists
from secrets import choice
from string import ascii_lowercase
@@ -58,16 +58,16 @@ if __name__ == "__main__":
)
keypad_size = KeypadSize(
numb_of_keys=5,
attrs_per_key=6 # aka number of sets
props_per_key=6 # aka number of sets
)
customer_id = api.create_new_customer(keypad_size, policy)
customer = api.customers[customer_id]
set_vals = customer.attributes.set_vals
attr_vals = customer.attributes.attr_vals
customer_attr_view = list_to_matrix(attr_vals, keypad_size.attrs_per_key)
set_vals = customer.customer_cipher.set_key
attr_vals = customer.customer_cipher.prop_key
customer_attr_view = list_to_matrix(attr_vals, keypad_size.props_per_key)
attr_keypad_view = list_to_matrix(attr_vals, keypad_size.attrs_per_key)
attr_keypad_view = list_to_matrix(attr_vals, keypad_size.props_per_key)
attr_set_view = matrix_transpose(attr_keypad_view)
set_attribute_dict = dict(zip(set_vals, attr_set_view))
@@ -78,7 +78,7 @@ if __name__ == "__main__":
passcode_len = 4
user_passcode = signup_interface[:passcode_len]
selected_keys_set = select_keys_with_passcode_values(user_passcode, signup_interface, keypad_size.numb_of_keys)
server_side_attr = [customer.attributes.attr_vals[idx] for idx in user_passcode]
server_side_attr = [customer.customer_cipher.prop_key[idx] for idx in user_passcode]
confirm_interface = api.set_nkode(username, customer_id, selected_keys_set, session_id)
@@ -88,20 +88,20 @@ if __name__ == "__main__":
success = api.confirm_nkode(username, customer_id, selected_keys_confirm, session_id)
assert success
passcode_server_attr = [customer.attributes.attr_vals[idx] for idx in user_passcode]
passcode_server_set = [customer.attributes.get_attr_set_val(attr) for attr in passcode_server_attr]
passcode_server_attr = [customer.customer_cipher.prop_key[idx] for idx in user_passcode]
passcode_server_set = [customer.customer_cipher.get_prop_set_val(attr) for attr in passcode_server_attr]
user_keys = customer.users[username].user_keys
padded_passcode_server_set = user_keys.pad_user_mask(passcode_server_set, customer.attributes.set_vals)
padded_passcode_server_set = user_keys.pad_user_mask(passcode_server_set, customer.customer_cipher.set_key)
set_idx = [customer.attributes.get_set_index(set_val) for set_val in padded_passcode_server_set]
set_idx = [customer.customer_cipher.get_set_index(set_val) for set_val in padded_passcode_server_set]
mask_set_keys = [user_keys.set_key[idx] for idx in set_idx]
ciphered_mask = xor_lists(mask_set_keys, padded_passcode_server_set)
ciphered_mask = xor_lists(ciphered_mask, user_keys.mask_key)
mask = user_keys.encode_base64_str(ciphered_mask)
ciphered_customer_attrs = xor_lists(customer.attributes.attr_vals, user_keys.alpha_key)
ciphered_customer_attrs = xor_lists(customer.customer_cipher.prop_key, user_keys.alpha_key)
passcode_ciphered_attrs = [ciphered_customer_attrs[idx] for idx in user_passcode]
pad_len = customer.nkode_policy.max_nkode_len - passcode_len
@@ -122,8 +122,8 @@ if __name__ == "__main__":
USER LOGIN
"""
login_interface = api.get_login_interface(username, customer_id)
login_keypad = list_to_matrix(login_interface, keypad_size.attrs_per_key)
selected_keys_login = select_keys_with_passcode_values(user_passcode, login_interface, keypad_size.attrs_per_key)
login_keypad = list_to_matrix(login_interface, keypad_size.props_per_key)
selected_keys_login = select_keys_with_passcode_values(user_passcode, login_interface, keypad_size.props_per_key)
success = api.login(customer_id, username, selected_keys_login)
assert success
@@ -133,7 +133,7 @@ if __name__ == "__main__":
"""
user = customer.users[username]
set_vals = customer.attributes.set_vals
set_vals = customer.customer_cipher.set_key
user_keys = user.user_keys
user_mask = user.enciphered_passcode.mask
decoded_mask = user_keys.decode_base64_str(user_mask)
@@ -148,7 +148,7 @@ if __name__ == "__main__":
GET PRESUMED ATTRIBUTES
"""
set_vals_idx = [customer.attributes.get_set_index(set_val) for set_val in login_passcode_sets]
set_vals_idx = [customer.customer_cipher.get_set_index(set_val) for set_val in login_passcode_sets]
presumed_selected_attributes_idx = []
for idx in range(passcode_len):
@@ -161,12 +161,12 @@ if __name__ == "__main__":
RENEW KEYS
"""
old_attrs = customer.attributes.attr_vals.copy()
old_sets = customer.attributes.set_vals.copy()
customer.attributes.renew()
new_attrs = customer.attributes.attr_vals
new_sets = customer.attributes.set_vals
customer_new_attr_view = list_to_matrix(new_attrs, keypad_size.attrs_per_key)
old_attrs = customer.customer_cipher.prop_key.copy()
old_sets = customer.customer_cipher.set_key.copy()
customer.customer_cipher.renew()
new_attrs = customer.customer_cipher.prop_key
new_sets = customer.customer_cipher.set_key
customer_new_attr_view = list_to_matrix(new_attrs, keypad_size.props_per_key)
"""
RENEW USER
@@ -181,12 +181,12 @@ if __name__ == "__main__":
"""
REFRESH USER KEYS
"""
user.user_keys = UserCipherKeys.create(
customer.attributes.keypad_size,
customer.attributes.set_vals,
user.user_keys = UserCipher.create(
customer.customer_cipher.keypad_size,
customer.customer_cipher.set_key,
user.user_keys.max_nkode_len
)
user.enciphered_passcode = user.user_keys.encipher_nkode(presumed_selected_attributes_idx, customer.attributes)
user.enciphered_passcode = user.user_keys.encipher_nkode(presumed_selected_attributes_idx, customer.customer_cipher)
user.renew = False
# Define some data to pass to the template