summaryrefslogtreecommitdiffstats
path: root/base/tps/apache/docroot/esc/SettingsEsc.html
blob: 8dd4be5232c4dd555763c158e232e20ceb57d42b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
<!-- --- BEGIN COPYRIGHT BLOCK ---
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; version 2 of the License.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

     Copyright (C) 2009 Red Hat, Inc.
     All rights reserved.
     --- END COPYRIGHT BLOCK --- -->
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>

<link rel=stylesheet href="/pki/style.css" type="text/css">

<script lang="JavaScript">
//
// initialize netkey globals
var netkey;
var gNotify = null;
var isMSHTML;

//
// Determine if we are running MSHTML or GECKO
//
if (navigator.userAgent.indexOf("MSIE") != -1) {
  isMSHTML = true;
} else {
  isMSHTML = false;
}


//
// Notify callback for GECKO
//
function jsNotify()  {}

jsNotify.prototype = {

  rhNotifyKeyStateChange: function(aKeyType,aKeyID,aKeyState,aData,strData)
  {

    OnCOOLKeyStateChange(aKeyType, aKeyID, aKeyState, aData);
  },

  QueryInterface: function(iid)
  {
    <!--  alert("iid: " + iid); -->
     if(!iid.equals(Components.interfaces.rhIKeyNotify) &&
         !iid.equals(Components.interfaces.nsISupports))
      {
          alert("Can't find jsNotify interface");
          throw Components.results.NS_ERROR_NO_INTERFACE;
      }
      return this;
  }
};

//
// Attach to the object.
//
if (!isMSHTML) {
  // GECKO ONLY initialization
  try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    netkey = Components.classes["@redhat.com/rhCoolKey"].getService();
    netkey = netkey.QueryInterface(Components.interfaces.rhICoolKey);

    gNotify = new jsNotify;

    netkey.rhCoolKeySetNotifyCallback(gNotify);

  } catch(e) {
     alert("Can't get UniversalXPConnect: " + e);
  }
} else {
  // MSHTML only initialization
  netkey = external;
}

//
// unregister our notify event
//
function cleanup()
{
  if (!isMSHTML) {
    try {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");


      netkey.rhCoolKeyUnSetNotifyCallback(gNotify);
    } catch(e) {
     alert("Can't get UniversalXPConnect: " + e);
    }
  }
}


////////////////////////////////////////////////////////////////
//
// Host will be responsible for generating the gBindingsArray.
//
////////////////////////////////////////////////////////////////

var gBindingsArray = [
  <!-- SECURECOOL_BINDINGS_ARRAY -->
];

////////////////////////////////////////////////////////////////
//
// Utility functions specific to this page.
//
////////////////////////////////////////////////////////////////

var gKeyBusyArray = [ ];

function KeyToRowID(keyType, keyID)
{
  return keyType + "--" + keyID;
}

function RowIDToKeyInfo(rowID)
{
  return rowID.split("--");
}

function GetRowForKey(keyType, keyID)
{
  return document.getElementById(KeyToRowID(keyType, keyID));
}

function LoadBindingsIntoTable()
{
  var table = document.getElementById("KeyTable");

  if (table)
  {
    var i;
    for (i=0; i < gBindingsArray.length; i++)
    {
      CreateTableRow(table, gBindingsArray[i][0], gBindingsArray[i][1], false,
                     gBindingsArray[i][2], true);
    }
  }
}

function InsertCOOLKeyIntoBindingTable(keyType, keyID)
{
  var row = GetRowForKey(keyType, keyID);

  if (!row)
  {
    var table = document.getElementById("KeyTable");
    if (table)
    {
      // The assumption here is that if the key isn't already
      // listed in the table, then it must be a new unbound key!

      row = CreateTableRow(table, keyType, keyID, true, keyID, false);
    }

    if (!row)
      return null;
  }
  else if (IsKeyBound(keyType, keyID))
    SetKeyIsVisible(row, true);

  return row;
}

function ConvertVariantArrayToJScriptArray(varr)
{
  // C++ native methods, like netkey.GetAvailableCOOLKeys(), can only
  // return variant SafeArrays, so to access the data inside, you must
  // first convert it to a VBArray, and then call toArray() to convert
  // it to a JScript array. Lame, but that's what it takes to
  // use an array returned from an ActiveX component.

  return new VBArray(varr).toArray();
}

function ReportException(msg, e)
{
  alert(msg + " " + e.description + "(" + e.number + ")");
}

function GetAvailableCOOLKeys()
{
  try {
    var keyArr;

    if (!isMSHTML) {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
      var inArray = netkey.GetAvailableCoolKeys( {} );
      keyArr = new Array(inArray.length);
      var i;

      for (i=0; i < keyArr.length; i++) {
	keyArr[i] = new Array( "1", inArray[i]);
      }
    } else {
      keyArr = ConvertVariantArrayToJScriptArray(netkey.GetAvailableCoolKeys());

      var i;
      for (i=0; i < keyArr.length; i++)
        keyArr[i] = ConvertVariantArrayToJScriptArray(keyArr[i]);
    }
    return keyArr;
  } catch(e) {
    ReportException("netkey.GetAvailableCoolKeys() failed!", e);
    return [];
  }
}

function BlinkCOOLKey(keyType, keyID, rate, duration)
{
  try {
    if (!isMSHTML) {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    }
    netkey.BlinkCoolKey(keyType, keyID, rate, duration);
  } catch(e) {
    ReportException("netkey.BlinkCoolKey() failed!", e);
    return false;
  }
  return true;
}

//
// MSHTML/GECKO compatibility functions.
//
function RemoveRow(table, row)
{
  if (isMSHTML) {
    row.removeNode(row);
  } else {
    table.deleteRow(row.rowIndex);
  }
}

function InsertRow(table)
{
  var row;

  if (isMSHTML) {
    row = table.insertRow();
  } else {
    row = table.insertRow(table.rows.length);
  }
  return row;
}

function InsertCell(row)
{
  var cell;

  if (isMSHTML) {
    cell = row.insertCell();
  } else {
    cell = row.insertCell(row.cells.length);
  }
  return cell;
}

function UpdateBindingTableAvailability()
{
  var arr = GetAvailableCOOLKeys();

  if (!arr || arr.length < 1)
    return;

  var i;

  for (i=0; i < arr.length; i++)
    InsertCOOLKeyIntoBindingTable(arr[i][0], arr[i][1]);
}

function InitializeBindingTable()
{
  LoadBindingsIntoTable();
  UpdateBindingTableAvailability();
}

function IsKeyBound(keyType, keyID)
{
  
  for (i=0; i < gBindingsArray.length; i++)
  {
    if (keyType == gBindingsArray[i][0] && keyID == gBindingsArray[i][1])
      return true;
  }

  return false;
}

function COOLKeyIsBusy(keyType, keyID)
{
  for (i=0; i < gKeyBusyArray.length; i++)
  {
    if (keyType == gKeyBusyArray[i][0] && keyID == gKeyBusyArray[i][1])
      return true;
  }

  return false;
}

function AddKeyToBusyArray(keyType, keyID)
{
  // If key is already in our array, nothing to do.
  if (COOLKeyIsBusy(keyType, keyID))
    return;

  gKeyBusyArray.push(new Array(keyType, keyID));
}

function RemoveKeyFromBusyArray(keyType, keyID)
{
  for (i=0; i < gKeyBusyArray.length; i++)
  {
    if (keyType == gKeyBusyArray[i][0] && keyID == gKeyBusyArray[i][1])
      gKeyBusyArray.splice(i, 1);
  }
}

function SetKeyIsVisible(row, isVisible)
{
  if (!row) return;
  var cell = row.cells(0);
  if (!cell) return;

  var v = "inherit";
  if (!isVisible)
    v = "hidden";
  cell.firstChild.style.visibility = v;
}

function KeyToUIString(keyType, keyID)
{
  // If it's an COOLKey, format the keyID string.

  if (keyType == 1 && keyID.length == 20)
  {
    var re = /([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})/i;
    keyID = keyID.replace(re, "$1-$2-$3-$4-$5").toLowerCase();
  }

  return keyID;
}

function CreateTableRow(table, keyType, keyID, isAvailable, label, isSecured)
{
  
  var row = InsertRow(table);
  if (!row)
    return null;

  row.setAttribute("id", KeyToRowID(keyType, keyID));

  var keyIDStr = KeyToUIString(keyType, keyID);

  if (label == keyID)
    label = keyIDStr;

  // Add a tooltip to the row so that it displays more info.
  var title = keyType + " - " + keyIDStr;
  if (isSecured && label)
    title += " - " + label;
  row.setAttribute("title", title);

  // Create the isAvailable cell:
  cell = InsertCell(row);
  cell.setAttribute("align", "center");
  var a = document.createElement("a");
  a.setAttribute("href", "javascript:DoBlinkCOOLKey(" + keyType + ", '" + keyID + "');");
  if (! isAvailable)
    a.style.visibility = "hidden";
  var img = document.createElement("img");
  img.setAttribute("src", "/pki/esc/images/NetKey-Small.gif");
  a.appendChild(img);
  cell.appendChild(a);

  // Create the label cell. Make sure we truncate long
  // labels so that they fit nicely into the window.
  cell = InsertCell(row);
  if (label.length > 24)
    label = label.substr(0, 24) + "...";
  cell.appendChild(document.createTextNode(label));

  // Create the action cell:
  cell = InsertCell(row);
  a = document.createElement("a");
  if (isSecured)
  {
  //  a.setAttribute("href", "javascript:UnbindCOOLKey(" + keyType + ", '" + keyID + "');");
    a.appendChild(document.createTextNode("Release"));
  }
  else
  {
  //  a.setAttribute("href", "javascript:BindCOOLKey(" + keyType + ", '" + keyID + "');");
    a.appendChild(document.createTextNode("Secure"));
  }
  cell.appendChild(a);

  // Create the secured cell:
  cell = InsertCell(row);
  cell.setAttribute("align", "center");
  img = document.createElement("img");
  img.setAttribute("src", "/pki/esc/images/PadLock.gif");
  if (!isSecured)
  img.style.visibility = "hidden";
  cell.appendChild(img);

  return row;
}

////////////////////////////////////////////////////////////////
//
// Functions that contact the server or talk directly to
// ASC native code.
//
// ASC Native Functions:
//
//     netkey.GetAvailableCOOLKeys()
//
//       - Returns an ActiveX Variant SafeArray containing the ID for each key
//         that is currentlly plugged into the computer. Before accessing any
//         data in this array you must convert it to a JScript Array with a
//         call to ConvertVariantArrayToJScriptArray().
//
//     netkey.GetCOOLKeyIsEnrolled(keyType, keyID)
//
//       - Returns true if a key has been initialized, false if it hasn't.
//         Initialized means the card has been formatted with certificates
//         for either an COOL HouseKey or NetKey.
//
//     netkey.GetCOOLKeyStatus(keyType, keyID)
//
//       - Returns an integer describing the status of the COOLKey. Possible
//         values are:
//
//           0 // Unavailable
//           1 // AppletNotFound
//           2 // Uninitialized
//           3 // Unknown
//           4 // Available
//           5 // EnrollmentInProgress
//           6 // UnblockInProgress
//           7 // PINResetInProgress
//           8 // RenewInProgress
//           9 // FormatInProgress
//          10 // BlinkInProgress
//
//     netkey.GetCOOLKeyPolicy(keyType, keyID)
//
//       - Retrieves the Certificate Policy Extension Object Identifier (OID)
//         as a string. This can be useful for distinguishing between types of
//         COOLKeys. The list of currently defined OIDS are:
//
//             Bronze Member - Phase 1:     OID.1.3.6.1.4.1.1066.1.1000.1.0.1.1
//             Silver Member - Phase 2:     OID.1.3.6.1.4.1.1066.1.1000.1.0.1.2
//             Gold Associate - Phase 2:    OID.1.3.6.1.4.1.1066.1.1000.1.0.1.3
//             Platinum MyDoctor - Phase 2: OID.1.3.6.1.4.1.1066.1.1000.1.0.1.4
//
//     netkey.GetCOOLKeyRequiresAuthentication(keyType, keyID)
//
//       - Returns a bool value that indicates whether or not the COOLKey
//         requires a PIN to access crypto functionality.
//
//     netkey.AuthenticateCOOLKey(keyType, keyID, pin)
//
//       - Attempts to authenticates to the COOLKey using the supplied
//         pin string.
//
//     netkey.InitCOOLKey(keyType, keyID, screenName, pin)
//
//       - Initiates an async connection to the RA to initialize a specific
//         key. If you want the key to be initialized as a HouseKey, you should
//         pass null values for both screenName and pin, otherwise, the key.
//         is formatted as a NetKey.
//
//     netkey.ChallengeCOOLKey(keyType, keyID, data)
//
//       - Signs some data with the specified key, and returns the results
//         in an AcviteX Variant SafeArray. Before accessing any data in
//         this array, you must convert it to a JScript Array with a
//         call to ConvertVariantArrayToJScriptArray(). The elements in the
//         array are as follows:
//
//             array[0] --> Length of the signed challenge data in binary form.
//             array[1] --> The signed challenge data as hex.
//             array[0] --> Length of the nonce data in binary form.
//             array[0] --> The nonce data as hex.
//
//     netkey.BlinkCOOLKey(keyType, keyID, rate, duration)
//
//       - Make a specific key blink at a given rate for a given duration.
//         rate and duration are specified in milliseconds.
//
//     netkey.RequestServiceTicket(screenName, serviceName)
//
//       - Makes an async ticket request for a specific service.
//         The ticket is returned via the OnTicketRequestSuccess()
//         callback.
//
//     netkey.CancelServiceTicketRequest(screenName, serviceName)
//
//       - Cancels a specific service ticket request that may be pending.
//
////////////////////////////////////////////////////////////////

function BindCOOLKey(keyType, keyID)
{
  if (COOLKeyIsBusy(keyType, keyID))
  {
    alert("COOLKey '" + keyID + "' is busy!");
    return;
  }

  document.forms[0].action.value = "setlabelpage";
  document.forms[0].keytype.value = keyType;
  document.forms[0].keyid.value = keyID;
  document.forms[0].submit();
}

function UnbindCOOLKey(keyType, keyID)
{
  if (COOLKeyIsBusy(keyType, keyID))
  {
    alert("COOLKey '" + keyID + "' is busy!");
    return;
  }

  document.forms[0].action.value = "unbindprogresspage";
  document.forms[0].keytype.value = keyType;
  document.forms[0].keyid.value = keyID;
  document.forms[0].submit();
}

function PurchaseMoreKeys()
{
}

function LoadHelp()
{
  alert("- Click on the key icon for a specific key to make it blink.\n");
}

function DoBlinkCOOLKey(keyType, keyID)
{
  if (!keyID)
    return;

  BlinkCOOLKey(keyType, keyID, 400, 5000);
}

function OnCOOLKeyInserted(keyType, keyID)
{
  var row = InsertCOOLKeyIntoBindingTable(keyType, keyID);

  refresh();
}

function OnCOOLKeyRemoved(keyType, keyID)
{
  var row = GetRowForKey(keyType, keyID);
  var table = document.getElementById("KeyTable");
  if (row && table)
  {
    if (IsKeyBound(keyType, keyID))
      SetKeyIsVisible(row, false);
    else
      RemoveRow(table, row)
  }

  refresh();
}

function OnCOOLKeyBusyStart(keyType, keyID)
{
  AddKeyToBusyArray(keyType, keyID);
}

function OnCOOLKeyBusyEnd(keyType, keyID)
{
  RemoveKeyFromBusyArray(keyType, keyID);
}

function refresh()
{
  window.resizeBy(0,1);
  window.resizeBy(0,-1);

}

////////////////////////////////////////////////////////////////////////////
//
// Notification functions called directly from ASC native code. These
// functions will only be called if they exist in the current running
// JavaScript context.
//
//   OnCOOLKeyStateChange(keyType, keyID, keyState, data)
//
//     - Called when the state of the COOLKey changes. Values for key
//
//     keyState   Description             data
//     -------------------------------------------------------
//       1000     Key Inserted            <none>
//       1001     Key Removed             <none>
//       1002     Enrollment Start        <0=Phase1, 1=Phase2>
//       1003     Enrollment Complete     <none>
//       1004     Enrollment Error        Integer Error Code
//       1005     Unblock Start           <none>
//       1006     Unblock Complete        <none>
//       1007     Unblock Error           Integer Error Code
//       1008     PIN Reset Start         <none>
//       1009     PIN Reset Complete      <none>
//       1010     PIN Reset Error         Integer Error Code
//       1011     Renew Start             <none>
//       1012     Renew Complete          <none>
//       1013     Renew Error             Integer Error Code
//       1014     Format Start            <none>
//       1015     Format Complete         <none>
//       1016     Format Error            Integer Error Code
//       1017     Blink Start             <none>
//       1018     Blink Complete          <none>
//       1019     Blink Error             Integer Error Code
//       1020     Operation Cancelled     Integer Error Code
//
//    OnTicketRequestSuccess(serviceName, ticket, authenticator)
//
//      - Called when a service ticket request made with 
//        netkey.RequestServiceTicket() completes successfully.
//        ticket is the Base64 encoded Kerberos ticket. authenticator
//        is the Base64 encoded authenticator.
//
//    OnTicketRequestException(serviceName, errCode, errSubSystem, errMsg)
//
//      - Called when a service ticket request made with
//        netkey.RequestServiceTicket() fails. serviceName is the service
//        name used when the request was made. errCode is the error code
//        defined by CLC. errSubSystem is the sub system defined by CLC.
//        errMsg is the string containing the error message to display. This
//        string is provided by UAS or CLC.
//
////////////////////////////////////////////////////////////////////////////

function OnCOOLKeyStateChange(keyType, keyID, keyState, data)
{
  switch(keyState)
  {
    case 1000: // KeyInserted
      OnCOOLKeyInserted(keyType, keyID);
      break;
    case 1001: // KeyRemoved
      OnCOOLKeyRemoved(keyType, keyID);
      break;
    case 1002: // EnrollmentStart
    case 1005: // UnblockStart
    case 1008: // PINResetStart
    case 1011: // RenewStart
    case 1014: // FormatStart
      OnCOOLKeyBusyStart(keyType, keyID);
      break;
    case 1003: // EnrollmentComplete
    case 1004: // EnrollmentError
    case 1006: // UnblockComplete
    case 1007: // UnblockError
    case 1009: // PINResetComplete
    case 1010: // PINResetError
    case 1012: // RenewComplete
    case 1013: // RenewError
    case 1015: // FormatComplete
    case 1016: // FormatError
      OnCOOLKeyBusyEnd(keyType, keyID);
      break;
  }
}

</script>
</head>
<body onLoad="InitializeBindingTable();" onUnload="cleanup();">

<table width="100%">
  <tr>
    <td>
<img src="/pki/esc/images/logo.gif">     </td>
    <td>
      <p class="headerText"><a href="esc.cgi?screenname=">Enterprise Security Client</a></p>
    </td>
  <tr>
</table>

<form method="post" action="esc.cgi">
<input type="hidden" name="action" value="settingspage">
<input type="hidden" name="screenname" value="<!-- SECURECOOL_SCREENNAME -->">
<input type="hidden" name="keytype" value="">
<input type="hidden" name="keyid" value="">
<table class="PageHeader">
</table>
<table class="ContentTable">
<tbody>
<tr><td colspan="2">
<b>Coolkey</b> (Enterprise Security Key) helps users perform various cryptographic operations.
<br>
Your Coolkey(s) and any other Coolkey(s) plugged into this computer are shown here. 
<br>
<br>
<div class="TableTitle">Coolkey(s)   <!-- SECURECOOL_SCREENNAME --></div>
</td></tr>
<tr>
  <td width="55%" valign="top">
  <table id="KeyTable">
  <tbody>
    <tr class="KeyTableHeader">
      <th></th>
      <th><p class="titleText">Name</p></th>
      <th></th>
      <th><p class="titleText">Secured</p></th>
    </tr>
  </tbody>
  </table>
  </td>
</tr>
</tbody>
</table>
</form>
</body>
</html>