use sha-1/hmac

This commit is contained in:
2020-04-04 23:34:42 +08:00
parent 6e116f7003
commit b1a9e6f8f2
7 changed files with 111 additions and 266 deletions

View File

@@ -1,7 +1,10 @@
use std::{
cmp::{min, max, },
fs,
path::Path,
cmp::{
min,
max,
},
};
use rust_util::{
iff,
@@ -9,9 +12,7 @@ use rust_util::{
new_box_ioerror,
util_msg::*,
};
use chrono::{
Utc,
};
use chrono::Utc;
pub const ETC_OSS_BACKUPD_CONFIG: &str = "/etc/oss-backupd/config.json";
pub const OSS_BACKUPD_CONFIG: &str = "oss-backupd-config.json";
@@ -100,7 +101,10 @@ impl OSSBackupdConfigItem {
pub fn get_safe_backup_count(&self) -> usize {
min(
max(self.backup_count.unwrap_or(10u32) as usize, 1_usize),
max(
self.backup_count.unwrap_or(10u32) as usize,
1_usize
),
1000_usize
)
}

View File

@@ -8,21 +8,22 @@ mod zip_util;
mod opt;
use std::{
fs::{self, File},
time::SystemTime,
path::Path,
fs::{
self,
File,
},
};
use rust_util::{
iff,
XResult,
util_msg::*,
iff,
};
use oss_util::*;
use config_util::*;
use pgp_util::OpenPGPTool;
use opt::{
Options,
};
use opt::Options;
// https://docs.sequoia-pgp.org/sequoia_openpgp/serialize/stream/struct.Encryptor.html
// https://gitlab.com/sequoia-pgp/sequoia/blob/master/openpgp/examples/generate-encrypt-decrypt.rs

View File

@@ -1,7 +1,9 @@
use rust_util::{
XResult,
use rust_util::XResult;
use argparse::{
ArgumentParser,
Store,
StoreTrue,
};
use argparse::{ArgumentParser, StoreTrue, Store};
// lazy_static! {
// pub static ref IS_DEBUG: bool = rust_util::util_env::is_env_on("DEBUG");

View File

@@ -2,17 +2,12 @@ use std::{
fs::File,
time::SystemTime,
};
use crypto::{
mac::{
Mac,
MacResult,
},
hmac::Hmac,
sha1::Sha1,
};
use reqwest::{
Response,
use sha1::Sha1;
use hmac::{
Hmac,
Mac,
};
use reqwest::Response;
use rust_util::*;
pub const DEFAULT_URL_VALID_IN_SECS: u64 = 1000;
@@ -101,7 +96,7 @@ impl OSSClient {
signed_url.push_str("&Signature=");
let to_be_signed = get_to_be_signed(verb, expire_secs, bucket_name, key);
let signature = to_base64(calc_hmac_sha1(self.access_key_secret.as_bytes(), to_be_signed.as_bytes()));
let signature = calc_hmac_sha1(self.access_key_secret.as_bytes(), to_be_signed.as_bytes());
signed_url.push_str(&urlencoding::encode(signature.as_str()));
signed_url
@@ -134,14 +129,14 @@ fn get_to_be_signed(verb: &str, expire_secs: u64, bucket_name: &str, key: &str)
to_be_signed
}
fn to_base64(mac_result: MacResult) -> String {
base64::encode(mac_result.code())
}
fn calc_hmac_sha1(key: &[u8], message: &[u8]) -> MacResult {
let mut hmac = Hmac::new(Sha1::new(), key);
hmac.input(message);
hmac.result()
fn calc_hmac_sha1(key: &[u8], message: &[u8]) -> String {
match Hmac::<Sha1>::new_varkey(key) {
Ok(mut mac) => {
mac.input(message);
base64::encode(&mac.result().code())
},
Err(e) => format!("[ERROR]Hmac error: {}", e),
}
}
fn get_current_secs() -> u64 {

View File

@@ -3,9 +3,7 @@ use std::{
cell::RefCell,
fs::File,
path::Path,
io::{
BufWriter,
},
io::BufWriter,
};
use zip::{
CompressionMethod,