From 2f42efad01d5422d492fdc0ee918f19ef80565ee Mon Sep 17 00:00:00 2001 From: solidstore Date: Tue, 18 Jul 2023 11:21:21 +0100 Subject: [PATCH] SetSslCertSetKey fixes --- src/ext/Http/ca/sslcert.cpp | 26 ++++++++++++++++----- src/ext/Http/wixext/HttpTableDefinitions.cs | 12 +++++----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/ext/Http/ca/sslcert.cpp b/src/ext/Http/ca/sslcert.cpp index fe3aeefd5..bf8258606 100644 --- a/src/ext/Http/ca/sslcert.cpp +++ b/src/ext/Http/ca/sslcert.cpp @@ -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 @@ -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; @@ -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( @@ -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(&addr); SetSslCertSetKey(&set.KeyDesc, wzHost, iPort); set.ParamDesc.SslHashLength = cbCertificateThumbprint; set.ParamDesc.pSslHash = rgbCertificateThumbprint; @@ -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(&addr); SetSslCertSetKey(&query.KeyDesc, wzHost, nPort); er = ::HttpQueryServiceConfiguration(NULL, HttpServiceConfigSSLCertInfo, &query, sizeof(query), pSet, cbSet, &cbSet, NULL); @@ -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(&addr); SetSslCertSetKey(&set.KeyDesc, wzHost, iPort); er = ::HttpDeleteServiceConfiguration(NULL, HttpServiceConfigSSLCertInfo, &set, sizeof(set), NULL); @@ -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(&pKey->pIpPort); - InetPtonW(AF_INET, wzHost, &(pss->sin_addr)); + DWORD er = ERROR_SUCCESS; + + SOCKADDR_IN* pss = reinterpret_cast(pKey->pIpPort); pss->sin_family = AF_INET; pss->sin_port = htons(static_cast(iPort)); + if (!InetPtonW(AF_INET, wzHost, &pss->sin_addr)) + { + er = WSAGetLastError(); + } + + HRESULT hr = HRESULT_FROM_WIN32(er); + return hr; } diff --git a/src/ext/Http/wixext/HttpTableDefinitions.cs b/src/ext/Http/wixext/HttpTableDefinitions.cs index f0e49fe5e..3f743e4cd 100644 --- a/src/ext/Http/wixext/HttpTableDefinitions.cs +++ b/src/ext/Http/wixext/HttpTableDefinitions.cs @@ -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), }, @@ -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), },