Skip to content

Instantly share code, notes, and snippets.

@dannycoates
dannycoates / fptt.js
Created November 6, 2013 23:45
hack the test
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var test = require('tap').test
var log = { trace: function() {} }
var timestamp = Date.now()
// increment timestamp by 500ms each time now is called
function now() { return (timestamp += 500) }
@dannycoates
dannycoates / doc.md
Last active December 27, 2015 03:08
MySQL instructions for FXA testing

MySQL setup

Install MySQL

Mac

Installation is easy with homebrew. I use mariadb which is a fork of mysql but either should work.

brew install mariadb
var cluster = require('cluster')
var Client = require('../../client')
var origin = process.env.PICL_ORIGIN || 'http://127.0.0.1:9000'
var password = 'foobar'
var threads = 50
if (cluster.isMaster) {
@dannycoates
dannycoates / db.js
Created October 24, 2013 21:38
abstract db interface
/*/
# Notes
All endpoints that use HAWK require tokens and the token must be read from the
db to validate the request. Ideally all data required for an endpoint to do it's
job can be read in the same db call.
Different db implementations will have different data layouts. For example, SQL
may use a join to get the keys for a keyFetchToken, while Cassandra will store
@dannycoates
dannycoates / log.js
Created August 31, 2013 18:31
logging with domains
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var Domain = require('domain')
var inherits = require('util').inherits
var Logger = require('bunyan')
function Overdrive(options) {
Logger.call(this, options)
@dannycoates
dannycoates / test.js
Created August 20, 2013 20:40
simplesmtp _onData bug
var smtp = require('simplesmtp')
var net = require('net')
var server = net.createServer(
function (c) {
console.log('connected')
c.write('220 127.0.0.1\r\n')
c.on('data',
function (data) {
console.log(data.toString())
// 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) {
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 = '[email protected]'
var password = 'foobar'
@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

@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;