Skip to content

Commit

Permalink
Apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
molotkov-and committed Apr 1, 2024
1 parent cfe1eeb commit a92f507
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ TVector<std::pair<TString, TString>> X509CertificateReader::ReadAllSubjectTerms(

int entryCount = X509_NAME_entry_count(name);
subjectTerms.reserve(entryCount);
char buf[1024];
static const int bufLen = sizeof(buf);
for (int i = 0; i < entryCount; i++) {
const X509_NAME_ENTRY* entry = X509_NAME_get_entry(name, i);
if (!entry) {
Expand All @@ -80,17 +78,14 @@ TVector<std::pair<TString, TString>> X509CertificateReader::ReadAllSubjectTerms(
if (!data) {
continue;
}
int dataLen = (data->length > (bufLen - 1)) ? (bufLen - 1) : data->length;
memcpy(buf, data->data, dataLen);
buf[dataLen] = '\0';

const ASN1_OBJECT* object = X509_NAME_ENTRY_get_object(entry);
if (!object) {
continue;
}
int nid = OBJ_obj2nid(object);
const int nid = OBJ_obj2nid(object);
const char* sn = OBJ_nid2sn(nid);
subjectTerms.push_back(std::make_pair(TString(sn, std::strlen(sn)), TString(buf, std::strlen(buf))));
subjectTerms.push_back(std::make_pair(TString(sn, std::strlen(sn)), TString(reinterpret_cast<char*>(data->data), data->length)));
}
return subjectTerms;
}
Expand Down
8 changes: 3 additions & 5 deletions ydb/core/security/ticket_parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,18 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
if (record.TokenType != TDerived::ETokenType::Certificate) {
return false;
}
const static TString error = "Cannot create token from certificate. Cannot extract subject from certificate";
CounterTicketsCertificate->Inc();
X509CertificateReader::X509Ptr x509cert = X509CertificateReader::ReadCertAsPEM(record.Certificate);
if (!x509cert) {
SetError(key, record, { .Message = error, .Retryable = false });
SetError(key, record, { .Message = "Cannot create token from certificate. Cannot read certificate", .Retryable = false });
return false;
}
TStringBuilder dn;
for (const auto& [attribute, value] : X509CertificateReader::ReadAllSubjectTerms(x509cert)) {
dn << attribute << "=" << value << ",";
}
if (dn.empty()) {
SetError(key, record, { .Message = error, .Retryable = false });
SetError(key, record, { .Message = "Cannot create token from certificate. Cannot extract subject from certificate", .Retryable = false });
return false;
}
dn.remove(dn.size() - 1);
Expand Down Expand Up @@ -1547,8 +1546,7 @@ class TTicketParserImpl : public TActorBootstrapped<TDerived> {
} else {
return TDerived::ETokenType::Unsupported;
}
}
if (tokenType == "ApiKey") {
} else if (tokenType == "ApiKey") {
if (ApiKeyEnabled()) {
return TDerived::ETokenType::ApiKey;
} else {
Expand Down

0 comments on commit a92f507

Please sign in to comment.