BlackDex
9 months ago
No known key found for this signature in database
GPG Key ID: 58C80A2AA6C765E1
1 changed files with
4 additions and
4 deletions
-
src/auth.rs
|
|
@ -36,14 +36,14 @@ static PRIVATE_RSA_KEY: OnceCell<EncodingKey> = OnceCell::new(); |
|
|
|
static PUBLIC_RSA_KEY: OnceCell<DecodingKey> = OnceCell::new(); |
|
|
|
|
|
|
|
pub fn initialize_keys() -> Result<(), crate::error::Error> { |
|
|
|
fn read_key(creat_if_missing: bool) -> Result<(Rsa<openssl::pkey::Private>, Vec<u8>), crate::error::Error> { |
|
|
|
fn read_key(create_if_missing: bool) -> Result<(Rsa<openssl::pkey::Private>, Vec<u8>), crate::error::Error> { |
|
|
|
let mut priv_key_buffer = Vec::with_capacity(2048); |
|
|
|
|
|
|
|
let mut priv_key_file = File::options() |
|
|
|
.create(creat_if_missing) |
|
|
|
.create(create_if_missing) |
|
|
|
.truncate(false) |
|
|
|
.read(true) |
|
|
|
.write(creat_if_missing) |
|
|
|
.write(create_if_missing) |
|
|
|
.open(CONFIG.private_rsa_key())?; |
|
|
|
|
|
|
|
#[allow(clippy::verbose_file_reads)] |
|
|
@ -51,7 +51,7 @@ pub fn initialize_keys() -> Result<(), crate::error::Error> { |
|
|
|
|
|
|
|
let rsa_key = if bytes_read > 0 { |
|
|
|
Rsa::private_key_from_pem(&priv_key_buffer[..bytes_read])? |
|
|
|
} else if creat_if_missing { |
|
|
|
} else if create_if_missing { |
|
|
|
// Only create the key if the file doesn't exist or is empty
|
|
|
|
let rsa_key = openssl::rsa::Rsa::generate(2048)?; |
|
|
|
priv_key_buffer = rsa_key.private_key_to_pem()?; |
|
|
|