Skip to content

Instantly share code, notes, and snippets.

View sowbug's full-sized avatar

Mike Tsao sowbug

View GitHub Profile
@sowbug
sowbug / gnuk-on-stlinkv2.sh
Last active August 14, 2023 18:15
Gnuk on ST-Link v2
# https://github.com/cabo/stlink
# https://blog.danman.eu/2-usb-crypto-token-for-use-with-gpg-and-ssh/
sudo ./upgrade_by_passwd.py -f ../regnual/regnual.bin ../src/build/gnuk-vidpid.bin
sudo st-flash erase && st-flash --reset write ~/src/gnuk/src/build/gnuk-vidpid.bin 0x08000000
-- or --
~/src/stlink/build/Debug/st-flash reset && \
~/src/stlink/build/Debug/st-flash erase && \
# Thanks https://lists.gnupg.org/pipermail/gnupg-users/2016-May/055985.html
#
# To specify the passphrase on the command line:
#
# gpg --pinentry-mode loopback --passphrase "secret" --batch --generate-key x25519-gen.gpgbatch
%echo Generating ed25519 primary and cv25519 subkey
Key-Type: eddsa
Key-Curve: Ed25519
Key-Usage: sign
@sowbug
sowbug / openpgp-bitlength-mismatch.go
Created January 17, 2018 06:29
Demo code showing problem with GnuPG keys generated in golang.org/x/crypto/openpgp
// some of this was adapted from https://gist.github.com/eliquious/9e96017f47d9bd43cdf9
func (sg SecretGenerator) GetPGPKey(passphrase string) string {
var config packet.Config
config.Time = func() time.Time {
return time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC)
}
uid := packet.NewUserId(sg.GetFriendlyName("main"), "", "")
if uid == nil {
#!/usr/bin/python
import subprocess
SOURCES = [
('npth', 'npth-1.5'),
('ntbtls', 'ntbtls-0.1.2'),
('libgpg-error', 'libgpg-error-1.27'),
('libassuan', 'libassuan-2.5.1'),
('libgcrypt', 'libgcrypt-1.8.2'),
@sowbug
sowbug / bitcoin-esp32.ino
Last active July 13, 2022 11:39
Display Bitcoin prices on a $10 OLED ticker
//
// For Wemos Lolin ESP32 OLED Module For Arduino ESP32 OLED WiFi + Bluetooth
//
// All of these are available in Arduino Library Manager
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <SSD1306.h>
#include <WiFiMulti.h>
@sowbug
sowbug / auto_download_microbit.py
Created January 1, 2018 19:24
Automatically moves BBC micro:bit files from the browser to the device
# usage:
#
# auto_download_microbit.py dir_to_watch dir_of_microbit
import os.path, shutil, sys, time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
src = sys.argv[1] if len(sys.argv) > 1 else '.'
dst = sys.argv[2] if len(sys.argv) > 2 else '/Volumes/MICROBIT/'
@sowbug
sowbug / gce_server.py
Created December 25, 2017 23:44
A script that you can wrap with helper scripts to make it easier for your kids to start up the Minecraft server on their own.
#!/usr/bin/env python
# sudo pip install --upgrade google-api-python-client
from apiclient.discovery import build
from oauth2client import client, GOOGLE_TOKEN_URI
import argparse
import httplib2
import sys
@sowbug
sowbug / generate_refresh_token.py
Created December 25, 2017 23:34
Given a Google APIs Client ID and Client secret, get back a refresh token for Compute Engine
#!/usr/bin/env python
"""Generates refresh token for Google API."""
# This is adapted from generate_refresh_token.py in
# https://github.com/googleads/googleads-python-lib
import argparse
import sys
from oauth2client import client, GOOGLE_TOKEN_URI
@sowbug
sowbug / gist:5628ab9cd4a21c39808bf1d7113ef1f1
Created November 5, 2017 05:11
Generate 128-bit base58 passphrase from shell without dependencies
$ cat /dev/urandom | base64 | tr -cd [:alnum:] | tr -d [0OIl] | head -c 22
# same but emit QR code
$ cat /dev/urandom | base64 | tr -cd [:alnum:] | tr -d [0OIl] | head -c 22 | qr
@sowbug
sowbug / gist:c7f83140581fbe3e6a9b3ddf24891e77
Last active January 25, 2023 09:22
Making an encrypted DVD image
# All the code from http://billauer.co.il/blog/2010/10/encrypted-iso-dvd-luks-dm-crypt-fedora-linux/
MB_COUNT=100
VOL_NAME=MyVolName
DIR_TO_COPY=/tmp/mydir
# Make a 100MB disk image
dd if=/dev/zero of=disk.img bs=1M count=$MB_COUNT
# become root