This commit is contained in:
core 2023-03-29 17:49:02 -04:00
parent 9cea470b43
commit ec7b4a8ea4
Signed by: core
GPG Key ID: FDBF740DADDCEECF
3 changed files with 11 additions and 11 deletions

View File

@ -49,7 +49,7 @@ impl Client {
/// credentials to be used for future DN API requests, and an object containing organization information. /// credentials to be used for future DN API requests, and an object containing organization information.
/// # Errors /// # Errors
/// This function will return an error in any of the following situations: /// This function will return an error in any of the following situations:
/// - the server_url is invalid /// - the `server_url` is invalid
/// - the HTTP request fails /// - the HTTP request fails
/// - the HTTP response is missing X-Request-ID /// - the HTTP response is missing X-Request-ID
/// - X-Request-ID isn't valid UTF-8 /// - X-Request-ID isn't valid UTF-8
@ -100,7 +100,7 @@ impl Client {
Ok((r.config, dh_privkey_pem, creds, meta)) Ok((r.config, dh_privkey_pem, creds, meta))
} }
/// Send a signed message to the DNClient API to learn if there is a new configuration available. /// Send a signed message to the `DNClient` API to learn if there is a new configuration available.
/// # Errors /// # Errors
/// This function returns an error if the dnclient request fails, or the server returns invalid data. /// This function returns an error if the dnclient request fails, or the server returns invalid data.
pub fn check_for_update(&self, creds: &Credentials) -> Result<bool, Box<dyn Error>> { pub fn check_for_update(&self, creds: &Credentials) -> Result<bool, Box<dyn Error>> {
@ -111,10 +111,10 @@ impl Client {
Ok(result.data.update_available) Ok(result.data.update_available)
} }
/// Send a signed message to the DNClient API to fetch the new configuration update. During this call a new /// Send a signed message to the `DNClient` API to fetch the new configuration update. During this call a new
/// DH X25519 keypair is generated for the new Nebula certificate as well as a new Ed25519 keypair for DNClient API /// DH X25519 keypair is generated for the new Nebula certificate as well as a new Ed25519 keypair for `DNClient` API
/// communication. On success it returns the new config, a Nebula private key PEM to be inserted into the config /// communication. On success it returns the new config, a Nebula private key PEM to be inserted into the config
/// and new DNClient API credentials /// and new `DNClient` API credentials
/// # Errors /// # Errors
/// This function returns an error in any of the following scenarios: /// This function returns an error in any of the following scenarios:
/// - if the message could not be serialized /// - if the message could not be serialized
@ -154,7 +154,7 @@ impl Client {
if result.nonce != update_keys.nonce { if result.nonce != update_keys.nonce {
error!("nonce mismatch between request {:x?} and response {:x?}", result.nonce, update_keys.nonce); error!("nonce mismatch between request {:x?} and response {:x?}", result.nonce, update_keys.nonce);
return Err(format!("nonce mismatch between request and response").into()) return Err("nonce mismatch between request and response".into())
} }
let trusted_keys = ed25519_public_keys_from_pem(&result.trusted_keys)?; let trusted_keys = ed25519_public_keys_from_pem(&result.trusted_keys)?;
@ -169,12 +169,12 @@ impl Client {
Ok((result.config, dh_privkey_pem, new_creds)) Ok((result.config, dh_privkey_pem, new_creds))
} }
/// Wraps and signs the given req_type and value, and then makes the API call. /// Wraps and signs the given `req_type` and value, and then makes the API call.
/// On success, returns the response body. /// On success, returns the response body.
/// # Errors /// # Errors
/// This function will return an error if: /// This function will return an error if:
/// - serialization in any step fails /// - serialization in any step fails
/// - if the server_url is invalid /// - if the `server_url` is invalid
/// - if the request could not be sent /// - if the request could not be sent
pub fn post_dnclient(&self, req_type: &str, value: &[u8], host_id: &str, counter: u32, ed_privkey: &SigningKey) -> Result<Vec<u8>, Box<dyn Error>> { pub fn post_dnclient(&self, req_type: &str, value: &[u8], host_id: &str, counter: u32, ed_privkey: &SigningKey) -> Result<Vec<u8>, Box<dyn Error>> {
let encoded_msg = serde_json::to_string(&RequestWrapper { let encoded_msg = serde_json::to_string(&RequestWrapper {

View File

@ -23,7 +23,7 @@ pub fn new_nebula_keypair() -> (Vec<u8>, Vec<u8>) {
/// Generate a new 32-byte X25519 keypair /// Generate a new 32-byte X25519 keypair
pub fn new_x25519_keypair() -> ([u8; 32], [u8; 32]) { pub fn new_x25519_keypair() -> ([u8; 32], [u8; 32]) {
let priv_key = StaticSecret::new(&mut OsRng); let priv_key = StaticSecret::new(OsRng);
let pub_key = PublicKey::from(&priv_key); let pub_key = PublicKey::from(&priv_key);
(pub_key.to_bytes(), priv_key.to_bytes()) (pub_key.to_bytes(), priv_key.to_bytes())
} }

View File

@ -6,9 +6,9 @@ use serde::{Serialize, Deserialize};
/// The version 1 `DNClient` API endpoint /// The version 1 `DNClient` API endpoint
pub const ENDPOINT_V1: &str = "/v1/dnclient"; pub const ENDPOINT_V1: &str = "/v1/dnclient";
/// The CheckForUpdate message type /// The `CheckForUpdate` message type
pub const CHECK_FOR_UPDATE: &str = "CheckForUpdate"; pub const CHECK_FOR_UPDATE: &str = "CheckForUpdate";
/// The DoUpdate message type /// The `DoUpdate` message type
pub const DO_UPDATE: &str = "DoUpdate"; pub const DO_UPDATE: &str = "DoUpdate";
base64_serde_type!(Base64Standard, base64::engine::general_purpose::STANDARD); base64_serde_type!(Base64Standard, base64::engine::general_purpose::STANDARD);