1818using System . Text . Json ;
1919using System . Threading ;
2020using System . Threading . Tasks ;
21+ using System . Reflection ;
2122
2223namespace Keyfactor . Extensions . CAPlugin . HashicorpVault
2324{
@@ -50,10 +51,22 @@ public void Initialize(IAnyCAPluginConfigProvider configProvider, ICertificateDa
5051 {
5152 logger . MethodEntry ( LogLevel . Trace ) ;
5253 string rawConfig = JsonSerializer . Serialize ( configProvider . CAConnectionData ) ;
53- logger . LogTrace ( $ "serialized config: { rawConfig } ") ;
5454 _caConfig = JsonSerializer . Deserialize < HashicorpVaultCAConfig > ( rawConfig ) ;
5555 logger . MethodExit ( LogLevel . Trace ) ;
5656 _client = new HashicorpVaultClient ( _caConfig ) ;
57+ _certificateDataReader = certificateDataReader ;
58+
59+ Assembly targetAssembly = typeof ( HashicorpVaultCAConnector ) . Assembly ;
60+
61+ // Get the AssemblyName object
62+ AssemblyName assemblyName = targetAssembly ? . GetName ( ) ;
63+
64+ // Get the Version object
65+ Version version = assemblyName ? . Version ;
66+
67+ logger . LogTrace ( $ "-- { assemblyName ? . Name ?? "unknown" } v{ version } --") ;
68+
69+ logger . LogTrace ( $ "serialized config: { rawConfig } ") ;
5770 }
5871
5972 /// <summary>
@@ -239,7 +252,7 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
239252 }
240253 catch ( Exception ex )
241254 {
242- logger . LogError ( $ "failed to retreive serial numbers: { LogHandler . FlattenException ( ex ) } ") ;
255+ logger . LogError ( $ "failed to retrieve serial numbers: { LogHandler . FlattenException ( ex ) } ") ;
243256 throw ;
244257 }
245258
@@ -250,25 +263,25 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
250263 CertResponse certFromVault = null ;
251264 var dbStatus = - 1 ;
252265
253- // first, retreive the details from Vault
266+ // first, retrieve the details from Vault
254267 try
255268 {
256269 logger . LogTrace ( $ "Calling GetCertificate on our client, passing serial number: { certSerial } ") ;
257270 certFromVault = await _client . GetCertificate ( certSerial ) ;
258271 }
259272 catch ( Exception ex )
260273 {
261- logger . LogError ( $ "Failed to retreive details for certificate with serial number { certSerial } from Vault. Errors: { LogHandler . FlattenException ( ex ) } ") ;
274+ logger . LogError ( $ "Failed to retrieve details for certificate with serial number { certSerial } from Vault. Errors: { LogHandler . FlattenException ( ex ) } ") ;
262275 throw ;
263276 }
264277 logger . LogTrace ( $ "converting { certSerial } to database trackingId") ;
265278
266- var trackingId = certSerial . Replace ( ":" , "-" ) ; // we store with '-'; hashi stores with ':'
279+ var trackingId = certSerial . Replace ( ":" , "-" ) ; // we store with '-'; hashi stores with ':'
267280
268281 // then, check for an existing local entry
269282 try
270283 {
271- logger . LogTrace ( $ "attempting to retreive status of cert with tracking id { trackingId } from the database") ;
284+ logger . LogTrace ( $ "attempting to retrieve status of cert with tracking id { trackingId } from the database") ;
272285 dbStatus = await _certificateDataReader . GetStatusByRequestID ( trackingId ) ;
273286 }
274287 catch
@@ -280,29 +293,29 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
280293 {
281294 logger . LogTrace ( $ "adding cert with serial { trackingId } to the database. fullsync is { fullSync } , and the certificate { ( dbStatus == - 1 ? "does not yet exist" : "already exists" ) } in the database.") ;
282295
283- logger . LogTrace ( "attempting to retreive the role name (productId) from the certificate metadata, if available" ) ;
296+ logger . LogTrace ( "attempting to retrieve the role name (productId) from the certificate metadata, if available" ) ;
284297
285298 var metaData = new MetadataResponse ( ) ;
286-
299+
287300 try
288301 {
289302 metaData = await _client . GetCertMetadata ( certSerial ) ;
290303 }
291- catch ( Exception )
304+ catch ( Exception )
292305 {
293- logger . LogTrace ( "an error occurred when attempting to retreive the metadata, continuing.." ) ;
306+ logger . LogTrace ( "an error occurred when attempting to retrieve the metadata, continuing.." ) ;
294307 }
295308
296309 var newCert = new AnyCAPluginCertificate
297310 {
298311 CARequestID = trackingId ,
299312 Certificate = certFromVault . Certificate ,
300313 Status = certFromVault . RevocationTime != null ? ( int ) EndEntityStatus . REVOKED : ( int ) EndEntityStatus . GENERATED ,
301- RevocationDate = certFromVault . RevocationTime ,
314+ RevocationDate = certFromVault . RevocationTime ,
302315 } ;
303316
304317 // if we were able to get the role name from metadata, we include it
305- if ( ! string . IsNullOrEmpty ( metaData ? . Role ) )
318+ if ( ! string . IsNullOrEmpty ( metaData ? . Role ) )
306319 {
307320 newCert . ProductID = metaData . Role ;
308321 }
@@ -346,7 +359,7 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
346359 /// </summary>
347360 /// <param name="connectionInfo">The information used to connect to the CA.</param>
348361 public async Task ValidateCAConnectionInfo ( Dictionary < string , object > connectionInfo )
349- {
362+ {
350363 logger . MethodEntry ( ) ;
351364 logger . LogTrace ( message : $ "Validating CA connection info: { JsonSerializer . Serialize ( connectionInfo ) } ") ;
352365
@@ -372,7 +385,7 @@ public async Task ValidateCAConnectionInfo(Dictionary<string, object> connection
372385
373386 // make sure an authentication mechanism is defined (either certificate or token)
374387 var token = connectionInfo [ Constants . CAConfig . TOKEN ] as string ;
375-
388+
376389 //var cert = connectionInfo[Constants.CAConfig.CLIENTCERT] as string;
377390
378391 var cert = string . Empty ; // temporary until client cert auth into vault is implemented
@@ -422,12 +435,12 @@ public async Task ValidateCAConnectionInfo(Dictionary<string, object> connection
422435
423436 _client = new HashicorpVaultClient ( config ) ;
424437
425- // attempt an authenticated request to retreive role names
438+ // attempt an authenticated request to retrieve role names
426439 try
427440 {
428441 logger . LogTrace ( "making an authenticated request to the Vault server to verify credentials (listing role names).." ) ;
429442 var roleNames = await _client . GetRoleNamesAsync ( ) ;
430- logger . LogTrace ( $ "successfule request: received a response containing { roleNames . Count } role names") ;
443+ logger . LogTrace ( $ "successful request: received a response containing { roleNames ? . Count } role names") ;
431444 }
432445 catch ( Exception ex )
433446 {
@@ -465,7 +478,7 @@ public Task ValidateProductInfo(EnrollmentProductInfo productInfo, Dictionary<st
465478 logger . LogError ( LogHandler . FlattenException ( ex ) ) ;
466479 throw ;
467480 }
468-
481+
469482 // if any errors, throw
470483 if ( errors . Any ( ) )
471484 {
@@ -570,7 +583,10 @@ public List<string> GetProductIds()
570583 try
571584 {
572585 logger . LogTrace ( "requesting role names from vault.." ) ;
573- var roleNames = _client . GetRoleNamesAsync ( ) . Result ;
586+ var roleNames = _client . GetRoleNamesAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
587+ if ( roleNames == null ) {
588+ throw new Exception ( "no role names returned, or deserialization failed." ) ;
589+ }
574590 logger . LogTrace ( $ "got { roleNames . Count } role names from vault:") ;
575591 foreach ( var name in roleNames )
576592 {
0 commit comments