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

Message encryption #130

Open
sagikazarmark opened this issue Nov 24, 2014 · 14 comments
Open

Message encryption #130

sagikazarmark opened this issue Nov 24, 2014 · 14 comments

Comments

@sagikazarmark
Copy link
Contributor

In some cases it exposes a security issue if the messages in a queue are not encrypted, thus can be read by a human.

Is it possible to implement encryption? Not meaning having it in the core, but having the possibility to implement it. Any ideas?

@henrikbjorn
Copy link
Contributor

Yes

This is on the roadmap, i am working on writing a specification for the message format which is based on HTTP Messages, where headers arent encoded but can define encryption, serialization format etc.

@sagikazarmark
Copy link
Contributor Author

Sounds like a great feature

@lakiboy
Copy link

lakiboy commented May 7, 2015

@sagikazarmark You can encrypt messages by doing something like this:

Producer:

    public function collect(Foo $foo)
    {
        $message = new DefaultMessage($this->queueName);
        $message->data = serialize($foo);
        $message->encrypted = false;

        if ($this->encrypter !== null) {
            $message->encrypted = true;
            $message->data = $this->encrypter->encrypt($message->data);
        }

        $this->bernard->produce($message, $this->queueName);
    }

Consumer:

    public function __invoke(DefaultMessage $message)
    {
        $data = $message->data;

        if ($message->encrypted) {
            if ($this->encrypter === null) {
                throw new \RuntimeException('Can not decrypt message. Encrypter is not configured.');
            }

            $data = $this->encrypter->decrypt($data);
        }

        /** @var Foo $foo */
        $foo = unserialize($data);

        // Do something with $foo
    }

As an encrypter you could use https://github.com/nelmio/NelmioSecurityBundle/blob/master/Encrypter.php

We use this approach to collect some sensitive data in front-end application for post process in backend application. Just need to make sure the secret is the same for both apps.

@sagikazarmark
Copy link
Contributor Author

Yeah, it could definitely work. But it seems a bit hacky. What I am thinking about is to have a custom serializer which encrypts the serialized message itself. The benefit is that you can encrypt any kinds of message with it.

@lakiboy
Copy link

lakiboy commented May 7, 2015

It sounded like you need a solution ASAP, hence I provided a hint. Custom normalizer is cleaner, of course, but I guess you need to wrap your message with EncryptedMessage class for normalizer to pick it up.

@sagikazarmark
Copy link
Contributor Author

@lakiboy thank you very much, but it is not so urgent.

Actually, you can create a normalizer which wraps around the "usual" normalizer so that you can encrypt any messages.

@Baachi
Copy link
Contributor

Baachi commented May 8, 2015

Why not just extend the DefaultMessage and overwrite get/set methods?

@sagikazarmark
Copy link
Contributor Author

I think message encryption should be universal. Every message is normalized into string at some point. So why not an encryption layer after that point? It is simple, universal.

@Baachi
Copy link
Contributor

Baachi commented May 8, 2015

@sagikazarmark Thats the best/optimal solution, may solution was more the easy way. If you want to setup on this point, i would think the best position is to extend the Serializer. He serialize any envelope/message to a string, so i think this is the best point to startup.

@henrikbjorn
Copy link
Contributor

Unfortunately i have not had much time for my OSS projects because of an alarming close deadline at work.

As @Baachi meantions i think extending the Serializer is a good idea. Could even be done through composition.

@sagikazarmark
Copy link
Contributor Author

Probably yes. But as I know @henrikbjorn plans some sort of message format RFC and I think encryption could be an extension of that.

@sagikazarmark
Copy link
Contributor Author

So basically we have two propsals:

  • Have some kind of encryption on the driver level (after serialization happens)
  • Handle encryption on the serialization layer

@holtkamp
Copy link
Contributor

holtkamp commented Jun 24, 2017

@sagikazarmark did you have any progress on this? What option worked out best?

Note that when the SQSDriver is used, Amazon AWS SQS now supports server-side encryption, which might be an alternative...

@henrikbjorn
Copy link
Contributor

I once had the idea of doing something like having a message consist of headers and a body, where the headers would indicate encryption, type of body etc etc. kinda like a http message and i guess that is kind of what Rabbit does also.

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

5 participants