adding Context to CakeSocket #334

Closed
wants to merge 5 commits into
from

Projects

None yet

3 participants

@pocketcrocodile

#2270 adding Context to CakeSocket and HTTP Socket. Changing CakeSocket

from fsockopen to stream_socket_client allows giving the connection an
context. the default behavior is: if the connection is secure we get
the certificate, parse it and deliver it with the http-response object.

@pocketcrocodile pocketcrocodile #2270 adding Context to CakeSocket
#2270 adding Context to CakeSocket and HTTP Socket. Changing CakeSocket
from fsockopen to stream_socket_client allows giving the connection an
context. the default behavior is: if the connection is secure we get
the certificate, parse it and deliver it with the http-response object.
954ac7f
@pocketcrocodile

#2270 adding Context to CakeSocket and HTTP Socket. Changing CakeSocket
from fsockopen to stream_socket_client allows giving the connection an
context. the default behavior is: if the connection is secure we get
the certificate, parse it and deliver it with the http-response object.

@lorenzo
Member
lorenzo commented Nov 24, 2011

I'm not sure what is this trying to fix. using the CakeSocket class with the ssl:// protocol already works. can you explain this a little bit more?

@pocketcrocodile

of course cake socket works with ssl, but it does not give the context back (esp. the ssl cert for checking if we are communicating with the right server). the change is, we now get the certificate back and deliver it in the resonse object to the application.

@markstory
Member

Shouldn't you be checking for the openssl_x509_export function before trying to use it? Not all installations have openssl installed.

@pocketcrocodile

good point. i'll check this.

@pocketcrocodile

i am getting crazy, but github did not let me update my request.

@markstory
Member

You should be able to push to the original branch you pushed to. Github will automatically update the pull request.

pocketcrocodile added some commits Nov 28, 2011
@pocketcrocodile pocketcrocodile undo last Change 68b3365
@pocketcrocodile pocketcrocodile check openssl
check if openssl is installed by if php know openssl functions.
1516f9a
@pocketcrocodile

don't know why the change did not appear here, but now it does (and also my earlier changes).

@markstory markstory commented on the diff Feb 22, 2012
lib/Cake/Network/Http/HttpSocket.php
+ if ($context !== null && is_array($context) &&!empty($context)){
+ $this->config['request']['context'] = set::merge($this->config['request']['context'], $context);
+ }
+ }
+
+/**
+ * checking Fingerprint and setting Fingerprint to contextarray.
+ *
+ * @param string fingerprint fingerprint the certificate should have
+ * return bool
+ * @access protected
+ */
+
+
+ public function checkFingerprint($fingerprint){
+ if (!isset($this->request['context']['ssl']['peer_certificate']))
@markstory
markstory Feb 22, 2012 CakePHP member

Missing braces.

@markstory markstory commented on the diff Feb 22, 2012
lib/Cake/Network/Http/HttpSocket.php
@@ -373,6 +383,10 @@ public function request($request = array()) {
}
$responseClass = $this->responseClass;
$this->response = new $responseClass($response);
+
+ if (!empty($context) && isset($context['ssl']['peer_certificate']))
@markstory
markstory Feb 22, 2012 CakePHP member

Missing braces.

@markstory markstory commented on the diff Feb 22, 2012
lib/Cake/Network/Http/HttpResponse.php
@@ -419,6 +426,21 @@ public function offsetGet($offset) {
return null;
}
+ public function setContext($context){
+ if (get_resource_type($context) === "OpenSSL X.509" && function_exists(openssl_x509_export)){
+ if (!isset($context))
@markstory
markstory Feb 22, 2012 CakePHP member

Missing braces.

@pocketcrocodile pocketcrocodile added missing branches
added missing branches
edec0bc
@markstory markstory was assigned Oct 29, 2012
@markstory
Member

Closing in favor of #947

@markstory markstory closed this Nov 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment