Skip to content

Commit 31ce6c5

Browse files
committed
Added decryption of TGT-REP Tickets.
1 parent 0c19abd commit 31ce6c5

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

NtApiDotNet/Win32/Security/Authentication/Kerberos/KerberosTGTReplyAuthenticationToken.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// limitations under the License.
1414

1515
using NtApiDotNet.Utilities.ASN1;
16+
using System.Collections.Generic;
1617
using System.IO;
18+
using System.Linq;
1719
using System.Text;
1820

1921
namespace NtApiDotNet.Win32.Security.Authentication.Kerberos
@@ -45,6 +47,30 @@ public override string Format()
4547
return builder.ToString();
4648
}
4749

50+
/// <summary>
51+
/// Decrypt the Authentication Token using a keyset.
52+
/// </summary>
53+
/// <param name="keyset">The set of keys to decrypt the </param>
54+
/// <returns>The decrypted token, or the same token if nothing could be decrypted.</returns>
55+
public override AuthenticationToken Decrypt(IEnumerable<AuthenticationKey> keyset)
56+
{
57+
KerberosEncryptedData authenticator = null;
58+
59+
KerberosKeySet tmp_keys = new KerberosKeySet(keyset.OfType<KerberosAuthenticationKey>());
60+
if (!Ticket.Decrypt(tmp_keys, KeyUsage.AsRepTgsRepTicket, out KerberosTicket ticket))
61+
{
62+
ticket = null;
63+
}
64+
65+
if (ticket != null || authenticator != null)
66+
{
67+
var ret = (KerberosTGTReplyAuthenticationToken)MemberwiseClone();
68+
ret.Ticket = ticket ?? ret.Ticket;
69+
return ret;
70+
}
71+
return base.Decrypt(keyset);
72+
}
73+
4874
#region Internal Static Methods
4975
/// <summary>
5076
/// Try and parse data into an ASN1 authentication token.

NtApiDotNet/Win32/Security/Authentication/Kerberos/KerberosTransitedEncoding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal static KerberosTransitedEncoding Parse(DERValue value)
7676
}
7777
}
7878

79-
if (type == 0 || data == null)
79+
if (data == null)
8080
throw new InvalidDataException();
8181
return new KerberosTransitedEncoding(type, data);
8282
}

0 commit comments

Comments
 (0)