Skip to content

Commit a3e4e7a

Browse files
committed
Fix revocation list bug
We were checking the list for intermediate certs, but not for for the leaf identity certs. Also fix some typos P4:6570824
1 parent aaa54dc commit a3e4e7a

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

src/steamnetworkingsockets/steamnetworkingsockets_certs.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@
99

1010
namespace SteamNetworkingSocketsLib {
1111

12-
uint64 CalculatePublicKeyID( const CECSigningPublicKey &pubKey )
12+
uint64 CalculatePublicKeyID_Ed25519( const void *pPubKey, size_t cbPubKey )
1313
{
14-
if ( !pubKey.IsValid() )
14+
if ( cbPubKey != 32 )
1515
return 0;
1616

17-
// SHA over the whole public key.
1817
SHA256Digest_t digest;
19-
uint8 data[32];
20-
DbgVerify( pubKey.GetRawData( data ) == sizeof(data) );
21-
CCrypto::GenerateSHA256Digest( data, sizeof(data), &digest );
18+
CCrypto::GenerateSHA256Digest( pPubKey, cbPubKey, &digest );
2219

2320
// First 8 bytes
2421
return LittleQWord( *(uint64*)&digest );
2522
}
2623

24+
uint64 CalculatePublicKeyID( const CECSigningPublicKey &pubKey )
25+
{
26+
if ( !pubKey.IsValid() )
27+
return 0;
28+
29+
// SHA over the whole public key.
30+
uint8 data[32];
31+
uint32 cbPubKey = pubKey.GetRawData( data );
32+
Assert( cbPubKey == sizeof(data) );
33+
return CalculatePublicKeyID_Ed25519( data, cbPubKey );
34+
}
35+
2736
// Returns:
2837
// -1 Bogus data
2938
// 0 Unknown type

src/steamnetworkingsockets/steamnetworkingsockets_certstore.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ struct PublicKey
244244
if ( m_eTrust >= k_ETrust_Trusted )
245245
return true;
246246
Assert( m_eTrust <= k_ETrust_NotTrusted );
247-
Assert( !m_status_msg.empty() ); // We should nkow the reason for any key we don't trust
247+
Assert( !m_status_msg.empty() ); // We should know the reason for any key we don't trust
248248
return false;
249249
}
250250

@@ -666,6 +666,38 @@ const CertAuthScope *CertStore_CheckCert( const CMsgSteamDatagramCertificateSign
666666
return nullptr;
667667
}
668668

669+
// Check if their key has specifically been revoked.
670+
if ( outMsgCert.key_type() != CMsgSteamDatagramCertificate_EKeyType_ED25519 )
671+
{
672+
V_sprintf_safe( errMsg, "Cert has invalid key type %d", (int)outMsgCert.key_type() );
673+
return nullptr;
674+
}
675+
uint64 nKeyID = CalculatePublicKeyID_Ed25519( outMsgCert.key_data().c_str(), outMsgCert.key_data().length() );
676+
if ( nKeyID == 0)
677+
{
678+
V_sprintf_safe( errMsg, "Cert has invalid public key" );
679+
return nullptr;
680+
}
681+
const PublicKey *pPubKey = FindPublicKey( nKeyID );
682+
if ( pPubKey )
683+
{
684+
if ( pPubKey->m_eTrust == k_ETrust_NotTrusted )
685+
{
686+
// Hm - this status doesn't mean "bad", it just means that the cert in the cert store
687+
// with this key was not able to be verified. This is an an unusual situation, ordinarily
688+
// we should not have any certs in the cert store that we are not able to trust. Still, we
689+
// just specific ally verified trust above. So let's continue on, but without adding this
690+
// to the cert store.
691+
}
692+
else if ( !pPubKey->IsTrusted() )
693+
{
694+
// Key is revoked.
695+
Assert( pPubKey->m_eTrust == k_ETrust_Revoked );
696+
V_sprintf_safe( errMsg, "Cert has untrusted public key. %s", pPubKey->m_status_msg.c_str() );
697+
return nullptr;
698+
}
699+
}
700+
669701
return pResult;
670702
}
671703

@@ -677,7 +709,7 @@ bool CheckCertAppID( const CMsgSteamDatagramCertificate &msgCert, const CertAuth
677709
{
678710
if ( !pCACertAuthScope || pCACertAuthScope->m_apps.HasItem( nAppID ) )
679711
return true;
680-
V_sprintf_safe( errMsg, "Cert is not restricted by appid, by CA trust chain is, and does not authorize %u", nAppID );
712+
V_sprintf_safe( errMsg, "Cert is not restricted by appid, but CA trust chain is, and does not authorize %u", nAppID );
681713
return true;
682714
}
683715

@@ -713,7 +745,7 @@ bool CheckCertPOPID( const CMsgSteamDatagramCertificate &msgCert, const CertAuth
713745
{
714746
if ( !pCACertAuthScope || pCACertAuthScope->m_pops.HasItem( popID ) )
715747
return true;
716-
V_sprintf_safe( errMsg, "Cert is not restricted by POPID, by CA trust chain is, and does not authorize %s", SteamNetworkingPOPIDRender( popID ).c_str() );
748+
V_sprintf_safe( errMsg, "Cert is not restricted by POPID, but CA trust chain is, and does not authorize %s", SteamNetworkingPOPIDRender( popID ).c_str() );
717749
return true;
718750
}
719751

src/steamnetworkingsockets/steamnetworkingsockets_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ extern uint32 Murmorhash32( const void *data, size_t len );
442442
/// although not really cryptographically secure. (We are in charge of the
443443
/// set of public keys and we expect it to be reasonably small.)
444444
extern uint64 CalculatePublicKeyID( const CECSigningPublicKey &pubKey );
445+
extern uint64 CalculatePublicKeyID_Ed25519( const void *pPubKey, size_t cbPubKey );
445446

446447
/// Check an arbitrary signature using the specified public key. (It's assumed that you have
447448
/// already verified that this public key is from somebody you trust.)

0 commit comments

Comments
 (0)