Пример #1
0
        public static KrbApReq CreateApReq(
            KrbKdcRep tgsRep,
            KerberosKey authenticatorKey,
            ApOptions options,
            out KrbAuthenticator authenticator
            )
        {
            var ticket = tgsRep.Ticket;

            authenticator = new KrbAuthenticator
            {
                CName          = tgsRep.CName,
                Realm          = ticket.Realm,
                SequenceNumber = KerberosConstants.GetNonce(),
                Subkey         = KrbEncryptionKey.Generate(authenticatorKey.EncryptionType),
                Checksum       = KrbChecksum.EncodeDelegationChecksum(new DelegationInfo())
            };

            KerberosConstants.Now(out authenticator.CTime, out authenticator.CuSec);

            var apReq = new KrbApReq
            {
                Ticket        = ticket,
                ApOptions     = options,
                Authenticator = KrbEncryptedData.Encrypt(
                    authenticator.EncodeApplication(),
                    authenticatorKey,
                    KeyUsage.ApReqAuthenticator
                    )
            };

            return(apReq);
        }
Пример #2
0
        private static KrbApReq CreateApReq(KrbKdcRep kdcRep, KrbEncryptionKey tgtSessionKey, KrbChecksum checksum, out KrbEncryptionKey sessionKey)
        {
            var tgt = kdcRep.Ticket;

            var authenticator = new KrbAuthenticator
            {
                CName          = kdcRep.CName,
                Realm          = kdcRep.CRealm,
                SequenceNumber = KerberosConstants.GetNonce(),
                Checksum       = checksum
            };

            sessionKey           = KrbEncryptionKey.Generate(tgtSessionKey.EType);
            sessionKey.Usage     = KeyUsage.EncTgsRepPartSubSessionKey;
            authenticator.Subkey = sessionKey;

            KerberosConstants.Now(out authenticator.CTime, out authenticator.CuSec);

            var encryptedAuthenticator = KrbEncryptedData.Encrypt(
                authenticator.EncodeApplication(),
                tgtSessionKey.AsKey(),
                KeyUsage.PaTgsReqAuthenticator
                );

            var apReq = new KrbApReq
            {
                Ticket        = tgt,
                Authenticator = encryptedAuthenticator
            };

            return(apReq);
        }
Пример #3
0
        public static KrbApReq CreateApReq(KrbKdcRep tgsRep, KerberosKey authenticatorKey, ApOptions options)
        {
            var ticket = tgsRep.Ticket;

            KerberosConstants.Now(out DateTimeOffset time, out int usec);

            var authenticator = new KrbAuthenticator
            {
                CName                      = tgsRep.CName,
                CTime                      = time,
                Cusec                      = usec,
                Realm                      = ticket.Realm,
                SequenceNumber             = KerberosConstants.GetNonce(),
                Subkey                     = null,
                AuthenticatorVersionNumber = 5
            };

            var apReq = new KrbApReq
            {
                Ticket        = ticket,
                ApOptions     = options,
                Authenticator = KrbEncryptedData.Encrypt(
                    authenticator.EncodeApplication(),
                    authenticatorKey,
                    KeyUsage.ApReqAuthenticator
                    )
            };

            return(apReq);
        }
Пример #4
0
        private static KrbApReq CreateApReq(KrbKdcRep kdcRep, KrbEncryptionKey tgtSessionKey)
        {
            var tgt = kdcRep.Ticket;

            KerberosConstants.Now(out DateTimeOffset time, out int usec);

            var authenticator = new KrbAuthenticator
            {
                CName                      = kdcRep.CName,
                CTime                      = time,
                Cusec                      = usec,
                Realm                      = tgt.Realm,
                SequenceNumber             = KerberosConstants.GetNonce(),
                Subkey                     = tgtSessionKey,
                AuthenticatorVersionNumber = 5
            };

            var encryptedAuthenticator = KrbEncryptedData.Encrypt(
                authenticator.EncodeApplication(),
                tgtSessionKey.AsKey(),
                KeyUsage.PaTgsReqAuthenticator
                );

            var apReq = new KrbApReq
            {
                Ticket        = tgt,
                Authenticator = encryptedAuthenticator
            };

            return(apReq);
        }
Пример #5
0
        public static KrbApReq CreateApReq(
            KrbKdcRep tgsRep,
            KerberosKey authenticatorKey,
            RequestServiceTicket rst,
            out KrbAuthenticator authenticator
            )
        {
            if (tgsRep == null)
            {
                throw new ArgumentNullException(nameof(tgsRep));
            }

            if (authenticatorKey == null)
            {
                throw new ArgumentNullException(nameof(authenticatorKey));
            }

            var ticket = tgsRep.Ticket;

            authenticator = new KrbAuthenticator
            {
                CName          = tgsRep.CName,
                Realm          = ticket.Realm,
                SequenceNumber = KerberosConstants.GetNonce(),
                Subkey         = KrbEncryptionKey.Generate(authenticatorKey.EncryptionType),
                Checksum       = KrbChecksum.EncodeDelegationChecksum(new DelegationInfo(rst))
            };

            KerberosConstants.Now(out DateTimeOffset ctime, out int usec);

            authenticator.CTime = ctime;
            authenticator.CuSec = usec;

            var apReq = new KrbApReq
            {
                Ticket        = ticket,
                ApOptions     = rst.ApOptions,
                Authenticator = KrbEncryptedData.Encrypt(
                    authenticator.EncodeApplication(),
                    authenticatorKey,
                    KeyUsage.ApReqAuthenticator
                    )
            };

            return(apReq);
        }
Пример #6
0
        public static KrbApReq CreateApReq(
            KrbKdcRep tgsRep,
            KerberosKey authenticatorKey,
            RequestServiceTicket rst,
            out KrbAuthenticator authenticator
            )
        {
            if (tgsRep == null)
            {
                throw new ArgumentNullException(nameof(tgsRep));
            }

            if (authenticatorKey == null)
            {
                throw new ArgumentNullException(nameof(authenticatorKey));
            }

            authenticator = new KrbAuthenticator
            {
                CName = tgsRep.CName,
                Realm = tgsRep.CRealm
            };

            if (rst.AuthenticatorChecksum != null)
            {
                authenticator.Checksum = rst.AuthenticatorChecksum;
            }
            else if (!rst.AuthenticatorChecksumSource.IsEmpty)
            {
                authenticator.Checksum = KrbChecksum.Create(
                    rst.AuthenticatorChecksumSource,
                    authenticatorKey,
                    KeyUsage.AuthenticatorChecksum
                    );
            }
            else if (rst.GssContextFlags != GssContextEstablishmentFlag.GSS_C_NONE)
            {
                authenticator.Checksum = KrbChecksum.EncodeDelegationChecksum(new DelegationInfo(rst));
            }

            if (rst.IncludeSequenceNumber ?? true)
            {
                authenticator.SequenceNumber = GetNonce();
            }

            if (rst.ApOptions.HasFlag(ApOptions.MutualRequired))
            {
                authenticator.Subkey = KrbEncryptionKey.Generate(authenticatorKey.EncryptionType);
            }

            Now(out DateTimeOffset ctime, out int usec);

            authenticator.CTime = ctime;
            authenticator.CuSec = usec;

            var apReq = new KrbApReq
            {
                Ticket        = tgsRep.Ticket,
                ApOptions     = rst.ApOptions,
                Authenticator = KrbEncryptedData.Encrypt(
                    authenticator.EncodeApplication(),
                    authenticatorKey,
                    KeyUsage.ApReqAuthenticator
                    )
            };

            return(apReq);
        }