`ssh-key` rejects valid certificates with non-text extensions and corrupts empty-string option values during TBS re-encoding
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- rust
- Domínio
- cryptography, security
Direção de pesquisa
Read ssh-key/src/certificate/options_map.rs first, focusing on OptionsMap::decode and OptionsMap::encode, then inspect Certificate::encode_tbs and Certificate::verify_signature in ssh-key/src/certificate.rs. Add or update tests covering binary and multi-field extension values, empty-string values, and signature verification over the resulting certificate. Done means valid certificates with unrecognized extensions are accepted, empty-string options retain their wire representation, signatures remain valid, and validate_at documentation includes the missing cert_type check.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Note: This is a low-priority RFC conformance edge case (not a security issue). Sharing it for tracking only — totally up to the maintainers whether it's worth fixing or closing as won't-fix.
Specification
Per draft-ietf-sshm-cert-01 Section 2.2:
The "critical options" and "extensions" certificate sections use the
same format for encoding, though they differ in how unsupported
options are handled.Both sections consist of zero or more key/value pairs, encoded as a
pair of strings:string key string value"key" should be a UTF-8 encoded string that identifies the option
being encoded. Available keys for extensions and for critical
options sections are listed below, but implementations may add their
own options using the domain-qualified naming convention defined in
Section 4.2 of [RFC4251].The contents and format of "value" are specific to each option or
extension. Key/value pairs MUST be ordered lexically by key name.
Per draft-ietf-sshm-cert-01 Section 2.1.1:
The "extensions" field similarly contains zero or more of the
certificate extensions described in Section 2.3 and encoded as
described in Section 2.2. An implementation that does not recognise
or support an extension present in a certificate extension section
MUST ignore the extension.
And per draft-ietf-sshm-cert-01 Section 3.1:
When making authentication or authorisation decisions with a
certificate, implementations:
MUST check that the certificate is well-formed
MUST ensure that no unsupported critical options are present
MUST check that the "certificate role" matches the intended
decision type (user or host authentication)MUST check the time against the certificate validity interval
MUST verify that at least one of the listed certificate principals
is acceptedMUST perform any additional authorisation operations required by
critical options.
Code
In options_map.rs, OptionsMap::decode requires every non-empty outer value buffer to contain exactly one nested UTF-8 String, failing with Error::Encoding whenever an unrecognized vendor extension carries raw binary or multi-field value bytes, and collapsing a nested empty string (00000004 00000000) into String::new() — indistinguishable from a zero-length flag (00000000):
impl Decode for OptionsMap {
type Error = Error;
fn decode(reader: &mut Decoder<impl Reader>) -> Result<Self> {
reader.read_prefixed(|reader| {
let mut entries = Vec::<(String, String)>::new();
while !reader.is_finished() {
let name = String::decode(reader)?;
let data = reader.read_prefixed(|reader| {
if reader.remaining_len() > 0 {
String::decode(reader)
} else {
Ok(String::default())
}
})?;
// Options must be lexically ordered by "name" if they appear in
// the sequence. Each named option may only appear once in a
// certificate.
if let Some((prev_name, _)) = entries.last() {
if prev_name.cmp(&name) != Ordering::Less {
return Err(Error::FormatEncoding);
}
}
entries.push((name, data));
}
Ok(OptionsMap::from_iter(entries))
})
}
}
During serialization in options_map.rs, OptionsMap::encode writes 0usize (00000000) whenever the stored String is empty:
impl Encode for OptionsMap {
fn encoded_len(&self) -> encoding::Result<usize> {
self.iter().try_fold(4, |acc, (name, data)| {
[
acc,
name.encoded_len()?,
if data.is_empty() {
4
} else {
data.encoded_len_prefixed()?
},
]
.checked_sum()
})
}
fn encode(&self, writer: &mut impl Writer) -> encoding::Result<()> {
self.encoded_len()?
.checked_sub(4)
.ok_or(encoding::Error::Length)?
.encode(writer)?;
for (name, data) in self.iter() {
name.encode(writer)?;
if data.is_empty() {
0usize.encode(writer)?;
} else {
data.encode_prefixed(writer)?;
}
}
Ok(())
}
}
In certificate.rs, Certificate::verify_signature reconstructs the signed byte buffer via self.encode_tbs(&mut tbs_certificate) rather than verifying over the original wire bytes. When OpenSSH ssh-keygen -s ca -I id -n user -O extension:[email protected]= user.pub signs a certificate with an empty string extension (00000004 00000000), encode_tbs re-serializes it as 00000000 and invalidates the CA signature:
#[doc(hidden)]
pub fn verify_signature(&self) -> Result<()> {
let mut tbs_certificate = Vec::new();
self.encode_tbs(&mut tbs_certificate)?;
self.signature_key
.verify(&tbs_certificate, &self.signature)
.map_err(|_| Error::CertificateValidation)
}
/// Encode the portion of the certificate "to be signed" by the CA
/// (or to be verified against an existing CA signature)
fn encode_tbs(&self, writer: &mut impl Writer) -> encoding::Result<()> {
self.algorithm().to_certificate_type().encode(writer)?;
self.nonce.encode(writer)?;
self.public_key.encode_key_data(writer)?;
self.serial.encode(writer)?;
self.cert_type.encode(writer)?;
self.key_id.encode(writer)?;
self.valid_principals.encode(writer)?;
self.valid_after.encode(writer)?;
self.valid_before.encode(writer)?;
self.critical_options.encode(writer)?;
self.extensions.encode(writer)?;
self.reserved.encode(writer)?;
self.signature_key.encode_prefixed(writer)
}
In addition, Certificate::validate_at's documentation checklist in certificate.rs enumerates caller checks without listing cert_type:
/// If this method succeeds, the following properties still need to be checked to ensure the
/// certificate is valid:
///
/// - `valid_principals` is empty or contains the expected principal.
/// - `critical_options` is empty or contains *only* options which are recognized, and that the
/// recognized options are all valid.
- Linguagem predominante
- Rust
- Estrelas
- 252
- Forks
- 68
- Merge médio
- 6h 39min
- PRs com merge (30d)
- 62
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de RustCrypto/SSH
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
RustCrypto/SSH#596 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
RustCrypto/SSH#595 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
RustCrypto/SSH#580 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 42/100
RustCrypto/SSH#527 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
PQ/T Hybrid Key ExchangeAberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
RustCrypto/SSH#349 · 3 reações ·
Mantenedores costumam responder em até 1 dia
Todas as issues de RustCrypto/SSH
Issues semelhantes
-
The new tests repeat each other and one only checks a two-line helperTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Abertainfra
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 90/100
storytold/wordcraft#9405 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
in-progress
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
area: ai-assistants documentation help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
BetaBots-LLC/latticegate#17 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 94/100
storytold/craft-libs#5594 ·
Mantenedores costumam responder em até 1 dia
-
available documentation good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Nixitov/Riptide-Native#932 ·
Mantenedores costumam responder em até 1 dia