Feature : mise en place de Clego avec un exemple d'implémentation crossplateforme de la librairie SESAM-Vitale SSV #23
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -769,6 +769,12 @@ dependencies = [
|
|||||||
"syn 2.0.72",
|
"syn 2.0.72",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dotenv"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dpi"
|
name = "dpi"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -2924,6 +2930,10 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "sesam-vitale"
|
name = "sesam-vitale"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"dotenv",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
|
3
crates/sesam-vitale/.env.build.linux.example
Normal file
3
crates/sesam-vitale/.env.build.linux.example
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
SESAM_FSV_VERSION=1.40.13
|
||||||
|
SESAM_FSV_LIB_PATH=/opt/santesocial/fsv/${SESAM_FSV_VERSION}/lib
|
||||||
|
SESAM_FSV_SSVLIB=ssvlux64
|
3
crates/sesam-vitale/.env.build.win.example
Normal file
3
crates/sesam-vitale/.env.build.win.example
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
SESAM_FSV_VERSION=1.40.13
|
||||||
|
SESAM_FSV_LIB_PATH="C:/Program Files/santesocial/fsv/${SESAM_FSV_VERSION}/lib"
|
||||||
|
SESAM_FSV_SSVLIB=ssvw64
|
2
crates/sesam-vitale/.env.linux.example
Normal file
2
crates/sesam-vitale/.env.linux.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
SESAM_FSV_VERSION=1.40.13
|
||||||
|
SESAM_INI_PATH=/etc/opt/santesocial/fsv/${SESAM_FSV_VERSION}/conf/sesam.ini
|
2
crates/sesam-vitale/.env.win.example
Normal file
2
crates/sesam-vitale/.env.win.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
SESAM_FSV_VERSION=1.40.13
|
||||||
|
SESAM_INI_PATH=${ALLUSERSPROFILE}\\santesocial\\fsv\\${SESAM_FSV_VERSION}\\conf\\sesam.ini
|
9
crates/sesam-vitale/.gitignore
vendored
Normal file
9
crates/sesam-vitale/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Ignore Rust target directory
|
||||||
|
/target
|
||||||
|
|
||||||
|
# Ignore .env files
|
||||||
|
.env
|
||||||
|
.env.build
|
||||||
|
|
||||||
|
# Ignore exploitation files - only usefull for local debugging on windows
|
||||||
|
lib/*.exp
|
@ -4,3 +4,8 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
dotenv = "0.15"
|
||||||
|
libc = "0.2"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
dotenv = "0.15"
|
||||||
|
34
crates/sesam-vitale/README.md
Normal file
34
crates/sesam-vitale/README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale)
|
||||||
|
- Les librairies dynamiques (.lib, .dll, ...) fournies ne sont pas installés dans les emplacements standard du système, il faudra donc configurer leur chemin d'installation dans le fichier de configuration `.env.build` (voir ci-dessous)
|
||||||
|
- Le détail des chemins d'installation est donné dans la documentation du package FSV `fsv-mi-004_pack-FSV1.40.14_V2.3.pdf`
|
||||||
|
- Linux - par défaut : `/opt/santesocial/fsv/1.40.13/lib`
|
||||||
|
- Windows - par défaut : `C:\Program Files\santesocial\santesocial\fsv\1.40.14\lib` (ou dans Program Files (x86) si c'est le package 32bits qui a été installé)
|
||||||
|
|
||||||
|
- Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps)
|
||||||
|
- Ce package fourni également l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
|
||||||
|
- Linux : `cpgeslux`
|
||||||
|
- Windows : `...`
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
- Créer et éditer le fichier de configuration de build `.env.build` en s'inspirant d'un des fichiers d'exemple (`.env.build.linux.example`, `.env.build.win.example`...)
|
||||||
|
- Ce fichier est nécessaire pour le build du package Rust
|
||||||
|
- Créer et éditer le fichier de configuration de l'exécution `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...)
|
||||||
|
- Ce fichier est nécessaire pour l'exécution du package Rust compilé, et doit donc être présent aux côtés de l'exécutable généré, le cas échéant
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
### Windows - Compilation des headers FSV
|
||||||
|
|
||||||
|
Sous windows, la librairie dynamique fournie par le package FSV nécessite des headers qui ne sont pas présents dans la `.dll`. Il est donc nécessaire de fournir ces headers, en les renseignant dans des fichiers `crates/sesam-vitale/src/win/fsv/*.def` qui seront compilés en leur version binaire `crates/sesam-vitale/lib/*.lib`.
|
||||||
|
|
||||||
|
En cas de modification des fichiers `.def`, pour re-compiler ces headers, faire appel au script `scripts/compile_win_headers.bat`.
|
||||||
|
|
||||||
|
| /!\ Attention, le script `compile_win_headers.bat` exécute, en interne, l'utilitaire `vcvarsall.bat` et le linker `lib.exe` de Visual Studio. Visual Studio doit donc être installé et le chemin vers l'intallation le script `vcvarsall.bat`, écrit en dur dans le script `compile_win_headers.bat` doit être adapté à votre installation.
|
||||||
|
|
||||||
|
## À creuser
|
||||||
|
|
||||||
|
- Compilation cross platform facilitée par du Docker : https://github.com/cross-rs/cross
|
||||||
|
- Pour éviter l'usage de dotenv pour la configuration, on peut utiliser https://direnv.net/
|
31
crates/sesam-vitale/build.rs
Normal file
31
crates/sesam-vitale/build.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
extern crate dotenv;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Load the .env.build file for build-time environment variables
|
||||||
|
dotenv::from_filename(".env.build").ok();
|
||||||
|
println!("cargo::rerun-if-changed=.env.build");
|
||||||
|
|
||||||
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
|
||||||
|
// Add local lib directory to the linker search path (for def files and static libs)
|
||||||
|
let static_lib_path = PathBuf::from(manifest_dir).join("lib");
|
||||||
|
println!("cargo::rustc-link-search=native={}", static_lib_path.display());
|
||||||
|
|
||||||
|
// Add the SESAM_FSV_LIB_PATH to the linker search path
|
||||||
|
let fsv_lib_path = PathBuf::from(env::var("SESAM_FSV_LIB_PATH").unwrap());
|
||||||
|
println!("cargo::rustc-link-search=native={}", fsv_lib_path.display());
|
||||||
|
|
||||||
|
// Add the SESAM_FSV_LIB_PATH to the PATH environment variable
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
let path = env::var("PATH").unwrap_or(String::new());
|
||||||
|
println!("cargo:rustc-env=PATH={};{}", fsv_lib_path.display(), path);
|
||||||
|
} else if cfg!(target_os = "linux") {
|
||||||
|
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", fsv_lib_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Link the SESAM_FSV_SSVLIB dynamic library
|
||||||
|
println!("cargo::rustc-link-lib=dylib={}", env::var("SESAM_FSV_SSVLIB").unwrap());
|
||||||
|
}
|
0
crates/sesam-vitale/lib/.gitkeep
Normal file
0
crates/sesam-vitale/lib/.gitkeep
Normal file
BIN
crates/sesam-vitale/lib/ssvw64.lib
Normal file
BIN
crates/sesam-vitale/lib/ssvw64.lib
Normal file
Binary file not shown.
5
crates/sesam-vitale/src/main.rs
Normal file
5
crates/sesam-vitale/src/main.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
mod ssvlib_demo;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
ssvlib_demo::demo();
|
||||||
|
}
|
84
crates/sesam-vitale/src/ssvlib_demo.rs
Normal file
84
crates/sesam-vitale/src/ssvlib_demo.rs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
extern crate libc;
|
||||||
|
extern crate dotenv;
|
||||||
|
|
||||||
|
use libc::{ c_char, c_void, c_ushort, size_t };
|
||||||
|
use std::ffi::CString;
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort;
|
||||||
|
fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||||
|
fn SSV_LireConfig(ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssv_init_lib_2() {
|
||||||
|
let ini_str = env::var("SESAM_INI_PATH").expect("SESAM_INI_PATH must be set");
|
||||||
|
let ini = CString::new(ini_str).expect("CString::new failed");
|
||||||
|
unsafe {
|
||||||
|
let result = SSV_InitLIB2(ini.as_ptr());
|
||||||
|
println!("SSV_InitLIB2 result: {}", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssv_lire_carte_ps() {
|
||||||
|
let resource_ps = CString::new("PS").expect("CString::new failed");
|
||||||
|
let resource_reader = CString::new("TRANSPA1").expect("CString::new failed");
|
||||||
|
let card_number = CString::new("1234567890").expect("CString::new failed");
|
||||||
|
|
||||||
|
let mut buffer: *mut c_void = ptr::null_mut();
|
||||||
|
let mut size: size_t = 0;
|
||||||
|
unsafe {
|
||||||
|
let result = SSV_LireCartePS(
|
||||||
|
resource_ps.as_ptr(),
|
||||||
|
resource_reader.as_ptr(),
|
||||||
|
card_number.as_ptr(),
|
||||||
|
&mut buffer,
|
||||||
|
&mut size
|
||||||
|
);
|
||||||
|
println!("SSV_LireCartePS result: {}", result);
|
||||||
|
|
||||||
|
if !buffer.is_null() {
|
||||||
|
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||||
|
for &byte in hex_values {
|
||||||
|
print!("{:02X} ", byte);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
|
||||||
|
libc::free(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ssv_lire_config() {
|
||||||
|
let mut buffer: *mut c_void = ptr::null_mut();
|
||||||
|
let mut size: size_t = 0;
|
||||||
|
unsafe {
|
||||||
|
let result = SSV_LireConfig(&mut buffer, &mut size);
|
||||||
|
println!("SSV_LireConfig result: {}", result);
|
||||||
|
|
||||||
|
if !buffer.is_null() {
|
||||||
|
let hex_values = std::slice::from_raw_parts(buffer as *const u8, size);
|
||||||
|
for &byte in hex_values {
|
||||||
|
print!("{:02X} ", byte);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
|
||||||
|
libc::free(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn demo() {
|
||||||
|
dotenv().ok();
|
||||||
|
|
||||||
|
println!("------- Demo for the SSV library --------");
|
||||||
|
|
||||||
|
ssv_init_lib_2();
|
||||||
|
ssv_lire_carte_ps();
|
||||||
|
ssv_lire_config();
|
||||||
|
|
||||||
|
println!("-----------------------------------------");
|
||||||
|
}
|
5
crates/sesam-vitale/src/win/fsv/ssvw64.def
Normal file
5
crates/sesam-vitale/src/win/fsv/ssvw64.def
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
LIBRARY "ssvw64"
|
||||||
|
EXPORTS
|
||||||
|
SSV_InitLIB2
|
||||||
|
SSV_LireCartePS
|
||||||
|
SSV_LireConfig
|
26
scripts/compile_win_headers.bat
Normal file
26
scripts/compile_win_headers.bat
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
@echo off
|
||||||
|
rem Set variables
|
||||||
|
set LIB_DIR=crates/sesam-vitale/lib
|
||||||
|
set DEF_DIR=crates/sesam-vitale/src/win/fsv
|
||||||
|
|
||||||
|
if "%1"=="/clean" (
|
||||||
|
goto clean
|
||||||
|
)
|
||||||
|
|
||||||
|
rem Set the environment for the x64 platform
|
||||||
|
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||||
|
|
||||||
|
rem Create a ssvw64.lib file from the ssvw64.def file
|
||||||
|
lib /def:ssvw64.def /out:%LIB_DIR%\ssvw64.lib /machine:x64
|
||||||
|
|
||||||
|
rem Build complete
|
||||||
|
pause
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:clean
|
||||||
|
del %LIB_DIR%\*.lib
|
||||||
|
del %LIB_DIR%\*.exp
|
||||||
|
|
||||||
|
rem Clean complete
|
||||||
|
pause
|
||||||
|
exit /b 0
|
Loading…
Reference in New Issue
Block a user