Skip to content

Commit 6e8928b

Browse files
committed
Add CCryptoKeyBase::BMatchesRawData
Fix bug in SteamNetworkingSockets::InternalSetCertificate incorrectly assuming that GetRawDataPtr was always available. It only works for some crypto implementations. P4: 7307233
1 parent 1838b62 commit 6e8928b

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/common/keypair.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ bool CCryptoKeyBase::operator==( const CCryptoKeyBase &rhs ) const
364364
return memcmp( bufLHS.Base(), bufRHS.Base(), cbRawData ) == 0;
365365
}
366366

367+
368+
//-----------------------------------------------------------------------------
369+
// Purpose: Return true if our raw data matches the the specified buffer
370+
//-----------------------------------------------------------------------------
371+
bool CCryptoKeyBase::BMatchesRawData( const void *pData, size_t cbData ) const
372+
{
373+
uint32 cbMyRawData = GetRawData(nullptr);
374+
if ( cbMyRawData != cbData ) return false;
375+
376+
CAutoWipeBuffer bufMyRawData( cbMyRawData );
377+
DbgVerify( GetRawData( bufMyRawData.Base() ) == cbMyRawData );
378+
379+
return memcmp( bufMyRawData.Base(), pData, cbData ) == 0;
380+
}
381+
367382
void CCryptoKeyBase::CopyFrom( const CCryptoKeyBase &x )
368383
{
369384
Assert( m_eKeyType == x.m_eKeyType );

src/common/keypair.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class CCryptoKeyBase
8383
bool operator==( const CCryptoKeyBase &rhs ) const;
8484
bool operator!=( const CCryptoKeyBase &rhs ) const { return !operator==( rhs ); }
8585

86+
// Return true if our raw data matches the specified buffer.
87+
bool BMatchesRawData( const void *pData, size_t cbData ) const;
88+
8689
// Make a copy of the key, by using the raw data functions
8790
void CopyFrom( const CCryptoKeyBase &x );
8891

src/steamnetworkingsockets/clientlib/csteamnetworkingsockets.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,7 @@ bool CSteamNetworkingSockets::InternalSetCertificate( const void *pCertificate,
752752
// We already chose a private key, so the cert must match.
753753
// For the most common use cases, we choose a private
754754
// key and it never leaves the current process.
755-
if ( m_keyPrivateKey.GetRawDataSize() != private_key_data.length()
756-
|| memcmp( m_keyPrivateKey.GetRawDataPtr(), private_key_data.c_str(), private_key_data.length() ) != 0 )
755+
if ( !m_keyPrivateKey.BMatchesRawData( private_key_data.data(), private_key_data.length() ) )
757756
{
758757
V_strcpy_safe( errMsg, "Private key mismatch" );
759758
return false;

0 commit comments

Comments
 (0)