mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
print the public key on login
This commit is contained in:
parent
83387da305
commit
c2a1daab63
@ -30,7 +30,7 @@ use crate::ops;
|
|||||||
use crate::ops::Packages;
|
use crate::ops::Packages;
|
||||||
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_DOMAIN, CRATES_IO_REGISTRY};
|
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_DOMAIN, CRATES_IO_REGISTRY};
|
||||||
use crate::util::auth::{
|
use crate::util::auth::{
|
||||||
check_format_like_paserk_secret, {self, AuthorizationError},
|
paserk_public_from_paserk_secret, {self, AuthorizationError},
|
||||||
};
|
};
|
||||||
use crate::util::config::{Config, SslVersionConfig, SslVersionConfigRange};
|
use crate::util::config::{Config, SslVersionConfig, SslVersionConfigRange};
|
||||||
use crate::util::errors::CargoResult;
|
use crate::util::errors::CargoResult;
|
||||||
@ -807,7 +807,7 @@ pub fn registry_login(
|
|||||||
let new_token;
|
let new_token;
|
||||||
if generate_keypair || secret_key_required || key_subject.is_some() {
|
if generate_keypair || secret_key_required || key_subject.is_some() {
|
||||||
if !config.cli_unstable().registry_auth {
|
if !config.cli_unstable().registry_auth {
|
||||||
panic!("-registry_auth required.");
|
panic!("-Zregistry_auth required.");
|
||||||
}
|
}
|
||||||
assert!(token.is_none());
|
assert!(token.is_none());
|
||||||
// we are dealing with asymmetric tokens
|
// we are dealing with asymmetric tokens
|
||||||
@ -839,7 +839,9 @@ pub fn registry_login(
|
|||||||
.cloned()
|
.cloned()
|
||||||
.ok_or_else(|| anyhow!("need a secret_key to set a key_subject"))?;
|
.ok_or_else(|| anyhow!("need a secret_key to set a key_subject"))?;
|
||||||
}
|
}
|
||||||
if !check_format_like_paserk_secret(&secret_key) {
|
if let Some(p) = paserk_public_from_paserk_secret(&secret_key) {
|
||||||
|
drop_println!(config, "{}", &p);
|
||||||
|
} else {
|
||||||
bail!("not a validly formated PASERK secret key");
|
bail!("not a validly formated PASERK secret key");
|
||||||
}
|
}
|
||||||
new_token = RegistryCredentialConfig::AsymmetricKey((
|
new_token = RegistryCredentialConfig::AsymmetricKey((
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use crate::util::{config, config::ConfigKey, CanonicalUrl, CargoResult, Config, IntoUrl};
|
use crate::util::{config, config::ConfigKey, CanonicalUrl, CargoResult, Config, IntoUrl};
|
||||||
use anyhow::{bail, format_err, Context as _};
|
use anyhow::{bail, format_err, Context as _};
|
||||||
use cargo_util::ProcessError;
|
use cargo_util::ProcessError;
|
||||||
|
use pasetors::paserk::FormatAsPaserk;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use pasetors::keys::{AsymmetricPublicKey, AsymmetricSecretKey};
|
use pasetors::keys::{AsymmetricPublicKey, AsymmetricSecretKey};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@ -488,9 +489,12 @@ pub fn login(config: &Config, sid: &SourceId, token: RegistryCredentialConfig) -
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn check_format_like_paserk_secret(secret_key: &str) -> bool {
|
pub(crate) fn paserk_public_from_paserk_secret(secret_key: &str) -> Option<String> {
|
||||||
let key: Result<AsymmetricSecretKey<pasetors::version3::V3>, _> = secret_key.try_into();
|
let secret: AsymmetricSecretKey<pasetors::version3::V3> = secret_key.try_into().ok()?;
|
||||||
key.is_ok()
|
let public: AsymmetricPublicKey<pasetors::version3::V3> = (&secret).try_into().ok()?;
|
||||||
|
let mut paserk_pub_key = String::new();
|
||||||
|
FormatAsPaserk::fmt(&public, &mut paserk_pub_key).unwrap();
|
||||||
|
Some(paserk_pub_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the token for the given registry.
|
/// Removes the token for the given registry.
|
||||||
|
@ -1135,7 +1135,11 @@ fn login_with_asymmetric_token_and_subject_on_stdin() {
|
|||||||
cargo_process("login --key-subject=foo --secret-key -v -Z registry-auth")
|
cargo_process("login --key-subject=foo --secret-key -v -Z registry-auth")
|
||||||
.masquerade_as_nightly_cargo(&["registry-auth"])
|
.masquerade_as_nightly_cargo(&["registry-auth"])
|
||||||
.replace_crates_io(registry.index_url())
|
.replace_crates_io(registry.index_url())
|
||||||
.with_stdout("please paste the API secret key below")
|
.with_stdout(
|
||||||
|
"\
|
||||||
|
please paste the API secret key below
|
||||||
|
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
|
||||||
|
)
|
||||||
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
|
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
|
||||||
.run();
|
.run();
|
||||||
let credentials = fs::read_to_string(&credentials).unwrap();
|
let credentials = fs::read_to_string(&credentials).unwrap();
|
||||||
@ -1152,7 +1156,11 @@ fn login_with_asymmetric_token_on_stdin() {
|
|||||||
cargo_process("login --secret-key -v -Z registry-auth")
|
cargo_process("login --secret-key -v -Z registry-auth")
|
||||||
.masquerade_as_nightly_cargo(&["registry-auth"])
|
.masquerade_as_nightly_cargo(&["registry-auth"])
|
||||||
.replace_crates_io(registry.index_url())
|
.replace_crates_io(registry.index_url())
|
||||||
.with_stdout("please paste the API secret key below")
|
.with_stdout(
|
||||||
|
"\
|
||||||
|
please paste the API secret key below
|
||||||
|
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
|
||||||
|
)
|
||||||
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
|
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
|
||||||
.run();
|
.run();
|
||||||
let credentials = fs::read_to_string(&credentials).unwrap();
|
let credentials = fs::read_to_string(&credentials).unwrap();
|
||||||
@ -1175,7 +1183,10 @@ fn login_with_asymmetric_key_subject_without_key() {
|
|||||||
cargo_process("login --secret-key -v -Z registry-auth")
|
cargo_process("login --secret-key -v -Z registry-auth")
|
||||||
.masquerade_as_nightly_cargo(&["registry-auth"])
|
.masquerade_as_nightly_cargo(&["registry-auth"])
|
||||||
.replace_crates_io(registry.index_url())
|
.replace_crates_io(registry.index_url())
|
||||||
.with_stdout("please paste the API secret key below")
|
.with_stdout(
|
||||||
|
"please paste the API secret key below
|
||||||
|
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
|
||||||
|
)
|
||||||
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
|
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@ -1199,6 +1210,7 @@ fn login_with_generate_asymmetric_token() {
|
|||||||
cargo_process("login --generate-keypair -Z registry-auth")
|
cargo_process("login --generate-keypair -Z registry-auth")
|
||||||
.masquerade_as_nightly_cargo(&["registry-auth"])
|
.masquerade_as_nightly_cargo(&["registry-auth"])
|
||||||
.replace_crates_io(registry.index_url())
|
.replace_crates_io(registry.index_url())
|
||||||
|
.with_stdout("k3.public.[..]")
|
||||||
.run();
|
.run();
|
||||||
let credentials = fs::read_to_string(&credentials).unwrap();
|
let credentials = fs::read_to_string(&credentials).unwrap();
|
||||||
assert!(credentials.contains("secret-key = \"k3.secret."));
|
assert!(credentials.contains("secret-key = \"k3.secret."));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user