rasn_kerberos/lib.rs
1#![doc = include_str!("../README.md")]
2#![no_std]
3
4#[cfg(feature = "otp")]
5pub mod otp;
6
7use rasn::prelude::*;
8
9pub type HostAddresses = SequenceOf<HostAddress>;
10pub type AdMandatoryForKdc = AuthorizationData;
11
12/// Element are intended for interpretation only by application servers that
13/// understand the particular `type` of the embedded element.
14///
15/// Application servers that do not understand the type of an element embedded within the
16/// [AdIfRelevant] element MAY ignore the uninterpretable element. This element
17/// promotes interoperability across implementations that may have local
18/// extensions for authorization.
19pub type AdIfRelevant = AuthorizationData;
20pub type EtypeInfo2 = SequenceOf<EtypeInfo2Entry>;
21pub type EtypeInfo = SequenceOf<EtypeInfoEntry>;
22pub type PaEncTimestamp = EncryptedData;
23pub type LastReq = SequenceOf<LastReqValue>;
24pub type MethodData = SequenceOf<PaData>;
25pub type KerberosString = GeneralString;
26pub type ETypeList = SequenceOf<i32>;
27
28/// The name of the authentication server.
29pub type Realm = KerberosString;
30
31// ::= INTEGER (0..999999) -- microseconds
32pub type Microseconds = Integer;
33
34pub const OID: &Oid = Oid::ISO_IDENTIFIED_ORGANISATION_DOD_INTERNET_SECURITY_KERBEROS_V5;
35
36/// The name of the party to verify. Taken together, a [PrincipalName] and a
37/// [Realm] form a principal identifier.
38#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
39pub struct PrincipalName {
40 /// The type of name that follows. This should be should be treated as a
41 /// hint. Ignoring the type, no two names can be the same (i.e., at least
42 /// one of the components, or the realm, must be different).
43 #[rasn(tag(explicit(0)))]
44 pub r#type: i32,
45 /// A sequence of components that form a name.
46 #[rasn(tag(explicit(1)))]
47 pub string: SequenceOf<KerberosString>,
48}
49
50#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
51#[rasn(delegate)]
52pub struct KerberosTime(pub GeneralizedTime);
53
54/// The address of a given host.
55#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
56pub struct HostAddress {
57 /// The type of `address`. Some predefined values include:
58 ///
59 /// - [HostAddress::IPV4]
60 /// - [HostAddress::DIRECTIONAL]
61 /// - [HostAddress::CHAOS_NET]
62 /// - [HostAddress::XNS]
63 /// - [HostAddress::ISO]
64 /// - [HostAddress::DECNET_PHASE_IV]
65 /// - [HostAddress::APPLE_TALK_DDP]
66 /// - [HostAddress::NET_BIOS]
67 /// - [HostAddress::IPV6]
68 #[rasn(tag(explicit(0)))]
69 pub addr_type: i32,
70 /// A single address of type defined by `addr_type`.
71 #[rasn(tag(explicit(1)))]
72 pub address: OctetString,
73}
74
75impl HostAddress {
76 pub const IPV4: i32 = 2;
77 pub const DIRECTIONAL: i32 = 3;
78 pub const CHAOS_NET: i32 = 5;
79 pub const XNS: i32 = 6;
80 pub const ISO: i32 = 7;
81 pub const DECNET_PHASE_IV: i32 = 12;
82 pub const APPLE_TALK_DDP: i32 = 16;
83 pub const NET_BIOS: i32 = 20;
84 pub const IPV6: i32 = 24;
85}
86
87/// Authorization data.
88pub type AuthorizationData = SequenceOf<AuthorizationDataValue>;
89
90#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
91pub struct AuthorizationDataValue {
92 /// Specifies the format for the `data` field. All negative values are
93 /// reserved for local use. Non-negative values are reserved for registered
94 /// use. Some pre-defined values include:
95 ///
96 /// - [AuthorizationDataValue::IF_RELEVANT]
97 /// - [AuthorizationDataValue::KDC_ISSUED]
98 /// - [AuthorizationDataValue::AND_OR]
99 /// - [AuthorizationDataValue::MANDATORY_FOR_KDC]
100 #[rasn(tag(explicit(0)))]
101 pub r#type: i32,
102 /// Authorization data to be interpreted according to the value of the
103 /// corresponding `type` field.
104 #[rasn(tag(explicit(1)))]
105 pub data: OctetString,
106}
107
108impl AuthorizationDataValue {
109 /// DER encoding of [AdIfRelevant].
110 pub const IF_RELEVANT: i32 = 1;
111 /// DER encoding of [AdKdcIssued].
112 pub const KDC_ISSUED: i32 = 4;
113 /// DER encoding of [AdAndOr].
114 pub const AND_OR: i32 = 5;
115 /// DER encoding of [AdMandatoryForKdc].
116 pub const MANDATORY_FOR_KDC: i32 = 8;
117}
118
119/// Pre-Authenication data.
120#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
121pub struct PaData {
122 #[rasn(tag(explicit(1)))]
123 pub r#type: i32,
124 #[rasn(tag(explicit(2)))]
125 pub value: OctetString,
126}
127
128// KerberosFlags ::= BIT STRING (SIZE (32..MAX))
129pub type KerberosFlags = BitString;
130
131/// Container for arbitrary encrypted data
132#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
133pub struct EncryptedData {
134 /// Identifies which encryption algorithm was used to encipher the cipher.
135 #[rasn(tag(explicit(0)))]
136 pub etype: i32,
137 /// Contains the version number of the key under which data is encrypted.
138 /// It is only present in messages encrypted under long lasting keys, such
139 /// as principals' secret keys.
140 #[rasn(tag(explicit(1)))]
141 pub kvno: Option<u32>,
142 /// Contains the enciphered text.
143 #[rasn(tag(explicit(2)))]
144 pub cipher: OctetString,
145}
146
147/// The means by which cryptographic keys used for encryption are transferred.
148#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
149pub struct EncryptionKey {
150 /// This field specifies the encryption type of the encryption key that
151 /// follows in the `value` field.
152 #[rasn(tag(explicit(0)))]
153 pub r#type: i32,
154 /// The key itself.
155 #[rasn(tag(explicit(1)))]
156 pub value: OctetString,
157}
158
159/// Checksum of cleartext data.
160#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
161pub struct Checksum {
162 /// The algorithm used to generate the accompanying checksum.
163 #[rasn(tag(explicit(0)))]
164 pub r#type: i32,
165 /// The checksum itself.
166 #[rasn(tag(explicit(1)))]
167 pub checksum: OctetString,
168}
169
170pub use body::*;
171mod body {
172 use super::*;
173 /// Record that helps a client authenticate to a service.
174 #[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
175 #[rasn(tag(explicit(application, 1)))]
176 pub struct Ticket {
177 /// The version number for the ticket format.
178 #[rasn(tag(explicit(0)))]
179 pub tkt_vno: Integer,
180 /// The realm that issued a ticket. It also serves to identify the realm
181 /// part of the server's principal identifier. Since a Kerberos server can
182 /// only issue tickets for servers within its realm, the two will always
183 /// be identical.
184 #[rasn(tag(explicit(1)))]
185 pub realm: Realm,
186 /// All components of the name part of the server's identity, including
187 /// those parts that identify a specific instance of a service.
188 #[rasn(tag(explicit(2)))]
189 pub sname: PrincipalName,
190 /// The encrypted encoding of [EncTicketPart]. It is encrypted in the key
191 /// shared by Kerberos and the end server (the server's secret key), using a
192 /// key usage value of `2`.
193 #[rasn(tag(explicit(3)))]
194 pub enc_part: EncryptedData,
195 }
196}
197
198/// The encrypted part of a [Ticket].
199#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
200#[rasn(tag(explicit(application, 3)))]
201pub struct EncTicketPart {
202 /// Options that were used or requested when the ticket was issued.
203 #[rasn(tag(explicit(0)))]
204 pub flags: TicketFlags,
205 /// Used to pass the session key from Kerberos to the application server and
206 /// the client.
207 #[rasn(tag(explicit(1)))]
208 pub key: EncryptionKey,
209 /// The name of the realm in which the client is registered and in which
210 /// initial authentication took place.
211 #[rasn(tag(explicit(2)))]
212 pub crealm: Realm,
213 /// The name part of the client's principal identifier.
214 #[rasn(tag(explicit(3)))]
215 pub cname: PrincipalName,
216 /// Lists the names of the Kerberos realms that took part in authenticating
217 /// the user to whom this ticket was issued. It does not specify the order
218 /// in which the realms were transited.
219 #[rasn(tag(explicit(4)))]
220 pub transited: TransitedEncoding,
221 /// The time of initial authentication for the named principal. It
222 /// is the time of issue for the original ticket on which this ticket is
223 /// based. It is included in the ticket to provide additional information
224 /// to the end service, and to provide the necessary information for
225 /// implementation of a "hot list" service at the KDC. An end service that
226 /// is particularly paranoid could refuse to accept tickets for which the
227 /// initial authentication occurred "too far" in the past.
228 #[rasn(tag(explicit(5)))]
229 pub auth_time: KerberosTime,
230 /// The time after which the ticket is valid. Together with `end_time`, this
231 /// field specifies the life of the ticket. If the `start_time` field is
232 /// absent from the ticket, then the `auth_time` field should be used in its
233 /// place to determine the life of the ticket.
234 #[rasn(tag(explicit(6)))]
235 pub start_time: Option<KerberosTime>,
236 /// The time after which the ticket will not be honored (its expiration
237 /// time). Note that individual services may place their own limits on the
238 /// life of a ticket and MAY reject tickets which have not yet expired. As
239 /// such, this is really an upper bound on the expiration time for
240 /// the ticket.
241 #[rasn(tag(explicit(7)))]
242 pub end_time: KerberosTime,
243 /// The maximum `end_time` that may be included in a renewal. It can be
244 /// thought of as the absolute expiration time for the ticket, including
245 /// all renewals.
246 ///
247 /// Only present in tickets that have the [TicketFlags::renewable] flag set
248 /// in the flags field.
249 #[rasn(tag(explicit(8)))]
250 pub renew_till: Option<KerberosTime>,
251 /// Addresses from which the ticket can be used.
252 ///
253 /// If there are no addresses, the ticket can be used from any location. The
254 /// decision by the KDC to issue or by the end server to accept addressless
255 /// tickets is a policy decision and is left to the Kerberos and end-service
256 /// administrators; they may refuse to issue or accept such tickets. Because
257 /// of the wide deployment of network address translation, it is recommended
258 /// that policy allow the issue and acceptance of such tickets.
259 #[rasn(tag(explicit(9)))]
260 pub caddr: Option<HostAddresses>,
261 /// Restrictions on any authority obtained on the basis of authentication
262 /// using the ticket. It is possible for any principal in possession of
263 /// credentials to add entries to the authorization data field since these
264 /// entries further restrict what can be done with the ticket. Such
265 /// additions can be made by specifying the additional entries when a new
266 /// ticket is obtained during the TGS exchange, or they MAY be added during
267 /// chained delegation using the authorization data field of
268 /// the authenticator.
269 #[rasn(tag(explicit(10)))]
270 pub authorization_data: Option<AuthorizationData>,
271}
272
273#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
274pub struct TransitedEncoding {
275 #[rasn(tag(explicit(0)))]
276 pub r#type: i32,
277 #[rasn(tag(explicit(1)))]
278 pub contents: OctetString,
279}
280
281/// Various options that were used or requested when the ticket was issued.
282#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
283#[rasn(delegate)]
284pub struct TicketFlags(pub KerberosFlags);
285
286impl TicketFlags {
287 /// Reserved for future expansion of this field.
288 pub fn reserved() -> Self {
289 Self(KerberosFlags::from_element(0))
290 }
291
292 /// Tells the ticket-granting server that it is OK to issue a new TGT with a
293 /// different network address based on the presented ticket.
294 pub fn forwardable() -> Self {
295 Self(KerberosFlags::from_element(1))
296 }
297
298 /// Indicates that the ticket has either been forwarded or was issued based
299 /// on authentication involving a forwarded TGT.
300 pub fn forwarded() -> Self {
301 Self(KerberosFlags::from_element(2))
302 }
303
304 /// Identical to the [TicketFlags::forwardable] flag, except that it tells
305 /// the ticket-granting server that only non-TGTs may be issued with
306 /// different network addresses.
307 pub fn proxiable() -> Self {
308 Self(KerberosFlags::from_element(3))
309 }
310
311 /// Indicates that a ticket is a proxy.
312 pub fn proxy() -> Self {
313 Self(KerberosFlags::from_element(4))
314 }
315
316 /// Tells the ticket-granting server that a post-dated ticket may be issued
317 /// based on this TGT.
318 pub fn may_postdate() -> Self {
319 Self(KerberosFlags::from_element(0x8))
320 }
321
322 /// Indicates that this ticket has been postdated. The end-service can check
323 /// the `auth_time` field to see when the original authentication occurred.
324 pub fn postdated() -> Self {
325 Self(KerberosFlags::from_element(0x10))
326 }
327
328 /// Indicates that a ticket is invalid, and it must be validated by the KDC
329 /// before use. Application servers must reject tickets which have this
330 /// flag set.
331 pub fn invalid() -> Self {
332 Self(KerberosFlags::from_element(0x20))
333 }
334
335 /// Indicates that a ticket can be used to obtain a replacement ticket that
336 /// expires at a later date.
337 pub fn renewable() -> Self {
338 Self(KerberosFlags::from_element(0x40))
339 }
340
341 /// Indicates that this ticket was issued using the AS protocol, and not
342 /// issued based on a TGT.
343 pub fn initial() -> Self {
344 Self(KerberosFlags::from_element(0x80))
345 }
346
347 /// Indicates that during initial authentication, the client was
348 /// authenticated by the KDC before a ticket was issued. The strength of
349 /// the pre-authentication method is not indicated, but is acceptable to
350 /// the KDC.
351 pub fn pre_authent() -> Self {
352 Self(KerberosFlags::from_slice(&[0x1, 00]))
353 }
354
355 /// Indicates that the protocol employed for initial authentication required
356 /// the use of hardware expected to be possessed solely by the named client.
357 /// The hardware authentication method is selected by the KDC and the
358 /// strength of the method is not indicated.
359 pub fn hw_authent() -> Self {
360 Self(KerberosFlags::from_slice(&[0x2, 00]))
361 }
362
363 /// Indicates that the KDC for the realm has checked the transited field
364 /// against a realm-defined policy for trusted certifiers. If this flag is
365 /// reset (0), then the application server must check the transited field
366 /// itself, and if unable to do so, it must reject the authentication. If
367 /// the flag is set (1), then the application server MAY skip its own
368 /// validation of the transited field, relying on the validation performed
369 /// by the KDC. At its option the application server MAY still apply its
370 /// own validation based on a separate policy for acceptance.
371 pub fn transited_policy_checked() -> Self {
372 Self(KerberosFlags::from_slice(&[0x4, 00]))
373 }
374
375 /// Indicates that the server (not the client) specified in the ticket has
376 /// been determined by policy of the realm to be a suitable recipient of
377 /// delegation. A client can use the presence of this flag to help it decide
378 /// whether to delegate credentials (either grant a proxy or a forwarded
379 /// TGT) to this server. The client is free to ignore the value of this
380 /// flag. When setting this flag, an administrator should consider the
381 /// security and placement of the server on which the service will run, as
382 /// well as whether the service requires the use of delegated credentials.
383 pub fn ok_as_delegate() -> Self {
384 Self(KerberosFlags::from_slice(&[0x80, 0]))
385 }
386}
387
388/// Initial ticket request.
389#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
390#[rasn(tag(explicit(application, 10)), delegate)]
391pub struct AsReq(pub KdcReq);
392
393/// Additional ticket request.
394#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
395#[rasn(tag(explicit(application, 12)), delegate)]
396pub struct TgsReq(pub KdcReq);
397
398/// The ticket request struct.
399#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
400pub struct KdcReq {
401 /// The protocol version number.
402 #[rasn(tag(explicit(1)))]
403 pub pvno: Integer,
404 /// The type of a protocol message. It will almost always be the same as the
405 /// application identifier associated with a message. It is included to make
406 /// the identifier more readily accessible to the application.
407 #[rasn(tag(explicit(2)))]
408 pub msg_type: Integer,
409 /// Pre-authentication data
410 #[rasn(tag(explicit(3)))]
411 pub padata: Option<SequenceOf<PaData>>,
412 /// The remaining fields in ticket request. If a checksum is generated for
413 /// the request, it is done using this field.
414 #[rasn(tag(explicit(4)))]
415 pub req_body: KdcReqBody,
416}
417
418/// The remaining fields in ticket request. If a checksum is generated for
419/// the request, it is done using this field.
420#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
421pub struct KdcReqBody {
422 /// Flags that the client wants set on the tickets as well as other
423 /// information that is to modify the behavior of the KDC.
424 #[rasn(tag(explicit(0)))]
425 pub kdc_options: KdcOptions,
426 /// The name part of the client's principal identifier.
427 #[rasn(tag(explicit(1)))]
428 pub cname: Option<PrincipalName>,
429 /// This field specifies the realm part of the server's principal
430 /// identifier. In the AS exchange, this is also the realm part of the
431 /// client's principal identifier.
432 #[rasn(tag(explicit(2)))]
433 pub realm: Realm,
434 /// All components of the name part of the server's identity, including
435 /// those parts that identify a specific instance of a service.
436 ///
437 /// May only be absent when the [KdcOptions::enc_tkt_in_skey] option is
438 /// specified. If the sname is absent, the name of the server is taken from
439 /// the name of the client in the ticket passed as `additional_tickets`.
440 #[rasn(tag(explicit(3)))]
441 pub sname: Option<PrincipalName>,
442 /// Included in the [AsReq] and [TgsReq] ticket requests when the requested
443 /// ticket is to be postdated. It specifies the desired starttime for the
444 /// requested ticket. If this field is omitted, then the KDC should use the
445 /// current time instead.
446 #[rasn(tag(explicit(4)))]
447 pub from: Option<KerberosTime>,
448 /// the expiration date requested by the client in a ticket request. It is
449 /// not optional, but if the requested endtime is "19700101000000Z", the
450 /// requested ticket is to have the maximum endtime permitted according to
451 /// KDC policy.
452 #[rasn(tag(explicit(5)))]
453 pub till: KerberosTime,
454 /// If present, the requested renew-till time sent from a client to the KDC
455 /// in a ticket request.
456 #[rasn(tag(explicit(6)))]
457 pub rtime: Option<KerberosTime>,
458 /// A random number generated by the client. If the same number is included
459 /// in the encrypted response from the KDC, it provides evidence that the
460 /// response is fresh and has not been replayed by an attacker. Nonces must
461 /// never be reused.
462 #[rasn(tag(explicit(7)))]
463 pub nonce: u32,
464 /// The desired encryption algorithm(s) to be used in the response.
465 #[rasn(tag(explicit(8)))]
466 pub etype: SequenceOf<i32>,
467 /// The addresses from which the requested ticket is to be valid. Normally
468 /// it includes the addresses for the client's host. If a proxy is
469 /// requested, this field will contain other addresses. The contents of
470 /// this field are usually copied by the KDC into the `caddr` field of the
471 /// resulting ticket.
472 ///
473 /// included in the initial request for tickets, and it is optionally
474 /// included in requests for additional tickets from the
475 /// ticket-granting server.
476 #[rasn(tag(explicit(9)))]
477 pub addresses: Option<HostAddresses>,
478 /// If present (and it can only be present in the [TgsReq] form), is an
479 /// encoding of the desired `authorization_data` encrypted under the
480 /// `subkey` key if present in the [Authenticator], or alternatively from
481 /// the session key in the TGT (both the Authenticator and TGT come from the
482 /// `padata` field in the [TgsReq]). The key usage value used when
483 /// encrypting is `5` if a `subkey` key is used, or `4` if the session key
484 /// is used.
485 #[rasn(tag(explicit(10)))]
486 pub enc_authorization_data: Option<EncryptedData>,
487 /// Additional tickets included in the request.
488 #[rasn(tag(explicit(11)))]
489 pub additional_tickets: Option<SequenceOf<Ticket>>,
490}
491
492#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
493#[rasn(delegate)]
494pub struct KdcOptions(pub KerberosFlags);
495
496impl KdcOptions {
497 /// Reserved for future expansion of this field.
498 pub fn reserved() -> Self {
499 Self(KerberosFlags::from_element(0))
500 }
501
502 /// Indicates that the ticket to be issued is to have its forwardable flag
503 /// set. It may only be set on the initial request, or in a subsequent
504 /// request if the TGT on which it is based is also forwardable.
505 pub fn forwardable() -> Self {
506 Self(KerberosFlags::from_element(1))
507 }
508
509 /// Indicates that this is a request for forwarding. The address(es) of the
510 /// host from which the resulting ticket is to be valid are included in the
511 /// addresses field of the request.
512 pub fn forwarded() -> Self {
513 Self(KerberosFlags::from_element(2))
514 }
515
516 /// Indicates that the ticket to be issued is to have its proxiable flag
517 /// set. It may only be set on the initial request, or a subsequent request
518 /// if the TGT on which it is based is also proxiable.
519 pub fn proxiable() -> Self {
520 Self(KerberosFlags::from_element(4))
521 }
522
523 /// Indicates that this is a request for a proxy. This option will only be
524 /// honored if the TGT in the request has its PROXIABLE bit set. The
525 /// address(es) of the host from which the resulting ticket is to be valid
526 /// are included in the addresses field of the request.
527 pub fn proxy() -> Self {
528 Self(KerberosFlags::from_element(0x8))
529 }
530
531 /// Indicates that the ticket to be issued is to have its MAY-POSTDATE flag
532 /// set. It may only be set on the initial request, or in a subsequent
533 /// request if the TGT on which it is based also has its MAY-POSTDATE flag set.
534 pub fn allow_postdate() -> Self {
535 Self(KerberosFlags::from_element(0x10))
536 }
537
538 /// Indicates that this is a request for a postdated ticket. This option
539 /// will only be honored if the TGT on which it is based has its
540 /// [TicketFlags::may_postdate] flag set. The resulting ticket will also
541 /// have its INVALID flag set, and that flag may be reset by a subsequent
542 /// request to the KDC after the starttime in the ticket has been reached.
543 pub fn postdated() -> Self {
544 Self(KerberosFlags::from_element(0x20))
545 }
546
547 /// Indicates that the ticket to be issued is to have its RENEWABLE flag set.
548 /// It may only be set on the initial request, or when the TGT on which the
549 /// request is based is also renewable. If this option is requested, then
550 /// the `rtime` field in the request contains the desired absolute
551 /// expiration time for the ticket.
552 pub fn renewable() -> Self {
553 Self(KerberosFlags::from_element(0x80))
554 }
555
556 pub fn opt_hardware_auth() -> Self {
557 Self(KerberosFlags::from_slice(&[0x4, 00]))
558 }
559
560 /// Indicates checking of the transited field is disabled. Tickets issued
561 /// without the performance of this check will be noted by the reset (0)
562 /// value of the [TicketFlags::transited_policy_checked] flag, indicating to
563 /// the application server that the transited field must be checked locally.
564 /// KDCs are encouraged but not required to honor the
565 /// [Self::disable_transited_check] option.
566 pub fn disable_transited_check() -> Self {
567 Self(KerberosFlags::from_slice(&[0x4, 00, 00, 00]))
568 }
569
570 /// Indicates that a renewable ticket will be acceptable if a ticket with
571 /// the requested life cannot otherwise be provided, in which case a
572 /// renewable ticket may be issued with a `renew_till` equal to the
573 /// requested endtime. The value of the renew-till field may still be
574 /// limited by local limits, or limits selected by the individual principal
575 /// or server.
576 pub fn renewable_ok() -> Self {
577 Self(KerberosFlags::from_slice(&[0x8, 00, 00, 00]))
578 }
579
580 /// Indicates that the ticket for the end server is to be encrypted in the
581 /// session key from the additional TGT provided.
582 pub fn enc_tkt_in_skey() -> Self {
583 Self(KerberosFlags::from_slice(&[0x10, 00, 00, 00]))
584 }
585
586 /// Indicates that the present request is for a renewal. The ticket provided
587 /// is encrypted in the secret key for the server on which it is valid. This
588 /// option will only be honored if the ticket to be renewed has its
589 /// [TicketFlags::renewable] flag set and if the time in its `renew_till`
590 /// field has not passed. The ticket to be renewed is passed in the `padata`
591 /// field as part of the authentication header.
592 pub fn renew() -> Self {
593 Self(KerberosFlags::from_slice(&[0x40, 00, 00, 00]))
594 }
595
596 /// Indicates that the request is to validate a postdated ticket. It will
597 /// only be honored if the ticket presented is postdated, presently has its
598 /// [TicketFlags::invalid] flag set, and would otherwise be usable at this
599 /// time. A ticket cannot be validated before its `start_time`. The ticket
600 /// presented for validation is encrypted in the key of the server for which
601 /// it is valid and is passed in the `padata` field as part of the
602 /// authentication header.
603 pub fn validate() -> Self {
604 Self(KerberosFlags::from_slice(&[0x80, 00, 00, 00]))
605 }
606}
607
608/// The initial KDC response.
609#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
610#[rasn(tag(explicit(application, 11)), delegate)]
611pub struct AsRep(pub KdcRep);
612
613/// Subsequent KDC response.
614#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
615#[rasn(tag(explicit(application, 13)), delegate)]
616pub struct TgsRep(pub KdcRep);
617
618/// The main KDC body.
619#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
620pub struct KdcRep {
621 /// The protocol version number.
622 #[rasn(tag(explicit(0)))]
623 pub pvno: Integer,
624 /// The type of a protocol message. It will almost always be the same as
625 /// the application identifier associated with a message. It is included to
626 /// make the identifier more readily accessible to the application.
627 #[rasn(tag(explicit(1)))]
628 pub msg_type: Integer,
629 /// Pre-authentication data.
630 #[rasn(tag(explicit(2)))]
631 pub padata: Option<SequenceOf<PaData>>,
632 /// The name of the realm in which the client is registered and in which
633 /// initial authentication took place.
634 #[rasn(tag(explicit(3)))]
635 pub crealm: Realm,
636 /// The name part of the client's principal identifier.
637 #[rasn(tag(explicit(4)))]
638 pub cname: PrincipalName,
639 /// The newly-issued ticket.
640 #[rasn(tag(explicit(5)))]
641 pub ticket: Ticket,
642 /// the encrypted part of the message follows each appearance of this field.
643 /// The key usage value for encrypting this field is 3 in an [AsRep]
644 /// message, using the client's long-term key or another key selected via
645 /// pre-authentication mechanisms. In a TgsRep message, the key usage value
646 /// is 8 if the TGS session key is used, or 9 if a TGS authenticator subkey
647 /// is used.
648 #[rasn(tag(explicit(6)))]
649 pub enc_part: EncryptedData,
650}
651
652/// The encrypted initial request.
653#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
654#[rasn(tag(explicit(application, 25)), delegate)]
655pub struct EncAsRepPart(pub EncKdcRepPart);
656
657/// The encrypted subsequent request.
658#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
659#[rasn(tag(explicit(application, 26)), delegate)]
660pub struct EncTgsRepPart(pub EncKdcRepPart);
661
662/// The encrypted part of the [KdcRep] body.
663#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
664pub struct EncKdcRepPart {
665 /// Used to pass the session key from Kerberos to the application server and
666 /// the client.
667 #[rasn(tag(explicit(0)))]
668 pub key: EncryptionKey,
669 /// The time(s) of the last request by a principal.
670 ///
671 /// Depending on what information is available, this might be the last time
672 /// that a request for a TGT was made, or the last time that a request based
673 /// on a TGT was successful. It also might cover all servers for a realm, or
674 /// just the particular server. Some implementations MAY display this
675 /// information to the user to aid in discovering unauthorized use of one's
676 /// identity. It is similar in spirit to the last login time displayed when
677 /// logging in to timesharing systems.
678 #[rasn(tag(explicit(1)))]
679 pub last_req: LastReq,
680 /// A random number generated by the client. If the same number is included
681 /// in the encrypted response from the KDC, it provides evidence that the
682 /// response is fresh and has not been replayed by an attacker. Nonces must
683 /// never be reused.
684 #[rasn(tag(explicit(2)))]
685 pub nonce: u32,
686 #[rasn(tag(explicit(3)))]
687 /// The time that the client's secret key is due to expire.
688 pub key_expiration: Option<KerberosTime>,
689 /// Options that were used or requested when the ticket was issued.
690 #[rasn(tag(explicit(4)))]
691 pub flags: TicketFlags,
692 /// The time of initial authentication for the named principal. It
693 /// is the time of issue for the original ticket on which this ticket is
694 /// based.
695 ///
696 /// It is included in the ticket to provide additional information to the
697 /// end service, and to provide the necessary information for implementation
698 /// of a "hot list" service at the KDC. An end service that is particularly
699 /// paranoid could refuse to accept tickets for which the initial
700 /// authentication occurred "too far" in the past.
701 #[rasn(tag(explicit(5)))]
702 pub auth_time: KerberosTime,
703 /// The time after which the ticket is valid. Together with `end_time`, this
704 /// field specifies the life of the ticket. If the `start_time` field is
705 /// absent from the ticket, then the `auth_time` field should be used in its
706 /// place to determine the life of the ticket.
707 #[rasn(tag(explicit(6)))]
708 pub start_time: Option<KerberosTime>,
709 /// The time after which the ticket will not be honored (its expiration
710 /// time). Note that individual services may place their own limits on the
711 /// life of a ticket and MAY reject tickets which have not yet expired. As
712 /// such, this is really an upper bound on the expiration time for
713 /// the ticket.
714 #[rasn(tag(explicit(7)))]
715 pub end_time: KerberosTime,
716 /// The maximum `end_time` that may be included in a renewal. It can be
717 /// thought of as the absolute expiration time for the ticket, including
718 /// all renewals.
719 ///
720 /// Only present in tickets that have the [TicketFlags::renewable] flag set
721 /// in the flags field.
722 #[rasn(tag(explicit(8)))]
723 pub renew_till: Option<KerberosTime>,
724 /// The realm part of the server's principal identifier.
725 #[rasn(tag(explicit(9)))]
726 pub srealm: Realm,
727 /// All components of the name part of the server's identity, including
728 /// those parts that identify a specific instance of a service.
729 #[rasn(tag(explicit(10)))]
730 pub sname: PrincipalName,
731 /// Addresses from which the ticket can be used.
732 ///
733 /// If there are no addresses, the ticket can be used from any location. The
734 /// decision by the KDC to issue or by the end server to accept addressless
735 /// tickets is a policy decision and is left to the Kerberos and end-service
736 /// administrators; they may refuse to issue or accept such tickets. Because
737 /// of the wide deployment of network address translation, it is recommended
738 /// that policy allow the issue and acceptance of such tickets.
739 #[rasn(tag(explicit(11)))]
740 pub caddr: Option<HostAddresses>,
741 #[rasn(tag(explicit(12)))]
742 pub encrypted_pa_data: Option<SequenceOf<PaData>>,
743}
744
745/// The time of the last request.
746#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
747pub struct LastReqValue {
748 /// How the `value` field is to be interpreted.
749 ///
750 /// Negative values indicate that the information pertains only to the
751 /// responding server. Non-negative values pertain to all servers for
752 /// the realm.
753 ///
754 /// - `0` — No information is conveyed by `value`.
755 /// - `1` — `value` is the time of last initial request for a TGT.
756 /// - `2` — `value ` is the time of last initial request.
757 /// - `3` — `value` is the time of issue for the newest TGT used.
758 /// - `4` — `value` is the time of the last renewal.
759 /// - `5` — `value` is the time of last request (of any type).
760 /// - `6` — `value` is the time when the password will expire.
761 /// - `7`, then `value` is the time when the account will expire.
762 #[rasn(tag(explicit(0)))]
763 pub r#type: i32,
764 /// The time of the last request, defined by `type`.
765 #[rasn(tag(explicit(1)))]
766 pub value: KerberosTime,
767}
768
769#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
770#[rasn(tag(explicit(application, 14)))]
771pub struct ApReq {
772 /// The protocol version number.
773 #[rasn(tag(explicit(0)))]
774 pub pvno: Integer,
775 /// The type of a protocol message. It will almost always be the same as
776 /// the application identifier associated with a message. It is included to
777 /// make the identifier more readily accessible to the application.
778 #[rasn(tag(explicit(1)))]
779 pub msg_type: Integer,
780 /// Options for the request.
781 #[rasn(tag(explicit(2)))]
782 pub ap_options: ApOptions,
783 /// Ticket authenticating the client to the server.
784 #[rasn(tag(explicit(3)))]
785 pub ticket: Ticket,
786 /// The encrypted [Authenticator], which includes the client's choice of
787 /// a subkey.
788 #[rasn(tag(explicit(4)))]
789 pub authenticator: EncryptedData,
790}
791
792/// Options for [ApReq].
793#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
794#[rasn(delegate)]
795pub struct ApOptions(pub KerberosFlags);
796
797impl ApOptions {
798 /// Reserved for future expansion.
799 pub fn reserved() -> Self {
800 Self(KerberosFlags::from_element(0))
801 }
802
803 /// Indicates that the ticket the client is presenting to a server is
804 /// encrypted in the session key from the server's TGT. When this option is
805 /// not specified, the ticket is encrypted in the server's secret key.
806 pub fn use_session_key() -> Self {
807 Self(KerberosFlags::from_element(1))
808 }
809
810 /// Indicates that the client requires mutual authentication, and that it
811 /// must respond with a [ApRep] message.
812 pub fn mutual_required() -> Self {
813 Self(KerberosFlags::from_element(2))
814 }
815}
816
817/// The authenticator included in the [ApReq].
818///
819/// Tt certifies to a server that the sender has recent knowledge of the encryption key in the accompanying
820/// ticket, to help the server detect replays. It also assists in the selection
821/// of a "true session key" to use with the particular session.
822#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
823#[rasn(tag(explicit(application, 2)))]
824pub struct Authenticator {
825 /// The version number for the format of the authenticator.
826 #[rasn(tag(explicit(0)))]
827 pub authenticator_vno: Integer,
828 /// The name of the realm in which the client is registered and in which
829 /// initial authentication took place.
830 #[rasn(tag(explicit(1)))]
831 pub crealm: Realm,
832 /// The name part of the client's principal identifier.
833 #[rasn(tag(explicit(2)))]
834 pub cname: PrincipalName,
835 /// Contains a checksum of the application data that accompanies the
836 /// [ApReq], computed using a key usage value of `10` in normal application
837 /// exchanges, or `6` when used in the [TgsReq] `padata`.
838 #[rasn(tag(explicit(3)))]
839 pub cksum: Option<Checksum>,
840 /// The microsecond part of the client's timestamp. Its value (before
841 /// encryption) ranges from 0 to 999999. It often appears along with
842 /// `ctime`. The two fields are used together to specify a reasonably
843 /// accurate timestamp.
844 #[rasn(tag(explicit(4)))]
845 pub cusec: Microseconds,
846 /// Contains the current time on the client's host.
847 #[rasn(tag(explicit(5)))]
848 pub ctime: KerberosTime,
849 /// Contains the client's choice for an encryption key to be used to protect
850 /// this specific application session. Unless an application specifies
851 /// otherwise, if this field is left out, the session key from the ticket
852 /// will be used.
853 #[rasn(tag(explicit(6)))]
854 pub subkey: Option<EncryptionKey>,
855 /// The initial sequence number to be used by the [KrbPriv] or [KrbSafe]
856 /// messages when sequence numbers are used to detect replays.
857 #[rasn(tag(explicit(7)))]
858 pub seq_number: Option<u32>,
859 /// Restrictions on any authority obtained on the basis of authentication
860 /// using the ticket. It is possible for any principal in possession of
861 /// credentials to add entries to the authorization data field since these
862 /// entries further restrict what can be done with the ticket. Such
863 /// additions can be made by specifying the additional entries when a new
864 /// ticket is obtained during the TGS exchange, or they MAY be added during
865 /// chained delegation using the authorization data field of
866 /// the authenticator.
867 #[rasn(tag(explicit(8)))]
868 pub authorization_data: Option<AuthorizationData>,
869}
870
871#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
872#[rasn(tag(explicit(application, 15)))]
873pub struct ApRep {
874 /// The protocol version number.
875 #[rasn(tag(explicit(0)))]
876 pub pvno: Integer,
877 /// The type of a protocol message. It will almost always be the same as
878 /// the application identifier associated with a message. It is included to
879 /// make the identifier more readily accessible to the application.
880 #[rasn(tag(explicit(1)))]
881 pub msg_type: Integer,
882 /// The encrypted version of [EncApRepPart].
883 #[rasn(tag(explicit(2)))]
884 pub enc_part: EncryptedData,
885}
886
887/// The body of [ApRep].
888#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
889#[rasn(tag(explicit(application, 27)))]
890pub struct EncApRepPart {
891 /// Contains the current time on the client's host.
892 #[rasn(tag(explicit(0)))]
893 pub ctime: KerberosTime,
894 /// The microsecond part of the client's timestamp. Its value (before
895 /// encryption) ranges from 0 to 999999. It often appears along with
896 /// `ctime`. The two fields are used together to specify a reasonably
897 /// accurate timestamp.
898 #[rasn(tag(explicit(1)))]
899 pub cusec: Microseconds,
900 #[rasn(tag(explicit(2)))]
901 pub subkey: Option<EncryptionKey>,
902 /// The sequence number of the message.
903 #[rasn(tag(explicit(3)))]
904 pub seq_number: Option<u32>,
905}
906
907/// Message containing user data along with a collision-proof checksum keyed
908/// with the last encryption key negotiated via subkeys, or with the session key
909/// if no negotiation has occurred.
910#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
911#[rasn(tag(explicit(application, 20)))]
912pub struct KrbSafe {
913 /// The protocol version number.
914 #[rasn(tag(explicit(0)))]
915 pub pvno: Integer,
916 /// The type of a protocol message. It will almost always be the same as
917 /// the application identifier associated with a message. It is included to
918 /// make the identifier more readily accessible to the application.
919 #[rasn(tag(explicit(1)))]
920 pub msg_type: Integer,
921 /// The body of the message.
922 #[rasn(tag(explicit(2)))]
923 pub body: KrbSafeBody,
924 /// the checksum of the application data, computed with a key usage value
925 /// of `15`.
926 #[rasn(tag(explicit(3)))]
927 pub cksum: Checksum,
928}
929
930/// The body of [KrbSafe].
931#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
932pub struct KrbSafeBody {
933 /// Application-specific data that is being passed from the sender to the recipient.
934 #[rasn(tag(explicit(0)))]
935 pub user_data: OctetString,
936 /// The current time as known by the sender of the message.
937 ///
938 /// By checking the timestamp, the recipient of the message is able to make
939 /// sure that it was recently generated, and is not a replay.
940 #[rasn(tag(explicit(1)))]
941 pub timestamp: Option<KerberosTime>,
942 /// The microsecond part of the timestamp.
943 #[rasn(tag(explicit(2)))]
944 pub usec: Option<Microseconds>,
945 /// The sequence number of the message.
946 #[rasn(tag(explicit(3)))]
947 pub seq_number: Option<u32>,
948 #[rasn(tag(explicit(4)))]
949 pub s_address: HostAddress,
950 #[rasn(tag(explicit(5)))]
951 pub r_address: Option<HostAddress>,
952}
953
954#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
955#[rasn(tag(explicit(application, 21)))]
956pub struct KrbPriv {
957 /// The protocol version number.
958 #[rasn(tag(explicit(0)))]
959 pub pvno: Integer,
960 /// The type of a protocol message. It will almost always be the same as
961 /// the application identifier associated with a message. It is included to
962 /// make the identifier more readily accessible to the application.
963 #[rasn(tag(explicit(1)))]
964 pub msg_type: Integer,
965 /// The encrypted body of [KrbPriv].
966 #[rasn(tag(explicit(3)))]
967 pub enc_part: EncryptedData,
968}
969
970/// The body of [KrbPriv].
971#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
972#[rasn(tag(explicit(application, 28)))]
973pub struct EncKrbPrivPart {
974 /// Application-specific data that is being passed from the sender to the recipient.
975 #[rasn(tag(explicit(0)))]
976 pub user_data: OctetString,
977 /// The current time as known by the sender of the message.
978 ///
979 /// By checking the timestamp, the recipient of the message is able to make
980 /// sure that it was recently generated, and is not a replay.
981 #[rasn(tag(explicit(1)))]
982 pub timestamp: Option<KerberosTime>,
983 /// The microsecond part of the timestamp.
984 #[rasn(tag(explicit(2)))]
985 pub usec: Option<Microseconds>,
986 /// The sequence number of the message.
987 #[rasn(tag(explicit(3)))]
988 pub seq_number: Option<u32>,
989 /// The address in use by the sender of the message.
990 #[rasn(tag(explicit(4)))]
991 pub sender_address: HostAddress,
992 /// The address in use by the recipient of the message.
993 ///
994 /// It may be omitted for some uses (such as broadcast protocols), but the
995 /// recipient may arbitrarily reject such messages. This field, along with
996 /// `sender_address`, can be used to help detect messages that have been
997 /// incorrectly or maliciously delivered to the wrong recipient.
998 #[rasn(tag(explicit(5)))]
999 pub recipient_address: Option<HostAddress>,
1000}
1001
1002/// Message that can be used to send Kerberos credentials from one principal
1003/// to another.
1004#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1005#[rasn(tag(explicit(application, 22)))]
1006pub struct KrbCred {
1007 /// The protocol version number.
1008 #[rasn(tag(explicit(0)))]
1009 pub pvno: Integer,
1010 /// The type of a protocol message. It will almost always be the same as
1011 /// the application identifier associated with a message. It is included to
1012 /// make the identifier more readily accessible to the application.
1013 #[rasn(tag(explicit(1)))]
1014 pub msg_type: Integer,
1015 /// Tickets obtained from the KDC specifically for use by the
1016 /// intended recipient.
1017 #[rasn(tag(explicit(2)))]
1018 pub tickets: SequenceOf<Ticket>,
1019 /// The encrypted body of [EncKrbCredPart].
1020 #[rasn(tag(explicit(3)))]
1021 pub enc_part: EncryptedData,
1022}
1023
1024/// The body of [KrbCred].
1025#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1026#[rasn(tag(explicit(application, 29)))]
1027pub struct EncKrbCredPart {
1028 /// Sequence of tickets to be sent and information needed to use the
1029 /// tickets, including the session key from each.
1030 #[rasn(tag(explicit(0)))]
1031 pub ticket_info: SequenceOf<KrbCredInfo>,
1032 /// A random number generated by the client. If the same number is included
1033 /// in the encrypted response from the KDC, it provides evidence that the
1034 /// response is fresh and has not been replayed by an attacker. Nonces must
1035 /// never be reused.
1036 #[rasn(tag(explicit(1)))]
1037 pub nonce: Option<u32>,
1038 /// The current time as known by the sender of the message.
1039 ///
1040 /// By checking the timestamp, the recipient of the message is able to make
1041 /// sure that it was recently generated, and is not a replay.
1042 #[rasn(tag(explicit(2)))]
1043 pub timestamp: Option<KerberosTime>,
1044 /// The microsecond part of the timestamp.
1045 #[rasn(tag(explicit(3)))]
1046 pub usec: Option<Microseconds>,
1047 /// The address in use by the sender of the message.
1048 #[rasn(tag(explicit(4)))]
1049 pub sender_address: Option<HostAddress>,
1050 /// The address in use by the recipient of the message.
1051 #[rasn(tag(explicit(5)))]
1052 pub recipient_address: Option<HostAddress>,
1053}
1054
1055/// The tickets and information needed to use them in [KrbCred].
1056#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1057pub struct KrbCredInfo {
1058 /// The session key from the sender to the intended recipient.
1059 #[rasn(tag(explicit(0)))]
1060 pub key: EncryptionKey,
1061 /// The realm of the delegated principal identity.
1062 #[rasn(tag(explicit(1)))]
1063 pub prealm: Option<Realm>,
1064 /// The name of the delegated principal identity.
1065 #[rasn(tag(explicit(2)))]
1066 pub pname: Option<PrincipalName>,
1067 /// Options that were used or requested when the ticket was issued.
1068 #[rasn(tag(explicit(3)))]
1069 pub flags: Option<TicketFlags>,
1070 /// The time of initial authentication for the named principal. It
1071 /// is the time of issue for the original ticket on which this ticket is
1072 /// based.
1073 #[rasn(tag(explicit(4)))]
1074 pub auth_time: Option<KerberosTime>,
1075 /// The time after which the ticket is valid. Together with `end_time`, this
1076 /// field specifies the life of the ticket. If the `start_time` field is
1077 /// absent from the ticket, then the `auth_time` field should be used in its
1078 /// place to determine the life of the ticket.
1079 #[rasn(tag(explicit(5)))]
1080 pub start_time: Option<KerberosTime>,
1081 /// The time after which the ticket will not be honored (its expiration
1082 /// time). Note that individual services may place their own limits on the
1083 /// life of a ticket and MAY reject tickets which have not yet expired. As
1084 /// such, this is really an upper bound on the expiration time for
1085 /// the ticket.
1086 #[rasn(tag(explicit(6)))]
1087 pub end_time: Option<KerberosTime>,
1088 /// The maximum `end_time` that may be included in a renewal. It can be
1089 /// thought of as the absolute expiration time for the ticket, including
1090 /// all renewals.
1091 #[rasn(tag(explicit(7)))]
1092 pub renew_till: Option<KerberosTime>,
1093 /// The realm part of the server's principal identifier.
1094 #[rasn(tag(explicit(8)))]
1095 pub srealm: Option<Realm>,
1096 /// All components of the name part of the server's identity, including
1097 /// those parts that identify a specific instance of a service.
1098 #[rasn(tag(explicit(9)))]
1099 pub sname: Option<PrincipalName>,
1100 /// Addresses from which the ticket can be used.
1101 #[rasn(tag(explicit(10)))]
1102 pub caddr: Option<HostAddresses>,
1103}
1104
1105/// An error from Kerberos.
1106#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1107#[rasn(tag(explicit(application, 30)))]
1108pub struct KrbError {
1109 /// The protocol version number.
1110 #[rasn(tag(explicit(0)))]
1111 pub pvno: Integer,
1112 /// The type of a protocol message. It will almost always be the same as
1113 /// the application identifier associated with a message. It is included to
1114 /// make the identifier more readily accessible to the application.
1115 #[rasn(tag(explicit(1)))]
1116 pub msg_type: Integer,
1117 /// Contains the current time on the client's host.
1118 #[rasn(tag(explicit(2)))]
1119 pub ctime: Option<KerberosTime>,
1120 /// The microsecond part of the client's timestamp. Its value (before
1121 /// encryption) ranges from 0 to 999999. It often appears along with
1122 /// `ctime`. The two fields are used together to specify a reasonably
1123 /// accurate timestamp.
1124 #[rasn(tag(explicit(3)))]
1125 pub cusec: Option<Microseconds>,
1126 /// The current time on the server.
1127 #[rasn(tag(explicit(4)))]
1128 pub stime: KerberosTime,
1129 /// The microsecond part of the server's timestamp.
1130 #[rasn(tag(explicit(5)))]
1131 pub susec: Microseconds,
1132 /// The error code returned by Kerberos or the server when a request fails.
1133 #[rasn(tag(explicit(6)))]
1134 pub error_code: i32,
1135 /// The name of the realm in which the client is registered and in which
1136 /// initial authentication took place.
1137 #[rasn(tag(explicit(7)))]
1138 pub crealm: Option<Realm>,
1139 /// The name part of the client's principal identifier.
1140 #[rasn(tag(explicit(8)))]
1141 pub cname: Option<PrincipalName>,
1142 /// The realm of the issuing principal.
1143 #[rasn(tag(explicit(9)))]
1144 pub realm: Realm,
1145 /// The name of the issuing principal.
1146 #[rasn(tag(explicit(10)))]
1147 pub sname: PrincipalName,
1148 /// Additional text to help explain the error code associated with the
1149 /// failed request.
1150 #[rasn(tag(explicit(11)))]
1151 pub e_text: Option<KerberosString>,
1152 /// Additional data about the error for use by the application to help it
1153 /// recover from or handle the error.
1154 #[rasn(tag(explicit(12)))]
1155 pub e_data: Option<OctetString>,
1156}
1157
1158pub type TypedData = SequenceOf<TypedDataItem>;
1159
1160#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1161pub struct TypedDataItem {
1162 #[rasn(tag(explicit(0)))]
1163 pub r#type: i32,
1164 #[rasn(tag(explicit(1)))]
1165 pub value: Option<OctetString>,
1166}
1167
1168#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1169pub struct PaEncTsEnc {
1170 #[rasn(tag(explicit(0)))]
1171 pub patimestamp: KerberosTime,
1172 #[rasn(tag(explicit(1)))]
1173 pub pausec: Option<Microseconds>,
1174}
1175
1176#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1177pub struct EtypeInfoEntry {
1178 #[rasn(tag(explicit(0)))]
1179 pub etype: i32,
1180 #[rasn(tag(explicit(1)))]
1181 pub salt: Option<OctetString>,
1182}
1183
1184#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1185pub struct EtypeInfo2Entry {
1186 #[rasn(tag(explicit(0)))]
1187 pub etype: i32,
1188 #[rasn(tag(explicit(1)))]
1189 pub salt: Option<KerberosString>,
1190 #[rasn(tag(explicit(2)))]
1191 pub s2kparams: Option<OctetString>,
1192}
1193
1194/// Provides a means for Kerberos principal credentials to embed within
1195/// themselves privilege attributes and other mechanisms for positive
1196/// authorization.
1197///
1198/// This amplifies the privileges of the principal beyond what can be
1199/// done using credentials without such an a-data element.
1200#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1201pub struct AdKdcIssued {
1202 /// A cryptographic checksum computed over the DER encoding of the
1203 /// [AuthorizationData] in the `elements` field, keyed with the session key.
1204 /// Its checksumtype is the mandatory checksum type for the encryption type
1205 /// of the session key, and its key usage value is `19`.
1206 #[rasn(tag(explicit(0)))]
1207 pub ad_checksum: Checksum,
1208 /// The realm of the issuing principal if different from that of the
1209 /// KDC itself.
1210 #[rasn(tag(explicit(1)))]
1211 pub realm: Option<Realm>,
1212 /// The name of the issuing principal if different from that of the
1213 /// KDC itself.
1214 #[rasn(tag(explicit(2)))]
1215 pub sname: Option<PrincipalName>,
1216 /// A sequence of authorization data elements issued by the KDC.
1217 #[rasn(tag(explicit(3)))]
1218 pub elements: AuthorizationData,
1219}
1220
1221/// Used to implement an "or" operation by setting the condition-count field to
1222/// `1`, and it may specify an "and" operation by setting the condition count to
1223/// the number of embedded elements.
1224///
1225/// Application servers that do not implement
1226/// this element MUST reject tickets that contain authorization data elements of
1227/// this type.
1228#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1229pub struct AdAndOr {
1230 /// The number elements required to be satisfied.
1231 #[rasn(tag(explicit(0)))]
1232 pub condition_count: i32,
1233 /// The authorization elements.
1234 #[rasn(tag(explicit(1)))]
1235 pub elements: AuthorizationData,
1236}
1237
1238#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1239pub struct AdCammac {
1240 #[rasn(tag(explicit(0)))]
1241 pub elements: AuthorizationData,
1242 #[rasn(tag(explicit(1)))]
1243 pub kdc_verifier: Option<VerifierMac>,
1244 #[rasn(tag(explicit(2)))]
1245 pub svc_verifier: Option<VerifierMac>,
1246 #[rasn(tag(explicit(3)))]
1247 pub other_verifiers: SequenceOf<Verifier>,
1248}
1249
1250#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1251#[non_exhaustive]
1252#[rasn(choice)]
1253pub enum Verifier {
1254 Mac(VerifierMac),
1255}
1256
1257#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1258pub struct VerifierMac {
1259 #[rasn(tag(explicit(0)))]
1260 pub identifier: Option<PrincipalName>,
1261 #[rasn(tag(explicit(1)))]
1262 pub kvno: Option<u32>,
1263 #[rasn(tag(explicit(2)))]
1264 pub enctype: Option<i32>,
1265 #[rasn(tag(explicit(3)))]
1266 pub mac: Checksum,
1267}
1268
1269#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
1270#[non_exhaustive]
1271pub struct AdLoginAlias {
1272 #[rasn(tag(explicit(0)))]
1273 pub login_aliases: SequenceOf<PrincipalName>,
1274}
1275
1276impl AdLoginAlias {
1277 pub fn new(login_aliases: SequenceOf<PrincipalName>) -> Self {
1278 Self { login_aliases }
1279 }
1280}