Skip to content

Instantly share code, notes, and snippets.

View adiroiban's full-sized avatar
🇺🇦
Slava Ukraini!

Adi Roiban adiroiban

🇺🇦
Slava Ukraini!
  • VGR, La Gomera
  • 02:07 (UTC +01:00)
View GitHub Profile
@adiroiban
adiroiban / twisted_proxy_connect.py
Last active October 10, 2017 23:10
Twisted HTTP Connect Proxy
"""
Based on the code from Scrapy
BSD-3-Clause
"""
from __future__ import absolute_import, unicode_literals
import re
from urlparse import urlparse
from twisted.internet import defer
@adiroiban
adiroiban / ssl_sni_client.py
Created October 6, 2017 10:47
Simple test for pyOpenSSL with SNI
# Copyright (C) Jean-Paul Calderone
# See LICENSE for details.
from sys import argv, stdout
from socket import socket
from OpenSSL.SSL import TLSv1_METHOD, Context, Connection
def test_ssl_client_sni():
@adiroiban
adiroiban / ldaptor_as_ad_server.py
Created September 22, 2017 16:35
ldaptor LDAP server faking AD UPN BIND
"""
An ldaptor LDAP server which can authenticate based on UPN, as AD does.
The LDAP entry needs to have the `userPrincipalName` attribute set.
"""
from __future__ import absolute_import
from ldaptor import interfaces
from ldaptor.protocols import pureldap
from ldaptor.protocols.ldap import distinguishedname, ldaperrors
0x3d0ceF43945Ff0aB47403db22bf53d118d2d0990
@adiroiban
adiroiban / bashrc
Created June 21, 2017 16:45
Bash Prompt
# based on the prompt from
# http://www.gilesorr.com/bashprompt/prompts/twtty.html
function prompt_command {
TERMWIDTH=${COLUMNS}
# Calculate the width of the prompt:
hostnam=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
# "whoami" and "pwd" include a trailing newline
#usernam=$(whoami)
@adiroiban
adiroiban / crl_cdp_validator.py
Last active May 19, 2017 17:23
pyopenssl SSLContext.set_verify callback for CRL / CDP validation
class CRLValidator(object):
"""
Helper for validating certificates against CRL.
For now it only support a single CRL signed by a single CA.
It provides the `CRLValidator.validate(certificate)` method which can be
used as a callback for `SSLContext.set_verify`.
"""
_random = random
@adiroiban
adiroiban / example run
Last active January 31, 2019 11:51
Persistent pool not closed in Twisted
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
>>> import cryptography
>>> import OpenSSL
>>> cryptography.__version__
'1.7.2'
>>> OpenSSL.__version__
'16.2.0'
>>>
@adiroiban
adiroiban / form.py
Last active October 21, 2020 13:42
Twisted support for parsing multipart/form-data POST requests
# Copyright (c) 2014 Adi Roiban.
# See LICENSE for details.
"""
Code for handling data submitted via HTTP form.
We should try to keep this code independent of Chevah project as we plan
to send it upstream in Twisted.
"""
from StringIO import StringIO
@adiroiban
adiroiban / endpoint_client_server.py
Last active August 11, 2016 13:41
Client TLS transport connected state out of sync
#
# Script to demonstrate the Client.transport.connected state
#
from twisted.internet.protocol import Protocol
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import SSL4ServerEndpoint, TCP4ServerEndpoint
from twisted.internet.endpoints import (
SSL4ClientEndpoint, TCP4ClientEndpoint, connectProtocol)
from twisted.internet import reactor
from twisted.internet.ssl import PrivateCertificate, ClientContextFactory
@adiroiban
adiroiban / twisted.diff
Created July 19, 2016 13:09
pydoctor for twisted no fetch
diff --git twisted/python/_pydoctor.py twisted/python/_pydoctor.py
index 76a5458..4d064b4 100644
--- twisted/python/_pydoctor.py
+++ twisted/python/_pydoctor.py
@@ -60,6 +60,13 @@ class TwistedSphinxInventory(SphinxInventory):
# as an exceptional case.
# We get the base URL from IInterface which is assume that is
# always and already well defined in the Sphinx index.
+ link = self._links.get('zope.interface.interfaces.IInterface')
+