/// <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> /// 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)); }
public NegTokenResp( NegState negState, MechType supportedMech, Asn1OctetString responseToken, Asn1OctetString mechListMIC) { this.negState = negState; this.supportedMech = supportedMech; this.responseToken = responseToken; this.mechListMIC = mechListMIC; }
/// <summary> /// SPNG Client Packet API, which is to generate SpngNegTokenResp. /// </summary> /// <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>SpngNegTokenResp packet</returns> public SpngNegTokenResp CreateNegTokenResp(NegState negotiationState, byte[] responseToken, byte[] mechListMIC) { Asn1OctetString asn1RespToken = null; Asn1OctetString asn1MechListMIC = null; if (responseToken != null) { asn1RespToken = new Asn1OctetString(responseToken); } if (mechListMIC != null) { asn1MechListMIC = new Asn1OctetString(mechListMIC); } NegTokenResp negToken = new NegTokenResp(negotiationState, this.Context.NegotiatedMechType, asn1RespToken, asn1MechListMIC); SpngNegTokenResp spngToken = new SpngNegTokenResp(negToken); return(spngToken); }