Skip to content
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

Added better error handling #13

Merged
merged 23 commits into from
May 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions ldid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,10 @@ class Buffer {
Buffer(PKCS7 *pkcs) :
Buffer()
{
_assert(i2d_PKCS7_bio(bio_, pkcs) != 0);
if(i2d_PKCS7_bio(bio_, pkcs) == 0){
printf("An error occured while getting the PKCS12 file: \n %s\n", ERR_error_string(ERR_get_error(), NULL));
exit(1);
}
}

~Buffer() {
Expand Down Expand Up @@ -1801,20 +1804,18 @@ class Stuff {
}

if(PKCS12_parse(value_, password.c_str(), &key_, &cert_, &ca_) <= 0){
printf("An error occured while parsing: %s\n", ERR_error_string(ERR_get_error(), NULL));
printf("An error occured while parsing: \n %s\n", ERR_error_string(ERR_get_error(), NULL));
exit(1);
}
if(key_ == NULL || cert_ == NULL){
printf("An error occured while parsing: %s\n Your p12 cert might not be valid", ERR_error_string(ERR_get_error(), NULL));
printf("An error occured while parsing: \n %s\n Your p12 cert might not be valid", ERR_error_string(ERR_get_error(), NULL));
exit(1);
}
_assert(key_ != NULL);
_assert(cert_ != NULL);

if (ca_ == NULL)
ca_ = sk_X509_new_null();
if(ca_ == NULL){
printf("An error occured while parsing: %s\n", ERR_error_string(ERR_get_error(), NULL));
printf("An error occured while parsing: \n %s\n", ERR_error_string(ERR_get_error(), NULL));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't re-add those newlines, I had removed them on purpose.

exit(1);
}
}
Expand Down Expand Up @@ -1855,7 +1856,10 @@ class Signature {
public:
Signature(const Stuff &stuff, const Buffer &data, const std::string &xml) {
value_ = PKCS7_new();
_assert(value_ != NULL);
if(value_ == NULL){
printf("An error occured while getting creating PKCS7 file: %s\n", ERR_error_string(ERR_get_error(), NULL));
exit(1);
}

_assert(PKCS7_set_type(value_, NID_pkcs7_signed));
_assert(PKCS7_content_new(value_, NID_pkcs7_data));
Expand Down Expand Up @@ -2069,7 +2073,10 @@ Hash Sign(const void *idata, size_t isize, std::streambuf &output, const std::st
if (!key.empty()) {
Stuff stuff(key);
auto name(X509_get_subject_name(stuff));
_assert(name != NULL);
if(name == NULL){
printf("Your certificate might not be valid: \n %s\n", ERR_error_string(ERR_get_error(), NULL));
exit(1);
}
get(team, name, NID_organizationalUnitName);
get(common, name, NID_commonName);
}
Expand Down