Add templated version of ByteBufferWriter.

This CL switches to a Buffer for storing the data and allows using
a different class, e.g. "ZeroOnFreeBuffer" for sensitive data.

Bug: webrtc:8905
Change-Id: Ic56f3f51cc6d640135c4ee0e1ad0fd48d27bbbdf
Reviewed-on: https://webrtc-review.googlesource.com/60660
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Joachim Bauch <jbauch@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22354}
This commit is contained in:
Joachim Bauch
2018-03-08 00:55:33 +01:00
committed by Commit Bot
parent 89d88c0b9d
commit 4c6a30c1bf
3 changed files with 107 additions and 154 deletions

View File

@ -665,7 +665,7 @@ void AsyncSocksProxySocket::SendHello() {
}
void AsyncSocksProxySocket::SendAuth() {
ByteBufferWriter request;
ByteBufferWriterT<ZeroOnFreeBuffer<char>> request;
request.WriteUInt8(1); // Negotiation Version
request.WriteUInt8(static_cast<uint8_t>(user_.size()));
request.WriteString(user_); // Username
@ -673,14 +673,10 @@ void AsyncSocksProxySocket::SendAuth() {
size_t len = pass_.GetLength() + 1;
char * sensitive = new char[len];
pass_.CopyTo(sensitive, true);
// Don't write anything to |request| afterwards to avoid potential
// reallocations where the old memory (containing the password) will not
// be cleared securely.
request.WriteBytes(sensitive, pass_.GetLength()); // Password
ExplicitZeroMemory(sensitive, len);
delete [] sensitive;
DirectSend(request.Data(), request.Length());
ExplicitZeroMemory(request.MutableData(), request.Length());
state_ = SS_AUTH;
}