예제 #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;
        }
예제 #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));
            }
        }
예제 #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);
        }
예제 #5
0
        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"));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #9
0
 public KdcSocketWorker(Socket socket, KdcServerOptions options)
     : base(socket, options)
 {
     this.kdc    = new KdcServer(options);
     this.logger = options.Log.CreateLoggerSafe <KdcSocketWorker>();
 }
예제 #10
0
 protected SocketBase(KdcServerOptions options)
 {
     this.Options = options;
 }
예제 #11
0
 protected KdcMessageHandlerBase(ReadOnlyMemory <byte> message, KdcServerOptions options)
 {
     this.message = message;
     this.Options = options;
 }