# SSL Authentication in Mongrel

**URL:** <https://www.ruby-forum.com/t/ssl-authentication-in-mongrel/131752>\
**Category:** Rails\
**Created:** [March 12, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/ssl-authentication-in-mongrel/131752 "2008-03-12T23:19:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [March 12, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/ssl-authentication-in-mongrel/131752/1 "2008-03-12T23:19:21Z")

</div>

I am working on project and I need to get the value stored in the  
header  
(SSL\_CLIENT\_S\_DN\_CN ). We have been doing PKI authentication for  
sometime in PHP by getting the value of  
$\_SERVER[“SSL\_CLIENT\_S\_DN\_CN”] .  
Now that I am trying some stuff in Rails I can’t seem to get  
anywhere.  
I try to do what you do above and I get a “Bad Request” when I have  
SSLUserName SSL\_CLIENT\_S\_DN\_CN in the httpd-ssl.conf file. I am able  
to get up and running when I comment it out.

Here is my config:

SSLRandomSeed startup builtin  
SSLRandomSeed connect builtin  
SSLRandomSeed connect file:/dev/urandom 512  
Listen 443  
AddType application/x-x509-ca-cert .crt  
AddType application/x-pkcs7-crl .crl  
SSLPassPhraseDialog builtin  
SSLSessionCache “shmcb:/var/run/ssl\_scache(512000)”  
SSLSessionCacheTimeout 28800  
SSLMutex “file:/var/run/ssl\_mutex”  
\<VirtualHost \*:443\>  
\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://127.0.0.1:3000](http://127.0.0.1:3000)

# General setup for the virtual host

ServerName [luther.example.com](http://luther.example.com)  
ServerAdmin removed\_email\_address@domain.invalid  
ErrorLog “/var/log/httpd-error.log”  
TransferLog “/var/log/httpd-access.log”  
RequestHeader set X\_FORWARDED\_PROTO ‘https’  
SSLUserName SSL\_CLIENT\_S\_DN\_CN  
ProxyPass / balancer://mongrel\_cluster/  
ProxyPassReverse / balancer://mongrel\_cluster/  
ProxyPreserveHost ON  
#Rewrite the REMOTE\_USER env variable into the request header  
RewriteEngine On  
RewriteCond %{LA-U:REMOTE\_USER} (.+)  
RewriteRule . -[E=RU:%1]  
RequestHeader add X-FORWARDED-User %{RU}e  
SSLEngine on  
SSLCipherSuite  
ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL  
SSLCertificateFile “/usr/local/etc/apache22/ssl/luther.crt”  
SSLCertificateKeyFile “/usr/local/etc/apache22/ssl/privkey.pem”  
SSLCertificateChainFile “/usr/local/etc/apache22/ssl/chain.crt”  
SSLCACertificatePath “/usr/local/etc/apache22/ssl.crt”  
SSLVerifyClient require  
SSLVerifyDepth 10  
SSLOptions +StdEnvVars +ExportCertData  
  
And in an controller I am just doing:

\<%= request.env['SSL\_CLIENT\_S\_DN\_CN'] %\>

also tried \<%= request.env['HTTP-X-FORWARDED-SSL\_CLIENT\_S\_DN\_CN'] %\>

All I get is blank.

Any advice would be MUCH appreciated

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [March 12, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/ssl-authentication-in-mongrel/131752/2 "2008-03-12T23:45:57Z")

</div>

On Thu, Mar 13, 2008 at 9:18 AM, Ben M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am working on project and I need to get the value stored in the  
> header  
> (SSL\_CLIENT\_S\_DN\_CN ). We have been doing PKI authentication for  
> sometime in PHP by getting the value of

> All I get is blank.
> 
> Any advice would be MUCH appreciated

As a “quick and nasty, see what the hell is happening” thing, I would  
put the following in your view:

```
<%= session.to_yaml -%>
```

That way you can see what the session actually contains and debug from  
there.

Mikel

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [March 15, 2008, 4:33pm UTC](https://www.ruby-forum.com/t/ssl-authentication-in-mongrel/131752/3 "2008-03-15T16:33:01Z")

</div>

Fantastic! … I did that and was able to see that I was calling it  
wrong!

I was \<%= request.env[‘HTTP-X-FORWARDED-SSL\_CLIENT\_S\_DN\_CN’] %\>

and all I needed was \<%=  
request.env[‘HTTP\_X\_FORWARDED\_SSL\_CLIENT\_S\_DN\_CN’] %\>

This is great news thanks for all your help.

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [March 17, 2008, 3:21am UTC](https://www.ruby-forum.com/t/ssl-authentication-in-mongrel/131752/4 "2008-03-17T03:21:59Z")

</div>

On Sun, Mar 16, 2008 at 2:32 AM, Ben M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Fantastic! … I did that and was able to see that I was calling it  
> wrong!

Good! 🙂

That is a bit of a hackish way to do it though (putting it in the  
view). A better solution is making an around filter and then  
requesting it.

Like here:

[http://www.lindsaar.net/2008/3/17/debugging-the-rails-session-store](http://www.lindsaar.net/2008/3/17/debugging-the-rails-session-store)

Mikel

> **[Mikel Lindsaar](https://lindsaar.net/)**
>
> Internet Home for Mikel Lindsaar
