Commit Graph

429 Commits

Author SHA1 Message Date
Michael Weghorn
22edc2a228 Port from PyCrypto to PyCroptodome
As the PyCrypto website says [1]:

> PyCrypto 2.x is unmaintained, obsolete, and contains security
> vulnerabilities.

Therefore, switch to PyCryptodome, a maintained PyCrypto fork
which is listed there as the recommended alternative for
existing software that depends on PyCrypto.

Notes on the port:

1) As the PyCryptodome introduction documentation [2] says,
there are 2 alternative projects/namespaces that can be
used:

* pycryptodome, which uses the `Crypto` package
  that PyCrypto also uses, so is almost a drop-in
  replacement for Pycrypto

* pycryptodomex, which uses the `Cryptodome` package

It also mentions that the use of pycryptodome
"is therefore recommended only when you are
sure that the whole application is deployed in a virtualenv".

Since it isn't sure that the application is deployed in a
virtualenv, to make it more explicit that PyCryptodome
is being used and because Linux distros like Debian
package the `Cryptodome` package [3], the port is done to
the `pycryptodomex` library that uses the `Cryptodome`
package name.

2) As the "Compatibility with PyCrypto" page in the PyCryptodome
doc [4] says:

> The following packages, modules and functions have been removed:
>
> * Crypto.Random.OSRNG, Crypto.Util.winrandom and Crypto.Random.randpool.
>   You should use Crypto.Random only.

The `PublicKey.RSA.generate` method already uses
`Crypto.Random.get_random_bytes()` as default [5],
so just drop the second parameter using `RandomPool.getBytes`
in `virtualsmartcard/src/vpicc/virtualsmartcard/cards/cryptoflex.py`.

[1] https://www.pycrypto.org/
[2] https://www.pycryptodome.org/src/introduction
[3] https://packages.debian.org/bullseye/python3-pycryptodome
[4] https://pycryptodome.readthedocs.io/en/latest/src/vs_pycrypto.html
[5] https://pycryptodome.readthedocs.io/en/latest/src/public_key/rsa.html
2022-09-17 22:15:39 +02:00
Michael Weghorn
141509cce3 Drop unused PyCrypto imports 2022-09-17 21:32:56 +02:00
Michael Weghorn
468e01d164 Correct hmac import from Python stdlib
Commit 82c0c4fdd2
("Fallback to hashlib instead of deprecated libs")
had changed the hmac import to try the import from
the hashlib module, but there appears to be 'hmac'
underneath hashlib in neither Python 2 nor Python 3, but
it's a separate module.

Test on Debian testing with Python 2.7.18:

    $ python2
    Python 2.7.18 (default, Aug  1 2022, 06:23:55)
    [GCC 12.1.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    Jedi is not installed, falling back to readline
    >>> from hashlib import hmac as HMAC
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name hmac
    >>> import hmac as HMAC
    >>>

The same with Python 3.10.6:

    $ python3
    Python 3.10.6 (main, Aug 10 2022, 11:19:32) [GCC 12.1.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    Using Jedi for tab completion.
    >>> from hashlib import hmac as HMAC
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: cannot import name 'hmac' from 'hashlib' (/usr/lib/python3.10/hashlib.py)
    >>> import hmac as HMAC
    >>>

Even the official Python 3.10.6 documentation for the hashlib
module use plain hmac import [1] in its example:

    >>> import hmac, hashlib
    >>> m = hmac.new(b'secret key', digestmod=hashlib.blake2s)
    >>> m.update(b'message')
    >>> m.hexdigest()
    'e3c8102868d28b5ff85fc35dda07329970d1a01e273c37481326fe0c861c8142'

Therefore, revert that change to the import and use the direct hmac
import again to make the case where PyCrypto is not installed work
again.

[1] https://docs.python.org/3/library/hashlib.html

Fixes: #223
2022-08-29 22:42:18 +02:00
Michael Weghorn
c6f8011ade Drop unused SHA1 import
It is unused since commit 36970a26d7
("Replace PBKDF2 class by python stdlib implementation").

Fixes #218
2022-07-23 13:50:12 +02:00
bowb
76543ea32b Change socket fd checks against INVALID_SOCKET. Fix issue with allowing reconnects from client to a server. 2022-06-07 13:42:25 -06:00
Frank Morgner
51fb023c3b vicc: use Quad9 instead of Goolge for detecting IP 2022-06-01 10:28:33 +02:00
Frank Morgner
68ca1fb49d vpcd: add support for SCARD_ATTR_ATR_STRING
fixes https://github.com/frankmorgner/vsmartcard/issues/201
2022-06-01 10:27:56 +02:00
Frank Morgner
b57b383a1d vicc: move detailed description to APDU class for generic use 2022-05-09 22:26:58 +02:00
Frank Morgner
471abe6950 vicc: fixed error printing 2022-05-06 14:06:18 +02:00
Frank Morgner
4b872bb000 vicc: debug parsed APDU
closes https://github.com/frankmorgner/vsmartcard/pull/103/
2022-05-06 12:24:03 +02:00
Frank Morgner
fe5977bc39 vicc: use logging.critical if vicc needs exit() 2022-05-06 11:57:23 +02:00
Frank Morgner
1e5731fb0e vicc: debug incoming commands as well 2022-05-06 11:53:05 +02:00
Frank Morgner
a982efd8c5 ePass: Python 3 compatibility 2022-02-02 16:36:27 +01:00
Frank Morgner
98bd7a0c8e virtualsmartcard: fixed more python3 compatibility 2022-02-01 14:21:48 +01:00
Frank Morgner
be6d6e2f73 virtualsmartcard: added missing include
fixes https://github.com/frankmorgner/vsmartcard/issues/138
2022-01-28 00:06:56 +01:00
Frank Morgner
af028aa8c3 virtualsmartcard: fixed some python3 compatibility
fixes https://github.com/frankmorgner/vsmartcard/issues/200
2022-01-27 22:46:12 +01:00
Guinness
82c0c4fdd2 Fallback to hashlib instead of deprecated libs 2022-01-21 14:38:30 +01:00
Frank Morgner
9284766532 Don't use ASN.1 data as ASN.1 tuple for encoding
fixes https://github.com/frankmorgner/vsmartcard/issues/209
2021-11-02 14:14:24 +01:00
Jakub Jelen
e8be94964b vpcd: Initialize variable also on Windows
This should fix the appveyor build failure:

C:\projects\vsmartcard\virtualsmartcard\src\vpcd\vpcd.c(183): error C4700: uninitialized local variable 'rfds' used [C:\projects\vsmartcard\virtualsmartcard\win32\BixVReader\BixVReader.vcxproj]
2021-08-26 10:15:39 +02:00
Jakub Jelen
8d34ee42c7 vpcd: Fix timeout calculation
Authored by Doug Engert <deengert@gmail.com>
2021-08-23 15:31:05 +02:00
Jakub Jelen
f611240fba vpcd: Initialize variables
This caused OpenSC CI failing as described in

https://github.com/OpenSC/OpenSC/issues/2390

Authored by Doug Engert <deengert@gmail.com>
2021-08-23 15:29:36 +02:00
Bowb
cebe05e78d Update vpcd.c
FIXES #193
2021-08-09 14:47:38 -06:00
Frank Morgner
4658f86108 fixed syntax error in python 2.7 2021-04-28 17:56:06 +02:00
Frank Morgner
a053f1aecd let distcheck pass 2021-04-28 16:00:15 +02:00
Ludovic Rousseau
3324167331 Fix handler_test URL 2021-04-17 18:48:21 +02:00
Frank Morgner
82e68a6339 Merge pull request #181 from betawave/relay-mitm-enhancement
basic Man-in-the-Middle extension to the Relay-Card
2020-10-27 11:06:05 +01:00
Leonard Hübner
71e0f2e8fc basic Man-in-the-Middle extension to the Relay-Card 2020-10-26 17:01:28 +01:00
Leonard Hübner
97194d230d enable msg to be either string or bytes 2020-10-26 16:36:31 +01:00
fabio rodrigues
919c13c907 [vpicc] Python 3 linting
Some additional code linting
- remove unused imports
- remove unecessary parenthesis from if statements
- created TLVutils TAG dictionary in creation time
2020-08-18 15:19:23 +01:00
fabio rodrigues
475fad371a [vpicc] Python 3 updates and code fixing
- Use pycryptodome instead of pycrypto
- Fixed some unit tests asserts
- fixed some instances that sending message to vpcd the msg is considered a string object instead of byte array
- make TLVutils.pack work in python 3
2020-08-18 13:12:13 +01:00
David Ward
c18df66d4c Fix "make dist" without "make all"
Fix prerequisites and Automake variables in the Makefiles, so that
running "make dist" does not fail if the program is not built. When
running help2man, have it execute "gengetopt --show-help" instead
of the built program to obtain the help message.
2020-04-11 10:09:27 -04:00
David Ward
5abc01cf70 Respect Automake silent mode in custom rules 2020-04-11 10:09:27 -04:00
Frank Morgner
c63cc40c34 fixed misuse of realloc
if called with size 0, realloc frees the buffer, which may eventually
lead to a double free corruption.
2019-01-17 15:04:35 +01:00
Frank Morgner
3209ef2261 nPA: fixed Python 2/3 incompatibilities 2019-01-15 14:33:54 +01:00
Rob
d40b203774 Fix cast of APDU res to byte array (aka string) 2018-10-26 13:00:32 +02:00
Frank Morgner
5082ab09d4 vicc: temporarily drop python3 compatibility for relay
fixes https://github.com/frankmorgner/vsmartcard/issues/129
2018-10-20 04:05:44 +02:00
Frank Morgner
04642a3bfc fixed more Python 3 issues
also fixes the debug output
2018-05-03 22:55:10 +02:00
Frank Morgner
3b7c04c535 added more Python 3 compatibility
fixes https://github.com/frankmorgner/vsmartcard/issues/71
2018-05-03 16:30:08 +02:00
Frank Morgner
ae0d04f8b7 added some Python 3 compatibility 2018-05-02 16:21:44 +02:00
Dániel SÜTTŐ
a9482d9f99 Use at least two bytes for filesize in FCP template (#116)
* Fix length of filesize parameter in FCP template

'Number of data bytes in the file' parameters should be represented on
two bytes in FCP.

* Extendable length of filesize parameter in FCP

Increase length of filesize parameter in FCP template if can't be
represented on two bytes.
2018-01-10 23:07:08 +01:00
Dániel SÜTTŐ
b0783bd373 Fix selection by DF name (#118)
DF names shall be globally uniqe within a given card. Selecting by DF
name should be made on card level instead of current DF level.

A new list has been inroduced as a static attribute of MF in order to
track each named DF.

* Prevent prettyprint from infinite recursion

By adding a possible self-pointer to MF prettyprint_anything function
got into an infinite loop. Printing of named DFs has been cut off.
2018-01-10 23:01:56 +01:00
Daniel SUTTO
0f4e79db17 Fix SFID parameter in FCP template
In FCP SFID tag bits 8 to 4 encode the short EF identifier.
2018-01-08 13:03:32 +01:00
Daniel SUTTO
666294b313 Fix missing raise statement before SwError 2018-01-08 12:29:44 +01:00
Frank Morgner
377774fd65 vicc: catch ctrl-c via KeyboardInterrupt
... and ignore EINT in recv as it may be triggered for various other reasons

fixes https://github.com/frankmorgner/vsmartcard/issues/95
2017-04-05 12:20:20 +02:00
Nick Russler
de515d80d2 Add MSI installer for win32 virtualsmartcard.
Also ignore temporary VS artifacts and removes conflicting snprintf definition with standard definition
2016-11-12 00:16:36 +01:00
Frank Morgner
eb4c8a8103 fixed distcheck 2016-10-10 10:33:09 +02:00
Frank Morgner
fd8ae7c7c8 Merge pull request #78 from d0/no_serialization
Remove serialization support
2016-05-15 17:32:03 +02:00
Frank Morgner
0d1977fc1a print QR code in case of reversed mode 2016-04-15 11:11:15 -04:00
Dominik
41bd7ab105 Remove serialization support 2016-04-10 19:31:24 +02:00
Dominik
de683869b4 Refactored the python files in the cards directory according to PEP8 2016-03-19 10:04:16 +01:00