Esempio n. 1
0
 private void SendRecord(byte contentType, byte[] buf, int off, int len)
 {
     if (mWriteVersion != null)
     {
         if (len > mPlaintextLimit)
         {
             throw new TlsFatalAlert(80);
         }
         if (len < 1 && contentType != 23)
         {
             throw new TlsFatalAlert(80);
         }
         int    epoch  = mWriteEpoch.Epoch;
         long   num    = mWriteEpoch.AllocateSequenceNumber();
         byte[] array  = mWriteEpoch.Cipher.EncodePlaintext(GetMacSequenceNumber(epoch, num), contentType, buf, off, len);
         byte[] array2 = new byte[array.Length + 13];
         TlsUtilities.WriteUint8(contentType, array2, 0);
         ProtocolVersion version = mWriteVersion;
         TlsUtilities.WriteVersion(version, array2, 1);
         TlsUtilities.WriteUint16(epoch, array2, 3);
         TlsUtilities.WriteUint48(num, array2, 5);
         TlsUtilities.WriteUint16(array.Length, array2, 11);
         global::System.Array.Copy((global::System.Array)array, 0, (global::System.Array)array2, 13, array.Length);
         mTransport.Send(array2, 0, array2.Length);
     }
 }
 public virtual void Send(byte[] buf, int off, int len)
 {
     if (LostPacket(percentPacketLossSending))
     {
         Console.WriteLine("PACKET LOSS (" + len + " byte packet not sent)");
     }
     else
     {
         transport.Send(buf, off, len);
     }
 }
Esempio n. 3
0
        private static void SendDatagram(DatagramTransport sender, byte[] buf, int off, int len)
        {
            //try
            //{
            //    sender.Send(buf, off, len);
            //}
            //catch (InterruptedIOException e)
            //{
            //    e.bytesTransferred = 0;
            //    throw e;
            //}

            sender.Send(buf, off, len);
        }
Esempio n. 4
0
 protected void send(Chunk[] c)
 {
     if ((c != null) && (c.Length > 0))
     {
         ByteBuffer obb = mkPkt(c);
         Logger.Trace("sending SCTP packet" + Packet.getHex(obb));
         lock (this) {
             _transp.Send(obb.Data, obb.offset, obb.Limit);
         }
     }
     else
     {
         Logger.Trace("Blocked empty packet send() - probably no response needed.");
     }
 }
Esempio n. 5
0
 protected void send(Chunk[] c)
 {
     if ((c != null) && (c.Length > 0))
     {
         ByteBuffer obb = mkPkt(c);
         //logger.LogDebug($"SCTP packet send: {Packet.getHex(obb)}");
         lock (this)
         {
             _transp.Send(obb.Data, obb.offset, obb.Limit);
         }
     }
     //else
     //{
     //    logger.LogDebug("Blocked empty packet send() - probably no response needed.");
     //}
 }
Esempio n. 6
0
        private void SendRecord(byte contentType, byte[] buf, int off, int len)
        {
            // Never send anything until a valid ClientHello has been received
            if (mWriteVersion == null)
            {
                return;
            }

            if (len > this.mPlaintextLimit)
            {
                throw new TlsFatalAlert(AlertDescription.internal_error);
            }

            /*
             * RFC 5246 6.2.1 Implementations MUST NOT send zero-length fragments of Handshake, Alert,
             * or ChangeCipherSpec content types.
             */
            if (len < 1 && contentType != ContentType.application_data)
            {
                throw new TlsFatalAlert(AlertDescription.internal_error);
            }

            int  recordEpoch          = mWriteEpoch.Epoch;
            long recordSequenceNumber = mWriteEpoch.AllocateSequenceNumber();

            BufferSegment ciphertext = mWriteEpoch.Cipher.EncodePlaintext(
                GetMacSequenceNumber(recordEpoch, recordSequenceNumber), contentType, buf, off, len);

            // TODO Check the ciphertext length?

            byte[] record = new byte[ciphertext.Count + RECORD_HEADER_LENGTH];
            TlsUtilities.WriteUint8(contentType, record, 0);
            ProtocolVersion version = mWriteVersion;

            TlsUtilities.WriteVersion(version, record, 1);
            TlsUtilities.WriteUint16(recordEpoch, record, 3);
            TlsUtilities.WriteUint48(recordSequenceNumber, record, 5);
            TlsUtilities.WriteUint16(ciphertext.Count, record, 11);
            Array.Copy(ciphertext.Data, ciphertext.Offset, record, RECORD_HEADER_LENGTH, ciphertext.Count);

            mTransport.Send(record, 0, record.Length);

            BufferPool.Release(ciphertext);
        }
        private void SendRecord(byte contentType, byte[] buf, int off, int len)
        {
            if (len > this.mPlaintextLimit)
            {
                throw new TlsFatalAlert(AlertDescription.internal_error);
            }

            /*
             * RFC 5264 6.2.1 Implementations MUST NOT send zero-length fragments of Handshake, Alert,
             * or ChangeCipherSpec content types.
             */
            if (len < 1 && contentType != ContentType.application_data)
            {
                throw new TlsFatalAlert(AlertDescription.internal_error);
            }

            int  recordEpoch          = mWriteEpoch.Epoch;
            long recordSequenceNumber = mWriteEpoch.AllocateSequenceNumber();

            byte[] ciphertext = mWriteEpoch.Cipher.EncodePlaintext(
                GetMacSequenceNumber(recordEpoch, recordSequenceNumber), contentType, buf, off, len);

            // TODO Check the ciphertext length?

            byte[] record = new byte[ciphertext.Length + RECORD_HEADER_LENGTH];
            TlsUtilities.WriteUint8(contentType, record, 0);
            ProtocolVersion version = mDiscoveredPeerVersion != null ? mDiscoveredPeerVersion : mContext.ClientVersion;

            TlsUtilities.WriteVersion(version, record, 1);
            TlsUtilities.WriteUint16(recordEpoch, record, 3);
            TlsUtilities.WriteUint48(recordSequenceNumber, record, 5);
            TlsUtilities.WriteUint16(ciphertext.Length, record, 11);
            Array.Copy(ciphertext, 0, record, RECORD_HEADER_LENGTH, ciphertext.Length);

            mTransport.Send(record, 0, record.Length);
        }
Esempio n. 8
0
 public static Task SendAsync(this DatagramTransport transport, byte[] buf, int off, int len)
 {
     return(Task.Run(() => transport.Send(buf, off, len)));
 }
Esempio n. 9
0
 public virtual void Send(byte[] buf, int off, int len)
 {
     DumpDatagram("Sending", buf, off, len);
     transport.Send(buf, off, len);
 }