Add sha256 ckecksums to okpg
PATCH 1/1 Add sha256 ckecksums to okpg
Here is a patch which adds sha256 checksum checking to Opkg. More Opkg patches will follow shortly (x509 and smime signature support, libcurl client/server authentication)
I hope these patch will be useful and finds their ways into okpg
Camille Moncelier
http://devlife.org/
pkg_parse.c +4 -0
@@ -266,6 +266,10 @@case 'S' :if (isGenericFieldType ("Section:" , *lines)) pkg->section =parseGenericFieldType ("Section" , *lines); +#ifdef HAVE_SHA256 + else if(isGenericFieldType("SHA256sum:", *lines)) + pkg->sha256sum = parseGenericFieldType("SHA256sum", *lines); +#endif else if(isGenericFieldType("Size:", *lines)) pkg->size = parseGenericFieldType("Size", *lines); else if(isGenericFieldType("Source:", *lines))
opkg.c +2 -0
@@ -531,6 +531,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
@@ -670,6 +671,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
opkg.h +2 -1
@@ -43,7 +43,8 @@OPKG_PACKAGE_NOT_FOUND ,OPKG_PACKAGE_NOT_INSTALLED ,OPKG_GPG_ERROR , - OPKG_MD5_ERROR +OPKG_MD5_ERROR , + OPKG_SHA256_ERROR };struct _opkg_package_t
file_util.c +55 -0
64 lines not on this page · raw message
opkg_error.h +1 -0
@@ -41,6 +41,7 @@OPKG_INSTALL_ERR_SIGNATURE ,OPKG_INSTALL_ERR_MD5 ,OPKG_INSTALL_ERR_INTERNAL , + OPKG_INSTALL_ERR_SHA256, };typedef enum opkg_error opkg_error_t ;
file_util.h +1 -0
@@ -25,5 +25,6 @@int file_copy (const char *src,const char *dest);int file_mkdir_hier (const char *path,long mode);char *file_md5sum_alloc (const char *file_name); +char *file_sha256sum_alloc (const char *file_name);#endif
pkg.c +25 -1
@@ -131,6 +131,9 @@ pkg->local_filename =NULL ; pkg->tmp_unpack_dir =NULL ; pkg->md5sum =NULL ; +#if definedHAVE_SHA256 + pkg->sha256sum =NULL ; +#endif pkg->size =NULL ; pkg->installed_size =NULL ; pkg->priority =NULL ;
@@ -255,6 +258,10 @@ pkg->tmp_unpack_dir =NULL ;free (pkg->md5sum); pkg->md5sum =NULL ; +#if definedHAVE_SHA256 +free (pkg->sha256sum); + pkg->sha256sum =NULL ; +#endif free (pkg->size); pkg->size =NULL ;free (pkg->installed_size);
@@ -405,6 +412,10 @@ oldpkg->tmp_unpack_dir =str_dup_safe (newpkg->tmp_unpack_dir);if (!oldpkg->md5sum) oldpkg->md5sum =str_dup_safe (newpkg->md5sum); +#if definedHAVE_SHA256 +if (!oldpkg->sha256sum) + oldpkg->sha256sum =str_dup_safe (newpkg->sha256sum); +#endif if (!oldpkg->size) oldpkg->size =str_dup_safe (newpkg->size);if (!oldpkg->installed_size)
@@ -955,7 +966,7 @@break ;case 's' :case 'S' : { -/* Section | Size | Source | Status | Suggests */ +/* Section | SHA256sum | Size | Source | Status | Suggests */ if (strcasecmp (field,"Section" ) ==0 ) {/* Section */ if (pkg->section) {
@@ -967,6 +978,19 @@ temp[0 ]='\0' ;snprintf (temp, (strlen (pkg->section)+11 ),"Section: %s\n" , pkg->section); } +#if definedHAVE_SHA256 + } else if (strcasecmp(field, "SHA256sum") == 0) { +/* SHA256sum */ +if (pkg->sha256sum) { + temp = (char *)realloc (temp,strlen (pkg->sha256sum)+13 ); +if ( temp ==NULL ){ +fprintf (stderr,"%s: out of memory\n" , __FUNCTION__); +return NULL ; + } + temp[0 ]='\0' ; +snprintf (temp, (strlen (pkg->sha256sum)+13 ),"SHA256sum: %s\n" , pkg->sha256sum); + } +#endif }else if (strcasecmp (field,"Size" ) ==0 ) {/* Size */ if (pkg->size) {
pkg.h +3 -0
@@ -161,6 +161,9 @@char *url;char *tmp_unpack_dir;char *md5sum; +#if definedHAVE_SHA256 +char *sha256sum; +#endif char *size;char *installed_size;char *priority;
opkg_install.c +19 -0
@@ -766,6 +766,9 @@abstract_pkg_t *ab_pkg =NULL ;int old_state_flag;char * file_md5; +#ifdef HAVE_SHA256 +char * file_sha256; +#endif char *pkgid;if ( from_upgrade )
@@ -874,6 +877,22 @@free (file_md5); } +#ifdef HAVE_SHA256 +/* Check for sha256 value */ +if (pkg->sha256sum) + { + file_sha256 =file_sha256sum_alloc (pkg->local_filename); +if (strcmp (file_sha256, pkg->sha256sum)) + { +opkg_message (conf,OPKG_ERROR , +"Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n" , + pkg->name); +free (file_sha256); +return OPKG_INSTALL_ERR_SHA256 ; + } + } +#endif +if (pkg->tmp_unpack_dir ==NULL ) {unpack_pkg_control_files (conf, pkg); }
Makefile.am +4 -0
@@ -30,6 +30,10 @@ sprintf_alloc.c sprintf_alloc.h str_util.c str_util.h \ xregex.c xregex.h xsystem.c xsystem.h +if HAVE_SHA256 +opkg_util_sources += sha256.c sha256.h +endif + lib_LTLIBRARIES = libopkg.la libopkg_la_SOURCES = \ $(opkg_libcore_sources) \
configure.ac +11 -0
@@ -37,7 +37,18 @@ AC_DEFINE(HAVE_CURL, 1, [Define if you want CURL support]) fi +# check for sha256 +AC_ARG_ENABLE(sha256, + AC_HELP_STRING([--enable-sha256], [Enable sha256sum check + [[default=yes]] ]), + [want_sha256="$enableval"], [want_sha256="yes"]) +if test "x$want_sha256" = "xyes"; then + AC_DEFINE(HAVE_SHA256, 1, [Define if you want sha256 support]) +fi +AM_CONDITIONAL(HAVE_SHA256, test "x$want_sha256" = "xyes") + + dnl ********** dnl GPGME dnl **********
pkg_parse.c +4 -0
@@ -266,6 +266,10 @@case 'S' :if (isGenericFieldType ("Section:" , *lines)) pkg->section =parseGenericFieldType ("Section" , *lines); +#ifdef HAVE_SHA256 + else if(isGenericFieldType("SHA256sum:", *lines)) + pkg->sha256sum = parseGenericFieldType("SHA256sum", *lines); +#endif else if(isGenericFieldType("Size:", *lines)) pkg->size = parseGenericFieldType("Size", *lines); else if(isGenericFieldType("Source:", *lines))
opkg.c +2 -0
@@ -531,6 +531,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
@@ -670,6 +671,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
opkg.h +2 -1
@@ -43,7 +43,8 @@OPKG_PACKAGE_NOT_FOUND ,OPKG_PACKAGE_NOT_INSTALLED ,OPKG_GPG_ERROR , - OPKG_MD5_ERROR +OPKG_MD5_ERROR , + OPKG_SHA256_ERROR };struct _opkg_package_t
sha256.c +554 -0
554 lines not on this page · raw message
file_util.c +55 -0
64 lines not on this page · raw message
sha256.h +91 -0
91 lines not on this page · raw message
opkg_error.h +1 -0
@@ -41,6 +41,7 @@OPKG_INSTALL_ERR_SIGNATURE ,OPKG_INSTALL_ERR_MD5 ,OPKG_INSTALL_ERR_INTERNAL , + OPKG_INSTALL_ERR_SHA256, };typedef enum opkg_error opkg_error_t ;
file_util.h +1 -0
@@ -25,5 +25,6 @@int file_copy (const char *src,const char *dest);int file_mkdir_hier (const char *path,long mode);char *file_md5sum_alloc (const char *file_name); +char *file_sha256sum_alloc (const char *file_name);#endif
pkg.c +25 -1
@@ -131,6 +131,9 @@ pkg->local_filename =NULL ; pkg->tmp_unpack_dir =NULL ; pkg->md5sum =NULL ; +#if definedHAVE_SHA256 + pkg->sha256sum =NULL ; +#endif pkg->size =NULL ; pkg->installed_size =NULL ; pkg->priority =NULL ;
@@ -255,6 +258,10 @@ pkg->tmp_unpack_dir =NULL ;free (pkg->md5sum); pkg->md5sum =NULL ; +#if definedHAVE_SHA256 +free (pkg->sha256sum); + pkg->sha256sum =NULL ; +#endif free (pkg->size); pkg->size =NULL ;free (pkg->installed_size);
@@ -405,6 +412,10 @@ oldpkg->tmp_unpack_dir =str_dup_safe (newpkg->tmp_unpack_dir);if (!oldpkg->md5sum) oldpkg->md5sum =str_dup_safe (newpkg->md5sum); +#if definedHAVE_SHA256 +if (!oldpkg->sha256sum) + oldpkg->sha256sum =str_dup_safe (newpkg->sha256sum); +#endif if (!oldpkg->size) oldpkg->size =str_dup_safe (newpkg->size);if (!oldpkg->installed_size)
@@ -955,7 +966,7 @@break ;case 's' :case 'S' : { -/* Section | Size | Source | Status | Suggests */ +/* Section | SHA256sum | Size | Source | Status | Suggests */ if (strcasecmp (field,"Section" ) ==0 ) {/* Section */ if (pkg->section) {
@@ -967,6 +978,19 @@ temp[0 ]='\0' ;snprintf (temp, (strlen (pkg->section)+11 ),"Section: %s\n" , pkg->section); } +#if definedHAVE_SHA256 + } else if (strcasecmp(field, "SHA256sum") == 0) { +/* SHA256sum */ +if (pkg->sha256sum) { + temp = (char *)realloc (temp,strlen (pkg->sha256sum)+13 ); +if ( temp ==NULL ){ +fprintf (stderr,"%s: out of memory\n" , __FUNCTION__); +return NULL ; + } + temp[0 ]='\0' ; +snprintf (temp, (strlen (pkg->sha256sum)+13 ),"SHA256sum: %s\n" , pkg->sha256sum); + } +#endif }else if (strcasecmp (field,"Size" ) ==0 ) {/* Size */ if (pkg->size) {
pkg.h +3 -0
@@ -161,6 +161,9 @@char *url;char *tmp_unpack_dir;char *md5sum; +#if definedHAVE_SHA256 +char *sha256sum; +#endif char *size;char *installed_size;char *priority;
opkg_install.c +19 -0
@@ -766,6 +766,9 @@abstract_pkg_t *ab_pkg =NULL ;int old_state_flag;char * file_md5; +#ifdef HAVE_SHA256 +char * file_sha256; +#endif char *pkgid;if ( from_upgrade )
@@ -874,6 +877,22 @@free (file_md5); } +#ifdef HAVE_SHA256 +/* Check for sha256 value */ +if (pkg->sha256sum) + { + file_sha256 =file_sha256sum_alloc (pkg->local_filename); +if (strcmp (file_sha256, pkg->sha256sum)) + { +opkg_message (conf,OPKG_ERROR , +"Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n" , + pkg->name); +free (file_sha256); +return OPKG_INSTALL_ERR_SHA256 ; + } + } +#endif +if (pkg->tmp_unpack_dir ==NULL ) {unpack_pkg_control_files (conf, pkg); }
Makefile.am +4 -0
@@ -30,6 +30,10 @@ sprintf_alloc.c sprintf_alloc.h str_util.c str_util.h \ xregex.c xregex.h xsystem.c xsystem.h +if HAVE_SHA256 +opkg_util_sources += sha256.c sha256.h +endif + lib_LTLIBRARIES = libopkg.la libopkg_la_SOURCES = \ $(opkg_libcore_sources) \
configure.ac +11 -0
@@ -37,7 +37,18 @@ AC_DEFINE(HAVE_CURL, 1, [Define if you want CURL support]) fi +# check for sha256 +AC_ARG_ENABLE(sha256, + AC_HELP_STRING([--enable-sha256], [Enable sha256sum check + [[default=yes]] ]), + [want_sha256="$enableval"], [want_sha256="yes"]) +if test "x$want_sha256" = "xyes"; then + AC_DEFINE(HAVE_SHA256, 1, [Define if you want sha256 support]) +fi +AM_CONDITIONAL(HAVE_SHA256, test "x$want_sha256" = "xyes") + + dnl ********** dnl GPGME dnl **********
pkg_parse.c +4 -0
@@ -266,6 +266,10 @@case 'S' :if (isGenericFieldType ("Section:" , *lines)) pkg->section =parseGenericFieldType ("Section" , *lines); +#ifdef HAVE_SHA256 + else if(isGenericFieldType("SHA256sum:", *lines)) + pkg->sha256sum = parseGenericFieldType("SHA256sum", *lines); +#endif else if(isGenericFieldType("Size:", *lines)) pkg->size = parseGenericFieldType("Size", *lines); else if(isGenericFieldType("Source:", *lines))
opkg.c +2 -0
@@ -531,6 +531,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
@@ -670,6 +671,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
opkg.h +2 -1
@@ -43,7 +43,8 @@OPKG_PACKAGE_NOT_FOUND ,OPKG_PACKAGE_NOT_INSTALLED ,OPKG_GPG_ERROR , - OPKG_MD5_ERROR +OPKG_MD5_ERROR , + OPKG_SHA256_ERROR };struct _opkg_package_t
sha256.c +554 -0
554 lines not on this page · raw message
file_util.c +55 -0
64 lines not on this page · raw message
sha256.h +91 -0
91 lines not on this page · raw message
opkg_error.h +1 -0
@@ -41,6 +41,7 @@OPKG_INSTALL_ERR_SIGNATURE ,OPKG_INSTALL_ERR_MD5 ,OPKG_INSTALL_ERR_INTERNAL , + OPKG_INSTALL_ERR_SHA256, };typedef enum opkg_error opkg_error_t ;
file_util.h +1 -0
@@ -25,5 +25,6 @@int file_copy (const char *src,const char *dest);int file_mkdir_hier (const char *path,long mode);char *file_md5sum_alloc (const char *file_name); +char *file_sha256sum_alloc (const char *file_name);#endif
pkg.c +25 -1
@@ -131,6 +131,9 @@ pkg->local_filename =NULL ; pkg->tmp_unpack_dir =NULL ; pkg->md5sum =NULL ; +#if definedHAVE_SHA256 + pkg->sha256sum =NULL ; +#endif pkg->size =NULL ; pkg->installed_size =NULL ; pkg->priority =NULL ;
@@ -255,6 +258,10 @@ pkg->tmp_unpack_dir =NULL ;free (pkg->md5sum); pkg->md5sum =NULL ; +#if definedHAVE_SHA256 +free (pkg->sha256sum); + pkg->sha256sum =NULL ; +#endif free (pkg->size); pkg->size =NULL ;free (pkg->installed_size);
@@ -405,6 +412,10 @@ oldpkg->tmp_unpack_dir =str_dup_safe (newpkg->tmp_unpack_dir);if (!oldpkg->md5sum) oldpkg->md5sum =str_dup_safe (newpkg->md5sum); +#if definedHAVE_SHA256 +if (!oldpkg->sha256sum) + oldpkg->sha256sum =str_dup_safe (newpkg->sha256sum); +#endif if (!oldpkg->size) oldpkg->size =str_dup_safe (newpkg->size);if (!oldpkg->installed_size)
@@ -955,7 +966,7 @@break ;case 's' :case 'S' : { -/* Section | Size | Source | Status | Suggests */ +/* Section | SHA256sum | Size | Source | Status | Suggests */ if (strcasecmp (field,"Section" ) ==0 ) {/* Section */ if (pkg->section) {
@@ -967,6 +978,19 @@ temp[0 ]='\0' ;snprintf (temp, (strlen (pkg->section)+11 ),"Section: %s\n" , pkg->section); } +#if definedHAVE_SHA256 + } else if (strcasecmp(field, "SHA256sum") == 0) { +/* SHA256sum */ +if (pkg->sha256sum) { + temp = (char *)realloc (temp,strlen (pkg->sha256sum)+13 ); +if ( temp ==NULL ){ +fprintf (stderr,"%s: out of memory\n" , __FUNCTION__); +return NULL ; + } + temp[0 ]='\0' ; +snprintf (temp, (strlen (pkg->sha256sum)+13 ),"SHA256sum: %s\n" , pkg->sha256sum); + } +#endif }else if (strcasecmp (field,"Size" ) ==0 ) {/* Size */ if (pkg->size) {
pkg.h +3 -0
@@ -161,6 +161,9 @@char *url;char *tmp_unpack_dir;char *md5sum; +#if definedHAVE_SHA256 +char *sha256sum; +#endif char *size;char *installed_size;char *priority;
opkg_install.c +19 -0
@@ -766,6 +766,9 @@abstract_pkg_t *ab_pkg =NULL ;int old_state_flag;char * file_md5; +#ifdef HAVE_SHA256 +char * file_sha256; +#endif char *pkgid;if ( from_upgrade )
@@ -874,6 +877,22 @@free (file_md5); } +#ifdef HAVE_SHA256 +/* Check for sha256 value */ +if (pkg->sha256sum) + { + file_sha256 =file_sha256sum_alloc (pkg->local_filename); +if (strcmp (file_sha256, pkg->sha256sum)) + { +opkg_message (conf,OPKG_ERROR , +"Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n" , + pkg->name); +free (file_sha256); +return OPKG_INSTALL_ERR_SHA256 ; + } + } +#endif +if (pkg->tmp_unpack_dir ==NULL ) {unpack_pkg_control_files (conf, pkg); }
Makefile.am +4 -0
@@ -30,6 +30,10 @@ sprintf_alloc.c sprintf_alloc.h str_util.c str_util.h \ xregex.c xregex.h xsystem.c xsystem.h +if HAVE_SHA256 +opkg_util_sources += sha256.c sha256.h +endif + lib_LTLIBRARIES = libopkg.la libopkg_la_SOURCES = \ $(opkg_libcore_sources) \
configure.ac +11 -0
@@ -37,7 +37,18 @@ AC_DEFINE(HAVE_CURL, 1, [Define if you want CURL support]) fi +# check for sha256 +AC_ARG_ENABLE(sha256, + AC_HELP_STRING([--enable-sha256], [Enable sha256sum check + [[default=yes]] ]), + [want_sha256="$enableval"], [want_sha256="yes"]) +if test "x$want_sha256" = "xyes"; then + AC_DEFINE(HAVE_SHA256, 1, [Define if you want sha256 support]) +fi +AM_CONDITIONAL(HAVE_SHA256, test "x$want_sha256" = "xyes") + + dnl ********** dnl GPGME dnl **********
This time with a working patch, damn fat fingers...
Camille Moncelier
http://devlife.org/
Quoted 9 lines · Camille Moncelier
Here is a patch which adds sha256 checksum checking to Opkg. More Opkg patches will follow shortly (x509 and smime signature support, libcurl client/server authentication)
I hope these patch will be useful and finds their ways into okpg
Camille Moncelier
http://devlife.org/
pkg_parse.c +4 -0
@@ -266,6 +266,10 @@case 'S' :if (isGenericFieldType ("Section:" , *lines)) pkg->section =parseGenericFieldType ("Section" , *lines); +#ifdef HAVE_SHA256 + else if(isGenericFieldType("SHA256sum:", *lines)) + pkg->sha256sum = parseGenericFieldType("SHA256sum", *lines); +#endif else if(isGenericFieldType("Size:", *lines)) pkg->size = parseGenericFieldType("Size", *lines); else if(isGenericFieldType("Source:", *lines))
opkg.c +2 -0
@@ -531,6 +531,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
@@ -670,6 +671,7 @@case OPKG_INSTALL_ERR_ALREADY_INSTALLED :return OPKG_PACKAGE_ALREADY_INSTALLED ;case OPKG_INSTALL_ERR_SIGNATURE :return OPKG_GPG_ERROR ;case OPKG_INSTALL_ERR_MD5 :return OPKG_MD5_ERROR ; +case OPKG_INSTALL_ERR_SHA256 :return OPKG_SHA256_ERROR ;default :return OPKG_UNKNOWN_ERROR ; } }
opkg.h +2 -1
@@ -43,7 +43,8 @@OPKG_PACKAGE_NOT_FOUND ,OPKG_PACKAGE_NOT_INSTALLED ,OPKG_GPG_ERROR , - OPKG_MD5_ERROR +OPKG_MD5_ERROR , + OPKG_SHA256_ERROR };struct _opkg_package_t
sha256.c +554 -0
554 lines not on this page · raw message
file_util.c +55 -0
64 lines not on this page · raw message
sha256.h +91 -0
91 lines not on this page · raw message
opkg_error.h +1 -0
@@ -41,6 +41,7 @@OPKG_INSTALL_ERR_SIGNATURE ,OPKG_INSTALL_ERR_MD5 ,OPKG_INSTALL_ERR_INTERNAL , + OPKG_INSTALL_ERR_SHA256, };typedef enum opkg_error opkg_error_t ;
file_util.h +1 -0
@@ -25,5 +25,6 @@int file_copy (const char *src,const char *dest);int file_mkdir_hier (const char *path,long mode);char *file_md5sum_alloc (const char *file_name); +char *file_sha256sum_alloc (const char *file_name);#endif
pkg.c +25 -1
@@ -131,6 +131,9 @@ pkg->local_filename =NULL ; pkg->tmp_unpack_dir =NULL ; pkg->md5sum =NULL ; +#if definedHAVE_SHA256 + pkg->sha256sum =NULL ; +#endif pkg->size =NULL ; pkg->installed_size =NULL ; pkg->priority =NULL ;
@@ -255,6 +258,10 @@ pkg->tmp_unpack_dir =NULL ;free (pkg->md5sum); pkg->md5sum =NULL ; +#if definedHAVE_SHA256 +free (pkg->sha256sum); + pkg->sha256sum =NULL ; +#endif free (pkg->size); pkg->size =NULL ;free (pkg->installed_size);
@@ -405,6 +412,10 @@ oldpkg->tmp_unpack_dir =str_dup_safe (newpkg->tmp_unpack_dir);if (!oldpkg->md5sum) oldpkg->md5sum =str_dup_safe (newpkg->md5sum); +#if definedHAVE_SHA256 +if (!oldpkg->sha256sum) + oldpkg->sha256sum =str_dup_safe (newpkg->sha256sum); +#endif if (!oldpkg->size) oldpkg->size =str_dup_safe (newpkg->size);if (!oldpkg->installed_size)
@@ -955,7 +966,7 @@break ;case 's' :case 'S' : { -/* Section | Size | Source | Status | Suggests */ +/* Section | SHA256sum | Size | Source | Status | Suggests */ if (strcasecmp (field,"Section" ) ==0 ) {/* Section */ if (pkg->section) {
@@ -967,6 +978,19 @@ temp[0 ]='\0' ;snprintf (temp, (strlen (pkg->section)+11 ),"Section: %s\n" , pkg->section); } +#if definedHAVE_SHA256 + } else if (strcasecmp(field, "SHA256sum") == 0) { +/* SHA256sum */ +if (pkg->sha256sum) { + temp = (char *)realloc (temp,strlen (pkg->sha256sum)+13 ); +if ( temp ==NULL ){ +fprintf (stderr,"%s: out of memory\n" , __FUNCTION__); +return NULL ; + } + temp[0 ]='\0' ; +snprintf (temp, (strlen (pkg->sha256sum)+13 ),"SHA256sum: %s\n" , pkg->sha256sum); + } +#endif }else if (strcasecmp (field,"Size" ) ==0 ) {/* Size */ if (pkg->size) {
pkg.h +3 -0
@@ -161,6 +161,9 @@char *url;char *tmp_unpack_dir;char *md5sum; +#if definedHAVE_SHA256 +char *sha256sum; +#endif char *size;char *installed_size;char *priority;
opkg_install.c +19 -0
@@ -766,6 +766,9 @@abstract_pkg_t *ab_pkg =NULL ;int old_state_flag;char * file_md5; +#ifdef HAVE_SHA256 +char * file_sha256; +#endif char *pkgid;if ( from_upgrade )
@@ -874,6 +877,22 @@free (file_md5); } +#ifdef HAVE_SHA256 +/* Check for sha256 value */ +if (pkg->sha256sum) + { + file_sha256 =file_sha256sum_alloc (pkg->local_filename); +if (strcmp (file_sha256, pkg->sha256sum)) + { +opkg_message (conf,OPKG_ERROR , +"Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n" , + pkg->name); +free (file_sha256); +return OPKG_INSTALL_ERR_SHA256 ; + } + } +#endif +if (pkg->tmp_unpack_dir ==NULL ) {unpack_pkg_control_files (conf, pkg); }
Makefile.am +4 -0
@@ -30,6 +30,10 @@ sprintf_alloc.c sprintf_alloc.h str_util.c str_util.h \ xregex.c xregex.h xsystem.c xsystem.h +if HAVE_SHA256 +opkg_util_sources += sha256.c sha256.h +endif + lib_LTLIBRARIES = libopkg.la libopkg_la_SOURCES = \ $(opkg_libcore_sources) \
configure.ac +11 -0
@@ -37,7 +37,18 @@ AC_DEFINE(HAVE_CURL, 1, [Define if you want CURL support]) fi +# check for sha256 +AC_ARG_ENABLE(sha256, + AC_HELP_STRING([--enable-sha256], [Enable sha256sum check + [[default=yes]] ]), + [want_sha256="$enableval"], [want_sha256="yes"]) +if test "x$want_sha256" = "xyes"; then + AC_DEFINE(HAVE_SHA256, 1, [Define if you want sha256 support]) +fi +AM_CONDITIONAL(HAVE_SHA256, test "x$want_sha256" = "xyes") + + dnl ********** dnl GPGME dnl **********