Close
0%
0%

TurtleAuth: The DIY gpg usb key

Let's make a DIY gpg usb key

Similar projects worth following

Some of you may know that you can use yubikey's as a gpg smart card for message encryption / ssh login however starting at $45 for a compatible one I didn't really like that, so I searched a bit around and found a project by danman creating such token with a St link V2 (the stm32/8 programmer) after looking a bit I found out that there is the gnuk project that implements just that on a stm32f103.

BOM_Stm32GPG_2020-06-08_03-15-35.csv

BOM For the pcb

ms-excel - 4.01 kB - 06/08/2020 at 13:02

Download

  • Making it look cooler

    Samuel06/08/2020 at 12:58 0 comments

    So I decided to improve my by design and soldering skill by only choosing 0603 sized components (Which is retrospect a size that I won't go further unless I get a magnifying glass or a microscope).

    I wanted to have to boards one on top of each other to clean up the design and make it appear less "hacky" and I recently discovered the TTP223E Touch control ic, so I don't wanted to use a typical pushbutton to validate the access. So I basically cloned the blue pill design and added the ic:

    I replaced the BOOT0/1 header with tiny pads that you solder to change the position, the USB connector to a USB A male one , I also tried to solder a metal dome for the reset button but that was a TOTAL failure of course I chose LCSC as my component provider (Partly for the shipping discount when you order via JLCPCB) and here is the BOM list the PCB design was by far the most challenging one that I did since I tried to do my best to reduce the board size (which cause me some problem during assembly later) at the end I submitted a panelized version of this board:

    The bottom and top board are connected to allow me to test everything without the top board being in the way. After finally receiving my PCB from JLCPCB I snapped on board out and started soldering 

    And you can probably see the big mistake that I made, the USB is too far in and interferes with the board (I should really get the real 3d Model) a bit of surgery fixes that. As it turns out gunk doesn't need the 32.768kHz oscillator, so I didn't solder it but left the pads in if I ever want to repurpose the board in the future. After a painful soldering session this was the result and I'm very happy with it:

  • Testing the concept

    Samuel06/08/2020 at 12:53 0 comments

    I, next found that there is another gpg key called the Nitro Key which is cheaper but still a bit pricey. As I already had some Blue pills (stm32f103 devboard) lying around I decided to test it.

    I started by finding the source code of gnuk (and the sub module chopstx) which was more difficult than I thought (Some git services were shut down), upon finding the source on GitLab I cloned it on my GitHub (https://github.com/TheStaticTurtle/gnuk https://github.com/TheStaticTurtle/chopstx/).

    I named my project TurtleAuth, so I started by just using the same config as the ST_DONGLE target since I don't plan on changing the MCU and the officials ones are based on the stm32f103c8 (clones are often the stm32f101 which doesn't officially have "USB capabilities" but can be used anyway somehow). I proceed by creating my own board definition (chopstx/board/turtle-auth.h) and adding / changing configuration like the led pin which I set to PA13 (On board led on the bluepill) and configuring a button on PA8 in pull up

    /*
     * Port A setup.
     * PA11 - Push Pull output 10MHz 0 default (until USB enabled) (USBDM)
     * PA12 - Push Pull output 10MHz 0 default (until USB enabled) (USBDP)
     *
     * Port C setup.
     * PC13 - Push pull output 50MHz (LED 1:ON 0:OFF)
     * ------------------------ Default
     * PAx  - input with pull-up
     * PCx  - input with pull-up
     */
    #define VAL_GPIO_USB_ODR            0xFFFFE6FF
    #define VAL_GPIO_USB_CRL            0x88888888      /*  PA7...PA0 */
    #define VAL_GPIO_USB_CRH            0x88811888      /* PA15...PA8 */
    
    #define VAL_GPIO_OTHER_ODR          VAL_GPIO_USB_ODR
    #define VAL_GPIO_OTHER_CRL          VAL_GPIO_USB_CRL
    #define VAL_GPIO_OTHER_CRH          VAL_GPIO_USB_CRH
    
    #define VAL_GPIO_LED_ODR            0xFFFFFFFF
    #define VAL_GPIO_LED_CRL            0x88888888      /*  PC7...PC0 */
    #define VAL_GPIO_LED_CRH            0x88388888      /* PC15...PC8 */

    The button will still not work with this code I still had to add it the gnuk / chopstx source code. First I need to add a new function in chopstx to wait until the button has been pressed. I set it up to blink the led  every 100ms and break out of the loop if the button goes high (I have a 10k pull down resistor on the button)

    void wait_button() {
        #if defined(GPIO_BUTTON_PIN)
            while (1){
                set_led(1);
                wait(1000000);
                if( (GPIO_OTHER->IDR & (1 << GPIO_BUTTON_PIN)) ) break;
    
                set_led(0);
                wait(1000000);
                if( (GPIO_OTHER->IDR & (1 << GPIO_BUTTON_PIN)) ) break;
            }
        #endif
    }

    Next I added the wait button function in the openpgp.c file at line 936 and 1144

    #ifdef CONFIRM_BUTTON_SUPPORT
      wait_button();
    #endif

    (https://github.com/TheStaticTurtle/gnuk/search?q=wait_button&unscoped_q=wait_button)

    and added the CONFIRM_BUTTON_SUPPORT option to the command line arguments (https://github.com/TheStaticTurtle/gnuk/search?q=CONFIRM_BUTTON_SUPPORT&unscoped_q=CONFIRM_BUTTON_SUPPORT)

    Since I didn't have any experience programming and stm32 outside the Arduino environment I followed danman guide to build and transfer the program.

    I started by creating a config for OpenOCD (Debugger / Programmer) and setting up to use a st link V2 to flash the software.

    #daemon configuration
    telnet_port 4444
    gdb_port 3333
    
    #interface
    interface hla
    hla_layout stlink
    hla_device_desc "ST-LINK/V2"
    hla_vid_pid 0x0483 0x3748
    ...
    Read more »

View all 2 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates