-
Notifications
You must be signed in to change notification settings - Fork 6
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
don't raise error in get if certificate is empty #84
Changes from all commits
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 |
---|---|---|
|
@@ -78,6 +78,17 @@ def get(certificate_thumbprint, store_name: @store_name, store_location: @store_ | |
cert_get(certificate_thumbprint, store_name: store_name, store_location: store_location) | ||
end | ||
|
||
# Return `OpenSSL::X509` certificate object if present otherwise raise a "Certificate not found!" error | ||
# @param request [thumbprint<string>] of certificate | ||
# @return [Object] of certificates in OpenSSL::X509 format | ||
def get!(certificate_thumbprint, store_name: @store_name, store_location: @store_location) | ||
cert_pem = cert_get(certificate_thumbprint, store_name: store_name, store_location: store_location) | ||
|
||
raise ArgumentError, "Unable to retrieve the certificate" if cert_pem.empty? | ||
|
||
cert_pem | ||
end | ||
|
||
# Returns all the certificates in a store | ||
# @param [nil] | ||
# @return [Array] array of certificates list | ||
|
@@ -103,7 +114,13 @@ def search(search_token) | |
# @param request[thumbprint<string>] of certificate | ||
# @return [true, false] only true or false | ||
def valid?(certificate_thumbprint, store_location: "", store_name: "") | ||
cert_validate(certificate_thumbprint, store_location: store_location, store_name: store_name) | ||
cert_validate(certificate_thumbprint, store_location: store_location, store_name: store_name).yield_self do |x| | ||
if x.is_a?(TrueClass) || x.is_a?(FalseClass) | ||
x | ||
else | ||
false | ||
end | ||
end | ||
end | ||
Comment on lines
116
to
124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the implementations of def valid?
# validation logic
# return boolean
end
def cert_validate
# use valid? to check
# raise error or return formatted error string (based on use case)
end |
||
|
||
# To close and destroy pointer of open certificate store handler | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,13 +92,8 @@ def cert_get(certificate_thumbprint, store_name:, store_location:) | |
thumbprint = update_thumbprint(certificate_thumbprint) | ||
cert_pem = get_cert_pem(thumbprint, store_name: store_name, store_location: store_location) | ||
cert_pem = format_pem(cert_pem) | ||
if cert_pem.empty? | ||
raise ArgumentError, "Unable to retrieve the certificate" | ||
end | ||
|
||
unless cert_pem.empty? | ||
build_openssl_obj(cert_pem) | ||
end | ||
cert_pem.empty? ? cert_pem : build_openssl_obj(cert_pem) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should return nil or cert_pem/object. This would also clean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get on Teams and talk about this? I feel like we have competing agendas and I want to make sure I am doing this correctly. |
||
end | ||
|
||
# Listing certificate of open certstore and return list in json | ||
|
@@ -147,6 +142,8 @@ def cert_validate(certificate_thumbprint, store_location:, store_name:) | |
thumbprint = update_thumbprint(certificate_thumbprint) | ||
cert_pem = get_cert_pem(thumbprint, store_name: store_name, store_location: store_location) | ||
cert_pem = format_pem(cert_pem) | ||
return "Certificate not found" if cert_pem.empty? | ||
|
||
verify_certificate(cert_pem) | ||
end | ||
|
||
|
@@ -223,8 +220,6 @@ def update_thumbprint(certificate_thumbprint) | |
|
||
# Verify OpenSSL::X509::Certificate object | ||
def verify_certificate(cert_pem) | ||
return "Certificate not found" if cert_pem.empty? | ||
|
||
valid_duration?(build_openssl_obj(cert_pem)) | ||
end | ||
|
||
|
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.
ArgumentError
would be fitting if we were validating arguments here but since we are calling an external entity/store, we should either relay/wrap that entity's error or define a custom exception.