Commit Graph

239 Commits

Author SHA1 Message Date
Peter Marschall 16c889cf7d spelling fixes
Fix various spelling errors, mostly in comments but also in texts displayed.

Errors found & interactively fixed using 'codespell', with additional manual
checks after the fixes.
2020-08-30 10:35:14 +02:00
Peter Marschall 4dbfc77eba opensc-explorer: extend do_asn1() to accept offsets
Have do_asn1() accept an optional parameter indicating an offset.
If this is given then start ASN.1-decoding the file/record at this offset.
2020-08-23 22:46:26 +02:00
Peter Marschall 45e7039940 opensc-explorer: extend do_asn1() to decode records
Have do_asn1() accept an optional parameter indicating a record number.
If this is given and the file is a record-oriented file, then ASN.1-decode
the record requested.
2020-08-23 22:46:26 +02:00
Peter Marschall d345c65a5d opensc-explorer: extend do_cat()
Have do_cat() accept an optional second parameter indicating a record number.
If this is given and the file is a record-oriented file, only print the record
requested.
2020-08-23 22:46:26 +02:00
René Liebscher 4d96fbfed4 Remove compiler warnings/errors
Recent compilers have activated some additional
checks which let the build fail. (at least with cygwin)
(Normally it would be warnings but opensc compiles
with -Werror)

GCC 9.3:
In file included from profile.c:27:
profile.c: In function '__expr_get':
profile.c:2273:18: error: array subscript has type 'char' [-Werror=char-subscripts]
 2273 |   while (isspace(*s))
      |                  ^~

clang 8.0.1:
compat_getopt_main.c:102:22: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts]
                rc = toupper(rc);
                     ^~~~~~~~~~~
/usr/include/ctype.h:161:25: note: expanded from macro 'toupper'
      (void) __CTYPE_PTR[__x]; (toupper) (__x);})
                        ^~~~

Actually the code is correct as isspace and others
are used here with data type char, and are to be used
with data type int.

So either the compiler should have deactivated
this error, or the ctype.h macros have to be
written so the compiler no longer complains.

As there is also a simple workaround by casting
char to unsigned char, there is no need to wait for one
of the former options to be happen sometime.
2020-06-22 10:47:02 +02:00
Peter Marschall ca5f5c8844 explorer: set stdout to O_BINARY in Windows where needed 2020-06-05 14:48:08 +02:00
Peter Marschall 5714dbfa08 opensc-explorer: add function 'get_record' 2020-06-05 14:48:08 +02:00
Peter Marschall f55c4e5c93 opensc-explorer: extend path_to_filename()
Expect a record number as 3rd parameter:
if this record number is greater than 0, indicating a single record,
then append the record number to the file name being constructed.
2020-06-05 14:48:08 +02:00
Frank Morgner 7840804762 fixed typo
fixes coverity's: "Argument cannot be negative (NEGATIVE_RETURNS)"
2020-03-21 16:47:43 +01:00
Peter Marschall 44c22b7820 opensc-explorer: re-factor do_put()
* replace magic magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_DATA_SIZE
* start error message with upper-case letter
2020-03-04 21:59:38 +01:00
Peter Marschall b2f86b3997 opensc-explorer: re-factor read_and_print_record_file()
* replace magic magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_RESP_SIZE
* start error message with upper-case letter
* return 0 on success
2020-03-04 21:59:38 +01:00
Peter Marschall 9b0983e96d opensc-explorer: re-factor do_random()
* use braces after sizeof, i.e. sizeof(X) instead of sizeof X
2020-03-04 21:59:38 +01:00
Peter Marschall b9d4f0c7d8 opensc-explorer: re-factor & fix do_update_record()
* bug fix: pass correct buffer length to sc_update_record()
* bug fix: report correct number of bytes written
* bug fix: check for offs to be small enough
* replace magic magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_DATA_SIZE
* remove print() statement that looks suspiciously like a leftover from debugging
* start error messages with upper-case letters
* use sc_strerror(r) instead of plain numeric r in error messages
* fix spaces before opening curly braces
2020-03-04 21:59:38 +01:00
Peter Marschall be152f78b4 opensc-explorer: re-factor do_update_binary()
* replace magic magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_DATA_SIZE
* remove print() statement that looks suspiciously like a leftover from debugging
* start error messages with upper-case letters
* use sc_strerror(r) instead of plain numeric r in error message
* fix spaces before opening curly braces
2020-03-04 21:59:38 +01:00
Peter Marschall c2a8102615 opensc-explorer: re-factor do_get()
* replace magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_RESP_SIZE
* start error messages with upper-case letters
2020-03-04 21:59:38 +01:00
Peter Marschall b77e0faadb opensc-explorer: re-factor do_ls()
* replace magic magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_RESP_SIZE
* replace magic number for filename by SC_MAX_PATH_STRING_SIZE
* start error messages with upper-case letters
* use braces after sizeof, i.e. sizeof(X) instead of sizeof X
* fix indentation
2020-03-04 21:59:38 +01:00
Peter Marschall f1d46401cb opensc-explorer: re-factor do_put_data()
* determine DO ID/tag the same way as do_find_tags()
* start error message with upper-case letter
* use sc_strerror(r) instead of plain numeric r in error message
* adapt size of buffer to SC_MAX_EXT_APDU_DATA_SIZE
2020-03-04 21:59:38 +01:00
Peter Marschall 968815e6ef opensc-explorer: re-factor do_get_data()
* determine DO ID/tag the same way as do_find_tags()
* replace magic magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_RESP_SIZE
* change buffer type from unsigned char to u8 for consistency with
  do_put_data() & do_find_tags()
* give ID/tag of DO in error message
* open target file in binary mode
2020-03-04 21:59:38 +01:00
Peter Marschall f556c275f7 opensc-explorer: re-factor do_find_tags()
* set default values for variables at declaration time
* replace magic number used as potentially too small buffer size
  by SC_MAX_EXT_APDU_RESP_SIZE
* use braces after sizeof, i.e. sizeof(X) instead of sizeof X
2020-03-04 21:59:38 +01:00
Peter Marschall b6febc0c7a opensc-explorer: re-factor do_find()
* set default values for variables at declaration time
* use sizeof(fid) instead of magic number
* use braces after sizeof, i.e. sizeof(X) instead of sizeof X
* start error message with upper-case letter
2020-03-04 21:59:38 +01:00
Peter Marschall 4abacbf5c1 opensc-explorer: re-factor read_and_print_binary_file()
* rename from read_and_util_print_binary_file(); adapt callers
* use large enough buffer size SC_MAX_EXT_APDU_RESP_SIZE
  instead of potentially too small magic number
* fix spaces before opening curly braces
* avoid special casing SC_CARD_TYPE_BELPIC_EID: a successful read
  of an empty file is still a success, even if nothing can get printed
2020-03-04 21:59:38 +01:00
Peter Marschall f20b646a97 opensc-explorer: re-factor do_cd()
* do not fail on SC_FILE_TYPE_UNKNOWN: be more flexible w.r.t accepting
  unknown file types when the preceding card operations succeeded
* fix spaces before opening curly braces
2020-03-04 21:59:38 +01:00
Peter Marschall 78c79c0efb opensc-explorer: refactor arg_to_path()
* fix indentation
* fix spaces before opening curly braces
2020-03-04 21:59:38 +01:00
Peter Marschall 81ace3689d opensc-explorer: extend do_info()
* distinguish between Internal and Working EFs
* add information optionally available in sc_file_t
  - record_count
  - record_length
  - type_attr
* align all labelled values
2020-02-27 22:55:38 +01:00
Peter Marschall 95cae64f83 opensc-explorer: replace magic numbers by SC_MAX_PIN_SIZE
Replace magic numbers, used as size of PIN-type buffers,
with the symbolic constant SC_MAX_PIN_SIZE, fixing
- readability / understandability
- too small sizes (e.g. for GnuPG cards)
2020-02-27 22:54:50 +01:00
Frank Morgner 5475dbcb3c fixed Uninitialized scalar variable
Thanks to Coverity Scan
2020-02-04 13:56:53 +01:00
Peter Marschall 5da40bf027 opensc-explorer: make '--card-driver ?' list all available drivers
Make opensc-explorer a bit more user friendly by treating the question mark
given as argument to option '--card-driver' special: list all available
drivers instead of stupidly bailing out.
2020-01-12 09:36:49 +01:00
carblue f14043aad6 opensc-explorer get: prevent sc_read_binary applied on record-based files 2020-01-07 10:35:39 +01:00
Peter Marschall 229dd32e3a opensc-explorer: fix APDU command
Do not ignore first parameter.
2019-06-21 14:34:38 +02:00
Frank Morgner fc9277b778 use compat_getopt_long if getopt_long is not available
uses the autoconf way for replacing getopt.h

fixes https://github.com/OpenSC/OpenSC/issues/1527
2019-03-25 14:30:09 +01:00
Frank Morgner 6fdb29a470 fixed use of uninitialized values 2019-02-14 09:22:23 +01:00
Frank Morgner 85485eb9b0 fixed unused assignments 2019-02-14 09:22:23 +01:00
Frank Morgner 3fe198f21e treat records with size_t 2019-01-20 23:02:21 +01:00
Peter Marschall a6ee84f13d opensc-explorer: fix 'pin_info' command
Correctly treat 'data.pin1.logged_in' as tristate instead of boolean.
While at it, fix visual glitch to not wrap around a stand-alone period.
2019-01-02 09:08:00 +01:00
Frank Morgner b01ca2dcc9
added support for colors (#1534)
because everyone loves colors
2018-11-25 22:08:36 +01:00
Frank Morgner 3c0a16dc39 CID 321790 (#1 of 1): Resource leak (RESOURCE_LEAK) 2018-11-06 15:53:17 +01:00
Jakub Jelen e920ef8eb8 opensc-explorer: Make static analyzers happy 2018-10-01 23:07:34 +02:00
Peter Marschall 3cc2670f3e opensc-explorer: avoid warnings on readline-less builds 2018-09-24 00:03:13 +02:00
Peter Marschall 14a31a3c42 opensc-explorer: refactor main()
* localize variables
* print errors to stderr
* release allocated resources
* return error code on error - improve non-interactive use
* do not show help on unknown commands when used non-interactively
2018-09-24 00:03:13 +02:00
Peter Marschall 9616ad4d94 opensc-explorer: fix&clarify handling of interactive mode
* make 'interactive' a global variable
* set it when opensc was called with the SCRIPT argument
* document the behaviour in the manual page

Make interactive a global variable and set it in main.
2018-09-24 00:03:13 +02:00
Peter Marschall c5679bfe39 opensc-explorer: refactor read_cmdline()
* add comments
* simplify #ifdef logic
* increase commandline buffer in non-interactive / non-readline case
2018-09-24 00:03:13 +02:00
Peter Marschall ca9538761b opensc-explorer: refactor parse_cmdline()
* add comments
* always terminate argv[] with a NULL element
* fail if number of arguments is too large
2018-09-24 00:03:13 +02:00
Peter Marschall c9db3f7385 opensc-explorer: allow arguments for 'help'
When arguments are given, compare them like ambguous_match() does,
and show the matching ones only.

Add documentation of the 'help' command to the manual page.

In main loop on multiple matches, show help on matching commands only.
2018-09-24 00:03:13 +02:00
Peter Marschall c817be8faa opensc-explorer: refactor ambiguous_match()
* most importantly: immediately return success on exact match
  - this allows one command to be a prefix of another one
  - it fixes the long-standing breakage between 'find' and 'find_tags'
* fail on second prefix-only match instead of waiting until the end
* check all parameters
* add comments
* inform caller on whether the match was ambiguous or there was no match
* move printing error messages to processing loopt in main()
2018-09-24 00:03:13 +02:00
Peter Marschall 593a90f64e opensc-explorer: write error messages to stderr
Clarify the distinction between error messages and status messages or prompts.
Prepare for better non-interactive support.
2018-09-24 00:03:13 +02:00
Peter Marschall 77297f7965 opensc-explorer: check length of argument to option --mf
* fail when it is too long
* replace a magic numerical constant
2018-09-24 00:03:13 +02:00
Peter Marschall 9d501766b4 opensc-explorer: extend 'random' to allow writing to a file
Accept a file name as a second argument to the 'random' command
to allow storing the generated random bytes to the file given.

Forbid writing binary data to stdout in interactive mode.
2018-09-24 00:03:13 +02:00
Peter Marschall 7a4a9f1951 opensc-explorer: refactor do_put() slightly
Avoid misunderstandings by renaming a variable that refers to an
input file handle from 'outf' to 'inf'.
2018-09-24 00:03:13 +02:00
Peter Marschall 1245b617d1 opensc-explorer: refactor do_apdu() slightly
* limit buffer to SC_MAX_EXT_APDU_BUFFER_SIZE
* fix buffer length calculation to correctly calculate the available space
* add length checks when parsing passed data into buffer
2018-09-24 00:03:13 +02:00
Peter Marschall 58da74bc32 opensc-explorer: refactor do_put_data() slightly
* increase input buffer size
* avoid magic number
* notify caller on error details when parsing fails
2018-09-24 00:03:13 +02:00