Skip to content

Fixes #2 the "got an unexpected keyword argument 'cacert'" #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions postmanproxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from postman.collection_creator_proxy import CollectionCreatorProxy
from postman.header_filter_proxy import HeaderFilterProxy
from libmproxy import controller, proxy
from libmproxy.proxy.server import ProxyServer
import argparse
import signal
import sys
Expand Down Expand Up @@ -41,10 +42,8 @@ def start_creator_proxy(options):
}

collection = Collection(name, path)
config = proxy.ProxyConfig(
cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
)
server = proxy.ProxyServer(config, port)
config = proxy.ProxyConfig(port=port)
server = ProxyServer(config)

if options.tcp_connection == 'false':
tcp_connection = False
Expand All @@ -62,10 +61,8 @@ def start_creator_proxy(options):
def start_filter_proxy(options):
print "Press Ctrl+C to stop the proxy"
port = int(options.port)
config = proxy.ProxyConfig(
cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
)
server = proxy.ProxyServer(config, port)
config = proxy.ProxyConfig(port=port)
server = ProxyServer(config)
m = HeaderFilterProxy(server)
m.run()

Expand Down Expand Up @@ -95,4 +92,4 @@ def main():
start_creator_proxy(args)

if __name__ == "__main__":
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ def save(self):

data = self.get_json()
with open(target, 'w') as outfile:
json.dump(data, outfile)
json.dump(data, outfile)
24 changes: 13 additions & 11 deletions postmanproxy/postman/collection_creator_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def send_to_postman(self, request):
try:
TCP_IP = self.tcp_host
TCP_PORT = self.tcp_port
BUFFER_SIZE = 1024 * 100
BUFFER_SIZE = 1048573
MESSAGE = json.dumps(request.get_json())

print MESSAGE
Expand Down Expand Up @@ -105,12 +105,13 @@ def run(self):
except KeyboardInterrupt:
self.shutdown()

def handle_request(self, msg):
def handle_request(self, flow):
try:
request = Request(self.collection.id)
request.init_from_proxy(msg)
msg = flow.request
request2 = Request(self.collection.id)
request2.init_from_proxy(msg)

print request.headers
print request2.headers
allowed_host = True
allowed_method = True
allowed_status_code = True
Expand All @@ -130,18 +131,19 @@ def handle_request(self, msg):
if allowed_method and allowed_host and allowed_status_code:
print self.rules
if not self.rules['restricted_headers']:
self.remove_restricted_headers(request)
self.remove_restricted_headers(request2)

self.collection.add_request(request)
self.collection.add_request(request2)

if self.tcp_connection:
self.send_to_postman(request)
self.send_to_postman(request2)
print "Sent to Postman"
except Exception as ex:
logging.exception("Something awful happened!")

msg.reply()
flow.reply(flow.response)

def handle_response(self, msg):
def handle_response(self, flow):
print "Sent response"
msg.reply()
flow.reply(flow.response)

6 changes: 4 additions & 2 deletions postmanproxy/postman/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def get_urlencoded_body(self, data, header, method):
return d

def get_name(self, proxy_request):
return proxy_request.path
path = proxy_request.path
name = path[:30]
return name

def get_url(self, proxy_request):
if proxy_request.port == 443:
Expand Down Expand Up @@ -156,4 +158,4 @@ def init_from_proxy(self, proxy_request):
else:
pass
except Exception as ex:
logging.exception("Something awful happened!")
logging.exception("Something awful happened!")