Skip to content

wsct/WSCT-GlobalPlatform

Repository files navigation

WSCT GlobalPlatform

Public repository for WSCT GlobalPlatform project NuGet.

Features

The current status of this project is work in progress.

  • GP 2.2 commands:
    • SELECT CARD MANAGER
    • GET CARD DATA
    • GET DATA
    • GET STATUS
    • INSTALL [for load]
    • INSTALL [for install]
    • INSTALL [for make selectable]
    • INSTALL [for install and make selectable]
    • LOAD
    • DELETE
  • SCP01 support:
    • Mutual authentication (INITIALIZE UPDATE, EXTERNAL AUTHENTICATE)
    • Automatic wrapping / unwrapping of APDU
    • CMAC
    • CDEC
  • SCP02 support:
    • 3-keys
    • 1-key
    • Mutual authentication (INITIALIZE UPDATE, EXTERNAL AUTHENTICATE)
    • Automatic wrapping / unwrapping of APDU
    • CMAC
    • RMAC
    • CDEC

Some examples of usage

Establish a secure channel

// Define card keys
var SEnc = "40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F".FromHexa();
var SMac = "40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F".FromHexa();
var Dek = "40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F".FromHexa();

CardContext? cardContext;
CardChannel? cardChannel;
try
{
    // Get a valid cardChannel instance
    // ...

    // Use GlobalPlatform API
    var gpCard = new GlobalPlatformCard(cardChannel);

    gpCard
        .ProcessSelectCardManager();

    gpCard
        .ProcessGetCardData();

    Console.WriteLine(gpCard.CardData);

    // Do SCP02 Mutual Authentication
    var scpUsed = gpCard.CardData.SupportedScps.First(scp => scp.Identifier == 0x02);

    gpCard
        .ProcessInitializeUpdate(scpUsed, keyVersion, KeyIdentifier, hostChallenge);

    Console.WriteLine(gpCard.SecureChannelData);

    gpCard
        .CreateSessionKeys(new Keys(SEnc, SMac, Dek));

    Console.WriteLine(gpCard.SecureChannelData);

    gpCard
        .AuthenticateCard();

    gpCard
        .ProcessExternalAuthenticate(SecurityLevel.CMac /*| SecurityLevel.CEnc */);

    Console.WriteLine(gpCard.SecureChannelData);

    // GET STATUS command
    gpCard
        .ProcessCommand(new CommandAPDU(0x80, 0xF2, 0x40, 0x00, 0x02, new byte[] { 0x4F, 0x00 }, 0x00));

    // GET DATA Key Information Template
    gpCard
        .ProcessCommand(new GetDataCommand(0xE0));

    // GET DATA Sequence Counter of the default Key Version Number
    gpCard
        .ProcessCommand(new GetDataCommand(0xC1));
}
finally
{
    cardChannel?
        .Disconnect(Disposition.UnpowerCard);

    cardContext
        .Release();
}

INSTALL [for load]

Once the secure channel is established, a new application on the card can be loaded on the card.

var loadFileAid = "F04341454E42".FromHexa();
byte[] securityDomainAid = [];
byte[] loadFileDataBlockHash = [];
byte[] loadParameters = [];
byte[] loadToken = [];

gpCard
	.ProcessInstallForLoad(loadFileAid, securityDomainAid, loadFileDataBlockHash, loadParameters, loadToken);

var pathToCapFile = @"path/to/cap/file/applet.cap";

gpCard
	.ProcessLoad(pathToCapFile);

INSTALL [for install and make selectable]

var moduleAid = "F04341454E42 01".FromHexa();
var applicationAid = "F04341454E42 01".FromHexa();
var privileges = "00".FromHexa();
var installParameters = "C9 00".FromHexa();
byte[] installToken = [];

gpCard
	.ProcessInstallForInstallAndMakeSelectable(loadFileAid, moduleAid, applicationAid, privileges, installParameters, installToken);

DELETE

var aid = "F04341454E42".FromHexa();

gpCard
	.ProcessDelete(aid);

About

Public repository for WSCT GlobalPlatform project

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages