首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ICC未激活

ICC未激活
EN

Stack Overflow用户
提问于 2022-01-02 17:51:32
回答 1查看 123关注 0票数 1

我目前正试图破解我的智能卡,但我现在被困在阅读任何有用的卡片。我试图发送一个选择文件命令(0x6F, 0xB, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x04, 0x0c, 0x06, 0xd2, 0x76, 0x00, 0x00, 0x01, 0x02)到我的卡(在PC_to_RDR_IccPowerOn之后,它返回正确的PC_to_RDR_XfrBlock命令)。

但是,我的响应将bmICCStatus标志设置为0x40,表示"ICC存在且不活动(未因硬件错误而激活或关闭)“,但我不太确定如何处理该信息。我该怎么激活卡片?我以为给它供电就够了。

很有可能我只是瞎了眼,而且它是写在规范中的,但是我找不到它,我的谷歌搜索给我带来了一个这样的问题,这并没有对我的问题造成很大的影响。

我正在使用libusb1.0和C,但我认为这与问题无关。

编辑:

我已经添加了一个代码示例,但是如果您想运行它,您必须自己选择设备。

代码语言:javascript
复制
#include <stdio.h>
#include <stdlib.h>
#include <libusb-1.0/libusb.h>
#include <string.h>

#define TIMEOUT 1000

void print_bytes(unsigned char * arr, int len) {
    for(int i = 0; i < len; ++i) {
        printf("%0.2x ", arr[i]);
    }
    printf("\n");
}

int main() {

    /* I have some logic which is not included to find the apropriate sc-reader. */
    /* Please use libusb_get_device_list() or similar to select your device. */
    libusb_device * egk_sc_reader = NULL;

    libusb_device_handle * handle = NULL;
    int k = libusb_open(egk_sc_reader, &handle);

    int transferred = 0;

    libusb_claim_interface(handle, 0);

    unsigned char cmd_pwr_on[] = {
        0x62,   0x00, 0x00, 0x00, 0x00,   0x00, 0x00, 0x00,   0x00, 0x00
    };

    unsigned char cmd_select_file[] = {
        // CMD (1), LEN (4), Slot (1), Seq (1), Block Wait Time (1), Level Parameter (2), abData (LEN)
        0x6F, 0xB, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x04, 0x0c, 0x06, 0xd2, 0x76, 0x00, 0x00, 0x01, 0x02
    };

    int buf_in_len = 128;
    unsigned char buf_in[buf_in_len];
    memset(buf_in, 0, buf_in_len);

    // Write power on
    libusb_bulk_transfer(handle, 0x05, cmd_pwr_on, sizeof(cmd_pwr_on), &transferred, TIMEOUT);

    // read atr
    libusb_bulk_transfer(handle, 0x86, buf_in, buf_in_len, &transferred, TIMEOUT);

    print_bytes(buf_in, buf_in_len);
    memset(buf_in, 0, 128);

    // Write select command
    libusb_bulk_transfer(handle, 0x05, cmd_select_file, sizeof(cmd_select_file), &transferred, TIMEOUT);

    // read answer
    libusb_bulk_transfer(handle, 0x86, buf_in, buf_in_len, &transferred, TIMEOUT);

    print_bytes(buf_in, buf_in_len);

    libusb_release_interface(handle, 0);
    libusb_close(handle);

    return 0;
}

此代码示例试图模仿我的实际代码。它不完全相同,但结果与我的问题相匹配,因为标准输出是:

代码语言:javascript
复制
80 0e 00 00 00 00 00 00 80 00 3b d3 96 ff 81 b1 fe 45 1f 07 80 81 05 2d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
80 00 00 00 00 00 01 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

我使用的阅读器是来自WD Plus GmbHWD Plus GmbH,智能卡是来自Bahn BKKEGK (Elektronische Gesundheitskarte) (en: Electronic Healtcare Card)。该卡支持T=0和T=1 (Gematik规范:https://fachportal.gematik.de/fileadmin/user_upload/fachportal/files/Spezifikationen/Basis-Rollout/Elektronische_Gesundheitskarte/gemLF_Impl_eGK_V160.pdf)

只要发送APDU,就会返回一个“不受支持/消息参数不正确的索引”错误。这是有道理的,当我想到它。

提前感谢

塞迪韦里

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-01 11:40:28

根据ATR,您的卡仅为T=1 https://smartcard-atr.apdu.fr/parse?ATR=3BD396FF81B1FE451F078081052D

我不知道你用的是哪种阅读器。如果读取器使用的是TPDU而不是APDU,那么它比仅仅发送APDU要复杂得多。您必须在代码中实现T=1。

我猜缺少的CCID命令是PC_to_RDR_SetParameters,可以用正确的参数配置读取器。

我真的建议使用已经存在的软件。就像我的Unix驱动程序https://ccid.apdu.fr/一样。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70558359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档