/// <summary>
        /// Create KRB_ERROR response
        /// </summary>
        /// <param name="kileConnection">Maintain a connection with a target client. This argument cannot be null.</param>
        /// <param name="errorCode">Error code returned by Kerberos or the server when a request fails</param>
        /// <param name="errorText">Additional text to help explain the error code. This argument could be null.</param>
        /// <param name="errorData">Additional data about the error. This argument could be null.</param>
        /// <returns>The created Krb Error response</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the input parameter is null.</exception>
        public KileKrbError CreateKrbErrorResponse(
            KileConnection kileConnection,
            KRB_ERROR_CODE errorCode,
            string errorText,
            byte[] errorData)
        {
            KileServerContext serverContext = GetServerContextByKileConnection(kileConnection);
            KileKrbError      response      = new KileKrbError(serverContext);

            // Set KRB_ERROR
            response.KerberosError.pvno       = new Asn1Integer(ConstValue.KERBEROSV5);
            response.KerberosError.msg_type   = new Asn1Integer((int)MsgType.KRB_ERROR);
            response.KerberosError.stime      = KileUtility.CurrentKerberosTime;
            response.KerberosError.susec      = new Microseconds(0);
            response.KerberosError.sname      = serverContext.SName;
            response.KerberosError.realm      = new Realm(domain);
            response.KerberosError.error_code = new Int32((int)errorCode);

            if (errorText != null)
            {
                response.KerberosError.e_text = new KerberosString(errorText);
            }
            if (errorData != null)
            {
                response.KerberosError.e_data = new Asn1OctetString(errorData);
            }

            return(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Decode the Krb Error from bytes
        /// </summary>
        /// <param name="buffer">The byte array to be decoded.</param>
        /// <exception cref="System.ArgumentNullException">thrown when input buffer is null</exception>
        public override void FromBytes(byte[] buffer)
        {
            if (null == buffer)
            {
                throw new ArgumentNullException("buffer");
            }
            KerberosUtility.OnDumpMessage("KRB5:KrbMessage",
                                          "Kerberos Message",
                                          KerberosUtility.DumpLevel.WholeMessage,
                                          buffer);
            // Decode Krb Error
            Asn1DecodingBuffer decodeBuffer = new Asn1DecodingBuffer(buffer);

            this.KrbError.BerDecode(decodeBuffer);

            ErrorCode = (KRB_ERROR_CODE)KrbError.error_code.Value;
        }
        /// <summary>
        /// Create KRB_ERROR response
        /// </summary>
        /// <param name="kileConnection">Maintain a connection with a target client. This argument cannot be null.</param>
        /// <param name="errorCode">Error code returned by Kerberos or the server when a request fails</param>
        /// <param name="errorText">Additional text to help explain the error code. This argument could be null.</param>
        /// <param name="errorData">Additional data about the error. This argument could be null.</param>
        /// <returns>The created Krb Error response</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the input parameter is null.</exception>
        public KileKrbError CreateKrbErrorResponse(
            KileConnection kileConnection,
            KRB_ERROR_CODE errorCode,
            string errorText,
            byte[] errorData)
        {
            KileServerContext serverContext = GetServerContextByKileConnection(kileConnection);
            KileKrbError response = new KileKrbError(serverContext);

            // Set KRB_ERROR
            response.KerberosError.pvno = new Asn1Integer(ConstValue.KERBEROSV5);
            response.KerberosError.msg_type = new Asn1Integer((int)MsgType.KRB_ERROR);
            response.KerberosError.stime = KileUtility.CurrentKerberosTime;
            response.KerberosError.susec = new Microseconds(0);
            response.KerberosError.sname = serverContext.SName;
            response.KerberosError.realm = new Realm(domain);
            response.KerberosError.error_code = new Int32((int)errorCode);

            if (errorText != null)
            {
                response.KerberosError.e_text = new KerberosString(errorText);
            }
            if (errorData != null)
            {
                response.KerberosError.e_data = new Asn1OctetString(errorData);
            }

            return response;
        }