-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathProgram.cs
81 lines (63 loc) · 2.13 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Kerberos.NET;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace KerbCrypto
{
class Program
{
// test files sourced from https://github.com/drankye/haox
// original Apache 2.0 license
private static readonly Dictionary<string, string> Files = new Dictionary<string, string> {
{ "rc4-kerberos-data", "rc4-key-data" },
{ "rc4-spnego-data", "rc4-key-data" },
{ "aes128-kerberos-data", "aes128-key-data" },
{ "aes128-spnego-data", "aes128-key-data" },
{ "aes256-kerberos-data", "aes256-key-data" },
{ "aes256-spnego-data", "aes256-key-data" }
};
static void Main(string[] args)
{
MainAsync().Wait();
}
private static async System.Threading.Tasks.Task MainAsync()
{
foreach (var f in Files)
{
var data = File.ReadAllBytes("data\\" + f.Key);
var key = File.ReadAllBytes("data\\" + f.Value);
W($"Decrypting {f.Key} with key {f.Value}", ConsoleColor.Green);
var validator = new KerberosValidator(key)
{
//Logger = W,
ValidateAfterDecrypt = ValidationActions.Replay
};
var authenticator = new KerberosAuthenticator(validator);
var result = await authenticator.Authenticate(data);
;
if (result == null)
{
throw new InvalidDataException("Could not decrypt token");
}
foreach (var c in result.Claims.OrderBy(c => c.Type))
{
W($"{c.Type}: {c.Value}");
}
W("");
;
}
;
}
private static void W(string w, ConsoleColor color)
{
Console.ForegroundColor = color;
W(w);
Console.ResetColor();
}
private static void W(string w)
{
Console.WriteLine(w);
}
}
}