Exemple #1
0
    def __init__(self, device, baudrate):

        # create trasnport
        self.sl = SerialSimLink(device=device, baudrate=baudrate)

        # create command layer
        self.scc = SimCardCommands(transport=self.sl)

        # wait for SIM card
        print("[INFO] Waiting for SIM card ...")
        self.sl.wait_for_card()

        # program the card
        print("[INFO] Reading SIM card ...")
Exemple #2
0
def auth(request, slot):
    """REST API endpoint for performing authentication against a USIM.
       Expects a JSON body containing RAND and AUTN.
       Returns a JSON body containing RES, CK, IK and Kc."""
    try:
        # there are two hex-string JSON parameters in the body: rand and autn
        content = json.loads(request.content.read())
        rand = content['rand']
        autn = content['autn']
    except:
        request.setResponseCode(400)
        return "Malformed Request"

    try:
        tp = PcscSimLink(slot, apdu_tracer=ApduPrintTracer())
        tp.connect()
    except ReaderError:
        request.setResponseCode(404)
        return "Specified SIM Slot doesn't exist"
    except ProtocolError:
        request.setResponseCode(500)
        return "Error"
    except NoCardError:
        request.setResponseCode(410)
        return "No SIM card inserted in slot"

    scc = SimCardCommands(tp)
    card = UsimCard(scc)
    # this should be part of UsimCard, but FairewavesSIM breaks with that :/
    scc.cla_byte = "00"
    scc.sel_ctrl = "0004"
    try:
        card.read_aids()
        card.select_adf_by_aid(adf='usim')
        res, sw = scc.authenticate(rand, autn)
    except SwMatchError as e:
        request.setResponseCode(500)
        return "Communication Error %s" % e

    tp.disconnect()

    return json.dumps(res, indent=4)
Exemple #3
0
parser.add_argument('--smpp', action='store_true')
parser.add_argument('--test', action='store_true')
parser.add_argument('--aram-apdu', default='')

args = parser.parse_args()

if args.pcsc is not None:
    from pySim.transport.pcsc import PcscSimLink
    sl = PcscSimLink(args.pcsc)
elif args.serialport is not None:
    from pySim.transport.serial import SerialSimLink
    sl = SerialSimLink(device=args.serialport, baudrate=9600)
else:
    raise RuntimeError("Need to specify either --serialport or --pcsc")

sc = SimCardCommands(sl)
ac = AppLoaderCommands(sl)

if not args.smpp:
    sl.wait_for_card(newcardonly=args.new_card_required)
    time.sleep(args.sleep_after_insertion)

if not args.smpp:
    # Get the ICCID
    # print "ICCID: " + swap_nibbles(sc.read_binary(['3f00', '2fe2'])[0])
    ac.select_usim()
    ac.send_terminal_profile()

if len(args.aram_apdu) > 0:
    # Select the ARA-M applet from its AID
    aram_rv = rv = ac._tp.send_apdu('00A4040009A00000015141434C00')
Exemple #4
0
if __name__ == '__main__':

    # Parse options
    opts = parse_options()

    # Connect to the card
    if opts.pcsc_dev is None:
        from pySim.transport.serial import SerialSimLink
        sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate)
    else:
        from pySim.transport.pcsc import PcscSimLink
        sl = PcscSimLink(opts.pcsc_dev)

    # Create command layer
    scc = SimCardCommands(transport=sl)

    # Wait for SIM card
    sl.wait_for_card()

    # Program the card
    print("Reading ...")

    # EF.ICCID
    (res, sw) = scc.read_binary(['3f00', '2fe2'])
    if sw == '9000':
        print("ICCID: %s" % (dec_iccid(res), ))
    else:
        print("ICCID: Can't read, response code = %s" % (sw, ))

    # EF.IMSI