Skip to content

Commit 12a26eb

Browse files
cpp: Use verify-full for libpq sample (#158)
Co-authored-by: Daniel Frankcom <frankcom@amazon.com>
1 parent 7c2c7cc commit 12a26eb

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

.github/workflows/cpp-libpq-integ-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ jobs:
8080
CLUSTER_USER: admin
8181
LD_LIBRARY_PATH: /lib/x86_64-linux-gnu:/home/runner/work/aurora-dsql-samples/aurora-dsql-samples/cpp/libpq/aws-sdk-install/lib
8282
run: |
83+
wget https://www.amazontrust.com/repository/AmazonRootCA1.pem -O root.pem
8384
./libpq_example

cpp/libpq/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ The example contains comments explaining the code and the operations being perfo
4747
[Using database roles with IAM roles](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/using-database-and-iam-roles.html)
4848
guide.
4949

50+
### Download the Amazon root certificate from the official trust store
51+
52+
Download the Amazon root certificate from the official trust store:
53+
54+
```
55+
wget https://www.amazontrust.com/repository/AmazonRootCA1.pem -O root.pem
56+
```
5057

5158
#### C++ compiler
5259
A c++ compiler that supports c++11 standard or newer.

cpp/libpq/src/libpq_example.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ std::string generateDBAuthToken(const std::string clusterUser, const std::string
3232

3333
PGconn* connectToCluster(std::string clusterUser, std::string clusterEndpoint, std::string region) {
3434
std::string dbname = "postgres";
35-
std::string sslmode = "require";
35+
std::string sslrootcert = "./root.pem";
36+
std::string sslmode = "verify-full";
3637
int port = 5432;
3738

3839
// Generate a fresh password token for each connection, to ensure the token is not expired
@@ -45,8 +46,8 @@ PGconn* connectToCluster(std::string clusterUser, std::string clusterEndpoint, s
4546
}
4647

4748
char conninfo[4096];
48-
sprintf(conninfo, "dbname=%s user=%s host=%s port=%i sslmode=%s password=%s",
49-
dbname.c_str(), clusterUser.c_str(), clusterEndpoint.c_str(), port, sslmode.c_str(), password_token.c_str());
49+
sprintf(conninfo, "dbname=%s user=%s host=%s port=%i sslrootcert=%s sslmode=%s password=%s",
50+
dbname.c_str(), clusterUser.c_str(), clusterEndpoint.c_str(), port, sslrootcert.c_str(), sslmode.c_str(), password_token.c_str());
5051

5152
PGconn *conn = PQconnectdb(conninfo);
5253

0 commit comments

Comments
 (0)