@@ -18,6 +18,7 @@ struct CmdArgs
1818 String cert;
1919 String key;
2020 String clientId;
21+ String caFile;
2122 String topic = " test/topic" ;
2223 String message = " Hello from mqtt5 sample" ;
2324 uint32_t count = 5 ;
@@ -29,14 +30,14 @@ void printHelp()
2930 printf (" options:\n " );
3031 printf (" --help show this help message and exit\n " );
3132 printf (" required arguments:\n " );
32- printf (" --endpoint IoT endpoint hostname (default: None) \n " );
33+ printf (" --endpoint IoT endpoint hostname\n " );
3334 printf (
3435 " --cert Path to the certificate file to use during mTLS connection establishment (default: None)\n " );
3536 printf (
3637 " --key Path to the private key file to use during mTLS connection establishment (default: None)\n " );
3738 printf (" optional arguments:\n " );
3839 printf (" --client-id Client ID (default: mqtt5-sample-<uuid>)\n " );
39- printf (" --ca_file Path to optional CA bundle (PEM) (default: None) \n " );
40+ printf (" --ca_file Path to optional CA bundle (PEM)\n " );
4041 printf (" --topic Topic (default: test/topic)\n " );
4142 printf (" --message Message payload (default: Hello from mqtt5 sample)\n " );
4243 printf (" --count Messages to publish (0 = infinite) (default: 5)\n " );
@@ -66,6 +67,10 @@ CmdArgs parseArgs(int argc, char *argv[])
6667 {
6768 args.key = argv[++i];
6869 }
70+ else if (strcmp (argv[i], " --ca_file" ) == 0 )
71+ {
72+ args.caFile = argv[++i];
73+ }
6974 else if (strcmp (argv[i], " --client_id" ) == 0 )
7075 {
7176 args.clientId = argv[++i];
@@ -137,7 +142,13 @@ int main(int argc, char *argv[])
137142 exit (1 );
138143 }
139144
140- /* Setup connection options */
145+ // Setup CA file if provided
146+ if (!cmdData.caFile .empty ())
147+ {
148+ builder->WithCertificateAuthority (cmdData.caFile .c_str ());
149+ }
150+
151+ // Setup connection options
141152 std::shared_ptr<Mqtt5::ConnectPacket> connectOptions =
142153 Aws::Crt::MakeShared<Mqtt5::ConnectPacket>(Aws::Crt::DefaultAllocatorImplementation ());
143154 connectOptions->WithClientId (cmdData.clientId );
0 commit comments