Una vez más sobre las llaves de hardware GPG por un centavo


En febrero de 2020, apareció un artículo fascinante en Habré sobre la conversión del programador ST-Link v2 en una clave de cifrado de hardware. Incluso entonces, en los comentarios hubo quejas de que el resultado no podía repetirse, pero quedaron sin respuesta.


En el pasado, me llegaron un par de paquetes de Aliexpress y ahora, habiendo realizado todo el camino de forma independiente, intentaré enviar una instrucción más o menos completa con comentarios que ayuden a un laico a actualizar el microprocesador en el clon chino ST-Link v2 . Intentaré no repetir lo que ya se sabe, así que vea el artículo fuente sobre cómo soldar contactos y usar GPG con una llave de hardware.


Hardware


, , — Aliexpress. , - STM32***, . , , , .


— - . , USB USB , , , , .


ST-Link v2 STMicroelectronics STM32F103 , 128 -.


STM32F103CKS32F103C8*. . CS32F CKS32F. - , , 64 K -. , CKS32F103CB* 128 K , .


STM32GC102CB. , , , 64 K - (, , USB).


, 64 . ST-Link v2 .



- Linux, Debian. antiX Linux Debian 9 Stretch.


make git , :


sudo apt install gcc-arm-none-eabi
sudo apt install libnewlib-arm-none-eabi
sudo apt install openocd

, .


- c Arm Embedded Toolchain CentOS. .


Windows :



, .



, , . .


, . , , , , . , , . .


, OpenOCD.


- , ( ).


1: ST32F1** ( STM32GC102CB)


$ openocd -f interface/stlink-v2.cfg -f target/st32f1x.cfg -c 'init; reset halt; stm32f1x unlock 0; reset halt;exit'
...
Info : device id = 0x20036410
Info : flash size = 64kbytes
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.

2: CKS32F1**


$ openocd -f interface/stlink-v2.cfg -f target/st32f1x.cfg -c 'init; reset halt; stm32f1x unlock 0; reset halt;exit'
...
Info : STLINK v2 JTAG v29 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.174295
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477

interface/stlink-v2.cfg target/st32f1x.cfgOpenOCD, . ID 0x2ba01477, STM321F1*** 0x1ba01477. , OpenOCD ID, , STM321F1**, ID set _CPUTAPID 0x1ba01477.


 mkdir ~/.openocd/{target}
 cp /usr/share/openocd/scripts/target/stm32f1x.cfg ~/.openocd/target/cks32f1x.cfg
 sed -i 's/0x1ba01477/0x2ba01477/' /.openocd/target/cks32f1x.cfg

, CKS32F1** -f target/cks32f1x.cfg.


. , , 128 -. OpenOCD :


Error: checksum mismatch - attempting binary compare
diff 0 address 0x08010000. Was 0x00 instead of 0x7d
diff 1 address 0x08010001. Was 0x50 instead of 0x40

:


$ openocd -f interface/stlink-v2.cfg -f target/cks32f1x.cfg -c 'init; reset halt; stm32f1x unlock 1; reset halt;exit'
...
Error: flash bank 1 does not exist
...

— , .


GNUK


- , GNUK, .


, 2003 g10code, GnuPG, , OpenPGP, , ISO/IEC 7816. — ZeitControl , , Card OS ( -). FLOSS-Shop OpenPGP Smart Card 17,90 €. , -, .


Free Software Initiative of JapanFSF. GNUK STM32*, - OpenPGP Smart Card.


GNUK — 1.0 1.2, . , STABLE-BRANCH-1-0 STABLE-BRANCH-1-2 .


PolarSSL, 1.0 ChibiOS_2.0.8, 1.2 chopstx.


, 1.0 62 , 1.2 — 112 .


, 128 , 1.2


git clone https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
cd gnuk
git checkout  STABLE-BRANCH-1-2
#   'chopstx'
git submodule update --init
cd src
# --target   ,       USB
#  --target   - FST_01 -    ST-LINK v2
# --vidpid="234b:0000"  USB  -
# --enable-factory-reset -       PIN
./configure --target=ST_DONGLE --vidpid="234b:0000" --enable-factory-reset
make

64 , 1.0


git clone https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
cd gnuk
git checkout STABLE-BRANCH-1-0
cd src
#  ,       - OLIMEX_STM32_H103 -   ST-LINK v2
# --enable-keygen -     
./configure --vidpid="234b:0000" --enable-keygen
make

, :


usb_lld.o: In function `usb_lld_set_data_to_recv':
usb_lld.c:(.text.usb_lld_set_data_to_recv+0x0): multiple definition of `usb_lld_set_data_to_recv'
main.o:/mnt/f/DocSasha/devzone/gnuk/src/usb_lld.h:136: first defined here
...

, inline usb_lld.h usb_lld_set_data_to_recv , .


inline- #define make. patch, , , , .


--- a/src/usb_lld.h
+++ b/src/usb_lld.h
@@ -131,10 +131,7 @@ extern void usb_lld_set_feature (uint8_t feature);

 extern void usb_lld_set_data_to_send (const void *p, size_t len);

-extern inline void usb_lld_set_data_to_recv (void *p, size_t len)
-{
-  usb_lld_set_data_to_send ((const void *)p, len);
-}
+#define usb_lld_set_data_to_recv(p, len)  usb_lld_set_data_to_send ((const void *)p, len)

 extern void usb_lld_prepare_shutdown (void);
 extern void usb_lld_shutdown (void);

. cfg , 1.2 src/build/gnuk.elf, 1.0 src/gnuk.elf


#  
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c 'program build/gnuk.elf verify reset exit'
#     
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f1x lock 0" -c reset -c exit

Como tengo todos los procesadores con 64 Kbytes de memoria flash, no pude verificar si el comando stm32f1x lock 1 debería usarse para bloquear el acceso al segundo banco de memoria.


Conclusión


Entonces eso es todo. Me las arreglé. Espero que tengas éxito.


Otros enlaces



All Articles