# Agentzh's encrypted session module

**URL:** <https://www.ruby-forum.com/t/agentzhs-encrypted-session-module/238342>\
**Category:** NGINX\
**Created:** [January 5, 2014, 9:00am UTC](https://www.ruby-forum.com/t/agentzhs-encrypted-session-module/238342 "2014-01-05T09:00:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [January 5, 2014, 9:00am UTC](https://www.ruby-forum.com/t/agentzhs-encrypted-session-module/238342/1 "2014-01-05T09:00:29Z")

</div>

I’ve been studying agentzh’s encrypted session module from  
[https://github.com/agentzh/encrypted-session-nginx-module/tree/master/src](https://github.com/agentzh/encrypted-session-nginx-module/tree/master/src).

There are essentially two methods: one to encrypt values, and a second  
to decrypt modules. The functions to do so are  
ngx\_http\_set\_encode\_encrypted\_session and  
ngx\_http\_set\_decode\_encrypted\_session. The functions call  
ngx\_http\_encrypted\_session\_aes\_mac\_encrypt and  
ngx\_http\_encrypted\_session\_aes\_mac\_decrypt respectively.

The problem I am having is: I cannot tell how this is plumbed into  
nginx framework such that a value is encrypted going one way, and  
decrypted going another. From the module, I clearly see the command:

Can anyone shed some light on the magic I am missing?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@Jeffrey\_W](https://www.ruby-forum.com/u/Jeffrey_W)\
**Post date:** [January 6, 2014, 8:45pm UTC](https://www.ruby-forum.com/t/agentzhs-encrypted-session-module/238342/2 "2014-01-06T20:45:32Z")

</div>

Hello!

On Sat, Jan 4, 2014 at 11:59 PM, Jeffrey W. wrote:

> I’ve been studying agentzh’s encrypted session module from  
> [encrypted-session-nginx-module/src at master · openresty/encrypted-session-nginx-module · GitHub](https://github.com/agentzh/encrypted-session-nginx-module/tree/master/src).

Thank you for checking it out! 🙂

> The problem I am having is: I cannot tell how this is plumbed into  
> nginx framework such that a value is encrypted going one way, and  
> decrypted going another. From the module, I clearly see the command:

The callbacks are injected into the standard ngx\_rewrite module’s  
command list by means of the ndk\_set\_var submodule in the  
ngx\_devel\_kit (NDK) module:

```
https://github.com/simpl/ngx_devel_kit

```

The entry point of NDK called ngx\_encrypted\_session is  
ndk\_set\_var\_value. You can trace from there 🙂

The actual request-time caller of these configuration directives is  
the standard ngx\_rewrite module at the “rewrite” running phase.

Best regards,  
-agentzh
