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