235 lines
7.6 KiB
Plaintext
235 lines
7.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import sys\n",
|
|
"import os\n",
|
|
"sys.path.append(os.path.abspath('..')) # Adds the parent directory to path\n",
|
|
"from src.nkode_api import NKodeAPI\n",
|
|
"from src.models import NKodePolicy, KeypadSize\n",
|
|
"from src.utils import select_keys_with_passcode_values\n",
|
|
"from secrets import choice\n",
|
|
"from string import ascii_lowercase\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"def random_username() -> str:\n",
|
|
" return \"test_username\" + \"\".join([choice(ascii_lowercase) for _ in range(6)])\n"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:34.809483Z",
|
|
"start_time": "2025-03-27T19:17:34.735988Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"execution_count": 1
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Initialize nKode API and Create Customer\n",
|
|
"#### nKode Customer\n",
|
|
"An nKode customer is business has employees (users). An nKode API can service many customers each with their own users.\n",
|
|
"Each customer specifies a keypad size and a nkode policy.\n",
|
|
"The keypad can't be dispersable (`numb_of_keys < properties_per_key`)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"api = NKodeAPI()\n",
|
|
"policy = NKodePolicy(\n",
|
|
" max_nkode_len=10,\n",
|
|
" min_nkode_len=4,\n",
|
|
" distinct_positions=0,\n",
|
|
" distinct_properties=4,\n",
|
|
")\n",
|
|
"keypad_size = KeypadSize(\n",
|
|
" numb_of_keys = 5,\n",
|
|
" props_per_key = 6\n",
|
|
")\n",
|
|
"customer_id = api.create_new_customer(keypad_size, policy)\n",
|
|
"customer = api.get_customer(customer_id)"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:34.878585Z",
|
|
"start_time": "2025-03-27T19:17:34.817604Z"
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"execution_count": 2
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## nKode Enrollment\n",
|
|
"Users enroll in three steps:\n",
|
|
"1. Create Signup Session\n",
|
|
"2. Set nKode\n",
|
|
"3. Confirm nKode\n",
|
|
"\n",
|
|
"#### Create Signup Session\n",
|
|
"A user, associate with customer (or business), specifies a username and receives a signup_session_id and set_keypad. The keypad is a index array. It tells the client how to sort the user's icons."
|
|
]
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:34.918050Z",
|
|
"start_time": "2025-03-27T19:17:34.914192Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"username = random_username()\n",
|
|
"signup_session_id, set_keypad = api.generate_signup_keypad(customer_id, username)"
|
|
],
|
|
"outputs": [],
|
|
"execution_count": 3
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"### Set nKode\n",
|
|
"The client receives `user_icons`, `set_signup_keypad`\n"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:34.928470Z",
|
|
"start_time": "2025-03-27T19:17:34.926257Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"passcode_len = 4\n",
|
|
"passcode_property_indices = np.random.choice(set_keypad.reshape(-1), size=passcode_len, replace=False).tolist()\n",
|
|
"selected_keys_set = select_keys_with_passcode_values(passcode_property_indices, set_keypad, keypad_size.numb_of_keys)"
|
|
],
|
|
"outputs": [],
|
|
"execution_count": 4
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"### Confirm nKode\n",
|
|
"The user enter then submits their key entry. The server returns the confirm_keypad, another index array and dispersion of the set_keypad."
|
|
]
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:35.223175Z",
|
|
"start_time": "2025-03-27T19:17:34.978825Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"confirm_keypad = api.set_nkode(username, customer_id, selected_keys_set, signup_session_id)\n",
|
|
"selected_keys_confirm = select_keys_with_passcode_values(passcode_property_indices, confirm_keypad, keypad_size.numb_of_keys)\n",
|
|
"success = api.confirm_nkode(username, customer_id, selected_keys_confirm, signup_session_id)\n",
|
|
"assert success"
|
|
],
|
|
"outputs": [
|
|
{
|
|
"ename": "TypeError",
|
|
"evalue": "NKodeAPI.set_nkode() takes 4 positional arguments but 5 were given",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[0;32mIn[5], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m confirm_keypad \u001B[38;5;241m=\u001B[39m \u001B[43mapi\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mset_nkode\u001B[49m\u001B[43m(\u001B[49m\u001B[43musername\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcustomer_id\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mselected_keys_set\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43msignup_session_id\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 2\u001B[0m selected_keys_confirm \u001B[38;5;241m=\u001B[39m select_keys_with_passcode_values(passcode_property_indices, confirm_keypad, keypad_size\u001B[38;5;241m.\u001B[39mnumb_of_keys)\n\u001B[1;32m 3\u001B[0m success \u001B[38;5;241m=\u001B[39m api\u001B[38;5;241m.\u001B[39mconfirm_nkode(username, customer_id, selected_keys_confirm, signup_session_id)\n",
|
|
"\u001B[0;31mTypeError\u001B[0m: NKodeAPI.set_nkode() takes 4 positional arguments but 5 were given"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 5
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"### User Login\n",
|
|
"1. Get login keypad\n",
|
|
"2. Select keys with passcode icons (in our case, passcode property indices)\n"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:35.258024Z",
|
|
"start_time": "2025-03-24T20:25:00.973454Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"login_keypad = api.get_login_keypad(username, customer_id)\n",
|
|
"selected_keys_login = select_keys_with_passcode_values(passcode_property_indices, login_keypad, keypad_size.props_per_key)\n",
|
|
"success = api.login(customer_id, username, selected_keys_login)\n",
|
|
"assert success"
|
|
],
|
|
"outputs": [],
|
|
"execution_count": 13
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Renew Properties\n",
|
|
"Replace server-side ciphers keys and nkode hash with new values.\n",
|
|
"1. Renew Customer Properties\n",
|
|
"2. Renew User Keys\n",
|
|
"3. Refresh User on Login"
|
|
]
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-27T19:17:35.259102Z",
|
|
"start_time": "2025-03-24T20:25:01.209950Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"api.renew_keys(customer_id) # Steps 1 and 2\n",
|
|
"login_keypad = api.get_login_keypad(username, customer_id)\n",
|
|
"selected_keys_login = select_keys_with_passcode_values(passcode_property_indices, login_keypad, keypad_size.props_per_key)\n",
|
|
"success = api.login(customer_id, username, selected_keys_login) # Step 3\n",
|
|
"assert success"
|
|
],
|
|
"outputs": [],
|
|
"execution_count": 14
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|