forked from proxmox-mirrors/proxmox
subscription: move most of the implmentation into impl
feature
so we can use the types without having openssl, proxmox-sys, etc. as dependencies. Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
f96c0e6036
commit
ae55575f2a
@ -13,20 +13,21 @@ rust-version.workspace = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
base64.workspace = true
|
base64 = { workspace = true, optional = true }
|
||||||
hex.workspace = true
|
hex = { workspace = true, optional = true }
|
||||||
openssl.workspace = true
|
openssl = { workspace = true, optional = true }
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
|
|
||||||
proxmox-http = { workspace = true, features = ["client-trait", "http-helpers"] }
|
proxmox-http = { workspace = true, optional = true, features = ["client-trait", "http-helpers"] }
|
||||||
proxmox-serde.workspace = true
|
proxmox-serde.workspace = true
|
||||||
proxmox-sys.workspace = true
|
proxmox-sys = { workspace = true, optional = true }
|
||||||
proxmox-time.workspace = true
|
proxmox-time = { workspace = true, optional = true }
|
||||||
|
|
||||||
proxmox-schema = { workspace = true, features = ["api-macro"], optional = true }
|
proxmox-schema = { workspace = true, features = ["api-macro"], optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["impl"]
|
||||||
|
impl = [ "dep:base64", "dep:hex", "dep:openssl", "dep:proxmox-http", "dep:proxmox-sys", "dep:proxmox-time"]
|
||||||
api-types = ["dep:proxmox-schema"]
|
api-types = ["dep:proxmox-schema"]
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
|
|
||||||
mod subscription_info;
|
mod subscription_info;
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
pub use subscription_info::{
|
pub use subscription_info::{
|
||||||
get_hardware_address, ProductType, SubscriptionInfo, SubscriptionStatus,
|
get_hardware_address, ProductType, SubscriptionInfo, SubscriptionStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "impl"))]
|
||||||
|
pub use subscription_info::{ProductType, SubscriptionInfo, SubscriptionStatus};
|
||||||
|
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
pub mod check;
|
pub mod check;
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
pub mod files;
|
pub mod files;
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
pub mod sign;
|
pub mod sign;
|
||||||
|
@ -1,23 +1,11 @@
|
|||||||
use std::{fmt::Display, path::Path, str::FromStr};
|
use std::{fmt::Display, str::FromStr};
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, Error};
|
||||||
use openssl::hash::{hash, DigestBytes, MessageDigest};
|
|
||||||
use proxmox_sys::fs::file_get_contents;
|
|
||||||
use proxmox_time::TmEditor;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[cfg(feature = "api-types")]
|
#[cfg(feature = "api-types")]
|
||||||
use proxmox_schema::{api, Updater};
|
use proxmox_schema::{api, Updater};
|
||||||
|
|
||||||
use crate::sign::Verifier;
|
|
||||||
|
|
||||||
pub(crate) const SHARED_KEY_DATA: &str = "kjfdlskfhiuewhfk947368";
|
|
||||||
|
|
||||||
/// How long the local key is valid for in between remote checks
|
|
||||||
pub(crate) const SUBSCRIPTION_MAX_LOCAL_KEY_AGE: i64 = 15 * 24 * 3600;
|
|
||||||
pub(crate) const SUBSCRIPTION_MAX_LOCAL_SIGNED_KEY_AGE: i64 = 365 * 24 * 3600;
|
|
||||||
pub(crate) const SUBSCRIPTION_MAX_KEY_CHECK_FAILURE_AGE: i64 = 5 * 24 * 3600;
|
|
||||||
|
|
||||||
// Aliases are needed for PVE compat!
|
// Aliases are needed for PVE compat!
|
||||||
#[cfg_attr(feature = "api-types", api())]
|
#[cfg_attr(feature = "api-types", api())]
|
||||||
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
@ -144,6 +132,34 @@ pub struct SubscriptionInfo {
|
|||||||
pub signature: Option<String>,
|
pub signature: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
|
pub use _impl::get_hardware_address;
|
||||||
|
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
|
pub(crate) use _impl::{md5sum, SHARED_KEY_DATA};
|
||||||
|
|
||||||
|
#[cfg(feature = "impl")]
|
||||||
|
mod _impl {
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use anyhow::format_err;
|
||||||
|
use anyhow::{bail, Error};
|
||||||
|
use openssl::hash::{hash, DigestBytes, MessageDigest};
|
||||||
|
use proxmox_sys::fs::file_get_contents;
|
||||||
|
use proxmox_time::TmEditor;
|
||||||
|
|
||||||
|
use crate::sign::Verifier;
|
||||||
|
|
||||||
|
pub(crate) const SHARED_KEY_DATA: &str = "kjfdlskfhiuewhfk947368";
|
||||||
|
|
||||||
|
/// How long the local key is valid for in between remote checks
|
||||||
|
pub(crate) const SUBSCRIPTION_MAX_LOCAL_KEY_AGE: i64 = 15 * 24 * 3600;
|
||||||
|
pub(crate) const SUBSCRIPTION_MAX_LOCAL_SIGNED_KEY_AGE: i64 = 365 * 24 * 3600;
|
||||||
|
pub(crate) const SUBSCRIPTION_MAX_KEY_CHECK_FAILURE_AGE: i64 = 5 * 24 * 3600;
|
||||||
|
|
||||||
|
use super::{ProductType, SubscriptionInfo, SubscriptionStatus};
|
||||||
|
|
||||||
impl SubscriptionInfo {
|
impl SubscriptionInfo {
|
||||||
/// Returns the canonicalized signed data and, if available, signature contained in `self`.
|
/// Returns the canonicalized signed data and, if available, signature contained in `self`.
|
||||||
pub fn signed_data(&self) -> Result<(Vec<u8>, Option<String>), Error> {
|
pub fn signed_data(&self) -> Result<(Vec<u8>, Option<String>), Error> {
|
||||||
@ -306,7 +322,8 @@ pub fn get_hardware_address() -> Result<String, Error> {
|
|||||||
|
|
||||||
let contents = proxmox_sys::fs::file_get_contents(FILENAME)
|
let contents = proxmox_sys::fs::file_get_contents(FILENAME)
|
||||||
.map_err(|e| format_err!("Error getting host key - {}", e))?;
|
.map_err(|e| format_err!("Error getting host key - {}", e))?;
|
||||||
let digest = md5sum(&contents).map_err(|e| format_err!("Error digesting host key - {}", e))?;
|
let digest =
|
||||||
|
md5sum(&contents).map_err(|e| format_err!("Error digesting host key - {}", e))?;
|
||||||
|
|
||||||
Ok(hex::encode(digest).to_uppercase())
|
Ok(hex::encode(digest).to_uppercase())
|
||||||
}
|
}
|
||||||
@ -337,3 +354,4 @@ fn parse_next_due(value: &str) -> Result<i64, Error> {
|
|||||||
|
|
||||||
tm.into_epoch()
|
tm.into_epoch()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user