public void ParseFileRoundTrip()
        {
            var tmp   = Path.GetTempFileName();
            var cache = new Krb5TicketCache(tmp);

            try
            {
                Assert.IsNotNull(cache);

                cache.Add(new TicketCacheEntry
                {
                    Key   = "krbtgt/bar.com",
                    Value = new KerberosClientCacheEntry
                    {
                        KdcResponse = new KrbAsRep
                        {
                            CName  = KrbPrincipalName.FromString("*****@*****.**"),
                            CRealm = "bar.com",
                            Ticket = new KrbTicket
                            {
                                Realm         = "bar.com",
                                SName         = KrbPrincipalName.FromString("krbtgt/bar.com"),
                                EncryptedPart = new KrbEncryptedData
                                {
                                    EType  = EncryptionType.AES128_CTS_HMAC_SHA1_96,
                                    Cipher = Array.Empty <byte>()
                                }
                            }
                        },
                        SessionKey = KrbEncryptionKey.Generate(EncryptionType.AES128_CTS_HMAC_SHA1_96),
                        SName      = KrbPrincipalName.FromString("krbtgt/bar.com")
                    }
                });

                using (var secondCache = new Krb5TicketCache(tmp))
                {
                    var entry = secondCache.GetCacheItem <KerberosClientCacheEntry>("krbtgt/bar.com");

                    Assert.IsNotNull(entry.KdcResponse);
                    Assert.AreEqual("bar.com", entry.KdcResponse.CRealm);
                    Assert.AreEqual("*****@*****.**", entry.KdcResponse.CName.FullyQualifiedName);
                }
            }
            finally
            {
                cache.Dispose();

                if (File.Exists(tmp))
                {
                    File.Delete(tmp);
                }
            }
        }
Exemple #2
0
        public void ParseFileRoundTrip()
        {
            using (var tmp = new TemporaryFile())
                using (var cache = new Krb5TicketCache(tmp.File))
                {
                    Assert.IsNotNull(cache);

                    cache.Add(CreateCacheEntry());

                    using (var secondCache = new Krb5TicketCache(tmp.File))
                    {
                        var entry = secondCache.GetCacheItem <KerberosClientCacheEntry>("krbtgt/bar.com");

                        Assert.IsNotNull(entry.KdcResponse);
                        Assert.AreEqual("bar.com", entry.KdcResponse.CRealm);
                        Assert.AreEqual("*****@*****.**", entry.KdcResponse.CName.FullyQualifiedName);
                    }
                }
        }
Exemple #3
0
        public void CanConcurrentReadAndWriteCacheFile()
        {
            using (var tmp = new TemporaryFile())
            {
                Parallel.For(0, 1000, i =>
                {
                    using (var cache = new Krb5TicketCache(tmp.File))
                    {
                        var key = $"krbtgt/IPA-{i}.IDENTITYINTERVENTION.COM";

                        cache.Add(CreateCacheEntry(key));

                        var item = cache.GetCacheItem(key);

                        Assert.IsNotNull(item);
                    }
                });
            }
        }
Exemple #4
0
        public void Version3Roundtrips()
        {
            var key = $"krbtgt/IPA.IDENTITYINTERVENTION.COM";

            using (var tmp = new TemporaryFile())
            {
                using (var cache = new Krb5TicketCache(tmp.File)
                {
                    Version = 3
                })
                {
                    cache.Add(CreateCacheEntry(key));
                }

                using (var cache = new Krb5TicketCache(tmp.File))
                {
                    Assert.AreEqual(3, cache.Version);

                    var item = cache.GetCacheItem(key);

                    Assert.IsNotNull(item);
                }
            }
        }