use crate::tools;
use failure::*;
+use lazy_static::lazy_static;
use openssl::rsa::{Rsa};
+use openssl::pkey::{PKey, Public, Private};
+
use std::path::PathBuf;
pub fn generate_csrf_key() -> Result<(), Error> {
Ok(())
}
+
+pub fn csrf_secret() -> &'static [u8] {
+
+ lazy_static! {
+ static ref SECRET: Vec<u8> =
+ tools::file_get_contents("/etc/proxmox-backup/csrf.key").unwrap();
+ }
+
+ &SECRET
+}
+
+fn load_private_auth_key() -> Result<PKey<Private>, Error> {
+
+ let pem = tools::file_get_contents("/etc/proxmox-backup/authkey.key")?;
+ let rsa = Rsa::private_key_from_pem(&pem)?;
+ let key = PKey::from_rsa(rsa)?;
+
+ Ok(key)
+}
+
+pub fn private_auth_key() -> &'static PKey<Private> {
+
+ lazy_static! {
+ static ref KEY: PKey<Private> = load_private_auth_key().unwrap();
+ }
+
+ &KEY
+}
+
+fn load_public_auth_key() -> Result<PKey<Public>, Error> {
+
+ let pem = tools::file_get_contents("/etc/proxmox-backup/authkey.pub")?;
+ let rsa = Rsa::public_key_from_pem(&pem)?;
+ let key = PKey::from_rsa(rsa)?;
+
+ Ok(key)
+}
+
+pub fn public_auth_key() -> &'static PKey<Public> {
+
+ lazy_static! {
+ static ref KEY: PKey<Public> = load_public_auth_key().unwrap();
+ }
+
+ &KEY
+}
use std::sync::Arc;
-use proxmox_backup::tools;
+//use proxmox_backup::tools;
use proxmox_backup::api::schema::*;
use proxmox_backup::api::router::*;
use proxmox_backup::api::config::*;
eprintln!("unable to generate auth key: {}", err);
std::process::exit(-1);
}
+ let _ = private_auth_key(); // load with lazy_static
if let Err(err) = generate_csrf_key() {
eprintln!("unable to generate csrf key: {}", err);
std::process::exit(-1);
}
+ let _ = csrf_secret(); // load with lazy_static
let command : Arc<Schema> = StringSchema::new("Command.")
.format(Arc::new(ApiStringFormat::Enum(vec![
use proxmox_backup::api::config::*;
use proxmox_backup::server::rest::*;
use proxmox_backup::getopts;
+use proxmox_backup::auth_helpers::*;
//use failure::*;
use lazy_static::lazy_static;
std::process::exit(-1);
}
+ let _ = public_auth_key(); // load with lazy_static
+ let _ = csrf_secret(); // load with lazy_static
+
let command : Arc<Schema> = StringSchema::new("Command.")
.format(Arc::new(ApiStringFormat::Enum(vec![
"start".into(),