A crash while softhsm2-util --import rewrites token.object leaves it empty, and the token with every key in it unreadable

Abierto
#908 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
56/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
databases

Línea de trabajo

Start in src/lib/object_store/ObjectFile.cpp at ObjectFile::writeAttributes and trace how file-backend writes persist token.object; the report reproduces the failure by killing the write after truncation. Check existing tests for object-store writes and add coverage showing an interrupted rewrite leaves either the old or new content intact. Done when the token remains readable after an interrupted softhsm2-util --import rewrite.

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

Descripción

With the file backend, ObjectFile::writeAttributes truncates an object file and then writes it (src/lib/object_store/ObjectFile.cpp, unchanged on main at 9ad87341c9). softhsm2-util --import rewrites the token's own token.object this way. If the process is killed between the truncation and the write, token.object is left at 0 bytes, and the token disappears from its slot. The keys already in it are lost with it: their object files are still on disk, but token.object held the SO and user PIN blobs SoftHSM unwraps their key from.

To reproduce (SoftHSM 2.6.1, Debian 13 arm64):

export SOFTHSM2_CONF=$PWD/softhsm2.conf
mkdir tokens
printf 'directories.tokendir = %s/tokens\nobjectstore.backend = file\n' "$PWD" > softhsm2.conf
softhsm2-util --init-token --free --label t --pin 1234 --so-pin 5678
openssl genpkey -algorithm RSA -out k1.pem; openssl genpkey -algorithm RSA -out k2.pem
softhsm2-util --import k1.pem --token t --pin 1234 --label k1 --id 01
tok=$(ls -d tokens/*/)
strace -f -qq -P "$PWD/${tok}token.object" -e inject=write:signal=KILL \
  softhsm2-util --import k2.pem --token t --pin 1234 --label k2 --id 02
ls -l "$tok"; softhsm2-util --show-slots

strace shows ftruncate(3, 0) on token.object and the kill at the write that follows. Afterwards token.object is 0 bytes, --show-slots lists the slot with an empty label, and pkcs11-tool --token-label t --login --pin 1234 --list-objects answers No slot with token named "t" found, while k1's object file is still in the directory.

Expected: token.object holds its old content or its new content.

Found with Sideeye, a personal open-source tool, no commercial interest; say if you would rather not have such reports. Not measured: power loss, the database backend, and which other operations rewrite token.object.

Lenguaje dominante
C++
Estrellas
1.1k
Forks
434
Merge medio
12 d 14 h
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

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 softhsm/SoftHSMv2

Todos los issues de softhsm/SoftHSMv2

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.