コード例 #1
0
        /// <summary>
        /// Convert byte array to payload structure
        /// </summary>
        /// <param name="payloadData"></param>
        /// <returns>payload structure</returns>
        public static DIGEST_VALIDATION_REQ_Payload Parse(byte[] payloadData)
        {
            if (payloadData == null)
            {
                throw new ArgumentNullException("payloadData");
            }

            DIGEST_VALIDATION_REQ_Payload payload = new DIGEST_VALIDATION_REQ_Payload();
            Encoding payloadTextEncoding          = Encoding.GetEncoding(ApdsUtility.ISO_8859_1);

            uint offset = 0;

            payload.Username   = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Realm      = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Nonce      = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.CNonce     = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.NonceCount = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Algorithm  = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.QOP        = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Method     = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.URI        = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Response   = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Hentity    = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Authzid    = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);

            payloadTextEncoding = Encoding.Unicode;
            payload.AccountName = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Domain      = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.ServerName  = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);

            return(payload);
        }
コード例 #2
0
        /// <summary>
        /// Update the DIGEST_VALIDATION_REQ structure info after modification.
        /// For negative testing, user might need to modify the field of the structure.
        /// For example, if user change the domain name value, the message size need to
        /// recaculate after the modification.
        /// </summary>
        /// <param name="digestValidationReq">DIGEST_VALIDATION_REQ structure</param>
        public static DIGEST_VALIDATION_REQ UpdatePacketInfo(
            DIGEST_VALIDATION_REQ digestValidationReq)
        {
            if (digestValidationReq.Payload == null)
            {
                throw new ArgumentException(
                          "The payload field should not be null",
                          "digestValidationReq");
            }

            DIGEST_VALIDATION_REQ_Payload payload =
                DIGEST_VALIDATION_REQ_Payload.Parse(digestValidationReq.Payload);

            digestValidationReq.AccountNameLength =
                (ushort)ConvertStringToByteArray(payload.AccountName, Encoding.Unicode).Length;
            digestValidationReq.DomainLength =
                (ushort)ConvertStringToByteArray(payload.Domain, Encoding.Unicode).Length;
            digestValidationReq.ServerNameLength =
                (ushort)ConvertStringToByteArray(payload.ServerName, Encoding.Unicode).Length;

            // cacluate the size of payload
            // CharValuesLength specify the number of bytes in the Payload field of the
            // DIGEST_VALIDATION_REQ message, and MUST NOT exceed the total size in MsgSize
            digestValidationReq.CharValuesLength = (ushort)digestValidationReq.Payload.Length;

            // 16-bit unsigned integer that MUST specify
            // the total number of bytes in the DIGEST_VALIDATION_REQ message
            byte[] msgData = TypeMarshal.ToBytes <DIGEST_VALIDATION_REQ>(digestValidationReq);
            digestValidationReq.MsgSize = (ushort)msgData.Length;

            return(digestValidationReq);
        }
コード例 #3
0
        /// <summary>
        /// Create DPSP logon information structure
        /// </summary>
        /// <param name="parameterControl">
        /// A set of bit flags that contain information pertaining to the logon validation processing.
        /// </param>
        /// <param name="digestValidationReq">DIGEST_VALIDATION_REQ structure</param>
        /// <returns>Dpsp netlogon information structure</returns>
        public static _NETLOGON_LEVEL CreateDpspLogonInfo(
            NrpcParameterControlFlags parameterControl,
            DIGEST_VALIDATION_REQ digestValidationReq)
        {
            if (digestValidationReq.Payload == null)
            {
                throw new ArgumentException(
                          "invalid digestValidationReq parameter: the payload field is null",
                          "digestValidationReq");
            }

            _NETLOGON_LEVEL netLogonLevel = new _NETLOGON_LEVEL();

            DIGEST_VALIDATION_REQ_Payload payload =
                DIGEST_VALIDATION_REQ_Payload.Parse(digestValidationReq.Payload);

            byte[] logonData = TypeMarshal.ToBytes <DIGEST_VALIDATION_REQ>(digestValidationReq);

            //Identity: A NETLOGON_LOGON_IDENTITY_INFO structure, as specified in section MS-NRPC 2.2.1.4.15,
            //that contains information about the logon identity.
            _NETLOGON_LOGON_IDENTITY_INFO identityInfo = NrpcUtility.CreateNetlogonIdentityInfo(
                parameterControl,
                payload.Domain,
                payload.Username,
                payload.ServerName);

            netLogonLevel.LogonGeneric                = new _NETLOGON_GENERIC_INFO[1];
            netLogonLevel.LogonGeneric[0].Identity    = identityInfo;
            netLogonLevel.LogonGeneric[0].PackageName = DtypUtility.ToRpcUnicodeString(DIGEST_PACKAGENAME);
            netLogonLevel.LogonGeneric[0].LogonData   = logonData;
            netLogonLevel.LogonGeneric[0].DataLength  = (uint)logonData.Length;

            return(netLogonLevel);
        }
コード例 #4
0
        /// <summary>
        /// Encode common part of DigestValidationRequest
        /// </summary>
        /// <param name="serverName">server name</param>
        /// <param name="domainName">domain name</param>
        /// <param name="accountName">account name</param>
        /// <param name="digestType">digest type</param>
        /// <param name="digestChallengeAlgorithm">digest challenge algorithm</param>
        /// <param name="dpspResponse">dpspResponse</param>
        /// <param name="payload">DIGEST_VALIDATION_REQ_Payload structure</param>
        /// <param name="digestValidationReq">digestValidationReq</param>
        private static void EncodeCommonPartOfDigestValidationRequest(
            string serverName,
            string domainName,
            string accountName,
            DigestType_Values digestType,
            string digestChallengeAlgorithm,
            DpspResponse dpspResponse,
            ref DIGEST_VALIDATION_REQ_Payload payload,
            ref DIGEST_VALIDATION_REQ digestValidationReq
            )
        {
            digestValidationReq.MessageType = DIGEST_VALIDATION_REQ_MessageType_Values.Default;
            digestValidationReq.Version     = DIGEST_VALIDATION_REQ_Version_Values.Default;
            digestValidationReq.DigestType  = digestType;
            digestValidationReq             = SetQopType(dpspResponse, digestValidationReq);
            digestValidationReq             = SetAlgType(digestChallengeAlgorithm, digestValidationReq);
            digestValidationReq.CharsetType = CharsetType_Values.UTF8;
            digestValidationReq.NameFormat  = NameFormat_Values.None;
            digestValidationReq.Flags       =
                DIGEST_VALIDATION_FLAGS.FormatOfUserNameAndRealmIsDeterminedByDC
                | DIGEST_VALIDATION_FLAGS.RequestIsSentFromServer;

            digestValidationReq.Reserved3 = DIGEST_VALIDATION_REQ_Reserved3_Values.Default;
            digestValidationReq.Reserved4 = Reserved4_Values.Default;
            digestValidationReq.Pad1      = DIGEST_VALIDATION_REQ_Pad1_Values.Default;

            // Each of the strings MUST be included. If the string value is empty,
            // then a terminating null character MUST be used for the value.
            payload.Username   = dpspResponse.GetAttributeValue(DpspUtility.USER_NAME_DIRECTIVE);
            payload.Realm      = dpspResponse.GetAttributeValue(DpspUtility.REALM_DIRECTIVE);
            payload.Nonce      = dpspResponse.GetAttributeValue(DpspUtility.NONCE_DIRECTIVE);
            payload.CNonce     = dpspResponse.GetAttributeValue(DpspUtility.CNONCE_DIRECTIVE);
            payload.NonceCount = dpspResponse.GetAttributeValue(DpspUtility.NONCE_COUNT_DIRECTIVE);
            payload.QOP        = dpspResponse.GetAttributeValue(DpspUtility.MESSAGE_QOP_DIRECTIVE);
            payload.Response   = dpspResponse.GetAttributeValue(DpspUtility.RESPONSE_DIRECTIVE);

            payload.AccountName = accountName;;
            payload.ServerName  = serverName;
            payload.Domain      = domainName;
        }
コード例 #5
0
        /// <summary>
        /// Encode common part of DigestValidationRequest
        /// </summary>
        /// <param name="serverName">server name</param>
        /// <param name="domainName">domain name</param>
        /// <param name="accountName">account name</param>
        /// <param name="digestType">digest type</param>
        /// <param name="digestChallengeAlgorithm">digest challenge algorithm</param>
        /// <param name="dpspResponse">dpspResponse</param>
        /// <param name="payload">DIGEST_VALIDATION_REQ_Payload structure</param>
        /// <param name="digestValidationReq">digestValidationReq</param>
        private static void EncodeCommonPartOfDigestValidationRequest(
            string serverName,
            string domainName,
            string accountName,
            DigestType_Values digestType,
            string digestChallengeAlgorithm,
            DpspResponse dpspResponse,
            ref DIGEST_VALIDATION_REQ_Payload payload,
            ref DIGEST_VALIDATION_REQ digestValidationReq
            )
        {
            digestValidationReq.MessageType = DIGEST_VALIDATION_REQ_MessageType_Values.Default;
            digestValidationReq.Version = DIGEST_VALIDATION_REQ_Version_Values.Default;
            digestValidationReq.DigestType = digestType;
            digestValidationReq = SetQopType(dpspResponse, digestValidationReq);
            digestValidationReq = SetAlgType(digestChallengeAlgorithm, digestValidationReq);
            digestValidationReq.CharsetType = CharsetType_Values.UTF8;
            digestValidationReq.NameFormat = NameFormat_Values.None;
            digestValidationReq.Flags =
                DIGEST_VALIDATION_FLAGS.FormatOfUserNameAndRealmIsDeterminedByDC
                | DIGEST_VALIDATION_FLAGS.RequestIsSentFromServer;

            digestValidationReq.Reserved3 = DIGEST_VALIDATION_REQ_Reserved3_Values.Default;
            digestValidationReq.Reserved4 = Reserved4_Values.Default;
            digestValidationReq.Pad1 = DIGEST_VALIDATION_REQ_Pad1_Values.Default;

            // Each of the strings MUST be included. If the string value is empty,
            // then a terminating null character MUST be used for the value.
            payload.Username = dpspResponse.GetAttributeValue(DpspUtility.USER_NAME_DIRECTIVE);
            payload.Realm = dpspResponse.GetAttributeValue(DpspUtility.REALM_DIRECTIVE);
            payload.Nonce = dpspResponse.GetAttributeValue(DpspUtility.NONCE_DIRECTIVE);
            payload.CNonce = dpspResponse.GetAttributeValue(DpspUtility.CNONCE_DIRECTIVE);
            payload.NonceCount = dpspResponse.GetAttributeValue(DpspUtility.NONCE_COUNT_DIRECTIVE);
            payload.QOP = dpspResponse.GetAttributeValue(DpspUtility.MESSAGE_QOP_DIRECTIVE);
            payload.Response = dpspResponse.GetAttributeValue(DpspUtility.RESPONSE_DIRECTIVE);

            payload.AccountName = accountName; ;
            payload.ServerName = serverName;
            payload.Domain = domainName;
        }
コード例 #6
0
        /// <summary>
        /// Construct DIGEST_VALIDATION_REQ structure
        /// </summary>
        /// <param name="serverName">server name</param>
        /// <param name="domainName">domain name</param>
        /// <param name="accountName">account name</param>
        /// <param name="httpMethod">http method</param>
        /// <param name="digestType">digest type</param>
        /// <param name="digestChallengeAlgorithm">digest challenge algorithm</param>
        /// <param name="dpspResponse">dpspResponse class instance</param>
        /// <returns>DIGEST_VALIDATION_REQ structure</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when dpspResponse or httpMethod is null  
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown when httpMethod or digestType input is invalid
        /// </exception>        
        public static DIGEST_VALIDATION_REQ CreateDigestValidationRequestPacket(
            string serverName,
            string domainName,
            string accountName,
            string httpMethod,
            DigestType_Values digestType,
            string digestChallengeAlgorithm,
            DpspResponse dpspResponse)
        {
            if (dpspResponse == null)
            {
                throw new ArgumentNullException("dpspResponse");
            }

            if (httpMethod == null)
            {
                throw new ArgumentNullException("httpMethod");
            }

            DIGEST_VALIDATION_REQ_Payload payload = new DIGEST_VALIDATION_REQ_Payload();

            DIGEST_VALIDATION_REQ digestValidationReq = new DIGEST_VALIDATION_REQ();
            if (digestType == DigestType_Values.Basic)
            {
                EncodeCommonPartOfDigestValidationRequest(
                    serverName,
                    domainName,
                    accountName,
                    digestType,
                    digestChallengeAlgorithm,
                    dpspResponse,
                    ref payload,
                    ref digestValidationReq);

                payload.Algorithm = dpspResponse.GetAttributeValue(DpspUtility.ALGORITHM_DIRECTIVE);
                payload.URI = dpspResponse.GetAttributeValue(DpspUtility.BASIC_DIGEST_URI_DIRECTIVE);
                if (httpMethod.ToUpper().Equals(HTTP_GET) || httpMethod.ToLower().Equals(HTTP_PUT))
                {
                    payload.Method = httpMethod;
                }
                else
                {
                    throw new ArgumentException("invalid http method", "httpMethod");
                }
            }
            else if (digestType == DigestType_Values.SASL)
            {
                EncodeCommonPartOfDigestValidationRequest(
                   serverName,
                   domainName,
                   accountName,
                   digestType,
                   digestChallengeAlgorithm,
                   dpspResponse,
                   ref payload,
                   ref digestValidationReq);

                payload.Method = SASL_AUTHENTICATE;
                payload.URI = dpspResponse.GetAttributeValue(DpspUtility.SASL_DIGEST_URI_DIRECTIVE);
                payload.Authzid = dpspResponse.GetAttributeValue(DpspUtility.AUTHZID_DIRECTIVE);
                payload.Hentity = dpspResponse.GetAttributeValue(DpspUtility.HENTITY_DIRECTIVE);

            }
            else
            {
                throw new ArgumentException(
                    "invalid digestType value",
                    "digestType");
            }

            digestValidationReq.Payload = payload.GetBytes();
            digestValidationReq = UpdatePacketInfo(digestValidationReq);

            return digestValidationReq;
        }
コード例 #7
0
        /// <summary>
        /// Convert byte array to payload structure
        /// </summary>
        /// <param name="payloadData"></param>
        /// <returns>payload structure</returns>
        public static DIGEST_VALIDATION_REQ_Payload Parse(byte[] payloadData)
        {
            if (payloadData == null)
            {
                throw new ArgumentNullException("payloadData");
            }

            DIGEST_VALIDATION_REQ_Payload payload = new DIGEST_VALIDATION_REQ_Payload();
            Encoding payloadTextEncoding = Encoding.GetEncoding(ApdsUtility.ISO_8859_1);

            uint offset = 0;
            payload.Username = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Realm = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Nonce = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.CNonce = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.NonceCount = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Algorithm = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.QOP = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Method = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.URI = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Response = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Hentity = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Authzid = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);

            payloadTextEncoding = Encoding.Unicode;
            payload.AccountName = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.Domain = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);
            payload.ServerName = ReadNullTerminateString(payloadData, ref offset, payloadTextEncoding);

            return payload;
        }
コード例 #8
0
        /// <summary>
        /// Construct DIGEST_VALIDATION_REQ structure
        /// </summary>
        /// <param name="serverName">server name</param>
        /// <param name="domainName">domain name</param>
        /// <param name="accountName">account name</param>
        /// <param name="httpMethod">http method</param>
        /// <param name="digestType">digest type</param>
        /// <param name="digestChallengeAlgorithm">digest challenge algorithm</param>
        /// <param name="dpspResponse">dpspResponse class instance</param>
        /// <returns>DIGEST_VALIDATION_REQ structure</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when dpspResponse or httpMethod is null
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown when httpMethod or digestType input is invalid
        /// </exception>
        public static DIGEST_VALIDATION_REQ CreateDigestValidationRequestPacket(
            string serverName,
            string domainName,
            string accountName,
            string httpMethod,
            DigestType_Values digestType,
            string digestChallengeAlgorithm,
            DpspResponse dpspResponse)
        {
            if (dpspResponse == null)
            {
                throw new ArgumentNullException("dpspResponse");
            }

            if (httpMethod == null)
            {
                throw new ArgumentNullException("httpMethod");
            }

            DIGEST_VALIDATION_REQ_Payload payload = new DIGEST_VALIDATION_REQ_Payload();

            DIGEST_VALIDATION_REQ digestValidationReq = new DIGEST_VALIDATION_REQ();

            if (digestType == DigestType_Values.Basic)
            {
                EncodeCommonPartOfDigestValidationRequest(
                    serverName,
                    domainName,
                    accountName,
                    digestType,
                    digestChallengeAlgorithm,
                    dpspResponse,
                    ref payload,
                    ref digestValidationReq);

                payload.Algorithm = dpspResponse.GetAttributeValue(DpspUtility.ALGORITHM_DIRECTIVE);
                payload.URI       = dpspResponse.GetAttributeValue(DpspUtility.BASIC_DIGEST_URI_DIRECTIVE);
                if (httpMethod.ToUpper().Equals(HTTP_GET) || httpMethod.ToLower().Equals(HTTP_PUT))
                {
                    payload.Method = httpMethod;
                }
                else
                {
                    throw new ArgumentException("invalid http method", "httpMethod");
                }
            }
            else if (digestType == DigestType_Values.SASL)
            {
                EncodeCommonPartOfDigestValidationRequest(
                    serverName,
                    domainName,
                    accountName,
                    digestType,
                    digestChallengeAlgorithm,
                    dpspResponse,
                    ref payload,
                    ref digestValidationReq);

                payload.Method  = SASL_AUTHENTICATE;
                payload.URI     = dpspResponse.GetAttributeValue(DpspUtility.SASL_DIGEST_URI_DIRECTIVE);
                payload.Authzid = dpspResponse.GetAttributeValue(DpspUtility.AUTHZID_DIRECTIVE);
                payload.Hentity = dpspResponse.GetAttributeValue(DpspUtility.HENTITY_DIRECTIVE);
            }
            else
            {
                throw new ArgumentException(
                          "invalid digestType value",
                          "digestType");
            }

            digestValidationReq.Payload = payload.GetBytes();
            digestValidationReq         = UpdatePacketInfo(digestValidationReq);

            return(digestValidationReq);
        }