r2fa
Rust implementation for HTOP, TOTP and steam guard tow-factor-authentication.
Use ring 0.16.20,
may be incompatible with other version of ring.
Features
- HOTP, TOTP
- user configurable settings
- digits
- secret key
- TOTP Key time step (period)
- TOTP Key start time (t0)
- HOTP Key initial counter
- user configurable settings
- steam guard (not implemented yet)
- verification
- code generate
Cargo Features
qrcode
qrcodeqrcodegenqrcoderead
The qrcode feature is enabled by default,
need to add default-features = false to disable the default feature.
Or, you can enable the qrcodegen feature explicitly
which used to generate the qrcode with the given opt auth data.
Or, the qrcoderead feature
which used to read the qrcode with the given opt auth qrcode.
Both qrcodegen and qrcoderead feature use the image
crate, which will greatly increase the package size.
log
log
This feature provided log support for the library.
TODO
- log feature
- steam guard
- generate steam guard code from mafile
- steam login
- add phone number to steam
- add steam guard method
- remove steam guard method
- confirmations
Usage
Manually Create the Struct
use HOTPKey;
use HMACType;
use Key;
let mut hotp_key = HOTPKey ;
let code = hotp_key.get_code.unwrap;
From URI Formate String
use otpauth_from_uri;
use TOTPKey;
use HMACType;
use Key;
let totp_key1 = otpauth_from_uri;
if let Err = totp_key1
let mut totp_key1 = totp_key1.unwrap;
let mut totp_key2 = TOTPKey ;
assert_eq!;
assert_eq!;
assert_eq!;
If given a opt auth struct, it can also be converted to a uri formate string.
use HOTPKey;
use HMACType;
use Key;
let mut hotp_key = HOTPKey ;
let uri = hotp_key.get_uri;
From URI QRCode
See the Cargo Features part first.
The original qrcode:

use otpauth_from_uri_qrcode;
use TOTPKey;
use HMACType;
use Key;
let totp_key1 = otpauth_from_uri_qrcode;
if let Err = totp_key1
let mut totp_key1 = totp_key1.unwrap;
let mut totp_key2 = TOTPKey ;
assert_eq!;
assert_eq!;
assert_eq!;
Or, generate the qrcode with the given opt auth data.
Note, all encoded image will be 2048x2048.
use otpauth_from_uri_qrcode;
use TOTPKey;
use HMACType;
use Key;
use OptAuthKey;
let totp_key = TOTPKey ;
let uri = totp_key.to_uri_struct;
// convert to image::DynamicImage data
let img: DynamicImage = uri.into;
// Or, save to a path
uri.to_qr_code.unwrap;
The encoded qrcode:

Steam Guard Code Generation
You need to have a mafile first.
On what is a mafile and how to get a mafile, follow ASF 2FA.
It will give you a .maFile at config folder.
Get Steam Guard Code
use SteamKey;
use Key;
use MaFile;
let mafile = from_file;
assert!;
let steam_key = from_mafile;
assert!;
let mut steam_key = steam_key.unwrap;
let code = steam_key.get_code;
assert!;
let code = code.unwrap;
println!;
Steam API
Phone Validate API
Test whether a phone number is valid and is a voip.
Host: store.steampowered.com
Endpoint: /phone/validate
Method: POST
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Request Body:
sessionID: session idphoneNumber: phone number
Response: json
Response Sample:
Add Phone Number
This is a multi process procedure.
- First you send you
phone numberto steam. - Then it is likely that steam will ask for your
Email Verification. - You click the email verification link send to your mailbox.
- You send a request to steam says that you have clicked the link.
- Then steam will send a
sms codeto the phone number. - You send a request to steam that contain the
sms code. - Done.
However all this process have the same host, endpoint, method
and content type.
The only difference is the request body.
Host: store.steampowered.com
Endpoint: /phone/add_ajaxop
Method: POST
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Send the phone number
Request Body:
op:get_phone_numberinput: your phone numbersessionID: your session idconfirmed:1checkfortos:1bisediting:0token:0
Response Sample:
The state is email_verification means you could go for email verification.
The state is get_sms_code means you could go for check sms code.
Email Verification
Request Body:
op:email_verificationinput: emptysessionID: your session idconfirmed:1checkfortos:1bisediting:0token:0
Response Sample:
The state is email_verification means you could go for email verification.
The state is get_sms_code means you could go for check sms code.
SMS Code Verification
Request Body:
op:get_sms_codeinput: sms code you receivesessionID: your session idconfirmed:1checkfortos:1bisediting:0token:0
Response Sample:
The state is done means the process is done.