Skip to content

Instantly share code, notes, and snippets.

View Lukasa's full-sized avatar

Cory Benfield Lukasa

View GitHub Profile
@Lukasa
Lukasa / timeout.py
Created April 1, 2014 08:18
Example of setting global timeout in requests.
from requests.adapters import HTTPAdapter
class TimeoutAdapter(HTTPAdapter):
def send(self, *args, **kwargs):
kwargs.setdefault('timeout', 30)
super(TimeoutAdapter, self).send(*args, **kwargs)
@Lukasa
Lukasa / history.log
Created June 20, 2014 13:41
Apt history
Start-Date: 2014-06-20 14:36:56
Commandline: apt-get install openssh-server
Install: ncurses-term:amd64 (5.9+20140118-1ubuntu1, automatic), python-urllib3:amd64 (1.7.1-1build1, automatic), openssh-server:amd64 (6.6p1-2ubuntu2), openssh-sftp-server:amd64 (6.6p1-2ubuntu2, automatic), ssh-import-id:amd64 (3.21-0ubuntu1, automatic), python-requests:amd64 (2.2.1-1, automatic), libck-connector0:amd64 (0.4.5-3.1ubuntu2, automatic), libwrap0:amd64 (7.6.q-25, automatic), tcpd:amd64 (7.6.q-25, automatic)
End-Date: 2014-06-20 14:37:01
@Lukasa
Lukasa / explanation.md
Last active August 29, 2015 14:05
Example of hyper code demonstrating incorrect response from Google

Google's server is providing an incorrect pseudo-header field. Their response contains the pseudo-header field ':status' with the value '302 Found', in violation of the draft. The relevant section is Section 8.1.2.4 of the h2-14 draft, which reads:

A single ":status" header field is defined that carries the HTTP status code field (see [RFC7231], Section 6). This header field MUST be included in all responses, otherwise the response is malformed (Section 8.1.2.6).

HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.

@Lukasa
Lukasa / fingerprinting.py
Created March 3, 2015 20:48
Example of how to do certificate fingerprinting with cryptography
# Needed for boring connection logic
import ssl
import socket
# Needed for the cert work
from binascii import hexlify
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
@Lukasa
Lukasa / netlink_ifnew.py
Created March 4, 2015 09:26
Monitor for new links using Python and Netlink
@Lukasa
Lukasa / headermap.py
Last active August 29, 2015 14:16
A prototype Python header mapping.
import collections
class HTTPHeaderMap(collections.MutableMapping):
"""
A structure that contains HTTP headers.
HTTP headers are a curious beast. At the surface level they look roughly
like a name-value set, but in practice they have many variations that
make them tricky:
@Lukasa
Lukasa / headerprofile.py
Created March 8, 2015 08:10
Profiles various header mappings.
import time
from hyper.common.headers import HTTPHeaderMap
from urllib3._collections import HTTPHeaderDict
def timeit(method):
def timed(*args, **kw):
ts = time.clock()
for _ in range(10000):
result = method(*args, **kw)
@Lukasa
Lukasa / requirements.txt
Created April 14, 2015 12:27
Twisted HTTP/2 spike
Twisted==15.1.0
hpack==1.0.0
hyperframe==1.0.0
@Lukasa
Lukasa / old_certs.pem
Created April 23, 2015 18:42
expired certificates
# Issuer: CN=Entrust.net Secure Server Certification Authority O=Entrust.net OU=www.entrust.net/CPS incorp. by ref. (limits liab.)/(c) 1999 Entrust.net Limited
# Subject: CN=Entrust.net Secure Server Certification Authority O=Entrust.net OU=www.entrust.net/CPS incorp. by ref. (limits liab.)/(c) 1999 Entrust.net Limited
# Label: "Entrust.net Secure Server CA"
# Serial: 927650371
# MD5 Fingerprint: df:f2:80:73:cc:f1:e6:61:73:fc:f5:42:e9:c5:7c:ee
# SHA1 Fingerprint: 99:a6:9b:e6:1a:fe:88:6b:4d:2b:82:00:7c:b8:54:fc:31:7e:15:39
# SHA256 Fingerprint: 62:f2:40:27:8c:56:4c:4d:d8:bf:7d:9d:4f:6f:36:6e:a8:94:d2:2f:5f:34:d9:89:a9:83:ac:ec:2f:ff:ed:50
# Issuer: CN=http://www.valicert.com/ O=ValiCert, Inc. OU=ValiCert Class 2 Policy Validation Authority
# Subject: CN=http://www.valicert.com/ O=ValiCert, Inc. OU=ValiCert Class 2 Policy Validation Authority
@Lukasa
Lukasa / README.md
Created June 1, 2015 13:42
Basic Twisted HTTP/2 client.

Simple Twisted H2 Client

This gist contains a really stupid implementation of a Twisted HTTP/2 client. It opens a connection, uses ALPN/NPN to negotiate HTTP/2, and then sends a single HTTP/2 GET request to the /ip endpoint.

To execute this:

  1. Create a clean virtual environment.
  2. Install the requirements: pip install -r requirements.txt.
  3. Install the development version of Twisted that contains the nextProtocols code.
  4. Execute the code using python h2test.py.