Skip to content

Commit 2cef480

Browse files
Updated to latest crt version, updated discovery client to use activa… (#103)
* Updated to latest crt version, updated discovery client to use activate api. * Updated discovery sample for ca to be optional.
1 parent f0ab8fc commit 2cef480

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

discovery/source/DiscoveryClient.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ namespace Aws
180180
}
181181
};
182182

183-
if (!connection->NewClientStream(requestOptions))
183+
auto stream = connection->NewClientStream(requestOptions);
184+
if (!stream)
185+
{
186+
onDiscoverResponse(nullptr, Crt::LastErrorOrUnknown(), 0);
187+
}
188+
189+
if (!stream->Activate())
184190
{
185191
onDiscoverResponse(nullptr, Crt::LastErrorOrUnknown(), 0);
186192
}

samples/greengrass/basic_discovery/main.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void s_printHelp()
3333
fprintf(
3434
stdout,
3535
"basic-discovery --region <optional: region> --cert <path to cert>"
36-
" --key <path to key> --ca_file <path to custom ca>"
36+
" --key <path to key> --ca_file <optional: path to custom ca>"
3737
" --thing_name <thing name> --topic <optional: topic> "
3838
" --mode <optional: both|publish|subscribe> --message <optional: message to publish>"
3939
" --proxy-host <optional: proxy host name> --proxy-port <optional: proxy port>\n\n");
@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
8686

8787
/*********************** Parse Arguments ***************************/
8888
if (!(s_cmdOptionExists(argv, argv + argc, "--cert") && s_cmdOptionExists(argv, argv + argc, "--key") &&
89-
s_cmdOptionExists(argv, argv + argc, "--thing_name") && s_cmdOptionExists(argv, argv + argc, "--ca_file")))
89+
s_cmdOptionExists(argv, argv + argc, "--thing_name")))
9090
{
9191
s_printHelp();
9292
return 0;
@@ -95,7 +95,11 @@ int main(int argc, char *argv[])
9595
certificatePath = s_getCmdOption(argv, argv + argc, "--cert");
9696
keyPath = s_getCmdOption(argv, argv + argc, "--key");
9797
thingName = s_getCmdOption(argv, argv + argc, "--thing_name");
98-
caFile = s_getCmdOption(argv, argv + argc, "--ca_file");
98+
99+
if (s_cmdOptionExists(argv, argv + argc, "--ca_file"))
100+
{
101+
caFile = s_getCmdOption(argv, argv + argc, "--ca_file");
102+
}
99103

100104
if (s_cmdOptionExists(argv, argv + argc, "--region"))
101105
{
@@ -142,7 +146,17 @@ int main(int argc, char *argv[])
142146
Io::TlsContextOptions tlsCtxOptions =
143147
Io::TlsContextOptions::InitClientWithMtls(certificatePath.c_str(), keyPath.c_str());
144148

145-
tlsCtxOptions.OverrideDefaultTrustStore(nullptr, caFile.c_str());
149+
if (!tlsCtxOptions)
150+
{
151+
fprintf(stderr, "TLS Context Options creation failed with error %s\n", ErrorDebugString(Aws::Crt::LastError()));
152+
exit(-1);
153+
}
154+
155+
if (!caFile.empty())
156+
{
157+
tlsCtxOptions.OverrideDefaultTrustStore(nullptr, caFile.c_str());
158+
}
159+
146160
Io::TlsContext tlsCtx(tlsCtxOptions, Io::TlsMode::CLIENT);
147161

148162
if (!tlsCtx)

0 commit comments

Comments
 (0)