in dotnet/src/Azure.Iot.Operations.Protocol/Connection/MqttConnectionSettings.cs [257:298]
protected internal void ValidateMqttSettings(bool validateOptionalSettings)
{
if (string.IsNullOrWhiteSpace(HostName))
{
throw new ArgumentException($"{nameof(HostName)} is mandatory.", nameof(HostName));
}
if (string.IsNullOrEmpty(ClientId))
{
throw new ArgumentException($"{nameof(ClientId)} is mandatory.", nameof(ClientId));
}
if (!string.IsNullOrEmpty(SatAuthFile) && (!string.IsNullOrEmpty(PasswordFile)))
{
throw new ArgumentException(
$"{nameof(SatAuthFile)} cannot be used with {nameof(PasswordFile)}", nameof(SatAuthFile));
}
if (validateOptionalSettings)
{
if (!string.IsNullOrWhiteSpace(KeyFile) && string.IsNullOrWhiteSpace(CertFile))
{
throw new ArgumentException(
$"{nameof(CertFile)} and {nameof(KeyFile)} need to be provided together.",
$"{nameof(CertFile)} and {nameof(KeyFile)}");
}
}
if (!string.IsNullOrWhiteSpace(CertFile))
{
ClientCertificate = string.IsNullOrWhiteSpace(KeyPasswordFile)
? X509Certificate2.CreateFromPemFile(CertFile, KeyFile)
: X509Certificate2.CreateFromEncryptedPemFile(CertFile, KeyPasswordFile, KeyFile);
}
if (!string.IsNullOrWhiteSpace(CaFile))
{
X509Certificate2Collection chain = [];
chain.ImportFromPemFile(CaFile);
TrustChain = chain;
}
}