-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Google Authenticator converter
- Loading branch information
Showing
14 changed files
with
1,456 additions
and
397 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "google_authenticator_converter" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT" | ||
description= "Extract name, secret and issuer from a Google Authenticator migration QR code" | ||
|
||
[dependencies] | ||
base32 = "0.4.0" | ||
base64 = "0.21.0" | ||
urlencoding = "2.1.2" | ||
protobuf = { version = "2" } | ||
serde_json = { version = "1"} | ||
serde = {version = "1", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2023 Lőrik Levente | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# google_authenticator_converter | ||
|
||
- Extract name, secret and issuer from a Google Authenticator migration QR code | ||
|
||
### Based on: | ||
|
||
[google-authenticator-extractor | ||
](https://github.com/zhangyuan/google-authenticator-extractor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use base64::{engine::general_purpose, Engine as _}; | ||
use protobuf::Message; | ||
use serde::Serialize; | ||
|
||
mod proto; | ||
#[derive(Debug, Serialize)] | ||
pub struct Account { | ||
name: String, | ||
secret: String, | ||
issuer: String, | ||
} | ||
|
||
impl Account { | ||
pub fn new(name: String, secret: String, mut issuer: String) -> Account { | ||
// If the issuer is empty, use the name as the issuer. | ||
if issuer.is_empty() { | ||
issuer = name.clone() | ||
} | ||
|
||
Account { | ||
name, | ||
secret, | ||
issuer, | ||
} | ||
} | ||
} | ||
|
||
pub fn process_data(string: &str) -> Vec<Account> { | ||
let encoded_data = extract_data_from_uri(string).unwrap(); | ||
let decoded_data = general_purpose::STANDARD.decode(encoded_data).unwrap(); | ||
|
||
let migration_payload = | ||
proto::google_auth::MigrationPayload::parse_from_bytes(decoded_data.as_slice()).unwrap(); | ||
|
||
let otp_parameters = migration_payload.otp_parameters.into_vec(); | ||
|
||
let alphabet = base32::Alphabet::RFC4648 { padding: false }; | ||
|
||
let payloads: Vec<Account> = otp_parameters | ||
.into_iter() | ||
.map(|a| { | ||
Account::new( | ||
a.name, | ||
base32::encode(alphabet, a.secret.as_slice()), | ||
a.issuer, | ||
) | ||
}) | ||
.collect(); | ||
|
||
return payloads; | ||
} | ||
|
||
pub fn extract_data_from_uri(raw: &str) -> Result<String, Box<dyn std::error::Error>> { | ||
let mut split = raw.split("data="); | ||
|
||
if let Some(encoded_data) = split.next() { | ||
let s = urlencoding::decode(encoded_data)?; | ||
Ok(s.to_string()) | ||
} else { | ||
Err("No data found in URI".into()) | ||
} | ||
} |
Oops, something went wrong.