Stop using Google Charts for the 2-Factor-Auth QR-Code (#1044)

This commit is contained in:
RainLoop Team 2016-05-26 22:37:02 +03:00
parent 4988b276ad
commit 2fefad437e
15 changed files with 1802 additions and 8 deletions

View file

@ -7,6 +7,7 @@
window = require('window'),
_ = require('_'),
ko = require('ko'),
qr = require('qr'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
@ -43,6 +44,7 @@
this.viewSecret = ko.observable('');
this.viewBackupCodes = ko.observable('');
this.viewUrlTitle = ko.observable('');
this.viewUrl = ko.observable('');
this.viewEnable_ = ko.observable(false);
@ -125,6 +127,7 @@
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
};
@ -148,6 +151,7 @@
{
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
this.twoFactorTested(false);
@ -162,6 +166,7 @@
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
};
@ -173,6 +178,13 @@
}
};
TwoFactorConfigurationPopupView.prototype.getQr = function ()
{
return 'otpauth://totp/' + window.encodeURIComponent(this.viewUser()) +
'?secret=' + window.encodeURIComponent(this.viewSecret()) +
'&issuer=' + window.encodeURIComponent('');
};
TwoFactorConfigurationPopupView.prototype.onResult = function (sResult, oData)
{
this.processing(false);
@ -187,7 +199,9 @@
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewBackupCodes(Utils.pString(oData.Result.BackupCodes).replace(/[\s]+/g, ' '));
this.viewUrl(Utils.pString(oData.Result.Url));
this.viewUrlTitle(Utils.pString(oData.Result.UrlTitle));
this.viewUrl(qr.toDataURL({level: 'M', size: 8, value: this.getQr()}));
}
else
{
@ -198,6 +212,7 @@
this.viewSecret('');
this.viewBackupCodes('');
this.viewUrlTitle('');
this.viewUrl('');
}
};
@ -209,11 +224,13 @@
if (Enums.StorageResultType.Success === sResult && oData && oData.Result)
{
this.viewSecret(Utils.pString(oData.Result.Secret));
this.viewUrl(Utils.pString(oData.Result.Url));
this.viewUrlTitle(Utils.pString(oData.Result.UrlTitle));
this.viewUrl(qr.toDataURL({level: 'M', size: 6, value: this.getQr()}));
}
else
{
this.viewSecret('');
this.viewUrlTitle('');
this.viewUrl('');
}
};

View file

@ -201,6 +201,7 @@ cfg.paths.js = {
'vendors/lightGallery/dist/js/lg-autoplay.min.js',
'vendors/keymaster/keymaster.min.js',
'vendors/ifvisible/ifvisible.min.js',
'vendors/qr.js/qr.min.js',
'vendors/bootstrap/js/bootstrap.min.js'
]
},

View file

@ -6722,7 +6722,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
'IsSet' => false,
'Enable' => false,
'Secret' => '',
'Url' => '',
'UrlTitle' => '',
'BackupCodes' => ''
);
@ -6749,9 +6749,7 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
$aResult['Enable'] = isset($mData['Enable']) ? !!$mData['Enable'] : false;
$aResult['Secret'] = $mData['Secret'];
$aResult['BackupCodes'] = $mData['BackupCodes'];
$aResult['Url'] = $this->TwoFactorAuthProvider()->GetQRCodeGoogleUrl(
$aResult['User'], $aResult['Secret'], $this->Config()->Get('webmail', 'title', ''));
$aResult['UrlTitle'] = $this->Config()->Get('webmail', 'title', '');
}
if ($bRemoveSecret)
@ -6761,9 +6759,9 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
unset($aResult['Secret']);
}
if (isset($aResult['Url']))
if (isset($aResult['UrlTitle']))
{
unset($aResult['Url']);
unset($aResult['UrlTitle']);
}
if (isset($aResult['BackupCodes']))

7
vendors/qr.js/AUTHORS.md vendored Normal file
View file

@ -0,0 +1,7 @@
# Authors ordered by first contribution
* tz <tz@execpc.com>
* Alasdair Mercer <mercer.alasdair@gmail.com>
* Alexandre Perrin <alex@kaworu.ch>
* Michael Mason
* Benjamin Besse

60
vendors/qr.js/CHANGES.md vendored Normal file
View file

@ -0,0 +1,60 @@
## Version 1.1.4, 2015.11.11
* [#2](https://github.com/neocotic/qr.js/issues/2): Fix padding issues
* [#35](https://github.com/neocotic/qr.js/pull/35): Make the QR-code center-aligned
* [#38](https://github.com/neocotic/qr.js/pull/38): Update node-canvas dependency version to support Node.js v4 and above
## Version 1.1.3, 2014.09.01
* [#23](https://github.com/neocotic/qr.js/issues/23): Revert back to [GPL License][]
## Version 1.1.2, 2014.04.27
* [#20](https://github.com/neocotic/qr.js/issues/20): Fix "too many open files" bug
## Version 1.1.1, 2013.12.03
* Fix bug with IIFE
## Version 1.1.0, 2013.12.02
* [#9](https://github.com/neocotic/qr.js/issues/9): Fix RequireJS support
* [#13](https://github.com/neocotic/qr.js/issues/13): Remove [Ender][] support
* [#14](https://github.com/neocotic/qr.js/issues/14): Improve code formatting and style
* [#16](https://github.com/neocotic/qr.js/issues/16): Support different MIME types for `toDataURL` and other related functions
* [#17](https://github.com/neocotic/qr.js/issues/17): Remove unnecessary callback arguments from synchronous functions
* [#17](https://github.com/neocotic/qr.js/issues/17): Make `save` fully asynchronous
* [#17](https://github.com/neocotic/qr.js/issues/17): Add `saveSync` for synchronous saving
* [#18](https://github.com/neocotic/qr.js/issues/18): Add [Grunt][] build system
* [#18](https://github.com/neocotic/qr.js/issues/18): Generate source map as part of build
* [#18](https://github.com/neocotic/qr.js/issues/18): Improve developer documentation
* [#19](https://github.com/neocotic/qr.js/issues/19): Add support for [Bower][]
* Many small fixes and tweaks
## Version 1.0.3, 2011.12.19
* [#3](https://github.com/neocotic/qr.js/issues/3): Rename `QRCode` to `qr`
* [#3](https://github.com/neocotic/qr.js/issues/3): Remove all deprecated methods
* [#4](https://github.com/neocotic/qr.js/issues/4): Reformat code and add additional, along with some original, code comments
* [#6](https://github.com/neocotic/qr.js/issues/6): Add support for [Node.js][], [CommonJS][] and [Ender][]
* [#6](https://github.com/neocotic/qr.js/issues/6): Add optional `callback` functionality to API methods
* [#7](https://github.com/neocotic/qr.js/issues/7): Allow `data` arguments to be an object or string value
* [#8](https://github.com/neocotic/qr.js/issues/8): Add `VERSION` property to the API
* [#8](https://github.com/neocotic/qr.js/issues/8): Add `toDataURL`, `save` and `noConflict` methods to the API
* Now distributed under the [MIT License][]
## Version 1.0.2, 2011.08.31
* [#1](https://github.com/neocotic/qr.js/issues/1): Deprecate `generateCanvas` and `generateImage` and replaced with `canvas` and `image` respectively
## Version 1.0.1, 2011.08.12
* Allow customisation of colours used when rendering
[bower]: http://bower.io
[commonjs]: http://commonjs.org
[ender]: http://ender.no.de
[gpl license]: http://www.gnu.org/licenses/
[grunt]: http://gruntjs.com
[mit license]: http://en.wikipedia.org/wiki/MIT_License
[node.js]: http://nodejs.org

59
vendors/qr.js/CONTRIBUTING.md vendored Normal file
View file

@ -0,0 +1,59 @@
# Contributing
Here are some guidelines that we'd like contributors to follow so that we can have a chance of
keeping things right.
## Getting Starting
* Make sure you have a [GitHub account](https://github.com/signup/free)
* Submit a ticket for your issue if one does not already exist
* Clearly describe the issue including steps to reproduce when it is a bug
* Include the earliest version that you know has the issue
* Fork the repository on GitHub
* Read the `INSTALL.md` file
## Making Changes
* Create a topic branch from where you want to base your work
* This is usually the master branch
* Only target release branches if you are certain your fix must be on that branch
* To quickly create a topic branch based on master;
`git branch fix/master/my_contribution master` then checkout the new branch with
`git checkout fix/master/my_contribution`
* Avoid working directly on the `master` branch
* Make commits of logical units
* Check for unnecessary whitespace with `git diff --check` before committing
* Make sure your commit messages are in the proper format
* Avoid updating the distributable file or annotated source code documentation
```
(#99999) Make the example in CONTRIBUTING imperative and concrete
Without this patch applied the example commit message in the CONTRIBUTING document is not a
concrete example. This is a problem because the contributor is left to imagine what the commit
message should look like based on a description rather than an example. This patch fixes the
problem by making the example concrete and imperative.
The first line is a real life imperative statement with a ticket number from our issue tracker. The
body describes the behavior without the patch, why this is a problem, and how the patch fixes the
problem when applied.
```
* Make sure you have added the necessary tests for your changes
* Run *all* the tests to assure nothing else was accidentally broken
## Submitting Changes
* Ensure you added your details to `AUTHORS.md` in the correct format
`Joe Bloggs <joe.bloggs@example.com>`
* Push your changes to a topic branch in your fork of the repository
* Submit a pull request to neocotic's repository
* Update your issue to mark that you have submitted code and are ready for it to be reviewed
* Include a link to the pull request in the issue
# Additional Resources
* [qr.js repository](https://github.com/neocotic/qr.js)
* [Issue tracker](https://github.com/neocotic/qr.js/issues)
* [General GitHub documentation](http://help.github.com)
* [GitHub pull request documentation](http://help.github.com/send-pull-requests)

46
vendors/qr.js/INSTALL.md vendored Normal file
View file

@ -0,0 +1,46 @@
This document is only relevant for those that want to contribute to the [qr.js][] open source
project (we love you guys!). If you are only interested in installing the tool look at `README.md`.
## Build Requirements
In order to build [qr.js][], you need to have the following install [git][] 1.7+ and [node.js][]
0.8+ (which includes [npm][]).
### Canvas Support
[qr.js][] heavily depends on [node-canvas][] to support the HTML5 canvas element in the [node.js][]
environment. Unfortunately, this library is dependant on [Cairo][], which is not managed by
[npm][]. Before you are able to build [qr.js][] (and it's dependencies), you must have [Cairo][]
installed. Please see their wiki on steps on how to do this on various platforms:
https://github.com/LearnBoost/node-canvas/wiki/_pages
## Building
Follow these steps to build [qr.js][];
1. Clone a copy of the main [qr.js git repository](https://github.com/neocotic/qr.js) by running
`git clone git://github.com/neocotic/qr.js.git`
2. `cd` to the repository directory
3. Ensure you have all of the dependencies by entering `npm install`
4. Ensure you can run [Grunt][] by running `npm install -g grunt-cli`
5. To run the full test suite enter `grunt test`
* **Pro Tip:** You can easily run step 5 by just entering `grunt`
6. To update the optimized distributable file and documentation enter `grunt dist`
* Outputs to documentation to the `docs` directory
## Important
If you're planning on contributing to [qr.js][] please do **NOT** update the distributable file or
documentation (step 6) when submitting a pull request. We will not accept pull requests when these
files have been changed as we do this ourselves when finalizing a release.
Read the `CONTRIBUTING.md` file for more information about submitting pull requests.
[cairo]: http://cairographics.org
[git]: http://git-scm.com
[grunt]: http://gruntjs.com
[node.js]: http://nodejs.org
[node-canvas]: https://github.com/LearnBoost/node-canvas
[npm]: http://npmjs.org
[qr.js]: http://neocotic.com/qr.js

14
vendors/qr.js/LICENSE.md vendored Normal file
View file

@ -0,0 +1,14 @@
Copyright (C) 2015 Alasdair Mercer, http://neocotic.com
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, either version 3 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.

290
vendors/qr.js/README.md vendored Normal file
View file

@ -0,0 +1,290 @@
__
__ _ __ /\_\ ____
/'__`\/\`'__\ \/\ \ /',__\
/\ \L\ \ \ \/__ \ \ \/\__, `\
\ \___, \ \_\\_\_\ \ \/\____/
\/___/\ \/_//_/\ \_\ \/___/
\ \_\ \ \____/
\/_/ \/___/
[qr.js][] is a pure JavaScript library for [QR code][] generation using canvas.
* [Install](#install)
* [Examples](#examples)
* [API](#api)
* [Canvas Support](#canvas-support)
* [Bugs](#bugs)
* [Questions](#questions)
## Install
Install using the package manager for your desired environment(s):
``` bash
# for node.js:
$ npm install qr-js
# OR; for the browser:
$ bower install qr-js
```
## Examples
In the browser:
``` html
<html>
<body>
<canvas id="qr-code"></canvas>
<script src="/path/to/qr.min.js"></script>
<script>
qr.canvas({
canvas: document.getElementById('qr-code'),
value: 'http://neocotic.com/qr.js'
});
</script>
</body>
</html>
```
In [node.js][]:
``` javascript
var qr = require('qr-js');
qr.saveSync('http://neocotic.com/qr.js', 'qrcode.png');
```
## API
### Standard Data
The following configuration data options are recognised by all of the core API methods (all of
which are optional):
<table>
<tr>
<th>Property</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td>background</td>
<td>Background colour to be used</td>
<td><code>#fff</code></td>
</tr>
<tr>
<td>canvas</td>
<td><code>&lt;canvas&gt;</code> element in which the QR code should be rendered</td>
<td>Creates a new element</td>
</tr>
<tr>
<td>foreground</td>
<td>Foreground colour to be used</td>
<td><code>#000</code></td>
</tr>
<tr>
<td>level</td>
<td>ECC (error correction capacity) level to be applied</td>
<td><code>L</code></td>
</tr>
<tr>
<td>size</td>
<td>Module size of the generated QR code</td>
<td><code>4</code></td>
</tr>
<tr>
<td>value</td>
<td>Value to be encoded in the generated QR code</td>
<td><code>""</code></td>
</tr>
</table>
### `canvas([data|value])`
Renders a QR code in an HTML5 `<canvas>` element for a given value.
``` javascript
// Render the QR code on a newly created canvas element
var canvas = qr.canvas('http://neocotic.com/qr.js');
// Re-render the QR code on an existing element
qr.canvas({
canvas: canvas,
value: 'https://github.com/neocotic/qr.js'
});
```
### `image([data|value])`
Renders a QR code in an HTML `<img>` element for a given value.
``` javascript
// Render the QR code on a newly created img element
var img = qr.image('http://neocotic.com/qr.js');
// Re-render the QR code on an existing element
qr.image({
image: img,
value: 'https://github.com/neocotic/qr.js'
});
```
#### Additional Data
As well as the [Standard Data](#standard-data), this method also accepts the following additional
data options:
<table>
<tr>
<th>Property</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td>image</td>
<td><code>&lt;img&gt;</code> element in which the QR code should be rendered</td>
<td>Creates a new element</td>
</tr>
<tr>
<td>mime</td>
<td>MIME type to process the QR code image</td>
<td><code>image/png</code></td>
</tr>
</table>
### `save([data|value][, path], callback)`
Saves a QR code, which has been rendered for a given value, to the user's file system.
``` javascript
// Render a QR code to a PNG file
qr.save('http://neocotic.com/qr.js', 'qr.png', function(err) {
if (err) throw err;
// ...
});
// Render a QR code to a JPEG file
qr.save({
mime: 'image/jpeg',
path: 'qr.jpg',
value: 'https://github.com/neocotic/qr.js'
}, function(err) {
if (err) throw err;
// ...
});
```
**Note:** Currently, in the browser, this just does it's best to force a download prompt. We will
try to improve on this in the future.
#### Additional Data
As well as the [Standard Data](#standard-data), this method also accepts the following additional
data options:
<table>
<tr>
<th>Property</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td>mime</td>
<td>MIME type to process the QR code image</td>
<td><code>image/png</code></td>
</tr>
<tr>
<td>path</td>
<td>Path to which the QR code should be saved<br><strong>Ignored in browsers</strong></td>
<td><em>Required if not specified as an argument</em></td>
</tr>
</table>
### `saveSync([data|value][, path])`
Synchronous [`save(3)`](#savedatavalue-path-callback).
### `toDataURL([data|value])`
Returns a data URL for rendered QR code. This is a convenient shorthand for dealing with the native
`HTMLCanvasElement.prototype.toDataURL` function.
``` javascript
console.log(qr.toDataURL('http://neocotic.com/qr.js')); // "data:image/png;base64,iVBORw0KGgoAAAA..."
console.log(qr.toDataURL({
mime: 'image/jpeg',
value: 'https://github.com/neocotic/qr.js'
})); // "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
```
#### Additional Data
As well as the [Standard Data](#standard-data), this method also accepts the following additional
data options:
<table>
<tr>
<th>Property</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td>mime</td>
<td>MIME type to process the QR code image</td>
<td><code>image/png</code></td>
</tr>
</table>
### Miscellaneous
#### `noConflict()`
Returns `qr` in a no-conflict state, reallocating the `qr` global variable name to its previous
owner, where possible.
This is really just intended for use within a browser.
``` html
<script src="/path/to/conflict-lib.js"></script>
<script src="/path/to/qr.min.js"></script>
<script>
var qrNC = qr.noConflict();
// Conflicting lib works again and use qrNC for this library onwards...
</script>
```
#### `VERSION`
The current version of `qr`.
``` javascript
console.log(qr.VERSION); // "1.1.4"
```
## Canvas Support
For browser users; their browser must support the HTML5 canvas element or the API will throw an
error immediately.
For [node.js][] users; [qr.js][] heavily depends on [node-canvas][] to support the HTML5 canvas
element in the [node.js][] environment. Unfortunately, this library is dependant on [Cairo][],
which is not managed by [npm][]. Before you are able to install [qr.js][] (and it's dependencies),
you must have [Cairo][] installed. Please see their wiki on steps on how to do this on various
platforms:
https://github.com/LearnBoost/node-canvas/wiki/_pages
## Bugs
If you have any problems with this library or would like to see the changes currently in
development you can do so here;
https://github.com/neocotic/qr.js/issues
## Questions?
Take a look at `docs/qr.html` to get a better understanding of what the code is doing.
If that doesn't help, feel free to follow me on Twitter, [@neocotic][].
However, if you want more information or examples of using this library please visit the project's
homepage;
http://neocotic.com/qr.js
[@neocotic]: https://twitter.com/neocotic
[cairo]: http://cairographics.org
[node.js]: http://nodejs.org
[node-canvas]: https://github.com/LearnBoost/node-canvas
[npm]: http://npmjs.org
[qr.js]: http://neocotic.com/qr.js
[qr code]: http://en.wikipedia.org/wiki/QR_code

38
vendors/qr.js/bower.json vendored Normal file
View file

@ -0,0 +1,38 @@
{
"name": "qr-js",
"version": "1.1.4",
"description": "Library for QR code generation using canvas",
"homepage": "http://neocotic.com/qr.js",
"authors": [
{
"name": "Alasdair Mercer",
"email": "mercer.alasdair@gmail.com",
"homepage": "http://neocotic.com"
}
],
"license": "GPL-3.0",
"keywords": [
"qr",
"code",
"encode",
"canvas",
"image"
],
"repository": {
"type": "git",
"url": "https://github.com/neocotic/qr.js.git"
},
"main": "qr.min.js",
"ignore": [
"**/.*",
"docs",
"AUTHORS.md",
"CHANGES.md",
"CONTRIBUTING.md",
"Gruntfile.js",
"INSTALL.md",
"README.md",
"bower.json",
"package.json"
]
}

40
vendors/qr.js/package.json vendored Normal file
View file

@ -0,0 +1,40 @@
{
"name": "qr-js",
"version": "1.1.4",
"description": "Library for QR code generation using canvas",
"homepage": "http://neocotic.com/qr.js",
"bugs": {
"url": "https://github.com/neocotic/qr.js/issues"
},
"author": {
"name": "Alasdair Mercer",
"email": "mercer.alasdair@gmail.com",
"url": "http://neocotic.com"
},
"license": "GPL-3.0",
"keywords": [
"qr",
"code",
"encode",
"canvas",
"image"
],
"repository": {
"type": "git",
"url": "https://github.com/neocotic/qr.js.git"
},
"dependencies": {
"canvas": "^1.3.1"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.3",
"grunt-contrib-uglify": "^0.10.0",
"grunt-docco": "^0.4.0"
},
"main": "qr.js",
"scripts": {
"test": "grunt test"
}
}

1217
vendors/qr.js/qr.js vendored Normal file

File diff suppressed because it is too large Load diff

5
vendors/qr.js/qr.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
vendors/qr.js/qr.min.map vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -67,6 +67,7 @@ module.exports = {
'ssm': 'window.ssm',
'key': 'window.key',
'_': 'window._',
'qr': 'window.qr',
'Promise': 'window.Promise',
'$': 'window.jQuery'
}