using System; using System.IO; namespace S22.Sasl.Mechanisms.Srp { /// /// Represents the second message sent by the server as part of the SRP /// authentication exchange. /// internal class ServerMessage2 { /// /// The evidence which proves to the client server-knowledge of the shared /// context key. /// public byte[] Proof { get; set; } /// /// The initial vector the client will use to set up its encryption /// context, if confidentiality protection will be employed. /// public byte[] InitialVector { get; set; } /// /// The session identifier the server has given to this session. /// public string SessionId { get; set; } /// /// The time period for which this session's parameters may be re-usable. /// public uint Ttl { get; set; } /// /// Deserializes a new instance of the ServerMessage2 class from the /// specified buffer of bytes. /// /// The byte buffer to deserialize the ServerMessage2 /// instance from. /// An instance of the ServerMessage2 class deserialized from the /// specified byte array. /// Thrown if the byte buffer does not /// contain valid data. public static ServerMessage2 Deserialize(byte[] buffer) { using (var ms = new MemoryStream(buffer)) { using (var r = new BinaryReader(ms)) { uint bufferLength = r.ReadUInt32(true); OctetSequence M2 = r.ReadOs(), sIV = r.ReadOs(); Utf8String sid = r.ReadUtf8String(); uint ttl = r.ReadUInt32(true); return new ServerMessage2() { Proof = M2.Value, InitialVector = sIV.Value, SessionId = sid.Value, Ttl = ttl }; } } } } }