Skip to content

Commit

Permalink
Merged PR 928705: Fix EdgeHub in IotedgeCtl mode issue
Browse files Browse the repository at this point in the history
EdgeHub was expecting its cert to be present in the path pointed to by the environment variables SSL_CERTIFICATE_PATH and SSL_CERTIFICATE_NAME. However, since the start.sh script was removed, these environment variables are no longer being set.
So updating EdgeHub to instead use the new Cert path Environment variables.
Tested with 1.0 bits.
  • Loading branch information
varunpuranik committed Jun 28, 2018
1 parent 92e45a3 commit cc7e142
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
2 changes: 0 additions & 2 deletions edge-hub/docker/linux/amd64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ FROM azureiotedge/azureiotedge-runtime-base:1.0.0-preview001-linux-amd64 as buil
FROM microsoft/dotnet:${base_tag}

ARG EXE_DIR=.
ENV SSL_CERTIFICATE_PATH=/app/certs
ENV SSL_CERTIFICATE_NAME=mqtt-server.pfx

# RocksDB requires snappy
RUN apk update && \
Expand Down
2 changes: 0 additions & 2 deletions edge-hub/docker/linux/arm32v7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ ARG base_tag=1.0.0-preview008-linux-arm32v7
FROM azureiotedge/azureiotedge-hub-base:${base_tag}

ARG EXE_DIR=.
ENV SSL_CERTIFICATE_PATH=/etc/ssl/certs
ENV SSL_CERTIFICATE_NAME=mqtt-server.pfx

WORKDIR /app

Expand Down
3 changes: 0 additions & 3 deletions edge-hub/docker/windows/amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
ARG base_tag=2.1.0-runtime-nanoserver-1803
FROM microsoft/dotnet:${base_tag}

ENV SSL_CERTIFICATE_PATH=c:\\mnt\\edgehub
ENV SSL_CERTIFICATE_NAME=edge-hub-server.cert.pfx

ARG EXE_DIR=.

WORKDIR /app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public static class Constants
public const string WorkloadApiVersion = "2018-06-28";
public const int CertificateValidityDays = 90;
public const string InitializationVectorFileName = "EdgeHubIV";
public const string EdgeHubServerCAChainCertificateFileKey = "EdgeModuleHubServerCAChainCertificateFile";
public const string EdgeHubServerCertificateFileKey = "EdgeModuleHubServerCertificateFile";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public static async Task<int> MainAsync(IConfigurationRoot configuration)
}
else
{
(cert, chain) = CertificateHelper.GetServerCertificatesFromFile(configuration.GetValue<string>(Constants.SslCertPathEnvName), configuration.GetValue<string>(Constants.SslCertEnvName));
string edgeHubCertPath = configuration.GetValue<string>(Constants.EdgeHubServerCertificateFileKey);
cert = new X509Certificate2(edgeHubCertPath);
string edgeHubCaChainCertPath = configuration.GetValue<string>(Constants.EdgeHubServerCAChainCertificateFileKey);
chain = CertificateHelper.GetServerCACertificatesFromFile(edgeHubCaChainCertPath);
}

// TODO: set certificate for Startup without the cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,10 @@ public static IEnumerable<X509Certificate2> GetCertificatesFromPem(IEnumerable<s
return ParseCertificateResponse(response);
}

public static (X509Certificate2, IEnumerable<X509Certificate2>) GetServerCertificatesFromFile(string certPath, string certName)
public static IEnumerable<X509Certificate2> GetServerCACertificatesFromFile(string chainPath)
{
string certFullPath = Path.Combine(certPath, certName);
var sslCert = new X509Certificate2(Preconditions.CheckNonWhiteSpace(certFullPath, nameof(certFullPath)));

string chainPath = Environment.GetEnvironmentVariable("EdgeModuleHubServerCAChainCertificateFile");
IEnumerable<X509Certificate2> certChain = !string.IsNullOrWhiteSpace(chainPath) ? ExtractCertsFromPem(chainPath) : null;
return (sslCert, certChain);
return certChain;
}

public static IList<string> ParsePemCerts(string pemCerts)
Expand Down

0 comments on commit cc7e142

Please sign in to comment.