0

I'm currently digging into HiveMQ Plugin development. I developed custom functionality based on AfterLoginCallback. I configured a working TLS connection and I'm able to connect with the clients certificate.

mosquitto_pub.exe -t test -m "testMessage" --cafile myCertificates/hivemq-server-cert.pem  --cert myCertificates/sender.crt --key myCertificates/sender.key -p 8883"

However, when I debug the AfterLoginCallback code I find that my "ClientData -> certificate" is "null" throwing a IllegalStateExcpetion when accessed.

[INFO] java.lang.IllegalStateException: Optional.get() cannot be called on an absent value
[INFO]  at com.google.common.base.Absent.get(Unknown Source)
[INFO]  at mycode.hivemq.plugins.first_plugin.callbacks.AfterLoginCallbackTest.afterSuccessfulLogin(AfterLoginCallbackTest.java:33)

Can anyone explain please, why the certificate is null?

Thanks, Lomungo

Green Lomu
  • 65
  • 1
  • 9
  • 1
    Please make sure that you set client-authentication-mode to "OPTIONAL" or "REQUIRED" in your configuration file. An example can be found here: http://www.hivemq.com/docs/hivemq/latest/#client-cert-tls – Schäbo Sep 16 '16 at 12:03
  • yes, setting it from NONE to OPTIONAL or REQUIRED solved the problem. – Green Lomu Sep 20 '16 at 19:48

1 Answers1

6

In the callback to check the credentials the clientData must be handled as ClientCredentialData

Here is an example:

public class AuthorizationCallback implements OnAuthenticationCallback, OnAuthorizationCallback {

    @Override
    public Boolean checkCredentials(@NotNull final ClientCredentialsData clientData) throws AuthenticationException {

        //Throw out clients which didn't provide a client certificate
        if (!clientData.getCertificate().isPresent()) {
            log.debug("Client {} didn't provide a client certificate. Disconnecting client", clientData.getClientId());
            throw AuthenticationExceptions.WRONG_CERTIFICATE;
        }

        final Certificate certificate = clientData.getCertificate().get().certificate();
        ...
        }

}

Hope that helps!

gehbiszumeis
  • 3,525
  • 4
  • 24
  • 41
Anja H
  • 119
  • 2
  • 5