Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Deploy Documentation

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout cryptnoxpro repository
uses: actions/checkout@v4
with:
path: cryptnoxpro

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: |
cd cryptnoxpro
pip install sphinx sphinx-rtd-theme

- name: Build Sphinx documentation
run: |
cd cryptnoxpro
sphinx-build -b html docs docs/_build/html

- name: Checkout documentation repository
uses: actions/checkout@v4
with:
repository: cryptnox-software/cryptnox-software.github.io
token: ${{ secrets.DOCS_DEPLOY_TOKEN }}
path: docs-repo

- name: Update documentation
run: |
# Remove old cryptnoxpro folder if it exists
rm -rf docs-repo/cryptnoxpro

# Copy new documentation
cp -r cryptnoxpro/docs/_build/html docs-repo/cryptnoxpro

# Add a timestamp file for tracking
echo "Last updated: $(date)" > docs-repo/cryptnoxpro/last-updated.txt

- name: Commit and push changes
run: |
cd docs-repo
git config --local user.email "yannw.dev@gmail.com"
git config --local user.name "YanNaingWinDev"
git add .
git commit -m "Update cryptnoxpro documentation from cryptnoxpro@${{ github.sha }}" || exit 0
git push
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ venv
signature.sig
cardpub.pub

_build
_static
_templates
docs/_build/

cryptnoxpro.egg-info
17 changes: 10 additions & 7 deletions cryptnoxpro/command/card/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@
from tabulate import tabulate

from ..cards import Cards
from ..helper.cards import CardManager
from ..helper.security import (
check,
is_easy_mode
)

try:
import enums
from config import get_configuration
from wallet import eth
from wallet.btc import BTCwallet, BlkHubApi
except ImportError:
from ... import enums
from ...config import get_configuration
from ...wallet import eth
from ...wallet.btc import BTCwallet, BlkHubApi
except ImportError:
import enums
from config import get_configuration
from wallet import eth
from wallet.btc import BTCwallet, BlkHubApi

__all__ = ['Cards']


class Info:
def __init__(self, data: Namespace, cards: Cards = None):
def __init__(self, data: Namespace, cards: CardManager = None):
self.data = data
self._cards = cards or Cards(self.data.verbose if "verbose" in self.data else False)
self._cards = cards or CardManager(self.data.verbose if "verbose" in self.data else False)
self.serial_number = None

@staticmethod
Expand Down
7 changes: 5 additions & 2 deletions cryptnoxpro/command/card/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

from ..cards import Cards
from ..helper import ui, security
from ..helper.cards import CardManager

__all__ = ['Cards']


class Initialize:
def __init__(self, data: Namespace, cards: Cards = None):
def __init__(self, data: Namespace, cards: CardManager = None):
self.data = data
self._cards = cards or Cards(self.data.verbose if "verbose" in self.data else False)
self._cards = cards or CardManager(self.data.verbose if "verbose" in self.data else False)
self.serial_number = None

def execute(self, card) -> int:
Expand Down
7 changes: 4 additions & 3 deletions cryptnoxpro/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ui, security
)
from .helper.cards import (
Cards,
CardManager,
ExitException,
TimeoutException,
)
Expand All @@ -30,16 +30,17 @@ class Command(metaclass=abc.ABCMeta):
:param Namespace data: Command line arguments
"""

def __init__(self, data: Namespace, cards: Cards = None):
def __init__(self, data: Namespace, cards: CardManager = None):
self.data = data
self._cards = cards or Cards(self.data.verbose if "verbose" in self.data else False)
self._cards = cards or CardManager(self.data.verbose if "verbose" in self.data else False)
self.serial_number = None

def execute(self, serial_number: int = None) -> int:
"""
Main execution method of the command.

Finds card and establishes connection to it. Executes _execute method.

:param serial_number: Serial number of the wanted card
:return: 0 if the command executed without issues. Other number
indicating and issue
Expand Down
13 changes: 8 additions & 5 deletions cryptnoxpro/command/erc_token/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
from web3 import Web3

from ..cards import Cards
from ..helper.cards import CardManager

__all__ = ['Cards']

try:
import enums
from wallet import eth
except ImportError:
from ... import enums
from ...wallet import eth
except ImportError:
import enums
from wallet import eth

_SEED_SOURCE_TRANSLATION = {
cryptnoxpy.SeedSource.NO_SEED: "No seed",
Expand All @@ -47,9 +50,9 @@ class Info:
"""
_name = enums.Command.INFO.value

def __init__(self, data: Namespace, cards: Cards = None):
def __init__(self, data: Namespace, cards: CardManager = None):
self.data = data
self._cards = cards or Cards(self.data.verbose if "verbose" in self.data else False)
self._cards = cards or CardManager(self.data.verbose if "verbose" in self.data else False)
self.serial_number = None

def execute(self, card: cryptnoxpy.Card) -> int:
Expand Down
6 changes: 3 additions & 3 deletions cryptnoxpro/command/erc_token/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import requests

from ..helper import ui
from ..helper.cards import ExitException, Cards
from ..helper.cards import ExitException, CardManager

try:
from wallet import eth
Expand All @@ -25,9 +25,9 @@


class Initialize:
def __init__(self, data: Namespace, cards: Cards = None):
def __init__(self, data: Namespace, cards: CardManager = None):
self.data = data
self._cards = cards or Cards(self.data.verbose if "verbose" in self.data else False)
self._cards = cards or CardManager(self.data.verbose if "verbose" in self.data else False)
self.serial_number = None

def execute(self, card: cryptnoxpy.Card) -> int:
Expand Down
4 changes: 2 additions & 2 deletions cryptnoxpro/command/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from argparse import Namespace

from .command import Command
from .helper.cards import Cards
from .helper.cards import CardManager
from .unknown import Unknown


def command(data: Namespace, cards: Cards = None) -> Command:
def command(data: Namespace, cards: CardManager = None) -> Command:
"""
Gives back the command that took responsibility for executing the
command
Expand Down
13 changes: 8 additions & 5 deletions cryptnoxpro/command/helper/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
except ImportError:
import config

# Global connection cache to preserve connections across Cards instances
# Global connection cache to preserve connections across CardManager instances
_GLOBAL_CONNECTIONS: Dict[int, cryptnoxpy.Connection] = {}


Expand All @@ -42,7 +42,7 @@ class TimeoutException(Exception):
"""


class Cards:
class CardManager:
def __init__(self, debug: bool = False):
self._cards: Dict[int, cryptnoxpy.Card] = {}
self._cards_by_index: Dict[int, cryptnoxpy.Card] = {}
Expand Down Expand Up @@ -70,7 +70,7 @@ def __getitem__(self, key: int) -> cryptnoxpy.Card:
card = self._cards_by_index[key]
index = key

if index in _GLOBAL_CONNECTIONS:
if index in _GLOBAL_CONNECTIONS and card.alive:
return card

if card.alive:
Expand Down Expand Up @@ -150,7 +150,7 @@ def print_card_list(self, show_warnings: bool = False,
info["applet_version"],
info["name"] + ((" <" + info["email"] + ">") if info["email"]
else ""),
", ".join(Cards.printable_flags(card))
", ".join(CardManager.printable_flags(card))
]

uninitialized |= not info["initialized"]
Expand Down Expand Up @@ -194,8 +194,11 @@ def _open_card(self, index: int, remote: bool = False) -> cryptnoxpy.Card:
if test_response:
if index in self._cards_by_index:
return self._cards_by_index[index]
except BaseException:
except (BaseException, cryptnoxpy.exceptions.ConnectionException):
# Connection is stale, remove it and create new one
del _GLOBAL_CONNECTIONS[index]
if index in self._cards_by_index:
self._remove_card(self._cards_by_index[index].serial_number)

# Create new connection only if needed
connection = cryptnoxpy.Connection(index, self.debug, config.REMOTE_CONNECTIONS, remote)
Expand Down
30 changes: 26 additions & 4 deletions cryptnoxpro/command/helper/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,32 @@

import cryptnoxpy

from . import ui
from .. import user_keys


class ExitException(Exception):
"""Raised when user has indicated he want's to exit the command"""


def _secret_with_exit(text, required=True):
"""
Local implementation of secret_with_exit to avoid circular import.
Replicates the functionality of ui.secret_with_exit.
"""
from stdiomask import getpass

while True:
value = getpass(text).strip()
if value.lower() == "exit":
raise ExitException
if required and not value:
print("This entry is required")
else:
break

return value


class Unauthorized(Exception):
"""
None of the authorization methods has validated the user.
Expand Down Expand Up @@ -173,7 +195,7 @@ def get_puk_code(card: cryptnoxpy.Card, text: str = "", allowed_values: List = N
:param Card card: Card for use to check PUK code validity
:param str text: Text displayed to user for value input.
:param List allowed_values: Values other than 15 digits long strings
that can be accepted.
that can be accepted.
:return: Entered puk code.
:rtype: str
"""
Expand All @@ -186,7 +208,7 @@ def _get_code(
text: str = "",
allowed_values: List = None) -> str:
allowed_values = allowed_values or []
code = ui.secret_with_exit(text, required=("" not in allowed_values))
code = _secret_with_exit(text, required=("" not in allowed_values))

if not {code, ""}.isdisjoint(allowed_values):
return code
Expand All @@ -196,7 +218,7 @@ def _get_code(
validation_method(code)
except cryptnoxpy.exceptions.DataValidationException as error:
print(error, "\n")
code = ui.secret_with_exit(text, required=("" not in allowed_values))
code = _secret_with_exit(text, required=("" not in allowed_values))

if code in allowed_values:
break
Expand Down
7 changes: 4 additions & 3 deletions cryptnoxpro/command/helper/seed_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ def create_data_key(session, cmk_id, key_spec="AES_256"):
"""Generate a data key to use when encrypting and decrypting data

:param cmk_id: KMS CMK ID or ARN under which to generate and encrypt the
data key.
data key.
:param key_spec: Length of the data encryption key. Supported values:
'AES_128': Generate a 128-bit symmetric key
'AES_256': Generate a 256-bit symmetric key
:return Tuple(EncryptedDataKey, PlaintextDataKey) where:
:return: Tuple(EncryptedDataKey, PlaintextDataKey) where:
EncryptedDataKey: Encrypted CiphertextBlob data key as binary string
PlaintextDataKey: Plaintext base64-encoded data key as binary string
:return Tuple(None, None) if error"""
:return: Tuple(None, None) if error
"""
# Create data key
kms_client = session.client("kms")

Expand Down
1 change: 1 addition & 0 deletions cryptnoxpro/command/unknown.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def execute(self, serial_number: int = None) -> int:
Main execution method of the command.

Finds card and establishes connection to it. Executes _execute method.

:param serial_number: Serial number of the wanted card
:return: 0 if the command executed without issues. Other number
indicating and issue
Expand Down
2 changes: 1 addition & 1 deletion cryptnoxpro/command/user_keys/piv/piv_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def is_locked(self, pin_bank: int) -> bool:

:param int pin_bank: The PIN bank to check
:return: Whether the PIV is locked for pin_bank
:rtype; bool
:rtype: bool
"""
try:
self.verify_pin(pin_bank, "")
Expand Down
6 changes: 3 additions & 3 deletions cryptnoxpro/interactive_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from command.options import options
from command.helper import security
from command.helper.cards import (
Cards,
CardManager,
ExitException,
TimeoutException
)
Expand All @@ -27,7 +27,7 @@
from .command.options import options
from .command.helper import security
from .command.helper.cards import (
Cards,
CardManager,
ExitException,
TimeoutException
)
Expand Down Expand Up @@ -223,7 +223,7 @@ def __init__(self, version: str, debug: bool = False, port: int = None):

self._reconnect = False
self._card_info = None
self._cards = Cards()
self._cards = CardManager()

self.subcommand = []
self.parser = None
Expand Down
Binary file modified dev-requirements.txt
Binary file not shown.
Loading