feature: Implement basics from FSV and CryptolibCPS

This commit is contained in:
Florian Briand 2024-07-05 00:28:02 +02:00
parent 7a22503bac
commit 9c1e06915e
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B
3 changed files with 81 additions and 3 deletions

View File

@ -1,3 +1,12 @@
## À explorer ## À explorer
- Générer des bindings RUST depuis des .h : https://jvns.ca/blog/2017/12/21/bindgen-is-awesome/ - Générer des bindings RUST depuis des .h : https://jvns.ca/blog/2017/12/21/bindgen-is-awesome/
## Setup
- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale)
- Ajouter le path des librairies FSV à `LD_LIBRARY_PATH` : `export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH`
- Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps)
- Fourni l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
- Linux : `cpgeslux`

View File

@ -2,4 +2,8 @@ fn main() {
println!("cargo:rustc-link-search=native=./lib"); println!("cargo:rustc-link-search=native=./lib");
println!("cargo:rustc-link-lib=static=p4pillondebuglib"); println!("cargo:rustc-link-lib=static=p4pillondebuglib");
println!("cargo:rerun-if-changed=lib/libp4pillondebuglib.a"); println!("cargo:rerun-if-changed=lib/libp4pillondebuglib.a");
println!("cargo:rustc-link-search=native=/opt/santesocial/fsv/1.40.13/lib");
println!("cargo:rustc-link-lib=dylib=ssvlux64");
println!("cargo:rerun-if-changed=/opt/santesocial/fsv/1.40.13/lib/libssvlux64.so");
} }

View File

@ -1,6 +1,6 @@
extern crate libc; extern crate libc;
use libc::{ c_char, c_int, c_void, size_t }; use libc::{ c_char, c_int, c_void, c_ushort, size_t };
use std::ffi::{ CStr, CString }; use std::ffi::{ CStr, CString };
use std::ptr; use std::ptr;
@ -16,11 +16,74 @@ extern "C" {
fn fillHexValues(result: *mut *mut c_void, size: *mut size_t); fn fillHexValues(result: *mut *mut c_void, size: *mut size_t);
} }
#[link(name = "ssvlux64")]
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 = CString::new("/etc/opt/santesocial/fsv/1.40.13/conf/sesam.ini").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);
}
}
}
fn main() { fn main() {
unsafe { unsafe {
let c_str = hello(); let c_str = hello();
let r_str = CStr::from_ptr(c_str).to_str().unwrap(); let r_str: &str = CStr::from_ptr(c_str).to_str().unwrap();
println!("{} from C", r_str); println!("{} from C", r_str);
} }
@ -96,6 +159,8 @@ fn main() {
} }
} }
ssv_init_lib_2();
ssv_lire_carte_ps();
ssv_lire_config();
} }