Skip to content

Commit 6cc055d

Browse files
committed
Merge branch 'release/0.1.2'
2 parents bd25edb + 188afa6 commit 6cc055d

File tree

7 files changed

+145
-42
lines changed

7 files changed

+145
-42
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smart-id-rust-client"
3-
version = "0.1.0"
3+
version = "0.1.2"
44
description = "Smart ID Rust Client"
55
homepage = "https://smart-id.com"
66
authors = ["Michallis Pashidis <[email protected]>"]

README.MD

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ authentication and mobile digital signing using Smart-ID.</div>
1616

1717
</div>
1818

19+
# Introduction
20+
The library can be used for easy integration with the Smart-ID API.
21+
It provides a simple interface for mobile authentication and mobile digital signing using Smart-ID.
22+
Additional utilities has been provided for easy integration with the Smart-ID API:
23+
- generate digest and calculate verification code
24+
- helper structs
25+
- interactions with the mobile end-user
26+
27+
## Status
28+
Beta version - under development!
29+
1930
## Documentation
2031

2132
[Smart-ID Documentation](https://github.com/SK-EID/smart-id-documentation)

docs/src/intro.md

+60-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
# Introduction
1+
# Introduction
2+
3+
This document describes the relying party service interface protocol of Smart-ID server and
4+
provides information for integration. The interface offers the entry point to Smart-ID main use
5+
cases, i.e. authentication and signing.
6+
7+
The interface is to be used by relaying parties - parties who wish to use Smart-ID services,
8+
i.e. ask end users to perform authentication and signing operations.
9+
10+
## 1.1 Glossary
11+
12+
* Smart-ID account - A person has to register a Smart-ID account to use services provided by the Smart-ID
13+
system. Account binds a Smart-ID app instance (installed on a person's mobile device)
14+
to a person's identity in the Smart-ID system. In the course of account creation and
15+
registration, the identity of the account owner (person) is proofed by a Registration
16+
Authority (RA) and the relation between the identity and a key pair is certified by a
17+
Certificate Authority (CA). An account has a signature key pair and an authentication
18+
key pair.
19+
* Smart-ID app - A technical component of the Smart-ID system. A mobile app instance installed on a
20+
person's mobile device that provides access to Smart-ID functionality for persons.
21+
* Smart-ID provider - An organization that is legally responsible for the Smart-ID system.
22+
* Smart-ID server - A technical component of the Smart-ID system. Server-side counterpart of the Smart-ID
23+
app. Handles backend operations and provides API-s to Relying Party (RP).
24+
* Smart-ID system - A technical and organizational environment, which enables digital authentication and
25+
issuing of digital signatures of persons in an electronic environment. The Smart-ID
26+
system provides services that allow persons (Smart-ID account owners) to authenticate
27+
themselves to RPs, to give digital signatures requested by RPs, and to manage their
28+
Smart-ID accounts.
29+
* Authentication key pair (or authentication key) - Key pair, which is used to digitally authenticate a person.
30+
* Certificate Authority (CA) - An entity that issues certificates for Smart-ID account owners.
31+
* Key pair - Pair of keys, which are required for digital signature scheme. There are two kinds of key
32+
pairs (or shortly, keys) in the Smart-ID system, authentication key pair and signature key
33+
pair. The word pair refers to to the private and public keys of each key pair used in an
34+
assymetric cryptographic algorithm, here RSA.
35+
* Mobile device - A tablet computer or smartphone that runs a mobile device operating system (Apple iOS,
36+
Google Android).
37+
* Person - A natural person who uses the Smart-ID system to authenticate herself to an RP and to
38+
issue digital signatures requested by RP.
39+
* Registration Authority (RA) - An entity responsible for recording or verifying some or all of the information (particularly
40+
the identities of subjects) needed by a CA to issue certificates and CRLs and to perform
41+
other certificate management functions.
42+
* Relying Party (RP) - An organization or service, for example a bank, which is using the Smart-ID service to
43+
authenticate its users and to get them to sign the documents.
44+
* Relying Party request - A request from an RP that requires some kind of operation in the Smart-ID backend
45+
system. It may or may not create a transaction.
46+
* Signature key pair (or signature key) - Key pair, which is used to give digital signatures of a person.
47+
48+
49+
## 1.2. References
50+
51+
* **ETSI319412-1** ETSI. Electronic Signatures and Infrastructures (ESI); Certificate Profiles;
52+
Part 1: Overview and common data structures. 2015. URL: <http://www.etsi.org/deliver/etsi_en/319400_319499/31941201/01.01.00_30/en_31941201v010100v.pdf>.
53+
* **rfc2616** R. Fielding et al. Hypertext Transfer Protocol – HTTP/1.1. RFC 2616 (Draft Standard).
54+
Obsoleted by RFCs 7230, 7231, 7232, 7233, 7234, 7235, updated by RFCs 2817, 5785,
55+
6266, 6585. Internet Engineering Task Force, June 1999. URL: <https://tools.ietf.org/html/rfc2616>.
56+
* **rfc4122** P. Leach, M. Mealling, and R. Salz. A Universally Unique IDentifier (UUID) URN
57+
Namespace. RFC 4122 (Standards Track). Internet Engineering Task Force, July 2005.
58+
URL: <https://tools.ietf.org/html/rfc4122>.
59+
* **rfc4648** S. Josefsson. The Base16, Base32, and Base64 Data Encodings. RFC 4648
60+
(Proposed Standard). Internet Engineering Task Force, Oct. 2006. URL: <https://tools.ietf.org/html/rfc4648>.

docs/src/verfiication.md

+38-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
11
# Verification Code
22

3-
[https://github.com/SK-EID/smart-id-documentation?tab=readme-ov-file#23132-computing-the-verification-code](https://github.com/SK-EID/smart-id-documentation?tab=readme-ov-file#23132-computing-the-verification-code)
3+
> Source: [https://github.com/SK-EID/smart-id-documentation?tab=readme-ov-file#23132-computing-the-verification-code](https://github.com/SK-EID/smart-id-documentation?tab=readme-ov-file#23132-computing-the-verification-code)
44
5-
## 2.3.13.2 Computing the verification code
6-
The RP must compute a verification code for each authentication and siging request, so the user can bind together the session on the browser or RP app and the authentication request on the Smart-ID app. The VC is computed as follows:
5+
#### 2.3.13.2 Computing the verification code
6+
7+
The RP must compute a verification code for each authentication and siging request, so the
8+
user can bind together the session on the browser or RP app and the authentication request
9+
on the Smart-ID app. The VC is computed as follows:
710

811
`integer(SHA256(hash)[-2:-1]) mod 10000`
912

10-
Calculate SHA256 from the hash to be signed, extract 2 rightmost bytes from the result, interpret them as a big-endian unsigned integer and take the last 4 digits in decimal form for display. SHA256 is always used here, no matter what algorithm was used to calculate the original hash.
13+
Calculate SHA256 from the hash to be signed, extract 2 rightmost bytes from the result,
14+
interpret them as a big-endian unsigned integer and take the last 4 digits in decimal form for
15+
display. SHA256 is always used here, no matter what algorithm was used to calculate the
16+
original hash.
17+
18+
Please mind that hash is a real hash byte value (for example, the byte array returned
19+
from the `md.digest()` call), not the Base64 form used for transport or the popular hexadecimal
20+
representation.
21+
22+
The VC value must be displayed to the user in the browser together with a message asking
23+
the end user to verify the code matches with the one displayed on their mobile device. The
24+
user must not proceed if these don't match.
25+
26+
[^1]: See https://docs.oracle.com/javase/8/docs/api/java/security/SecureRandom.html
1127

12-
Please mind that hash is a real hash byte value (for example, the byte array returned from the md.digest() call), not the Base64 form used for transport or the popular hexadecimal representation.
28+
#### 2.3.13.3 Verifying the authentication response
1329

14-
The VC value must be displayed to the user in the browser together with a message asking the end user to verify the code matches with the one displayed on their mobile device. The user must not proceed if these don't match.
30+
After receiving the transaction response from the Session status API call, the following
31+
algorithm must be used to decide, if the authentication result is trustworthy and what the identity
32+
of the authenticating end user is.
1533

16-
## 2.3.13.3 Verifying the authentication response
17-
After receiving the transaction response from the Session status API call, the following algorithm must be used to decide, if the authentication result is trustworthy and what the identity of the authenticating end user is.
34+
- `result.endResult` has the value `OK`.
35+
- The certificate from `cert.value` is valid:
36+
- The certificate is trusted (signed by a trusted CA).
37+
- The certificate has not expired.
38+
- The person's certificate given in the `cert.value` is of required or higher assurance level
39+
as requested.
40+
- The identity of the authenticated person is in the `subject` field or `subjectAltName`
41+
extension of the X.509 certificate.
42+
- `signature.value` is the valid signature over the same `hash`, which was submitted by
43+
the RP verified using the public key from `cert.value`.
1844

19-
result.endResult has the value OK.
20-
The certificate from cert.value is valid:
21-
The certificate is trusted (signed by a trusted CA).
22-
The certificate has not expired.
23-
The person's certificate given in the cert.value is of required or higher assurance level as requested.
24-
The identity of the authenticated person is in the subject field or subjectAltName extension of the X.509 certificate.
25-
signature.value is the valid signature over the same hash, which was submitted by the RP verified using the public key from cert.value.
26-
It is strongly recommended to have these steps performed using standard cryptographic libraries.
45+
It is strongly recommended to have these steps performed using standard cryptographic
46+
libraries.
2747

28-
After successful authentication, the RP must invalidate the old user's browser or API session identifier and generate a new one.
48+
After successful authentication, the RP must invalidate the old user's browser or API
49+
session identifier and generate a new one.

examples/smart_id_client.rs

+31-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use tracing::{error, info};
2-
use smart_id_rust_client::{authenticate_by_semantic_identifier, generate_verification_number, get_certificate_by_semantic_identifier, get_config_from_env, sha_digest, sign_by_semantic_identifier};
1+
use tracing::{error, info, warn};
2+
use smart_id_rust_client::{authenticate_by_semantic_identifier, generate_verification_number, get_certificate_by_semantic_identifier, get_config_from_env, SessionSignature, SessionStatus, sha_digest, sign_by_semantic_identifier};
33
use smart_id_rust_client::common::{CountryCode, HashType, IdentityType, Interaction, ResultState, SemanticsIdentifier};
44
use smart_id_rust_client::config::{SmartIDConfig, SmartIDConfigBuilder};
55
use anyhow::Result;
@@ -22,10 +22,10 @@ async fn main() -> Result<()> {
2222

2323

2424
/// Example get Certificate
25-
let _ = uc_get_certificate_choice(&cfg).await;
25+
//let _ = uc_get_certificate_choice(&cfg).await;
2626

2727
/// Example authenticate user
28-
let _ = uc_authenticate_by_semantic_identifier(&cfg).await;
28+
//let _ = uc_authenticate_by_semantic_identifier(&cfg).await;
2929

3030
/// Example sign document digest
3131
let _ = uc_sign_by_semantic_identifier(&cfg).await;
@@ -34,12 +34,15 @@ async fn main() -> Result<()> {
3434
}
3535

3636
async fn uc_get_certificate_choice(cfg: &SmartIDConfig) -> Result<()> {
37+
3738
/// Create the semantic identifier
3839
let sem_id = SemanticsIdentifier::new_from_enum(IdentityType::PNO, CountryCode::BE, "81092402747");
40+
41+
/// Verify if a certificate exists for given id
3942
let res = get_certificate_by_semantic_identifier(&cfg, sem_id).await;
4043
match res {
4144
Ok(r) => {
42-
let cert = r.cert.unwrap().value.unwrap();
45+
let cert = validate_response_success(r).map(|res| res.cert.unwrap().value.unwrap())?;
4346
info!("Smart ID Certificate {:#?}", cert);
4447
Ok(())
4548
}
@@ -63,18 +66,14 @@ async fn uc_authenticate_by_semantic_identifier(cfg: &SmartIDConfig) -> Result<(
6366

6467
/// Ask user for authentication
6568
let res = authenticate_by_semantic_identifier(&cfg, sem_id, interactions, b64_hash, hash_type).await;
69+
6670
match res {
6771
Ok(r) => {
68-
info!("Smart ID Authentication DUMP RESPONSE {:#?}", r);
69-
if r.state == "COMPLETE" && ResultState::from(r.result.end_result).eq(&ResultState::OK) {
70-
let cert = r.cert.unwrap().value.unwrap();
71-
info!("Smart ID Authentication Result {:#?}", cert);
72-
Ok(())
73-
} else {
74-
Err(anyhow::anyhow!("Error UC authenticate"))
75-
}
72+
let session_result = validate_response_success(r).map(|res| res.result)?;
73+
info!("Smart ID Authentication result {:#?}", session_result);
74+
Ok(())
7675
}
77-
Err(e) => Err(anyhow::anyhow!("Error UC Authenticate: {:?}", e))
76+
Err(_) => Err(anyhow::anyhow!("Error during authentication"))
7877
}
7978
}
8079

@@ -98,15 +97,25 @@ async fn uc_sign_by_semantic_identifier(cfg: &SmartIDConfig) -> Result<()> {
9897
let res = sign_by_semantic_identifier(&cfg, sem_id, interactions, b64_hash, hash_type).await;
9998
match res {
10099
Ok(r) => {
101-
info!("Smart ID SIGN DUMP RESPONSE {:#?}", r);
102-
if r.state == "COMPLETE" && ResultState::from(r.result.end_result).eq(&ResultState::OK) {
103-
let siganture = r.signature.unwrap().value.unwrap();
104-
info!("Smart ID SIGN Result {:#?}", siganture);
105-
Ok(())
106-
} else {
107-
Err(anyhow::anyhow!("Error UC SIGN"))
100+
match validate_response_success(r).map(|res| res.signature)? {
101+
None => {
102+
warn!("No signature");
103+
Ok(())
104+
}
105+
Some(signature) => {
106+
info!("Smart ID signature result {:#?}", signature);
107+
Ok(())
108+
}
108109
}
109110
}
110-
Err(e) => Err(anyhow::anyhow!("Error UC SIGN: {:?}", e))
111+
Err(_) => Err(anyhow::anyhow!("Error signing digest"))
112+
}
113+
}
114+
115+
fn validate_response_success(response: SessionStatus) -> Result<SessionStatus> {
116+
if response.state == "COMPLETE" && ResultState::from(response.result.end_result.clone()).eq(&ResultState::OK) {
117+
Ok(response)
118+
} else {
119+
Err(anyhow::anyhow!("Error SmartID Response"))
111120
}
112121
}

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ use crate::client_controller::{ctrl_authenticate_by_document_number, ctrl_authen
2121
/// Common models are exposed
2222
pub use models::common;
2323
pub use crate::models::session::SessionStatus;
24+
pub use crate::models::session::SessionSignature;
25+
pub use crate::models::session::SessionCertificate;
26+
pub use crate::models::session::SessionResult;
2427
pub use utils::verification::{generate_verification_number, sha_digest};
2528

2629

0 commit comments

Comments
 (0)