1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ // Ignore Spelling: Keyfactor IISU Crypto
1516using System ;
1617using System . Collections . Generic ;
1718using System . Collections . ObjectModel ;
@@ -34,7 +35,9 @@ public class Management : WinCertJobTypeBase, IManagementJobExtension
3435 private ILogger _logger ;
3536
3637 private PSHelper _psHelper ;
38+ #pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3739 private Collection < PSObject > ? _results = null ;
40+ #pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3841
3942 // Function wide config values
4043 private string _clientMachineName = string . Empty ;
@@ -99,11 +102,15 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
99102 {
100103 string certificateContents = config . JobCertificate . Contents ;
101104 string privateKeyPassword = config . JobCertificate . PrivateKeyPassword ;
105+ #pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
102106 string ? cryptoProvider = config . JobProperties [ "ProviderName" ] ? . ToString ( ) ;
107+ #pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
103108
104109 // Add Certificate to Cert Store
105110 try
106111 {
112+ IISBindingInfo bindingInfo = new IISBindingInfo ( config . JobProperties ) ;
113+
107114 OrchestratorJobStatusJobResult psResult = OrchestratorJobStatusJobResult . Unknown ;
108115 string failureMessage = "" ;
109116
@@ -112,9 +119,8 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
112119 _logger . LogTrace ( $ "New thumbprint: { newThumbprint } ") ;
113120
114121 // Bind Certificate to IIS Site
115- if ( newThumbprint != null )
122+ if ( ! string . IsNullOrEmpty ( newThumbprint ) )
116123 {
117- IISBindingInfo bindingInfo = new IISBindingInfo ( config . JobProperties ) ;
118124 _logger . LogTrace ( "Returned after binding certificate to store" ) ;
119125 var results = WinIISBinding . BindCertificate ( _psHelper , bindingInfo , newThumbprint , "" , _storePath ) ;
120126 if ( results != null && results . Count > 0 )
@@ -172,6 +178,14 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
172178 FailureMessage = failureMessage
173179 } ;
174180 }
181+ else
182+ {
183+ complete = new JobResult
184+ {
185+ Result = OrchestratorJobStatusJobResult . Failure ,
186+ JobHistoryId = _jobHistoryID ,
187+ FailureMessage = $ "No thumbprint was returned. Unable to bind certificate to site: { bindingInfo . SiteName } ."
188+ } ; }
175189 }
176190 catch ( Exception ex )
177191 {
@@ -183,7 +197,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
183197 } ;
184198 }
185199
186- _logger . LogTrace ( $ "Completed adding and binding the certificate to the store ") ;
200+ _logger . LogTrace ( $ "Exiting the Adding of Certificate process. ") ;
187201
188202 break ;
189203 }
0 commit comments