| 1 |
GNU SASL examples/openid20/README -- Explanation of SMTP OpenID 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 OpenID 2.0 authentication support. |
| 7 |
|
| 8 |
There is one example SMTP server and two helper tools that implement |
| 9 |
the actual OpenID 2.0 protocol: |
| 10 |
|
| 11 |
smtp-server-openid20.c: |
| 12 |
|
| 13 |
The actual SMTP server, based on ../smtp-server.c. |
| 14 |
|
| 15 |
gsasl-openid20-redirect.php: |
| 16 |
|
| 17 |
Given a user-supplied identifier it performs discovery and |
| 18 |
prints a user redirect URL. Invoked by smtp-server-openid20.c. |
| 19 |
|
| 20 |
gsasl-openid20-rp.php: |
| 21 |
|
| 22 |
OpenID 2.0 Relying-Party, receives the return_to URL. Intended |
| 23 |
to be invoked via a webserver. |
| 24 |
|
| 25 |
The PHP scripts requires JanRain's PHP5 OpenID implementation. On |
| 26 |
Modern Debian/Ubuntu systems, it is available in the "php-openid" |
| 27 |
package: |
| 28 |
|
| 29 |
apt-get install php-openid |
| 30 |
|
| 31 |
You need a webserver, for example Apache. The script |
| 32 |
'gsasl-openid20-redirect.php' should be placed in the PATH and |
| 33 |
'gsasl-openid20-rp.php' be placed somewhere in the web server root so |
| 34 |
it can be accessed through an URL. |
| 35 |
|
| 36 |
These three tools communicate with each other using a simple |
| 37 |
file-based IPC interface below /tmp/gsasl-openid20-store/. The OpenID |
| 38 |
library also uses that path for storage. If you want to change the |
| 39 |
path, you need to modify the gsasl-openid20-rp.php script and to pass |
| 40 |
the new location to the smtp-server-openid20 as discussed below. |
| 41 |
|
| 42 |
Here is the normal process: |
| 43 |
|
| 44 |
1) Start smtp-server-openid20, for example when running it on the |
| 45 |
interop.josefsson.org server the following is used: |
| 46 |
|
| 47 |
www-data$ ./smtp-server-openid20 2000 /tmp/gsasl-openid20-store http://interop.josefsson.org/ http://interop.josefsson.org/gsasl-openid20-rp.php |
| 48 |
|
| 49 |
For permission reasons, you should run the server under the same |
| 50 |
user as the webserver runs gsasl-openid20-rp.php. |
| 51 |
|
| 52 |
The first parameter is the path to the IPC root. The second |
| 53 |
parameter is the OpenID "realm". The third parameter is the |
| 54 |
"return_to" URL to where the gsasl-openid20-rp.php helper is found. |
| 55 |
|
| 56 |
For testing, it actually works fine to run the server on |
| 57 |
"localhost" and be able to complete OpenID 2.0 authentication: |
| 58 |
|
| 59 |
www-data$ PATH=$PWD LD_PRELOAD=../../lib/src/.libs/libgsasl.so ./.libs/smtp-server-openid20 2000 /tmp/gsasl-openid20-store http://localhost/ http://localhost/gsasl-openid20-rp.php |
| 60 |
|
| 61 |
2) The smtp-server-openid20 receives incoming connections from |
| 62 |
clients. The client sends its user-supplied identifier. You may |
| 63 |
use the gsasl command line tool to act as a client. For example: |
| 64 |
|
| 65 |
gsasl -a https://openidp.feide.no/simplesaml/module.php/openidProvider/user.php/jas4711 -z user --smtp -m OPENID20 localhost 2000 |
| 66 |
|
| 67 |
3) smtp-server-openid20 generate a per-connection NONCE (a 64-byte |
| 68 |
long hex string) and create the following files: |
| 69 |
|
| 70 |
/tmp/gsasl-openid20-store/state/NONCE/openid_url: |
| 71 |
|
| 72 |
holds the OpenID URL above, e.g., |
| 73 |
https://openidp.feide.no/simplesaml/module.php/openidProvider/user.php/jas4711 |
| 74 |
|
| 75 |
/tmp/gsasl-openid20-store/state/NONCE/realm: |
| 76 |
|
| 77 |
holds the realm URL, e.g. http://interop.josefsson.org/ |
| 78 |
|
| 79 |
/tmp/gsasl-openid20-store/state/NONCE/return_to: |
| 80 |
|
| 81 |
holds the return_to URL, |
| 82 |
e.g. http://localhost/gsasl-openid20-rp.php |
| 83 |
|
| 84 |
4) smtp-server-openid20 invokes "gsasl-openid20-redirect.php" to get |
| 85 |
the redirect URL, in the following file: |
| 86 |
|
| 87 |
/tmp/gsasl-openid20-store/state/NONCE/redirect_url: holds the redirect URL |
| 88 |
|
| 89 |
The URL is usually quite long and is dynamic for each |
| 90 |
authentication attempt. For example: |
| 91 |
|
| 92 |
https://openidp.feide.no/simplesaml/module.php/openidProvider/server.php?openid.assoc_handle=%7BHMAC-SHA1%7D%7B4f72fc46%7D%7BoC4UoA%3D%3D%7D&openid.claimed_id=https%3A%2F%2Fopenidp.feide.no%2Fsimplesaml%2Fmodule.php%2FopenidProvider%2Fuser.php%2Fjas4711&openid.identity=https%3A%2F%2Fopenidp.feide.no%2Fsimplesaml%2Fmodule.php%2FopenidProvider%2Fuser.php%2Fjas4711&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1&openid.realm=http%3A%2F%2Finterop.josefsson.org%2F&openid.return_to=http%3A%2F%2Finterop.josefsson.org%2Fgsasl-openid20-rp.php%2Ff9ff7386503e978f9643e9fe7bb01b911a621e0529aedd94b426e7320120b356%3Fjanrain_nonce%3D2012-03-28T11%253A55%253A53ZFWWO0z&openid.sreg.optional=nickname%2Cfullname%2Cemail |
| 93 |
|
| 94 |
5) smtp-server-openid20 waits for one of the following files to appear: |
| 95 |
|
| 96 |
/tmp/gsasl-openid20-store/state/NONCE/fail |
| 97 |
/tmp/gsasl-openid20-store/state/NONCE/success |
| 98 |
|
| 99 |
6) Meanwhile the user will receive the redirect URL over the SMTP |
| 100 |
connection and will access the URL in his browser. Eventually, |
| 101 |
after IdP approval, the user will be redirected to the "return_to" |
| 102 |
URL in his browser. |
| 103 |
|
| 104 |
7) The gsasl-openid20-rp.php return_to URL handler verify the OpenID |
| 105 |
2.0 authentication and writes the following files: |
| 106 |
|
| 107 |
/tmp/gsasl-openid20-store/state/NONCE/sreg: SREG values provided |
| 108 |
/tmp/gsasl-openid20-store/state/NONCE/claimed: claimed identity |
| 109 |
/tmp/gsasl-openid20-store/state/NONCE/success |
| 110 |
|
| 111 |
on success, or on failure it writes the following file: |
| 112 |
|
| 113 |
/tmp/gsasl-openid20-store/state/NONCE/fail |
| 114 |
|
| 115 |
8) smtp-server-openid20 notice that one of the stamp files is present |
| 116 |
and proceeds by reading the files and returning success/fail to the |
| 117 |
client as appropriate. The SREG values are sent to the client when |
| 118 |
provided. |
| 119 |
|
| 120 |
---------------------------------------------------------------------- |
| 121 |
Copying and distribution of this file, with or without modification, |
| 122 |
are permitted in any medium without royalty provided the copyright |
| 123 |
notice and this notice are preserved. |