Compare commits

...

2 Commits

15 changed files with 257 additions and 39 deletions

86
Cargo.lock generated
View File

@ -70,7 +70,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -340,9 +340,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.5"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052"
checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f"
[[package]]
name = "cesu8"
@ -399,6 +399,10 @@ dependencies = [
[[package]]
name = "clego"
version = "0.1.0"
dependencies = [
"dotenv",
"libc",
]
[[package]]
name = "cocoa"
@ -553,7 +557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331"
dependencies = [
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -563,7 +567,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f"
dependencies = [
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -587,7 +591,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -598,7 +602,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -621,7 +625,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -681,9 +685,15 @@ checksum = "f2b99bf03862d7f545ebc28ddd33a665b50865f4dfd84031a393823879bd4c54"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "dpi"
version = "0.1.1"
@ -722,9 +732,9 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
[[package]]
name = "embed-resource"
version = "2.4.2"
version = "2.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6985554d0688b687c5cb73898a34fbe3ad6c24c58c238a4d91d5e840670ee9d"
checksum = "4edcacde9351c33139a41e3c97eb2334351a81a2791bebb0b243df837128f602"
dependencies = [
"cc",
"memchr",
@ -818,7 +828,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -902,7 +912,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1160,7 +1170,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1239,7 +1249,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2228,7 +2238,7 @@ dependencies = [
"phf_shared 0.11.2",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2275,7 +2285,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2670,7 +2680,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2742,7 +2752,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2753,7 +2763,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2785,7 +2795,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2836,7 +2846,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3058,9 +3068,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.71"
version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
dependencies = [
"proc-macro2",
"quote",
@ -3251,7 +3261,7 @@ dependencies = [
"serde",
"serde_json",
"sha2",
"syn 2.0.71",
"syn 2.0.72",
"tauri-utils",
"thiserror",
"time",
@ -3269,7 +3279,7 @@ dependencies = [
"heck 0.5.0",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
"tauri-codegen",
"tauri-utils",
]
@ -3419,22 +3429,22 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
[[package]]
name = "thiserror"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3518,7 +3528,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3641,7 +3651,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3919,7 +3929,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
"wasm-bindgen-shared",
]
@ -3953,7 +3963,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -4053,7 +4063,7 @@ checksum = "ac1345798ecd8122468840bcdf1b95e5dc6d2206c5e4b0eafa078d061f59c9bc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -4159,7 +4169,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -4170,7 +4180,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]

View 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

View 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
clego/.env.linux.example Normal file
View 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
clego/.env.win.example Normal file
View File

@ -0,0 +1,2 @@
SESAM_FSV_VERSION=1.40.13
SESAM_INI_PATH=${ALLUSERSPROFILE}\\santesocial\\fsv\\${SESAM_FSV_VERSION}\\conf\\sesam.ini

9
clego/.gitignore vendored Normal file
View 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

View File

@ -4,3 +4,8 @@ version = "0.1.0"
edition = "2021"
[dependencies]
dotenv = "0.15"
libc = "0.2"
[build-dependencies]
dotenv = "0.15"

34
clego/README.md Normal file
View 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 header qui ne sont pas présents dans la `.dll`. Il est donc nécessaire de fournir ces headers, en les renseignant dans des fichiers `src/ssv_headers_c/*.def` qui seront compilés en leur version binaire `lib/*.lib`.
En cas de modification des fichiers `.def`, pour re-compiler ces headers, faire appel au script `make.bat` du dossier `src/ssv_headers_c`.
| /!\ Attention, le script `make.bat` s'appuie sur l'utilitaire `vcvarsall.bat` et le linker `lib.exe` de Visual Studio. Le chemin vers l'intallation de Visual Studio est renseigné en dur dans le script `make.bat` et doit être adapté en fonction de l'installation de Visual Studio sur votre machine.
## À 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
clego/build.rs Normal file
View 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
clego/lib/.gitkeep Normal file
View File

BIN
clego/lib/ssvw64.lib Normal file

Binary file not shown.

View File

@ -1,3 +1,5 @@
mod ssvlib_demo;
fn main() {
println!("Hello, world!");
ssvlib_demo::demo();
}

View File

@ -0,0 +1,28 @@
@echo off
rem Set variables
set LIB_DIR=..\..\lib
rem Create the %LIB_DIR% directory if it does not exist
if not exist %LIB_DIR% mkdir %LIB_DIR%
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

View File

@ -0,0 +1,5 @@
LIBRARY "ssvw64"
EXPORTS
SSV_InitLIB2
SSV_LireCartePS
SSV_LireConfig

84
clego/src/ssvlib_demo.rs Normal file
View 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!("-----------------------------------------");
}