Rekey SA binds a key that is not Active (no key-state check)

Abierto Apto para principiantes
#562 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
security

Línea de trabajo

Lee sa_rekey en src/sa/internal/sa_interface_inmemory.template.c y compara su validación de claves con Crypto_Key_OTAR en src/core/crypto_key_mgmt.c. Comprueba cómo prueba el proyecto los errores de estado de las claves y, después, verifica que Rekey SA devuelve KEY_ID_ERROR para una clave desconocida y KEY_STATE_INVALID para una clave que no está en estado Active, mientras acepta una clave en estado Active.

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

Descripción

bug
Description
Summary

CCSDS 355.1-B-1 sec. 3.3.3.3.2 requires the new key at Rekey SA to be in the Active state. On v1.5.1 (5b98c8b; v1.5.0 shares the code), sa_rekey stores the Encryption Key ID from the PDU without consulting the key's state, so it accepts a PreActivation key, a Deactivated key, or a key id that does not exist. A following Start SA then makes the SA Operational, but every frame fails at the transmit/receive path with KEY_STATE_INVALID (-61) because the bound key cannot be used: management reports SUCCESS while no traffic can flow.

The library already does the right check elsewhere: Crypto_Key_OTAR (src/core/crypto_key_mgmt.c:117-126) refuses non-Active keys, and the key directives themselves refuse wrong-state transitions (-59) and unknown ids (-47). sa_rekey simply lacks the equivalent guard.

Code site

sa_rekey, src/sa/internal/sa_interface_inmemory.template.c (ekid parse): stores ekid from the PDU with no key_if->get_key state check.

Impact

Conformance / robustness. An out-of-order EP flow can leave an SA reporting Operational while bound to an unusable key; management answers SUCCESS, data answers KEY_STATE_INVALID on every frame. No memory-safety issue.

Suggested fix

After parsing ekid, look the key up with key_if->get_key(ekid) and return KEY_ID_ERROR (-47) for an unknown id and KEY_STATE_INVALID (-61) for a non-Active key, exactly as Crypto_Key_OTAR does. Valid rekeys onto Active keys are unchanged. I have a compile-checked patch verified with a standalone C PoC and can open a PR or share the PoC on request.

Found with active automata learning (AutoSDLS) and confirmed with a standalone C PoC that uses none of that tooling.

Branch Name

No response

Reproduction steps
1. Build CryptoLib v1.5.1 (`5b98c8b`) with the in-memory SA interface.
2. Create an SA, and have a key whose state is not Active (PreActivation or Deactivated), or use a key id that does not exist.
3. Send a Rekey SA directive binding that key id to the SA.
4. Observe `sa_rekey` returns `CRYPTO_LIB_SUCCESS` and stores the ekid, with no key-state check.
5. Start the SA (it goes Operational), then send a frame: every frame fails with `KEY_STATE_INVALID` (-61), so management reports success while no traffic can flow.

A standalone C PoC reproducing this (independent of the discovery tooling) is available on request.
Screenshots
![DESCRIPTION](LINK.png)
Logs

OS

Linux

Lenguaje dominante
C
Estrellas
178
Forks
70
Merge medio
1 h 32 min
PR fusionados (30 d)
1

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

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 nasa/CryptoLib

Todos los issues de nasa/CryptoLib

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.