Remove unused imports and fix a small lint issue

This commit is contained in:
Roman Zeyde
2023-04-25 17:29:54 +03:00
parent 58bbb24fb4
commit 97416308ed
3 changed files with 30 additions and 43 deletions

View File

@@ -9,21 +9,17 @@ See these links for more details:
import argparse import argparse
import base64 import base64
import contextlib
import datetime
import io import io
import logging import logging
import os import os
import sys import sys
import traceback
import bech32 import bech32
import pkg_resources import pkg_resources
import semver
from cryptography.exceptions import InvalidTag from cryptography.exceptions import InvalidTag
from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305 from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
from .. import device, server, util from .. import device, util
from . import client from . import client
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@@ -159,35 +159,35 @@ class OnlyKey(interface.Device):
else: else:
vk = ecdsa.VerifyingKey.from_string(ok_pubkey, curve=ecdsa.SECP256k1) vk = ecdsa.VerifyingKey.from_string(ok_pubkey, curve=ecdsa.SECP256k1)
return vk return vk
else:
ok_pubkey = []
while time.time() < t_end:
try:
ok_pub_part = self.ok.read_bytes(timeout_ms=100)
if len(ok_pub_part) == 64 and len(set(ok_pub_part[0:63])) != 1:
log.info('received part= %s', repr(ok_pub_part))
ok_pubkey += ok_pub_part
# Todo know RSA type to know how many packets
except Exception as e:
raise interface.DeviceError(e)
log.info('received= %s', repr(ok_pubkey)) ok_pubkey = []
if len(ok_pubkey) == 256: while time.time() < t_end:
# https://security.stackexchange.com/questions/42268/how-do-i-get-the-rsa-bit-length-with-the-pubkey-and-openssl try:
ok_pubkey = b'\x00\x00\x00\x07' + b'\x73\x73\x68\x2d\x72\x73\x61' + \ ok_pub_part = self.ok.read_bytes(timeout_ms=100)
b'\x00\x00\x00\x03' + b'\x01\x00\x01' + \ if len(ok_pub_part) == 64 and len(set(ok_pub_part[0:63])) != 1:
b'\x00\x00\x01\x01' + b'\x00' + bytes(ok_pubkey) log.info('received part= %s', repr(ok_pub_part))
# ok_pubkey = b'\x00\x00\x00\x07' + b'\x72\x73\x61\x2d\x73\x68\x61\x32\x2d\x32\x35\x ok_pubkey += ok_pub_part
# 36' + b'\x00\x00\x00\x03' + b'\x01\x00\x01' + b'\x00\x00\x01\x01' + b'\x00' + byte # Todo know RSA type to know how many packets
# s(ok_pubkey) except Exception as e:
elif len(ok_pubkey) == 512: raise interface.DeviceError(e)
ok_pubkey = b'\x00\x00\x00\x07' + b'\x73\x73\x68\x2d\x72\x73\x61' + \
b'\x00\x00\x00\x03' + b'\x01\x00\x01' + \ log.info('received= %s', repr(ok_pubkey))
b'\x00\x00\x02\x01' + b'\x00' + bytes(ok_pubkey) if len(ok_pubkey) == 256:
else: # https://security.stackexchange.com/questions/42268/how-do-i-get-the-rsa-bit-length-with-the-pubkey-and-openssl
raise interface.DeviceError("Error response length is not a valid public key") ok_pubkey = b'\x00\x00\x00\x07' + b'\x73\x73\x68\x2d\x72\x73\x61' + \
log.info('pubkey len = %s', len(ok_pubkey)) b'\x00\x00\x00\x03' + b'\x01\x00\x01' + \
return ok_pubkey b'\x00\x00\x01\x01' + b'\x00' + bytes(ok_pubkey)
# ok_pubkey = b'\x00\x00\x00\x07' + b'\x72\x73\x61\x2d\x73\x68\x61\x32\x2d\x32\x35\x
# 36' + b'\x00\x00\x00\x03' + b'\x01\x00\x01' + b'\x00\x00\x01\x01' + b'\x00' + byte
# s(ok_pubkey)
elif len(ok_pubkey) == 512:
ok_pubkey = b'\x00\x00\x00\x07' + b'\x73\x73\x68\x2d\x72\x73\x61' + \
b'\x00\x00\x00\x03' + b'\x01\x00\x01' + \
b'\x00\x00\x02\x01' + b'\x00' + bytes(ok_pubkey)
else:
raise interface.DeviceError("Error response length is not a valid public key")
log.info('pubkey len = %s', len(ok_pubkey))
return ok_pubkey
def sign(self, identity, blob): def sign(self, identity, blob):
"""Sign given blob and return the signature (as bytes).""" """Sign given blob and return the signature (as bytes)."""

View File

@@ -2,21 +2,12 @@
import argparse import argparse
import binascii import binascii
import contextlib
import functools
import hashlib import hashlib
import logging import logging
import os
import re
import struct
import subprocess
import sys import sys
import time import time
import pkg_resources from .. import util
import semver
from .. import formats, server, util
from ..device import interface, ui from ..device import interface, ui
log = logging.getLogger(__name__) log = logging.getLogger(__name__)