MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / TestOpenSSHEd25519

Function TestOpenSSHEd25519

tests/test_crypto.cpp:541–603  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Test parsing and re-writing of keys in OpenSSH formats -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

539// Purpose: Test parsing and re-writing of keys in OpenSSH formats
540//-----------------------------------------------------------------------------
541void TestOpenSSHEd25519()
542{
543 char buf[ 2048 ];
544
545 // Generate some keys, and make sure we can round trip them
546 {
547 CECSigningPublicKey pubKey;
548 CECSigningPrivateKey privKey;
549 CCrypto::GenerateSigningKeyPair( &pubKey, &privKey );
550
551 uint32 cbBuf;
552
553 // Get public key as authorized_keys format.
554 // Should fail if we tell it the buffer is too small
555 CHECK( !pubKey.GetAsOpenSSHAuthorizedKeys( buf, 16, &cbBuf, "" ) );
556 CHECK( pubKey.GetAsOpenSSHAuthorizedKeys( buf, sizeof(buf), &cbBuf, "" ) );
557 CHECK( (int)cbBuf == V_strlen( buf )+1 );
558 CHECK( 75 <= cbBuf && cbBuf <= 85 ); // typical size (assuming no password or key comment). Not necessarily a bug if this assert fires, but maybe something suspicious
559
560 // Parse it back out, make sure it matches
561 CECSigningPublicKey pubKey2;
562 CHECK( pubKey2.LoadFromAndWipeBuffer( buf, cbBuf ) );
563 CHECK( pubKey2 == pubKey );
564
565 // Get private key in openSSH PEM-ish format.
566 // Should fail if we tell it the buffer is too small
567 CHECK( !privKey.GetAsPEM( buf, 64, &cbBuf ) );
568 CHECK( privKey.GetAsPEM( buf, sizeof(buf), &cbBuf ) );
569 CHECK( (int)cbBuf == V_strlen( buf )+1 );
570 CHECK( 370 <= cbBuf && cbBuf <= 390 ); // typical size (assuming no password or key comment). Not necessarily a bug if this assert fires, but maybe something suspicious
571
572 // Parse it back out, make sure it matches
573 CECSigningPrivateKey privKey2;
574 CHECK( privKey2.LoadFromAndWipeBuffer( buf, cbBuf ) );
575 CHECK( privKey2 == privKey );
576
577 CHECK( privKey2.MatchesPublicKey( pubKey2 ) );
578 }
579
580 // Parse some known keys
581 {
582 CUtlBuffer bufPrivKeyPEMA;
583 bufPrivKeyPEMA.PutString(
584R"PEM(
585-----BEGIN OPENSSH PRIVATE KEY-----
586b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
587QyNTUxOQAAACC3vdN6llE0by4d7aFur0nBXdu5hXJb7LLkiC5UCEPFDgAAAJgJaJG1CWiR
588tQAAAAtzc2gtZWQyNTUxOQAAACC3vdN6llE0by4d7aFur0nBXdu5hXJb7LLkiC5UCEPFDg
589AAAECpUfg4C0BkgsCO+GlFAbcTQZUeFFQcamXzDA1tx7aNWre903qWUTRvLh3toW6vScFd
59027mFclvssuSILlQIQ8UOAAAAEmZsZXRjaGVyZEBzcmNkczAwMwECAw==
591-----END OPENSSH PRIVATE KEY-----
592)PEM" );
593 CECSigningPrivateKey privKeyA;
594 CHECK( privKeyA.LoadFromAndWipeBuffer( bufPrivKeyPEMA.Base(), bufPrivKeyPEMA.TellPut() ) );
595
596 CUtlBuffer bufPubKeyA;
597 bufPubKeyA.PutString( "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILe903qWUTRvLh3toW6vScFd27mFclvssuSILlQIQ8UO" );
598 CECSigningPublicKey pubKeyA;

Callers 1

mainFunction · 0.85

Calls 8

V_strlenFunction · 0.85
LoadFromAndWipeBufferMethod · 0.80
GetAsPEMMethod · 0.80
MatchesPublicKeyMethod · 0.80
PutStringMethod · 0.80
TellPutMethod · 0.80
BaseMethod · 0.45

Tested by

no test coverage detected