Skip to content

Instantly share code, notes, and snippets.

@jcleveley-zz
Last active October 20, 2015 14:27
Show Gist options
  • Save jcleveley-zz/d4fa9a9239b33efaafe4 to your computer and use it in GitHub Desktop.
Save jcleveley-zz/d4fa9a9239b33efaafe4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage:
# ./charles.sh on
# ./charles.sh off
# sed needs write permissions to the parent folder to create temp file
sudo chmod -R 777 /usr/share/php/Zend/Http/Client/Adapter
sudo chmod -R 777 /usr/share/php/BBC/Http/Multi/Client/Adapter/
if [ $1 = "on" ]; then
charles_ip=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10)
echo "Adding Charles proxy to Curl & Multi Curl adapters, IP set to $charles_ip"
charles_proxy="\$ch = isset(\$curlHandle) ? \$curlHandle : \$this->_curl;curl_setopt(\$ch, CURLOPT_PROXY, '"$charles_ip"'); curl_setopt(\$ch, CURLOPT_PROXYPORT, 8888); curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, 0);//charles"
sed -i "/curl_exec/i\ $charles_proxy" /usr/share/php/Zend/Http/Client/Adapter/Curl.php
sed -i "/setResource/i\ $charles_proxy" /usr/share/php/BBC/Http/Multi/Client/Adapter/CurlMulti.php
else
echo "Removing Charles Proxy"
sed -i '/charles/d' /usr/share/php/Zend/Http/Client/Adapter/Curl.php
sed -i '/charles/d' /usr/share/php/BBC/Http/Multi/Client/Adapter/CurlMulti.php
fi
@jcleveley-zz
Copy link
Author

If you get Handshake alert: unrecognized_name error for SSL calls:

sudo vi /Applications/Charles.app/Contents/Info.plist
Within JVMOptions add:
-Djsse.enableSNIExtension=false

from: http://stackoverflow.com/questions/15725118/handshake-alert-unrecognized-name-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment