Skip to content

Instantly share code, notes, and snippets.

View public's full-sized avatar
🏠
Working from home

Alex Stapleton public

🏠
Working from home
View GitHub Profile
import cryptography.hazmat.backends
b = cryptography.hazmat.backends.default_backend()
print "%x" % b.lib.OPENSSL_VERSION_NUMBER
print b.lib.EVP_get_cipherbyname("aes-128-gcm")
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py
index 6231aad..ea43e30 100644
--- a/cryptography/hazmat/backends/openssl/backend.py
+++ b/cryptography/hazmat/backends/openssl/backend.py
@@ -154,7 +154,7 @@ class Backend(object):
@public
public / crypto_locking.py
Last active January 1, 2016 10:39
Implement the OpenSSL locking callback in Python. It seems to work but is ~4x slower on PyPy and ~8x slower in CPython than using the C implementation from Modules/_ssl.py.
import thread
import threading
import itertools
import cryptography.hazmat.backends
b = cryptography.hazmat.backends.default_backend()
# UNCOMMENT THIS TO POSSIBLY STOP CRASHES
#import _ssl
@public
public / crypto_thread_crash.py
Created December 24, 2013 15:00
Crashes quickly on my Ubuntu machine when _ssl is not imported and there at least 3 threads. Reducing threads or importing _ssl seems to work around the race. _ssl happens to setup locking callbacks OpenSSL wants to do multi-threading safely. I think this will still crash if we import a different OpenSSL to the one the Python implementation is l…
import thread
import threading
import struct
import itertools
import cryptography.hazmat.backends
# UNCOMMENT THIS TO POSSIBLY STOP CRASHES
#import _ssl
cryptography/hazmat/backends/openssl/__pycache__/_cffi__xff7f7876x43e58bcb.c:4056:17: error: storage size of ‘x0’ isn’t known
import cffi
isdefined_template = """
#include <openssl/opensslconf.h>
char cryptography_isdefined_{0}() {{
#ifdef {0}
return 1;
#else
return 0;
@public
public / breach.py
Last active December 21, 2015 16:49
Ghetto BREACH attack against itsdangerous cookies. This is kind of like attacking an itsdangerous cookie over a TLS connection using a stream cipher. Just uses the lengths of the cookies to determine the contents of a secret value. Things rapidly get more complicated in more realistic situations. e.g. if the cookie is more complex its hard to pi…
import os
from binascii import hexlify
import json
import itsdangerous
import random
secret = hexlify(os.urandom(160/8))
#secret = "4e0f4e0bbd859501d57460168babbe9bda0f9e77"
serializer = itsdangerous.URLSafeSerializer("SECRET")
session = {
@public
public / wut
Created August 21, 2013 22:26
People who probably package python modules that no one uses
home@alex:~$ awk '/ 1$/{print $1}' < numdeps | xargs apt-cache show | grep Original-Maintainer | sort | uniq -c | sort -k1 -n
1 Original-Maintainer: "Adam C. Powell, IV" <[email protected]>
1 Original-Maintainer: Adam C. Powell, IV <[email protected]>
1 Original-Maintainer: Adam Schmalhofer <[email protected]>
1 Original-Maintainer: Aleksey Kravchenko <[email protected]>
1 Original-Maintainer: Alexandre Fayolle <[email protected]>
1 Original-Maintainer: Al Stone <[email protected]>
1 Original-Maintainer: A Mennucc1 <[email protected]>
1 Original-Maintainer: Ana Beatriz Guerrero Lopez <[email protected]>
1 Original-Maintainer: Andrea Gasparini <[email protected]>
@public
public / virt-ip.sh
Created August 1, 2013 09:14
Get the IP address of the named running KVM VM. ./virt-ip.sh YOUR-VM
#!/bin/sh
grep $(virsh domiflist $1 | grep -vE '^((.)\2*)?$' | awk 'NR == 1 { for(i=1; i <= NF; i++) { if($i == "MAC") { MAC=i } } } NR > 1 { print $MAC }') /var/lib/libvirt/dnsmasq/default.leases | cut -d\ -f3
import Data.List
import Math.NumberTheory.Primes.Sieve
import Control.Monad
import Debug.Trace
numWays without p =
let (poor, rich) = splitAt p without
with = poor ++
def block(func, args):
def decorator(f2):
return func(f2, args)
return decorator
@block(map, range(10))
def square(x):
return x**2