Skip to content

impl(bq_driver): Implementing Configuration Properties- UseSystemTrustStore#1337

Merged
sachinpro merged 2 commits into
mainfrom
system_trust_store_impl
May 13, 2026
Merged

impl(bq_driver): Implementing Configuration Properties- UseSystemTrustStore#1337
sachinpro merged 2 commits into
mainfrom
system_trust_store_impl

Conversation

@Khushikathuria008
Copy link
Copy Markdown
Collaborator

@Khushikathuria008 Khushikathuria008 commented Dec 12, 2025

No description provided.

auto conn = std::make_shared<ODBCHandles>();
EXPECT_EQ(Connect(kDefaultConnectionString, conn), SQL_SUCCESS);
std::string connection_string =
kDefaultConnectionString + ";UseSystemTrustStore=1;";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is windows only feature , please add a flag

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done


struct SslCredentials {
std::string pem_root_certs;
bool use_system_trust_store = false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's add this under windows only flag as well

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@shivamd-gpartner shivamd-gpartner marked this pull request as ready for review December 15, 2025 06:47
@shivamd-gpartner shivamd-gpartner requested review from a team and sachinpro December 15, 2025 06:47
namespace {

#ifdef _WIN32
std::string ExportWindowsSystemCertsToPem() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please write a unit test case for this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@shivamd-gpartner
Copy link
Copy Markdown
Collaborator

@Khushikathuria008 approved, please write unit test case for the function

}

#ifdef _WIN32
TEST(ExportWindowsSystemCertsToPemTest, ReturnsValidPemFilePath) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we can combine all these three test cases in one as they are all doing basically the same thing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@sachinpro sachinpro changed the title impl(bq_driver): Implementing Configuration Properties- UseSystemTrus… impl(bq_driver): Implementing Configuration Properties- UseSystemTrustStore Dec 17, 2025
// -----------------------------
// Create a REAL temp .pem file directly
// -----------------------------
char temp_path[MAX_PATH];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't spend much time on this but verify once if client libraries have a way of setting directly the file contents in binary.

#ifdef _WIN32
// UseSystemTrustStore is only valid on Windows.
std::string connection_string =
kDefaultConnectionString + ";UseSystemTrustStore=1;";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not validating the behaviour since removing this line will still make the tast succeed.

Please modify an HTAPI test(SQLExecDirect_htapi_basictypes let's say) to disable using the packaged pem file, validate the error, set UseSystemTrustStore . There should be no errors finally.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done
Made a separate testcase as this change is only valid for windows.
Existing driver gives error while we do a driver connect whereas our driver gives error when we run a query.


namespace {
#ifdef _WIN32
std::string ExportWindowsSystemCertsToPem() {
Copy link
Copy Markdown
Collaborator

@sachinpro sachinpro Dec 19, 2025

Choose a reason for hiding this comment

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

Rather than returning empty strings, this function should return StatusRecordOr to handle failures.

#endif

namespace {
google::cloud::ProxyConfig CreateProxyConfig(std::string hostname,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Although not related to this change, please remove this function. I cannot find it being used anywhere else . ref.

*(unsigned long long*)(guid.Data4 + 2));

// Build final *.pem path
std::string pem_file = std::string(temp_path) + "bqca_" + guid_str + ".pem";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We cannot use guid in the file name since it will create a new file every time ExportWindowsSystemCertsToPem is called with ODBCBQClient::CreateBQClient(.

std::string pem_path;
if (use_system_trust_store == true) {
pem_path = ExportWindowsSystemCertsToPem();
options.set<google::cloud::CARootsFilePathOption>(pem_path);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need to set it here when we are setting it with read_options also?

This is not needed for REST, right?

Copy link
Copy Markdown
Collaborator

@sachinpro sachinpro left a comment

Choose a reason for hiding this comment

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

I think there is a way to directly use the certificates string. It would be a better implementation if it works.

Let me test it out. I can fix my comments myself alongwith those changes, so no need to update this PR right now.

@sachinpro sachinpro force-pushed the system_trust_store_impl branch from 38ac556 to 9aa5b0a Compare May 12, 2026 13:30
@sachinpro sachinpro requested a review from a team as a code owner May 12, 2026 13:30
@sachinpro sachinpro force-pushed the system_trust_store_impl branch from 9aa5b0a to 09a2b1a Compare May 12, 2026 14:03
@sachinpro sachinpro force-pushed the system_trust_store_impl branch from 09a2b1a to 25bb9d6 Compare May 13, 2026 13:01
Copy link
Copy Markdown
Collaborator

@sachinpro sachinpro left a comment

Choose a reason for hiding this comment

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

We need to find a way to have a test to verify this through integration tests.
Currently, UseSystemTrustStore is an optional property. No errors are thrown in either case.

@sachinpro sachinpro merged commit 063e2c1 into main May 13, 2026
21 of 23 checks passed
@sachinpro sachinpro deleted the system_trust_store_impl branch May 13, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants