Skip to content

Commit

Permalink
Updated how-to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pglombardo committed Jan 9, 2024
1 parent 38e4bbc commit 68e0433
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
48 changes: 46 additions & 2 deletions Documentation/docs/how-to/client-certificates.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,61 @@ For more information on X.509 client certificates, see the following:

You can add one or more client certificates to the HiveMQtt client through the `HiveMQClientOptionsBuilder` class.

Adding certificates will cause the client to present these certificates to the broker upon TLS connection negotiation.

# Using X509Certificate2

```csharp
using HiveMQtt.Client.Options;
using System.Security.Cryptography.X509Certificates;

// Can pre-create a X509Certificate2 or alternatively pass a string path
// to the certificate (see below)
var clientCertificate = new X509Certificate2('path/to/certificate-file-1.pem');

var options = new HiveMQClientOptionsBuilder().
var options = new HiveMQClientOptionsBuilder()
.WithClientCertificate(clientCertificate);
.WithClientCertificate('path/to/certificate-file-2.pem');

var client = new HiveMQttClient(options);
```

Adding the certificates will cause the client to present these certificates to the broker upon TLS connection negotiation.
# Using Certificates with a Passwords

If your certificate and protected with a password, you can either instantiate the
`X509Certificate2` object manually and pass it to the HiveMQtt client with
`WithClientCertificate`:

```csharp
using HiveMQtt.Client.Options;
using System.Security.Cryptography.X509Certificates;

var clientCertificate = new X509Certificate2('path/to/certificate-with-password.pem',
'certificate-password');

var options = new HiveMQClientOptionsBuilder()
.WithClientCertificate(clientCertificate);

var client = new HiveMQttClient(options);
```

...or alternatively, just pass the string path to the certificate with the password:

```csharp
using HiveMQtt.Client.Options;
using System.Security.Cryptography.X509Certificates;


var options = new HiveMQClientOptionsBuilder()
.WithClientCertificate(
'path/to/certificate-with-password.pem',
'certificate-password'
);

var client = new HiveMQttClient(options);
```

# Extended Options

TLS negotiation with client certificates is based on the `X509Certificate2` class. See the [official
.NET documentation](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate2?view=net-8.0) for more options and information.
2 changes: 1 addition & 1 deletion Documentation/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const config = {
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} HiveMQ, GmbH. Built with Docusaurus.`,
copyright: `Copyright © ${new Date().getFullYear()} HiveMQ, GmbH.`,
},
prism: {
additionalLanguages: ['csharp'],
Expand Down

0 comments on commit 68e0433

Please sign in to comment.