Reputation: 1152
I build a forward proxy server with apache using follow settings:
<VirtualHost *:8088>
ServerAdmin [email protected]
DocumentRoot "E:/test"
ServerName www.test.com
ServerAlias test.com
ErrorLog "logs/test.com-error.log"
CustomLog "logs/test.com-access.log" common
<Directory "E:/test">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ProxyRequests On
ProxyVia Off
ProxyTimeout 10
<Proxy *>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Proxy>
</VirtualHost>
hosts file
127.0.0.1 localhost
Then I use curl to test the proxy server
curl.exe -v https://www.google.com.hk -x localhost:8088
The output
* About to connect() to proxy localhost port 8088 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8088 (#0)
* Establish HTTP proxy tunnel to www.google.com.hk:443
> CONNECT www.google.com.hk:443 HTTP/1.1
> Host: www.google.com.hk:443
> User-Agent: curl/7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.
2.5
> Proxy-Connection: Keep-Alive
>
< HTTP/1.0 200 Connection Established
< Proxy-agent: Apache/2.2.25 (Win32) PHP/5.4.21
<
* Proxy replied OK to CONNECT request
* successfully set certificate verify locations:
* CAfile: D:\curl-ssl\curl-ca-bundle.crt
CApath: none
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.googl
e.com.hk
* start date: 2013-11-20 14:47:22 GMT
* expire date: 2014-03-20 00:00:00 GMT
* subjectAltName: www.google.com.hk matched
* issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.
2.5
> Host: www.google.com.hk
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 05 Dec 2013 02:21:27 GMT
< Expires: -1
< Cache-Control: private, max-age=0
< Content-Type: text/html; charset=Big5
< Set-Cookie: PREF=ID=12cdbbbf43c234b5:FF=0:NW=1:TM=1386210087:LM=1386210087:S=B
HZ4WAj3fqZicDa_; expires=Sat, 05-Dec-2015 02:21:27 GMT; path=/; domain=.google.c
om.hk
< Set-Cookie: NID=67=EvwPZiG49GZO1AMLw7cTY1Azrqzb77uTpCUv9rOECEJh4PRB523yMIJm8L5
OxxWBeq44qM-Dn8xYUijDmBrvXfL504U4_FSunEfG5UUIDveWbHG2BirORx5Jqk9MVFkd; expires=F
ri, 06-Jun-2014 02:21:27 GMT; path=/; domain=.google.com.hk; HttpOnly
< P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/
bin/answer.py?hl=en&answer=151657 for more info."
< Server: gws
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Alternate-Protocol: 443:quic
< Transfer-Encoding: chunked
<
... The google home page HTML ...
I think the https proxying flow is:
send a CONNECT http request to the proxy server
the proxy server forward this CONNECT request to www.google.com.hk:443
www.google.com.hk:443 return a response of 200 Connection Establish to the proxy server
proxy server forward the response to curl
curl begin to send tls handshake datagram (Maybe is encrypted?) to the proxy server
proxy server doesn't know anything about the datagram since the datagram is encrypted, the proxy server just forward this datagram to www.google.com.hk:443 using the socket which it sent the CONNECT request before.
www.google.com.hk:443 send tls handshake datagram encrypted to the proxy server
proxy server forward the encrypted data to curl without decrypting
... after several times handshakes, the handshakes finished and start to send a GET request
curl send a GET request to proxy server , this request datagram is encrypted
proxy server forward the encryted datagram to www.google.com.hk:443 using the socket mentioned above
www.google.com.hk:443 return a encrypted response
proxy server forward the response to curl
curl decrypts the response and show the html
I don't know whether my understanding is right, especially after STEP 3, curl received the 200 CONNECTION ESTABLISHED response.
What I want to know is that what does the proxy server do after receiving the 200 CONNECTION ESTABLISHED response, does the proxy decypts the request datagram?
Upvotes: 3
Views: 9429
Reputation: 46040
HTTPS proxy can CONNECT to any remote resource. If it connects to HTTPS server, it doesn't see 200 response since the response is encrypted.
In general CONNECT verb means "build an opaque tunnel and let me know when it's ready". Point. So the server literally builds a tunnel by connecting to the remote server, and once connection is established the proxy sends positive response to the client. After that the client can send anything to the proxy, the proxy will simply relay the data to the remote server, pick the data coming from the server and send it back to the client.
Such scheme lets one use HTTPS proxy to connect to any type of server and not just HTTP/HTTPS.
Upvotes: 1