/// <summary> /// SPNG Client Packet API, which is to generate SpngInitialNegToken /// </summary> /// <param name="payloadType">An enum parameter, indicates the inner payload type, /// e.g. PayloadType.NegInit is for NegTokenInit</param> /// <param name="negotiationState">Indicate the negotation status, e.g. incomplete, completed.</param> /// <param name="mechToken">Binary mechToken byte array, or responseToken. /// This field could be null when the first time invoked.</param> /// <param name="mechListMIC">This field, if present, contains an MIC token for /// the mechanism list in the initial negotiation message. /// This field could be null.</param> /// <returns>SpngInitialNegToken2 packet</returns> /// <exception cref="ArgumentOutOfRangeException">PayloadType is not in scope. </exception> public SpngInitialNegToken CreateInitialNegToken(SpngPayloadType payloadType, NegState negotiationState, byte[] mechToken, byte[] mechListMIC) { Asn1Object asn1Element; NegotiationToken negToken; Asn1OctetString asn10MechListMic = null; if (mechListMIC != null) { asn10MechListMic = new Asn1OctetString(mechListMIC); } switch (payloadType) { case SpngPayloadType.NegInit: asn1Element = new NegTokenInit(this.Config.MechList, this.Config.Asn1ContextAttributes, new Asn1.Asn1OctetString(mechToken), asn10MechListMic ); // save the initial MechType list. Will be used when computing MechListMIC this.Context.InitMechTypeList = (asn1Element as NegTokenInit).mechTypes; negToken = new NegotiationToken(NegotiationToken.negTokenInit, asn1Element); break; default: //throw exception here throw new ArgumentOutOfRangeException("payloadType"); } InitialNegToken intialToken = new InitialNegToken(new MechType(this.Config.SpngOidIntArray), negToken); return(new SpngInitialNegToken(intialToken)); }
/// <summary> /// SPNG Client Packet API, which is to generate SpngNegotiationToken. /// </summary> /// <param name="payloadType">An enum parameter, indicates the inner payload type, /// e.g. PayloadType.NegInit is for NegTokenInit</param> /// <param name="negotiationState">Indicate the negotation status, e.g. incomplete, completed.</param> /// <param name="responseToken">Byte array of responseToken. /// This field could be null when the first time invoked.</param> /// <param name="mechListMIC">This field, if present, contains an MIC token for /// the mechanism list in the initial negotiation message. /// This field could be null.</param> /// <returns>SpngNegotiationToken packet</returns> /// <exception cref="ArgumentOutOfRangeException">PayloadType is not in scope. </exception> public SpngNegotiationToken CreateNegotiationToken( SpngPayloadType payloadType, NegState negotiationState, byte[] responseToken, byte[] mechListMIC) { NegotiationToken token; switch (payloadType) { case SpngPayloadType.NegResp: SpngNegTokenResp negResp = CreateNegTokenResp(negotiationState, responseToken, mechListMIC); token = new NegotiationToken(NegotiationToken.negTokenResp, negResp.Asn1Token); break; case SpngPayloadType.NegInit: NegTokenInit negInit = new NegTokenInit( this.config.MechList, SpngUtility.ConvertUintToContextFlags(this.config.ContextAttributes), new Asn1OctetString(responseToken), new Asn1OctetString(mechListMIC) ); token = new NegotiationToken(NegotiationToken.negTokenInit, negInit); break; default: throw new ArgumentOutOfRangeException("payloadType"); } return(new SpngNegotiationToken(token)); }
/// <summary> /// Generate a NegotiationToken byte array, and insert the internal security token /// </summary> /// <param name="payloadType">the internal payload type</param> /// <param name="inToken">the internal security token</param> /// <returns>the generated NegotiationToken byte array</returns> private byte[] WrapNegotiationToken(SpngPayloadType payloadType, byte[] inToken) { byte[] mechListMic = null; if (this.needMechListMic && securityMechContext != null && !securityMechContext.NeedContinueProcessing) { mechListMic = this.client.GenerateMechListMIC(securityMechContext); } SpngNegotiationToken negToken = client.CreateNegotiationToken(payloadType, new NegState(NegState.accept_incomplete), inToken, mechListMic); return(negToken.ToBytes()); }