Skip to content

Instantly share code, notes, and snippets.

🌴
Working from home

Adi Roiban adiroiban

🌴
Working from home
View GitHub Profile
@adiroiban
adiroiban / esmtp.py
Last active Nov 26, 2017
Twisted Mail SMTPConnectError strange behaviour
View esmtp.py
# Copyright (c) 2015 Adi Roiban.
# MIT License
"""
(E)SMTP high level client.
"""
from email.header import Header
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formataddr, formatdate, make_msgid
@adiroiban
adiroiban / urllib_quote.py
Created Oct 11, 2017
Urllib quote strange behaviour
View urllib_quote.py
(Pdb) result
u'/ci-test-site/Shared Documents/v2/no such+\u2603'
(Pdb) urllib.quote(result.encode('utf-8'), safe=b'/+')
*** UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 42: ordinal not in range(128)
(Pdb) urllib.quote(result.encode('utf-8'), safe=b'+/')
'/ci-test-site/Shared%20Documents/v2/no%20such+%E2%98%83'
(Pdb) urllib.quote(result.encode('utf-8'), safe=b'/')
@adiroiban
adiroiban / twisted_proxy_connect.py
Last active Oct 10, 2017
Twisted HTTP Connect Proxy
View twisted_proxy_connect.py
"""
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 Oct 6, 2017
Simple test for pyOpenSSL with SNI
View ssl_sni_client.py
# 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 Sep 22, 2017
ldaptor LDAP server faking AD UPN BIND
View ldaptor_as_ad_server.py
"""
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
View bashrc
# 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
pyopenssl SSLContext.set_verify callback for CRL / CDP validation
View crl_cdp_validator.py
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 Jan 31, 2019
Persistent pool not closed in Twisted
View example run
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 Aug 12, 2016
Twisted support for parsing multipart/form-data POST requests
View form.py
# 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
You can’t perform that action at this time.