* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-
+/*
+ * XXX: should use v4 signatures for binary files (already used for public key)
+ */
/**
* \file
* This file contains functions related to VLC update management
int i_bytes = pgp_unarmor( p_buf, i_size, (uint8_t*)p_sig, 65 );
free( p_buf );
- if( i_bytes > 65 )
+ if( i_bytes == 0 )
+ {
+ msg_Dbg( p_this, "Unarmoring failed" );
+ return VLC_EGENERIC;
+ }
+ else if( i_bytes > 65 )
{
msg_Dbg( p_this, "Signature is too big: %d bytes", i_bytes );
return VLC_EGENERIC;
int i_r_len = mpi_len( p_sig->r );
if( i_r_len > 20 )
{
- msg_Dbg( p_this, "Signature invalid" );
+ msg_Dbg( p_this, "Invalid signature, r number too big: %d bytes",
+ i_r_len );
return VLC_EGENERIC;
}
else if( i_r_len < 20 )
fclose( f );
gcry_md_final( hd );
- uint8_t *p_hash = (uint8_t*) gcry_md_read( hd, GCRY_MD_SHA1);
- p_hash = strdup( p_hash );
+ uint8_t *p_tmp = (uint8_t*) gcry_md_read( hd, GCRY_MD_SHA1);
+ uint8_t *p_hash = malloc( 20 );
+ if( p_hash )
+ memcpy( p_hash, p_tmp, 20 );
gcry_md_close( hd );
return p_hash;
}
gcry_md_final( hd );
- uint8_t *p_hash = gcry_md_read( hd, GCRY_MD_SHA1);
+ uint8_t *p_tmp = gcry_md_read( hd, GCRY_MD_SHA1);
- if( p_hash[0] != p_pkey->sig.hash_verification[0] ||
- p_hash[1] != p_pkey->sig.hash_verification[1] )
+ if( !p_tmp ||
+ p_tmp[0] != p_pkey->sig.hash_verification[0] ||
+ p_tmp[1] != p_pkey->sig.hash_verification[1] )
{
gcry_md_close( hd );
return NULL;
}
- p_hash = strdup( p_hash );
+ uint8_t *p_hash = malloc( 20 );
+ if( p_hash )
+ memcpy( p_hash, p_tmp, 20 );
gcry_md_close( hd );
return p_hash;
}
/**
* Get the update file and parse it
- * *p_update has to be locked when calling this function
+ * p_update has to be locked when calling this function
*
* \param p_update pointer to update struct
* \return VLC_TRUE if the update is valid and authenticated
gcry_md_hd_t hd;
if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) )
- goto error;
+ goto error_hd;
gcry_md_write( hd, psz_version_line, strlen( psz_version_line ) );
FREENULL( psz_version_line );
p_hash[1] != sign.hash_verification[1] )
{
msg_Warn( p_update->p_libvlc, "Bad SHA1 hash for status file" );
- goto error;
+ goto error_hd;
}
if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
!= VLC_SUCCESS )
{
msg_Err( p_update->p_libvlc, "BAD SIGNATURE for status file" );
- goto error;
+ goto error_hd;
}
else
{
return VLC_TRUE;
}
-error:
+error_hd:
gcry_md_close( hd );
+error:
if( p_stream )
stream_Delete( p_stream );
free( psz_version_line );
update_check_thread_t *p_uct = vlc_object_create( p_update->p_libvlc,
sizeof( update_check_thread_t ) );
+ if( !p_uct )
+ {
+ msg_Err( p_update->p_libvlc, "out of memory" );
+ return;
+ }
+
p_uct->p_update = p_update;
p_uct->pf_callback = pf_callback;
p_uct->p_data = p_data;
if( p_uct->pf_callback )
(p_uct->pf_callback)( p_uct->p_data, b_ret );
- vlc_object_destroy( p_uct );
+ vlc_object_release( p_uct );
}
/**
static char *size_str( long int l_size )
{
char *psz_tmp = NULL;
+ int i_retval = 0;
if( l_size >> 30 )
- asprintf( &psz_tmp, "%.1f GB", (float)l_size/(1<<30) );
+ i_retval = asprintf( &psz_tmp, "%.1f GB", (float)l_size/(1<<30) );
else if( l_size >> 20 )
- asprintf( &psz_tmp, "%.1f MB", (float)l_size/(1<<20) );
+ i_retval = asprintf( &psz_tmp, "%.1f MB", (float)l_size/(1<<20) );
else if( l_size >> 10 )
- asprintf( &psz_tmp, "%.1f kB", (float)l_size/(1<<10) );
+ i_retval = asprintf( &psz_tmp, "%.1f kB", (float)l_size/(1<<10) );
else
- asprintf( &psz_tmp, "%ld B", l_size );
- return psz_tmp;
+ i_retval = asprintf( &psz_tmp, "%ld B", l_size );
+
+ return i_retval == -1 ? NULL : psz_tmp;
}
-/*
+/**
* Struct to launch the download in a thread
*/
typedef struct
assert( p_update );
update_download_thread_t *p_udt = vlc_object_create( p_update->p_libvlc,
- sizeof( update_download_thread_t ) );
+ sizeof( update_download_thread_t ) );
+ if( !p_udt )
+ {
+ msg_Err( p_update->p_libvlc, "out of memory" );
+ return;
+ }
p_udt->p_update = p_update;
p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
goto end;
psz_size = size_str( l_size );
- if( asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done", p_update->release.psz_url, psz_size, 0.0 ) != -1 )
+ if( asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done",
+ p_update->release.psz_url, psz_size, 0.0 ) != -1 )
{
i_progress = intf_UserProgress( p_udt, "Downloading ...", psz_status, 0.0, 0 );
free( psz_status );
while( ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
!intf_ProgressIsCancelled( p_udt, i_progress ) )
{
- fwrite( p_buffer, i_read, 1, p_file );
+ if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
+ {
+ msg_Err( p_udt, "Failed to write into %s", psz_destfile );
+ break;
+ }
l_downloaded += i_read;
psz_downloaded = size_str( l_downloaded );
f_progress = 100.0*(float)l_downloaded/(float)l_size;
- if( asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done", p_update->release.psz_url,
- psz_downloaded, psz_size, f_progress ) != -1 )
+ if( asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done",
+ p_update->release.psz_url, psz_downloaded, psz_size,
+ f_progress ) != -1 )
{
intf_ProgressUpdate( p_udt, i_progress, psz_status, f_progress, 0 );
free( psz_status );
if( !intf_ProgressIsCancelled( p_udt, i_progress ) )
{
- if( asprintf( &psz_status, "%s\nDone %s (100.0%%)", p_update->release.psz_url, psz_size ) != -1 )
+ if( asprintf( &psz_status, "%s\nDone %s (100.0%%)",
+ p_update->release.psz_url, psz_size ) != -1 )
{
intf_ProgressUpdate( p_udt, i_progress, psz_status, 100.0, 0 );
free( psz_status );
utf8_unlink( psz_destfile );
intf_UserFatal( p_udt, VLC_TRUE, _("File can not be verified"),
- _("It was not possible to downlaod a cryptographic signature for "
+ _("It was not possible to download a cryptographic signature for "
"downloaded file \"%s\", and so VLC deleted it."),
psz_destfile );
msg_Err( p_udt, "Couldn't download signature of downloaded file" );
goto end;
}
+ if( memcmp( sign.issuer_longid, p_update->p_pkey->longid, 8 ) )
+ {
+ utf8_unlink( psz_destfile );
+ msg_Err( p_udt, "Invalid signature issuer" );
+ intf_UserFatal( p_udt, VLC_TRUE, _("Invalid signature"),
+ _("The cryptographic signature for downloaded file \"%s\" was "
+ "invalid and couldn't be used to securely verify it, and so "
+ "VLC deleted it."),
+ psz_destfile );
+ goto end;
+ }
+
if( sign.type != BINARY_SIGNATURE )
{
utf8_unlink( psz_destfile );
free( p_buffer );
free( psz_size );
- vlc_object_destroy( p_udt );
+ vlc_object_release( p_udt );
}
#endif