commit code to git
[raven/abandoned/asp.git] / README.md
CommitLineData
f560b040
MV
1´╗┐University of Cambridge Classic ASP/VBScript Raven Authentication Module - v.1.0 (29/04/2014)\r
2==========================================================================\r
3\r
4Description\r
5-----------\r
6The software comprises a VBScript class 'Ucam_Webauth' and sample files that \r
7provide a Classic ASP/VBScript implementation of a 'Raven' authentication \r
8module; Raven is the web authentication protocol used by the University of \r
9Cambridge, UK. The logic and code of the 'Ucam_Webauth' class are loosely \r
10based on the PHP Raven authentication class provided at \r
11http://raven.cam.ac.uk/project/. \r
12- For a full description of the latest Raven specification and an explanation \r
13of how Raven works, go to http://raven.cam.ac.uk/project/.\r
14- This software was originally created for the Careers Service, University \r
15of Cambridge by sh801@cam.ac.uk\r
16\r
17Files and folders\r
18-----------------\r
19- [certificates]: Temporary location for Raven public key certificates.\r
20- [js]: Folder containing Javascript cryptography libraries.\r
21- [docs]: Supporting documentation.\r
22- [logs]: Possible location for log files created by the module.\r
23- Default.asp: A sample file showing how the 'Ucam_Webauth' class is used \r
24to provide Raven authentication.\r
25- Test.asp: A test file for unit testing the 'Ucam_Webauth' module using the \r
26'Ucam_RavenWLS' dummy Raven server (separate project, not included).\r
27- Ucam_Webauth.vbs: The main 'Ucam_Webauth' VBScript class.\r
28\r
29Platform requirements\r
30---------------------\r
31This module has been tested on IIS7 with .NET Framework set to \r
32'No managed code', ie. classic ASP.\r
33\r
34Installation\r
35------------\r
36### Cryptographic functions\r
37Cryptographic functions are provided by the Javascript libraries within the \r
38'js' folder. These libraries are versions of the client-side Javascript \r
39libraries provided at http://kjur.github.io/jsrsasign/index.html \r
40but modified to run server-side. There is no need to install any \r
41additional cryptography libraries.\r
42\r
43### Install Raven certificates\r
44The authentication module uses the Raven public key certificate at \r
45https://raven.cam.ac.uk/project/keys/ to verify authentication responses. \r
46Download the certificate from https://raven.cam.ac.uk/project/keys/ and copy \r
47to the 'certificates' folder provided with this authentication module \r
48download - the 'certificates' folder is a temporary location for the \r
49certificate while you get the module up and running. You will need to supply \r
50the full path to the 'certificates' folder as either a 'key_dir' argument \r
51to the 'Ucam_Webauth' constructor or by modifying the 'Ucam_Webauth' \r
52variable 'DEFAULT_KEY_DIR' directly. \r
53\r
54Once you have everything working, move the 'certificates' folder \r
55to a new location on your webserver that is not web- or publicly-accessible \r
56and modify the 'key_dir' string accordingly.\r
57 \r
58- NOTE: you may have to change the name of the key file from 'pubkey2.crt' \r
59to '2.crt'. \r
60\r
61If you're using the Raven test server \r
62(http://raven.cam.ac.uk/project/test-demo/) for testing purposes, make sure \r
63you install the test server keys instead, but ensure you remove these keys \r
64before using the authentication module in a production environment, as \r
65recommended by the demo Raven server:\r
66>> It is vital to keep these demo keys seperate from keys \r
67>> used with a production service - failure to do so could \r
68>> allow an attacker to successfully replay a response \r
69>> from the demonstration server, which anyone can easily \r
70>> obtain, against a production service. \r
71\r
72\r
73Getting started\r
74---------------\r
75\r
76The 'Ucam_Webauth' VBScript class must be used within an ASP server-side page \r
77as it interacts directly with a user's browser session. To use the \r
78'Ucam_Webauth' VBScript class:\r
79\r
80- 1. Ensure the 'Ucam_Webauth.vbs' class file and the folder 'js' are in the \r
81same directory as your ASP script. The folders 'certificates' and 'logs' may \r
82also be located here temporarily. \r
83- 2. Include the 'Ucam_Webauth.vbs' class file in the 'head' of your ASP file:\r
84\r
85```\r
86<head>\r
87<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\r
88<!--#include file="Ucam_Webauth.vbs"-->\r
89</head>\r
90\r
91```\r
92\r
93- 3. Set up the initial arguments for the 'Ucam_Webauth' class:\r
94\r
95```\r
96Set args = CreateObject("Scripting.Dictionary")\r
97args.Add "hostname", "localhost"\r
98args.Add "auth_service", "https://demo.raven.cam.ac.uk/auth/authenticate.html"\r
99args.Add "key_dir", "C:/Ucam_Webauth/certificates"\r
100```\r
101\r
102'args' is an associative array of *text* strings so parameter values must \r
103be converted into strings, ie. numbers and booleans must be supplied within \r
104quotes as in "23", "TRUE", "FALSE".\r
105A full list of allowed parameters is provided at the end of this README. \r
106\r
107- 4. Create an instance of the 'Ucam_Webauth' class from within your ASP \r
108server page and initialize with setup variables:\r
109\r
110```\r
111Set oUcam_Webauth = New Ucam_Webauth\r
112Call oUcam_Webauth(args) \r
113```\r
114 \r
115- 5. Call 'Authenticate()' on the Ucam_Webauth object and act according to \r
116the value returned:\r
117\r
118```\r
119 Select Case oUcam_Webauth.Authenticate()\r
120 \r
121 Case oUcam_Webauth.AUTHENTICATE_INCOMPLETE\r
122\r
123 ... \r
124 Exit Sub\r
125\r
126 Case oUcam_Webauth.AUTHENTICATE_COMPLETE_AUTHENTICATED \r
127\r
128 ...\r
129 \r
130 Case oUcam_Webauth.AUTHENTICATE_COMPLETE_NOT_AUTHENTICATED \r
131\r
132 ...\r
133\r
134 Case oUcam_Webauth.AUTHENTICATE_COMPLETE_ERROR \r
135\r
136 ...\r
137 \r
138 End Select\r
139```\r
140\r
141The four possible return values of 'Authenticate()' are:\r
142\r
143- AUTHENTICATE_INCOMPLETE : The authentication process has yet to complete. \r
144The user may have been redirected to the Raven server and has yet to enter \r
145their login details.\r
146- AUTHENTICATE_COMPLETE_AUTHENTICATED : The authentication process completed \r
147and the user has been successfully authenticated.\r
148- AUTHENTICATE_COMPLETE_NOT_AUTHENTICATED : The authentication process \r
149completed and the user was not successfully authenticated. \r
150The user may have clicked 'Cancel' at the Raven server.\r
151- AUTHENTICATE_COMPLETE_ERROR : There was an error during the authentication \r
152process forcing the authentication cycle to terminate early.\r
153\r
154As the 'Authenticate()' function may need to send HTTP headers, it must be \r
155called before any output (e.g. HTML, HTTP headers) is sent to the browser.\r
156\r
157The 'Default.asp' file provided is a sample of a simple server page using \r
158the 'Ucam_Webauth' VBScript class.\r
159\r
160Overview of Raven process\r
161-------------------------\r
162A diagram of the Raven authentication process is located within the 'docs' \r
163folder as [I - Overview of Raven Authentication Process.pdf]. \r
164\r
165The authentication cycle consists of the following key stages:\r
166\r
167#### User first tries to access authenticated page\r
168User tries to load an authenticated page on a particular website. \r
169The 'Ucam_Webauth' class is loaded and the 'Authenticate()' function is called. \r
170If no authentication cookie is found to indicate the user is authenticated, \r
171the user's browser is redirected to a separate Raven server using a special \r
172'Authentication Request'. The authentication request consists of a series of \r
173authentication parameters encoded into the URL redirect as name/value pairs.\r
174\r
175#### User is prompted for login information\r
176The Raven server interprets the authentication request sent by the main \r
177website and prompts the user for their username and password. The user may \r
178then be successfully authenticated or may decide to click 'Cancel'. They are \r
179redirected back to the main website with a series of 'Authentication Response' \r
180parameters encoded into a 'WLS-Response' GET variable.\r
181\r
182#### User redirected back to main webserver\r
183The user's original page is loaded again and 'Authenticate()' is called a \r
184second time. 'Ucam_Webauth' processes the new 'WLS-Response' GET value and, \r
185if it's valid, sets an authentication cookie on the user's browser. The \r
186user's original page is then loaded again. \r
187\r
188#### User redirected back to main webserver again \r
189With an authentication cookie now set, 'Authenticate()' checks the status \r
190code contained in the value of the authentication cookie and returns either \r
191'AUTHENTICATE_COMPLETE_AUTHENTICATED' or \r
192'AUTHENTICATE_COMPLETE_NOT_AUTHENTICATED'. If \r
193'AUTHENTICATE_COMPLETE_AUTHENTICATED' is returned , the original page can \r
194go on to display authenticated content to the user.\r
195\r
196Specifics of module\r
197-------------------\r
198The 'Authenticate()' function is the overarching authentication function of \r
199'Ucam_Webauth'. It performs some basic sanity checks using 'CheckSetup()' \r
200then uses 'GetCurrentState()' to establish the current state of the \r
201authentication process before branching accordingly. The possible return \r
202values of 'GetCurrentState()' are:\r
203\r
204#### STATE_NEW_AUTHENTICATION\r
205A completely fresh authentication. 'SendAuthenticationRequest()' [*1*] is \r
206then triggered which performs some basic data checks, sets the authentication \r
207cookie to 'AUTHENTICATIONCOOKIE_REDIRECT_WLS' (to record where we are in the \r
208authentication process) and redirects the user's browser to the Raven \r
209authentication server with a series of authentication parameters \r
210encoded as name/value pairs.\r
211\r
212#### STATE_WLS_RESPONSE_RECEIVED\r
213The Raven authentication server has processed the user and has returned the \r
214user's browser back to the original website with a series of authentication \r
215response parameters encoded into the 'WLS-Response' GET variable. \r
216'ProcessAuthenticationResponse()' [*2*] is then called which checks the \r
217validity of the 'WLS-Response' value, sets an authentication cookie and \r
218redirects the user back to the original page.\r
219\r
220#### STATE_WAA_AUTHENTICATIONCOOKIE_SET\r
221A valid authentication cookie has been set \r
222(<> AUTHENTICATIONCOOKIE_REDIRECT_WLS). \r
223'ProcessAuthenticationCookie()' [*3*] is then called which checks the \r
224validity of the cookie. If the cookie has expired, \r
225'SendAuthenticationRequest()' is called again in case the user needs to \r
226reauthenticate themselves. If the cookie is still valid, an \r
227'AUTHENTICATE_COMPLETE_XXX' value is returned, indicating that the \r
228authentication cycle has completed successfully. \r
229NOTE: this may be true if the user has cancelled the authentication process, \r
230in which case 'AUTHENTICATE_COMPLETE_NOT_AUTHENTICATED' will be returned.\r
231\r
232#### STATE_ERROR\r
233An error occurred, breaking the authentication cycle and returning \r
234AUTHENTICATE_COMPLETE_ERROR to 'Authenticate()'. This return value will \r
235also be generated by the other functions above if they generate an error.\r
236\r
237## Accompanying diagrams\r
238Detailed diagrams of the Raven process flow for (i) a successful \r
239authentication (ii) a cancelled authentication, are located in the 'docs' \r
240folder as [II - Ucam_Webauth - Flowchart for Valid Authentication.pdf] and \r
241[III - Ucam_Webauth - Flowchart for Cancelled Authentication.pdf], respectively. \r
242\r
243The numbers on these diagrams correspond to the three key secondary functions \r
244described above:\r
245- *1*. SendAuthenticationRequest()\r
246- *2*. ProcessAuthenticationResponse()\r
247- *3*. ProcessAuthenticationCookie()\r
248\r
249Other important functions include:\r
250\r
251### ResetState()\r
252Attempts to reset state as if a new user has just loaded a fresh browser \r
253window. This is typically used when a user has experienced an error and we \r
254want to give them a fresh opportunity to try again. \r
255\r
256### check_signature(...)\r
257Checks the signature provided by the Raven server, when it signed the \r
258'WLS-Response' variable, is a valid signature for the data. This ensures the \r
259data has not been tampered with.\r
260\r
261### hmac_sha1(...)\r
262Creates a hash value for signing the local authentication cookie.\r
263\r
264### wls_encode/decode(...)\r
265Encoding/decoding functions to allow base64 signatures to be sent within URLs.\r
266\r
267Possible arguments to 'Ucam_Webauth'\r
268------------------------------------\r
269(Based on documentation for PHP Raven authentication module)\r
270\r
271- log_file : \r
272The location for a log file that will record progress and track possible \r
273errors. The folder containing the file must be read/writable by the webserver.\r
274Default: log.txt\r
275\r
276- response_timeout : \r
277Responses from the central authentication server are time-stamped. \r
278This parameter sets the period of time in seconds during which these \r
279responses are considered valid. \r
280Default: 30 seconds.\r
281\r
282- key_dir : \r
283The name of the directory containing the public key certificate(s) required \r
284to validate the authentication responses sent by the server. \r
285Default: '/etc/httpd/conf/webauth_keys'.\r
286\r
287- max_session_life : \r
288The maximum period of time in seconds for which an established session will \r
289be valid. This may be overriden if the authentication reply contains a \r
290shorter 'life' parameter. Note that this does NOT define an expiry time for \r
291the session cookie. Session cookies are always set without an expiry time, \r
292causing them to expire when the browser session finishes. \r
293Default: 7200 (2 hours).\r
294\r
295- timeout_message : \r
296A re-authentication by the authentication service will be triggered when an \r
297established session expires. This option sets a text string which is sent to \r
298the authentication server to explain to the user why they are being asked to \r
299authenticate again. HTML markup is suppressed as for the description \r
300parameter described below. \r
301Default: 'your login to the site has expired'.\r
302\r
303- hostname (required) :\r
304The fully-qualified TCP/IP hostname that should be used in request URLs \r
305referencing the Ucam_Webauth-enabled application. This *must* be set, as it \r
306is needed for multiple reasons - primarily security but also to avoid varying \r
307hostnames in URLs leading to failed or inconsistent authentication. \r
308No default.\r
309\r
310- cookie_key (required): \r
311A random key used to protect session cookies from tampering. Any reasonably \r
312unpredictable string (for example the MD5 checksum of a rapidly changing \r
313logfile) will be satisfactory. This key must be the same for all uses of the \r
314web authentication system that will receive the same session cookies (see the \r
315cookie_name, cookie_path and cookie_domain parameters below). \r
316No default.\r
317\r
318- cookie_name :\r
319The name used for the session cookie. \r
320When used for access to resources over HTTPS the string '-S' is appended to \r
321this name. \r
322Default: 'Ucam-Webauth-Session'.\r
323\r
324- cookie_path :\r
325The 'Path' attribute for the session cookie. The default is the directory \r
326component of the path to the script currently being executed. This should \r
327result in the cookie being returned for future requests for this script and \r
328for the other resources in the same 'directory'; see the important \r
329information about the cookie_key parameter above. \r
330Default: '/'.\r
331\r
332- cookie_domain :\r
333The 'Domain' attribute for the session cookie. By default the 'Domain' \r
334attribute is omitted when setting the cookie. This should result in the \r
335cookie being returned only to the server running the script. Be aware that \r
336some people may treat with suspicion cookies with domain attributes that are \r
337wider than the host setting the cookie. \r
338No default.\r
339\r
340- auth_service : The full URL for the web login service to be used. \r
341Default: 'https://raven.cam.ac.uk/auth/authenticate.html' \r
342\r
343#### Authentication request properties\r
344The following setup parameters prefixed with 'authrequest_' relate to \r
345properties that will be sent to the authentication server as part of an \r
346authentication request:\r
347\r
348- authrequest_desc : A text description of the resource that is requesting \r
349authentication. This may be displayed to the user by the authentication \r
350service. It is restricted to printable ASCII characters (0x20 - 0x7e) though \r
351it may contain HTML entities representing other characters. The characters \r
352'<' and '>' will be converted into HTML entities before being sent to the \r
353browser and so this text cannot usefully contain HTML markup.\r
354No default.\r
355\r
356- authrequest_params : Data that will be returned unaltered to the WAA in \r
357any 'authentication response message' issued as a result of this request. \r
358This could be used to carry the identity of the resource originally requested \r
359or other WAA state, or to associate authentication requests with their \r
360eventual replies. When returned, this data will be protected by the digital \r
361signature applied to the authentication response message but nothing else is \r
362done to ensure the integrity or confidentiality of this data - the WAA MUST \r
363take responsibility for this if necessary.\r
364No default.\r
365\r
366- authrequest_skew : Interpretation of response_timeout is difficult if the \r
367clocks on the server running the PHP agent and on the authentication server \r
368are out of step. Both servers should use NTP to synchronize their clocks, \r
369but if they don't then this parameter should be set to an estimate of the \r
370maximum expected difference between them (in seconds). \r
371Default: 0.\r
372\r
373- authrequest_fail :\r
374If TRUE, sets the fail parameter in any authentication request sent to the \r
375authentication server to 'yes'. This has the effect of requiring the \r
376authentication server itself to report any errors that it encounters, rather \r
377than returning an error indication. Note however that even with this parameter \r
378set errors may be detected by this module that will result in authentication \r
379failing here. \r
380Default: FALSE.\r
381\r
382- authrequest_iact :\r
383If TRUE, then the 'iact' parameter provided to the authentication server is \r
384set to 'yes'. If FALSE, then the 'iact' parameter is set to 'no'. If no value \r
385is provided for 'authrequest_iact', the 'iact' parameter is left blank. \r
386The value 'yes' for 'iact' requires that a re-authentication exchange takes \r
387place with the user. This could be used prior to a sensitive transaction in \r
388an attempt to ensure that a previously authenticated user is still present \r
389at the browser. The value 'no' requires that the authentication request will \r
390only succeed if the user's identity can be returned without interacting with \r
391the user. This could be used as an optimisation to take advantage of any \r
392existing authentication but without actively soliciting one. If omitted or \r
393empty, then a previously established identity may be returned if the WLS \r
394supports doing so, and if not then the user will be prompted as necessary.\r
395Default: omitted.