i具有这些变量定义为任何函数之外的全局变量
//testing parameters (init to all nonfail)
int serverRandom = 0; //nonzero == fail > gotofail for first sha1 methode
SSLBuffer sigpar= 0; //nonzero == fail > gotofail for second sha1 methode
string hashOut = "nonfail"; //"fail" == error condition > gotofail for third sha1 methode
这些变量用于此功能:
static OSStatus SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams, uint8_t *signature, uint16_t signatureLen)
{
OSStatus err;
cout << "initval:"<< serverRandom<< signedParams<< hashOut<<endl;
if ((err = SSLHashSHA1::update(&hashCtx, &serverRandom)) != 0)
cout << "firstfail" <<endl;
goto fail;
if ((err = SSLHashSHA1::update(&hashCtx, &signedParams)) != 0)
cout <<"secondfail"<<endl;
goto fail;
//goto fail;
if ((err = SSLHashSHA1::final(&hashCtx, &hashOut)) != 0)
cout << "thirdfail" << endl;
goto fail;
cout << "nonfail" << endl;
fail:
SSLFreeBuffer(&signedHashes);
SSLFreeBuffer(&hashCtx);
return err;
}
请注意,全局变量ServerRandom和Hashout直接在该函数中访问,而SIGPAR变量被授予sslverify函数的签名Params参数。
现在,我编写了一个单元测试,通过此功能分开测试每个失败的情况
void unittest(){
//all tests passing
cout << "-------------nonfail-------------" << endl;
result = SSLVerifySignedServerKeyExchange(&ctx,isrsa,sigpar,&sig,siglen);
//first test fail
cout << "-------------firstfail-------------" << endl;
serverRandom = 1;
result = SSLVerifySignedServerKeyExchange(&ctx,isrsa,sigpar,&sig,siglen);
serverRandom = 0;
//second test fail
cout << "-------------secondfail-------------" << endl;
sigpar= 1;
result = SSLVerifySignedServerKeyExchange(&ctx,isrsa,sigpar,&sig,siglen);
sigpar= 0;
//third test fail
cout << "-------------thirdfail-------------" << endl;
hashOut = "fail";
result = SSLVerifySignedServerKeyExchange(&ctx,isrsa,sigpar,&sig,siglen);
hashOut = "nonfail";
}
现在,它适用于第一个失败案例,例如。输出FirstFail线。之后,它不再起作用了,因为它仅输出-----------秒fail ---------&amp;------第三fail ---------------------------------------------------------
请注意,sslverify内部的initval ...()显示了正确的值,但是第一个testcause之后的更新/最终功能显示为0作为它们收到的相应值的值。
好吧,最终很容易解决:
在sslverifysignedserverkeyexchange()我添加 cout<<
之后,我只是忘了在多行if
周围添加 {}