internal static BufLen Send(DHHandshakeContext context) { context.TimestampA = (uint)Math.Ceiling((DateTime.UtcNow - I2PDate.RefDate).TotalSeconds); var cleartext = new BufRefStream(); var ri = RouterContext.Inst.MyRouterIdentity.ToByteArray(); cleartext.Write(BufUtils.Flip16B((ushort)ri.Length)); cleartext.Write(ri); cleartext.Write(BufUtils.Flip32B(context.TimestampA)); #if LOG_ALL_TRANSPORT Logging.LogTransport("SessionConfirmA send TimestampA: " + (I2PDate.RefDate.AddSeconds(context.TimestampA).ToString())); Logging.LogTransport("SessionConfirmA send TimestampB: " + (I2PDate.RefDate.AddSeconds(context.TimestampB).ToString())); #endif var sign = I2PSignature.DoSign(RouterContext.Inst.PrivateSigningKey, context.X.Key, context.Y.Key, context.RemoteRI.IdentHash.Hash, BufUtils.Flip32BL(context.TimestampA), BufUtils.Flip32BL(context.TimestampB)); var padsize = BufUtils.Get16BytePadding((int)(sign.Length + cleartext.Length)); cleartext.Write(BufUtils.Random(padsize)); cleartext.Write(sign); var buf = new BufLen(cleartext.ToArray()); context.Encryptor.ProcessBytes(buf); return(buf); }
public I2PRouterInfo( I2PRouterIdentity identity, I2PDate publisheddate, I2PRouterAddress[] adresses, I2PMapping options, I2PSigningPrivateKey privskey) { Identity = identity; PublishedDate = publisheddate; Adresses = adresses; Options = options; var dest = new BufRefStream(); Identity.Write(dest); PublishedDate.Write(dest); dest.Write((byte)Adresses.Length); foreach (var addr in Adresses) { addr.Write(dest); } dest.Write(0); // Always zero Options.Write(dest); Data = new BufLen(dest.ToArray()); Signature = new I2PSignature(new BufRefLen(I2PSignature.DoSign(privskey, Data)), privskey.Certificate); }
public byte[] ToByteArray() { var buf = new BufRefStream(); Write(buf); return(buf.ToArray()); }
public void Write(BufRefStream dest) { var dest2 = new BufRefStream(); Destination.Write(dest2); Map.Write(dest2); Date.Write(dest2); var dest2data = dest2.ToArray(); var sig = new I2PSignature(new BufRefLen(I2PSignature.DoSign(PrivateSigningKey, new BufLen(dest2data))), PrivateSigningKey.Certificate); dest.Write(dest2data); sig.Write(dest); }
public Garlic(I2PDate expiration, IEnumerable <GarlicClove> cloves) { BufRefStream buf = new BufRefStream(); buf.Write((byte)cloves.Count()); foreach (var clove in cloves) { clove.Write(buf); } // Certificate buf.Write(new byte[] { 0, 0, 0 }); buf.Write((BufRefLen)BufUtils.Flip32BL(BufUtils.RandomUint())); expiration.Write(buf); Data = new BufLen(buf.ToArray()); ParseData(new BufRefLen(Data)); }
public void Sign() { if (Mode != BuildMode.BatchList) { throw new InvalidOperationException("Cannot mix build modes"); } var buf = new BufRefStream(); foreach (var data in Batch) { data.Write(buf); } SignedData = buf.ToArray(); Hash = DoSign(SignedData); Mode = BuildMode.Signed; }
public void Save(string filename) { var fullpath = GetFullPath(filename); using (var fs = new FileStream(fullpath, FileMode.Create, FileAccess.Write)) { var dest = new BufRefStream(); Certificate.Write(dest); PrivateSigningKey.Write(dest); PublicSigningKey.Write(dest); PrivateKey.Write(dest); PublicKey.Write(dest); MyRouterIdentity.Write(dest); Published.Write(dest); IntroKey.WriteTo(dest); var ar = dest.ToArray(); fs.Write(ar, 0, ar.Length); } }