Skip to content

fix(kerberos): remove unnecessary sequence number incrementation - #717

Merged
Benoît Cortier (CBenoit) merged 2 commits into
masterfrom
fix/kerberos-sequence-number-incrementation
Jul 31, 2026
Merged

fix(kerberos): remove unnecessary sequence number incrementation#717
Benoît Cortier (CBenoit) merged 2 commits into
masterfrom
fix/kerberos-sequence-number-incrementation

Conversation

@TheBestTvarynka

@TheBestTvarynka Pavlo Myroniuk (TheBestTvarynka) commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Hi,
This PR fixes the authentication issue inside the Kerberos implementation.

The problem was in an unnecessary sequence number incrementation:

client.next_seq_number();
. It was added last year in #435.

Why did we add it?

It was necessary back then. But after the big Negotiate refactoring and NTLM fallback improvement, this sequence number incrementation became unneeded.

Why did the tests not catch it?

Because our Kerberos implementation did not check the MIC token sequence number properly. I improved the implementation, and now it will fail if we mess it up again.

Why did we not notice it during dev testing?

Because it happens only when the MIC token exchange is present. After the Negotiate module refactoring and NTLM fallback improvements, we skip MIC token exchange in many cases. For example, regular password-based Kerberos auth using FreeRDP always worked.

Related issues

Devolutions/IronRDP#1469

closes #668

@CBenoit Benoît Cortier (CBenoit) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@CBenoit
Benoît Cortier (CBenoit) merged commit 6d17708 into master Jul 31, 2026
62 checks passed
@CBenoit
Benoît Cortier (CBenoit) deleted the fix/kerberos-sequence-number-incrementation branch July 31, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Kerberos authentication failures during SPNEGO MIC exchange by correctly tracking peer sequence numbers.

Changes:

  • Removes the unnecessary client sequence increment.
  • Validates MIC sequence numbers against peer state.
  • Refactors AP-REP decryption and field extraction.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/kerberos/client/extractors.rs Refactors AP-REP extraction.
src/kerberos/client/mod.rs Tracks the server sequence number.
src/kerberos/mod.rs Stores and validates remote sequence numbers.
src/kerberos/server/mod.rs Tracks the client sequence number.
src/kerberos/tests.rs Updates Kerberos test fixtures.
src/kerberos/utils.rs Adds MIC sequence validation.
src/pku2u/mod.rs Adopts shared AP-REP decryption.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +252 to +259
let seq_number = u32::from_be_bytes(seq_number_bytes.try_into().map_err(|err| {
Error::new(
ErrorKind::InvalidToken,
format!("invalid ApRep sequence number: {:?}", err),
)
})?);

Ok(seq_number)

let ap_rep_enc_part: EncApRepPart = picky_asn1_der::from_bytes(&res)?;

pub fn extract_sub_session_key_from_ap_rep(ap_rep_enc_part: &EncApRepPart) -> Result<Secret<Vec<u8>>> {

/// Extracts a sequence number from the [EncApRepPart].
#[instrument(level = "trace", ret)]
pub fn extract_seq_number_from_ap_rep(ap_rep_enc_part: &EncApRepPart) -> Result<u32> {
}

/// Extracts the sequence number from the [ApRep].
/// Decrypt and decodes the encrypted part of the encoded [ApRep] message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

MsRdpEx session failed with 'specified data could not be decrypted' error if connecting via kerberos protocol when KDC_URL and DNS are set

4 participants