Skip to content

Commit

Permalink
SetSslCertSetKey fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
solidstore committed Jul 18, 2023
1 parent 1a4fabf commit 2f42efa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
26 changes: 20 additions & 6 deletions src/ext/Http/ca/sslcert.cpp
Expand Up @@ -52,7 +52,7 @@ static HRESULT RemoveSslCert(
__in_z LPWSTR wzHost,
__in int iPort
);
static void SetSslCertSetKey(
static HRESULT SetSslCertSetKey(
__in HTTP_SERVICE_CONFIG_SSL_KEY* pKey,
__in_z LPWSTR wzHost,
__in int iPort
Expand Down Expand Up @@ -270,7 +270,7 @@ static UINT SchedHttpSslCerts(
)
{
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
//UINT er = ERROR_SUCCESS;
BOOL fHttpInitialized = FALSE;
DWORD cCertificates = 0;

Expand Down Expand Up @@ -429,7 +429,7 @@ static UINT SchedHttpSslCerts(
::HttpTerminate(HTTP_INITIALIZE_CONFIG, NULL);
}

return WcaFinalize(er = FAILED(hr) ? ERROR_INSTALL_FAILURE : er);
return hr;
}

static HRESULT WriteExistingSslCert(
Expand Down Expand Up @@ -575,7 +575,9 @@ static HRESULT AddSslCert(
HRESULT hr = S_OK;
DWORD er = ERROR_SUCCESS;
HTTP_SERVICE_CONFIG_SSL_SET set = { };
SOCKADDR_STORAGE addr = { };

set.KeyDesc.pIpPort = reinterpret_cast<PSOCKADDR>(&addr);
SetSslCertSetKey(&set.KeyDesc, wzHost, iPort);
set.ParamDesc.SslHashLength = cbCertificateThumbprint;
set.ParamDesc.pSslHash = rgbCertificateThumbprint;
Expand Down Expand Up @@ -606,10 +608,12 @@ static HRESULT GetSslCert(
HTTP_SERVICE_CONFIG_SSL_QUERY query = { };
HTTP_SERVICE_CONFIG_SSL_SET* pSet = NULL;
ULONG cbSet = 0;
SOCKADDR_STORAGE addr = { };

*ppSet = NULL;

query.QueryDesc = HttpServiceConfigQueryExact;
query.KeyDesc.pIpPort = reinterpret_cast<PSOCKADDR>(&addr);
SetSslCertSetKey(&query.KeyDesc, wzHost, nPort);

er = ::HttpQueryServiceConfiguration(NULL, HttpServiceConfigSSLCertInfo, &query, sizeof(query), pSet, cbSet, &cbSet, NULL);
Expand Down Expand Up @@ -650,7 +654,9 @@ static HRESULT RemoveSslCert(
HRESULT hr = S_OK;
DWORD er = ERROR_SUCCESS;
HTTP_SERVICE_CONFIG_SSL_SET set = { };
SOCKADDR_STORAGE addr = { };

set.KeyDesc.pIpPort = reinterpret_cast<PSOCKADDR>(&addr);
SetSslCertSetKey(&set.KeyDesc, wzHost, iPort);

er = ::HttpDeleteServiceConfiguration(NULL, HttpServiceConfigSSLCertInfo, &set, sizeof(set), NULL);
Expand All @@ -666,14 +672,22 @@ static HRESULT RemoveSslCert(
return hr;
}

static void SetSslCertSetKey(
static HRESULT SetSslCertSetKey(
__in HTTP_SERVICE_CONFIG_SSL_KEY* pKey,
__in_z LPWSTR wzHost,
__in int iPort
)
{
SOCKADDR_IN* pss = reinterpret_cast<SOCKADDR_IN*>(&pKey->pIpPort);
InetPtonW(AF_INET, wzHost, &(pss->sin_addr));
DWORD er = ERROR_SUCCESS;

SOCKADDR_IN* pss = reinterpret_cast<SOCKADDR_IN*>(pKey->pIpPort);
pss->sin_family = AF_INET;
pss->sin_port = htons(static_cast<USHORT>(iPort));
if (!InetPtonW(AF_INET, wzHost, &pss->sin_addr))
{
er = WSAGetLastError();
}

HRESULT hr = HRESULT_FROM_WIN32(er);
return hr;
}
12 changes: 6 additions & 6 deletions src/ext/Http/wixext/HttpTableDefinitions.cs
Expand Up @@ -11,12 +11,12 @@ public static class HttpTableDefinitions
HttpSymbolDefinitions.WixHttpSniSslCert,
new[]
{
new ColumnDefinition("Wix4HttpSniSslCert", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("WixHttpSniSslCert", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("Host", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Host for the SNI SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Port", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Port for the SNI SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Thumbprint", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "humbprint of the SNI SSL certificate to find.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Thumbprint", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Thumbprint of the SNI SSL certificate to find.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("AppId", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Optional application id for the SNI SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Store", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Optional application id for the SNI SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Store", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Certificate store containing the SNI SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("HandleExisting", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 2, description: "The behavior when trying to install a SNI SSL certificate and it already exists."),
new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key into the Component table referencing the component that controls the URL reservation.", modularizeType: ColumnModularizeType.Column),
},
Expand All @@ -28,12 +28,12 @@ public static class HttpTableDefinitions
HttpSymbolDefinitions.WixHttpSslCert,
new[]
{
new ColumnDefinition("Wix4HttpSslCert", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("WixHttpSslCert", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
new ColumnDefinition("Host", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Host for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Port", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Port for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Thumbprint", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "humbprint of the SSL certificate to find.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Thumbprint", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "Thumbprint of the SSL certificate to find.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("AppId", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Optional application id for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Store", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Optional application id for the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("Store", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Certificate store containing the SSL certificate.", modularizeType: ColumnModularizeType.Property),
new ColumnDefinition("HandleExisting", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 2, description: "The behavior when trying to install a SSL certificate and it already exists."),
new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key into the Component table referencing the component that controls the URL reservation.", modularizeType: ColumnModularizeType.Column),
},
Expand Down

0 comments on commit 2f42efa

Please sign in to comment.