mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Cleanup/improve PList usage and Event API
Majority of PLists are now created as automatic/stack objects, rather than on heap and initialized either with the known-capacity reserved upfront or directly from an initializer_list (so there's no wasted slack in the memory that gets allocated for lists containing a fixed/known number of elements). Added versions of the ConnectionEvent/QueueEvent methods that take a val_list by value. Added a move ctor/assign-operator to Plists to allow passing them around without having to copy the underlying array of pointers.
This commit is contained in:
parent
78dcbcc71a
commit
8bc65f09ec
92 changed files with 1585 additions and 1679 deletions
|
@ -417,10 +417,6 @@ void file_analysis::OCSP::ParseRequest(OCSP_REQUEST* req)
|
|||
char buf[OCSP_STRING_BUF_SIZE]; // we need a buffer for some of the openssl functions
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
// build up our response as we go along...
|
||||
val_list* vl = new val_list();
|
||||
vl->append(GetFile()->GetVal()->Ref());
|
||||
|
||||
uint64 version = 0;
|
||||
|
||||
#if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER)
|
||||
|
@ -431,23 +427,24 @@ void file_analysis::OCSP::ParseRequest(OCSP_REQUEST* req)
|
|||
// TODO: try to parse out general name ?
|
||||
#endif
|
||||
|
||||
vl->append(val_mgr->GetCount(version));
|
||||
mgr.QueueEvent(ocsp_request, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
val_mgr->GetCount(version),
|
||||
});
|
||||
|
||||
BIO *bio = BIO_new(BIO_s_mem());
|
||||
|
||||
mgr.QueueEvent(ocsp_request, vl);
|
||||
|
||||
int req_count = OCSP_request_onereq_count(req);
|
||||
for ( int i=0; i<req_count; i++ )
|
||||
{
|
||||
val_list* rvl = new val_list();
|
||||
rvl->append(GetFile()->GetVal()->Ref());
|
||||
val_list rvl(5);
|
||||
rvl.append(GetFile()->GetVal()->Ref());
|
||||
|
||||
OCSP_ONEREQ *one_req = OCSP_request_onereq_get0(req, i);
|
||||
OCSP_CERTID *cert_id = OCSP_onereq_get0_id(one_req);
|
||||
|
||||
ocsp_add_cert_id(cert_id, rvl, bio);
|
||||
mgr.QueueEvent(ocsp_request_certificate, rvl);
|
||||
ocsp_add_cert_id(cert_id, &rvl, bio);
|
||||
mgr.QueueEvent(ocsp_request_certificate, std::move(rvl));
|
||||
}
|
||||
|
||||
BIO_free(bio);
|
||||
|
@ -470,14 +467,13 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
char buf[OCSP_STRING_BUF_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
val_list* vl = new val_list();
|
||||
vl->append(GetFile()->GetVal()->Ref());
|
||||
|
||||
const char *status_str = OCSP_response_status_str(OCSP_response_status(resp));
|
||||
StringVal* status_val = new StringVal(strlen(status_str), status_str);
|
||||
vl->append(status_val->Ref());
|
||||
mgr.QueueEvent(ocsp_response_status, vl);
|
||||
vl = nullptr;
|
||||
|
||||
mgr.QueueEvent(ocsp_response_status, {
|
||||
GetFile()->GetVal()->Ref(),
|
||||
status_val->Ref(),
|
||||
});
|
||||
|
||||
//if (!resp_bytes)
|
||||
// {
|
||||
|
@ -490,6 +486,8 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
//int len = BIO_read(bio, buf, sizeof(buf));
|
||||
//BIO_reset(bio);
|
||||
|
||||
val_list vl(8);
|
||||
|
||||
// get the basic response
|
||||
basic_resp = OCSP_response_get1_basic(resp);
|
||||
if ( !basic_resp )
|
||||
|
@ -501,28 +499,27 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
goto clean_up;
|
||||
#endif
|
||||
|
||||
vl = new val_list();
|
||||
vl->append(GetFile()->GetVal()->Ref());
|
||||
vl->append(resp_val->Ref());
|
||||
vl->append(status_val);
|
||||
vl.append(GetFile()->GetVal()->Ref());
|
||||
vl.append(resp_val->Ref());
|
||||
vl.append(status_val);
|
||||
|
||||
#if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER)
|
||||
vl->append(val_mgr->GetCount((uint64)ASN1_INTEGER_get(resp_data->version)));
|
||||
vl.append(val_mgr->GetCount((uint64)ASN1_INTEGER_get(resp_data->version)));
|
||||
#else
|
||||
vl->append(parse_basic_resp_data_version(basic_resp));
|
||||
vl.append(parse_basic_resp_data_version(basic_resp));
|
||||
#endif
|
||||
|
||||
// responderID
|
||||
if ( OCSP_RESPID_bio(basic_resp, bio) )
|
||||
{
|
||||
len = BIO_read(bio, buf, sizeof(buf));
|
||||
vl->append(new StringVal(len, buf));
|
||||
vl.append(new StringVal(len, buf));
|
||||
BIO_reset(bio);
|
||||
}
|
||||
else
|
||||
{
|
||||
reporter->Weird("OpenSSL failed to get OCSP responder id");
|
||||
vl->append(val_mgr->GetEmptyString());
|
||||
vl.append(val_mgr->GetEmptyString());
|
||||
}
|
||||
|
||||
// producedAt
|
||||
|
@ -532,7 +529,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
produced_at = OCSP_resp_get0_produced_at(basic_resp);
|
||||
#endif
|
||||
|
||||
vl->append(new Val(GetTimeFromAsn1(produced_at, GetFile(), reporter), TYPE_TIME));
|
||||
vl.append(new Val(GetTimeFromAsn1(produced_at, GetFile(), reporter), TYPE_TIME));
|
||||
|
||||
// responses
|
||||
|
||||
|
@ -545,8 +542,8 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
if ( !single_resp )
|
||||
continue;
|
||||
|
||||
val_list* rvl = new val_list();
|
||||
rvl->append(GetFile()->GetVal()->Ref());
|
||||
val_list rvl(10);
|
||||
rvl.append(GetFile()->GetVal()->Ref());
|
||||
|
||||
// cert id
|
||||
const OCSP_CERTID* cert_id = nullptr;
|
||||
|
@ -557,7 +554,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
cert_id = OCSP_SINGLERESP_get0_id(single_resp);
|
||||
#endif
|
||||
|
||||
ocsp_add_cert_id(cert_id, rvl, bio);
|
||||
ocsp_add_cert_id(cert_id, &rvl, bio);
|
||||
BIO_reset(bio);
|
||||
|
||||
// certStatus
|
||||
|
@ -574,38 +571,38 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
reporter->Weird("OpenSSL failed to find status of OCSP response");
|
||||
|
||||
const char* cert_status_str = OCSP_cert_status_str(status);
|
||||
rvl->append(new StringVal(strlen(cert_status_str), cert_status_str));
|
||||
rvl.append(new StringVal(strlen(cert_status_str), cert_status_str));
|
||||
|
||||
// revocation time and reason if revoked
|
||||
if ( status == V_OCSP_CERTSTATUS_REVOKED )
|
||||
{
|
||||
rvl->append(new Val(GetTimeFromAsn1(revoke_time, GetFile(), reporter), TYPE_TIME));
|
||||
rvl.append(new Val(GetTimeFromAsn1(revoke_time, GetFile(), reporter), TYPE_TIME));
|
||||
|
||||
if ( reason != OCSP_REVOKED_STATUS_NOSTATUS )
|
||||
{
|
||||
const char* revoke_reason = OCSP_crl_reason_str(reason);
|
||||
rvl->append(new StringVal(strlen(revoke_reason), revoke_reason));
|
||||
rvl.append(new StringVal(strlen(revoke_reason), revoke_reason));
|
||||
}
|
||||
else
|
||||
rvl->append(new StringVal(0, ""));
|
||||
rvl.append(new StringVal(0, ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
rvl->append(new Val(0.0, TYPE_TIME));
|
||||
rvl->append(new StringVal(0, ""));
|
||||
rvl.append(new Val(0.0, TYPE_TIME));
|
||||
rvl.append(new StringVal(0, ""));
|
||||
}
|
||||
|
||||
if ( this_update )
|
||||
rvl->append(new Val(GetTimeFromAsn1(this_update, GetFile(), reporter), TYPE_TIME));
|
||||
rvl.append(new Val(GetTimeFromAsn1(this_update, GetFile(), reporter), TYPE_TIME));
|
||||
else
|
||||
rvl->append(new Val(0.0, TYPE_TIME));
|
||||
rvl.append(new Val(0.0, TYPE_TIME));
|
||||
|
||||
if ( next_update )
|
||||
rvl->append(new Val(GetTimeFromAsn1(next_update, GetFile(), reporter), TYPE_TIME));
|
||||
rvl.append(new Val(GetTimeFromAsn1(next_update, GetFile(), reporter), TYPE_TIME));
|
||||
else
|
||||
rvl->append(new Val(0.0, TYPE_TIME));
|
||||
rvl.append(new Val(0.0, TYPE_TIME));
|
||||
|
||||
mgr.QueueEvent(ocsp_response_certificate, rvl);
|
||||
mgr.QueueEvent(ocsp_response_certificate, std::move(rvl));
|
||||
|
||||
num_ext = OCSP_SINGLERESP_get_ext_count(single_resp);
|
||||
for ( int k = 0; k < num_ext; ++k )
|
||||
|
@ -621,10 +618,10 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
#if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER)
|
||||
i2a_ASN1_OBJECT(bio, basic_resp->signatureAlgorithm->algorithm);
|
||||
len = BIO_read(bio, buf, sizeof(buf));
|
||||
vl->append(new StringVal(len, buf));
|
||||
vl.append(new StringVal(len, buf));
|
||||
BIO_reset(bio);
|
||||
#else
|
||||
vl->append(parse_basic_resp_sig_alg(basic_resp, bio, buf, sizeof(buf)));
|
||||
vl.append(parse_basic_resp_sig_alg(basic_resp, bio, buf, sizeof(buf)));
|
||||
#endif
|
||||
|
||||
//i2a_ASN1_OBJECT(bio, basic_resp->signature);
|
||||
|
@ -633,7 +630,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
//BIO_reset(bio);
|
||||
|
||||
certs_vector = new VectorVal(internal_type("x509_opaque_vector")->AsVectorType());
|
||||
vl->append(certs_vector);
|
||||
vl.append(certs_vector);
|
||||
|
||||
#if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER)
|
||||
certs = basic_resp->certs;
|
||||
|
@ -654,7 +651,8 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPVal *resp_val)
|
|||
reporter->Weird("OpenSSL returned null certificate");
|
||||
}
|
||||
}
|
||||
mgr.QueueEvent(ocsp_response_bytes, vl);
|
||||
|
||||
mgr.QueueEvent(ocsp_response_bytes, std::move(vl));
|
||||
|
||||
// ok, now that we are done with the actual certificate - let's parse extensions :)
|
||||
num_ext = OCSP_BASICRESP_get_ext_count(basic_resp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue