小程序
传感搜
传感圈

Leveraging Enhanced Authentication for MQTT Security

2023-07-25 15:46:24
关注

Illustration: © IoT For All

Enhanced authentication is a novel authentication framework introduced in MQTT 5.0. It offers a range of alternative methods that are more secure than traditional password authentication.

However, increased security comes with added complexity. Certain authentication methods, like SCRAM, require multiple exchanges of authentication data. This renders the single-exchange authentication framework of the CONNECT and CONNACK packets outdated.

To address this limitation, MQTT 5.0 introduces the AUTH packet, which supports multiple exchanges of authentication data. It enables the use of SASL (Simple Authentication and Security Layer) mechanisms with a challenge-response style in MQTT.

What Problems Does Enhanced Authentication Solve?

Before delving into enhanced authentication, it is essential to understand the shortcomings of password authentication in terms of security.

In fact, despite employing techniques like Salt and Hash to store passwords securely, the client must transmit the password in plain text over the network, making it vulnerable to theft. Even when employing TLS encryption for communication, there remains a risk of attackers obtaining sensitive data like passwords due to outdated SSL versions, weak cipher suites, or the presence of fake CA certificates.

Moreover, simple password authentication only lets the server check the identity of the client, but not the other way around, which allows the attacker to pretend to be the server and get sensitive data from the client. This is what we often call a man-in-the-middle attack.

Enhanced authentication allows users to employ highly secure authentication methods within the SASL framework. These methods offer several advantages, such as eliminating the transmission of passwords over the network and facilitating mutual identity verification between the client and server. By presenting these options, users can select the authentication method that aligns with their specific needs and security preferences.

Common SASL Mechanisms Used for Enhanced Authentication

DIGEST-MD5

DIGEST-MD5 is an authentication method within the SASL framework. It utilizes the Message Digest 5 (MD5) hash algorithm and a challenge-response mechanism to verify the identity between the client and the server. One notable advantage is that the client does not need to transmit the password in plain text over the network.

In simple terms, when a client wants to access a protected resource, the server will send a challenge with a one-time random number and some required parameters. The client utilizes these parameters, along with its username and password, to generate a response, which is then transmitted back to the server.

The server independently creates an expected response using the same method and compares it with the received response. If they match, authentication is successful. This approach effectively mitigates the risk of password exposure through network snooping. Additionally, by utilizing a one-time random number for each connection, it enhances protection against replay attacks.

However, it’s important to note that DIGEST-MD5, while enabling server-side verification of the client’s identity, lacks the ability for the client to verify the identity of the server. This limitation leaves room for potential man-in-the-middle attacks. Furthermore, since MD5 is no longer secure, it is strongly recommended to replace it with a hash function that offers stronger resistance to collisions, such as SHA-256.

SCRAM

SCRAM (Salted Challenge Response Authentication Mechanism) is another authentication method within the SASL framework. It shares similarities with DIGEST-MD5 in terms of approach. SCRAM prompts the client to generate a response using a one-time random number, thereby avoiding sending the password in plain text over the network.

However, SCRAM further enhances security by incorporating Salt, Iterations, and more robust hash algorithms like SHA-256 and SHA-512. These additions significantly enhance the security of password storage, effectively mitigating the risks associated with offline attacks, replay attacks, and other potential vulnerabilities.

Furthermore, SCRAM incorporates a more intricate challenge-response process that includes server-side proof sent to the client. The client can then utilize this proof to verify the server’s possession of the correct password, enabling mutual authentication. This additional step reduces the vulnerability to man-in-the-middle attacks.

However, using hash algorithms like SHA256 in SCRAM introduces additional computational overhead, which can potentially impact the performance of devices with limited resources.

Kerberos

Kerberos utilizes a trusted third-party Kerberos server to facilitate authentication services. The server issues tokens to verified users, enabling them to access resource servers. A notable advantage is the ability for users to access multiple systems and services with a single authentication, thereby achieving the convenience of single sign-on (SSO).

The token issued by the Kerberos server has a limited lifespan, and clients can only use this token to access the service for a certain period, which can prevent security issues caused by token leakage. Of course, although a shorter lifespan can enhance security, it sacrifices some convenience. Users need to make their trade-offs.

At the core of Kerberos lies the utilization of a symmetric encryption algorithm. The server employs locally stored password hashes to encrypt the authentication data, which is then transmitted to the client. The client, in turn, hashes its password and utilizes it to decrypt the received authentication data. This process offers several advantages, including the elimination of the need to transmit passwords in plain text over the network and enabling mutual verification of the correct password between the server and client.

Additionally, through symmetric encryption, the server and client can securely share session keys, which can be utilized for subsequent encrypted communication. Therefore, Kerberos also provides security measures for protecting subsequent communications beyond authentication.

While providing strong security, Kerberos also brings significant complexity. Implementing and configuring Kerberos comes with its challenges, and its reliance on up to six handshakes can introduce requirements for high network latency and reliability. As a result, Kerberos is typically employed within the internal network environments of enterprises.

How Does Enhanced Authentication Work in MQTT?

Let’s examine how enhanced authentication works in MQTT using the SCRAM as an example. While this article will not delve into the specific principles of SCRAM, it’s important to note that SCRAM requires the following four messages to complete authentication:

  • client-first-message
  • server-first-message
  • client-final-message
  • server-final-message

EMQ Technologies Inc.

To initiate SCRAM authentication, the client sends a CONNECT packet with the Authentication Method attribute set to SCRAM-SHA-256, indicating the intention to use SCRAM authentication. SHA-256 indicates the hash function to be used. The Authentication Data attribute is used to store the content of the client-first message. The Authentication Method attribute determines how the server should parse and process the data contained in the Authentication Data field.

If the server does not support SCRAM authentication, or if the content of the client-first message is found to be invalid, it will return a CONNACK packet containing a Reason Code indicating the reason for authentication failure, and then close the network connection.

Otherwise, the server will proceed with the next step: return an AUTH packet and set Reason Code to 0x18, indicating continued authentication. The Authentication Method in the packet will be the same as the CONNECT packet, and the Authentication Data attribute will contain the content of the server-first message.

After verifying that the content of the server-first message is correct, the client also returns an AUTH packet with Reason Code 0x18, and the Authentication Data attribute will contain the content of the client-final message.

After verifying that the content of the client-final message is correct, the server has completed the verification of the client’s identity. So, this time, the server will not return an AUTH packet, but a CONNACK packet with Reason Code 0 to indicate successful authentication and pass the server-final message through the Authentication Data attribute in the packet.

If the server’s identity is successfully verified, the client can proceed to subscribe to topics or publish messages. However, if the verification fails, the client will send a DISCONNECT packet to terminate the connection.

More Identity Verification Methods

Enhanced authentication provides users with the possibility to introduce more identity verification methods. You can choose authentication methods suitable for your specific needs and further enhance the security of your system.

Tweet

Share

Share

Email

  • Cybersecurity
  • Data Analytics
  • Network and Protocols
  • Security

  • Cybersecurity
  • Data Analytics
  • Network and Protocols
  • Security

参考译文
利用增强型身份验证提升MQTT安全性
插图:© IoT For All --> 增强型身份验证是MQTT 5.0中引入的一种全新的身份验证框架。它提供了一系列比传统密码身份验证更安全的替代方法。然而,更高的安全性也带来了更多的复杂性。某些身份验证方法,比如SCRAM,需要多次交换身份验证数据。这使得CONNECT和CONNACK数据包中单次交换身份验证框架过时了。为了解决这个局限性,MQTT 5.0引入了AUTH数据包,以支持多次交换身份验证数据。它使得在MQTT中可以使用SASL(Simple Authentication and Security Layer,简单身份验证和安全层)机制中的挑战-响应风格。增强型身份验证解决了哪些问题?在深入了解增强型身份验证之前,我们必须了解传统密码身份验证在安全性方面的不足之处。实际上,尽管使用诸如Salt和Hash等技术来安全地存储密码,客户端仍然必须在网络上传输明文密码,从而使其容易被盗取。即使在使用TLS加密通信的情况下,由于SSL版本过旧、弱密码套件或存在伪造的CA证书,攻击者仍有可能获取密码等敏感信息。此外,简单的密码身份验证只能让服务器验证客户端的身份,而不能反过来验证服务器,这就允许攻击者伪装成服务器从客户端获取敏感信息。这就是我们常说的中间人攻击。增强型身份验证使用户可以在SASL框架内使用高安全性的身份验证方法。这些方法具有许多优势,例如消除了密码在网络上的传输,并实现了客户端与服务器之间的相互身份验证。通过提供这些选项,用户可以自由选择与自身特定需求和安全偏好相匹配的身份验证方法。用于增强型身份验证的常见SASL机制 **DIGEST-MD5** DIGEST-MD5是SASL框架中的一种身份验证方法。它使用消息摘要5(MD5)哈希算法和挑战-响应机制来验证客户端和服务器之间的身份。一个显著的优势是客户端不需要通过网络传输明文密码。简单来说,当客户端想要访问受保护资源时,服务器将发送一个挑战,包括一个一次性随机数和一些所需参数。客户端利用这些参数、用户名和密码生成一个响应,然后将其发送回服务器。服务器用相同的方法独立生成一个预期响应,并将其与接收到的响应进行比较。如果匹配,身份验证成功。这种方法有效降低了密码通过网络嗅探暴露的风险。此外,通过为每次连接使用一次性随机数,增强了对重放攻击的防护。然而,需要注意的是,DIGEST-MD5虽然能够实现服务器对客户端身份的验证,但无法实现客户端对服务器身份的验证。这一限制为中间人攻击留下了可能性。此外,由于MD5已不再安全,建议强烈将其替换为对碰撞攻击具有更强抵抗力的哈希函数,例如SHA-256。**SCRAM** SCRAM(Salted Challenge Response Authentication Mechanism,加盐的挑战响应身份验证机制)是SASL框架中的另一种身份验证方法。它在方法上与DIGEST-MD5相似。SCRAM通过让客户端使用一次性随机数生成响应,从而避免在网络上传输明文密码。然而,SCRAM通过引入Salt(盐值)、Iterations(迭代次数)以及更强大的哈希算法(例如SHA-256和SHA-512)进一步增强了安全性。这些改进显著提升了密码存储的安全性,有效降低了离线攻击、重放攻击及其他潜在漏洞的风险。此外,SCRAM引入了一个更为复杂的挑战-响应过程,包括服务器向客户端发送的验证信息。客户端可以利用该信息验证服务器是否拥有正确的密码,从而实现相互身份验证。这一步骤进一步降低了中间人攻击的风险。然而,SCRAM中使用哈希算法(如SHA256)会带来额外的计算开销,这可能会对资源受限的设备性能产生影响。**Kerberos** Kerberos利用一个可信的第三方Kerberos服务器来提供身份验证服务。服务器向经过验证的用户颁发令牌,使其能够访问资源服务器。一个显著的优势是用户可以通过一次身份验证访问多个系统和服务,实现单点登录(SSO)的便利性。Kerberos服务器颁发的令牌具有有限的生命周期,客户端只能在特定时间内使用该令牌访问服务,从而防止由于令牌泄露带来的安全问题。当然,虽然较短的生命周期可以增强安全性,但这也牺牲了一些便利性。用户需要在这之间做出权衡。Kerberos的核心在于使用对称加密算法。服务器使用本地存储的密码哈希加密身份验证数据,然后将其发送给客户端。客户端通过哈希其密码并使用该密码解密接收到的身份验证数据。这个过程具有多项优势,包括消除了在网上传输明文密码的需求,并实现了服务器和客户端之间对正确密码的相互验证。此外,通过对称加密,服务器和客户端可以安全地共享会话密钥,用于后续的加密通信。因此,Kerberos还提供了在身份验证之外保护后续通信的安全措施。MQTT中增强型身份验证的工作方式 我们以SCRAM为例,来看看MQTT中增强型身份验证是如何工作的。尽管本文不会深入探讨SCRAM的具体原理,但需要明确的是,SCRAM需要以下四条消息来完成身份验证: - client-first-message(客户端首条消息) - server-first-message(服务器首条消息) - client-final-message(客户端最终消息) - server-final-message(服务器最终消息) EMQ Technologies Inc. 为了启动SCRAM身份验证,客户端将发送一个CONNECT数据包,并将身份验证方法属性设置为SCRAM-SHA-256,表明其打算使用SCRAM身份验证。SHA-256表示所使用的哈希函数。身份验证数据属性用于存储客户端首条消息的内容。身份验证方法属性决定了服务器应该如何解析和处理身份验证数据字段中的数据。如果服务器不支持SCRAM身份验证,或者客户端首条消息的内容被发现无效,服务器将返回一个包含原因代码的CONNACK数据包,指示身份验证失败的原因,然后关闭网络连接。否则,服务器将继续下一步:返回一个AUTH数据包,并设置原因代码为0x18,表示身份验证继续。数据包中的身份验证方法将与CONNECT数据包相同,身份验证数据属性将包含服务器首条消息的内容。在验证了服务器首条消息内容的正确性后,客户端也将返回一个AUTH数据包,原因代码为0x18,身份验证数据属性将包含客户端最终消息的内容。在验证了客户端最终消息内容的正确性后,服务器完成对客户端身份的验证。此时,服务器将不会返回AUTH数据包,而是返回一个原因代码为0的CONNACK数据包,表示身份验证成功,并通过数据包中的身份验证数据属性传递服务器最终消息。如果服务器身份成功验证,客户端可以继续订阅主题或发布消息。但如果验证失败,客户端将发送一个DISCONNECT数据包以终止连接。更多身份验证方法 增强型身份验证为用户提供引入更多身份验证方法的可能性。您可以选择适合自己特定需求的身份验证方法,从而进一步增强系统的安全性。推特 分享 邮件 网络安全 数据分析 网络与协议 安全
您觉得本篇内容如何
评分

评论

您需要登录才可以回复|注册

提交评论

广告
提取码
复制提取码
点击跳转至百度网盘