upgrade gpauth

This commit is contained in:
Kevin Yue
2024-12-13 10:58:39 +00:00
parent 32cb582e78
commit b5064ef179
62 changed files with 4334 additions and 6499 deletions

View File

@@ -1,5 +1,6 @@
[package]
name = "gpclient"
rust-version.workspace = true
authors.workspace = true
version.workspace = true
edition.workspace = true

View File

@@ -1,7 +1,10 @@
use std::{env::temp_dir, fs::File};
use clap::{Parser, Subcommand};
use gpapi::utils::openssl;
use gpapi::{
clap::{handle_error, Args},
utils::openssl,
};
use log::{info, LevelFilter};
use tempfile::NamedTempFile;
@@ -50,12 +53,25 @@ struct Cli {
#[command(subcommand)]
command: CliCommand,
#[arg(long, help = "Uses extended compatibility mode for OpenSSL operations to support a broader range of systems and formats.")]
#[arg(
long,
help = "Uses extended compatibility mode for OpenSSL operations to support a broader range of systems and formats."
)]
fix_openssl: bool,
#[arg(long, help = "Ignore the TLS errors")]
ignore_tls_errors: bool,
}
impl Args for Cli {
fn fix_openssl(&self) -> bool {
self.fix_openssl
}
fn ignore_tls_errors(&self) -> bool {
self.ignore_tls_errors
}
}
impl Cli {
fn fix_openssl(&self) -> anyhow::Result<Option<NamedTempFile>> {
if self.fix_openssl {
@@ -113,24 +129,7 @@ pub(crate) async fn run() {
info!("gpclient started: {}", VERSION);
if let Err(err) = cli.run().await {
eprintln!("\nError: {}", err);
let err = err.to_string();
if err.contains("unsafe legacy renegotiation") && !cli.fix_openssl {
eprintln!("\nRe-run it with the `--fix-openssl` option to work around this issue, e.g.:\n");
// Print the command
let args = std::env::args().collect::<Vec<_>>();
eprintln!("{} --fix-openssl {}\n", args[0], args[1..].join(" "));
}
if err.contains("certificate verify failed") && !cli.ignore_tls_errors {
eprintln!("\nRe-run it with the `--ignore-tls-errors` option to ignore the certificate error, e.g.:\n");
// Print the command
let args = std::env::args().collect::<Vec<_>>();
eprintln!("{} --ignore-tls-errors {}\n", args[0], args[1..].join(" "));
}
handle_error(err, &cli);
std::process::exit(1);
}
}

View File

@@ -5,6 +5,7 @@ use directories::ProjectDirs;
use gpapi::{
process::service_launcher::ServiceLauncher,
utils::{endpoint::http_endpoint, env_utils, shutdown_signal},
GP_CALLBACK_PORT_FILENAME,
};
use log::info;
use tokio::io::AsyncWriteExt;
@@ -80,12 +81,7 @@ impl<'a> LaunchGuiHandler<'a> {
}
async fn feed_auth_data(auth_data: &str) -> anyhow::Result<()> {
let (res_gui, res_cli) = tokio::join!(feed_auth_data_gui(auth_data), feed_auth_data_cli(auth_data));
if let Err(err) = res_gui {
info!("Failed to feed auth data to the GUI: {}", err);
}
if let Err(err) = res_cli {
if let Err(err) = feed_auth_data_cli(auth_data).await {
info!("Failed to feed auth data to the CLI: {}", err);
}
@@ -98,24 +94,10 @@ async fn feed_auth_data(auth_data: &str) -> anyhow::Result<()> {
Ok(())
}
async fn feed_auth_data_gui(auth_data: &str) -> anyhow::Result<()> {
info!("Feeding auth data to the GUI");
let service_endpoint = http_endpoint().await?;
reqwest::Client::default()
.post(format!("{}/auth-data", service_endpoint))
.body(auth_data.to_string())
.send()
.await?
.error_for_status()?;
Ok(())
}
async fn feed_auth_data_cli(auth_data: &str) -> anyhow::Result<()> {
info!("Feeding auth data to the CLI");
let port_file = temp_dir().join("gpcallback.port");
let port_file = temp_dir().join(GP_CALLBACK_PORT_FILENAME);
let port = tokio::fs::read_to_string(port_file).await?;
let mut stream = tokio::net::TcpStream::connect(format!("127.0.0.1:{}", port.trim())).await?;