mirror of
				https://github.com/dani-garcia/vaultwarden.git
				synced 2025-10-31 18:28:20 +02:00 
			
		
		
		
	Improve JWT key initialization and avoid saving public key (#4085)
This commit is contained in:
		
							
								
								
									
										27
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -71,7 +71,7 @@ async fn main() -> Result<(), Error> { | ||||
|     let extra_debug = matches!(level, LF::Trace | LF::Debug); | ||||
|  | ||||
|     check_data_folder().await; | ||||
|     check_rsa_keys().unwrap_or_else(|_| { | ||||
|     auth::initialize_keys().unwrap_or_else(|_| { | ||||
|         error!("Error creating keys, exiting..."); | ||||
|         exit(1); | ||||
|     }); | ||||
| @@ -444,31 +444,6 @@ async fn container_data_folder_is_persistent(data_folder: &str) -> bool { | ||||
|     true | ||||
| } | ||||
|  | ||||
| fn check_rsa_keys() -> Result<(), crate::error::Error> { | ||||
|     // If the RSA keys don't exist, try to create them | ||||
|     let priv_path = CONFIG.private_rsa_key(); | ||||
|     let pub_path = CONFIG.public_rsa_key(); | ||||
|  | ||||
|     if !util::file_exists(&priv_path) { | ||||
|         let rsa_key = openssl::rsa::Rsa::generate(2048)?; | ||||
|  | ||||
|         let priv_key = rsa_key.private_key_to_pem()?; | ||||
|         crate::util::write_file(&priv_path, &priv_key)?; | ||||
|         info!("Private key created correctly."); | ||||
|     } | ||||
|  | ||||
|     if !util::file_exists(&pub_path) { | ||||
|         let rsa_key = openssl::rsa::Rsa::private_key_from_pem(&std::fs::read(&priv_path)?)?; | ||||
|  | ||||
|         let pub_key = rsa_key.public_key_to_pem()?; | ||||
|         crate::util::write_file(&pub_path, &pub_key)?; | ||||
|         info!("Public key created correctly."); | ||||
|     } | ||||
|  | ||||
|     auth::load_keys(); | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
| fn check_web_vault() { | ||||
|     if !CONFIG.web_vault_enabled() { | ||||
|         return; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user