-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fba8ed6
commit 5f284b5
Showing
3 changed files
with
125 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,48 @@ | ||
mod upload; | ||
mod download; | ||
mod renew; | ||
mod upload; | ||
|
||
pub use upload::UploadCertCmd; | ||
use crate::bridge::BridgeLocation; | ||
use crate::read_cert_to_string; | ||
use crate::CertError; | ||
use crate::CreateCertCmd; | ||
use camino::Utf8PathBuf; | ||
use certificate::NewCertificateConfig; | ||
pub use download::DownloadCertCmd; | ||
pub use renew::RenewCertCmd; | ||
use std::fs::OpenOptions; | ||
use std::io::Write; | ||
use tedge_utils::paths::set_permission; | ||
pub use upload::UploadCertCmd; | ||
|
||
/// Create a device private key and CSR | ||
fn create_device_csr( | ||
common_name: String, | ||
key_path: Utf8PathBuf, | ||
csr_path: Utf8PathBuf, | ||
) -> Result<String, CertError> { | ||
let config = NewCertificateConfig::default(); | ||
let create_cmd = CreateCertCmd { | ||
id: common_name, | ||
cert_path: "should-be-unused".into(), | ||
key_path, | ||
csr_path: Some(csr_path.clone()), | ||
bridge_location: BridgeLocation::BuiltIn, | ||
}; | ||
create_cmd.create_certificate_signing_request(&config)?; | ||
read_cert_to_string(&csr_path) | ||
} | ||
|
||
/// Store a device certificate | ||
fn store_device_cert(cert_path: &Utf8PathBuf, cert: String) -> Result<(), CertError> { | ||
let mut file = OpenOptions::new() | ||
.write(true) | ||
.create_new(true) | ||
.open(cert_path)?; | ||
|
||
file.write_all(cert.as_bytes())?; | ||
file.sync_all()?; | ||
|
||
set_permission(&file, 0o444)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters