Skip to content
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

stomp+ssl #34

Open
josecelano opened this issue Feb 5, 2015 · 6 comments
Open

stomp+ssl #34

josecelano opened this issue Feb 5, 2015 · 6 comments

Comments

@josecelano
Copy link

I am trying to connect to stomp over ssl and I get this error

SSL/TLS handshake failed

My sample:

<?php

echo "stomb test";

$queue  = '/queue/foo';
$msg    = 'bar';

$user = 'admin';
$pwd = 'XXXXX';

/* connection */
try {
    $stomp = new Stomp('ssl://XXX.XXX.XX.XXX:61612', $user, $pwd);
} catch(StompException $e) {
    //var_dump($stomp->error());
    die('Connection failed: ' . $e->getMessage());
}

/* send a message to the queue 'foo' */
$stomp->send($queue, $msg);

/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);

/* read a frame */
$frame = $stomp->readFrame();

if ($frame->body === $msg) {

    var_dump($frame);

    // acknowledge that the frame was received
    $stomp->ack($frame);
}

/* close connection */
unset($stomp);

And my activemq.xml config file:

    <sslContext>
        <sslContext 
              keyStore="file:${activemq.base}/conf/broker.ks" 
              keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts" 
              trustStorePassword="password"/>
    </sslContext>

Server is up and accepting stomp connections.

This is the ActiveMQ guide to use stomp+ssl
http://activemq.apache.org/how-do-i-use-ssl.html

I suppose:

  • I have to create two certificates for broker and client.
  • Restart ActiveMQ.
  • And configure PHP client to use server certificate, something like this:
$context = stream_context_create(); 
$result = stream_context_set_option($context, 'ssl', 'local_cert', '/path/to/keys.pem'); 
$result = stream_context_set_option($context, 'ssl', 'passphrase', 'pass_to_access_keys'); 

Does somebody knows any good step by step tutorial/sample code?

@monofone
Copy link
Collaborator

monofone commented Feb 5, 2015

This is likely a mismatch between the given hostname and the hostname in the cert, this changed by php5.5. or php5.6 to be a strict match

@josecelano
Copy link
Author

Thanks @monofone, I´m using PHP 5.4.24 but I'm going to continue on the way you told me.

@josecelano
Copy link
Author

@josecelano
Copy link
Author

I still does not manage to connect using SSL.

I have seen you use fsockopen function and PHP manual says that function does not allow to provide stream context. stream_socket_client function allows to provide such context. Then, it seems I can not connect using SSL using your class. I have also seen in your functional test:

https://github.com/dejanb/stomp-php/blob/master/tests/functional/StompSslTest.php

that you do not use any context parameters like client certificate.

I want to use some context options like these:

$opts = array(
    'ssl' => array(
        'local_cert'          => $localCertPath,
        'cafile'                 => $cafilePath,
        'verify_peer'        => true,
        'CN_match'          => 'My Name',
        'allow_self_signed'          => true,
        'disable_compression'   => true,
        'SNI_enabled'                   => true,    
        'passphrase'            => 'xxxxxxxx',
        'capture_peer_cert_chain' => true,
        'capture_peer_cert'            => true,
    )
);
$context = stream_context_create($opts); 

@josecelano
Copy link
Author

I have found the problem. The problem is just what I told before. Now I am using a fork of this repo and works fine.

This fork fixs the problem: https://github.com/rethab/stomp-php

That fork uses stream_socket_client functions instead of fsockopen.

@MPParsley
Copy link

It still seems to be impossible to connect over ssl. I keep getting Connection refused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants