File tree Expand file tree Collapse file tree 5 files changed +52
-11
lines changed Expand file tree Collapse file tree 5 files changed +52
-11
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+ import xml .etree .ElementTree as ET
3
+ import json
4
+
5
+ def fetch_json (filename ):
6
+ tree = ET .parse (filename )
7
+ j = tree .find ("string" ).text .replace (""" ,"\" " )
8
+ return json .loads (j )
9
+
10
+ def object_to_cotp_json (d ):
11
+ final = []
12
+ for element in d :
13
+ final .append (
14
+ {
15
+ 'label' : element ['name' ],
16
+ 'secret' : element ['decryptedSecret' ],
17
+ 'issuer' : "" ,
18
+ 'digits' : int (element ['digits' ])
19
+ }
20
+ )
21
+ return final
22
+
23
+ def main ():
24
+ if len (sys .argv ) != 3 :
25
+ print ("Usage: python authy.py [INPUT_FILE] [OUTPUT_FILE]" )
26
+ return
27
+
28
+ data = fetch_json (sys .argv [1 ])
29
+ output_file = open (sys .argv [2 ],'w' )
30
+ output_file .write (json .dumps (object_to_cotp_json (data )))
31
+ output_file .close ()
32
+
33
+
34
+ main ()
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ def get_accounts(filename):
12
12
'label' : row [0 ],
13
13
'secret' : row [1 ],
14
14
'issuer' : row [2 ],
15
+ 'digits' : 6 ,
15
16
}
16
17
)
17
18
c .close ()
Original file line number Diff line number Diff line change @@ -27,7 +27,9 @@ pub fn import(args: Vec<String>){
27
27
match & args[ 2 ] [ ..] {
28
28
"cotp" | "andotp" => result = importers:: and_otp:: import ( & args[ 3 ] ) ,
29
29
"aegis" => result = importers:: aegis:: import ( & args[ 3 ] ) ,
30
- "gauth" | "google_authenticator" => result = importers:: gauth:: import ( & args[ 3 ] ) ,
30
+ "gauth" |
31
+ "google_authenticator" |
32
+ "authy" => result = importers:: converted:: import ( & args[ 3 ] ) ,
31
33
_=> {
32
34
println ! ( "Invalid argument: {}" , & args[ 2 ] ) ;
33
35
return ;
@@ -57,6 +59,8 @@ pub fn import(args: Vec<String>){
57
59
println ! ( "\" cotp\" " ) ;
58
60
println ! ( "\" aegis\" " ) ;
59
61
println ! ( "\" andotp\" " ) ;
62
+ println ! ( "\" gauth\" or \" google_authenticator\" " ) ;
63
+ println ! ( "\" authy\" " ) ;
60
64
}
61
65
}
62
66
Original file line number Diff line number Diff line change @@ -4,33 +4,35 @@ use serde_json;
4
4
use serde:: Deserialize ;
5
5
6
6
#[ derive( Deserialize ) ]
7
- struct GAuthJson {
7
+ struct ConvertedJson {
8
8
label : Option < String > ,
9
9
secret : String ,
10
10
issuer : Option < String > ,
11
+ digits : u64 ,
11
12
}
12
13
13
14
pub fn import ( filepath : & str ) -> Result < Vec < OTPElement > , String > {
14
15
let file_to_import_contents = read_to_string ( filepath) . unwrap ( ) ;
15
- let result: Result < Vec < GAuthJson > , serde_json:: Error > = serde_json:: from_str ( & file_to_import_contents) ;
16
- let gauth : Vec < GAuthJson > ;
16
+ let result: Result < Vec < ConvertedJson > , serde_json:: Error > = serde_json:: from_str ( & file_to_import_contents) ;
17
+ let vector : Vec < ConvertedJson > ;
17
18
18
19
match result{
19
- Ok ( r) => gauth = r,
20
+ Ok ( r) => vector = r,
20
21
Err ( e) => return Err ( format ! ( "{}" , e) ) ,
21
22
}
22
23
23
24
let mut elements: Vec < OTPElement > = Vec :: new ( ) ;
24
25
25
- for i in 0 ..gauth. len ( ) {
26
- let secret = gauth[ i] . secret . to_owned ( ) ;
27
- let issuer = gauth[ i] . issuer . to_owned ( ) . unwrap_or_default ( ) ;
28
- let label = gauth[ i] . label . to_owned ( ) . unwrap_or_default ( ) ;
26
+ for i in 0 ..vector. len ( ) {
27
+ let secret = vector[ i] . secret . to_owned ( ) ;
28
+ let issuer = vector[ i] . issuer . to_owned ( ) . unwrap_or_default ( ) ;
29
+ let label = vector[ i] . label . to_owned ( ) . unwrap_or_default ( ) ;
30
+ let digits = vector[ i] . digits ;
29
31
elements. push ( OTPElement :: new (
30
32
secret,
31
33
issuer,
32
34
label,
33
- 6 ,
35
+ digits ,
34
36
String :: from ( "TOTP" ) ,
35
37
String :: from ( "SHA1" ) ,
36
38
String :: from ( "" ) ,
Original file line number Diff line number Diff line change 1
1
pub mod and_otp;
2
2
pub mod aegis;
3
- pub mod gauth ;
3
+ pub mod converted ;
You can’t perform that action at this time.
0 commit comments