diff --git a/shinkai-bin/shinkai-node/src/runner.rs b/shinkai-bin/shinkai-node/src/runner.rs index e7c1dc12a..cac191d4a 100644 --- a/shinkai-bin/shinkai-node/src/runner.rs +++ b/shinkai-bin/shinkai-node/src/runner.rs @@ -145,13 +145,25 @@ pub async fn initialize_node() -> Result< let encryption_secret_key_string = encryption_secret_key_to_string(node_keys.encryption_secret_key.clone()); // Add the HTTPS certificates to the secret content + let private_cert = node_keys + .private_https_certificate + .clone() + .unwrap_or_default() + .replace('\n', "\\n"); + + let public_cert = node_keys + .public_https_certificate + .clone() + .unwrap_or_default() + .replace('\n', "\\n"); + let secret_content = format!( "GLOBAL_IDENTITY_NAME={}\nIDENTITY_SECRET_KEY={}\nENCRYPTION_SECRET_KEY={}\nPRIVATE_HTTPS_CERTIFICATE={}\nPUBLIC_HTTPS_CERTIFICATE={}", global_identity_name, identity_secret_key_string, encryption_secret_key_string, - node_keys.private_https_certificate.clone().unwrap_or_default(), - node_keys.public_https_certificate.clone().unwrap_or_default() + private_cert, + public_cert ); if !node_env.no_secrets_file { @@ -337,26 +349,13 @@ fn parse_secrets_file(secrets_file_path: &str) -> HashMap { let contents = fs::read_to_string(secrets_file_path).unwrap_or_default(); let mut map = HashMap::new(); - let mut current_key = String::new(); - let mut current_value = String::new(); for line in contents.lines() { if let Some((key, value)) = line.split_once('=') { - if !current_key.is_empty() { - map.insert(current_key.clone(), current_value.trim_end().to_string()); - } - current_key = key.to_string(); - current_value = value.to_string(); - } else { - current_value.push_str("\n"); - current_value.push_str(line); + map.insert(key.to_string(), value.to_string()); } } - if !current_key.is_empty() { - map.insert(current_key, current_value.trim_end().to_string()); - } - map } diff --git a/shinkai-bin/shinkai-node/src/utils/keys.rs b/shinkai-bin/shinkai-node/src/utils/keys.rs index 1cced8523..d3a445d24 100644 --- a/shinkai-bin/shinkai-node/src/utils/keys.rs +++ b/shinkai-bin/shinkai-node/src/utils/keys.rs @@ -28,28 +28,14 @@ pub fn generate_or_load_keys(secrets_file_path: &str) -> NodeKeys { // First check for .secret file if let Ok(contents) = fs::read_to_string(secrets_file_path) { // Parse the contents of the file - let mut lines = contents.lines(); let mut map = HashMap::new(); - let mut current_key = None; - let mut current_value = String::new(); - while let Some(line) = lines.next() { - if line.contains('=') && current_key.is_none() { - if let Some(key) = current_key.take() { - map.insert(key, current_value.trim().to_string()); - } - let mut parts = line.splitn(2, '='); - current_key = parts.next().map(|s| s.to_string()); - current_value = parts.next().unwrap_or("").to_string(); - } else if let Some(_) = current_key { - current_value.push('\n'); - current_value.push_str(line); + for line in contents.lines() { + if let Some((key, value)) = line.split_once('=') { + map.insert(key.trim().to_string(), value.trim().to_string()); } } - if let Some(key) = current_key { - map.insert(key, current_value.trim().to_string()); - } // Use the values from the file if they exist if let (Some(identity_secret_key_string), Some(encryption_secret_key_string)) = @@ -64,8 +50,18 @@ pub fn generate_or_load_keys(secrets_file_path: &str) -> NodeKeys { let encryption_public_key = x25519_dalek::PublicKey::from(&encryption_secret_key); // Read the HTTPS certificates if they exist - let private_https_certificate = map.get("PRIVATE_HTTPS_CERTIFICATE").cloned(); - let public_https_certificate = map.get("PUBLIC_HTTPS_CERTIFICATE").cloned(); + let private_https_certificate = match map.get("PRIVATE_HTTPS_CERTIFICATE").cloned() { + Some(certificate) if certificate.trim().len() > 0 => { + Some(certificate.replace("\\n", "\n")) + }, + _ => None, + }; + let public_https_certificate = match map.get("PUBLIC_HTTPS_CERTIFICATE").cloned() { + Some(certificate) if certificate.trim().len() > 0 => { + Some(certificate.replace("\\n", "\n")) + }, + _ => None, + }; return NodeKeys { identity_secret_key,