From b87194acf7c41ddb23fbab90d3fd6de2f485d411 Mon Sep 17 00:00:00 2001 From: "benjamin.747" Date: Wed, 5 Feb 2025 14:44:50 +0800 Subject: [PATCH] upgrade russh version and remove russh-keys --- Cargo.toml | 28 +++++++++++++-------------- aria/lib/routes-config.ts | 2 +- ceres/src/lfs/handler.rs | 4 ++-- common/src/utils.rs | 17 +++++++++++++--- mega/tests/lfs_test.rs | 2 +- mono/Cargo.toml | 2 -- mono/src/api/user/user_router.rs | 2 +- mono/src/git_protocol/ssh.rs | 33 ++++++++++++++++++-------------- mono/src/server/ssh_server.rs | 11 ++++++----- 9 files changed, 58 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0dd29d6e..b6d9b16a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,53 +36,53 @@ libra = { path = "libra" } anyhow = "1.0.93" serde = "1.0.215" -serde_json = "1.0.132" +serde_json = "1.0.138" tracing = "0.1.40" tracing-subscriber = "0.3.19" tracing-appender = "0.2" -thiserror = "2.0.9" -rand = "0.8.5" +thiserror = "2.0.11" +rand = "0.9.0" smallvec = "1.13.2" tokio = "1.42" tokio-stream = "0.1.17" tokio-test = "0.4.4" -clap = "4.5.23" -async-trait = "0.1.83" +clap = "4.5.28" +async-trait = "0.1.86" async-stream = "0.3.6" -bytes = "1.8.0" +bytes = "1.10.0" memchr = "2.7.4" chrono = "0.4.39" sha1 = "0.10.6" futures = "0.3.30" futures-util = "0.3.30" go-defer = "0.1.0" -russh = "0.49.0" -russh-keys = "0.49.1" +russh = "0.50.0" +# russh-keys = "0.49.2" axum = "0.8.1" axum-extra = "0.10.0" axum-server = "0.7.1" tower-http = "0.6.1" tower = "0.5.2" hex = "0.4.3" -sea-orm = "1.1.3" +sea-orm = "1.1.4" flate2 = "1.0.35" -bstr = "1.11.0" +bstr = "1.11.3" colored = "3.0.0" idgenerator = "2.0.0" num_cpus = "1.16.0" -config = "0.15.4" +config = "0.15.7" shadow-rs = "0.36.0" reqwest = "0.12.12" lazy_static = "1.5.0" -uuid = "1.11.0" +uuid = "1.13.1" regex = "1.11.1" ed25519-dalek = "2.1.1" ctrlc = "3.4.4" git2 = "0.20.0" -tempfile = "3.14.0" +tempfile = "3.16.0" home = "0.5.9" ring = "0.17.8" -cedar-policy = "4.2.2" +cedar-policy = "4.3.1" secp256k1 = "0.30.0" oauth2 = "4.4.2" base64 = "0.22.1" diff --git a/aria/lib/routes-config.ts b/aria/lib/routes-config.ts index 27b12724..8b05a46c 100644 --- a/aria/lib/routes-config.ts +++ b/aria/lib/routes-config.ts @@ -26,7 +26,7 @@ export const ROUTES: EachRoute[] = [ { title: "Quick Start", href: "/quick-start" }, { title: "Config File", href: "/config-file" }, { title: "Test", href: "/test" }, - { title: "Code Guide", href: "/code-guideline" }, + { title: "Code GuideLine", href: "/code-guideline" }, { title: "Database", href: "/database" }, ], }, diff --git a/ceres/src/lfs/handler.rs b/ceres/src/lfs/handler.rs index c7247407..91c44d73 100644 --- a/ceres/src/lfs/handler.rs +++ b/ceres/src/lfs/handler.rs @@ -112,9 +112,9 @@ pub async fn lfs_create_lock(storage: LfsDbStorage, req: LockRequest) -> Result< let lock = Lock { id: { let mut random_num = String::new(); - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); for _ in 0..8 { - random_num += &(rng.gen_range(0..9)).to_string(); + random_num += &(rng.random_range(0..9)).to_string(); } random_num }, diff --git a/common/src/utils.rs b/common/src/utils.rs index cc82499d..5efaf7a1 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -1,5 +1,5 @@ use idgenerator::IdInstance; -use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use rand::prelude::*; use regex::Regex; use serde_json::{json, Value}; @@ -14,8 +14,9 @@ pub fn generate_id() -> i64 { } pub fn generate_link() -> String { - let str: String = thread_rng() - .sample_iter(&Alphanumeric) + let rng = rand::rng(); + let str: String = rng + .sample_iter(rand::distr::Alphanumeric) .take(8) .map(char::from) .collect(); @@ -160,4 +161,14 @@ mod test { let msg = "()(common): add new feature"; // unssupported characters in type assert!(!check_conventional_commits_message(msg)); } + + #[test] + fn test_link_generate() { + let link = generate_link(); + println!("MR Link: '{:?}'", link); + assert!( + link.chars().count() == 8 + && link.chars().all(|c| !c.is_alphabetic() || c.is_uppercase()) + ) + } } diff --git a/mega/tests/lfs_test.rs b/mega/tests/lfs_test.rs index 4a238912..e7da558f 100644 --- a/mega/tests/lfs_test.rs +++ b/mega/tests/lfs_test.rs @@ -116,7 +116,7 @@ fn run_mega_server(data_dir: &Path) -> Child { fn generate_large_file(path: &str, size_mb: usize) -> io::Result<()> { let mut file = fs::File::create(path)?; - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); const BUFFER_SIZE: usize = 1024 * 1024; // 1MB buffer let mut buffer = [0u8; BUFFER_SIZE]; diff --git a/mono/Cargo.toml b/mono/Cargo.toml index de46e086..4b8c57ee 100644 --- a/mono/Cargo.toml +++ b/mono/Cargo.toml @@ -29,13 +29,11 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } tracing-appender = { workspace = true } russh = { workspace = true } -russh-keys = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } chrono = { workspace = true } futures = { workspace = true } bytes = { workspace = true } -async-trait = { workspace = true } clap = { workspace = true, features = ["derive"] } tower-http = { workspace = true, features = [ "cors", diff --git a/mono/src/api/user/user_router.rs b/mono/src/api/user/user_router.rs index b46b6e1c..957c5a61 100644 --- a/mono/src/api/user/user_router.rs +++ b/mono/src/api/user/user_router.rs @@ -5,7 +5,7 @@ use axum::{ routing::{get, post}, Json, Router, }; -use russh_keys::{parse_public_key_base64, HashAlg}; +use russh::keys::{parse_public_key_base64, HashAlg}; use common::model::CommonResult; diff --git a/mono/src/git_protocol/ssh.rs b/mono/src/git_protocol/ssh.rs index 68c786fc..93173c3f 100644 --- a/mono/src/git_protocol/ssh.rs +++ b/mono/src/git_protocol/ssh.rs @@ -3,13 +3,12 @@ use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; -use async_trait::async_trait; use bytes::{Bytes, BytesMut}; use chrono::{DateTime, Duration, Utc}; use futures::{stream, StreamExt}; +use russh::keys::{HashAlg, PublicKey}; use russh::server::{self, Auth, Msg, Session}; -use russh::{Channel, ChannelId, MethodSet}; -use russh_keys::{self, HashAlg, PublicKey}; +use russh::{Channel, ChannelId}; use tokio::io::AsyncReadExt; use ceres::lfs::lfs_structs::Link; @@ -41,7 +40,6 @@ impl server::Server for SshServer { } } -#[async_trait] impl server::Handler for SshServer { type Error = anyhow::Error; @@ -132,19 +130,20 @@ impl server::Handler for SshServer { ) -> Result { let fingerprint = public_key.fingerprint(HashAlg::Sha256).to_string(); - tracing::info!( - "auth_publickey: {} / {}", - user, - fingerprint - ); - let res = self.context.user_stg().search_ssh_key_finger(&fingerprint).await.unwrap(); + tracing::info!("auth_publickey: {} / {}", user, fingerprint); + let res = self + .context + .user_stg() + .search_ssh_key_finger(&fingerprint) + .await + .unwrap(); if !res.is_empty() { tracing::info!("Client public key verified successfully!"); Ok(Auth::Accept) } else { tracing::warn!("Client public key verification failed!"); Ok(Auth::Reject { - proceed_with_methods: Some(MethodSet::PUBLICKEY), + proceed_with_methods: None, }) } } @@ -205,7 +204,9 @@ impl SshServer { .unwrap(); tracing::info!("buf is {:?}", buf); - session.data(channel, String::from_utf8(buf.to_vec()).unwrap().into()).unwrap(); + session + .data(channel, String::from_utf8(buf.to_vec()).unwrap().into()) + .unwrap(); while let Some(chunk) = send_pack_data.next().await { let mut reader = chunk.as_slice(); @@ -220,7 +221,9 @@ impl SshServer { session.data(channel, bytes_out.to_vec().into()).unwrap(); } } - session.data(channel, smart::PKT_LINE_END_MARKER.to_vec().into()).unwrap(); + session + .data(channel, smart::PKT_LINE_END_MARKER.to_vec().into()) + .unwrap(); } async fn handle_receive_pack(&mut self, channel: ChannelId, session: &mut Session) { @@ -246,6 +249,8 @@ impl SshServer { } tracing::info!("report status: {:?}", report_status); - session.data(channel, report_status.to_vec().into()).unwrap(); + session + .data(channel, report_status.to_vec().into()) + .unwrap(); } } diff --git a/mono/src/server/ssh_server.rs b/mono/src/server/ssh_server.rs index 7fd68313..0643eb3f 100644 --- a/mono/src/server/ssh_server.rs +++ b/mono/src/server/ssh_server.rs @@ -5,10 +5,12 @@ use std::sync::Arc; use bytes::BytesMut; use clap::Args; - use ed25519_dalek::pkcs8::spki::der::pem::LineEnding; -use russh::{server::Server, Preferred}; -use russh_keys::{ssh_key::rand_core::OsRng, PrivateKey}; +use russh::{ + keys::{ssh_key::rand_core::OsRng, Algorithm, PrivateKey}, + server::Server, + Preferred, +}; use common::model::CommonOptions; use jupiter::context::Context; @@ -73,8 +75,7 @@ pub fn load_key() -> PrivateKey { PrivateKey::from_openssh(secret_key).unwrap() } else { // generate a keypair if not exists - let keys = - russh_keys::PrivateKey::random(&mut OsRng, russh_keys::Algorithm::Ed25519).unwrap(); + let keys = PrivateKey::random(&mut OsRng, Algorithm::Ed25519).unwrap(); let secret = serde_json::json!({ "secret_key": *keys.to_openssh(LineEnding::CR).unwrap()