Skip to content

Instantly share code, notes, and snippets.

@dannycoates
dannycoates / broken.js
Created September 15, 2011 19:27
ssl test
var http = require('http'), // intentionally using http to connect to https
options = {
host: 'localhost',
port: 4443,
path: '/ping',
};
function pingLoop() {
http.get(options, function (res) {
console.assert(false, "server should never accept http over https");
@dannycoates
dannycoates / socket-destroyed.js
Created December 5, 2012 22:06
Of nextTicks and sockets
var http = require('http')
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end('Hello World\n')
}).listen(1337)
var agent = new http.Agent({maxSockets: 1})
agent.on('free', function (socket, host, port) {
@dannycoates
dannycoates / readable-test.js
Created December 17, 2012 06:31
Readable stream test
var fs = require('fs')
var Readable = require('readable-stream')
var readable = new Readable({ bufferSize: 64 })
readable.wrap(fs.createReadStream(__filename))
readable.on(
'readable',
function () {
var data = ''
@dannycoates
dannycoates / node.sh
Last active December 17, 2015 14:08
update the node version on awsbox
#!/usr/bin/env bash
VERSION=$NODE_VERSION
: ${VERSION:="stable"}
echo "installing nave"
git clone git://github.com/isaacs/nave.git
sudo ln -s /home/ec2-user/nave/nave.sh /usr/local/bin/nave
echo "using node" $VERSION
@dannycoates
dannycoates / iptables
Last active December 17, 2015 14:29
awsbox iptables
# Generated by iptables-save v1.4.7 on Thu Apr 5 23:32:48 2012
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [2:120]
:OUTPUT ACCEPT [3:252]
:POSTROUTING ACCEPT [3:252]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
-A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443
COMMIT
# Completed on Thu Apr 5 23:32:48 2012
@dannycoates
dannycoates / hekad.toml
Last active December 17, 2015 23:08
heka statsd
Timestamp: 2013-05-31 11:02:25.780902984 -0700 PDT
Type: statmetric
Hostname: moz.local
Pid: 5267
UUID: 93100895-b5f8-4283-9687-ab4e2eaefd0d
Logger:
Payload: stats.rss 558678016 1370023345
stats.heapTotal 498229248 1370023345
stats.heapUsed 211741608 1370023345
statsd.numStats 3 1370023345
@dannycoates
dannycoates / client.js
Last active December 18, 2015 23:49
SRP test client
var crypto = require('crypto');
var config = require('../lib/config').get('srp');
var srp = require('../lib/srp');
var srpParams = require('../lib/srp_group_params');
var util = require('../lib/util');
var bigint = require('bigint');
var request = require('request');
var alg = config.alg_name;
@dannycoates
dannycoates / api.md
Last active December 19, 2015 12:59

Key Server API

For details of the client/server server protocol and how each parameter is derived see the design.

Our SRP protocol order is slightly different from the sample on wikipedia, but the variables are the same.

Hawk is used to authenticate /sign and

var crypto = require('crypto')
var salt = crypto.randomBytes(32).toString('hex')
var wrapKb = crypto.randomBytes(32).toString('hex')
var Client = require('../client')
var c = new Client('http://localhost:9000')
var email = 'me@example.com'
var password = 'foobar'
// To start a promise chain from a sync function wrap it with P().
// This is short-hand for creating a deferred and immediately resolving it.
function getFiles(pth) {
return P(shell.find(pth))
}
// It's ok to put sync function in a promise chain
function filterFolders(data) {
return data.filter(
function (file) {