For educational reasons I've decided to create my own CA. Here is what I learned.
Lets get some context first.
| # Procedure is for Archlinux. | |
| # Using these guides: | |
| # http://datacenteroverlords.com/2012/03/01/creating-your-own-ssl-certificate-authority/ | |
| # https://turboflash.wordpress.com/2009/06/23/curl-adding-installing-trusting-new-self-signed-certificate/ | |
| # https://jamielinux.com/articles/2013/08/act-as-your-own-certificate-authority/ | |
| # Generate the root (GIVE IT A PASSWORD IF YOU'RE NOT AUTOMATING SIGNING!): | |
| openssl genrsa -aes256 -out ca.key 2048 | |
| openssl req -new -x509 -days 7300 -key ca.key -sha256 -extensions v3_ca -out ca.crt |
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
| Latency Comparison Numbers | |
| -------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| begin; | |
| create extension pgtap; | |
| create table users( | |
| username text primary key, | |
| email text not null, | |
| firstname text, | |
| lastname text | |
| ); |
| upstream myapp { | |
| server 127.0.0.1:8081; | |
| } | |
| limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s; | |
| server { | |
| listen 443 ssl spdy; | |
| server_name _; | |
| CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french ); | |
| ALTER TEXT SEARCH CONFIGURATION fr ALTER MAPPING | |
| FOR hword, hword_part, word WITH unaccent, french_stem; | |
| CREATE TEXT SEARCH CONFIGURATION en ( COPY = english ); | |
| ALTER TEXT SEARCH CONFIGURATION en ALTER MAPPING | |
| FOR hword, hword_part, word WITH unaccent, english_stem; | |
| CREATE TEXT SEARCH CONFIGURATION de ( COPY = german ); | |
| ALTER TEXT SEARCH CONFIGURATION de ALTER MAPPING |
| #------------------------------------------------------------------------------ | |
| # ERROR REPORTING AND LOGGING | |
| #------------------------------------------------------------------------------ | |
| # - Where to Log - | |
| log_destination = 'csvlog' # Valid values are combinations of | |
| # stderr, csvlog, syslog, and eventlog, | |
| # depending on platform. csvlog | |
| # requires logging_collector to be on. |
| package org.yourcompany.test; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.SortedSet; | |
| import javax.sql.DataSource; |
| Bacon = require('baconjs') | |
| Imm = require('immutable') | |
| React = require('react') | |
| window.Actions = | |
| changeFirstName: new Bacon.Bus() | |
| changeLastName: new Bacon.Bus() | |
| changeCountry: new Bacon.Bus() | |
| addCountryBird: new Bacon.Bus() | |
| addFriend: new Bacon.Bus() |