Skip to content

Commit

Permalink
connect pynitrokey
Browse files Browse the repository at this point in the history
  • Loading branch information
jj-so committed May 16, 2024
1 parent cb5c2a8 commit 02eaa90
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
55 changes: 54 additions & 1 deletion nitrokeyapp/settings_tab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from random import randbytes
from typing import Callable, Optional

from pynitrokey.fido2 import find
from fido2.ctap2.pin import ClientPin, PinProtocol
from pynitrokey.nk3.secrets_app import SecretsApp

from PySide6.QtCore import Qt, QThread, QTimer, Signal, Slot
from PySide6.QtGui import QGuiApplication
from PySide6.QtWidgets import QLineEdit, QListWidgetItem, QWidget, QTreeWidgetItem
Expand Down Expand Up @@ -183,6 +187,11 @@ def show_pin(self, item) -> None:
self.ui.pin_description.setText(desc)
self.ui.pin_description.setReadOnly(True)

if pintype == SettingsTabState.Fido:
self.fido_status()
elif pintype == SettingsTabState.otp:
self.otp_status()


def edit_pin(self, item) -> None:
self.ui.settings_empty.hide()
Expand All @@ -207,13 +216,57 @@ def edit_pin(self, item) -> None:

self.field_btn()

def fido_status(self) -> None:
ctaphid_raw_dev = self.data._device.device
fido2_client = find(raw_device=ctaphid_raw_dev)
self.ui.status_label.setText("pin ja" if fido2_client.has_pin() else "pin nein")

def otp_status(self) -> None:
secrets = SecretsApp(self.data._device)
status = secrets.select()
status_txt = str(status)
self.ui.status_label.setText(status_txt)

def abort(self, item) -> None:
p_item = item.parent()
self.show(p_item)



# def reset(self) -> None:

# def save(self) -> None:
def save_pin(self, item) -> None:
pintype = item.data(1, 0)
if pintype == SettingsTabState.FidoPw:
print(pintype)
ctaphid_raw_dev = self.data._device.device
fido2_client = find(raw_device=ctaphid_raw_dev)
client = fido2_client.client
# assert isinstance(fido2_client.ctap2, Ctap2)
client_pin = ClientPin(fido2_client.ctap2)
old_pin = self.ui.current_password.text()
new_pin = self.ui.repeat_password.text()
print(old_pin)
print(new_pin)

client_pin.change_pin(old_pin, new_pin)
else:
secrets = SecretsApp(self.data._device)
print(secrets)
old_pin = self.ui.current_password.text()
new_pin = self.ui.repeat_password.text()
print(type(old_pin))
print(type(new_pin))
print(old_pin)
print(new_pin)
secrets.change_pin_raw(old_pin, new_pin)
print(old_pin)
print(new_pin)




# or pintype == SettingsTabState.otp:


def act_current_password_show(self) -> None:
Expand Down
3 changes: 3 additions & 0 deletions nitrokeyapp/ui/settings_tab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>&lt;empty&gt;</string>
</property>
Expand Down

0 comments on commit 02eaa90

Please sign in to comment.