These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | // error_reporting(E_ALL); ini_set('display_errors',1); |
||
4 | |||
5 | require_once __DIR__ . '/vendor/autoload.php'; |
||
6 | |||
7 | use CILogon\Service\Util; |
||
8 | use CILogon\Service\Content; |
||
9 | use CILogon\Service\ShibError; |
||
10 | use CILogon\Service\Loggit; |
||
11 | |||
12 | Util::startPHPSession(); |
||
13 | |||
14 | // Util::startTiming(); |
||
15 | // Util::$timeit->printTime('MAIN Program START...'); |
||
16 | |||
17 | // Check for a Shibboleth error and handle it |
||
18 | $shiberror = new ShibError(); |
||
19 | |||
20 | // Check the csrf cookie against either a hidden <form> element or a |
||
21 | // PHP session variable, and get the value of the 'submit' element. |
||
22 | // Note: replace CR/LF with space for 'Show/Hide Help' buttons. |
||
23 | $retchars = array("\r\n","\n","\r"); |
||
24 | $submit = str_replace( |
||
25 | $retchars, |
||
26 | " ", |
||
27 | Util::getCsrf()->verifyCookieAndGetSubmit() |
||
28 | ); |
||
29 | Util::unsetSessionVar('submit'); |
||
30 | |||
31 | $log = new Loggit(); |
||
32 | $log->info('submit="' . $submit . '"'); |
||
33 | |||
34 | // Depending on the value of the clicked 'submit' button or the |
||
35 | // equivalent PHP session variable, take action or print out HTML. |
||
36 | switch ($submit) { |
||
37 | case 'Log On': // Check for OpenID or InCommon usage. |
||
38 | case 'Continue': // For OOI |
||
39 | Content::handleLogOnButtonClicked(); |
||
40 | break; // End case 'Log On' |
||
41 | |||
42 | case 'Log Off': // Click the 'Log Off' button |
||
43 | printLogonPage(true); |
||
44 | break; // End case 'Log Off' |
||
45 | |||
46 | case 'gotuser': // Return from the getuser script |
||
47 | Content::handleGotUser(); |
||
48 | break; // End case 'gotuser' |
||
49 | |||
50 | case 'Go Back': // Return to the Main page |
||
51 | case 'Proceed': // Proceed after 'User Changed' or Error page |
||
52 | case 'Done with Two-Factor': |
||
53 | Util::verifySessionAndCall('printMainPage'); |
||
54 | break; // End case 'Go Back' / 'Proceed' |
||
55 | |||
56 | case 'Cancel': // Cancel button on WAYF page - go to Google |
||
57 | header('Location: https://www.google.com/'); |
||
58 | exit; // No further processing necessary |
||
59 | break; |
||
60 | |||
61 | case 'Get New Certificate': |
||
62 | if (Util::verifySessionAndCall( |
||
63 | 'CILogon\\Service\\Content::generateP12' |
||
64 | )) { |
||
65 | printMainPage(); |
||
66 | } |
||
67 | break; // End case 'Get New Certificate' |
||
68 | |||
69 | case 'Get New Activation Code': |
||
70 | if (Util::verifySessionAndCall('generateActivationCode')) { |
||
0 ignored issues
–
show
|
|||
71 | printMainPage(); |
||
72 | } |
||
73 | break; // End case 'Get New Activation Code' |
||
74 | |||
75 | case 'Manage Two-Factor': |
||
76 | Util::verifySessionAndCall( |
||
77 | 'CILogon\\Service\\Content::printTwoFactorPage' |
||
78 | ); |
||
79 | break; // End case 'Manage Two-Factor' |
||
80 | |||
81 | case 'Enable': // Enable / Disable two-factor authentication |
||
82 | case 'Disable': |
||
83 | case 'Verify': // Log in with Google Authenticator |
||
84 | case 'Disable Two-Factor': |
||
85 | $enable = !preg_match('/^Disable/', $submit); |
||
86 | Util::verifySessionAndCall( |
||
87 | 'CILogon\\Service\\Content::handleEnableDisableTwoFactor', |
||
88 | array($enable) |
||
89 | ); |
||
90 | break; // End case 'Enable' / 'Disable' |
||
91 | |||
92 | case 'I Lost My Phone': |
||
93 | Util::verifySessionAndCall( |
||
94 | 'CILogon\\Service\\Content::handleILostMyPhone' |
||
95 | ); |
||
96 | break; // End case 'I Lost My Phone' |
||
97 | |||
98 | case 'Enter': // Verify Google Authenticator one time password |
||
99 | Util::verifySessionAndCall( |
||
100 | 'CILogon\\Service\\Content::handleGoogleAuthenticatorLogin' |
||
101 | ); |
||
102 | break; // End case 'Enter' |
||
103 | |||
104 | case 'EnterDuo': // Verify Duo Security login |
||
105 | Util::verifySessionAndCall( |
||
106 | 'CILogon\\Service\\Content::handleDuoSecurityLogin' |
||
107 | ); |
||
108 | break; // End case 'EnterDuo' |
||
109 | |||
110 | case 'Show Help ': // Toggle showing of help text on and off |
||
111 | case 'Hide Help ': |
||
112 | Content::handleHelpButtonClicked(); |
||
113 | break; // End case 'Show Help' / 'Hide Help' |
||
114 | |||
115 | default: // No submit button clicked nor PHP session submit variable set |
||
116 | Content::handleNoSubmitButtonClicked(); |
||
117 | break; // End default case |
||
118 | } // End switch($submit) |
||
119 | |||
120 | |||
121 | /** |
||
122 | * printLogonPage |
||
123 | * |
||
124 | * This function prints out the HTML for the main cilogon.org page. |
||
125 | * Explanatory text is shown as well as a button to log in to an IdP |
||
126 | * and get rerouted to the Shibboleth protected service script, or the |
||
127 | * OpenID script. |
||
128 | * |
||
129 | * @param bool $clearcookies True if the Shibboleth cookies and session |
||
130 | * variables should be cleared out before displaying the page. |
||
131 | * Defaults to false. |
||
132 | */ |
||
133 | function printLogonPage($clearcookies = false) |
||
134 | { |
||
135 | if ($clearcookies) { |
||
136 | Util::removeShibCookies(); |
||
137 | Util::unsetAllUserSessionVars(); |
||
138 | Util::getSkin()->init(true); // Clear cilogon_skin var; check for forced skin |
||
139 | } |
||
140 | |||
141 | $log = new Loggit(); |
||
142 | $log->info('Welcome page hit.'); |
||
143 | |||
144 | Util::setSessionVar('stage', 'logon'); // For Show/Hide Help button clicks |
||
145 | |||
146 | Content::printHeader('Welcome To The CILogon Service'); |
||
147 | |||
148 | echo ' |
||
149 | <div class="boxed"> |
||
150 | '; |
||
151 | |||
152 | Content::printHelpButton(); |
||
153 | Content::printWAYF(); |
||
154 | |||
155 | echo ' |
||
156 | </div> <!-- End boxed --> |
||
157 | '; |
||
158 | Content::printFooter(); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * printMainPage |
||
163 | * |
||
164 | * This function prints out the HTML for the main page where the user |
||
165 | * can download a certificate or generate an Activation Code. |
||
166 | */ |
||
167 | function printMainPage() |
||
168 | { |
||
169 | $log = new Loggit(); |
||
170 | $log->info('Get And Use Certificate page hit.'); |
||
171 | |||
172 | Util::setSessionVar('stage', 'main'); // For Show/Hide Help button clicks |
||
173 | |||
174 | Content::printHeader('Get Your Certificate'); |
||
175 | |||
176 | echo ' |
||
177 | <div class="boxed"> |
||
178 | '; |
||
179 | |||
180 | Content::printHelpButton(); |
||
181 | printCertInfo(); |
||
182 | printGetCertificate(); |
||
183 | printDownloadCertificate(); |
||
184 | printGetActivationCode(); |
||
185 | Content::printTwoFactorBox(); |
||
186 | printLogOff(); |
||
187 | |||
188 | echo ' |
||
189 | </div> <!-- boxed --> |
||
190 | '; |
||
191 | Content::printFooter(); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * printCertInfo |
||
196 | * |
||
197 | * This function prints the certificate information table at the top |
||
198 | * of the main page. |
||
199 | */ |
||
200 | function printCertInfo() |
||
201 | { |
||
202 | $dn = Util::getSessionVar('dn'); |
||
203 | $dn = Content::reformatDN(preg_replace('/\s+email=.+$/', '', $dn)); |
||
204 | |||
205 | echo ' |
||
206 | <table class="certinfo"> |
||
207 | <tr> |
||
208 | <th>Certificate Subject:</th> |
||
209 | <td>' , Util::htmlent($dn) , '</td> |
||
210 | </tr> |
||
211 | <tr> |
||
212 | <th>Identity Provider:</th> |
||
213 | <td>' , Util::getSessionVar('idpname') , '</td> |
||
214 | </tr> |
||
215 | <tr> |
||
216 | <th><a target="_blank" |
||
217 | href="http://ca.cilogon.org/loa">Level of Assurance:</a></th> |
||
218 | <td> |
||
219 | '; |
||
220 | |||
221 | $loa = Util::getSessionVar('loa'); |
||
222 | if ($loa == 'openid') { |
||
223 | echo '<a href="http://ca.cilogon.org/policy/openid" |
||
224 | target="_blank">OpenID</a>'; |
||
225 | } elseif ($loa == 'http://incommonfederation.org/assurance/silver') { |
||
226 | echo '<a href="http://ca.cilogon.org/policy/silver" |
||
227 | target="_blank">Silver</a>'; |
||
228 | } else { |
||
229 | echo '<a href="http://ca.cilogon.org/policy/basic" |
||
230 | target="_blank">Basic</a>'; |
||
231 | } |
||
232 | echo ' |
||
233 | </td> |
||
234 | </tr> |
||
235 | </table> |
||
236 | '; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * printGetCertificate |
||
241 | * |
||
242 | * This function prints the 'Get New Certificate' box on the main page. |
||
243 | * If the 'p12' PHP session variable is valid, it is read and a link for the |
||
244 | * usercred.p12 file is presented to the user. |
||
245 | */ |
||
246 | function printGetCertificate() |
||
247 | { |
||
248 | // Check if PKCS12 downloading is disabled. If so, print out message. |
||
249 | $skin = Util::getSkin(); |
||
250 | $disabled = $skin->getConfigOption('pkcs12', 'disabled'); |
||
251 | if ((!is_null($disabled)) && ((int)$disabled == 1)) { |
||
252 | $disabledmsg = $skin->getConfigOption( |
||
253 | 'pkcs12', |
||
254 | 'disabledmessage' |
||
255 | ); |
||
256 | if (!is_null($disabledmsg)) { |
||
257 | $disabledmsg = trim(html_entity_decode($disabledmsg)); |
||
258 | } |
||
259 | if (strlen($disabledmsg) == 0) { |
||
260 | $disabledmsg = "Downloading PKCS12 certificates is " . |
||
261 | "restricted. Please try another method or log on " . |
||
262 | "with a different Identity Provider."; |
||
263 | } |
||
264 | |||
265 | echo '<div class="p12actionbox"><p> |
||
266 | ', $disabledmsg , ' |
||
267 | </p></div> <!-- p12actionbox -->'; |
||
268 | } else { // PKCS12 downloading is okay |
||
269 | $downloadcerttext = "Clicking this button will generate a link " . |
||
270 | "to a new certificate, which you can download to your local " . |
||
271 | "computer. The certificate is valid for up to 13 months."; |
||
272 | $p12linktext = "Left-click this link to import the certificate " . |
||
273 | "into your broswer / operating system. (Firefox users see " . |
||
274 | "the FAQ.) Right-click this link and select 'Save As...' to " . |
||
275 | "save the certificate to your desktop."; |
||
276 | $passwordtext1 = 'Enter a password of at least 12 characters to " . |
||
277 | "protect your certificate.'; |
||
278 | $passwordtext2 = 'Re-enter your password to verify.'; |
||
279 | |||
280 | validateP12(); |
||
281 | $p12expire = ''; |
||
282 | $p12link = ''; |
||
283 | $p12 = Util::getSessionVar('p12'); |
||
284 | if (preg_match('/([^\s]*)\s(.*)/', $p12, $match)) { |
||
285 | $p12expire = $match[1]; |
||
286 | $p12link = $match[2]; |
||
287 | } |
||
288 | |||
289 | if ((strlen($p12link) > 0) && (strlen($p12expire) > 0)) { |
||
290 | $p12link = '<a href="' . $p12link . |
||
291 | '">» Click Here To Download Your Certificate «</a>'; |
||
292 | } |
||
293 | if ((strlen($p12expire) > 0) && ($p12expire > 0)) { |
||
294 | $expire = $p12expire - time(); |
||
295 | $minutes = floor($expire % 3600 / 60); |
||
296 | $seconds = $expire % 60; |
||
297 | $p12expire = 'Link Expires: ' . |
||
298 | sprintf("%02dm:%02ds", $minutes, $seconds); |
||
299 | } else { |
||
300 | $p12expire = ''; |
||
301 | } |
||
302 | |||
303 | $p12lifetime = Util::getSessionVar('p12lifetime'); |
||
304 | if ((strlen($p12lifetime) == 0) || ($p12lifetime == 0)) { |
||
305 | $p12lifetime = Util::getCookieVar('p12lifetime'); |
||
306 | } |
||
307 | $p12multiplier = Util::getSessionVar('p12multiplier'); |
||
308 | if ((strlen($p12multiplier) == 0) || ($p12multiplier == 0)) { |
||
309 | $p12multiplier = Util::getCookieVar('p12multiplier'); |
||
310 | } |
||
311 | |||
312 | // Try to read the skin's intiallifetime if not yet set |
||
313 | if ((strlen($p12lifetime) == 0) || ($p12lifetime <= 0)) { |
||
314 | // See if the skin specified an initial value |
||
315 | $skinlife = $skin->getConfigOption('pkcs12', 'initiallifetime', 'number'); |
||
316 | $skinmult = $skin->getConfigOption('pkcs12', 'initiallifetime', 'multiplier'); |
||
317 | if ((!is_null($skinlife)) && (!is_null($skinmult)) && |
||
318 | ((int)$skinlife > 0) && ((int)$skinmult > 0)) { |
||
319 | $p12lifetime = (int)$skinlife; |
||
320 | $p12multiplier = (int)$skinmult; |
||
321 | } else { |
||
322 | $p12lifetime = 13; // Default to 13 months |
||
323 | $p12multiplier = 732; |
||
324 | } |
||
325 | } |
||
326 | if ((strlen($p12multiplier) == 0) || ($p12multiplier <= 0)) { |
||
327 | $p12multiplier = 732; // Default to months |
||
328 | if ($p12lifetime > 13) { |
||
329 | $p12lifetime = 13; |
||
330 | } |
||
331 | } |
||
332 | |||
333 | // Make sure lifetime is within [minlifetime,maxlifetime] |
||
334 | list($minlifetime, $maxlifetime) = |
||
335 | Content::getMinMaxLifetimes('pkcs12', 9516); |
||
336 | if (($p12lifetime * $p12multiplier) < $minlifetime) { |
||
337 | $p12lifetime = $minlifetime; |
||
338 | $p12multiplier = 1; // In hours |
||
339 | } elseif (($p12lifetime * $p12multiplier) > $maxlifetime) { |
||
340 | $p12lifetime = $maxlifetime; |
||
341 | $p12multiplier = 1; // In hours |
||
342 | } |
||
343 | |||
344 | $lifetimetext = "Specify the certificate lifetime. Acceptable range " . |
||
345 | "is between $minlifetime and $maxlifetime hours" . |
||
346 | (($maxlifetime > 732) ? |
||
347 | " ( = " . round(($maxlifetime / 732), 2) . " months)." : |
||
348 | "." |
||
349 | ); |
||
350 | |||
351 | echo ' |
||
352 | <div class="p12actionbox"'; |
||
353 | |||
354 | if (Util::getSessionVar('showhelp') == 'on') { |
||
355 | echo ' style="width:92%;"'; |
||
356 | } |
||
357 | |||
358 | echo '> |
||
359 | <table class="helptable"> |
||
360 | <tr> |
||
361 | <td class="actioncell"> |
||
362 | '; |
||
363 | |||
364 | Content::printFormHead(); |
||
365 | |||
366 | echo ' |
||
367 | <fieldset> |
||
368 | '; |
||
369 | |||
370 | $p12error = Util::getSessionVar('p12error'); |
||
371 | if (strlen($p12error) > 0) { |
||
372 | echo "<p class=\"logonerror\">$p12error</p>"; |
||
373 | Util::unsetSessionVar('p12error'); |
||
374 | } |
||
375 | |||
376 | echo ' |
||
377 | <p> |
||
378 | Password Protect Your New Certificate: |
||
379 | </p> |
||
380 | |||
381 | <p> |
||
382 | <label for="password1" class="helpcursor" title="' , |
||
383 | $passwordtext1 , '">Enter A Password:</label> |
||
384 | <input type="password" name="password1" id="password1" |
||
385 | size="22" title="' , $passwordtext1 , '" onkeyup="checkPassword()"/> |
||
386 | <img src="/images/blankIcon.png" width="14" height="14" alt="" |
||
387 | id="pw1icon"/> |
||
388 | </p> |
||
389 | |||
390 | <p> |
||
391 | <label for="password2" class="helpcursor" title="' , |
||
392 | $passwordtext2 , '">Confirm Password:</label> |
||
393 | <input type="password" name="password2" id="password2" |
||
394 | size="22" title="' , $passwordtext2 , '" onkeyup="checkPassword()"/> |
||
395 | <img src="/images/blankIcon.png" width="14" height="14" alt="" |
||
396 | id="pw2icon"/> |
||
397 | </p> |
||
398 | |||
399 | <p class="p12certificatelifetime"> |
||
400 | <label for="p12lifetime" title="' , $lifetimetext , |
||
401 | '" class="helpcursor">Certificate Lifetime:</label> |
||
402 | <input type="text" name="p12lifetime" id="p12lifetime" |
||
403 | title="', $lifetimetext , |
||
404 | '" class="helpcursor" value="' , $p12lifetime , |
||
405 | '" size="8" maxlength="8"/> |
||
406 | <select title="' , $lifetimetext , |
||
407 | '" class="helpcursor" id="p12multiplier" name="p12multiplier"> |
||
408 | <option value="1"' , |
||
409 | (($p12multiplier == 1) ? ' selected="selected"' : '') , |
||
410 | '>hours</option> |
||
411 | <option value="24"' , |
||
412 | (($p12multiplier == 24) ? ' selected="selected"' : '') , |
||
413 | '>days</option> |
||
414 | <option value="732"' , |
||
415 | (($p12multiplier == 732) ? ' selected="selected"' : '') , |
||
416 | '>months</option> |
||
417 | </select> |
||
418 | <img src="/images/blankIcon.png" width="14" height="14" alt=""/> |
||
419 | </p> |
||
420 | |||
421 | <p> |
||
422 | <input type="submit" name="submit" class="submit helpcursor" |
||
423 | title="' , $downloadcerttext , '" value="Get New Certificate" |
||
424 | onclick="showHourglass(\'p12\')"/> |
||
425 | <img src="/images/hourglass.gif" width="32" height="32" alt="" |
||
426 | class="hourglass" id="p12hourglass"/> |
||
427 | </p> |
||
428 | |||
429 | <p id="p12value" class="helpcursor" title="' , |
||
430 | $p12linktext , '">' , $p12link , '</p> |
||
431 | <p id="p12expire">' , $p12expire , '</p> |
||
432 | |||
433 | </fieldset> |
||
434 | </form> |
||
435 | </td> |
||
436 | '; |
||
437 | |||
438 | if (Util::getSessionVar('showhelp') == 'on') { |
||
439 | echo ' |
||
440 | <td class="helpcell"> |
||
441 | <div> |
||
442 | <p> |
||
443 | In order to get a new certificate, please enter a password of at |
||
444 | least 12 characters in length. This password protects the private |
||
445 | key of the certificate and is different from your identity provider |
||
446 | password. You must enter the password twice for verification. |
||
447 | </p> |
||
448 | <p> |
||
449 | After entering a password, click the "Get New Certificate" button to |
||
450 | generate a new link. Right-click on this link to download the |
||
451 | certificate to your computer. The certificate is valid for up to 13 |
||
452 | months. |
||
453 | </p> |
||
454 | </div> |
||
455 | </td> |
||
456 | '; |
||
457 | } |
||
458 | |||
459 | echo ' |
||
460 | </tr> |
||
461 | </table> |
||
462 | </div> <!-- p12actionbox --> |
||
463 | '; |
||
464 | } |
||
465 | } |
||
466 | |||
467 | /** |
||
468 | * printDownlaodCertificate |
||
469 | * |
||
470 | * This function prints the 'Download Certificate' box, which uses the |
||
471 | * GridShib-CA JWS client to download a certificate for the user. |
||
472 | */ |
||
473 | function printDownloadCertificate() |
||
474 | { |
||
475 | $gridshibconf = Util::parseGridShibConf(); |
||
476 | $idpname = Util::getSessionVar('idpname'); |
||
0 ignored issues
–
show
$idpname is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
477 | |||
478 | $downloadcerttext = "Download a certificate to your local computer. " . |
||
479 | "Clicking this button should launch a Java Web Start (JWS) " . |
||
480 | "application, which requires Java to be installed on your " . |
||
481 | "computer and enabled in your web browser."; |
||
482 | |||
483 | echo ' |
||
484 | <div class="certactionbox"'; |
||
485 | |||
486 | if (Util::getSessionVar('showhelp') == 'on') { |
||
487 | echo ' style="width:92%;"'; |
||
488 | } |
||
489 | |||
490 | echo '> |
||
491 | <table class="helptable"> |
||
492 | <tr> |
||
493 | <td class="actioncell"> |
||
494 | '; |
||
495 | |||
496 | // CIL-593 - Add note to retire Download Certificate |
||
497 | echo ' |
||
498 | <div> |
||
499 | <p style="color:red;font-weight:bold"> |
||
500 | "Download Certificate" will be retired 2019-10-01. Please use "Get New Certificate" above instead. |
||
501 | </p> |
||
502 | </div> |
||
503 | '; |
||
504 | |||
505 | Content::printFormHead( |
||
506 | preg_replace( |
||
507 | '/^\s*=\s*/', |
||
508 | '', |
||
509 | $gridshibconf['root']['GridShibCAURL'] |
||
510 | ) . 'shibCILaunchGSCA.jnlp', |
||
511 | 'post', |
||
512 | true |
||
513 | ); |
||
514 | |||
515 | $certlifetime = Util::getCookieVar('certlifetime'); |
||
516 | $certmultiplier = Util::getCookieVar('certmultiplier'); |
||
517 | |||
518 | // Try to read the skin's initiallifetime if not yet set |
||
519 | if ((strlen($certlifetime) == 0) || ($certlifetime <= 0)) { |
||
520 | $skin = Util::getSkin(); |
||
521 | $skinlife = $skin->getConfigOption('gsca', 'initiallifetime', 'number'); |
||
522 | $skinmult = $skin->getConfigOption('gsca', 'initiallifetime', 'multiplier'); |
||
523 | if ((!is_null($skinlife)) && (!is_null($skinmult)) && |
||
524 | ((int)$skinlife > 0) && ((int)$skinmult > 0)) { |
||
525 | $certlifetime = (int)$skinlife; |
||
526 | $certmultiplier = (int)$skinmult; |
||
527 | } else { // Use gridshib-ca.conf default value |
||
528 | $certlifetime = round(preg_replace( |
||
529 | '/^\s*=\s*/', |
||
530 | '', |
||
531 | $gridshibconf['root']['CA']['DefaultCredLifetime'] |
||
532 | ) / 3600); |
||
533 | $certmultiplier = 3600; |
||
534 | } |
||
535 | } |
||
536 | if ((strlen($certmultiplier) == 0) || ($certmultiplier <= 0)) { |
||
537 | $certmultiplier = 3600; // Default to hours |
||
538 | } |
||
539 | |||
540 | // Make sure lifetime is within [minlifetime,maxlifetime] |
||
541 | $defaultmaxlifetime = preg_replace( |
||
542 | '/^\s*=\s*/', |
||
543 | '', |
||
544 | $gridshibconf['root']['CA']['MaximumCredLifetime'] |
||
545 | ) / 3600; |
||
546 | list($minlifetime, $maxlifetime) = |
||
547 | Content::getMinMaxLifetimes('gsca', $defaultmaxlifetime); |
||
548 | if (($certlifetime * $certmultiplier / 3600) < $minlifetime) { |
||
549 | $certlifetime = $minlifetime; |
||
550 | $certmultiplier = 3600; // In hours |
||
551 | } elseif (($certlifetime * $certmultiplier / 3600) > $maxlifetime) { |
||
552 | $certlifetime = $maxlifetime; |
||
553 | $certmultiplier = 3600; // In hours |
||
554 | } |
||
555 | |||
556 | $lifetimetext = "Specify the certificate lifetime. Acceptable range " . |
||
557 | "is between $minlifetime and $maxlifetime hours" . |
||
558 | (($maxlifetime > 732) ? |
||
559 | " ( = " . round(($maxlifetime / 732), 2) . " months)." : |
||
560 | "." |
||
561 | ); |
||
562 | |||
563 | $maxcleartextlifetime = preg_replace( |
||
564 | '/^\s*=\s*/', |
||
565 | '', |
||
566 | $gridshibconf['root']['LaunchClient']['MaxCleartextLifetime'] |
||
567 | ) / 3600; |
||
568 | if (($maxcleartextlifetime > 0) && |
||
569 | ($maxlifetime >= $maxcleartextlifetime)) { |
||
570 | $lifetimetext .= " Lifetimes greater than " . |
||
571 | round(($maxcleartextlifetime / 24), 2) . |
||
572 | " days will require you to specify a passphrase."; |
||
573 | } |
||
574 | |||
575 | echo ' |
||
576 | <fieldset> |
||
577 | <p class="jwscertificatelifetime"> |
||
578 | <label for="certlifetime" title="' , $lifetimetext , |
||
579 | '" class="helpcursor">Lifetime:</label> |
||
580 | <input type="text" name="certlifetime" id="certlifetime" |
||
581 | title="', $lifetimetext , |
||
582 | '" class="helpcursor" value="' , $certlifetime , |
||
583 | '" size="8" maxlength="8" disabled="disabled"/> |
||
584 | <select title="' , $lifetimetext , |
||
585 | '" class="helpcursor" id="certmultiplier" name="certmultiplier" |
||
586 | disabled="disabled"> |
||
587 | <option value="3600"' , |
||
588 | (($certmultiplier == 3600) ? ' selected="selected"' : '') , |
||
589 | '>hours</option> |
||
590 | <option value="86400"' , |
||
591 | (($certmultiplier == 86400) ? ' selected="selected"' : '') , |
||
592 | '>days</option> |
||
593 | <option value="2635200"' , |
||
594 | (($certmultiplier == 2635200) ? ' selected="selected"' : '') , |
||
595 | '>months</option> |
||
596 | </select> |
||
597 | <input type="hidden" name="minlifetime" id="minlifetime" value="' , |
||
598 | $minlifetime * 3600 , '" /> |
||
599 | <input type="hidden" name="maxlifetime" id="maxlifetime" value="' , |
||
600 | $maxlifetime * 3600 , '" /> |
||
601 | <input type="hidden" name="RequestedLifetime" id="RequestedLifetime" |
||
602 | value="' , ($certlifetime * $certmultiplier) , '" /> |
||
603 | </p> |
||
604 | <p> |
||
605 | <input type="submit" name="submit" class="submit helpcursor" |
||
606 | title="' , $downloadcerttext , |
||
607 | '" value="Download Certificate" onclick="handleLifetime();" /> |
||
608 | </p> |
||
609 | <p class="smaller zeroheight" id="mayneedjava"> |
||
610 | You may need to install <a target="_blank" |
||
611 | href="http://www.javatester.org/version.html">Java</a>. |
||
612 | </p> |
||
613 | </fieldset> |
||
614 | |||
615 | <noscript> |
||
616 | <div class="nojs smaller"> |
||
617 | JavaScript must be enabled to specify Lifetime. |
||
618 | </div> |
||
619 | </noscript> |
||
620 | |||
621 | </form> |
||
622 | </td> |
||
623 | '; |
||
624 | |||
625 | if (Util::getSessionVar('showhelp') == 'on') { |
||
626 | echo ' |
||
627 | <td class="helpcell"> |
||
628 | <div> |
||
629 | <p> |
||
630 | When you click on the "Download Certificate" button, a JNLP file is |
||
631 | downloaded to your computer which will launch Java Web Start |
||
632 | (assuming <a target="_blank" |
||
633 | href="http://java.com/getjava/">Java</a> is correctly installed on |
||
634 | your machine). This will run the CILogon Certificate Retriever |
||
635 | program to download a certificate. The program may prompt you to |
||
636 | enter a password of at least 12 characters to protect the private |
||
637 | key of the certificate. This password is different from your |
||
638 | identity provider password. |
||
639 | </p> |
||
640 | </div> |
||
641 | </td> |
||
642 | '; |
||
643 | } |
||
644 | |||
645 | echo ' |
||
646 | </tr> |
||
647 | </table> |
||
648 | </div> <!-- certactionbox --> |
||
649 | '; |
||
650 | } |
||
651 | |||
652 | /** |
||
653 | * printGetActivationCode |
||
654 | * |
||
655 | * This function prints the 'Get New Activation Code' box on the main |
||
656 | * page. If the 'activation' PHP session variable is valid, it is |
||
657 | * shown at the bottom of the box. The Activation Code can be used by |
||
658 | * the GridShib-CA python client to fetch a certificate. |
||
659 | */ |
||
660 | function printGetActivationCode() |
||
661 | { |
||
662 | $generatecodetext = "Get a new one-time-use activation code for " . |
||
663 | "CILogon-enabled applications."; |
||
664 | $tokenhelptext = "Click the button below to display a one-time-use " . |
||
665 | "activation code for CILogon-enabled applications. You can copy " . |
||
666 | "and paste this code into the application to download a " . |
||
667 | "certificate. See FAQ for more information."; |
||
668 | $tokenvaluetext = 'Copy and paste the one-time-use activation code " . |
||
669 | "into your CILogon-enabled application to download a certificate.'; |
||
670 | |||
671 | echo ' |
||
672 | <div class="tokenactionbox"'; |
||
673 | |||
674 | if (Util::getSessionVar('showhelp') == 'on') { |
||
675 | echo ' style="width:92%;"'; |
||
676 | } |
||
677 | |||
678 | echo '> |
||
679 | <table class="helptable"> |
||
680 | <tr> |
||
681 | <td class="actioncell"> |
||
682 | '; |
||
683 | |||
684 | Content::printFormHead(); |
||
685 | |||
686 | validateActivationCode(); |
||
687 | $tokenvalue = ''; |
||
688 | $tokenexpire = ''; |
||
689 | $activation = Util::getSessionVar('activation'); |
||
690 | if (preg_match('/([^\s]*)\s(.*)/', $activation, $match)) { |
||
691 | $tokenexpire = $match[1]; |
||
692 | $tokenvalue = $match[2]; |
||
693 | } |
||
694 | if ((strlen($tokenvalue) > 0) && (strlen($tokenexpire) > 0)) { |
||
695 | $tokenvalue = 'Activation Code: ' . $tokenvalue; |
||
696 | } |
||
697 | if ((strlen($tokenexpire) > 0) && ($tokenexpire > 0)) { |
||
698 | $expire = $tokenexpire - time(); |
||
699 | $minutes = floor($expire % 3600 / 60); |
||
700 | $seconds = $expire % 60; |
||
701 | $tokenexpire = 'Code Expires: ' . |
||
702 | sprintf("%02dm:%02ds", $minutes, $seconds); |
||
703 | } else { |
||
704 | $tokenexpire = ''; |
||
705 | } |
||
706 | |||
707 | echo ' |
||
708 | <p class="helpcursor" title="' , |
||
709 | $tokenhelptext , '">For CILogon-enabled Applications:</p> |
||
710 | <p> |
||
711 | |||
712 | <input type="submit" name="submit" class="submit helpcursor" |
||
713 | title="' , $generatecodetext , '" value="Get New Activation Code" |
||
714 | onclick="showHourglass(\'token\')"/> |
||
715 | <img src="/images/hourglass.gif" width="32" height="32" alt="" |
||
716 | class="hourglass" id="tokenhourglass"/> |
||
717 | </p> |
||
718 | <p id="tokenvalue" class="helpcursor" title="' , |
||
719 | $tokenvaluetext , '">' , $tokenvalue , '</p> |
||
720 | <p id="tokenexpire">' , $tokenexpire , '</p> |
||
721 | |||
722 | </form> |
||
723 | </td> |
||
724 | '; |
||
725 | |||
726 | if (Util::getSessionVar('showhelp') == 'on') { |
||
727 | echo ' |
||
728 | <td class="helpcell"> |
||
729 | <div> |
||
730 | <p> |
||
731 | An Activation Code can be used by a <a target="_blank" |
||
732 | href="http://www.cilogon.org/enabled">CILogon-enabled |
||
733 | Application</a> to download a certificate. Click the "Get New |
||
734 | Activation Code" button to generate a random sequence of letters and |
||
735 | numbers. Highlight the activation code (e.g. double-click it), copy |
||
736 | the code from your browser, and paste it into the CILogon-enabled |
||
737 | application. |
||
738 | </p> |
||
739 | </div> |
||
740 | </td> |
||
741 | '; |
||
742 | } |
||
743 | |||
744 | echo ' |
||
745 | </tr> |
||
746 | </table> |
||
747 | </div> <!-- tokenactionbox --> |
||
748 | '; |
||
749 | } |
||
750 | |||
751 | /** |
||
752 | * printLogOff |
||
753 | * |
||
754 | * This function prints the Log Off boxes at the bottom of the main page. |
||
755 | */ |
||
756 | function printLogOff() |
||
757 | { |
||
758 | $logofftext = 'End your CILogon session and return to the welcome page. ' . |
||
759 | 'Note that this will not log you out at ' . |
||
760 | Util::getSessionVar('idpname') . '.'; |
||
761 | |||
762 | $showhelp = Util::getSessionVar('showhelp'); |
||
763 | |||
764 | echo ' |
||
765 | <div class="logoffactionbox"'; |
||
766 | |||
767 | if ($showhelp == 'on') { |
||
768 | echo ' style="width:92%;"'; |
||
769 | } |
||
770 | |||
771 | echo '> |
||
772 | <table class="helptable"> |
||
773 | <tr> |
||
774 | <td class="actioncell"> |
||
775 | '; |
||
776 | |||
777 | Content::printFormHead(); |
||
778 | |||
779 | echo ' |
||
780 | <p> |
||
781 | <input type="submit" name="submit" class="submit helpcursor" |
||
782 | title="' , $logofftext , '" value="Log Off" /> |
||
783 | </p> |
||
784 | </form> |
||
785 | </td> |
||
786 | '; |
||
787 | |||
788 | if ($showhelp == 'on') { |
||
789 | echo ' |
||
790 | <td class="helpcell"> |
||
791 | <div> |
||
792 | <p> |
||
793 | This button will log you off of the CILogon Service. In order to log |
||
794 | out from your identity provider, you must either quit your browser |
||
795 | or manually clear your browser\'s cookies. |
||
796 | </p> |
||
797 | </div> |
||
798 | </td> |
||
799 | '; |
||
800 | } |
||
801 | |||
802 | echo ' |
||
803 | </tr> |
||
804 | </table> |
||
805 | </div> <!-- logoffactionbox --> |
||
806 | |||
807 | <div class="logofftextbox"'; |
||
808 | |||
809 | if ($showhelp == 'on') { |
||
810 | echo ' style="width:92%;"'; |
||
811 | } |
||
812 | |||
813 | echo '> |
||
814 | <table class="helptable"> |
||
815 | <tr> |
||
816 | <td class="actioncell"> |
||
817 | <p>To log off, please quit your browser.<p> |
||
818 | </td> |
||
819 | '; |
||
820 | |||
821 | if ($showhelp == 'on') { |
||
822 | echo ' |
||
823 | <td class="helpcell"> |
||
824 | <div> |
||
825 | <p> |
||
826 | Quitting your browser clears all session cookies which logs you out |
||
827 | from your identity provider. Alternatively, you can manually clear |
||
828 | your browser\'s cookies. |
||
829 | </p> |
||
830 | </div> |
||
831 | </td> |
||
832 | '; |
||
833 | } |
||
834 | |||
835 | echo ' |
||
836 | </tr> |
||
837 | </table> |
||
838 | </div> <!-- logofftextbox --> |
||
839 | '; |
||
840 | } |
||
841 | |||
842 | /** |
||
843 | * generateActivationCode |
||
844 | * |
||
845 | * This function is called when the user clicks the 'Get New Activation |
||
846 | * Code' button. It calls the GridShib CA functionality to create a |
||
847 | * .jnlp file, uses 'curl' to slurp in the resulting .jnlp file, and |
||
848 | * scans for the AuthenticationToken in the file. This is stored in |
||
849 | * the 'activation' PHP session value to be output to the user when |
||
850 | * the Main Page is redrawn. The token can be used by the GridShib-CA |
||
851 | * python client to fetch a certificate. |
||
852 | */ |
||
853 | function generateActivationCode() |
||
854 | { |
||
855 | $tokenvalue = ''; |
||
856 | $gridshibconf = Util::parseGridShibConf(); |
||
857 | |||
858 | $ch = curl_init(); |
||
859 | if ($ch !== false) { |
||
860 | $csrf = Util::getCsrf(); |
||
861 | $url = 'https://' . Util::getHN() . preg_replace( |
||
862 | '/^\s*=\s*/', |
||
863 | '', |
||
864 | $gridshibconf['root']['GridShibCAURL'] |
||
865 | ) . 'shibCILaunchGSCA.jnlp'; |
||
866 | curl_setopt($ch, CURLOPT_URL, $url); |
||
867 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
868 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
||
869 | curl_setopt($ch, CURLOPT_POST, true); |
||
870 | curl_setopt($ch, CURLOPT_HEADER, false); |
||
871 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||
872 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
||
873 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||
874 | curl_setopt($ch, CURLOPT_POSTFIELDS, 'CSRFProtection=' . |
||
875 | $csrf->getTokenValue()); |
||
876 | curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=' . |
||
877 | Util::getCookieVar('PHPSESSID') . '; CSRFProtection=' . |
||
878 | $csrf->getTokenValue() . ';'); |
||
879 | |||
880 | // Must close PHP session file so GridShib-CA can read it. |
||
881 | session_write_close(); |
||
882 | $output = curl_exec($ch); |
||
883 | if (curl_errno($ch)) { // Send alert on curl errors |
||
884 | Util::sendErrorAlert( |
||
885 | 'cUrl Error', |
||
886 | 'cUrl Error = ' . curl_error($ch) . "\n" . |
||
887 | "URL Accessed = $url" |
||
888 | ); |
||
889 | } |
||
890 | if (!empty($output)) { |
||
891 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
892 | if ($httpcode == 200) { |
||
893 | if (preg_match( |
||
894 | '/AuthenticationToken = ([^<]+)/', |
||
895 | $output, |
||
896 | $match |
||
897 | )) { |
||
898 | $tokenvalue = $match[1]; |
||
899 | } |
||
900 | } |
||
901 | } |
||
902 | curl_close($ch); |
||
903 | |||
904 | // If we got a valid AuthenticationToken, store it in the session. |
||
905 | Util::startPHPSession(); |
||
906 | if (strlen($tokenvalue) > 0) { |
||
907 | $tokenlifetime = preg_replace( |
||
908 | '/^\s*=\s*/', |
||
909 | '', |
||
910 | $gridshibconf['root']['Session']['CredentialRetrieverClientLifetime'] |
||
911 | ); |
||
912 | if ((strlen($tokenlifetime) == 0) || ($tokenlifetime == 0)) { |
||
913 | $tokenlifetime = 300; |
||
914 | } |
||
915 | $activation = (time() + $tokenlifetime) . " " . $tokenvalue; |
||
916 | Util::setSessionVar('activation', $activation); |
||
917 | $log = new Loggit(); |
||
918 | $log->info('Generated New Activation Code="' . $tokenvalue . '"'); |
||
919 | } |
||
920 | } |
||
921 | } |
||
922 | |||
923 | /** |
||
924 | * validateP12 |
||
925 | * |
||
926 | * This function is called just before the 'Download your certificate' |
||
927 | * link is printed out to HTML. It checks to see if the p12 is still |
||
928 | * valid time-wise. If not, then it unsets the PHP session variable |
||
929 | * 'p12'. |
||
930 | */ |
||
931 | function validateP12() |
||
932 | { |
||
933 | $p12link = ''; |
||
934 | $p12expire = ''; |
||
935 | $p12 = Util::getSessionVar('p12'); |
||
936 | if (preg_match('/([^\s]*)\s(.*)/', $p12, $match)) { |
||
937 | $p12expire = $match[1]; |
||
938 | $p12link = $match[2]; |
||
939 | } |
||
940 | |||
941 | // Verify that the p12expire and p12link values are valid. |
||
942 | if ((strlen($p12expire) == 0) || |
||
943 | ($p12expire == 0) || |
||
944 | (time() > $p12expire) || |
||
945 | (strlen($p12link) == 0)) { |
||
946 | Util::unsetSessionVar('p12'); |
||
947 | } |
||
948 | } |
||
949 | |||
950 | /** |
||
951 | * validateActivationCode |
||
952 | * |
||
953 | * This function is called just before the certificate token is printed |
||
954 | * out to HTML. It checks to see if the activation token value is |
||
955 | * expired. If so, it unsets the PHP session variable 'activation'. |
||
956 | */ |
||
957 | function validateActivationCode() |
||
958 | { |
||
959 | $tokenvalue = ''; |
||
0 ignored issues
–
show
$tokenvalue is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
960 | $tokenexpire = ''; |
||
961 | $activation = Util::getSessionVar('activation'); |
||
962 | if (preg_match('/([^\s]*)\s(.*)/', $activation, $match)) { |
||
963 | $tokenexpire = $match[1]; |
||
964 | $tokenvalue = $match[2]; |
||
0 ignored issues
–
show
$tokenvalue is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
965 | } |
||
966 | |||
967 | // If there is a tokenexpire value, check against current time. |
||
968 | if ((strlen($tokenexpire) == 0) || |
||
969 | ($tokenexpire == 0) || |
||
970 | (time() > $tokenexpire)) { |
||
971 | Util::unsetSessionVar('activation'); |
||
972 | } |
||
973 | } |
||
974 | |||
975 | // Util::$timeit->printTime('MAIN Program END... '); |
||
976 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: