\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
The question came up:  "What needs to be modified in order to provide Horde authentication using X509 digital certificates?"

\subsection{PKI}
Obviously, one will need user certificates and a means to distribute them;  a description of setting up a Public Key Infrastructure is beyond this document.  You should make yourself comfortable with PKI concepts before diving in.  If you don't know what a PKI is and the relationship between keys, certificates, and a CA, you \textit{will} find yourself in deep water fairly quickly.  Not trying to be snarky here, but it will pay to do your homework;  you might start at the <a href="http://en.wikipedia.org/wiki/Public_key_infrastructure">Wikipedia PKI entry</a>.

\subsection{Horde Auth}
Authenticating to Horde should be surprisingly simple, and you should be able to use the Basic Authentication driver, since Apache's X509 authentication functions in much the same manner and relies on the web server prompting one's browser to authenticate.

\textit{\textbf{But Wait!}}

Authenticating using X509 user certificates has more in common with using the <a href="http://wiki.horde.org/ShibbolethAuthHowTo">Shibboleth Authentication Driver</a>.  For example, unlike \textit{real} Basic Authentication, one's password is never passed across the network, and is not available in an environment variable.  Unless you plan on using X509 authentication for your mail service (\textit{most unlikely}), you should pay close attention to faking a SSO (\textit{Single Sign On}) arrangement.  Specifically, you should examine the instructions and samples there for

\begin{itemize}
\item selecting an HTTP header to convey the username (\textit{hint: you might parse SSL\_CLIENT\_S\_DN\_Email})


\item adding credentials (\textit{e.g., mailhost, username, password}) to a prefs backend so you can use hordeauth<br />
<del> Perhaps, by the time you read this, someone will have written an X509 Auth driver for Horde. </del><ins> A X509 authentication driver is available in Horde\_Auth since version 2.0.7 and support for it in the Horde stack is in Horde 5.2.</ins>


\end{itemize}
\subsection{Web server setup}
Most of the work will come in setting up authentication for your web server;

\subsubsection{Apache}
Apache uses the FakeBasicAuth directive to establish authentication using user certificates, and \textbf{these instructions assume you are using Apache with mod\_ssl support}

You setup authentication within either the virtual  host or directory directive stanza for your Horde services.

You should read the <a href="http://httpd.apache.org/docs/2.0/ssl/ssl_howto.html">SSL/TLS Strong Encryption How-To</a> in the Apache man pages for the version of Apache you are using (\textit{that link is for version 2.0, though it should be very similar for versions 1.3 and 2.2}).  <a href="http://httpd.apache.org/docs/2.0/ssl/ssl_howto.html#accesscontrol">This link</a> addresses Client Authentication and Access Control, but you should read the note at the top of the page and take it to heart.  The \textbf{mod\_ssl} pages on <a href="http://www.modssl.org/docs/2.8/ssl_howto.html#ToC6">Client Authentication and Access Control</a> are also valuable.


\noindent\rule{\textwidth}{1pt}
Two possible scenarios for X509 authentication follow:

\paragraph{A fairly strict authentication setup for one or two administrators}
<pre><code>
<Directory [absolute path to directory for service, in quotes]>
        SSLOptions  +StdEnvVars +ExportCertData +FakeBasicAuth +OptRenegotiate +CompatEnvVars
        SSLVerifyClient   require
        SSLVerifyDepth    5
        SSLRequireSSL
        SSLRequire \%\{SSL\_CLIENT\_I\_DN\_CN\} eq "the CN of the Issuer DN of client's certificate in quotes"  
         and \%\{SSL\_CLIENT\_S\_DN\_O\} eq "the O of the Subject DN in client's certificate in quotes"  
         and \%\{SSL\_CLIENT\_S\_DN\_CN\} in \{"the CN of one or more", "comma delimited Subject DNs in quotes"\}
</Directory>
</code></pre>
\paragraph{An authentication setup for many users with certs from a given CA}
<pre><code>
<Directory [path to directory where the application lives, in quotes]>
        SSLOptions  +StdEnvVars +ExportCertData +OptRenegotiate +FakeBasicAuth
        SSLVerifyClient   require
        SSLVerifyDepth    5
        SSLRequireSSL 
        SSLRequire \%\{SSL\_CLIENT\_I\_DN\_CN\} eq "the CN of Issuer DN of client's certificate in quotes"  
         and \%\{SSL\_CLIENT\_S\_DN\_O\} eq "the O of Subject DN in client's certificate in quotes"  
         and \%\{SSL\_CLIENT\_S\_DN\_OU\} eq ""the OU of Subject DN in client's certificate in quotes"
</Directory>
</code></pre>

\noindent\rule{\textwidth}{1pt}
\paragraph{Notes}
*You \textbf{will} want to read the mod\_ssl docs, particularly those for deciphering the certificate-specific <a href="http://www.modssl.org/docs/2.8/ssl_compat.html#ToC2">environment variables</a> (as in the examples above);  you will want to choose the ones relevant to your use.

*You \textit{\textbf{will}} want to adjust some of the values above (like \textbf{SSLVerifyDepth}) for your own needs.  Do \textbf{NOT} just plug in these values.

\subsubsection{Lighttpd}
Lighttpd, as usual, does not have configuration options as robust as Apache, but the basic setup can still be achieved. Again, \textbf{You must have SSL properly setup and working}.

<pre><code>
\# These are "normal" SSL directives, not specific to client certs.
ssl.engine                  = "enable"
ssl.pemfile                 = "/opt/local/etc/lighttpd/server.pem"
ssl.ca-file                 = "/opt/local/etc/lighttpd/ca-certs.crt"
server.name                 = "www.example.com"
server.document-root        = "/var/www/html"

\# These are for enabling client certs
ssl.verifyclient.activate   = "enable"
ssl.verifyclient.enforce    = "enable"
ssl.verifyclient.exportcert = "enable"
ssl.verifyclient.username   = "SSL\_CLIENT\_S\_DN\_UID"
\# Make sure you use the appropriate value for **you** for depth.
ssl.verifyclient.depth = 2
</code></pre>
\subsection{Horde configuration}
You would configure this driver in the Authentication tab of the Horde application setup page. There are two decisions to make regarding configuration:

\begin{itemize}
\item What field in the X509 certificate contains the value to be used as the horde login (normally SSL\_CLIENT\_S\_DN\_CN)


\item What to do about passwords for hordeauth in applications like IMP.


\end{itemize}
The first question is easy. What certificate field contains the username. Normally the default is fine. You \textbf{should} be aware, however of the type of value contained in that field. E.g., if it is a bare username or a full email address. Depending on your server setup, you may need to use a authusername hook to normalize the username (see horde/conf/hooks.php).

The second question takes a bit more effort. If using Horde for email, you will need to provide authentication for each user to the IMAP server. There are ways, of course, to get around this if your system is secured and only Horde/IMP is used to access the IMAP server (you can use a single password for all users, configure the IMAP server to accept any password etc...). More likely you will need to provide some mapping of usernames/passwords. This can all be done in a postauthenticate hook. In it, you can provide any means that makes sense for your server to provide the appropriate credentials. You can even perform extra validation by checking the certificate hash against a stored hash. There is an example provided in the hooks file to get you started. The hooks should return the credentials that horde is to use to authenticate anywhere hordeauth is used.

The X509 driver in Horde also provides the ability to perform custom validation. Any of the fields available in the certificate or any of the SSL environment variables passed by the webserver can be used to perform a final check before authentication is granted. For example, since lighttpd does not provide the same level of enforcement in it's configuration as Apache, you could perform these types of checks here. This is done in the x509\_validate hook. See horde/conf/hooks.php for details.

\end{document}
