Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump base64 from 0.13.1 to 0.21.0 #1081

Merged
merged 3 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ log4rs = { version = "1.2", optional = true }
serde = { version = "1.0", features = ["derive"] }
json5 = "0.4"
thiserror = "1.0"
base64 = "0.13"
base64 = "0.21"

clap = { version = "4.0", features = ["wrap_help", "suggestions"] }
cfg-if = "1"
Expand Down
2 changes: 1 addition & 1 deletion crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ smoltcp = { version = "0.8", optional = true, default-features = false, features

serde = { version = "1.0", features = ["derive"] }
json5 = "0.4"
base64 = "0.13"
base64 = "0.21"

shadowsocks = { version = "1.15.0", path = "../shadowsocks", default-features = false }

Expand Down
14 changes: 11 additions & 3 deletions crates/shadowsocks-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//!
//! These defined server will be used with a load balancing algorithm.

use base64::Engine as _;
use std::{
borrow::Cow,
convert::{From, Infallible},
Expand All @@ -66,7 +67,14 @@ use serde::{Deserialize, Serialize};
use shadowsocks::relay::socks5::Address;
use shadowsocks::{
config::{
ManagerAddr, Mode, ReplayAttackPolicy, ServerAddr, ServerConfig, ServerUser, ServerUserManager, ServerWeight,
ManagerAddr,
Mode,
ReplayAttackPolicy,
ServerAddr,
ServerConfig,
ServerUser,
ServerUserManager,
ServerWeight,
},
crypto::CipherKind,
plugin::PluginConfig,
Expand Down Expand Up @@ -1709,7 +1717,7 @@ impl Config {
let mut user_manager = ServerUserManager::new();

for user in users {
let key = match base64::decode_config(&user.password, base64::STANDARD) {
let key = match base64::engine::general_purpose::STANDARD.decode(&user.password) {
Ok(k) => k,
Err(..) => {
let err = Error::new(
Expand Down Expand Up @@ -2480,7 +2488,7 @@ impl fmt::Display for Config {
for u in m.users_iter() {
vu.push(SSServerUserConfig {
name: u.name().to_owned(),
password: base64::encode(u.key()),
password: base64::engine::general_purpose::STANDARD.encode(u.key()),
});
}
vu
Expand Down
7 changes: 5 additions & 2 deletions crates/shadowsocks-service/src/manager/server.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Shadowsocks Manager server

use base64::Engine as _;

#[cfg(unix)]
use std::path::PathBuf;
use std::{collections::HashMap, io, net::SocketAddr, sync::Arc, time::Duration};

use base64::engine::general_purpose::STANDARD;
use log::{error, info, trace};
use shadowsocks::{
config::{Mode, ServerConfig, ServerType, ServerUser, ServerUserManager},
Expand Down Expand Up @@ -469,7 +472,7 @@ impl Manager {
let mut user_manager = ServerUserManager::new();

for user in users.iter() {
let key = match base64::decode_config(&user.password, base64::STANDARD) {
let key = match STANDARD.decode(&user.password) {
Ok(key) => key,
Err(..) => {
error!(
Expand Down Expand Up @@ -522,7 +525,7 @@ impl Manager {
for user in user_manager.users_iter() {
vu.push(ServerUserConfig {
name: user.name().to_owned(),
password: base64::encode(user.key()),
password: STANDARD.encode(user.key()),
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/shadowsocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ libc = "0.2.94"
bytes = "1.2"
cfg-if = "1"
byte_string = "1.0"
base64 = "0.13"
base64 = "0.21"
url = "2.2"
once_cell = "1.17"
spin = { version = "0.9", features = ["std"] }
Expand Down
21 changes: 12 additions & 9 deletions crates/shadowsocks/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use std::{
time::Duration,
};

use base64::{decode_config, encode_config, URL_SAFE, URL_SAFE_NO_PAD};
use base64::{
engine::general_purpose::{STANDARD, URL_SAFE, URL_SAFE_NO_PAD},
Engine as _,
};
use byte_string::ByteStr;
use bytes::Bytes;
use cfg_if::cfg_if;
Expand Down Expand Up @@ -161,7 +164,7 @@ impl Debug for ServerUser {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ServerUser")
.field("name", &self.name)
.field("key", &base64::encode(&self.key))
.field("key", &STANDARD.encode(&self.key))
.field("identity_hash", &ByteStr::new(&self.identity_hash))
.finish()
}
Expand Down Expand Up @@ -302,7 +305,7 @@ pub struct ServerConfig {
fn make_derived_key(method: CipherKind, password: &str, enc_key: &mut [u8]) {
if method.is_aead_2022() {
// AEAD 2022 password is a base64 form of enc_key
match base64::decode_config(password, base64::STANDARD) {
match STANDARD.decode(password) {
Ok(v) => {
if v.len() != enc_key.len() {
panic!(
Expand Down Expand Up @@ -363,7 +366,7 @@ where
make_derived_key(method, upsk, &mut enc_key);

for ipsk in split_iter {
match base64::decode_config(ipsk, base64::STANDARD) {
match STANDARD.decode(ipsk) {
Ok(v) => {
identity_keys.push(Bytes::from(v));
}
Expand Down Expand Up @@ -564,7 +567,7 @@ impl ServerConfig {
/// ```
pub fn to_qrcode_url(&self) -> String {
let param = format!("{}:{}@{}", self.method(), self.password(), self.addr());
format!("ss://{}", encode_config(param, URL_SAFE_NO_PAD))
format!("ss://{}", URL_SAFE_NO_PAD.encode(param))
}

/// Get [SIP002](https://github.com/shadowsocks/shadowsocks-org/issues/27) URL
Expand All @@ -573,13 +576,13 @@ impl ServerConfig {
if #[cfg(feature = "aead-cipher-2022")] {
let user_info = if !self.method().is_aead_2022() {
let user_info = format!("{}:{}", self.method(), self.password());
encode_config(&user_info, URL_SAFE_NO_PAD)
URL_SAFE_NO_PAD.encode(&user_info)
} else {
format!("{}:{}", self.method(), percent_encoding::utf8_percent_encode(self.password(), percent_encoding::NON_ALPHANUMERIC))
};
} else {
let mut user_info = format!("{}:{}", self.method(), self.password());
user_info = encode_config(&user_info, URL_SAFE_NO_PAD)
user_info = URL_SAFE_NO_PAD.encode(&user_info)
}
}

Expand Down Expand Up @@ -629,7 +632,7 @@ impl ServerConfig {
None => return Err(UrlParseError::MissingHost),
};

let mut decoded_body = match decode_config(encoded, URL_SAFE_NO_PAD) {
let mut decoded_body = match URL_SAFE_NO_PAD.decode(encoded) {
Ok(b) => match String::from_utf8(b) {
Ok(b) => b,
Err(..) => return Err(UrlParseError::InvalidServerAddr),
Expand Down Expand Up @@ -690,7 +693,7 @@ impl ServerConfig {
URL_SAFE_NO_PAD
};

let account = match decode_config(decoded_user_info, base64_config) {
let account = match base64_config.decode(decoded_user_info) {
Ok(account) => match String::from_utf8(account) {
Ok(ac) => ac,
Err(..) => return Err(UrlParseError::InvalidAuthInfo),
Expand Down
3 changes: 2 additions & 1 deletion src/service/genkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::process::ExitCode;

use base64::Engine as _;
use clap::{builder::PossibleValuesParser, Arg, ArgAction, ArgMatches, Command};
use rand::RngCore;

Expand Down Expand Up @@ -36,7 +37,7 @@ pub fn main(matches: &ArgMatches) -> ExitCode {
let mut rng = rand::thread_rng();
rng.fill_bytes(&mut key);

let encoded_key = base64::encode(&key);
let encoded_key = base64::engine::general_purpose::STANDARD.encode(&key);
println!("{encoded_key}");
}

Expand Down