Commit Graph

10 Commits

Author SHA1 Message Date
Harald Welte 0f177c1d29 transport: Pass argparse.Namespace directly into transport classes
It's odd that the individual transport driver specifies their argparse
options but then the core transport part evaluates them individually.
This means we cannot add new options within a transport.

Let's pass the Namespace instance into the constructor of the
specific transport to improve this.

Change-Id: Ib977007dd605ec9a9c09a3d143d2c2308991a12c
2023-12-21 11:31:57 +00:00
Philipp Maier 3a37ad015c sim-reset-server: fix error printing sw_match_error
In the last line of the if,elif,else branch, when we print the ApiError
object, we pass the variable sw to str() instead passing it to
ApiError() like we do it in the lines above. This is not correct and
causes strange exceptions.

Related: OS#67094
Change-Id: I5a1d19abeb00c2c9dc26517abc44a5c916f2d658
2023-09-06 12:59:24 +02:00
Philipp Maier 7d13845285 sim-rest-server: fix REST method info
The REST megthd info uses deprecated methods to read the ICCID and the
IMSI from the card. However, we can replace those methods by selecting
the files we are interested in manually and then reading them.

Related: RT#67094
Change-Id: Ib0178823abb18187404249cfed71cfb3123d1d74
2023-08-25 09:52:48 +02:00
Philipp Maier 91b379a039 sim-rest-server: use UiccCardBase instead of UsimCard
The class UsimCard is deprecated and only still used in very old
legacy applications. let's use the more modern UiccCardBase class
instead.

Related: RT#67094
Change-Id: I3676f033833665751c0d953176eafe175b20c14a
2023-08-21 18:36:10 +00:00
Philipp Maier 71a3fb8b3a sim-rest-server: do not select ADF.USIM in connect_to_card
When the function connect_to_card is done, it selects ADF.USIM. This
might be contraproductive in case someone needs to access files on MF
level in one of the REST methods. Instead fo ADF.USIM, let's use MF as a
common ground to start from.

At the moment the only existing REST (info, auth) immediately select
ADF.USIM after calling connect_to_card already, so there are no further
modifications necessary.

Related: RT#67094
Change-Id: I16e7f3c991c83f81989ecc4e4764bb6cc799c01d
2023-08-21 18:36:10 +00:00
Harald Welte 04897d5f25 sim-rest-server: Report meaningful error message if PIN is blocked
Instead of a cryptic backtrace, we now return a meaningful error like this:

{"error": {"message": "Security Status not satisfied - Card PIN enabled?", "status_word": "6982"}

Change-Id: I6dafd37dfd9fa3d52ca2c2e5ec37a6d274ba651b
Closes: OS#5606
2022-07-23 14:07:00 +02:00
Harald Welte 3f3b45a27b sim-rest-server: Render error messages as JSON
Let's make sure even error messages are returned in JSON format.

While at it, also reduce some code duplication between the 'auth'
and 'info' route handlers by using the klein handle_errors decorator
instead of manual exception catching.

Change-Id: I1e0364e28ba7ce7451993f57c8228f9a7ade6b0e
Closes: OS#5607
2022-07-23 13:46:52 +02:00
Harald Welte 6f8cf9b315 sim-rest-server: Set Content-Type: application/json on response
Change-Id: Ib80a650f3e8d3e3ee6295db6de0981dfc23d3feb
2022-07-08 20:47:46 +02:00
Harald Welte 33f8da8a52 sim-rest-server: Add capability to obtain IMSI + ICCID of card
$ curl http://localhost:8000/sim-info-api/v1/slot/0
{
    "imsi": "262011500776110",
    "iccid": "89490240001879910128"
}

Change-Id: I9df8854f6a962e7f86f62b2d44ec7696271c58c8
2021-11-03 12:34:24 +01:00
Harald Welte c781ab85bc contrib: Add sim-rest-{server,client}.py
sim-rest-server.py can be used to provide a RESTful API to allow remote
clients to perform the authentication command against a SIM card in a
PC/SC reader.

sim-rest-client.py is an example client against sim-rest-server.py
which can be used to test the functionality of sim-rest-server.py.

Change-Id: I738ca3109ab038d4f5595cc1dab6a49087df5886
2021-05-25 09:43:13 +02:00