2 releases
0.0.2 | May 31, 2023 |
---|---|
0.0.1 | May 29, 2023 |
#522 in Authentication
105KB
2K
SLoC
Baltic ID (baltic-id) Rust Library Crate
Baltic ID is a Rust library crate that provides user authentication and document signing functionalities using ID Card, Smart ID, and Mobile ID from SK ID Solutions.
This crate aims to simplify the integration of Baltic ID services into Rust applications.
Features
- User authentication: Authenticate users using ID Card, Smart ID, or Mobile ID.
- Document signing: Enable users to digitally sign documents using their ID Card, Smart ID, or Mobile ID. Integration with SK ID Solutions: Leverage the API Services provided by SK ID Solutions for secure authentication and document signing.
Installation
To use the Baltic ID library crate in your Rust project, add the following line to your Cargo.toml file:
[dependencies]
baltic-id = "0.0.1"
Note: This is a basic example demonstrating the usage of Baltic ID. Please refer to the documentation for detailed instructions and additional options.
use base64::Engine;
use base64::engine::general_purpose;
use general_purpose::STANDARD;
use baltic_id::{
smart_id::{
models::{AuthenticationSessionRequest, DigestCalculator, HashType},
}
};
use baltic_id::smart_id::models::{CertificateLevel, Interaction, InteractionType, SemanticsIdentifier};
use baltic_id::smart_id::SmartIdClient;
const CERTIFICATE: &str = "MIIIFjCCBf6gAwIBAgIQDZ/p/MaW7yVhRDd0HaKZzDANBgkqhkiG9w0BAQsFADBoMQswCQYDVQQGEwJFRTEiMCAGA1UECgwZQVMgU2VydGlmaXRzZWVyaW1pc2tlc2t1czEXMBUGA1UEYQwOTlRSRUUtMTA3NDcwMTMxHDAaBgNVBAMME1RFU1Qgb2YgRUlELVNLIDIwMTYwHhcNMjEwOTE3MDYzNjM2WhcNMjQwOTE3MDYzNjM2WjB3MQswCQYDVQQGEwJMVDEgMB4GA1UEAwwXVEVTVE5VTUJFUixRVUFMSUZJRUQgT0sxEzARBgNVBAQMClRFU1ROVU1CRVIxFTATBgNVBCoMDFFVQUxJRklFRCBPSzEaMBgGA1UEBRMRUE5PTFQtMzAzMDMwMzk5MTQwggMhMA0GCSqGSIb3DQEBAQUAA4IDDgAwggMJAoIDAGtuICDz1b4qHQHEr5a+fvG5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Ni5kZXIuY3J0MDAGA1UdEQQpMCekJTAjMSEwHwYDVQQDDBhQTk9MVC0zMDMwMzAzOTgxNi0yREI1LVEwDQYJKoZIhvcNAQELBQADggIBAIb/2962fBUE015kwcgVl2BVaAa4t9JwuIJFqS6uhpin95v13Ei4JWle1Ge7i+kUyDexns3C3BzO8VXINNloYuxrNcVJo0iFh+7fZwpX55i4X78+Phlsj84Q8o97P/bwbyyGNmUUIjKcb0PlvKv/2TLsXTsdWv9a1o+a/Y2dHPpmvmqG7xzqgmUOTlfC+PvQTD+3LVywW4NpmgxtA/paa7KHVWC5iPtPGoO8vCo2gqHtmfSywozvWs7CgRs9cvKxrxD/F29eu47Cqis66X2hXXYJxkOptaEJtLim7U+gkCl0c+bMV2Gp9dSA0kpfKi4puP1KKtm4tURRxRxjSxEpFFtXb3Q46shYoWJZcsO4mNR5Qh+sJWyfN8l6BMn2j1u3tEcAqY1sFItsMdvuqjcYlYgxSn9JoNNN3PDaKFkOF+zSmW+No+xM0k9wLLanbGBCAx0JT71Ob8a6TldRSZmUS6DTUOXi6DatYppWNSRDvhaI4NmMXGWOdYeMg3VpOEz1JN9a9C3KZbDnhm0vayJwYQ1Hlm3Jf1EUOhoBiEBtBj8c4e324aj2ckiU8xWpr7GzIzszRcbW4PZfhQePPjvJfLXfpQKpu9UDC6ENbophzSduiGHZ8l/YvEZwjD3Bb5RdsjvNsIeIO4YaFb8rl/QqSOsGY9O+mIwAzIwI3vTfmJYI";
const CERTIFICATE_LEVEL: &str = "ADVANCED";
const DEMO_HOST_URL: &str = "https://sid.demo.sk.ee/smart-id-rp/v2/";
const DEMO_RELYING_PARTY_UUID: &str = "00000000-0000-0000-0000-000000000000";
const DEMO_RELYING_PARTY_NAME: &str = "DEMO";
const VALID_SEMANTICS_IDENTIFIER: &str = "PNOLT-30303039914";
const VALID_DOCUMENT_NUMBER: &str = "PNOEE-50001029996-MOCK-Q";
const SIGNABLE_TEXT: &str = "hashvalueinbase64";
const NETWORK_INTERFACE: &str = "docker0"; // network interface in machine. for example "docker0", "en7", "eth0", "127.0.0.1"
#[tokio::main]
async fn main() {
let client = SmartIdClient::new(DEMO_HOST_URL.to_string(), vec!["sha256//Ps1Im3KeB0Q4AlR+/J9KFd/MOznaARdwo4gURPCLaVA=".to_string()], DEMO_RELYING_PARTY_UUID.to_string(), DEMO_RELYING_PARTY_NAME.to_string());
let hash_in_base64 =
STANDARD.encode(&DigestCalculator::calculate_digest(SIGNABLE_TEXT, HashType::Sha512));
let mut authentication_session_request = AuthenticationSessionRequest::new(
DEMO_RELYING_PARTY_UUID.to_string(),
DEMO_RELYING_PARTY_NAME.to_string(),
hash_in_base64,
HashType::Sha512,
);
authentication_session_request.set_certificate_level(CertificateLevel::Qualified);
authentication_session_request.set_hash_type(HashType::Sha512);
authentication_session_request.set_network_interface(NETWORK_INTERFACE.to_string());
let interactions = vec![
Interaction::of_type_display_text_and_pin("Log into internet banking system".to_string()),
];
authentication_session_request.set_allowed_interactions_order(interactions);
let identifier = SemanticsIdentifier::from_string(VALID_DOCUMENT_NUMBER.to_string());
let _authenticate_session_response = client.authenticate_with_semantics_identifier(
&identifier,
authentication_session_request,
).await.unwrap();
}
Documentation
For detailed instructions on how to use the Baltic ID library crate, refer to the doc.rs documentation.
Contributing
Contributions to the Baltic ID crate are welcome! If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository. Pull requests are also encouraged.
License
This crate is licensed under the MIT License. See the LICENSE file for more information.
Acknowledgments
The Baltic ID crate was developed inspiration from the services provided by SK ID Solutions.
Special thanks to the Rust community for their support and contributions.
Contact
For any inquiries or feedback, please contact balamurali@live.com.
Dependencies
~15–29MB
~444K SLoC