#id #user-id #client #solution #api-client #baltic

baltic-id

Baltic ID-Card, Smart-ID & Mobile-ID Api客户端库,用于Rust

2个版本

0.0.2 2023年5月31日
0.0.1 2023年5月29日

#1606 in 加密学

MIT 许可证

105KB
2K SLoC

Baltic ID (baltic-id) Rust库包

Baltic ID是一个Rust库包,提供使用SK ID Solutions的ID卡、Smart ID和Mobile ID进行用户身份验证和文档签名的功能。

该库包旨在简化Baltic ID服务在Rust应用程序中的集成。

特性

  • 用户身份验证:使用ID卡、Smart ID或Mobile ID验证用户。
  • 文档签名:允许用户使用他们的ID卡、Smart ID或Mobile ID对文档进行数字签名。与SK ID Solutions集成:利用SK ID Solutions提供的API服务进行安全的身份验证和文档签名。

安装

要在您的Rust项目中使用Baltic ID库包,请在Cargo.toml文件中添加以下行

[dependencies]
baltic-id = "0.0.1"

注意:这是一个基本示例,演示了Baltic ID的使用方法。请参阅文档以获取详细说明和附加选项。

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/MaW7yVhRDd0HaKZzDANBgkqhkiG9w0BAQsFADBoMQswCQYDVQQGEwJFRTEiMCAGA1UECgwZQVMgU2VydGlmaXRzZWVyaW1pc2tlc2t1czEXMBUGA1UEYQwOTlRSRUUtMTA3NDcwMTMxHDAaBgNVBAMME1RFU1Qgb2YgRUlELVNLIDIwMTYwHhcNMjEwOTE3MDYzNjM2WhcNMjQwOTE3MDYzNjM2WjB3MQswCQYDVQQGEwJMVDEgMB4GA1UEAwwXVEVTVE5VTUJFUixRVUFMSUZJRUQgT0sxEzARBgNVBAQMClRFU1ROVU1CRVIxFTATBgNVBCoMDFFVQUxJRklFRCBPSzEaMBgGA1UEBRMRUE5PTFQtM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wQQYIKwYBBQUHMAKGNWh0dHA6Ly9zay5lZS91cGxvYWQvZmlsZXMvVEVTVF9vZl9FSUQtU0tfMjAxNi5kZXIuY3J0MDAGA1UdEQQpMCekJTAjMSEwHwYDVQQDDBhQTk9MVC0zMDMwMzAzOTgxNi0yREI1LVEwDQYJKoZIhvcNAQELBQADggIBAIb/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();
}

文档

有关如何使用Baltic ID库包的详细说明,请参阅doc.rs文档。

贡献

欢迎为Baltic ID库包做出贡献!如果您遇到任何问题或对改进有建议,请在GitHub仓库上创建一个问题。也鼓励提出拉取请求。

许可证

该库包受MIT许可证的许可。有关更多信息,请参阅LICENSE文件。

致谢

Baltic ID库包是从SK ID Solutions提供的服务中汲取灵感开发的。

特别感谢Rust社区的支持和贡献。

联系

有关任何查询或反馈,请联系[email protected]

依赖关系

~14–28MB
~455K SLoC