Skip to content

Mochi Broker mTLS #447

Closed Answered by IshanDaga
leandrofars asked this question in Q&A
Jan 17, 2025 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hey @leandrofars
Here is how we're doing this in production today:

I have a hook that provides mqtt.OnConnectAuthenticate and mqtt.OnACLCheck

Here is a sample implementation of our OnConnectAuthenticate function:

func (ah *ACLHook) OnConnectAuthenticates(cl *mqtt.Client, pk packets.Packet) bool {
        var flag bool
	var deviceInfo *DeviceInfos
	var parseError error

	tlsConn, ok := cl.Net.Conn.(*tls.Conn)
	if !ok {
		slog.Error("Error while getting tls connection")
		return false
	}

	// check that clientid and certificate common name match
	for _, cert := range tlsConn.ConnectionState().PeerCertificates {
		if cl.ID == cert.Subject.CommonName {
			deviceInfo, parseError := GetDeviceIn…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@leandrofars
Comment options

Answer selected by leandrofars
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants