exporting-tokens-from-freeotp.md (1431B)
1 # Exporting tokens from FreeOTP 2 3 After using FreeOTP on a single device for a while, I came to the conclusion that it would be safer to store the tokens on multiple devices, in case one is out of battery or out-of-arms-reach. 4 5 I didn't find any option from the UI to do it, so I checked the data over adb, and as the tokens were stored as JSON-in-XML, I whipped up a quick perl script to convert the data to a list of otpauth:// URIs. 6 7 #!/usr/bin/perl -w 8 9 use XML::LibXML; 10 use JSON; 11 use MIME::Base32; 12 use URI::Encode qw/uri_encode/; 13 14 my $p = XML::LibXML->new(); 15 my $d = $p->load_xml(string => join '', <<>>); 16 my $j = JSON->new(); 17 18 for ($d->findnodes('/map/string')) { 19 my $l = $_->findvalue('@name'); 20 next if $l eq 'tokenOrder'; 21 my $d = $j->decode($_->findvalue('.')); 22 $d->{secret} = encode_base32(join('', map { 23 chr(($_ + 256) % 256) 24 } @{$d->{'secret'}})); 25 print "otpauth://" . lc($d->{'type'}) . "/" . 26 uri_encode($l) . "?" . 27 join("&", map { $_ . "=" . uri_encode($d->{$_}) } keys %$d) . 28 "\n"; 29 } 30 31 The output of which can be then be fed to qrencode or similar to get tokens added to another device. 32 33 I used: 34 <pre>adb shell su -c 'cat /data/data/org.fedorahosted.freeotp/shared_prefs/tokens.xml''./otp.pl'while read u; do qrencode -o - $u ' display -; done</pre> 35 to view the codes one-by-one. (Note: this method needs rooted device, it may be possible to do it without, but didn't look for one).