| 687 | } |
| 688 | |
| 689 | fn write_local_tls_bundle(bundle: &PkiBundle, paths: &LocalPaths) -> Result<()> { |
| 690 | let temp = sibling_temp_dir(&paths.server_dir); |
| 691 | if temp.exists() { |
| 692 | std::fs::remove_dir_all(&temp) |
| 693 | .into_diagnostic() |
| 694 | .wrap_err_with(|| format!("failed to remove stale {}", temp.display()))?; |
| 695 | } |
| 696 | |
| 697 | let temp_server = temp.join("server"); |
| 698 | let temp_client = temp.join("client"); |
| 699 | create_dir_restricted(&temp)?; |
| 700 | create_dir_restricted(&temp_server)?; |
| 701 | create_dir_restricted(&temp_client)?; |
| 702 | |
| 703 | write_pem(&temp.join("ca.crt"), &bundle.ca_cert_pem, false)?; |
| 704 | write_pem(&temp.join("ca.key"), &bundle.ca_key_pem, true)?; |
| 705 | write_pem(&temp_server.join("tls.crt"), &bundle.server_cert_pem, false)?; |
| 706 | write_pem(&temp_server.join("tls.key"), &bundle.server_key_pem, true)?; |
| 707 | write_pem(&temp_client.join("tls.crt"), &bundle.client_cert_pem, false)?; |
| 708 | write_pem(&temp_client.join("tls.key"), &bundle.client_key_pem, true)?; |
| 709 | |
| 710 | create_dir_restricted(&paths.server_dir)?; |
| 711 | create_dir_restricted(&paths.client_dir)?; |
| 712 | let renames: [(PathBuf, &Path); 6] = [ |
| 713 | (temp.join("ca.crt"), paths.ca_crt.as_path()), |
| 714 | (temp.join("ca.key"), paths.ca_key.as_path()), |
| 715 | (temp_server.join("tls.crt"), paths.server_crt.as_path()), |
| 716 | (temp_server.join("tls.key"), paths.server_key.as_path()), |
| 717 | (temp_client.join("tls.crt"), paths.client_crt.as_path()), |
| 718 | (temp_client.join("tls.key"), paths.client_key.as_path()), |
| 719 | ]; |
| 720 | for (from, to) in &renames { |
| 721 | std::fs::rename(from, to) |
| 722 | .into_diagnostic() |
| 723 | .wrap_err_with(|| format!("failed to move {} -> {}", from.display(), to.display()))?; |
| 724 | } |
| 725 | |
| 726 | let _ = std::fs::remove_dir_all(&temp); |
| 727 | Ok(()) |
| 728 | } |
| 729 | |
| 730 | fn write_local_jwt_bundle(bundle: &PkiBundle, paths: &LocalPaths) -> Result<()> { |
| 731 | let temp = sibling_temp_dir(&paths.jwt_dir); |