Skip to content

Commit

Permalink
Merge pull request #20 from hivemq/feature/add-tls-and-client-certifi…
Browse files Browse the repository at this point in the history
…cate-support-#6

Feature/add tls and client certificate support #6
  • Loading branch information
gitseti committed Aug 8, 2019
2 parents 8dc5444 + cdf6b89 commit bec44a0
Show file tree
Hide file tree
Showing 31 changed files with 960 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/.idea
/mqtt-cli.iml
/hmq-mqtt.*.log.txt
/*.pem
/test-certificates/
65 changes: 42 additions & 23 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,32 @@ All further attributes are not mandatory.

```
mqtt con { @<fileName> |
-v {3|5}
-h <host>
-p <port>
-i client identifier
-u {<'user name'>}
-pw {$|<'password'>| @<fileName>}
-cs {0|1}
-se {0|1}
-wt {$|<'topic'>};
-wq {0|1|2|AT_MOST_ONCE|AT_LEAST_ONCE|EXACTLY_ONCE}
-wm {$|<'payload'>|@<fileName>};
-wr {0|1}
-we {[0 - 4_294_967_295]}
-wd {[0 - 4_294_967_295]}
-wp {UTF8|UTF_8}
-wc {<'content description'>}
-wrt {$|<'response topic'>}
-wcd {<'correlation data'>}
-wu {[<'header'='value'> [|<'header'>=<'value'>]]}
-sc {0|1}
-v {3|5}
-h <host>
-p <port>
-i client identifier
-u {<'user name'>}
-pw {∅|$|<'password'>| @<fileName>}
-cs {0|1}
-se {0|1}
-wt {$|<'topic'>};
-wq {0|1|2|AT_MOST_ONCE|AT_LEAST_ONCE|EXACTLY_ONCE}
-wm {$|<'payload'>|@<fileName>};
-wr {0|1}
-we {[0 - 4_294_967_295]}
-wd {[0 - 4_294_967_295]}
-wp {UTF8|UTF_8}
-wc {<'content description'>}
-wrt {$|<'response topic'>}
-wcd {<'correlation data'>}
-wu {[<'header'='value'> [|<'header'>=<'value'>]*}
-s {0|1}
--cafile {'filepath'}
--capath {'directorypath'}
--ciphers {['TLS_ciphersuite'] [:'TLS_ciphersuite']*}
--tls-version {'TLS_version'}
--cert {'filepath'}
--key {'filepath'}
}
```
|===
Expand All @@ -107,9 +113,11 @@ mqtt con { @<fileName> |
| -p | --port| The MQTT port. | 1883 will be used
| -i | --identifier| A unique Client identifier can be defined. | A randomly defined UTF-8 String will be generated.
| -u | --user | A User name can be defined. | Not set - user name will be empty.
| -pw | --password | A password can be defined direct or
| -pw | --password | A password can be defined directly, or

$ - via input from console - prompt, or
left blank - via input from console prompt, or

$ - via input from console prompt, or

@<fileName> - read from file
| Not set - password will be empty.
Expand Down Expand Up @@ -140,9 +148,20 @@ Can be disabled by setting it to ```4_294_967_295```|4_294_967_295


| -sc | --stayConnected | The client stays connected 0 or 1 | 0 - the client will be disconnected immediately. In shell mode the Client stays connected.
| -s | --secure | The client uses the default ssl configuration to communicate with the broker | False
| | --cafile | Path to a file containing a trusted CA certificate to enable encrypted certificate based communication | default empty
| | --capath | Path to a directory containing trusted CA certificates to enable encrypted certificate based communication | default empty
| | --ciphers | The supported cipher suites in IANA string format concatenated by the ':' character if more than one cipher should be supported.

See https://www.iana.org/assignments/tls-parameters/tls-parameters.xml for supported cipher suite strings.
| default empty
| | --tls-version | The TLS version to use | TLSv1.2
| | --cert | The path to the client certificate to use for client-side authentication.

NOTE: Currently only self signed certificates are supported. | default empty
| | --key | The path to the client private key to use for client-side authentication. | default empty
|===


.Full Example
```
mqtt con -i C1 -u Max -pw $ -sc 1
Expand Down
10 changes: 8 additions & 2 deletions assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>target/README.html</source>
<source>hivemq-cli</source>
<destName>hivemq-cli</destName>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>hivemq-cli</source>
<destName>hivemq-cli</destName>
<outputDirectory>/brew/</outputDirectory>
</file>
<file>
<source>target/${artifactId}-${version}.jar</source>
<destName>${artifactId}-${version}.jar</destName>
<destName>${artifactId}.jar</destName>
<outputDirectory>/</outputDirectory>
</file>
</files>
Expand Down
3 changes: 3 additions & 0 deletions hivemq-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# Runs HiveMQ-Cli
java -jar ##PREFIX##/hivemq-cli.jar "$@"
46 changes: 38 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.hivemq</groupId>
<artifactId>mqtt-cli</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>hivemq-cli</artifactId>
<version>1.0</version>

<description>HiveMQ MQTT Command line Interface</description>

Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.hivemq</groupId>
<artifactId>hivemq-mqtt-client</artifactId>
<version>1.0.1</version>
<version>1.1.1</version>
</dependency>

<!-- tiny fast logging framework -->
Expand All @@ -51,9 +51,9 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -85,7 +85,18 @@
<version>5.4.2</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.62</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.62</version>
</dependency>
<!--
<dependency>
<groupId>io.netty</groupId>
Expand Down Expand Up @@ -173,13 +184,32 @@
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptor>assembly.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>


<!--plugin>
<groupId>com.oracle.substratevm</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>1.0.0-rc14</version>
<configuration>
< configuration is declared in
resources/META-INF/native-image/com.hivemq/mqtt-cli/native-image.properties
resources/META-INF/native-image/com.hivemq/hivemq-cli/native-image.properties
/>
<mainClass>com.hivemq.cli.Mqtt</mainClass>
</configuration>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/hivemq/cli/Mqtt.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.pmw.tinylog.writers.RollingFileWriter;
import picocli.CommandLine;

import java.security.Security;
import java.util.List;

@CommandLine.Command(name = "mqtt",
Expand All @@ -36,6 +37,7 @@ public static void main(String[] args) {
final CommandLine cmd = new CommandLine(mqtt);
final HmqCli hmqCli = new HmqCli();
short status = EXIT_FAIL;
Security.setProperty("crypto.policy", "unlimited");

Configurator.defaultConfig()
.writer(new RollingFileWriter("hmq-mqtt-log.txt", 30, false, new TimestampLabeler("yyyy-MM-dd"), new SizePolicy(1024 * 10)))
Expand Down

0 comments on commit bec44a0

Please sign in to comment.