summaryrefslogtreecommitdiffstats
path: root/TwoStepsAuthenticator.TestWebsite/default.html
diff options
context:
space:
mode:
authorGuillaume Lacasa <guillaume.lacasa@ucaya.com>2013-06-12 18:42:34 +0200
committerGuillaume Lacasa <guillaume.lacasa@ucaya.com>2013-06-12 18:42:34 +0200
commitf83d2a6a47734300a265273328f31120c38941e8 (patch)
tree734545fab6c462040668f9e8618557a80ad16356 /TwoStepsAuthenticator.TestWebsite/default.html
parentd3ac57ba63e266e1edc5d503b602c7ff50618056 (diff)
downloadTwoStepsAuthenticator-f83d2a6a47734300a265273328f31120c38941e8.zip
TwoStepsAuthenticator-f83d2a6a47734300a265273328f31120c38941e8.tar.gz
TwoStepsAuthenticator-f83d2a6a47734300a265273328f31120c38941e8.tar.bz2
on avance dans l'algo
Diffstat (limited to 'TwoStepsAuthenticator.TestWebsite/default.html')
-rw-r--r--TwoStepsAuthenticator.TestWebsite/default.html199
1 files changed, 199 insertions, 0 deletions
diff --git a/TwoStepsAuthenticator.TestWebsite/default.html b/TwoStepsAuthenticator.TestWebsite/default.html
new file mode 100644
index 0000000..ad8522c
--- /dev/null
+++ b/TwoStepsAuthenticator.TestWebsite/default.html
@@ -0,0 +1,199 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <title> - jsFiddle demo by russau</title>
+
+ <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>
+ <link rel="stylesheet" type="text/css" href="/css/normalize.css">
+
+
+ <link rel="stylesheet" type="text/css" href="/css/result-light.css">
+
+
+ <link rel="stylesheet" type="text/css" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.css">
+
+
+
+
+
+ <script type='text/javascript' src="https://github.com/Caligatio/jsSHA/raw/master/src/sha.js"></script>
+
+
+ <style type='text/css'>
+ body { padding-top: 60px; }
+.container-fluid { min-width: 100px }
+
+ </style>
+
+
+
+<script type='text/javascript'>//<![CDATA[
+
+ function dec2hex(s) { return (s < 15.5 ? '0' : '') + Math.round(s).toString(16); }
+ function hex2dec(s) { return parseInt(s, 16); }
+
+ function base32tohex(base32) {
+ var base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
+ var bits = "";
+ var hex = "";
+
+ for (var i = 0; i < base32.length; i++) {
+ var val = base32chars.indexOf(base32.charAt(i).toUpperCase());
+ bits += leftpad(val.toString(2), 5, '0');
+ }
+
+ for (var i = 0; i + 4 <= bits.length; i += 4) {
+ var chunk = bits.substr(i, 4);
+ hex = hex + parseInt(chunk, 2).toString(16);
+ }
+ return hex;
+
+ }
+
+ function leftpad(str, len, pad) {
+ if (len + 1 >= str.length) {
+ str = Array(len + 1 - str.length).join(pad) + str;
+ }
+ return str;
+ }
+
+ function updateOtp() {
+
+ var key = base32tohex($('#secret').val());
+
+ //var date = new Date();
+ var date = new Date(2013, 5, 12, 18, 0, 0, 0); //12 juin 2013 18h00
+
+ var epoch = Math.round(date.getTime() / 1000.0);
+
+
+
+ var time = leftpad(dec2hex(Math.floor(epoch / 30)), 16, '0');
+
+ var hmacObj = new jsSHA(time, 'HEX');
+ var hmac = hmacObj.getHMAC(key, 'HEX', 'SHA-1', "HEX");
+
+ $('#qrImg').attr('src', 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=200x200&chld=M|0&cht=qr&chl=otpauth://totp/user@host.com%3Fsecret%3D' + $('#secret').val());
+ $('#secretHex').text(key);
+ $('#secretHexLength').text((key.length * 4) + ' bits');
+ $('#epoch').text(time);
+ $('#hmac').empty();
+
+ if (hmac == 'KEY MUST BE IN BYTE INCREMENTS') {
+ $('#hmac').append($('<span/>').addClass('label important').append(hmac));
+ } else {
+ var offset = hex2dec(hmac.substring(hmac.length - 1));
+ var part1 = hmac.substr(0, offset * 2);
+ var part2 = hmac.substr(offset * 2, 8);
+ var part3 = hmac.substr(offset * 2 + 8, hmac.length - offset);
+ if (part1.length > 0) $('#hmac').append($('<span/>').addClass('label').append(part1));
+ $('#hmac').append($('<span/>').addClass('label success').append(part2));
+ if (part3.length > 0) $('#hmac').append($('<span/>').addClass('label').append(part3));
+ }
+
+ var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
+ otp = (otp).substr(otp.length - 6, 6);
+
+ $('#otp').text(otp);
+
+ var a = otp;
+ }
+
+ function timer() {
+ var epoch = Math.round(new Date().getTime() / 1000.0);
+ var countDown = 30 - (epoch % 30);
+ if (epoch % 30 == 0) updateOtp();
+ $('#updatingIn').text(countDown);
+
+ }
+
+ $(function () {
+ updateOtp();
+
+ $('#update').click(function (event) {
+ updateOtp();
+ event.preventDefault();
+ });
+
+ $('#secret').keyup(function () {
+ updateOtp();
+ });
+
+ setInterval(timer, 1000);
+ });
+ //]]>
+
+</script>
+
+
+</head>
+<body>
+ <div class="container-fluid">
+ <div>
+ <div class="row">
+ <div class="span8">
+ <h1>Time-based One-time Password Algorithm</h1>
+ <p>This page contains a javascript implementation of the <em>Time-based One-time Password Algorithm</em> used by Google Authenticator and described in the <a href="http://tools.ietf.org/id/draft-mraihi-totp-timebased-06.html">TOTP RFC Draft</a>.</p>
+
+ <p>Install Google Authenticator on your smartphone: <a href="http://itunes.apple.com/au/app/google-authenticator/id388497605?mt=8">iOS</a>, <a href="https://market.android.com/details?id=com.google.android.apps.authenticator&hl=en">Android</a>, <a href="http://m.google.com/authenticator">Blackberry</a>. As the TOTP is an open standard you can use this app to create one-time passwords for your own application. You add an account plus secret by scanning a QR code (more info on the <a href="http://code.google.com/p/google-authenticator/wiki/KeyUriFormat">google code wiki</a>). The javascript below implements the algorithm the smartphone app uses to generate the OTP - you would use this same algorithm <em>server-side</em> to verify an OTP.</p>
+
+ <p>Put it to the test by setting the base32 secret, scanning the QR code in Google Authenticate. You should see the same OTP on your smartphone and displayed at the bottom on the page.</p>
+
+ </div>
+ </div>
+ <div class="row">
+
+ <form>
+ <fieldset>
+
+ <div class="clearfix">
+ <label for="secret">Secret (base32)</label>
+ <div class="input"><input type="text" size="30" name="secret" id="secret" class="xlarge" value="JBSWY3DPEHPK3PXP" /></div>
+ </div>
+ <!-- /clearfix -->
+ <div class="clearfix">
+ <label>Secret (hex)</label>
+ <div class="input"><span class="label" id="secretHex"></span>
+ <span id='secretHexLength'></span></div>
+ </div>
+ <!-- /clearfix -->
+ <div class="clearfix">
+ <label>QR Code</label>
+ <div class="input"><img id="qrImg" src="" /></div>
+ </div>
+ <!-- /clearfix -->
+ <div class="clearfix">
+ <label>Unix epoch div 30 (padded hex)</label>
+ <div class="input"><span class="label" id='epoch'></span></div>
+ </div>
+ <!-- /clearfix -->
+ <div class="clearfix">
+ <label>HMAC(secret, time)</label>
+ <div class="input" id='hmac'></div>
+ </div>
+ <!-- /clearfix -->
+ <div class="clearfix">
+ <label>One-time Password</label>
+ <div class="input"><span class="label success" id='otp'></span></div>
+ </div>
+ <!-- /clearfix -->
+ <div class="clearfix">
+ <label>Updating in</label>
+ <div class="input"><span id='updatingIn'></span></div>
+ </div>
+ <!-- /clearfix -->
+
+
+ </fieldset>
+ </form>
+ </div>
+ </div>
+ </div>
+
+
+</body>
+
+
+</html>
+