Mercurial > trustbridge
changeset 586:ecfd77751daf
Disambiguate enumerator values and add portable wrapper.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 27 May 2014 16:30:58 +0000 |
parents | 21f8d32f2d2a |
children | 02a89710a7cd |
files | common/binverify.c common/binverify.h |
diffstat | 2 files changed, 28 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/common/binverify.c Tue May 27 10:46:02 2014 +0000 +++ b/common/binverify.c Tue May 27 16:30:58 2014 +0000 @@ -11,6 +11,16 @@ #include "strhelp.h" #include "logging.h" +bin_verify_result +verify_binary(const char *filename, size_t name_len) { +#ifdef WIN32 + return verify_binary_win(filename, name_len); +#else + /* TODO */ + return VerifyValid; +#endif +} + #ifdef WIN32 #include <windows.h> @@ -20,7 +30,7 @@ bin_verify_result verify_binary_win(const char *filename, size_t name_len) { - bin_verify_result retval = UnknownError; + bin_verify_result retval = VerifyUnknownError; WCHAR *filenameW = NULL; BOOL result = FALSE; DWORD dwEncoding = 0, @@ -35,7 +45,7 @@ if (!filename || name_len > MAX_PATH || strlen(filename) != name_len) { ERRORPRINTF ("Invalid parameters\n"); - return UnknownError; + return VerifyUnknownError; } filenameW = utf8_to_wchar(filename, strnlen(filename, MAX_PATH)); @@ -55,7 +65,7 @@ if (!result || !hMsg) { PRINTLASTERROR ("Failed to query crypto object"); - retval = ReadFailed; + retval = VerifyReadFailed; goto done; } @@ -71,7 +81,7 @@ else { ERRORPRINTF ("Failed to get signer cert size."); - retval = UnknownError; + retval = VerifyUnknownError; goto done; } @@ -82,7 +92,7 @@ &dwSignerInfoSize))) { ERRORPRINTF ("Failed to get signer cert."); - retval = UnknownError; + retval = VerifyUnknownError; goto done; } @@ -94,7 +104,7 @@ if (!pSignerCertContext) { ERRORPRINTF ("Failed to find signer cert in store."); - retval = UnknownError; + retval = VerifyUnknownError; goto done; } @@ -106,10 +116,10 @@ { DEBUGPRINTF ("Verify signature succeeded. \n"); /* TODO pinning*/ - retval = Valid; + retval = VerifyValid; } else { ERRORPRINTF ("The signature was not verified. \n"); - retval = InvalidSignature; + retval = VerifyInvalidSignature; goto done; }
--- a/common/binverify.h Tue May 27 10:46:02 2014 +0000 +++ b/common/binverify.h Tue May 27 16:30:58 2014 +0000 @@ -23,13 +23,12 @@ * @brief Result of a verification */ typedef enum { - Valid = 100, /*! Could be read and signature matched */ - UnknownError = 1, /*! The expected unexpected */ - InvalidSignature = 4, /*! Signature was invalid */ - ReadFailed = 6, /*! File exists but could not read the file */ + VerifyValid = 100, /*! Could be read and signature matched */ + VerifyUnknownError = 1, /*! The expected unexpected */ + VerifyInvalidSignature = 4, /*! Signature was invalid */ + VerifyReadFailed = 6, /*! File exists but could not read the file */ } bin_verify_result; -#ifdef WIN32 /** * @brief verify a binary * @@ -48,6 +47,12 @@ * * @returns the verification result. */ +bin_verify_result verify_binary(const char *filename, size_t name_len); + +#ifdef WIN32 +/** + * @brief windows implementation of verify_binary + */ bin_verify_result verify_binary_win(const char *filename, size_t name_len); #endif /* WIN32 */