Skip to content

Commit

Permalink
Merge pull request #825 from benjamin-747/main
Browse files Browse the repository at this point in the history
upgrade russh version and remove russh-keys
  • Loading branch information
genedna authored Feb 5, 2025
2 parents 4b2c51b + b87194a commit dec8d2f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 43 deletions.
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion aria/lib/routes-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
],
},
Expand Down
4 changes: 2 additions & 2 deletions ceres/src/lfs/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
17 changes: 14 additions & 3 deletions common/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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();
Expand Down Expand Up @@ -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())
)
}
}
2 changes: 1 addition & 1 deletion mega/tests/lfs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 0 additions & 2 deletions mono/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion mono/src/api/user/user_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 19 additions & 14 deletions mono/src/git_protocol/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +40,6 @@ impl server::Server for SshServer {
}
}

#[async_trait]
impl server::Handler for SshServer {
type Error = anyhow::Error;

Expand Down Expand Up @@ -132,19 +130,20 @@ impl server::Handler for SshServer {
) -> Result<Auth, Self::Error> {
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,
})
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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();
}
}
11 changes: 6 additions & 5 deletions mono/src/server/ssh_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

1 comment on commit dec8d2f

@vercel
Copy link

@vercel vercel bot commented on dec8d2f Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mega – ./

gitmega.dev
mega-gitmono.vercel.app
www.gitmega.dev
mega-git-main-gitmono.vercel.app

Please sign in to comment.