Mqtt5Client.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/crt/Api.h>
  6. #include <aws/crt/auth/Credentials.h>
  7. #include <aws/crt/auth/Sigv4Signing.h>
  8. #include <aws/crt/http/HttpRequestResponse.h>
  9. #include <aws/crt/mqtt/Mqtt5Packets.h>
  10. #include <aws/iot/Mqtt5Client.h>
  11. #if !BYO_CRYPTO
  12. namespace Aws
  13. {
  14. namespace Iot
  15. {
  16. static Crt::String AddToUsernameParameter(
  17. Crt::String currentUsername,
  18. Crt::String parameterValue,
  19. Crt::String parameterPreText)
  20. {
  21. Crt::String return_string = currentUsername;
  22. if (return_string.find("?") != Crt::String::npos)
  23. {
  24. return_string += "&";
  25. }
  26. else
  27. {
  28. return_string += "?";
  29. }
  30. if (parameterValue.find(parameterPreText) != Crt::String::npos)
  31. {
  32. return return_string + parameterValue;
  33. }
  34. else
  35. {
  36. return return_string + parameterPreText + parameterValue;
  37. }
  38. }
  39. static bool buildMqtt5FinalUsername(
  40. Crt::Optional<Mqtt5CustomAuthConfig> customAuthConfig,
  41. Crt::String &username)
  42. {
  43. if (customAuthConfig.has_value())
  44. {
  45. /* If we're using token-signing authentication, then all token properties must be set */
  46. bool usingSigning = false;
  47. if (customAuthConfig->GetTokenValue().has_value() || customAuthConfig->GetTokenKeyName().has_value() ||
  48. customAuthConfig->GetTokenSignature().has_value())
  49. {
  50. usingSigning = true;
  51. if (!customAuthConfig->GetTokenValue().has_value() ||
  52. !customAuthConfig->GetTokenKeyName().has_value() ||
  53. !customAuthConfig->GetTokenSignature().has_value())
  54. {
  55. return false;
  56. }
  57. }
  58. Crt::String usernameString = "";
  59. if (!customAuthConfig->GetUsername().has_value())
  60. {
  61. if (!username.empty())
  62. {
  63. usernameString += username;
  64. }
  65. }
  66. else
  67. {
  68. usernameString += customAuthConfig->GetUsername().value();
  69. }
  70. if (customAuthConfig->GetAuthorizerName().has_value())
  71. {
  72. usernameString = AddToUsernameParameter(
  73. usernameString, customAuthConfig->GetAuthorizerName().value(), "x-amz-customauthorizer-name=");
  74. }
  75. if (usingSigning)
  76. {
  77. usernameString = AddToUsernameParameter(
  78. usernameString,
  79. customAuthConfig->GetTokenValue().value(),
  80. customAuthConfig->GetTokenKeyName().value() + "=");
  81. usernameString = AddToUsernameParameter(
  82. usernameString,
  83. customAuthConfig->GetTokenSignature().value(),
  84. "x-amz-customauthorizer-signature=");
  85. }
  86. username = usernameString;
  87. }
  88. return true;
  89. }
  90. /*****************************************************
  91. *
  92. * Mqtt5ClientOptionsBuilder
  93. *
  94. *****************************************************/
  95. Mqtt5ClientBuilder::Mqtt5ClientBuilder(Crt::Allocator *allocator) noexcept
  96. : m_allocator(allocator), m_port(0), m_lastError(0), m_enableMetricsCollection(true)
  97. {
  98. m_options = new Crt::Mqtt5::Mqtt5ClientOptions(allocator);
  99. }
  100. Mqtt5ClientBuilder::Mqtt5ClientBuilder(int error, Crt::Allocator *allocator) noexcept
  101. : m_allocator(allocator), m_options(nullptr), m_lastError(error)
  102. {
  103. }
  104. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
  105. const Crt::String hostName,
  106. const char *certPath,
  107. const char *pkeyPath,
  108. Crt::Allocator *allocator) noexcept
  109. {
  110. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  111. result->m_tlsConnectionOptions =
  112. Crt::Io::TlsContextOptions::InitClientWithMtls(certPath, pkeyPath, allocator);
  113. if (!result->m_tlsConnectionOptions.value())
  114. {
  115. result->m_lastError = result->m_tlsConnectionOptions->LastError();
  116. return result;
  117. }
  118. result->withHostName(hostName);
  119. return result;
  120. }
  121. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromMemory(
  122. const Crt::String hostName,
  123. const Crt::ByteCursor &cert,
  124. const Crt::ByteCursor &pkey,
  125. Crt::Allocator *allocator) noexcept
  126. {
  127. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  128. result->m_tlsConnectionOptions = Crt::Io::TlsContextOptions::InitClientWithMtls(cert, pkey, allocator);
  129. if (!result->m_tlsConnectionOptions.value())
  130. {
  131. result->m_lastError = result->m_tlsConnectionOptions->LastError();
  132. return result;
  133. }
  134. result->withHostName(hostName);
  135. return result;
  136. }
  137. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsPkcs11(
  138. const Crt::String hostName,
  139. const Crt::Io::TlsContextPkcs11Options &pkcs11Options,
  140. Crt::Allocator *allocator) noexcept
  141. {
  142. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  143. result->m_tlsConnectionOptions =
  144. Crt::Io::TlsContextOptions::InitClientWithMtlsPkcs11(pkcs11Options, allocator);
  145. if (!result->m_tlsConnectionOptions.value())
  146. {
  147. result->m_lastError = result->m_tlsConnectionOptions->LastError();
  148. return result;
  149. }
  150. result->withHostName(hostName);
  151. return result;
  152. }
  153. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithWindowsCertStorePath(
  154. const Crt::String hostName,
  155. const char *windowsCertStorePath,
  156. Crt::Allocator *allocator) noexcept
  157. {
  158. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  159. result->m_tlsConnectionOptions =
  160. Crt::Io::TlsContextOptions::InitClientWithMtlsSystemPath(windowsCertStorePath, allocator);
  161. if (!result->m_tlsConnectionOptions.value())
  162. {
  163. result->m_lastError = result->m_tlsConnectionOptions->LastError();
  164. return result;
  165. }
  166. result->withHostName(hostName);
  167. return result;
  168. }
  169. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithWebsocket(
  170. const Crt::String hostName,
  171. const WebsocketConfig &config,
  172. Crt::Allocator *allocator) noexcept
  173. {
  174. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  175. result->m_tlsConnectionOptions = Crt::Io::TlsContextOptions::InitDefaultClient();
  176. result->withHostName(hostName);
  177. result->m_websocketConfig = config;
  178. return result;
  179. }
  180. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithCustomAuthorizer(
  181. const Crt::String hostName,
  182. const Mqtt5CustomAuthConfig &customAuthConfig,
  183. Crt::Allocator *allocator) noexcept
  184. {
  185. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  186. result->m_tlsConnectionOptions = Crt::Io::TlsContextOptions::InitDefaultClient();
  187. result->withHostName(hostName);
  188. result->WithCustomAuthorizer(customAuthConfig);
  189. return result;
  190. }
  191. Mqtt5ClientBuilder *Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithCustomAuthorizerWebsocket(
  192. const Crt::String hostName,
  193. const Mqtt5CustomAuthConfig &customAuthConfig,
  194. const WebsocketConfig &config,
  195. Crt::Allocator *allocator) noexcept
  196. {
  197. Mqtt5ClientBuilder *result = new Mqtt5ClientBuilder(allocator);
  198. result->m_tlsConnectionOptions = Crt::Io::TlsContextOptions::InitDefaultClient();
  199. result->withHostName(hostName);
  200. result->m_websocketConfig = config;
  201. result->WithCustomAuthorizer(customAuthConfig);
  202. return result;
  203. }
  204. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withHostName(const Crt::String hostName)
  205. {
  206. m_options->withHostName(hostName);
  207. return *this;
  208. }
  209. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withPort(uint16_t port) noexcept
  210. {
  211. m_port = port;
  212. return *this;
  213. }
  214. Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithCertificateAuthority(const char *caPath) noexcept
  215. {
  216. if (m_tlsConnectionOptions)
  217. {
  218. if (!m_tlsConnectionOptions->OverrideDefaultTrustStore(nullptr, caPath))
  219. {
  220. m_lastError = m_tlsConnectionOptions->LastError();
  221. }
  222. }
  223. return *this;
  224. }
  225. Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithCertificateAuthority(const Crt::ByteCursor &cert) noexcept
  226. {
  227. if (m_tlsConnectionOptions)
  228. {
  229. if (!m_tlsConnectionOptions->OverrideDefaultTrustStore(cert))
  230. {
  231. m_lastError = m_tlsConnectionOptions->LastError();
  232. }
  233. }
  234. return *this;
  235. }
  236. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withHttpProxyOptions(
  237. const Crt::Http::HttpClientConnectionProxyOptions &proxyOptions) noexcept
  238. {
  239. m_proxyOptions = proxyOptions;
  240. return *this;
  241. }
  242. Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithCustomAuthorizer(const Iot::Mqtt5CustomAuthConfig &config) noexcept
  243. {
  244. m_customAuthConfig = config;
  245. return *this;
  246. }
  247. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withConnectOptions(
  248. std::shared_ptr<ConnectPacket> packetConnect) noexcept
  249. {
  250. m_connectOptions = packetConnect;
  251. return *this;
  252. }
  253. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withSessionBehavior(ClientSessionBehaviorType sessionBehavior) noexcept
  254. {
  255. m_options->withSessionBehavior(sessionBehavior);
  256. return *this;
  257. }
  258. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withClientExtendedValidationAndFlowControl(
  259. ClientExtendedValidationAndFlowControl clientExtendedValidationAndFlowControl) noexcept
  260. {
  261. m_options->withClientExtendedValidationAndFlowControl(clientExtendedValidationAndFlowControl);
  262. return *this;
  263. }
  264. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withOfflineQueueBehavior(
  265. ClientOperationQueueBehaviorType operationQueueBehavior) noexcept
  266. {
  267. m_options->withAckTimeoutSeconds(operationQueueBehavior);
  268. return *this;
  269. }
  270. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withReconnectOptions(ReconnectOptions reconnectOptions) noexcept
  271. {
  272. m_options->withReconnectOptions(reconnectOptions);
  273. return *this;
  274. }
  275. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withPingTimeoutMs(uint32_t pingTimeoutMs) noexcept
  276. {
  277. m_options->withPingTimeoutMs(pingTimeoutMs);
  278. return *this;
  279. }
  280. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withConnackTimeoutMs(uint32_t connackTimeoutMs) noexcept
  281. {
  282. m_options->withConnackTimeoutMs(connackTimeoutMs);
  283. return *this;
  284. }
  285. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withAckTimeoutSeconds(uint32_t ackTimeoutSeconds) noexcept
  286. {
  287. m_options->withAckTimeoutSeconds(ackTimeoutSeconds);
  288. return *this;
  289. }
  290. Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithSdkName(const Crt::String &sdkName)
  291. {
  292. m_sdkName = sdkName;
  293. return *this;
  294. }
  295. Mqtt5ClientBuilder &Mqtt5ClientBuilder::WithSdkVersion(const Crt::String &sdkVersion)
  296. {
  297. m_sdkVersion = sdkVersion;
  298. return *this;
  299. }
  300. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withClientConnectionSuccessCallback(
  301. OnConnectionSuccessHandler callback) noexcept
  302. {
  303. m_options->withClientConnectionSuccessCallback(std::move(callback));
  304. return *this;
  305. }
  306. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withClientConnectionFailureCallback(
  307. OnConnectionFailureHandler callback) noexcept
  308. {
  309. m_options->withClientConnectionFailureCallback(std::move(callback));
  310. return *this;
  311. }
  312. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withClientDisconnectionCallback(
  313. OnDisconnectionHandler callback) noexcept
  314. {
  315. m_options->withClientDisconnectionCallback(std::move(callback));
  316. return *this;
  317. }
  318. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withClientStoppedCallback(OnStoppedHandler callback) noexcept
  319. {
  320. m_options->withClientStoppedCallback(std::move(callback));
  321. return *this;
  322. }
  323. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withClientAttemptingConnectCallback(
  324. OnAttemptingConnectHandler callback) noexcept
  325. {
  326. m_options->withClientAttemptingConnectCallback(std::move(callback));
  327. return *this;
  328. }
  329. Mqtt5ClientBuilder &Mqtt5ClientBuilder::withPublishReceivedCallback(OnPublishReceivedHandler callback) noexcept
  330. {
  331. m_options->withPublishReceivedCallback(std::move(callback));
  332. return *this;
  333. }
  334. std::shared_ptr<Mqtt5Client> Mqtt5ClientBuilder::Build() noexcept
  335. {
  336. if (m_lastError != 0)
  337. {
  338. return nullptr;
  339. }
  340. uint16_t port = m_port;
  341. if (!port) // port is default to 0
  342. {
  343. if (m_websocketConfig || Crt::Io::TlsContextOptions::IsAlpnSupported())
  344. {
  345. port = 443;
  346. }
  347. else
  348. {
  349. port = 8883;
  350. }
  351. }
  352. if (port == 443 && !m_websocketConfig && Crt::Io::TlsContextOptions::IsAlpnSupported() &&
  353. !m_customAuthConfig.has_value())
  354. {
  355. if (!m_tlsConnectionOptions->SetAlpnList("x-amzn-mqtt-ca"))
  356. {
  357. return nullptr;
  358. }
  359. }
  360. if (m_customAuthConfig.has_value())
  361. {
  362. if (port != 443)
  363. {
  364. AWS_LOGF_WARN(
  365. AWS_LS_MQTT_GENERAL,
  366. "Attempting to connect to authorizer with unsupported port. Port is not 443...");
  367. }
  368. if (!m_websocketConfig)
  369. {
  370. if (!m_tlsConnectionOptions->SetAlpnList("mqtt"))
  371. {
  372. return nullptr;
  373. }
  374. }
  375. }
  376. // add metrics string to username (if metrics enabled)
  377. if (m_enableMetricsCollection || m_customAuthConfig.has_value())
  378. {
  379. Crt::String username = "";
  380. if (m_connectOptions != nullptr)
  381. {
  382. if (m_connectOptions->getUsername().has_value())
  383. username = m_connectOptions->getUsername().value();
  384. }
  385. else
  386. {
  387. m_connectOptions = std::make_shared<ConnectPacket>(m_allocator);
  388. }
  389. if (m_customAuthConfig.has_value())
  390. {
  391. if (!buildMqtt5FinalUsername(m_customAuthConfig, username))
  392. {
  393. AWS_LOGF_ERROR(
  394. AWS_LS_MQTT5_CLIENT,
  395. "Failed to setup CustomAuthorizerConfig, please check if the parameters are set "
  396. "correctly.");
  397. return nullptr;
  398. }
  399. if (m_customAuthConfig->GetPassword().has_value())
  400. {
  401. m_connectOptions->withPassword(m_customAuthConfig->GetPassword().value());
  402. }
  403. }
  404. if (m_enableMetricsCollection)
  405. {
  406. username = AddToUsernameParameter(username, "SDK", m_sdkName);
  407. username = AddToUsernameParameter(username, "Version", m_sdkName);
  408. }
  409. m_connectOptions->withUserName(username);
  410. }
  411. auto tlsContext =
  412. Crt::Io::TlsContext(m_tlsConnectionOptions.value(), Crt::Io::TlsMode::CLIENT, m_allocator);
  413. if (!tlsContext)
  414. {
  415. return nullptr;
  416. }
  417. m_options->withPort(port).withTlsConnectionOptions(tlsContext.NewConnectionOptions());
  418. if (m_connectOptions != nullptr)
  419. {
  420. m_options->withConnectOptions(m_connectOptions);
  421. }
  422. if (m_websocketConfig.has_value())
  423. {
  424. auto websocketConfig = m_websocketConfig.value();
  425. auto signerTransform = [websocketConfig](
  426. std::shared_ptr<Crt::Http::HttpRequest> req,
  427. const Crt::Mqtt::OnWebSocketHandshakeInterceptComplete &onComplete) {
  428. // it is only a very happy coincidence that these function signatures match. This is the callback
  429. // for signing to be complete. It invokes the callback for websocket handshake to be complete.
  430. auto signingComplete =
  431. [onComplete](const std::shared_ptr<Aws::Crt::Http::HttpRequest> &req1, int errorCode) {
  432. onComplete(req1, errorCode);
  433. };
  434. auto signerConfig = websocketConfig.CreateSigningConfigCb();
  435. websocketConfig.Signer->SignRequest(req, *signerConfig, signingComplete);
  436. };
  437. m_options->withWebsocketHandshakeTransformCallback(signerTransform);
  438. bool useWebsocketProxyOptions =
  439. m_websocketConfig->ProxyOptions.has_value() && !m_proxyOptions.has_value();
  440. if (useWebsocketProxyOptions)
  441. {
  442. m_options->withHttpProxyOptions(m_websocketConfig->ProxyOptions.value());
  443. }
  444. else if (m_proxyOptions.has_value())
  445. {
  446. m_options->withHttpProxyOptions(m_proxyOptions.value());
  447. }
  448. }
  449. return Crt::Mqtt5::Mqtt5Client::NewMqtt5Client(*m_options, m_allocator);
  450. }
  451. Aws::Iot::Mqtt5CustomAuthConfig::Mqtt5CustomAuthConfig(Crt::Allocator *allocator) noexcept
  452. : m_allocator(allocator)
  453. {
  454. AWS_ZERO_STRUCT(m_passwordStorage);
  455. }
  456. Aws::Iot::Mqtt5CustomAuthConfig::~Mqtt5CustomAuthConfig() { aws_byte_buf_clean_up(&m_passwordStorage); }
  457. Aws::Iot::Mqtt5CustomAuthConfig::Mqtt5CustomAuthConfig(const Mqtt5CustomAuthConfig &rhs)
  458. {
  459. if (&rhs != this)
  460. {
  461. m_allocator = rhs.m_allocator;
  462. if (rhs.m_authorizerName.has_value())
  463. {
  464. m_authorizerName = rhs.m_authorizerName.value();
  465. }
  466. if (rhs.m_tokenKeyName.has_value())
  467. {
  468. m_tokenKeyName = rhs.m_tokenKeyName.value();
  469. }
  470. if (rhs.m_tokenSignature.has_value())
  471. {
  472. m_tokenSignature = rhs.m_tokenSignature.value();
  473. }
  474. if (rhs.m_tokenValue.has_value())
  475. {
  476. m_tokenValue = rhs.m_tokenValue.value();
  477. }
  478. if (rhs.m_username.has_value())
  479. {
  480. m_username = rhs.m_username.value();
  481. }
  482. if (rhs.m_password.has_value())
  483. {
  484. AWS_ZERO_STRUCT(m_passwordStorage);
  485. aws_byte_buf_init_copy_from_cursor(&m_passwordStorage, m_allocator, rhs.m_password.value());
  486. m_password = aws_byte_cursor_from_buf(&m_passwordStorage);
  487. }
  488. }
  489. }
  490. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::operator=(const Mqtt5CustomAuthConfig &rhs)
  491. {
  492. if (&rhs != this)
  493. {
  494. m_allocator = rhs.m_allocator;
  495. if (rhs.m_authorizerName.has_value())
  496. {
  497. m_authorizerName = rhs.m_authorizerName.value();
  498. }
  499. if (rhs.m_tokenKeyName.has_value())
  500. {
  501. m_tokenKeyName = rhs.m_tokenKeyName.value();
  502. }
  503. if (rhs.m_tokenSignature.has_value())
  504. {
  505. m_tokenSignature = rhs.m_tokenSignature.value();
  506. }
  507. if (rhs.m_tokenValue.has_value())
  508. {
  509. m_tokenValue = rhs.m_tokenValue.value();
  510. }
  511. if (rhs.m_username.has_value())
  512. {
  513. m_username = rhs.m_username.value();
  514. }
  515. if (rhs.m_password.has_value())
  516. {
  517. aws_byte_buf_clean_up(&m_passwordStorage);
  518. AWS_ZERO_STRUCT(m_passwordStorage);
  519. aws_byte_buf_init_copy_from_cursor(&m_passwordStorage, m_allocator, rhs.m_password.value());
  520. m_password = aws_byte_cursor_from_buf(&m_passwordStorage);
  521. }
  522. }
  523. return *this;
  524. }
  525. const Crt::Optional<Crt::String> &Mqtt5CustomAuthConfig::GetAuthorizerName() { return m_authorizerName; }
  526. const Crt::Optional<Crt::String> &Mqtt5CustomAuthConfig::GetUsername() { return m_username; }
  527. const Crt::Optional<Crt::ByteCursor> &Mqtt5CustomAuthConfig::GetPassword() { return m_password; }
  528. const Crt::Optional<Crt::String> &Mqtt5CustomAuthConfig::GetTokenKeyName() { return m_tokenKeyName; }
  529. const Crt::Optional<Crt::String> &Mqtt5CustomAuthConfig::GetTokenValue() { return m_tokenValue; }
  530. const Crt::Optional<Crt::String> &Mqtt5CustomAuthConfig::GetTokenSignature() { return m_tokenSignature; }
  531. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithAuthorizerName(Crt::String authName)
  532. {
  533. m_authorizerName = std::move(authName);
  534. return *this;
  535. }
  536. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithUsername(Crt::String username)
  537. {
  538. m_username = std::move(username);
  539. return *this;
  540. }
  541. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithPassword(Crt::ByteCursor password)
  542. {
  543. aws_byte_buf_clean_up(&m_passwordStorage);
  544. AWS_ZERO_STRUCT(m_passwordStorage);
  545. aws_byte_buf_init_copy_from_cursor(&m_passwordStorage, m_allocator, password);
  546. m_password = aws_byte_cursor_from_buf(&m_passwordStorage);
  547. return *this;
  548. }
  549. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithTokenKeyName(Crt::String tokenKeyName)
  550. {
  551. m_tokenKeyName = std::move(tokenKeyName);
  552. return *this;
  553. }
  554. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithTokenValue(Crt::String tokenValue)
  555. {
  556. m_tokenValue = std::move(tokenValue);
  557. return *this;
  558. }
  559. Mqtt5CustomAuthConfig &Aws::Iot::Mqtt5CustomAuthConfig::WithTokenSignature(Crt::String tokenSignature)
  560. {
  561. m_tokenSignature = std::move(tokenSignature);
  562. return *this;
  563. }
  564. } // namespace Iot
  565. } // namespace Aws
  566. #endif // !BYO_CRYPTO