-
Notifications
You must be signed in to change notification settings - Fork 2
feat(licensing): quota enforcement, client rejection and trial license limits #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
21ede68
dda621d
be31b42
53ae0e1
567c2bb
f9f1d8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ impl HandleWithResponse for Heartbeat { | |
| machine_uuid: self.machine_uuid, | ||
| }, | ||
| app, | ||
| false, | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,10 @@ use crate::app::RuntimeApp; | |
| use crate::config::Config; | ||
| use anyhow::{Context, Result}; | ||
| use app::App; | ||
| use db::config::Config as dbConfig; | ||
| use db::node_nic::ReplaceNic; | ||
| use license::LicenseVerifier; | ||
| use protobuf::license::CertType; | ||
| use shared::bee_msg::target::RefreshTargetStates; | ||
| use shared::conn::incoming; | ||
| use shared::conn::outgoing::Pool; | ||
|
|
@@ -114,6 +116,31 @@ pub async fn start(info: StaticInfo, license: LicenseVerifier) -> Result<RunCont | |
| }) | ||
| .await?; | ||
|
|
||
| let prev_trial_serial: Option<String> = db | ||
| .read_tx(|tx| db::config::get(tx, db::config::Config::TrialSerial)) | ||
| .await?; | ||
|
|
||
| // Load and verify license certificate | ||
| match license | ||
| .load_and_verify_license_cert(&info.user_config.license_cert_file, prev_trial_serial) | ||
| .await | ||
| { | ||
| Ok(serial) => { | ||
| if license | ||
| .get_license_cert_data()? | ||
| .data | ||
| .is_some_and(|d| d.r#type == CertType::Trial.into()) | ||
| { | ||
| db.write_tx(|tx| db::config::set(tx, dbConfig::TrialSerial, serial)) | ||
| .await?; | ||
| } | ||
| } | ||
| Err(err) => log::warn!( | ||
| "Initializing licensing library failed. \ | ||
| Licensed features will be unavailable: {err}" | ||
|
Comment on lines
+139
to
+140
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Potentially incorrect message. Should be rather like "Loading and verifying license failed"
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I thought about that. But it also doesn't really matter to the user. I intended "Initializing library" to mean the entire process of initialization including loading and verifying a license file. But I have changed it. There is another log before on warning level when the license library can not be loaded. |
||
| ), | ||
| }; | ||
|
|
||
| // Fill node addrs store from db | ||
| db.read_tx(db::node_nic::get_all_addrs) | ||
| .await? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,6 +203,7 @@ impl LicenseVerifier { | |
| pub async fn load_and_verify_license_cert( | ||
| &self, | ||
| cert_path: impl AsRef<Path>, | ||
| prev_trial_serial: Option<String>, | ||
| ) -> Result<String> { | ||
| let Some(ref library) = self.0 else { | ||
| bail!("License verification library not loaded."); | ||
|
|
@@ -223,14 +224,27 @@ impl LicenseVerifier { | |
| let message = res.message; | ||
|
|
||
| match result { | ||
| VerifyResult::VerifyValid => { | ||
| log::info!("Successfully loaded license certificate: {serial}"); | ||
| Ok(serial) | ||
| } | ||
| VerifyResult::VerifyValid => match self.get_license_cert_data() { | ||
| Ok(c) => { | ||
| if c.data.is_some_and(|d| { | ||
| d.r#type() == CertType::Trial | ||
| && prev_trial_serial.is_some_and(|s| serial != s) | ||
| }) { | ||
| library.init_cert_store(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Why is this called again here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clear the cert store. The license we loaded might be valid, so we have to actively clear it if we reject applying it. |
||
| Err(anyhow!( | ||
| "System has previously used different trial license." | ||
| )) | ||
| } else { | ||
| log::info!("Successfully loaded license certificate: {serial}"); | ||
| Ok(serial) | ||
| } | ||
| } | ||
| Err(err) => Err(anyhow!("Error getting license data: {err}")), | ||
| }, | ||
| VerifyResult::VerifyInvalid => Err(anyhow!(message)), | ||
| VerifyResult::VerifyError => Err(anyhow!( | ||
| "Internal error during certificate verification: {message}" | ||
| )), | ||
| VerifyResult::VerifyError => { | ||
| Err(anyhow!("Error during license verification: {message}")) | ||
| } | ||
| VerifyResult::VerifyUnspecified => Err(anyhow!("Unspecified result.")), | ||
| } | ||
| } | ||
|
|
@@ -288,9 +302,9 @@ impl LicenseVerifier { | |
| match result { | ||
| VerifyResult::VerifyValid => Ok(()), | ||
| VerifyResult::VerifyInvalid => Err(anyhow!(message)), | ||
| VerifyResult::VerifyError => Err(anyhow!( | ||
| "Internal error during feature verification: {message}" | ||
| )), | ||
| VerifyResult::VerifyError => { | ||
| Err(anyhow!("Error during feature verification: {message}")) | ||
| } | ||
| VerifyResult::VerifyUnspecified => Err(anyhow!("Unspecified result.")), | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.