Skip to content

Commit f0d7194

Browse files
author
Theo Dumitrescu (from Dev Box)
committed
removed channel bindings from KDC
1 parent 44d78f3 commit f0d7194

4 files changed

Lines changed: 6 additions & 207 deletions

File tree

Kerberos.NET/Server/KdcMessageHandlerBase.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ public abstract class KdcMessageHandlerBase
2525

2626
protected KdcServerOptions Options { get; }
2727

28-
/// <summary>
29-
/// Expected channel bindings for this request's TGS-REQ validation.
30-
/// </summary>
31-
public GssChannelBindings ExpectedChannelBindings { get; set; }
32-
33-
/// <summary>
34-
/// Accepts a raw SEC_CHANNEL_BINDINGS buffer
35-
/// and converts it to <see cref="ExpectedChannelBindings"/>.
36-
/// </summary>
37-
public void SetExpectedChannelBindingsFromSecChannelBindings(ReadOnlyMemory<byte> buffer)
38-
{
39-
this.ExpectedChannelBindings = GssChannelBindings.FromSecChannelBindings(buffer);
40-
}
41-
4228
protected IRealmService RealmService { get; private set; }
4329

4430
public IDictionary<PaDataType, PreAuthHandlerConstructor> PreAuthHandlers => this.preAuthHandlers;
@@ -117,10 +103,7 @@ public virtual async Task<ReadOnlyMemory<byte>> ExecuteAsync()
117103
{
118104
try
119105
{
120-
var context = new PreAuthenticationContext
121-
{
122-
ExpectedChannelBindings = this.ExpectedChannelBindings
123-
};
106+
var context = new PreAuthenticationContext();
124107

125108
this.DecodeMessage(context);
126109

@@ -144,10 +127,7 @@ public virtual ReadOnlyMemory<byte> Execute()
144127
{
145128
try
146129
{
147-
var context = new PreAuthenticationContext
148-
{
149-
ExpectedChannelBindings = this.ExpectedChannelBindings
150-
};
130+
var context = new PreAuthenticationContext();
151131

152132
this.DecodeMessage(context);
153133

Kerberos.NET/Server/PaDataTgsTicketHandler.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public PaDataTgsTicketHandler(IRealmService service)
1717
{
1818
}
1919

20-
public ValidationActions Validation { get; set; } = ValidationActions.All & ~ValidationActions.Replay;
20+
public ValidationActions Validation { get; set; } = ValidationActions.All & ~ValidationActions.Replay & ~ValidationActions.ChannelBinding;
2121

2222
/// <summary>
2323
/// Executes before the validation stage and can be used for initial decoding of the message.
@@ -39,7 +39,7 @@ public override void PreValidate(PreAuthenticationContext preauth)
3939

4040
var state = preauth.GetState<TgsState>(PaDataType.PA_TGS_REQ);
4141

42-
state.DecryptedApReq = this.DecryptApReq(state.ApReq, preauth.EvidenceTicketKey, preauth.ExpectedChannelBindings);
42+
state.DecryptedApReq = this.DecryptApReq(state.ApReq, preauth.EvidenceTicketKey);
4343
}
4444

4545
/// <summary>
@@ -101,7 +101,7 @@ public override KrbPaData Validate(KrbKdcReq asReq, PreAuthenticationContext con
101101

102102
var state = context.GetState<TgsState>(PaDataType.PA_TGS_REQ);
103103

104-
state.DecryptedApReq ??= this.DecryptApReq(state.ApReq, context.EvidenceTicketKey, context.ExpectedChannelBindings);
104+
state.DecryptedApReq ??= this.DecryptApReq(state.ApReq, context.EvidenceTicketKey);
105105

106106
context.EncryptedPartKey = state.DecryptedApReq.SessionKey;
107107
context.Ticket = state.DecryptedApReq.Ticket;
@@ -135,14 +135,12 @@ public static KrbApReq ExtractApReq(PreAuthenticationContext context)
135135
return state.ApReq;
136136
}
137137

138-
private DecryptedKrbApReq DecryptApReq(KrbApReq apReq, KerberosKey krbtgtKey, GssChannelBindings expectedChannelBindings)
138+
private DecryptedKrbApReq DecryptApReq(KrbApReq apReq, KerberosKey krbtgtKey)
139139
{
140140
var apReqDecrypted = new DecryptedKrbApReq(apReq, MessageType.KRB_TGS_REQ);
141141

142142
apReqDecrypted.Decrypt(krbtgtKey);
143143

144-
apReqDecrypted.ExpectedChannelBindings = expectedChannelBindings;
145-
146144
apReqDecrypted.Validate(this.Validation);
147145

148146
return apReqDecrypted;

Kerberos.NET/Server/PreAuthenticationContext.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ public class PreAuthenticationContext
9090
/// </summary>
9191
public bool? IncludePac { get; set; }
9292

93-
/// <summary>
94-
/// Expected channel bindings for AP-REQ validation during TGS-REQ processing.
95-
/// </summary>
96-
public GssChannelBindings ExpectedChannelBindings { get; set; }
97-
9893
/// <summary>
9994
/// Retrieve the current pre-authentication state for a particular PA-Data type.
10095
/// If the initial state is not present it will be created.

Tests/Tests.Kerberos.NET/Kdc/KdcHandlerTests.cs

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -495,179 +495,5 @@ public void AsReqPreAuth_PkinitCertificateAccessible()
495495
Assert.AreEqual(credCert.Thumbprint, clientCert.Thumbprint);
496496
}
497497
}
498-
499-
// -- TGS-REQ Channel Binding Tests --
500-
501-
private static readonly byte[] TgsTestChannelBinding = new byte[]
502-
{
503-
0x74, 0x6C, 0x73, 0x2D, 0x73, 0x65, 0x72, 0x76,
504-
0x65, 0x72, 0x2D, 0x65, 0x6E, 0x64, 0x2D, 0x70,
505-
0x6F, 0x69, 0x6E, 0x74, 0x3A, 0xAA, 0xBB, 0xCC,
506-
0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44
507-
};
508-
509-
[TestMethod]
510-
public void KdcTgsReq_ChannelBinding_MatchingBindings_Succeeds()
511-
{
512-
// Channel bindings used by client in TGS-REQ
513-
// The same channel bindings are expected by the server
514-
// thus should result in a successful TGS-REQ processing
515-
var bindings = new GssChannelBindings { ApplicationData = TgsTestChannelBinding };
516-
517-
KrbAsRep asRep = RequestTgt(cname: Upn, crealm: Realm, srealm: Realm, out KrbEncryptionKey tgtKey);
518-
519-
var tgsReq = KrbTgsReq.CreateTgsReq(
520-
new RequestServiceTicket
521-
{
522-
Realm = Realm,
523-
ServicePrincipalName = "host/foo." + Realm,
524-
ChannelBindings = bindings
525-
},
526-
tgtKey, asRep, out _);
527-
528-
var handler = new KdcTgsReqMessageHandler(tgsReq.EncodeApplication(), new KdcServerOptions
529-
{
530-
DefaultRealm = Realm,
531-
IsDebug = true,
532-
RealmLocator = realm => new FakeRealmService(realm)
533-
});
534-
535-
536-
handler.ExpectedChannelBindings = bindings;
537-
538-
var results = handler.Execute();
539-
540-
var tgsRep = KrbTgsRep.DecodeApplication(results);
541-
Assert.IsNotNull(tgsRep);
542-
}
543-
544-
[TestMethod]
545-
public void KdcTgsReq_ChannelBinding_Mismatch_ReturnsError()
546-
{
547-
// Channel bindings used by client in TGS-REQ
548-
// Different channel bindings are expected by the server
549-
// thus should result in an error
550-
var clientBindings = new GssChannelBindings { ApplicationData = TgsTestChannelBinding };
551-
var serverBindings = new GssChannelBindings { ApplicationData = new byte[] { 0xFF, 0xFE, 0xFD } };
552-
553-
KrbAsRep asRep = RequestTgt(cname: Upn, crealm: Realm, srealm: Realm, out KrbEncryptionKey tgtKey);
554-
555-
var tgsReq = KrbTgsReq.CreateTgsReq(
556-
new RequestServiceTicket
557-
{
558-
Realm = Realm,
559-
ServicePrincipalName = "host/foo." + Realm,
560-
ChannelBindings = clientBindings
561-
},
562-
tgtKey, asRep, out _);
563-
564-
var handler = new KdcTgsReqMessageHandler(tgsReq.EncodeApplication(), new KdcServerOptions
565-
{
566-
DefaultRealm = Realm,
567-
IsDebug = true,
568-
RealmLocator = realm => new FakeRealmService(realm)
569-
});
570-
571-
handler.ExpectedChannelBindings = serverBindings;
572-
573-
var results = handler.Execute();
574-
575-
var error = KrbError.DecodeApplication(results);
576-
Assert.AreEqual(KerberosErrorCode.KRB_ERR_GENERIC, error.ErrorCode);
577-
}
578-
579-
[TestMethod]
580-
public void KdcTgsReq_ChannelBinding_ServerExpectsNone_Succeeds()
581-
{
582-
// Channel bindings used by client in TGS-REQ
583-
var clientBindings = new GssChannelBindings { ApplicationData = TgsTestChannelBinding };
584-
585-
KrbAsRep asRep = RequestTgt(cname: Upn, crealm: Realm, srealm: Realm, out KrbEncryptionKey tgtKey);
586-
587-
var tgsReq = KrbTgsReq.CreateTgsReq(
588-
new RequestServiceTicket
589-
{
590-
Realm = Realm,
591-
ServicePrincipalName = "host/foo." + Realm,
592-
ChannelBindings = clientBindings
593-
},
594-
tgtKey, asRep, out _);
595-
596-
// Server does not expect channel bindings
597-
var handler = new KdcTgsReqMessageHandler(tgsReq.EncodeApplication(), new KdcServerOptions
598-
{
599-
DefaultRealm = Realm,
600-
IsDebug = true,
601-
RealmLocator = realm => new FakeRealmService(realm)
602-
// ExpectedChannelBindings = null
603-
});
604-
605-
var results = handler.Execute();
606-
607-
// Should succeed even though client included channel bindings as the server does not require them
608-
var tgsRep = KrbTgsRep.DecodeApplication(results);
609-
Assert.IsNotNull(tgsRep);
610-
}
611-
612-
[TestMethod]
613-
public void KdcTgsReq_ChannelBinding_ServerExpects_ClientOmits_ReturnsError()
614-
{
615-
// Server expects channel bindings but client omits them in TGS-REQ
616-
var serverBindings = new GssChannelBindings { ApplicationData = TgsTestChannelBinding };
617-
618-
KrbAsRep asRep = RequestTgt(cname: Upn, crealm: Realm, srealm: Realm, out KrbEncryptionKey tgtKey);
619-
620-
var tgsReq = KrbTgsReq.CreateTgsReq(
621-
new RequestServiceTicket
622-
{
623-
Realm = Realm,
624-
ServicePrincipalName = "host/foo." + Realm
625-
},
626-
tgtKey, asRep, out _);
627-
628-
// Server expects channel bindings
629-
var handler = new KdcTgsReqMessageHandler(tgsReq.EncodeApplication(), new KdcServerOptions
630-
{
631-
DefaultRealm = Realm,
632-
IsDebug = true,
633-
RealmLocator = realm => new FakeRealmService(realm)
634-
});
635-
636-
handler.ExpectedChannelBindings = serverBindings;
637-
638-
var results = handler.Execute();
639-
640-
// Expect an error due to missing channel bindings in client
641-
var error = KrbError.DecodeApplication(results);
642-
Assert.AreEqual(KerberosErrorCode.KRB_ERR_GENERIC, error.ErrorCode);
643-
}
644-
645-
[TestMethod]
646-
public void KdcTgsReq_NoChannelBindings_Succeeds()
647-
{
648-
// Neither client nor server uses channel bindings
649-
// should succeed without error
650-
KrbAsRep asRep = RequestTgt(cname: Upn, crealm: Realm, srealm: Realm, out KrbEncryptionKey tgtKey);
651-
652-
var tgsReq = KrbTgsReq.CreateTgsReq(
653-
new RequestServiceTicket
654-
{
655-
Realm = Realm,
656-
ServicePrincipalName = "host/foo." + Realm
657-
},
658-
tgtKey, asRep, out _);
659-
660-
var handler = new KdcTgsReqMessageHandler(tgsReq.EncodeApplication(), new KdcServerOptions
661-
{
662-
DefaultRealm = Realm,
663-
IsDebug = true,
664-
RealmLocator = realm => new FakeRealmService(realm)
665-
});
666-
667-
var results = handler.Execute();
668-
669-
var tgsRep = KrbTgsRep.DecodeApplication(results);
670-
Assert.IsNotNull(tgsRep);
671-
}
672498
}
673499
}

0 commit comments

Comments
 (0)