Skip to content

Instantly share code, notes, and snippets.

@cagerton
cagerton / 0upgrade.md
Last active May 12, 2021 23:36
On storing password hashes

Upgrade sha1 => scrypt without user logging in/pw reset:

μBackground:

We hash passwords with one-way hash functions to reduce the impact of password database compromise. Passwords hashed with salted SHA or MD5 can ofen be brute forced. Newer password hashhing techniques like Scrypt/Bcrypt/PBKDF2 add computational work to make brute forcing prohibitively expensive.

Problem:

Your service already has users with salted sha1 password hashes. Since you don't have their original passwords you can't upgrade to a modern password hash without getting each user to log in and enter their password.

You have (salt,sha(salt+password)), you want (salt, scrypt(salt,password))

@cagerton
cagerton / diff.ts
Created September 24, 2020 02:01
Git based diff utility for NodeJS
import {join} from 'path';
import fs from "fs";
import os from "os";
import {spawnSync} from "child_process";
/**
* Use the local `git` executable to render a diff between two strings.
* This is intended for test/development environments. Consider using
* `jsdiff` if you need to compare potentially malicious strings.
*/
@cagerton
cagerton / README.md
Created June 10, 2020 08:04
Test Certificate Generator

TinyCA

This is handy for genrating transient keys and certificates used for unit tests.

Notable files generated by running tinyca.sh:

  • ca.pem - This is the root CA which should be added to the test client's trust store.
  • server.key - This is your server's secret key.
  • server.pem - This is your server's certificate, good for example.com and *.example.com.
  • expired.pem - This is an expired version of the server certificate.
  • ca - This directory contains the ca secrets and internals.
@cagerton
cagerton / yolo_redis.ts
Created January 27, 2020 03:08
Redis cluster demo example
import {spawn} from 'child_process';
import fs from 'fs';
import os from 'os';
function mkConfigs(port: number) {
return `
bind 127.0.0.1
port ${port}
cluster-enabled yes
cluster-config-file nodes-${port}.conf
@cagerton
cagerton / no_push_f_master.rb
Last active January 11, 2020 22:53
pre receive hook
#!/usr/bin/env ruby
# pre-receive hook to block 'push -f' on master
# For Phabricator, save this as:
# $REPO/hooks/pre-receive-phabricator.d/no_push_f_master.rb
# Remember to chmod +x
# Ref: http://git-scm.com/book/en/Customizing-Git-An-Example-Git-Enforced-Policy
args = STDIN.readline.chomp.split(" ")
$oldrev, $newrev, $refspec = args
@cagerton
cagerton / colorfade.py
Created May 15, 2019 05:23
Simple example for using udmx to control a monoprice rgbaw-uv dmx light
"""
Simple rgb color fade tested with the monoprice rgbawuv
Requires python3.7 for the async coroutine syntax; should be trivial to backport though
Requires:
libusb==1.0.22b4
numpy==1.16.3
pyusb==1.0.2
scikit-image==0.15.0
@cagerton
cagerton / edge_detect.java
Created May 15, 2011 20:25
Edge detection in Processing
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
PImage input, output;
void setup() {
int width=400;
int height=300;
size(width,height);
output = createImage(width,height,RGB);
@cagerton
cagerton / hijack_touch.js
Created December 13, 2013 18:21
Generate click events on touchstart; kill the mouse events that the browser cooks 200+ms afterwards.
(function touchJack(){
var lastTouch = 0;
document.addEventListener("touchstart", function(e){
lastTouch = Date.now();
var touch = e.touches[0],
synth_event = document.createEvent("MouseEvents");
synth_event.fab=true;
synth_event.initMouseEvent("click", true, true, window,
0, touch.screenX, touch.screenY, touch.clientX, touch.clientY,
#!yaml
#
# Postgres 9.3 packages salt state
#
# Created 9/9/13
#
# author: Micah Hausler, micah.hausler@akimbo.io
postgres-pkgs:
pkg:
@cagerton
cagerton / 0.check_keys.py_example.md
Last active December 25, 2015 00:59
Little python3.3 script to show information about ssh public keys from key files or known_hosts files.

SSH key info for pubkeys, known_hosts, and github users

Usage:
  check_keys.py hosts [<FILE>]
  check_keys.py key [<FILE>...]
  check_keys.py github <user>


$ check_hosts.py github cagerton
[