Example #1
0
        public SocketListener(KdcServerOptions options, Func <Socket, KdcServerOptions, SocketWorkerBase> workerFunc)
            : base(options)
        {
            this.logger = options.Log.CreateLoggerSafe <SocketListener>();

            // open the port 88 socket here so it can start listening

            this.listeningSocket = BindSocket(
                this.Options.Configuration.KdcDefaults.KdcTcpListenEndpoints,
                this.Options.Configuration.KdcDefaults.TcpListenBacklog
                );

            this.logger.LogInformation(
                "Listener has started. Endpoint = {Port}; Protocol = {Protocol}",
                this.listeningSocket.LocalEndPoint,
                this.listeningSocket.ProtocolType
                );

            if (options.Cancellation == null)
            {
                options.Cancellation = new CancellationTokenSource();
            }

            this.workerFunc = workerFunc;
        }
Example #2
0
        public KdcServer(KdcServerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.options = options;
            this.logger  = options.Log.CreateLoggerSafe <KdcServer>();

            if (options.Configuration.KdcDefaults.RegisterDefaultAsReqHandler)
            {
                this.RegisterMessageHandler(MessageType.KRB_AS_REQ, (message, op) => new KdcAsReqMessageHandler(message, op));
                this.RegisterPreAuthHandler(PaDataType.PA_ENC_TIMESTAMP, (service) => new PaDataTimestampHandler(service));

                if (options.Configuration.KdcDefaults.RegisterDefaultPkInitPreAuthHandler)
                {
                    this.RegisterPreAuthHandler(PaDataType.PA_PK_AS_REQ, (service) => new PaDataPkAsReqHandler(service));
                }
            }

            if (options.Configuration.KdcDefaults.RegisterDefaultTgsReqHandler)
            {
                this.RegisterMessageHandler(MessageType.KRB_TGS_REQ, (message, op) => new KdcTgsReqMessageHandler(message, op));
            }
        }
Example #3
0
        protected SocketWorkerBase(Socket socket, KdcServerOptions options)
            : base(options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.socket = socket;
            this.logger = options.Log.CreateLoggerSafe <SocketWorkerBase>();
        }
        public KdcTgsReqMessageHandler(ReadOnlyMemory <byte> message, KdcServerOptions options)
            : base(message, options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.logger = options.Log.CreateLoggerSafe <KdcTgsReqMessageHandler>();

            this.PreAuthHandlers[PaDataType.PA_TGS_REQ] = service => new PaDataTgsTicketHandler(service);
        }
        internal static ReadOnlyMemory <byte> GenerateGenericError(Exception ex, KdcServerOptions options)
        {
            KerberosErrorCode error     = KerberosErrorCode.KRB_ERR_GENERIC;
            string            errorText = options.IsDebug ? $"[Server] {ex}" : null;

            if (ex is KerberosProtocolException kex)
            {
                error     = kex.Error.ErrorCode;
                errorText = kex.Message;
            }

            return(GenerateError(error, errorText, options.DefaultRealm, "krbtgt"));
        }
Example #6
0
        public KdcAsReqMessageHandler(ReadOnlyMemory <byte> message, KdcServerOptions options)
            : base(message, options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.logger = options.Log.CreateLoggerSafe <KdcAsReqMessageHandler>();

            this.PostProcessAuthHandlers[PaDataType.PA_ETYPE_INFO2] = service => new PaDataETypeInfo2Handler(service);

            this.RegisterPreAuthHandlers(this.PostProcessAuthHandlers);
        }
Example #7
0
        protected ServiceListenerBase(
            KdcServerOptions options,
            Func <Socket, KdcServerOptions, SocketWorkerBase> workerFunc
            )
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.Options = options;

            this.logger         = options.Log.CreateLoggerSafe <ServiceListenerBase>();
            this.socketListener = new SocketListener(options, workerFunc);
        }
Example #8
0
        public SocketListener(KdcServerOptions options, Func <Socket, KdcServerOptions, SocketWorkerBase> workerFunc)
            : base(options)
        {
            this.logger = options.Log.CreateLoggerSafe <SocketListener>();

            this.listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);

            this.listeningSocket.Bind(this.Options.ListeningOn);
            this.listeningSocket.Listen(this.Options.QueueLength);

            this.logger.LogInformation(
                "Listener has started. Endpoint = {Port}; Protocol = {Protocol}",
                this.listeningSocket.LocalEndPoint,
                this.listeningSocket.ProtocolType
                );

            options.Cancellation = new CancellationTokenSource();

            this.workerFunc = workerFunc;
        }
Example #9
0
 public KdcSocketWorker(Socket socket, KdcServerOptions options)
     : base(socket, options)
 {
     this.kdc    = new KdcServer(options);
     this.logger = options.Log.CreateLoggerSafe <KdcSocketWorker>();
 }
Example #10
0
 protected SocketBase(KdcServerOptions options)
 {
     this.Options = options;
 }
 protected KdcMessageHandlerBase(ReadOnlyMemory <byte> message, KdcServerOptions options)
 {
     this.message = message;
     this.Options = options;
 }