From dc1486a77e7832a026b16341b3cfe304a680bd74 Mon Sep 17 00:00:00 2001 From: zaeyee Date: Mon, 2 Sep 2024 11:44:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E8=AF=81=E4=B9=A6=E6=97=A0=E5=BA=8F=E5=88=97=E5=8F=B7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/Cargo.lock | 85 ++++++++++++++++++++++--------------------- src-tauri/Cargo.toml | 5 ++- src-tauri/src/main.rs | 25 ++++++++++--- src/App.vue | 4 +- 4 files changed, 67 insertions(+), 52 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0c2152e..eacceaf 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -491,7 +491,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -501,7 +501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" dependencies = [ "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -525,7 +525,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -536,7 +536,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -559,7 +559,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -801,7 +801,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1290,9 +1290,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -1728,7 +1728,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1913,7 +1913,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1943,6 +1943,20 @@ dependencies = [ "siphasher", ] +[[package]] +name = "phiz-pay-tool" +version = "0.1.0" +dependencies = [ + "chrono", + "openssl", + "rand 0.8.5", + "serde", + "serde_json", + "tauri", + "tauri-build", + "thiserror", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -1968,7 +1982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ "base64 0.22.1", - "indexmap 2.4.0", + "indexmap 2.5.0", "quick-xml", "serde", "time", @@ -2357,7 +2371,7 @@ checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2366,7 +2380,7 @@ version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ - "indexmap 2.4.0", + "indexmap 2.5.0", "itoa 1.0.11", "memchr", "ryu", @@ -2381,7 +2395,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2403,7 +2417,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.4.0", + "indexmap 2.5.0", "serde", "serde_derive", "serde_json", @@ -2420,7 +2434,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2442,7 +2456,7 @@ checksum = "772ee033c0916d670af7860b6e1ef7d658a4629a6d0b4c8c3e67f09b3765b75d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2596,9 +2610,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.76" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -2686,7 +2700,7 @@ checksum = "f4e16beb8b2ac17db28eab8bca40e62dbfbb34c0fcdc6d9826b11b7b5d047dfd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2756,19 +2770,6 @@ dependencies = [ "windows 0.39.0", ] -[[package]] -name = "tauri-app" -version = "0.1.0" -dependencies = [ - "chrono", - "openssl", - "serde", - "serde_json", - "tauri", - "tauri-build", - "thiserror", -] - [[package]] name = "tauri-build" version = "1.5.4" @@ -2956,7 +2957,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3017,9 +3018,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.39.3" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", @@ -3074,7 +3075,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.4.0", + "indexmap 2.5.0", "serde", "serde_spanned", "toml_datetime", @@ -3087,7 +3088,7 @@ version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ - "indexmap 2.4.0", + "indexmap 2.5.0", "serde", "serde_spanned", "toml_datetime", @@ -3113,7 +3114,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3309,7 +3310,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -3343,7 +3344,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3947,5 +3948,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 864a7ae..101fb9a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "tauri-app" +name = "phiz-pay-tool" version = "0.1.0" description = "A Tauri App" authors = ["you"] @@ -11,12 +11,13 @@ edition = "2021" tauri-build = { version = "1", features = [] } [dependencies] -tauri = { version = "1", features = [ "path-all", "dialog-all", "shell-open"] } +tauri = { version = "1", features = ["path-all", "dialog-all", "shell-open"] } serde = { version = "1", features = ["derive"] } serde_json = "1" openssl = "0.10.66" thiserror = "1.0.63" chrono = "0.4.38" +rand = "0.8.5" [features] # This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!! diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 83409b5..aeaa841 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,14 +2,16 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use openssl::{ - asn1::Asn1Time, + asn1::{Asn1Integer, Asn1Time}, + bn::BigNum, + hash::MessageDigest, pkey::PKey, rsa::Rsa, x509::{X509Builder, X509NameBuilder}, }; +use rand::{thread_rng, Rng}; use std::fs::File; use std::io::Write; -use std::path::PathBuf; // create the error type that represents all errors possible in our program #[derive(Debug, thiserror::Error)] @@ -46,18 +48,29 @@ fn gen_rsa_pair(merchant_id: &str, email: &str, save_path: &str) -> Result<(), E let x509_name = x509_name_builder.build(); let mut x509_builder: X509Builder = X509Builder::new()?; + + let mut rng = thread_rng(); + let mut bytes = [0u8; 20]; + rng.fill(&mut bytes); + let bn: BigNum = BigNum::from_slice(&bytes)?; + let serial_number = Asn1Integer::from_bn(&bn)?; + x509_builder.set_serial_number(&serial_number)?; + + x509_builder.set_version(2)?; x509_builder.set_subject_name(&x509_name)?; x509_builder.set_issuer_name(&x509_name)?; x509_builder.set_pubkey(&private_key)?; - x509_builder.set_not_before(&Asn1Time::days_from_now(0).unwrap())?; - x509_builder.set_not_after(&Asn1Time::days_from_now(1095).unwrap())?; - x509_builder.sign(&private_key, openssl::hash::MessageDigest::sha256())?; + let not_before = Asn1Time::days_from_now(0)?; + let not_after = Asn1Time::days_from_now(1095)?; + x509_builder.set_not_before(¬_before)?; + x509_builder.set_not_after(¬_after)?; + x509_builder.sign(&private_key, MessageDigest::sha256())?; let x509 = x509_builder.build(); // 将私钥转换为 PEM 格式 let private_key_pem = private_key.private_key_to_pem_pkcs8()?; // 保存私钥到文件 - let private_key_path = PathBuf::from(format!("{}/{}_private_key.pem", save_path, merchant_id)); + let private_key_path = format!("{}/{}_private_key.pem", save_path, merchant_id); let mut private_key_file = File::create(&private_key_path)?; private_key_file.write_all(&private_key_pem)?; diff --git a/src/App.vue b/src/App.vue index 3cbec9b..ddd68ab 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,8 +4,8 @@ import { invoke } from '@tauri-apps/api/tauri' import { message, open } from '@tauri-apps/api/dialog' import { downloadDir } from '@tauri-apps/api/path' -const merchantId = ref('P80029767866') -const email = ref('zaeyee@163.com') +const merchantId = ref('') +const email = ref('') async function genPrivateKey() { try {