-
Notifications
You must be signed in to change notification settings - Fork 0
Bug Fix: Initializing _certDataReader #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-1.0
Are you sure you want to change the base?
Changes from all commits
f38db6c
d730756
c9bc2bb
cf00704
c6d7450
7beec7d
b452a66
b650d91
d605bb3
1f0ae06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,9 +131,15 @@ public async Task<CertResponse> GetCertificate(string certSerial) | |
|
|
||
| try | ||
| { | ||
| var response = await _vaultHttp.GetAsync<CertResponse>($"cert/{certSerial}"); | ||
| var response = await _vaultHttp.GetAsync<WrappedResponse<CertResponse>>($"cert/{certSerial}"); | ||
|
|
||
| logger.LogTrace($"successfully received a response for certificate with serial number: {certSerial}"); | ||
| return response; | ||
| logger.LogTrace($"--response data--"); | ||
| logger.LogTrace($"cert string: {response.Data?.Certificate}"); | ||
| logger.LogTrace($"revocation time: {response.Data?.RevocationTime}"); | ||
|
|
||
|
|
||
| return response.Data; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
|
|
@@ -152,9 +158,9 @@ public async Task<RevokeResponse> RevokeCertificate(string serial) | |
| logger.LogTrace($"making request to revoke cert with serial: {serial}"); | ||
| try | ||
| { | ||
| var response = await _vaultHttp.PostAsync<RevokeResponse>("revoke", new RevokeRequest(serial)); | ||
| logger.LogTrace($"successfully revoked cert with serial {serial}, revocation time: {response.RevocationTime}"); | ||
| return response; | ||
| var response = await _vaultHttp.PostAsync<WrappedResponse<RevokeResponse>>("revoke", new RevokeRequest(serial)); | ||
| logger.LogTrace($"successfully revoked cert with serial {serial}, revocation time: {response.Data.RevocationTime}"); | ||
| return response.Data; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
|
|
@@ -189,7 +195,7 @@ public async Task<bool> PingServer() | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Retreives all serial numbers for issued certificates | ||
| /// Retrieves all serial numbers for issued certificates | ||
| /// </summary> | ||
| /// <returns>a list of the certificate serial number strings</returns> | ||
| public async Task<List<string>> GetAllCertSerialNumbers() | ||
|
|
@@ -199,7 +205,7 @@ public async Task<List<string>> GetAllCertSerialNumbers() | |
| try | ||
| { | ||
| var res = await _vaultHttp.GetAsync<WrappedResponse<KeyedList>>("certs/?list=true"); | ||
| return res.Data.Entries; | ||
| return res.Data?.Entries; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
|
|
@@ -215,8 +221,8 @@ private async Task<List<string>> GetRevokedSerialNumbers() | |
| var keys = new List<string>(); | ||
| try | ||
| { | ||
| var res = await _vaultHttp.GetAsync<KeyedList>("certs/revoked"); | ||
| keys = res.Entries; | ||
| var res = await _vaultHttp.GetAsync<WrappedResponse<KeyedList>>("certs/revoked"); | ||
| keys = res.Data?.Entries; | ||
|
||
| } | ||
| catch (Exception ex) | ||
| { | ||
|
|
@@ -247,7 +253,7 @@ public async Task<List<string>> GetRoleNamesAsync() | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Retreives the metadata for the certificate | ||
| /// Retrieves the metadata for the certificate | ||
| /// </summary> | ||
| /// <param name="certSerial"></param> | ||
| /// <returns></returns> | ||
|
|
@@ -275,7 +281,7 @@ public async Task<MetadataResponse> GetCertMetadata(string certSerial) | |
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError($"an error occurred when attempting to retreive the certificate metadata: {ex.Message}"); | ||
| logger.LogError($"an error occurred when attempting to retrieve the certificate metadata: {ex.Message}"); | ||
| throw; | ||
| } | ||
| finally { logger.MethodExit(); } | ||
|
|
@@ -317,5 +323,7 @@ private static string ConvertSerialToTrackingId(string serialNumber) | |
|
|
||
| return serialNumber.Replace(":", "-"); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |||||
| using System.Collections.Generic; | ||||||
| using System.Text.Json; | ||||||
| using System.Text.Json.Serialization; | ||||||
| using System.Threading; | ||||||
| using System.Threading.Tasks; | ||||||
|
|
||||||
| namespace Keyfactor.Extensions.CAPlugin.HashicorpVault.Client | ||||||
|
|
@@ -36,12 +37,12 @@ public VaultHttp(string host, string mountPoint, string authToken, string nameSp | |||||
| _serializerOptions = new() | ||||||
| { | ||||||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault, | ||||||
| RespectNullableAnnotations = true, | ||||||
| PropertyNameCaseInsensitive = true, | ||||||
| PreferredObjectCreationHandling = JsonObjectCreationHandling.Replace, | ||||||
| RespectNullableAnnotations = true, | ||||||
| PreferredObjectCreationHandling = JsonObjectCreationHandling.Replace | ||||||
| }; | ||||||
|
|
||||||
| var restClientOptions = new RestClientOptions($"{host.TrimEnd('/')}/v1") { ThrowOnAnyError = true }; | ||||||
| var restClientOptions = new RestClientOptions($"{host.TrimEnd('/')}/v1") { ThrowOnAnyError = true }; | ||||||
| _restClient = new RestClient(restClientOptions, configureSerialization: s => s.UseSystemTextJson(_serializerOptions)); | ||||||
|
|
||||||
| _mountPoint = mountPoint.TrimStart('/').TrimEnd('/'); // remove leading and trailing slashes | ||||||
|
|
@@ -69,19 +70,32 @@ public VaultHttp(string host, string mountPoint, string authToken, string nameSp | |||||
| public async Task<T> GetAsync<T>(string path, Dictionary<string, string> parameters = null) | ||||||
| { | ||||||
| logger.MethodEntry(); | ||||||
| logger.LogTrace($"preparing to send GET request to {path} with parameters {JsonSerializer.Serialize(parameters)}"); | ||||||
| logger.LogTrace($"will attempt to deserialize the response into a {typeof(T)}"); | ||||||
| logger.LogTrace($"preparing to send GET request to {_mountPoint}/{path} with parameters {JsonSerializer.Serialize(parameters)}"); | ||||||
|
|
||||||
| try | ||||||
| { | ||||||
| var request = new RestRequest($"{_mountPoint}/{path}", Method.Get); | ||||||
| if (parameters != null) { request.AddJsonBody(parameters); } | ||||||
| if (parameters != null && parameters.Keys.Count > 0) { request.AddJsonBody(parameters); } | ||||||
| var response = await _restClient.ExecuteGetAsync(request); | ||||||
|
|
||||||
| logger.LogTrace($"raw response: {JsonSerializer.Serialize(response)}"); | ||||||
|
|
||||||
| logger.LogTrace($"response content: {response.Content}"); | ||||||
|
|
||||||
| logger.LogTrace($"response status: {response.StatusCode}"); | ||||||
|
|
||||||
| var response = await _restClient.ExecuteGetAsync<T>(request); | ||||||
| logger.LogTrace($"raw response: {response.Content}"); | ||||||
| logger.LogTrace($"response error msg: {response.ErrorMessage}"); | ||||||
|
|
||||||
| response.ThrowIfError(); | ||||||
| if (string.IsNullOrEmpty(response.Content)) throw new Exception(response.ErrorMessage ?? "no content returned from Vault"); | ||||||
|
|
||||||
| return response.Data; | ||||||
| logger.LogTrace($"deserializing the response into a {typeof(T)}"); | ||||||
|
|
||||||
| var deserialized = JsonSerializer.Deserialize<T>(response.Content, _serializerOptions); | ||||||
|
|
||||||
| logger.LogTrace($"successfully deserialized the response"); | ||||||
|
|
||||||
| return deserialized; | ||||||
| } | ||||||
| catch (Exception ex) | ||||||
| { | ||||||
|
|
@@ -108,8 +122,8 @@ public async Task<T> PostAsync<T>(string path, dynamic parameters = default) | |||||
| var request = new RestRequest(resourcePath, Method.Post); | ||||||
| if (parameters != null) | ||||||
| { | ||||||
| string serializedParams = JsonSerializer.Serialize(parameters, _serializerOptions); | ||||||
| logger.LogTrace($"serialized parameters (from {parameters.GetType()?.Name}): {serializedParams}"); | ||||||
| string serializedParams = JsonSerializer.Serialize(parameters); | ||||||
| logger.LogTrace($"deserialized parameters (from {parameters.GetType()?.Name}): {serializedParams}"); | ||||||
|
||||||
| logger.LogTrace($"deserialized parameters (from {parameters.GetType()?.Name}): {serializedParams}"); | |
| logger.LogTrace($"serialized parameters (from {parameters.GetType()?.Name}): {serializedParams}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference issue: The code accesses res.Data?.Entries without null-checking res itself. If the GetAsync call returns null, this will throw a NullReferenceException. Consider adding a null check for the response object before accessing its Data property.