Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

C_GetSlotList of opensc-pkcs11 returns inconsistent results on Rutokens depending on args

Abierto
#3,393 12 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@frankmorgner ya está trabajando en esto.

Desde el 26/6/2026.

  • #3721 de @frankmorgner — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
c
Área
api, security

Línea de trabajo

Start by reading the PKCS#11 implementations of C_GetSlotList and C_GetSlotInfo, then reproduce the reported behavior with a Rutoken using the provided program and compare the two debug logs. The issue names no source files or tests. Done means the present-token results are consistent between C_GetSlotList(CK_FALSE, ...) and C_GetSlotList(CK_TRUE, ...), as described in either expected-behavior option.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

opensc version 0.25.1
OS: Ubuntu 24.04.1 LTS

Description

Hi!

I noticed some curious behaviour of opensc-pkcs11 with Rutokens. C_GetSlotList(CK_TRUE, ...) returns empty list of slots, meanwhile C_GetSlotList(CK_FALSE, ...) returns list of with single slot marked as present. Calling C_GetSlotInfo on this slot returns CKR_TOKEN_NOT_RECOGNIZED

How to reproduce

Here is the program I used to check it:

#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

int main(int, char* argv[]) {
    CK_RV r;

    printf("load lib\n");
    void* h =dlopen(argv[1], RTLD_NOW);
    if (!h)
        return 1;
    
    printf("load funcs\n");
    CK_C_GetFunctionList flf= dlsym(h, "C_GetFunctionList");
    if (!flf)
        return 2;

    printf("get funcs\n");
    CK_FUNCTION_LIST_PTR fl;
    r = flf(&fl);
    if (r != CKR_OK)
        return 3;

    printf("init lib\n");
    r = fl->C_Initialize(NULL_PTR);
    if (r != CKR_OK)
        return 4;

    printf("get slots\n");
    CK_ULONG sls;
    CK_SLOT_ID_PTR sll = NULL_PTR;
    r = fl->C_GetSlotList(CK_FALSE, sll, &sls);
    if (r != CKR_OK)
        return 5;

    sll = malloc(sls*sizeof(CK_SLOT_ID));
    r = fl->C_GetSlotList(CK_FALSE, sll, &sls);
    if (r != CKR_OK)
        return 6;

    if (sls == 0)
        printf("no tokens\n");

    for (CK_ULONG i=0; i != sls; ++i) {
        CK_SLOT_INFO si;
        r = fl->C_GetSlotInfo(sll[i], &si);
        if (si.flags & CKF_TOKEN_PRESENT) {
            printf("slot has token\n");
            CK_TOKEN_INFO ti;
            r = fl->C_GetTokenInfo(sll[i], &ti);
            printf("get info res: %lu\n", r);
        } else {
            printf("slot has no  token\n");
        }
    }

    if (sll) {
        free(sll);
    }

    r = fl->C_Finalize(NULL_PTR);
    dlclose(h);
}

Output:

load lib
load funcs
get funcs
init lib
get slots
slot has token
get info res: 225

If replace it to C_GetSlotList(CK_FALSE, ...) to C_GetSlotList(CK_TRUE, ...) I see no tokens in output

Logs:
C_GetSlotList(CK_FALSE, ...) log: opensc-debug-with-C_GetSlotList-false.txt

C_GetSlotList(CK_TRUE, ...) log: opensc-debug-with-C_GetSlotList-true.txt

This issue connected with this one

Expected behaviour

So, I think a correct way to make showing of present tokens consistent. It's could be achieved two ways:

  1. tokens, marked as present and returned by C_GetSlotList(CK_FALSE, ...), should also be returned by C_GetSlotList(TRUE, ...)
  2. tokens, not returned by C_GetSlotList(TRUE, ...) shouldn't be marked as present by C_GetSlotList(CK_FALSE, ...)
Lenguaje dominante
C
Estrellas
3.1k
Forks
858
Merge medio
4 d 4 h
PR fusionados (30 d)
16

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenSC/OpenSC

Todos los issues de OpenSC/OpenSC

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.