]> git.proxmox.com Git - proxmox-backup.git/blob - pbs-tools/src/auth.rs
6e605dd85b8382d431b54d7898b1e63650031502
[proxmox-backup.git] / pbs-tools / src / auth.rs
1 //! Helpers for authentication used by both client and server.
2
3 use anyhow::Error;
4 use lazy_static::lazy_static;
5 use openssl::pkey::{PKey, Private};
6 use openssl::rsa::Rsa;
7
8 use proxmox::tools::fs::file_get_contents;
9
10 use pbs_buildcfg::configdir;
11
12 fn load_private_auth_key() -> Result<PKey<Private>, Error> {
13 let pem = file_get_contents(configdir!("/authkey.key"))?;
14 let rsa = Rsa::private_key_from_pem(&pem)?;
15 let key = PKey::from_rsa(rsa)?;
16
17 Ok(key)
18 }
19
20 pub fn private_auth_key() -> &'static PKey<Private> {
21 lazy_static! {
22 static ref KEY: PKey<Private> = load_private_auth_key().unwrap();
23 }
24
25 &KEY
26 }