Skip to content

Commit

Permalink
Updated to latest crt version, updated discovery client to use activa… (
Browse files Browse the repository at this point in the history
#103)

* Updated to latest crt version, updated discovery client to use activate api.

* Updated discovery sample for ca to be optional.
  • Loading branch information
JonathanHenson authored Mar 30, 2020
1 parent f0ab8fc commit 2cef480
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
8 changes: 7 additions & 1 deletion discovery/source/DiscoveryClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,13 @@ namespace Aws
}
};

if (!connection->NewClientStream(requestOptions))
auto stream = connection->NewClientStream(requestOptions);
if (!stream)
{
onDiscoverResponse(nullptr, Crt::LastErrorOrUnknown(), 0);
}

if (!stream->Activate())
{
onDiscoverResponse(nullptr, Crt::LastErrorOrUnknown(), 0);
}
Expand Down
22 changes: 18 additions & 4 deletions samples/greengrass/basic_discovery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void s_printHelp()
fprintf(
stdout,
"basic-discovery --region <optional: region> --cert <path to cert>"
" --key <path to key> --ca_file <path to custom ca>"
" --key <path to key> --ca_file <optional: path to custom ca>"
" --thing_name <thing name> --topic <optional: topic> "
" --mode <optional: both|publish|subscribe> --message <optional: message to publish>"
" --proxy-host <optional: proxy host name> --proxy-port <optional: proxy port>\n\n");
Expand Down Expand Up @@ -86,7 +86,7 @@ int main(int argc, char *argv[])

/*********************** Parse Arguments ***************************/
if (!(s_cmdOptionExists(argv, argv + argc, "--cert") && s_cmdOptionExists(argv, argv + argc, "--key") &&
s_cmdOptionExists(argv, argv + argc, "--thing_name") && s_cmdOptionExists(argv, argv + argc, "--ca_file")))
s_cmdOptionExists(argv, argv + argc, "--thing_name")))
{
s_printHelp();
return 0;
Expand All @@ -95,7 +95,11 @@ int main(int argc, char *argv[])
certificatePath = s_getCmdOption(argv, argv + argc, "--cert");
keyPath = s_getCmdOption(argv, argv + argc, "--key");
thingName = s_getCmdOption(argv, argv + argc, "--thing_name");
caFile = s_getCmdOption(argv, argv + argc, "--ca_file");

if (s_cmdOptionExists(argv, argv + argc, "--ca_file"))
{
caFile = s_getCmdOption(argv, argv + argc, "--ca_file");
}

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

tlsCtxOptions.OverrideDefaultTrustStore(nullptr, caFile.c_str());
if (!tlsCtxOptions)
{
fprintf(stderr, "TLS Context Options creation failed with error %s\n", ErrorDebugString(Aws::Crt::LastError()));
exit(-1);
}

if (!caFile.empty())
{
tlsCtxOptions.OverrideDefaultTrustStore(nullptr, caFile.c_str());
}

Io::TlsContext tlsCtx(tlsCtxOptions, Io::TlsMode::CLIENT);

if (!tlsCtx)
Expand Down

0 comments on commit 2cef480

Please sign in to comment.