8 #include <botan/tls_record.h>
9 #include <botan/internal/tls_handshake_hash.h>
10 #include <botan/lookup.h>
11 #include <botan/loadstor.h>
12 #include <botan/libstate.h>
21 buffer(DEFAULT_BUFFERSIZE)
40 major = minor = buf_type = 0;
56 major = (version >> 8) & 0xFF;
57 minor = (version & 0xFF);
87 const std::string cipher_algo = suite.
cipher_algo();
88 const std::string mac_algo = suite.
mac_algo();
93 cipher_algo +
"/CBC/NoPadding",
98 if(major > 3 || (major == 3 && minor >= 2))
116 if(major == 3 && minor == 0)
117 mac = af.
make_mac(
"SSL3-MAC(" + mac_algo +
")");
119 mac = af.
make_mac(
"HMAC(" + mac_algo +
")");
136 const size_t BUFFER_SIZE = buffer.
size();
141 buffer.
copy(buf_pos, input, length);
142 if(buf_pos + length >= BUFFER_SIZE)
144 send_record(buf_type, &buffer[0], length);
145 input += (BUFFER_SIZE - buf_pos);
146 length -= (BUFFER_SIZE - buf_pos);
147 while(length >= BUFFER_SIZE)
149 send_record(buf_type, input, BUFFER_SIZE);
150 input += BUFFER_SIZE;
151 length -= BUFFER_SIZE;
153 buffer.
copy(input, length);
164 const byte* buf_ptr = &buffer[0];
167 while(offset != buf_pos)
169 size_t record_size = buf_pos - offset;
173 send_record(buf_type, buf_ptr + offset, record_size);
174 offset += record_size;
183 void Record_Writer::send_record(
byte type,
const byte buf[],
size_t length)
187 "Record_Writer: Compressed packet is too big");
190 send_record(type, major, minor, buf, length);
196 if(major > 3 || (major == 3 && minor != 0))
202 mac->
update(get_byte<u16bit>(0, length));
203 mac->
update(get_byte<u16bit>(1, length));
206 SecureVector<byte> buf_mac = mac->
final();
215 SecureVector<byte> random_iv(iv_size);
217 rng.randomize(&random_iv[0], random_iv.size());
219 cipher.
write(random_iv);
222 cipher.
write(buf, length);
223 cipher.
write(buf_mac);
228 (block_size - (1 + length + buf_mac.size())) % block_size;
230 for(
size_t i = 0; i != pad_val + 1; ++i)
231 cipher.
write(pad_val);
237 send_record(type, major, minor, &output[0], output.size());
246 void Record_Writer::send_record(
byte type,
byte major,
byte minor,
247 const byte out[],
size_t length)
251 "Record_Writer: Record is too big");
253 byte header[5] = { type, major, minor, 0 };
254 for(
size_t i = 0; i != 2; ++i)
255 header[i+3] = get_byte<u16bit>(i, length);
257 output_fn(header, 5);
258 output_fn(out, length);
Record_Writer(std::tr1::function< void(const byte[], size_t)> output_fn)
void append(Filter *filt)
RandomNumberGenerator & global_rng()
void write(const byte in[], size_t length)
SymmetricKey server_mac_key() const
SymmetricKey client_cipher_key() const
SymmetricKey client_mac_key() const
std::invalid_argument Invalid_Argument
void set_version(Version_Code)
void set_keys(const CipherSuite &, const SessionKeys &, Connection_Side)
void copy(const T in[], size_t n)
InitializationVector server_iv() const
MessageAuthenticationCode * make_mac(const std::string &algo_spec, const std::string &provider="")
std::string cipher_algo() const
Algorithm_Factory & algorithm_factory() const
SymmetricKey server_cipher_key() const
SecureVector< byte > read_all(message_id msg=DEFAULT_MESSAGE)
RandomNumberGenerator * rng
void set_key(const SymmetricKey &key)
static const message_id LAST_MESSAGE
Library_State & global_state()
void update(const byte in[], size_t length)
size_t block_size_of(const std::string &name)
bool have_stream_cipher(const std::string &algo_spec)
bool have_hash(const std::string &algo_spec)
std::string mac_algo() const
bool have_block_cipher(const std::string &algo_spec)
void alert(Alert_Level, Alert_Type)
void update_be(const T in)
Keyed_Filter * get_cipher(const std::string &algo_spec, Cipher_Dir direction)
InitializationVector client_iv() const
void zeroise(MemoryRegion< T > &vec)
virtual size_t output_length() const =0
void send(byte type, const byte input[], size_t length)