Skip to content

Commit 5ce36bd

Browse files
TheBestTvarynkaCBenoit
authored andcommitted
test(sspi): implement simple KDC mock (#429)
1 parent 0efeb55 commit 5ce36bd

File tree

8 files changed

+818
-15
lines changed

8 files changed

+818
-15
lines changed

Cargo.lock

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/kerberos/client/generators.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ use crate::{ClientRequestFlags, Error, ErrorKind, Result};
5454

5555
const TGT_TICKET_LIFETIME_DAYS: i64 = 3;
5656
const NONCE_LEN: usize = 4;
57-
pub const MAX_MICROSECONDS_IN_SECOND: u32 = 999_999;
57+
/// [Microseconds](https://www.rfc-editor.org/rfc/rfc4120#section-5.2.4).
58+
/// The maximum microseconds value.
59+
///
60+
/// ```not_rust
61+
/// Microseconds ::= INTEGER (0..999999)
62+
/// ```
63+
pub const MAX_MICROSECONDS: u32 = 999_999;
5864
const MD5_CHECKSUM_TYPE: [u8; 1] = [0x07];
5965

6066
// Renewable, Canonicalize, and Renewable-ok are on by default
@@ -155,7 +161,7 @@ pub fn generate_pa_datas_for_as_req(options: &GenerateAsPaDataOptions) -> Result
155161

156162
let mut pa_datas = if *with_pre_auth {
157163
let current_date = OffsetDateTime::now_utc();
158-
let microseconds = current_date.microsecond().min(MAX_MICROSECONDS_IN_SECOND);
164+
let microseconds = current_date.microsecond().min(MAX_MICROSECONDS);
159165

160166
let timestamp = PaEncTsEnc {
161167
patimestamp: ExplicitContextTag0::from(KerberosTime::from(GeneralizedTime::from(current_date))),
@@ -548,8 +554,8 @@ pub fn generate_authenticator(options: GenerateAuthenticatorOptions) -> Result<A
548554

549555
let current_date = OffsetDateTime::now_utc();
550556
let mut microseconds = current_date.microsecond();
551-
if microseconds > MAX_MICROSECONDS_IN_SECOND {
552-
microseconds = MAX_MICROSECONDS_IN_SECOND;
557+
if microseconds > MAX_MICROSECONDS {
558+
microseconds = MAX_MICROSECONDS;
553559
}
554560

555561
let authorization_data = Optional::from(channel_bindings.as_ref().map(|_| {
@@ -611,7 +617,7 @@ pub fn generate_authenticator(options: GenerateAuthenticatorOptions) -> Result<A
611617
#[instrument(level = "trace", skip_all, ret)]
612618
pub fn generate_ap_rep(session_key: &[u8], seq_number: Vec<u8>, enc_params: &EncryptionParams) -> Result<ApRep> {
613619
let current_date = OffsetDateTime::now_utc();
614-
let microseconds = current_date.microsecond().min(MAX_MICROSECONDS_IN_SECOND);
620+
let microseconds = current_date.microsecond().min(MAX_MICROSECONDS);
615621

616622
let encryption_type = enc_params.encryption_type.as_ref().unwrap_or(&DEFAULT_ENCRYPTION_TYPE);
617623

src/pk_init.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use serde::{Deserialize, Serialize};
2828
use sha1::{Digest, Sha1};
2929
use time::OffsetDateTime;
3030

31-
use crate::kerberos::client::generators::MAX_MICROSECONDS_IN_SECOND;
31+
use crate::kerberos::client::generators::MAX_MICROSECONDS;
3232
use crate::{Error, ErrorKind, Result};
3333

3434
/// [Generation of Client Request](https://www.rfc-editor.org/rfc/rfc4556.html#section-3.2.1)
@@ -101,8 +101,8 @@ pub fn generate_pa_datas_for_as_req(options: &GenerateAsPaDataOptions<'_>) -> Re
101101

102102
let current_date = OffsetDateTime::now_utc();
103103
let mut microseconds = current_date.microsecond();
104-
if microseconds > MAX_MICROSECONDS_IN_SECOND {
105-
microseconds = MAX_MICROSECONDS_IN_SECOND;
104+
if microseconds > MAX_MICROSECONDS {
105+
microseconds = MAX_MICROSECONDS;
106106
}
107107

108108
// [Generation of Client Request](https://www.rfc-editor.org/rfc/rfc4556.html#section-3.2.1)

src/pku2u/generators.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use time::OffsetDateTime;
3232
use super::Pku2uConfig;
3333
use crate::crypto::compute_md5_channel_bindings_hash;
3434
use crate::kerberos::client::generators::{
35-
AuthenticatorChecksumExtension, ChecksumOptions, EncKey, GenerateAuthenticatorOptions, MAX_MICROSECONDS_IN_SECOND,
35+
AuthenticatorChecksumExtension, ChecksumOptions, EncKey, GenerateAuthenticatorOptions, MAX_MICROSECONDS,
3636
};
3737
use crate::pk_init::DhParameters;
3838
use crate::{Error, ErrorKind, Result, KERBEROS_VERSION};
@@ -217,8 +217,8 @@ pub fn generate_authenticator(options: GenerateAuthenticatorOptions) -> Result<A
217217

218218
let current_date = OffsetDateTime::now_utc();
219219
let mut microseconds = current_date.microsecond();
220-
if microseconds > MAX_MICROSECONDS_IN_SECOND {
221-
microseconds = MAX_MICROSECONDS_IN_SECOND;
220+
if microseconds > MAX_MICROSECONDS {
221+
microseconds = MAX_MICROSECONDS;
222222
}
223223

224224
let lsap_token = LsapTokenInfoIntegrity {

0 commit comments

Comments
 (0)