Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions openframe/openframe_encryption_service.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
/**
* Copyright (c) 2014-present, The osquery authors
*
* This source code is licensed as defined by the LICENSE file found in the
* root directory of this source tree.
*
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/

#include "openframe_encryption_service.h"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_encryption_service.cpp missing required copyright/SPDX header

Added the canonical osquery copyright/SPDX header block at the top of openframe/openframe_encryption_service.cpp, before the #include block, exactly as suggested in the finding.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.cpp around line 1, review and complete this code-review fix: openframe_encryption_service.cpp missing required copyright/SPDX header.
What the draft fix changed: Added the canonical osquery copyright/SPDX header block at the top of openframe/openframe_encryption_service.cpp, before the #include block, exactly as suggested in the finding.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 95 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_encryption_service.cpp violates all three openframe/ structural conventions

Same structural fix as above: header, namespace, and Status-based error handling applied throughout the file (constructor no longer throws, decrypt/base64Decode/handleOpenSSLError all return Status). Full conformance depends on updating the header file declarations accordingly.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.cpp around line 1, review and complete this code-review fix: openframe_encryption_service.cpp violates all three openframe/ structural conventions.
What the draft fix changed: Same structural fix as above: header, namespace, and Status-based error handling applied throughout the file (constructor no longer throws, decrypt/base64Decode/handleOpenSSLError all return Status). Full conformance depends on updating the header file declarations accordingly.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 75 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include <sstream>
#include <iomanip>

#include <osquery/logger/logger.h>

namespace osquery {

OpenframeEncryptionService::OpenframeEncryptionService(const std::string& secret)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeEncryptionService defined outside the osquery namespace

Wrapped all definitions (constructor, decrypt, base64Decode, handleOpenSSLError) in namespace osquery { ... } at the end of the file. This requires the corresponding header file to also declare the class inside namespace osquery, which is outside this file's scope β€” flagged as a dependency risk.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.cpp around line 8, review and complete this code-review fix: OpenframeEncryptionService defined outside the osquery namespace.
What the draft fix changed: Wrapped all definitions (constructor, decrypt, base64Decode, handleOpenSSLError) in `namespace osquery { ... }` at the end of the file. This requires the corresponding header file to also declare the class inside `namespace osquery`, which is outside this file's scope β€” flagged as a dependency risk.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 85 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

: secret_(secret) {
if (secret_.empty()) {
throw std::runtime_error("Secret cannot be empty");
}
}

std::string OpenframeEncryptionService::decrypt(const std::string& data) {
Status OpenframeEncryptionService::decrypt(const std::string& data, std::string& result) {
if (secret_.empty()) {
throw std::runtime_error("Encryption service not initialized with secret");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeEncryptionService throws std::runtime_error instead of returning Status

Changed decrypt() and the constructor to return osquery::Status instead of throwing std::runtime_error; decrypt() now takes an out-parameter std::string& result and returns Status, matching the aws_firehose.cpp convention. This is a signature/API change that requires updating the header (openframe_encryption_service.h) and all call sites, which are not visible in this file β€” those changes are necessary for the code to compile and are unverified here.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.cpp around line 17, review and complete this code-review fix: OpenframeEncryptionService throws std::runtime_error instead of returning Status.
What the draft fix changed: Changed decrypt() and the constructor to return osquery::Status instead of throwing std::runtime_error; decrypt() now takes an out-parameter `std::string& result` and returns Status, matching the aws_firehose.cpp convention. This is a signature/API change that requires updating the header (openframe_encryption_service.h) and all call sites, which are not visible in this file β€” those changes are necessary for the code to compile and are unverified here.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 70 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

return Status::failure("Encryption service not initialized with secret");
}

if (secret_.size() != 32) {
return Status::failure("Secret must be exactly 32 bytes for AES-256-GCM");
}

// Decode base64 data
auto decoded = base64Decode(data);
std::vector<unsigned char> decoded;
auto status = base64Decode(data, decoded);
if (!status.ok()) {
return status;
}
if (decoded.size() < IV_SIZE + TAG_SIZE) {
throw std::runtime_error("Invalid encrypted data size");
return Status::failure("Invalid encrypted data size");
}

// Extract IV (first 12 bytes) and tag (last 16 bytes)
Expand All @@ -31,21 +49,21 @@ std::string OpenframeEncryptionService::decrypt(const std::string& data) {
// Create and initialize the context
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
if (!ctx) {
handleOpenSSLError();
return handleOpenSSLError();
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ AES-256-GCM decrypt uses raw secret string as key without deriving/validating 32-byte key length

Added an explicit length check if (secret_.size() != 32) in decrypt() before calling EVP_DecryptInit_ex, returning Status::failure() if the secret is not exactly 32 bytes, preventing the out-of-bounds/truncation issue with the raw secret used as an AES-256 key. Does not add a proper KDF (e.g. HKDF) β€” a complete fix would derive the key rather than only validating length, which is a larger design decision left for review.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.cpp around line 36, review and complete this code-review fix: AES-256-GCM decrypt uses raw secret string as key without deriving/validating 32-byte key length.
What the draft fix changed: Added an explicit length check `if (secret_.size() != 32)` in decrypt() before calling EVP_DecryptInit_ex, returning Status::failure() if the secret is not exactly 32 bytes, preventing the out-of-bounds/truncation issue with the raw secret used as an AES-256 key. Does not add a proper KDF (e.g. HKDF) β€” a complete fix would derive the key rather than only validating length, which is a larger design decision left for review.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 80 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

// Initialize the decryption operation
if (1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), nullptr,
reinterpret_cast<const unsigned char*>(secret_.c_str()),
iv.data())) {
EVP_CIPHER_CTX_free(ctx);
handleOpenSSLError();
return handleOpenSSLError();
}

// Set the tag
if (1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, TAG_SIZE, tag.data())) {
EVP_CIPHER_CTX_free(ctx);
handleOpenSSLError();
return handleOpenSSLError();
}

// Decrypt the ciphertext
Expand All @@ -54,24 +72,25 @@ std::string OpenframeEncryptionService::decrypt(const std::string& data) {
if (1 != EVP_DecryptUpdate(ctx, plaintext.data(), &len,
ciphertext.data(), ciphertext.size())) {
EVP_CIPHER_CTX_free(ctx);
handleOpenSSLError();
return handleOpenSSLError();
}

// Finalize the decryption
int finalLen = 0;
if (1 != EVP_DecryptFinal_ex(ctx, plaintext.data() + len, &finalLen)) {
EVP_CIPHER_CTX_free(ctx);
handleOpenSSLError();
return handleOpenSSLError();
}

// Clean up
EVP_CIPHER_CTX_free(ctx);

// Convert the decrypted data to string
return std::string(plaintext.begin(), plaintext.begin() + len + finalLen);
result = std::string(plaintext.begin(), plaintext.begin() + len + finalLen);
return Status::success();
}

std::vector<unsigned char> OpenframeEncryptionService::base64Decode(const std::string& encoded) {
Status OpenframeEncryptionService::base64Decode(const std::string& encoded, std::vector<unsigned char>& result) {
BIO* b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);

Expand All @@ -84,20 +103,25 @@ std::vector<unsigned char> OpenframeEncryptionService::base64Decode(const std::s
BIO_free_all(bmem);

if (decodedLen < 0) {
throw std::runtime_error("Failed to decode base64 data");
return Status::failure("Failed to decode base64 data");
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 handleOpenSSLError builds diagnostic string without using LOG() macros

In handleOpenSSLError(), added LOG(ERROR) << message; (via new #include <osquery/logger/logger.h>) before returning Status::failure(message), so the OpenSSL diagnostic string is now logged through the standard osquery logger in addition to being returned as an error Status.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.cpp around line 88, review and complete this code-review fix: handleOpenSSLError builds diagnostic string without using LOG() macros.
What the draft fix changed: In handleOpenSSLError(), added `LOG(ERROR) << message;` (via new `#include <osquery/logger/logger.h>`) before returning Status::failure(message), so the OpenSSL diagnostic string is now logged through the standard osquery logger in addition to being returned as an error Status.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 85 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer


decoded.resize(decodedLen);
return decoded;
result = std::move(decoded);
return Status::success();
}

void OpenframeEncryptionService::handleOpenSSLError() {
Status OpenframeEncryptionService::handleOpenSSLError() {
std::stringstream ss;
unsigned long err;
while ((err = ERR_get_error()) != 0) {
char err_buf[256];
ERR_error_string_n(err, err_buf, sizeof(err_buf));
ss << err_buf << "; ";
}
throw std::runtime_error("OpenSSL error: " + ss.str());
}
std::string message = "OpenSSL error: " + ss.str();
LOG(ERROR) << message;
return Status::failure(message);
}

} // namespace osquery
22 changes: 18 additions & 4 deletions openframe/openframe_encryption_service.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Copyright (c) 2014-present, The osquery authors
*
* This source code is licensed as defined by the LICENSE file found in the
* root directory of this source tree.
*
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/
#pragma once

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_encryption_service.h missing standard osquery copyright/SPDX header

Prepended the canonical osquery copyright/SPDX header block (Copyright (c) 2014-present, The osquery authors ... SPDX-License-Identifier) above #pragma once at the top of the file, matching the convention used in other repo files.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.h around line 1, review and complete this code-review fix: openframe_encryption_service.h missing standard osquery copyright/SPDX header.
What the draft fix changed: Prepended the canonical osquery copyright/SPDX header block (Copyright (c) 2014-present, The osquery authors ... SPDX-License-Identifier) above `#pragma once` at the top of the file, matching the convention used in other repo files.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 92 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer


#include <string>
Expand All @@ -8,6 +16,10 @@
#include <openssl/err.h>
#include <stdexcept>

#include <osquery/utils/status/status.h>

namespace osquery {

class OpenframeEncryptionService {
public:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeEncryptionService class defined outside the osquery namespace

Wrapped the OpenframeEncryptionService class declaration in namespace osquery { ... } (opening brace added before the class, closing brace with // namespace osquery comment added at end of file), matching the convention in openframe_token_refresher.h.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.h around line 12, review and complete this code-review fix: OpenframeEncryptionService class defined outside the osquery namespace.
What the draft fix changed: Wrapped the `OpenframeEncryptionService` class declaration in `namespace osquery { ... }` (opening brace added before the class, closing brace with `// namespace osquery` comment added at end of file), matching the convention in `openframe_token_refresher.h`.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 88 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

explicit OpenframeEncryptionService(const std::string& secret);
Comment on lines 16 to 25

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ decrypt() documented to throw std::runtime_error instead of returning Status

Changed decrypt()'s signature from std::string decrypt(const std::string& data) (documented to throw std::runtime_error) to Status decrypt(const std::string& data, std::string& out), updated the Doxygen comment to describe Status-based error reporting instead of throwing, and added #include <osquery/utils/status/status.h> for the Status type. This is a header-only signature change; the corresponding .cpp implementation (not provided/visible) will need to be updated to match this new signature and to return Status::failure(...) instead of throwing, which is outside the scope of this single file and unverified here.

πŸ€– Prompt for AI agents
In openframe/openframe_encryption_service.h around line 14, review and complete this code-review fix: decrypt() documented to throw std::runtime_error instead of returning Status.
What the draft fix changed: Changed `decrypt()`'s signature from `std::string decrypt(const std::string& data)` (documented to throw `std::runtime_error`) to `Status decrypt(const std::string& data, std::string& out)`, updated the Doxygen comment to describe Status-based error reporting instead of throwing, and added `#include <osquery/utils/status/status.h>` for the `Status` type. This is a header-only signature change; the corresponding .cpp implementation (not provided/visible) will need to be updated to match this new signature and to return `Status::failure(...)` instead of throwing, which is outside the scope of this single file and unverified here.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 70 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Expand All @@ -16,10 +28,10 @@ class OpenframeEncryptionService {
/**
* Decrypts data using AES-GCM
* @param data Base64 encoded encrypted data
* @return Decrypted data as string
* @throws std::runtime_error if decryption fails
* @param out Decrypted data as string, populated on success
* @return Status::success() on success, Status::failure() with an error message on failure
*/
std::string decrypt(const std::string& data);
Status decrypt(const std::string& data, std::string& out);

std::vector<unsigned char> base64Decode(const std::string& encoded);

Expand All @@ -31,4 +43,6 @@ class OpenframeEncryptionService {
void handleOpenSSLError();

std::string secret_;
};
};

} // namespace osquery
34 changes: 27 additions & 7 deletions openframe/openframe_token_extractor.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
/**
* Copyright (c) 2014-present, The osquery authors
*
* This source code is licensed as defined by the LICENSE file found in the
* root directory of this source tree.
*
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/

#include "openframe_token_extractor.h"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_token_extractor.cpp missing the standard osquery copyright/SPDX header

Added the standard osquery copyright/SPDX header block at the top of the file, before the #include directives, matching the canonical form used elsewhere in the repo.

πŸ€– Prompt for AI agents
In openframe/openframe_token_extractor.cpp around line 1, review and complete this code-review fix: openframe_token_extractor.cpp missing the standard osquery copyright/SPDX header.
What the draft fix changed: Added the standard osquery copyright/SPDX header block at the top of the file, before the `#include` directives, matching the canonical form used elsewhere in the repo.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 95 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

#include <fstream>
#include <stdexcept>

#include <osquery/logger/logger.h>

namespace osquery {

OpenframeTokenExtractor::OpenframeTokenExtractor(std::shared_ptr<OpenframeEncryptionService> encryption_service,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeTokenExtractor class defined outside the osquery namespace

Wrapped the entire file's contents (constructor and extractToken/now extractToken(std::string&)) in namespace osquery { ... }, with the closing brace and // namespace osquery comment at end of file. Note: this assumes the corresponding header openframe_token_extractor.h also declares the class inside namespace osquery; that header is not shown/editable here, so if it doesn't match, this will fail to compile β€” flagging as a cross-file dependency risk.

πŸ€– Prompt for AI agents
In openframe/openframe_token_extractor.cpp around line 5, review and complete this code-review fix: OpenframeTokenExtractor class defined outside the osquery namespace.
What the draft fix changed: Wrapped the entire file's contents (constructor and `extractToken`/now `extractToken(std::string&)`) in `namespace osquery { ... }`, with the closing brace and `// namespace osquery` comment at end of file. Note: this assumes the corresponding header `openframe_token_extractor.h` also declares the class inside `namespace osquery`; that header is not shown/editable here, so if it doesn't match, this will fail to compile β€” flagging as a cross-file dependency risk.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 90 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

const std::string& token_file_path)
: encryption_service_(encryption_service), token_file_path_(token_file_path) {
if (!encryption_service_) {
LOG(ERROR) << "Encryption service cannot be null";
throw std::runtime_error("Encryption service cannot be null");
}
if (token_file_path_.empty()) {
LOG(ERROR) << "Token file path cannot be empty";
throw std::runtime_error("Token file path cannot be empty");
}
}

std::string OpenframeTokenExtractor::extractToken() {
Status OpenframeTokenExtractor::extractToken(std::string& token) {
// Open the token file
std::ifstream token_file(token_file_path_);
if (!token_file.is_open()) {
throw std::runtime_error("Failed to open token file at: " + token_file_path_);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeTokenExtractor throws std::runtime_error instead of returning osquery::Status

Changed extractToken()'s signature from std::string extractToken() to Status extractToken(std::string& token) in the .cpp, replacing all throw std::runtime_error(...) calls in extractToken with return Status::failure(...) and setting the output token via the by-reference parameter on success. The constructor still throws std::runtime_error since constructors cannot return a Status; this is a partial fix limited to what's achievable in this file's function signatures. A complete fix additionally requires updating openframe_token_extractor.h (not editable here) to change the declared signature of extractToken, and updating all call sites to check .ok() instead of using try/catch β€” those are outside this file and unverified.

πŸ€– Prompt for AI agents
In openframe/openframe_token_extractor.cpp around line 20, review and complete this code-review fix: OpenframeTokenExtractor throws std::runtime_error instead of returning osquery::Status.
What the draft fix changed: Changed `extractToken()`'s signature from `std::string extractToken()` to `Status extractToken(std::string& token)` in the .cpp, replacing all `throw std::runtime_error(...)` calls in `extractToken` with `return Status::failure(...)` and setting the output token via the by-reference parameter on success. The constructor still throws `std::runtime_error` since constructors cannot return a `Status`; this is a partial fix limited to what's achievable in this file's function signatures. A complete fix additionally requires updating `openframe_token_extractor.h` (not editable here) to change the declared signature of `extractToken`, and updating all call sites to check `.ok()` instead of using try/catch β€” those are outside this file and unverified.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 60 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

LOG(WARNING) << "Failed to open token file at: " << token_file_path_;
return Status::failure("Failed to open token file at: " + token_file_path_);
}

// Read the encrypted token
Expand All @@ -26,13 +41,18 @@ std::string OpenframeTokenExtractor::extractToken() {
token_file.close();

if (encrypted_token.empty()) {
throw std::runtime_error("Token file is empty");
LOG(WARNING) << "Token file is empty: " << token_file_path_;
return Status::failure("Token file is empty");
}

try {
// Decrypt the token using the encryption service

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 openframe_token_extractor.cpp has no diagnostic logging via LOG()/VLOG()

Added #include <osquery/logger/logger.h> and inserted LOG(ERROR)/LOG(WARNING) calls immediately before each failure path in the constructor and extractToken (null encryption service, empty path, missing file, empty file, decrypt failure), mirroring the LOG-then-return/throw pattern used elsewhere in the codebase.

πŸ€– Prompt for AI agents
In openframe/openframe_token_extractor.cpp around line 33, review and complete this code-review fix: openframe_token_extractor.cpp has no diagnostic logging via LOG()/VLOG().
What the draft fix changed: Added `#include <osquery/logger/logger.h>` and inserted `LOG(ERROR)`/`LOG(WARNING)` calls immediately before each failure path in the constructor and `extractToken` (null encryption service, empty path, missing file, empty file, decrypt failure), mirroring the LOG-then-return/throw pattern used elsewhere in the codebase.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 70 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

return encryption_service_->decrypt(encrypted_token);
token = encryption_service_->decrypt(encrypted_token);
return Status::success();
} catch (const std::exception& e) {
throw std::runtime_error("Failed to decrypt token: " + std::string(e.what()));
LOG(WARNING) << "Failed to decrypt token: " << e.what();
return Status::failure("Failed to decrypt token: " + std::string(e.what()));
}
}
}

} // namespace osquery
15 changes: 14 additions & 1 deletion openframe/openframe_token_extractor.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/**
* Copyright (c) 2014-present, The osquery authors
*
* This source code is licensed as defined by the LICENSE file found in the
* root directory of this source tree.
*
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/

#pragma once

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_token_extractor.h missing standard osquery copyright/SPDX header

Added the canonical osquery copyright/SPDX header block at the top of the file, before the #pragma once line, matching the format used in other production headers.

πŸ€– Prompt for AI agents
In openframe/openframe_token_extractor.h around line 1, review and complete this code-review fix: openframe_token_extractor.h missing standard osquery copyright/SPDX header.
What the draft fix changed: Added the canonical osquery copyright/SPDX header block at the top of the file, before the `#pragma once` line, matching the format used in other production headers.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 96 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeTokenExtractor class defined outside the osquery namespace

Wrapped the OpenframeTokenExtractor class declaration in namespace osquery { ... }, opening the namespace after the includes and closing it with } // namespace osquery at the end of the file, consistent with the sibling header openframe_authorization_manager.h.

πŸ€– Prompt for AI agents
In openframe/openframe_token_extractor.h around line 1, review and complete this code-review fix: OpenframeTokenExtractor class defined outside the osquery namespace.
What the draft fix changed: Wrapped the `OpenframeTokenExtractor` class declaration in `namespace osquery { ... }`, opening the namespace after the includes and closing it with `} // namespace osquery` at the end of the file, consistent with the sibling header `openframe_authorization_manager.h`.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 90 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer


#include <string>
#include <memory>
#include "openframe_encryption_service.h"

namespace osquery {

class OpenframeTokenExtractor {
public:
explicit OpenframeTokenExtractor(std::shared_ptr<OpenframeEncryptionService> encryption_service,
Expand All @@ -16,4 +27,6 @@ class OpenframeTokenExtractor {
private:
std::string token_file_path_;
std::shared_ptr<OpenframeEncryptionService> encryption_service_;
};
};

} // namespace osquery
18 changes: 16 additions & 2 deletions openframe/openframe_token_refresher.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Copyright (c) 2014-present, The osquery authors
*
* This source code is licensed as defined by the LICENSE file found in the
* root directory of this source tree.
*
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/

#include "openframe_token_refresher.h"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ Missing osquery copyright/SPDX header in openframe_token_refresher.cpp

Added the standard osquery copyright/SPDX header block at the top of openframe/openframe_token_refresher.cpp, before the #include lines, matching the style used in other .cpp files (tls_enroll.cpp, python_packages.cpp).

πŸ€– Prompt for AI agents
In openframe/openframe_token_refresher.cpp around line 1, review and complete this code-review fix: Missing osquery copyright/SPDX header in openframe_token_refresher.cpp.
What the draft fix changed: Added the standard osquery copyright/SPDX header block at the top of openframe/openframe_token_refresher.cpp, before the `#include` lines, matching the style used in other .cpp files (tls_enroll.cpp, python_packages.cpp).
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 95 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_token_refresher.cpp violates all three openframe/ structural conventions simultaneously

Combined fix of items 1 and 2 above (header added, throw removed) directly addresses the compounded finding about openframe/ structural conventions (header, namespace already correct, and Status/exception-based error handling) within this single file; namespace osquery was already present and unchanged.

πŸ€– Prompt for AI agents
In openframe/openframe_token_refresher.cpp around line 1, review and complete this code-review fix: openframe_token_refresher.cpp violates all three openframe/ structural conventions simultaneously.
What the draft fix changed: Combined fix of items 1 and 2 above (header added, throw removed) directly addresses the compounded finding about openframe/ structural conventions (header, namespace already correct, and Status/exception-based error handling) within this single file; namespace `osquery` was already present and unchanged.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 75 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

#include "openframe_authorization_manager_provider.h"

Expand All @@ -6,7 +15,7 @@ namespace osquery {
OpenframeTokenRefresher::OpenframeTokenRefresher(std::shared_ptr<OpenframeTokenExtractor> extractor)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ OpenframeTokenRefresher constructor throws std::runtime_error instead of returning Status

Removed the throw std::runtime_error(...) from the OpenframeTokenRefresher constructor and replaced it with a LOG(ERROR) call describing the null extractor condition. Since a constructor cannot return Status, a full factory/StatusOr refactor was avoided as out-of-scope/architectural; instead added a defensive guard in start() that checks extractor_ and logs an error/returns early rather than dereferencing a null pointer in process(), keeping behavior safe without throwing. A complete fix per convention would introduce a static factory method (e.g., Status OpenframeTokenRefresher::create(...)) returning Status/StatusOr<std::unique_ptr<OpenframeTokenRefresher>>, but that would require changes to the header file and call sites outside this file's scope.

πŸ€– Prompt for AI agents
In openframe/openframe_token_refresher.cpp around line 6, review and complete this code-review fix: OpenframeTokenRefresher constructor throws std::runtime_error instead of returning Status.
What the draft fix changed: Removed the `throw std::runtime_error(...)` from the `OpenframeTokenRefresher` constructor and replaced it with a `LOG(ERROR)` call describing the null extractor condition. Since a constructor cannot return `Status`, a full factory/StatusOr refactor was avoided as out-of-scope/architectural; instead added a defensive guard in `start()` that checks `extractor_` and logs an error/returns early rather than dereferencing a null pointer in `process()`, keeping behavior safe without throwing. A complete fix per convention would introduce a static factory method (e.g., `Status OpenframeTokenRefresher::create(...)`) returning `Status`/`StatusOr<std::unique_ptr<OpenframeTokenRefresher>>`, but that would require changes to the header file and call sites outside this file's scope.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟑 70 medium β€” react πŸ‘/πŸ‘Ž to teach the reviewer

: running_(false), extractor_(extractor) {
if (!extractor_) {
throw std::runtime_error("Token extractor cannot be null");
LOG(ERROR) << "Token extractor cannot be null; token refresher will be inoperative";
}
}

Expand All @@ -21,6 +30,11 @@ void OpenframeTokenRefresher::start() {
return;
}

if (!extractor_) {
LOG(ERROR) << "Cannot start token refresher: token extractor is null";
return;
}

running_ = true;
refresh_thread_ = std::thread([this]() {
while (running_) {
Expand Down Expand Up @@ -68,4 +82,4 @@ void OpenframeTokenRefresher::process() {
}
}

} // namespace osquery
} // namespace osquery
11 changes: 10 additions & 1 deletion openframe/openframe_token_refresher.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Copyright (c) 2014-present, The osquery authors
*
* This source code is licensed as defined by the LICENSE file found in the
* root directory of this source tree.
*
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
*/

#pragma once

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 πŸ”΄ openframe_token_refresher.h missing standard osquery copyright/SPDX header

Prepended the standard osquery Copyright/SPDX header block (matching the format used in other compliant headers like aws_kinesis.h) immediately before #pragma once at the top of openframe/openframe_token_refresher.h. No other lines were changed.

πŸ€– Prompt for AI agents
In openframe/openframe_token_refresher.h around line 1, review and complete this code-review fix: openframe_token_refresher.h missing standard osquery copyright/SPDX header.
What the draft fix changed: Prepended the standard osquery Copyright/SPDX header block (matching the format used in other compliant headers like aws_kinesis.h) immediately before `#pragma once` at the top of openframe/openframe_token_refresher.h. No other lines were changed.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 90 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer


#include <string>
Expand Down Expand Up @@ -30,4 +39,4 @@ class OpenframeTokenRefresher {
std::shared_ptr<OpenframeTokenExtractor> extractor_;
};

} // namespace osquery
} // namespace osquery
Loading