示例#1
0
 public CompatibilityResult(RecordLayer rl, SslRecordStatus status)
 {
     this.RecordLayer = rl;
     this.Status      = status;
 }
示例#2
0
 public CompatibilityResult(RecordLayer rl, SslRecordStatus status)
 {
     this.RecordLayer = rl;
     this.Status = status;
 }
示例#3
0
		public SslRecordStatus ProcessBytes(byte[] buffer, int offset, int size) {
			if (buffer == null)
				throw new ArgumentNullException();
			if (offset < 0 || offset + size > buffer.Length || size <= 0)
				throw new ArgumentException();
			SslRecordStatus ret = new SslRecordStatus();
			ret.Status = SslStatus.MessageIncomplete;
			MemoryStream decrypted = new MemoryStream();
			MemoryStream protocol = new MemoryStream();
			// copy the new bytes and the old bytes in one buffer
			byte[] fullbuffer = new byte[m_IncompleteMessage.Length + size];
			Array.Copy(m_IncompleteMessage, 0, fullbuffer, 0, m_IncompleteMessage.Length);
			Array.Copy(buffer, offset, fullbuffer, m_IncompleteMessage.Length, size);
			// extract all record messages, if any, and process them
			int recordSize = 0;
			int recordLength;
			while(IsRecordMessageComplete(fullbuffer, recordSize)) {
				RecordMessage message = new RecordMessage(fullbuffer, recordSize);
				recordLength = message.length + 5;
				UnwrapMessage(message); // decrypt and verify message
				// process message
				if (message.contentType == ContentType.ApplicationData) {
					if (!m_HandshakeLayer.IsNegotiating()) {
						decrypted.Write(message.fragment, 0, message.fragment.Length);
					} else {
						throw new SslException(AlertDescription.UnexpectedMessage, "The handshake procedure was not completed successfully before application data was received.");
					}
					ret.Status = SslStatus.OK;
				} else { // handshake message or change cipher spec message
					SslHandshakeStatus status = m_HandshakeLayer.ProcessMessages(message);
					if (status.Message != null)
						protocol.Write(status.Message, 0, status.Message.Length);
					ret.Status = status.Status;
				}
				recordSize += recordLength;
			}
			// copy remaining data [incomplete record]
			if (recordSize > 0) {
				m_IncompleteMessage = new byte[fullbuffer.Length - recordSize];
				Array.Copy(fullbuffer, recordSize, m_IncompleteMessage, 0, m_IncompleteMessage.Length);
			} else {
				m_IncompleteMessage = fullbuffer;
			}
			if (decrypted.Length > 0) {
				ret.Decrypted = decrypted.ToArray();
			}
			decrypted.Close();
			if (protocol.Length > 0) {
				ret.Buffer = protocol.ToArray();
			}
			protocol.Close();
			return ret;
		}
        public SslRecordStatus ProcessBytes(byte[] buffer, int offset, int size)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException();
            }
            if (offset < 0 || offset + size > buffer.Length || size <= 0)
            {
                throw new ArgumentException();
            }
            SslRecordStatus ret = new SslRecordStatus();

            ret.Status = SslStatus.MessageIncomplete;
            MemoryStream decrypted = new MemoryStream();
            MemoryStream protocol  = new MemoryStream();

            // copy the new bytes and the old bytes in one buffer
            byte[] fullbuffer = new byte[m_IncompleteMessage.Length + size];
            Array.Copy(m_IncompleteMessage, 0, fullbuffer, 0, m_IncompleteMessage.Length);
            Array.Copy(buffer, offset, fullbuffer, m_IncompleteMessage.Length, size);
            // extract all record messages, if any, and process them
            int recordSize = 0;
            int recordLength;

            while (IsRecordMessageComplete(fullbuffer, recordSize))
            {
                RecordMessage message = new RecordMessage(fullbuffer, recordSize);
                recordLength = message.length + 5;
                UnwrapMessage(message);                 // decrypt and verify message
                // process message
                if (message.contentType == ContentType.ApplicationData)
                {
                    if (!m_HandshakeLayer.IsNegotiating())
                    {
                        decrypted.Write(message.fragment, 0, message.fragment.Length);
                    }
                    else
                    {
                        throw new SslException(AlertDescription.UnexpectedMessage, "The handshake procedure was not completed successfully before application data was received.");
                    }
                    ret.Status = SslStatus.OK;
                }
                else                     // handshake message or change cipher spec message
                {
                    SslHandshakeStatus status = m_HandshakeLayer.ProcessMessages(message);
                    if (status.Message != null)
                    {
                        protocol.Write(status.Message, 0, status.Message.Length);
                    }
                    ret.Status = status.Status;
                }
                recordSize += recordLength;
            }
            // copy remaining data [incomplete record]
            if (recordSize > 0)
            {
                m_IncompleteMessage = new byte[fullbuffer.Length - recordSize];
                Array.Copy(fullbuffer, recordSize, m_IncompleteMessage, 0, m_IncompleteMessage.Length);
            }
            else
            {
                m_IncompleteMessage = fullbuffer;
            }
            if (decrypted.Length > 0)
            {
                ret.Decrypted = decrypted.ToArray();
            }
            decrypted.Close();
            if (protocol.Length > 0)
            {
                ret.Buffer = protocol.ToArray();
            }
            protocol.Close();
            return(ret);
        }