The default log level of the PySimLogger is DEBUG by default. This is to ensure that all messages are printed in an unconfigured setup.
However in pySim-Shell we care about configuring the logger, so let's set the debug log level to INFO in startup. This will allow us to turn debug messages on and off using the verbose switch.
card_key_provider: separate and refactor CSV column encryption
The CardKeyProviderCsv class implements a column decryption scheme where columns are protected using a transport key. The CSV files are enrcypted using contrib/csv-encrypt-columns.py.
The current implementation has two main problems:
- The decryption code in CardKeyProviderCsv is not specific to CSV files. It could be re-used in other formats, for example to decrypt columns (fields) red from a database. So let's split the decryption code in a separate class.
- The encryption code in csv-encrypt-columns.py accesses methods and properties in CardKeyProviderCsv. Also having the coresponding encryption code somewhere out of tree may be confusing. Let's improve the design and put encryption and decryption functions in a single class. Let's also make sure the encryption/decryption is covered by unittests.
card_key_provider: use case-insensitive field names
It is common in CSV files that the columns have uppercase names, so we have adopted this scheme when we started using the card_key_provider.
This also means that the API of the card_key_provider_get() and card_key_provider_get_field() function now implicitly requires uppercase field names like 'ICCID', 'ADM1', etc.
Unfortunately this may be unreliable, so let's convert the field names to uppercase as soon as we receive them. This makes the API case-insensitive and gives us the assurance that all field names we ever work with are in uppercase.
card_key_provider: remove unnecessary class property definitions
The two properties csv_file and csv_filename are defined by the constructor anyway, let's remove the declaration in the class body because it is not needed.
pySim-shell: add command to manually query the Card Key Provider
The Card Key Provider is a built in mechanism of pySim-shell which allows the user to read key material from a CSV file in order to avoid having to lookup and enter the key material himself. The lookup normally done by the pySim-shell commands automatically.
However, in some cases it may also be useful to be able to query the CSV file manually in order to get certain fields displayed. Such a command is in particular helpful to check and diagnose the CSV data source.
pySim-shell: re-organize Card Key Provider related options
As we plan to support other formats as data source for the Card Key Provider soon, the more commandline options may be added and it makes sense to group the Card Key Provider options in a dedicated group.
Let's also rename the option "--csv-column-key" to just "--column-key". The column encryption is a generic concept and not CSV format specific. (let's silently keep the "--csv-column-key" argument so maintain backward compatibility)
card_key_provider: remove method _verify_get_data from base class
The method _verify_get_data was intended to be used to verify the user input before it further processed but ended up to be a simple check that only checks the name of the key column very basically.
Unfortunately it is difficult to generalize the check code as the concrete implementation of those checks is highly format dependent. With the advent of eUICCs, we now have two data formats with different lookup keys, so a static list with valid lookup keys is also no longer up to the task.
After all it makes not much sense to keep this method, so let's remove it.
(From the technical perspective, the key column is not limitied to any specif field. In theory it would even be possible to use the KI as lookup key as well, even though it would not make sense in practice)
card_key_provider: refactor code and optimize out get_field method
The method get_field in the base class can be optimized out. This also allows us to remove code dup in the card_key_provider_get_field function.
Let's also fix the return code behavior. A get method in a CardKeyProvider implementation should always return None in case nothing is found. Also it should not crash in that case. This will allow the card_key_provider_get function to move on to the next CardKeyProvider. In case no CardKeyProvider yields any results, an exception is appropriate since it is pointless to continue execution with "None" as key material.
To make the debugging of problems easier, let's also print some debug messages that inform the user what key/value pair and which CardKeyProvider was queried. This will make it easier to investigate in case an expected result was not found.