Skip to content

Commit

Permalink
Merge pull request #18046 from afishbeck/espIssuerBasedTlsConfig
Browse files Browse the repository at this point in the history
HPCC-30755 Allow ESP server TLS config to be based on an issuer name

Reviewed-by: Gavin Halliday <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Nov 17, 2023
2 parents e557d19 + d93e2fb commit 3630d8f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
48 changes: 27 additions & 21 deletions esp/bindings/http/platform/httpprot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,32 +216,38 @@ CSecureHttpProtocol::CSecureHttpProtocol(IPropertyTree* cfg)
{
m_config.setown(cfg);

//ensure keys are specified. Passphrase is optional
StringBuffer sb;
cfg->getProp("certificate", sb);
if(sb.length() == 0)
{
throw MakeStringException(-1, "certificate file not specified in config file");
}
IEspPlugin *pplg = loadPlugin(SSLIB);
if (!pplg)
throw MakeStringException(-1, "dll/shared-object %s can't be loaded", SSLIB);

cfg->getProp("privatekey", sb.clear());
if(sb.length() == 0)
const char *issuer = cfg->queryProp("issuer");
if (!isEmptyString(issuer))
{
throw MakeStringException(-1, "private key file not specified in config file");
const char *trustedPeers = nullptr;
if (cfg->hasProp("verify"))
trustedPeers = cfg->queryProp("verify/trusted_peers");
createSecureSocketContextSecretSrv_t xproc = (createSecureSocketContextSecretSrv_t) pplg->getProcAddress("createSecureSocketContextSecretSrv");
if (!xproc)
throw MakeStringException(-1, "procedure createSecureSocketContextSecretSrv can't be loaded");
m_ssctx.setown(xproc(issuer, trustedPeers, false));
}

createSecureSocketContextEx2_t xproc = NULL;
IEspPlugin *pplg = loadPlugin(SSLIB);
if (pplg)
xproc = (createSecureSocketContextEx2_t) pplg->getProcAddress("createSecureSocketContextEx2");
else
throw MakeStringException(-1, "dll/shared-object %s can't be loaded", SSLIB);


if (xproc)
{
//ensure keys are specified. Passphrase is optional
StringBuffer sb;
cfg->getProp("certificate", sb);
if(sb.isEmpty())
throw MakeStringException(-1, "certificate file not specified in config file");

cfg->getProp("privatekey", sb.clear());
if(sb.isEmpty())
throw MakeStringException(-1, "private key file not specified in config file");

createSecureSocketContextEx2_t xproc = (createSecureSocketContextEx2_t) pplg->getProcAddress("createSecureSocketContextEx2");
if (!xproc)
throw MakeStringException(-1, "procedure createSecureSocketContextEx2 can't be loaded");
m_ssctx.setown(xproc(cfg, ServerSocket));
else
throw MakeStringException(-1, "procedure createSecureSocketContextEx2 can't be loaded");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions helm/hpcc/templates/esp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data:
tls: {{ include "hpcc.isIssuerEnabled" (dict "root" .root "issuerKeyName" $issuerKeyName) }}
{{- end }}
tls_config:
issuer: {{ $issuerKeyName }}
{{- if $externalCert }}
certificate: /opt/HPCCSystems/secrets/certificates/{{ $issuerKeyName }}/tls.crt
privatekey: /opt/HPCCSystems/secrets/certificates/{{ $issuerKeyName }}/tls.key
Expand Down
2 changes: 1 addition & 1 deletion system/mp/mpcomm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ CMPConnectThread::CMPConnectThread(CMPServer *_parent, unsigned port, bool _list

#if defined(_USE_OPENSSL)
if (parent->useTLS)
secureContextServer.setown(createSecureSocketContextSecretSrv("local", true));
secureContextServer.setown(createSecureSocketContextSecretSrv("local", nullptr, true));
#endif
}

Expand Down
11 changes: 6 additions & 5 deletions system/security/securesocket/securesocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,14 +2011,15 @@ SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSecret(const cha
}


SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSecretSrv(const char *issuer, bool requireMtlsFlag)
SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSecretSrv(const char *issuer, const char *optTrustedPeers, bool requireMtlsFlag)
{
if (requireMtlsFlag && !queryMtls())
throw makeStringException(-100, "TLS secure communication requested but not configured");
throw makeStringException(-100, "MTLS secure context required but not configured");

Owned<const ISyncedPropertyTree> info = getIssuerTlsSyncedConfig(issuer, optTrustedPeers, false);

Owned<const ISyncedPropertyTree> info = getIssuerTlsSyncedConfig(issuer);
if (!info->isValid())
throw makeStringException(-101, "TLS secure communication requested but not configured (2)");
throw makeStringExceptionV(-101, "TLS issuer %s secure context requested but not configured (2)", issuer);

return createSecureSocketContextSynced(info, ServerSocket);
}
Expand Down Expand Up @@ -2216,7 +2217,7 @@ class CSingletonSecureSocketConnection: public CSingletonSocketConnection
state = Snone;
cancelling = false;
secureContextClient.setown(createSecureSocketContextSecret("local", ClientSocket));
secureContextServer.setown(createSecureSocketContextSecretSrv("local", true));
secureContextServer.setown(createSecureSocketContextSecretSrv("local", nullptr, true));
#ifdef _CONTAINERIZED
tlsLogLevel = getComponentConfigSP()->getPropInt("logging/@detail", SSLogMin);
if (tlsLogLevel >= ExtraneousMsgThreshold) // or InfoMsgThreshold ?
Expand Down
3 changes: 2 additions & 1 deletion system/security/securesocket/securesocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ typedef ISecureSocketContext* (*createSecureSocketContext_t)(SecureSocketType);
typedef ISecureSocketContext* (*createSecureSocketContextEx_t)(const char* certFileOrBuf, const char* privKeyFileOrBuf, const char* passphrase, SecureSocketType);
typedef ISecureSocketContext* (*createSecureSocketContextEx2_t)(IPropertyTree* config, SecureSocketType);
typedef ISecureSocketContext* (*createSecureSocketContextSecret_t)(const char *mtlsSecretName, SecureSocketType);
typedef ISecureSocketContext* (*createSecureSocketContextSecretSrv_t)(const char *mtlsSecretName, const char *optTrustedPeers, bool requireMtlsConfig);

extern "C" {

//The following allow the creation of a secure socket context where the certificates will automatically be updated when they expire.
SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSynced(const ISyncedPropertyTree * config, SecureSocketType sockettype); // Will become the primary (only) factory method
SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSecret(const char *mtlsSecretName, SecureSocketType);
SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSecretSrv(const char *mtlsSecretName, bool requireMtlsConfig);
SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSecretSrv(const char *mtlsSecretName, const char *optTrustedPeers, bool requireMtlsConfig);
SECURESOCKET_API ISecureSocketContext* createSecureSocketContextSSF(ISmartSocketFactory* ssf);

//Helper function to aid migration to the functions above. This should eventually be removed.
Expand Down
2 changes: 1 addition & 1 deletion thorlcr/msort/tsorts1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected: friend class CSortMerge;
#if defined(_USE_OPENSSL)
if (slave.queryTLS())
{
secureContextServer.setown(createSecureSocketContextSecretSrv("local", true));
secureContextServer.setown(createSecureSocketContextSecretSrv("local", nullptr, true));
secureContextClients.setown(createSecureSocketContextSecret("local", ClientSocket));
}
#endif
Expand Down

0 comments on commit 3630d8f

Please sign in to comment.