Skip to content

Commit

Permalink
Use just Pubkey::algos()
Browse files Browse the repository at this point in the history
  • Loading branch information
honzasp committed Feb 4, 2023
1 parent 4ef11ec commit 46c972f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "makiko"
version = "0.2.0"
version = "0.2.1-pre"
edition = "2021"

authors = ["Jan Špaček <patek.mail@gmail.com>"]
Expand Down
2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async fn authenticate(client: &makiko::Client, username: String, mut keys: Vec<K
}

let pubkey = decode_pubkey(key).await?;
for algo in pubkey.algos_compatible_less_secure().iter() {
for algo in pubkey.algos().iter() {
if let Some(names) = ctx.pubkey_algo_names.as_ref() {
if !names.contains(algo.name) {
continue
Expand Down
31 changes: 22 additions & 9 deletions src/pubkey/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ pub enum Pubkey {
}

impl Pubkey {
/// Get best public key algorithms that work with this key.
/// Get all public key algorithms that work with this key.
///
/// Most key types work with just a single public key algorithm, but with RSA keys
/// ([`Pubkey::Rsa`]), there are multiple algorithms that differ in the hash function. This
/// method returns only highly secure algorithms, but older servers may not support them.
pub fn algos_secure(&self) -> &'static [&'static PubkeyAlgo] {
/// method returns all supported algorithms for this key.
pub fn algos(&self) -> &'static [&'static PubkeyAlgo] {
static ED25519: &[&PubkeyAlgo] = &[&SSH_ED25519];
static RSA: &[&PubkeyAlgo] = &[&RSA_SHA2_256, &RSA_SHA2_512];
static RSA: &[&PubkeyAlgo] = &[&RSA_SHA2_256, &RSA_SHA2_512, &SSH_RSA_SHA1];
static ECDSA_P256: &[&PubkeyAlgo] = &[&ECDSA_SHA2_NISTP256];
static ECDSA_P384: &[&PubkeyAlgo] = &[&ECDSA_SHA2_NISTP384];
match self {
Expand All @@ -78,19 +78,32 @@ impl Pubkey {
}
}

/// Get all public key algorithms that work with this key.
/// Get best public key algorithms that work with this key.
///
/// Most key types work with just a single public key algorithm, but with RSA keys
/// ([`Pubkey::Rsa`]), there are multiple algorithms that differ in the hash function. This
/// method returns all supported algorithms for maximum compatibility.
pub fn algos_compatible_less_secure(&self) -> &'static [&'static PubkeyAlgo] {
static RSA: &[&PubkeyAlgo] = &[&RSA_SHA2_256, &RSA_SHA2_512, &SSH_RSA_SHA1];
/// method returns only highly secure algorithms, but older servers may not support them.
#[deprecated(since = "0.2.1", note = "Disabling public key algorithms for authentication _on the client_ \
does not increase security, the older, less secure algorithms must be disabled on the server. \
Please use `Pubkey::algos()` instead.")]
pub fn algos_secure(&self) -> &'static [&'static PubkeyAlgo] {
static RSA: &[&PubkeyAlgo] = &[&RSA_SHA2_256, &RSA_SHA2_512];
match self {
Pubkey::Rsa(_) => RSA,
_ => self.algos_secure(),
_ => self.algos(),
}
}

/// Get all public key algorithms that work with this key.
///
/// Most key types work with just a single public key algorithm, but with RSA keys
/// ([`Pubkey::Rsa`]), there are multiple algorithms that differ in the hash function. This
/// method returns all supported algorithms for maximum compatibility.
#[deprecated(since = "0.2.1", note = "Please use `Pubkey::algos()` instead.")]
pub fn algos_compatible_less_secure(&self) -> &'static [&'static PubkeyAlgo] {
self.algos()
}

/// Decode a public key from SSH wire encoding.
///
/// This is the encoding initially defined by RFC 4253. For keys other than RSA, the encoding
Expand Down

0 comments on commit 46c972f

Please sign in to comment.