• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created almost 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A framework for creating smart cards (ICC-based cards with contacts).

swICC Library

Project needs to be cloned recursively. Downloading the ZIP is not enough.

Software ICC (or swICC) is a framework providing an easy and flexible way to develop most types of smart cards. It also allows any swICC-based card to be connected to the PC through the PC/SC interface (using the swICC PC/SC reader) which is the de facto standard for connecting smart cards to PCs.

Scope

  • Framework for developing smart cards in software, with no hardware dependencies.
  • Any swICC-based card can connect to the PC via PC/SC using the swICC PC/SC reader.
  • Smart card file system can be defined using JSON, examples present in ./test/data/disk. The FS can be saved to disk as a .swiccfs file, and loaded back into the card.
  • Plenty debug utilities.
  • Includes an easy-to-use BER-TLV implementation.

Install

  • You need make, cmake, and gcc to compile the project. No extra runtime dependencies.
  1. sudo apt-get install make cmake gcc
  2. git clone --recurse-submodules [email protected]:tomasz-lisowski/swicc.git
  3. cd swicc
  4. make main-dbg (for more info on building, take a look at ./doc/install.md).
  5. Link with ./build/libswicc.a (e.g. -Llib/swicc/build -lswicc) and add ./include to the include path (e.g. -Ilib/swicc/include).
  6. In your project add #include <swicc/swicc.h> to include all headers.

Usage

To create a minimal smart card do the following:

  1. Make sure to follow the installation instructions first and make sure ./build/libswicc.a exists.
  2. mkdir card
  3. cd card
  4. Copy the following code into a main.c file inside the ./card directory.
Click to see source code.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <swicc/swicc.h>

swicc_net_client_st client_ctx = {0U};

static void sig_exit_handler(__attribute__((unused)) int signum)
{
    printf("Shutting down...\n");
    swicc_net_client_destroy(&client_ctx);
    exit(0);
}

int32_t main(int32_t const argc, char const *const argv[const argc])
{
    swicc_disk_st disk = {0U};
    swicc_ret_et ret = swicc_diskjs_disk_create(&disk, "../test/data/disk/006-in.json");
    if (ret == SWICC_RET_SUCCESS)
    {
        swicc_st swicc_ctx = {0U};
        ret = swicc_fs_disk_mount(&swicc_ctx, &disk);
        if (ret == SWICC_RET_SUCCESS)
        {
            ret = swicc_net_client_sig_register(sig_exit_handler);
            if (ret == SWICC_RET_SUCCESS)
            {
                ret =
                    swicc_net_client_create(&client_ctx, "127.0.0.1", "37324");
                if (ret == SWICC_RET_SUCCESS)
                {
                    ret = swicc_net_client(&swicc_ctx, &client_ctx);
                    if (ret != SWICC_RET_SUCCESS)
                    {
                        printf("Failed to run network client.\n");
                    }
                    swicc_net_client_destroy(&client_ctx);
                }
                else
                {
                    printf("Failed to create a client.\n");
                }
            }
            else
            {
                printf("Failed to register signal handler.\n");
            }
            swicc_terminate(&swicc_ctx);
        }
        else
        {
            printf("Failed to mount disk.\n");
            swicc_disk_unload(&disk);
        }
    }
    else
    {
        printf("Failed to create disk.\n");
    }

    return 0;
}
  1. gcc main.c -I../include -L../build -lswicc -o card.elf to build the card.
  2. To interact with the card over PC/SC, you will need to start a swICC card server, e.g., the swICC PC/SC reader.
  3. ./card.elf which will connect the card to the card reader.
  4. pcsc_scan (part of the pcsc-tools package) will show some details of the card.
  5. You can begin interacting with the card through PC/SC as you would with a real card.

To implement a custom card, one needs to register an APDU demuxer (before running the network client) through swicc_apduh_pro_register, as well as APDU handlers that get called by the demuxer depending on command that was received. A good example for using the framework in a more advanced way is the swSIM project which implements a SIM card using swICC.

More Repositories

1

swsim

A software SIM card.
C
296
star
2

swicc-pcsc

A PC/SC IFD handler to attach swICC-based cards through a software PC/SC reader.
C
29
star
3

simurai

Shell
16
star
4

simurai-usenixsec2024-ae

Shell
5
star
5

zig-microui-example

Zig base for using https://github.com/rxi/microui (immediate-mode UI library)
Zig
3
star
6

b2xto

Stop apps that don't receive packets and start them when they do.
Zig
3
star
7

bytes2img

Read raw pixel data (i.e. a list of bytes) and save them into a standard image format.
Zig
3
star
8

lean-logic-examples

Proofs of exercises at https://leanprover.github.io/logic_and_proof/ and other miscellaneous formulas.
Lean
2
star
9

c-exe-template

Makefile
2
star
10

esolang-grta

A minimal and extremely difficult esolang written in WebASM and C.
WebAssembly
2
star
11

scraw-c

Cross-platform library for sending raw APDU T=0 or T=1 messages to smart cards. Superseded by https://github.com/tomasz-lisowski/scraw
C
1
star
12

lgnosleep

Prevents LG monitors from going to sleep when the screen is almost black.
C
1
star
13

a002513-generating-algorithm

Algorithm for generating the A002513 (https://oeis.org/A002513) integer sequence (including a list of the arrangements).
JavaScript
1
star
14

integer-java-virtual-machine

Fast IJVM virtual machine (with some extensions and a standalone debugger).
C
1
star
15

theme-ilk

VSCode theme which couples semantic groups to a small number of colors for improved readability. Made specifically for C.
1
star
16

scraw

Cross-platform library for sending raw APDU T=0 or T=1 messages to smart cards.
Zig
1
star
17

pysim-docker

Shell
1
star
18

scrng

Uses a smart card to generate random data (put those old SIM cards to good use :>).
C
1
star
19

generative

Collection of my generative arts.
C
1
star