-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
272 lines (232 loc) · 6.26 KB
/
index.html
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
<html>
<head>
<title>
Google Authenticator Database "Importer"
</title>
<script src="sql.js"></script>
<script src="qrcode.js"></script>
<script>
function create_qrcode(text, typeNumber, errorCorrectLevel) {
var qr = qrcode(typeNumber || 4, errorCorrectLevel || 'M');
qr.addData(text);
qr.make();
return qr.createImgTag();
};
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
function displayErrors(errors)
{
var import_error = document.getElementById('import_error');
if (errors && errors.length > 0)
{
import_error.style.display = 'block';
import_error.innerHTML = errors.join('<br/>');
}
else
{
document.getElementById('import_error').style.display = 'none';
}
}
function onDatabaseLoaded(evt)
{
var errors = [];
try
{
var db = SQL.open(new Uint8Array(evt.target.result));
var accounts = db.exec('SELECT email,secret,type,counter FROM accounts ORDER BY _id');
var codes_output = document.getElementById('codes');
var codes = [];
for (var i=0, acc; acc = accounts[i]; ++i)
{
var
email = acc[0].value,
secret = acc[1].value,
type = acc[2].value,
counter = acc[3].value;
if (!email)
{
errors.push('Account #' + parseInt(i) + ' has no name.');
continue;
}
if (!secret)
{
errors.push('Account ' + email + ' has no secret.');
continue;
}
var code_image;
if (type == 0)
{
code_image = create_qrcode(
'otpauth://totp/' + email + '?secret=' + secret,
10);
}
else if (type == 1)
{
code_image = create_qrcode(
'otpauth://hotp/' + email + '?secret=' + secret + '&counter=' + counter,
10);
}
else
{
errors.push('Account ' + htmlEscape(email) + ' has unknown type ' + type + '.');
continue;
}
codes.push(
'<div class="qrcode-box">' +
code_image + '<br/>' +
htmlEscape(email).replace('@', '<wbr/>@<wbr/>').replace('.', '<wbr/>@<wbr/>') +
'</div>');
}
codes_output.innerHTML = codes.join(' ');
codes_output.style.display = 'block';
}
catch(e)
{
errors.push(htmlEscape(e.toString()));
}
displayErrors(errors);
}
function onDatabaseError(evt)
{
var errors = [];
switch(evt.target.error.code) {
case evt.target.error.NOT_FOUND_ERR:
errors.push('File not found.');
break;
case evt.target.error.NOT_READABLE_ERR:
errors.push('File is not readable.');
break;
case evt.target.error.ABORT_ERR:
break; // noop
default:
errors.push('An error occurred reading this file.');
};
displayErrors(errors);
}
// Open a database
function handleFileSelect(evt) {
displayErrors(null);
document.getElementById('codes').style.display = 'none';
var errors = [];
try
{
var files = evt.target.files;
for (var i=0, f; f = files[i]; ++i)
{
var reader = new FileReader();
reader.onload = onDatabaseLoaded;
reader.onerror = onDatabaseError;
reader.readAsArrayBuffer(f);
}
}
catch(e)
{
errors.push(htmlEscape(e.message));
}
displayErrors(errors);
}
</script>
<style>
body {
font-size: larger;
font-family: sans-serif;
margin-left: 5em;
margin-right: 5em;
margin-top: 3em;
}
p {
line-height: 150%;
}
output {
padding: 1em;
min-height: 30px;
border: solid 1px black;
background-color: #fffffc;
display: block;
margin-top: 10px;
margin-bottom: 10px;
}
#import_error {
background-color: lightpink;
}
.qrcode-box {
display: inline-block;
width: 130px;
font-size: small;
word-wrap: break-word;
vertical-align: top;
text-align: center;
margin-right: 50px;
line-height: 140%;
}
code {
padding: 2px;
border: 1px solid lightgray;
}
h1 {
border-bottom: 3px solid green;
}
h2 {
border-bottom: 2px solid green;
}
em {
font-style: normal;
color: green;
}
.credits {
border-top: 1px dotted green;
padding-top: 10px;
font-style: italic;
}
</style>
</head>
<body>
<h1>Google Authenticator Database-to-QR converter</h1>
<p>
Database (SQLite) file: <input type="file" id="file" name="file" />
<output id="import_error" style="display:none;">
</output>
<output id="codes" style="display:none;">
</output>
</p>
<script>
document.getElementById('file').addEventListener('change', handleFileSelect, false);
</script>
<h2>What is this?</h2>
<p>
So, you've got a new Android phone and you want to move over
(or perhaps copy) your Google Authenticator (which might include
<a href="http://itservices.stanford.edu/service/webauth/twostep"/>more</a>
<a href="http://drupal.org/project/ga_login"/>than</a>
<a href="http://www.mnxsolutions.com/security/two-factor-ssh-with-google-authenticator.html">one</a>
<a href="http://helpdesk.lastpass.com/security-options/google-authenticator/">account</a>).
This workflow only works when the source device is <em>rooted</em>.
Otherwise, the only way to get the Google Authenticator database out
of the device is to root it.
</p>
<p>
First, copy the source device's <code>/data/data/com.google.android.apps.authenticator2/databases/databases</code>
file to your computer. If you have ADB, run
<code>adb pull /data/data/com.google.android.apps.authenticator2/databases/databases</code>. Otherwise,
use a file manager application to copy it.
</p>
<p>
If your new phone is also rooted, don't fuss with QR codes and just
copy the database to its target destination (with <code>adb push ...</code> or
a file manager). However, if it's <em>not rooted</em>, this is a simple
app to import your database quickly and painlessly <em>that's completely local</em> —
Your database is never sent anywhere. This app will generate QR codes out of your Google
Authenticator (SQLite) database.
</p>
<p class="credits">
Made with <a href="https://github.com/kripken/sql.js">sql.js</a>
and <a href="http://www.d-project.com/qrcode/index.html">QR Code Generator</a>.
</p>
</body>
</html>