|
1 /* |
|
2 * OTPWCalc - One time password challenge response calculator client |
|
3 * Copyright © 2013 Michael Schloh von Bennewitz <michael@schloh.com> |
|
4 * |
|
5 * OTPWCalc is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the European Union Public Licence, either |
|
7 * version 1.1 of the license, or (at your option) any later version. |
|
8 * |
|
9 * OTPWCalc is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty |
|
11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
|
12 * the European Union Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the European Union Public |
|
15 * Licence along with OTPWCalc. If not, please refer to |
|
16 * <http://joinup.ec.europa.eu/software/page/eupl/>. |
|
17 * |
|
18 * This file is part of project OTWPCalc, a one time password challenge |
|
19 * response calculator client and is found at http://otpwcalc.europalab.com/ |
|
20 * |
|
21 * main.js: ECMA JavaScript implementation |
|
22 */ |
|
23 |
|
24 // <![CDATA[ |
|
25 //// This doesn't work with AJAX (use pageinit instead) |
|
26 //// That means JavaScript in the head of any other HTML |
|
27 //// will be ignored, only the data-role="page" is parsed |
|
28 //$(document).ready(function() { |
|
29 //$.mobile.ajaxLinksEnabled = false; |
|
30 //}); |
|
31 $(document).on("mobileinit", function() { |
|
32 $.extend($.mobile, { |
|
33 pageLoadErrorMessage: 'Either the page cannot be found or it cannot be loaded.' |
|
34 }); |
|
35 }); |
|
36 //$(document).on("pageinit", function() { |
|
37 //}); |
|
38 $(document).on("pageinit", "[data-role='page'].oc-swipage", function() { |
|
39 var makepage = "#" + $(this).attr("id"), |
|
40 next = $(this).jqmData("next"), // Next page stored in data-next |
|
41 prev = $(this).jqmData("prev"); // Previous page stored in data-prev |
|
42 |
|
43 if (next) { // Check if data-next attribute is indeed set |
|
44 //// Prefetch next page |
|
45 //$.mobile.loadPage(next); |
|
46 // Navigate to next page on swipe left |
|
47 $(document).on("swipeleft", makepage, function(inev) { |
|
48 inev.stopImmediatePropagation(); |
|
49 $.mobile.changePage(next, {transition: "slide"}); |
|
50 }); |
|
51 } |
|
52 else { // If data-next not set then default to history |
|
53 $(document).on("swipeleft", makepage, function(inev) { |
|
54 inev.stopImmediatePropagation(); |
|
55 window.history.forward({transition: "slide"}); |
|
56 }); |
|
57 } |
|
58 if (prev) { // Check if data-prev attribute is set |
|
59 $(document).on("swiperight", makepage, function(inev) { |
|
60 inev.stopImmediatePropagation(); |
|
61 $.mobile.changePage(prev, {transition: "slide", reverse: true}); |
|
62 }); |
|
63 } |
|
64 else { // If data-prev not set then default to history |
|
65 $(document).on("swiperight", makepage, function(inev) { |
|
66 inev.stopImmediatePropagation(); |
|
67 //history.back(); // or window.history.back(); |
|
68 $.mobile.back({transition: "slide", reverse: true}); |
|
69 }); |
|
70 } |
|
71 }); |
|
72 |
|
73 // the main logical entry point |
|
74 function otpwcalc() { |
|
75 var secr = $('#paswrd').val(); |
|
76 var user = $('#seedid').val(); |
|
77 var iter = parseInt($('#crement').val(), 10); |
|
78 var hash = genotpmd5; |
|
79 if ($('form input[name=radiohash]:checked').attr('id') == 'hashsha1') |
|
80 hash = genotpsha1; |
|
81 else if ($('form input[name=radiohash]:checked').attr('id') == 'hashr160') |
|
82 hash = genotprmd160; |
|
83 var form = arrtosix; |
|
84 if ($('form input[name=radiodisplay]:checked').attr('id') == 'displayhex') |
|
85 form = arrtohex; |
|
86 var resp = hash(secr, user, iter); |
|
87 //var resp = sjcl.random.randomWords(1,0); |
|
88 return form(resp); |
|
89 } |
|
90 |
|
91 // helper function |
|
92 function dosubmit() { |
|
93 if ($('#seedid').val().length == 0) { |
|
94 $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Seed ID'); |
|
95 return false; |
|
96 } |
|
97 else if ($('#crement').val().length == 0 || isNaN($('#crement').val())) { |
|
98 $('#outext').css({'font-size': '1.125em', 'padding-top': '0em'}).text('Please enter exactly one Sequence #'); |
|
99 return false; |
|
100 } |
|
101 else { |
|
102 $('#outext').css({'font-size': '0.9em', 'padding-top': '0.25em'}).text(otpwcalc()); |
|
103 $('#crement').val(parseInt($("#crement").val()) - $('#selectdecr').val()); |
|
104 return false; |
|
105 } |
|
106 } |
|
107 |
|
108 // helper function |
|
109 function doreset() { |
|
110 $('#outext').css({'font-size': '1.125em', 'padding-top': '0'}).text('Please Click Submit For A OTP'); |
|
111 return true; |
|
112 } |
|
113 // ]]> |