| 1 |
GNU SASL examples/saml20/README -- Explanation of SMTP SAML 2.0 example. |
| 2 |
Copyright (C) 2012-2026 Simon Josefsson |
| 3 |
See the end for copying conditions. |
| 4 |
|
| 5 |
This directory holds a GNU SASL example application that implements a |
| 6 |
SMTP server with SAML 2.0 authentication support. The SAML |
| 7 |
implementation used is Lasso: http://lasso.entrouvert.org/ |
| 8 |
|
| 9 |
It should be noted that this is just an example of how it could work. |
| 10 |
You don't need to implement it this way. For example, sometimes |
| 11 |
having a Apache/PHP web server running is a problem. Then you could |
| 12 |
use something like MicroHTTPD and implement everything in one process |
| 13 |
using Lasso in C. Then you don't need any IPC stuff. Also, you could |
| 14 |
also want to use another SAML implementation instead of Lasso. The |
| 15 |
point of this example is just to proof that it works. |
| 16 |
|
| 17 |
This setup was tested with GNU SASL version 1.7.3. |
| 18 |
|
| 19 |
There is one example SMTP server and some helper tools that implement |
| 20 |
the actual SAML part: |
| 21 |
|
| 22 |
smtp-server-saml20.c: |
| 23 |
|
| 24 |
The actual SMTP server, based on ../smtp-server.c. It invokes |
| 25 |
gsasl-saml20-request.c to generate the request, and then waits |
| 26 |
for gsasl-saml20-sp.php to accept the SAML response. |
| 27 |
|
| 28 |
gsasl-saml20-request.c |
| 29 |
|
| 30 |
Given a Identity Provider identifier it generates a SAML Request |
| 31 |
and prints a user redirect URL. This tool is invoked by |
| 32 |
smtp-server-saml20.c. It uses Lasso as the SAML library. |
| 33 |
|
| 34 |
gsasl-saml20-sp.php: |
| 35 |
|
| 36 |
This is the SAML SP responsible for accepting SAML Responses. |
| 37 |
Intended to be invoked via a webserver. |
| 38 |
|
| 39 |
These three tools communicate with each other using a simple |
| 40 |
file-based IPC interface, normally placed below /tmp/gsasl-saml20/. |
| 41 |
|
| 42 |
Install the SAML SP: |
| 43 |
|
| 44 |
The "gsasl-saml20-sp.php" script needs to be install so that it is |
| 45 |
reachable under some URL via a web server. This is the |
| 46 |
AssertionConsumerService (ACS) for the GNU SASL SP. For example, on |
| 47 |
interop.josefsson.org I make the ACS available as |
| 48 |
|
| 49 |
http://interop.josefsson.org/gsasl-saml20-sp.php |
| 50 |
|
| 51 |
by copying the file into |
| 52 |
|
| 53 |
/var/www/gsasl-saml20-sp.php |
| 54 |
|
| 55 |
Configure the tool by specifying the state and configuration |
| 56 |
directories in a file called gsasl-saml20-config.php in the same |
| 57 |
directory, like this: |
| 58 |
|
| 59 |
echo '<?php $state_path = "/tmp/gsasl-saml20"; $cfg_path = "/etc/gsasl-saml20"; ?>' > /var/www/gsasl-saml20-config.php |
| 60 |
|
| 61 |
Of course you can chose different paths, but then you need to update |
| 62 |
the paths accordingly in the rest of this documentation. |
| 63 |
|
| 64 |
Create SAML SP configuration: |
| 65 |
|
| 66 |
/etc/gsasl-saml20/sp-key.pem |
| 67 |
/etc/gsasl-saml20/sp-crt.pem |
| 68 |
|
| 69 |
This is a private key and certificate for your SP. It can be |
| 70 |
self-signed. You may generate the files with GnuTLS like this: |
| 71 |
|
| 72 |
certtool -p --outfile sp-key.pem |
| 73 |
echo 'organization=My SP' > sp-crt.template |
| 74 |
certtool --generate-self-signed --load-privkey sp-key.pem |
| 75 |
--template sp-crt.template --outfile sp-crt.pem |
| 76 |
|
| 77 |
Currently the private key is not used to sign requests. |
| 78 |
|
| 79 |
/etc/gsasl-saml20/sp-metadata.xml |
| 80 |
|
| 81 |
This is specific for your SP. Use sp-metadata.xml as a starting |
| 82 |
point if you are unsure, and use a text editor to modify it. You |
| 83 |
need to: |
| 84 |
|
| 85 |
1) Change the entityID to something (the URL does not have to |
| 86 |
resolve to anything, but should be unique to this SP). |
| 87 |
|
| 88 |
2) Replace the ACS URL to point at your gsasl-saml20-sp.php. |
| 89 |
|
| 90 |
3) Replace the certificate data (in two places) with the base64 |
| 91 |
data from sp-crt.pem. |
| 92 |
|
| 93 |
4) Update with your contact information at the bottom. |
| 94 |
|
| 95 |
You may want to make the SP metadata reachable over the web as |
| 96 |
well, for example by doing: |
| 97 |
|
| 98 |
ln -s /etc/gsasl-saml20/sp-metadata.xml /var/www/ |
| 99 |
|
| 100 |
/etc/gsasl-saml20/IDP/idp-metadata.xml |
| 101 |
|
| 102 |
This is the XML metadata for each IdP. Replace "IDP" in the |
| 103 |
filename with the Identity Provider Identifier you expect users to |
| 104 |
type. |
| 105 |
|
| 106 |
/etc/gsasl-saml20/openidp.feide.no/idp-metadata.xml |
| 107 |
|
| 108 |
Here we used Feide OpenIdP as an example. The content of |
| 109 |
idp-metadata.xml is retrieved from the IdP. For Feide OpenIdP you |
| 110 |
can retrieve it from the following URL: |
| 111 |
|
| 112 |
https://openidp.feide.no/simplesaml/saml2/idp/metadata.php |
| 113 |
|
| 114 |
/etc/gsasl-saml20/idp.protectnetwork.org/idp-metadata.xml |
| 115 |
|
| 116 |
As the second test IdP we used Protect Network. You can retrieve |
| 117 |
the file from here: |
| 118 |
|
| 119 |
http://www.protectnetwork.org/protectnetwork-metadata.xml |
| 120 |
|
| 121 |
Lasso requires that the KeyDescriptor tags are qualified with |
| 122 |
attributes use="signing" or use="encryption" respectively, so you |
| 123 |
need to modify the file slightly. |
| 124 |
|
| 125 |
Here is the normal process: |
| 126 |
|
| 127 |
1) Start the example SMTP server "smtp-server-saml20", for example |
| 128 |
when running it on the interop.josefsson.org server the following |
| 129 |
is used: |
| 130 |
|
| 131 |
su -c "env LD_LIBRARY_PATH=/root/gsasl/lib/src/.libs PATH=$PATH:/root/gsasl/examples/saml20 nohup /root/gsasl/examples/saml20/smtp-server-saml20 2001 /etc/gsasl-saml20 /tmp/gsasl-saml20 /etc/gsasl-saml20/sp-metadata.xml /etc/gsasl-saml20/sp-key.pem /etc/gsasl-saml20/sp-crt.pem 2>&1 | logger -t saml20" www-data & |
| 132 |
|
| 133 |
For permission reasons, you should run the server under the same |
| 134 |
user as the webserver runs gsasl-saml20-sp.php. |
| 135 |
|
| 136 |
The "gsasl-saml20" tool takes some parameters, the port, the |
| 137 |
configuration directory, the IPC directory, and the metadata, key |
| 138 |
and certificate for the SP. |
| 139 |
|
| 140 |
2) The smtp-server-saml20 receives incoming connections from clients. |
| 141 |
The client sends the Identity Provider Identifier. You may use the |
| 142 |
gsasl command line tool to act as a client. For example: |
| 143 |
|
| 144 |
jas@latte:~$ gsasl --smtp -m SAML20 interop.josefsson.org 2001 |
| 145 |
Trying ‘interop.josefsson.org’... |
| 146 |
220 localhost ESMTP GNU SASL smtp-server |
| 147 |
EHLO [127.0.0.1] |
| 148 |
250-localhost |
| 149 |
250 AUTH ANONYMOUS EXTERNAL LOGIN PLAIN SECURID DIGEST-MD5 CRAM-MD5 SCRAM-SHA-1 SAML20 OPENID20 |
| 150 |
EHLO [127.0.0.1] |
| 151 |
250-localhost |
| 152 |
250 AUTH ANONYMOUS EXTERNAL LOGIN PLAIN SECURID DIGEST-MD5 CRAM-MD5 SCRAM-SHA-1 SAML20 OPENID20 |
| 153 |
AUTH SAML20 |
| 154 |
334 |
| 155 |
Enter SAML authentication identifier (e.g. "http://example.org/"): |
| 156 |
|
| 157 |
At the prompt, you could type for example "openidp.feide.no". |
| 158 |
|
| 159 |
3) smtp-server-saml20 invokes "gsasl-saml20-request" to get the |
| 160 |
redirect URL, which is also stored in this file: |
| 161 |
|
| 162 |
/tmp/gsasl-saml20/SESSIONID/redirect_url |
| 163 |
|
| 164 |
The SESSIONID will be unique for every SAML Request, it looks for |
| 165 |
example like "_B6F098F6D17C63796A9DF3BB63EF58AA". |
| 166 |
|
| 167 |
4) The server continue with the SMTP authentication process, the |
| 168 |
output from the gsasl client looks like: |
| 169 |
|
| 170 |
biwsb3BlbmlkcC5mZWlkZS5ubw== |
| 171 |
334 aHR0cHM6Ly9vcGVuaWRwLmZlaWRlLm5vL3NpbXBsZXNhbWwvc2FtbDIvaWRwL1NTT1NlcnZpY2UucGhwP1NBTUxSZXF1ZXN0PWZaRlBiNE13RE1XJTJGQ3NvZFFzdEthUVJJdEF5cDB2NVVZOXBobHltaXBzMFVraXdPM2ZidEIxU2R0a3N2UGp6N0p6OCUyRnA4ZzdhVmpSdTZONm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DRWFoS1dYeXN5OEtualIlMkY5TThDZWNUMU4lMkJ1NFV4emhVM1BDcG1zVnNUVW9ZekxYUGxWRnBod2owb0l4S2JGQUd0bnF3TktieENTV2JaUk5RJTNEJTNE |
| 172 |
Visit this URL to proceed with authentication: |
| 173 |
https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php?SAMLRequest=fZFPb4MwDMW%2FCsodQstKaQRItAyp0v5UY9phlymips0UkiwO3fbtB1SdtksvPjz7Jz8%2Fp8g7aVjRu6N6go8e0HlfnVTIpkZGequY5iiQKd4BMtewuri%2FY%2FMgZMZqpxstyR%2FkOsERwTqhFfG2ZUbe1nEVrpIqLmfLTRwtV3GxKqtovY6j22qRFAXxXsDiMJ%2BRAR8gxB62Ch1XbpDC2dwPb%2FxZ8hwmbLFg0eyVeOVwg1DcTdTROYOMUm1Aib0JWhB7CJSmKDojYXRMxzKnQ5fW9WMN9iQaCMzREK%2FStoEpm4y0XCKMDnbDEeIEFyVPR55Nzmx%2B2SeUA6tN8K4RWkStAm0P9IAcpT%2FtC300Kf2LpudXPAyhbcudlqL5Hg103F3PdFTE3m%2BnUeYsVyhAOeIVUurPjQXufs3S%2FLzz%2F8fzHw%3D%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1&Signature=EMaGrDEfEeIWxbRPTDk6MQye%2FjQuqUlcZtlONoEg2ER9LprE8QhRmwi1M6C9b2sIlE5oMOeu3x%2FS5ibbNUwcVp2MeE4eZqVvnqA8Fg9%2BasaGA68AZQYlqzSFerjuicZL07cVVA%2FFEk2ZbOpgTtfJmh5ukbQv9UDNxu0k9dXv8z40VWlT5REBGb1dQTE0AEs3kC%2BVqGFdQZGbkIxkw1PYnUGND3%2BRvu8W2LCQLa9d3uDiSRYLzHo%2FHfJNxnMQcMYb0uttSP6zvnKj%2BHbQLlDECLzli%2BFAnYF1L0i9z4pQRAKaVdMbcGiaAe%2Fuhd0%2BTAUQfRkhjCEahKWXysy8KnjR%2F9M8CecT1N%2Bu4UxzhU3PCpmsVsTUoYzLXPlVFphwj0oIxKbFAGtnqwNKbxCSWbZRNQ%3D%3D |
| 174 |
PQ== |
| 175 |
|
| 176 |
5) smtp-server-saml20 waits for one of the following files to appear: |
| 177 |
|
| 178 |
/tmp/gsasl-saml20/_B6F098F6D17C63796A9DF3BB63EF58AA/success |
| 179 |
/tmp/gsasl-saml20/_B6F098F6D17C63796A9DF3BB63EF58AA/fail |
| 180 |
|
| 181 |
6) Meanwhile the user will receive the redirect URL over the SMTP |
| 182 |
connection and will access the URL in his browser. Eventually, |
| 183 |
after IdP approval, the browser will be redirected to the SP with |
| 184 |
the SAML response. |
| 185 |
|
| 186 |
7) The gsasl-saml20-sp.php verify the SAML Response (using Lasso as |
| 187 |
the SAML library) and writes files to the IPC store. |
| 188 |
|
| 189 |
8) smtp-server-saml20 notice that one of the IPC files is present and |
| 190 |
proceeds by reading the files and returning success/fail to the |
| 191 |
client as appropriate. The client will print something like this: |
| 192 |
|
| 193 |
235 OK [authid: _d69b0f484333df7eea73fccfd0b4dae2629f2eeb89 authzid: N/A] |
| 194 |
Client authentication finished (server trusted)... |
| 195 |
Enter application data (EOF to finish): |
| 196 |
|
| 197 |
---------------------------------------------------------------------- |
| 198 |
Copying and distribution of this file, with or without modification, |
| 199 |
are permitted in any medium without royalty provided the copyright |
| 200 |
notice and this notice are preserved. |