]> git.sesse.net Git - vlc/blobdiff - src/misc/update.c
update: Various fixes to make it work on Mac OS X.
[vlc] / src / misc / update.c
index cd1cd408bfb5ea1ab4f6bb4b4887ebc0a93190c9..96a3948992f7fdfe5aed37b0fe3d8565272d2237 100644 (file)
@@ -22,9 +22,7 @@
  * 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
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_update.h>
 
 #ifdef UPDATE_CHECK
 
 #include <assert.h>
 
-#include <vlc_update.h>
 #include <vlc_pgpkey.h>
 #include <vlc_stream.h>
+#include <vlc_strings.h>
+#include <vlc_charset.h>
 #include <vlc_interface.h>
+
+#include <gcrypt.h>
 #include <vlc_gcrypt.h>
 
+#include "update.h"
+#include "../libvlc.h"
 
 /*****************************************************************************
  * Misc defines
@@ -64,7 +68,7 @@
  *      * e is an OPTIONAL extra letter
  *      * AKA "0.8.6d" or "0.9.0"
  * Second line is an url of the binary for this last version
- * Third line is a description of the update (it MAY be extended to several lines, but for now it is only one line)
+ * Remaining text is a required description of the update
  */
 
 #if defined( UNDER_CE )
@@ -101,14 +105,16 @@ static char * size_str( long int l_size );
 
 static inline int scalar_number( uint8_t *p, int header_len )
 {
+    assert( header_len == 1 || header_len == 2 || header_len == 4 );
+
     if( header_len == 1 )
         return( p[0] );
     else if( header_len == 2 )
         return( (p[0] << 8) + p[1] );
     else if( header_len == 4 )
         return( (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3] );
-    else
-        abort();
+
+    abort(); /* to shut up GCC warning */
 }
 
 /* number of data bytes in a MPI */
@@ -121,150 +127,294 @@ static inline int scalar_number( uint8_t *p, int header_len )
 static int parse_public_key_packet( public_key_packet_t *p_key, uint8_t *p_buf,
                                     size_t i_packet_len )
 {
-    if( i_packet_len > 418 )
+
+    if( i_packet_len > 418 || i_packet_len < 6 )
         return VLC_EGENERIC;
 
-    p_key->version   = *p_buf++;
+    size_t i_read = 0;
+
+    p_key->version   = *p_buf++; i_read++;
     if( p_key->version != 4 )
         return VLC_EGENERIC;
 
-    /* warn when timestamp is > date ? */
-    memcpy( p_key->timestamp, p_buf, 4 ); p_buf += 4;
+    /* XXX: warn when timestamp is > date ? */
+    memcpy( p_key->timestamp, p_buf, 4 ); p_buf += 4; i_read += 4;
 
-    p_key->algo      = *p_buf++;
+    p_key->algo      = *p_buf++; i_read++;
     if( p_key->algo != PUBLIC_KEY_ALGO_DSA )
         return VLC_EGENERIC;
 
+    /* read p */
+    if( i_read + 2 > i_packet_len )
+        return VLC_EGENERIC;
+
     int i_p_len = mpi_len( p_buf );
-    if( i_p_len > 128 )
+
+    if( i_p_len > 128 || i_read + 2 + i_p_len > i_packet_len )
+        return VLC_EGENERIC;
+
+    memcpy( p_key->p, p_buf, 2+i_p_len );
+    p_buf += 2+i_p_len; i_read += 2+i_p_len;
+
+    /* read q */
+    if( i_read + 2 > i_packet_len )
         return VLC_EGENERIC;
-    else
-    {
-        memcpy( p_key->p, p_buf, 2+i_p_len ); p_buf += 2+i_p_len;
-        if( i_p_len < 128 )
-            memmove( p_key->q, p_key->p + 2+i_p_len, 2+20 + 2+128 + 2+128 );
-    }
 
     int i_q_len = mpi_len( p_buf );
-    if( i_q_len > 20 )
+
+    if( i_q_len > 20 || i_read+2+i_q_len > i_packet_len )
+        return VLC_EGENERIC;
+
+    memcpy( p_key->q, p_buf, 2+i_q_len );
+    p_buf += 2+i_q_len; i_read += 2+i_q_len;
+
+    /* read g */
+    if( i_read + 2 > i_packet_len )
         return VLC_EGENERIC;
-    else
-    {
-        memcpy( p_key->q, p_buf, 2+i_q_len );  p_buf += 2+i_q_len;
-        if( i_p_len < 20 )
-            memmove( p_key->g, p_key->q + 2+i_q_len, 2+128 + 2+128 );
-    }
 
     int i_g_len = mpi_len( p_buf );
-    if( i_g_len > 128 )
+
+    if( i_g_len > 128 || i_read+2+i_g_len > i_packet_len )
+        return VLC_EGENERIC;
+
+    memcpy( p_key->g, p_buf, 2+i_g_len );
+    p_buf += 2+i_g_len; i_read += 2+i_g_len;
+
+    /* read y */
+    if( i_read + 2 > i_packet_len )
         return VLC_EGENERIC;
-    else
-    {
-        memcpy( p_key->g, p_buf, 2+i_g_len ); p_buf += 2+i_g_len;
-        if( i_g_len < 128 )
-            memmove( p_key->y, p_key->g + 2+i_g_len, 2+128 );
-    }
 
     int i_y_len = mpi_len( p_buf );
-    if( i_y_len > 128 )
+
+
+    if( i_y_len > 128 || i_read+2+i_y_len > i_packet_len )
+        return VLC_EGENERIC;
+
+    memcpy( p_key->y, p_buf, 2+i_y_len );
+    i_read += 2+i_y_len;
+
+    if( i_read != i_packet_len ) /* some extra data eh ? */
         return VLC_EGENERIC;
-    else
-        memcpy( p_key->y, p_buf, 2+i_y_len );
 
     return VLC_SUCCESS;
 }
 
+static size_t parse_signature_v3_packet( signature_packet_t *p_sig,
+                                      uint8_t *p_buf, size_t i_sig_len )
+{
+    size_t i_read = 1; /* we already read the version byte */
+
+    if( i_sig_len < 19 ) /* signature is at least 19 bytes + the 2 MPIs */
+        return 0;
+
+    p_sig->specific.v3.hashed_data_len = *p_buf++; i_read++;
+    if( p_sig->specific.v3.hashed_data_len != 5 )
+        return 0;
+
+    p_sig->type = *p_buf++; i_read++;
+
+    memcpy( p_sig->specific.v3.timestamp, p_buf, 4 );
+    p_buf += 4; i_read += 4;
+
+    memcpy( p_sig->issuer_longid, p_buf, 8 );
+    p_buf += 8; i_read += 8;
+
+    p_sig->public_key_algo = *p_buf++; i_read++;
+
+    p_sig->digest_algo = *p_buf++; i_read++;
+
+    p_sig->hash_verification[0] = *p_buf++; i_read++;
+    p_sig->hash_verification[1] = *p_buf++; i_read++;
+
+    assert( i_read == 19 );
+
+    return i_read;
+}
+
 /*
  * fill a signature_packet_v4_t from signature packet data
  * verify that it was used with a DSA public key, using SHA-1 digest
  */
-static int parse_signature_v4_packet( signature_packet_v4_t *p_sig,
+static size_t parse_signature_v4_packet( signature_packet_t *p_sig,
                                       uint8_t *p_buf, size_t i_sig_len )
 {
-    if( i_sig_len < 54 )
-        return VLC_EGENERIC;
+    size_t i_read = 1; /* we already read the version byte */
 
-    p_sig->version = *p_buf++;
-    if( p_sig->version != 4 )
-        return VLC_EGENERIC;
+    if( i_sig_len < 10 ) /* signature is at least 10 bytes + the 2 MPIs */
+        return 0;
 
-    p_sig->type = *p_buf++;
-    if( p_sig->type < GENERIC_KEY_SIGNATURE ||
-        p_sig->type > POSITIVE_KEY_SIGNATURE )
-        return VLC_EGENERIC;
+    p_sig->type = *p_buf++; i_read++;
 
-    p_sig->public_key_algo = *p_buf++;
-    if( p_sig->public_key_algo != PUBLIC_KEY_ALGO_DSA )
-        return VLC_EGENERIC;
+    p_sig->public_key_algo = *p_buf++; i_read++;
 
-    p_sig->digest_algo = *p_buf++;
-    if( p_sig->digest_algo != DIGEST_ALGO_SHA1 )
-        return VLC_EGENERIC;
+    p_sig->digest_algo = *p_buf++; i_read++;
 
-    memcpy( p_sig->hashed_data_len, p_buf, 2 ); p_buf += 2;
+    memcpy( p_sig->specific.v4.hashed_data_len, p_buf, 2 );
+    p_buf += 2; i_read += 2;
 
-    size_t i_pos = 6;
-    size_t i_hashed_data_len = scalar_number( p_sig->hashed_data_len, 2 );
-    i_pos += i_hashed_data_len;
-    if( i_pos > i_sig_len - 48 ) /* r & s are 44 bytes in total,
-                              * + the unhashed data length (2 bytes)
-                              * + the hash verification (2 bytes) */
-        return VLC_EGENERIC;
+    size_t i_hashed_data_len =
+        scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
+    i_read += i_hashed_data_len;
+    if( i_read + 4 > i_sig_len )
+        return 0;
 
-    p_sig->hashed_data = (uint8_t*) malloc( i_hashed_data_len );
-    if( !p_sig->hashed_data )
-        return VLC_ENOMEM;
-    memcpy( p_sig->hashed_data, p_buf, i_hashed_data_len );
+    p_sig->specific.v4.hashed_data = (uint8_t*) malloc( i_hashed_data_len );
+    if( !p_sig->specific.v4.hashed_data )
+        return 0;
+    memcpy( p_sig->specific.v4.hashed_data, p_buf, i_hashed_data_len );
     p_buf += i_hashed_data_len;
 
-    memcpy( p_sig->unhashed_data_len, p_buf, 2 ); p_buf += 2;
+    memcpy( p_sig->specific.v4.unhashed_data_len, p_buf, 2 );
+    p_buf += 2; i_read += 2;
 
-    size_t i_unhashed_data_len = scalar_number( p_sig->unhashed_data_len, 2 );
-    i_pos += 2 + i_unhashed_data_len;
-    if( i_pos != i_sig_len - 46 )
-    {
-        free( p_sig->hashed_data );
-        return VLC_EGENERIC;
-    }
+    size_t i_unhashed_data_len =
+        scalar_number( p_sig->specific.v4.unhashed_data_len, 2 );
+    i_read += i_unhashed_data_len;
+    if( i_read + 2 > i_sig_len )
+        return 0;
 
-    p_sig->unhashed_data = (uint8_t*) malloc( i_unhashed_data_len );
-    if( !p_sig->unhashed_data )
-    {
-        free( p_sig->hashed_data );
-        return VLC_ENOMEM;
-    }
-    memcpy( p_sig->unhashed_data, p_buf, i_unhashed_data_len );
+    p_sig->specific.v4.unhashed_data = (uint8_t*) malloc( i_unhashed_data_len );
+    if( !p_sig->specific.v4.unhashed_data )
+        return 0;
+
+    memcpy( p_sig->specific.v4.unhashed_data, p_buf, i_unhashed_data_len );
     p_buf += i_unhashed_data_len;
 
-    memcpy( p_sig->hash_verification, p_buf, 2 ); p_buf += 2;
+    memcpy( p_sig->hash_verification, p_buf, 2 );
+    p_buf += 2; i_read += 2;
+
+    uint8_t *p, *max_pos;
+    p = p_sig->specific.v4.unhashed_data;
+    max_pos = p + scalar_number( p_sig->specific.v4.unhashed_data_len, 2 );
 
-    int i_r_len = mpi_len( p_buf );
-    if( i_r_len > 20 )
+    for( ;; )
     {
-        free( p_sig->hashed_data );
-        free( p_sig->unhashed_data );
-        return VLC_EGENERIC;
+        if( p > max_pos )
+            return 0;
+
+        size_t i_subpacket_len;
+        if( *p < 192 )
+        {
+            if( p + 1 > max_pos )
+                return 0;
+            i_subpacket_len = *p++;
+        }
+        else if( *p < 255 )
+        {
+            if( p + 2 > max_pos )
+                return 0;
+            i_subpacket_len = (*p++ - 192) << 8;
+            i_subpacket_len += *p++ + 192;
+        }
+        else
+        {
+            if( p + 4 > max_pos )
+                return 0;
+            i_subpacket_len = *++p << 24;
+            i_subpacket_len += *++p << 16;
+            i_subpacket_len += *++p << 8;
+            i_subpacket_len += *++p;
+        }
+
+        if( *p == ISSUER_SUBPACKET )
+        {
+            if( p + 9 > max_pos )
+                return 0;
+
+            memcpy( &p_sig->issuer_longid, p+1, 8 );
+
+            return i_read;
+        }
+
+        p += i_subpacket_len;
     }
-    else
+}
+
+static int parse_signature_packet( signature_packet_t *p_sig,
+                                   uint8_t *p_buf, size_t i_sig_len )
+{
+    if( !i_sig_len ) /* 1st sanity check, we need at least the version */
+        return VLC_EGENERIC;
+
+    p_sig->version = *p_buf++;
+
+    size_t i_read;
+    switch( p_sig->version )
     {
-        memcpy( p_sig->r, p_buf, 2 + i_r_len );
-        p_buf += 2 + i_r_len;
+        case 3:
+            i_read = parse_signature_v3_packet( p_sig, p_buf, i_sig_len );
+            break;
+        case 4:
+            p_sig->specific.v4.hashed_data = NULL;
+            p_sig->specific.v4.unhashed_data = NULL;
+            i_read = parse_signature_v4_packet( p_sig, p_buf, i_sig_len );
+            break;
+        default:
+            return VLC_EGENERIC;
     }
 
-    int i_s_len = mpi_len( p_buf );
-    if( i_s_len > 20 )
+    if( i_read == 0 ) /* signature packet parsing has failed */
+        goto error;
+
+    if( p_sig->public_key_algo != PUBLIC_KEY_ALGO_DSA )
+        goto error;
+
+    if( p_sig->digest_algo != DIGEST_ALGO_SHA1 )
+        goto error;
+
+    switch( p_sig->type )
     {
-        free( p_sig->hashed_data );
-        free( p_sig->unhashed_data );
-        return VLC_EGENERIC;
+        case BINARY_SIGNATURE:
+        case TEXT_SIGNATURE:
+        case GENERIC_KEY_SIGNATURE:
+        case PERSONA_KEY_SIGNATURE:
+        case CASUAL_KEY_SIGNATURE:
+        case POSITIVE_KEY_SIGNATURE:
+            break;
+        default:
+            goto error;
     }
-    else
+
+    p_buf--; /* rewind to the version byte */
+    p_buf += i_read;
+
+    if( i_read + 2 > i_sig_len )
+        goto error;
+
+    size_t i_r_len = mpi_len( p_buf ); i_read += 2;
+    if( i_read + i_r_len > i_sig_len || i_r_len > 20 )
+        goto error;
+
+    memcpy( p_sig->r, p_buf, 2 + i_r_len );
+    p_buf += 2 + i_r_len;
+    i_read += i_r_len;
+
+    if( i_read + 2 > i_sig_len )
+        goto error;
+
+    size_t i_s_len = mpi_len( p_buf ); i_read += 2;
+    if( i_read + i_s_len > i_sig_len || i_s_len > 20 )
+        goto error;
+
+    memcpy( p_sig->s, p_buf, 2 + i_s_len );
+    p_buf += 2 + i_s_len;
+    i_read += i_s_len;
+
+    assert( i_read == i_sig_len );
+    if( i_read < i_sig_len ) /* some extra data, hm ? */
+        goto error;
+
+    return VLC_SUCCESS;
+
+error:
+
+    if( p_sig->version == 4 )
     {
-        memcpy( p_sig->s, p_buf, 2 + i_s_len );
-        p_buf += 2 + i_s_len;
+        free( p_sig->specific.v4.hashed_data );
+        free( p_sig->specific.v4.unhashed_data );
     }
 
-    return VLC_SUCCESS;
+    return VLC_EGENERIC;
 }
 
 /*
@@ -362,7 +512,7 @@ static int pgp_unarmor( char *p_ibuf, size_t i_ibuf_len,
  * We're given the file's url, we just append ".asc" to it and download
  */
 static int download_signature(  vlc_object_t *p_this,
-                                signature_packet_v3_t *p_sig,
+                                signature_packet_t *p_sig,
                                 const char *psz_url )
 {
     char *psz_sig = (char*) malloc( strlen( psz_url ) + 4 + 1 ); /* ".asc" + \0 */
@@ -379,22 +529,9 @@ static int download_signature(  vlc_object_t *p_this,
         return VLC_ENOMEM;
 
     int64_t i_size = stream_Size( p_stream );
-    if( i_size <= 65 ) /* binary format signature */
-    {
-        msg_Dbg( p_this, "Downloading unarmored signature" );
-        int i_read = stream_Read( p_stream, p_sig, (int)i_size );
-        stream_Delete( p_stream );
-        if( i_read != i_size )
-        {
-            msg_Dbg( p_this, "Couldn't read full signature" );
-            return VLC_EGENERIC;
-        }
-        else
-            return VLC_SUCCESS;
-    }
 
-    msg_Dbg( p_this, "Downloading armored signature" );
-    char *p_buf = (char*)malloc( i_size );
+    msg_Dbg( p_this, "Downloading signature (%"PRId64" bytes)", i_size );
+    uint8_t *p_buf = (uint8_t*)malloc( i_size );
     if( !p_buf )
     {
         stream_Delete( p_stream );
@@ -405,41 +542,83 @@ static int download_signature(  vlc_object_t *p_this,
 
     stream_Delete( p_stream );
 
-    if( i_read != i_size )
+    if( i_read != (int)i_size )
     {
-        msg_Dbg( p_this, "Couldn't read full signature" );
+        msg_Dbg( p_this,
+            "Couldn't download full signature (only %d bytes)", i_read );
         free( p_buf );
         return VLC_EGENERIC;
     }
 
-    int i_bytes = pgp_unarmor( p_buf, i_size, (uint8_t*)p_sig, 65 );
-    free( p_buf );
+    if( (uint8_t)*p_buf < 0x80 ) /* ASCII */
+    {
+        msg_Dbg( p_this, "Unarmoring signature" );
+
+        uint8_t* p_unarmored = (uint8_t*) malloc( ( i_size * 3 ) / 4 + 1 );
+        if( !p_unarmored )
+        {
+            free( p_buf );
+            return VLC_EGENERIC;
+        }
+
+        int i_bytes = pgp_unarmor( (char*)p_buf, i_size, p_unarmored, i_size );
+        free( p_buf );
+
+        p_buf = p_unarmored;
+        i_size = i_bytes;
+
+        if( i_bytes < 2 )
+        {
+            free( p_buf );
+            msg_Dbg( p_this, "Unarmoring failed : corrupted signature ?" );
+            return VLC_EGENERIC;
+        }
+    }
+
+    if( packet_type( *p_buf ) != SIGNATURE_PACKET )
+    {
+        free( p_buf );
+        msg_Dbg( p_this, "Not a signature: %d", *p_buf );
+        return VLC_EGENERIC;
+    }
 
-    if( i_bytes == 0 )
+    size_t i_header_len = packet_header_len( *p_buf );
+    if( ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) ||
+        i_header_len + 1 > (size_t)i_size )
     {
-        msg_Dbg( p_this, "Unarmoring failed" );
+        free( p_buf );
+        msg_Dbg( p_this, "Invalid signature packet header" );
         return VLC_EGENERIC;
     }
-    else if( i_bytes > 65 )
+
+    size_t i_len = scalar_number( p_buf+1, i_header_len );
+    if( i_len + i_header_len + 1 != (size_t)i_size )
     {
-        msg_Dbg( p_this, "Signature is too big: %d bytes", i_bytes );
+        free( p_buf );
+        msg_Dbg( p_this, "Invalid signature packet" );
         return VLC_EGENERIC;
     }
-    else
+
+    int i_ret = parse_signature_packet( p_sig, p_buf+1+i_header_len, i_len );
+    free( p_buf );
+    if( i_ret != VLC_SUCCESS )
     {
-        int i_r_len = mpi_len( p_sig->r );
-        if( i_r_len > 20 )
+        msg_Dbg( p_this, "Couldn't parse signature" );
+        return i_ret;
+    }
+
+    if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE )
+    {
+        msg_Dbg( p_this, "Invalid signature type: %d", p_sig->type );
+        if( p_sig->version == 4 )
         {
-            msg_Dbg( p_this, "Invalid signature, r number too big: %d bytes",
-                                i_r_len );
-            return VLC_EGENERIC;
+            free( p_sig->specific.v4.hashed_data );
+            free( p_sig->specific.v4.unhashed_data );
         }
-        else if( i_r_len < 20 )
-            /* move s to the right place if r is less than 20 bytes */
-            memmove( p_sig->s, p_sig->r + 2 + i_r_len, 20 + 2 );
-
-        return VLC_SUCCESS;
+        return VLC_EGENERIC;
     }
+
+    return VLC_SUCCESS;
 }
 
 /*
@@ -503,38 +682,14 @@ problem:
     return VLC_EGENERIC;
 }
 
-/*
- * Return the long id (8 bytes) of the public key used to generate a signature
- */
-static uint8_t *get_issuer_from_signature_v4( signature_packet_v4_t *p_sig )
-{
-    uint8_t *p = p_sig->unhashed_data;
-    uint8_t *max_pos = p + scalar_number( p_sig->unhashed_data_len, 2 );
-
-    while( p < max_pos )
-    {
-        int i_subpacket_len = *p < 192 ? *p++ :
-                *p < 255 ? ((*p++ - 192) << 8) + *p++ + 192 :
-                ((*++p) << 24) + (*++p << 16) + (*++p << 8) + *++p;
-
-        if( p >= max_pos - 1 )
-            return NULL;
-
-        if( *p == ISSUER_SUBPACKET )
-            return p+1;
-        else
-            p += i_subpacket_len;
-    }
-    return NULL;
-}
-
 /*
  * fill a public_key_t with public key data, including:
  *   * public key packet
  *   * signature packet issued by key which long id is p_sig_issuer
  *   * user id packet
  */
-static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public_key_t *p_key, const uint8_t *p_sig_issuer )
+static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len,
+                             public_key_t *p_key, const uint8_t *p_sig_issuer )
 {
     uint8_t *pos = (uint8_t*) p_key_data;
     uint8_t *max_pos = pos + i_key_len;
@@ -546,10 +701,9 @@ static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public
 
     uint8_t *p_key_unarmored = NULL;
 
-    signature_packet_v4_t sig;
-
     p_key->psz_username = NULL;
-    p_key->sig.hashed_data = p_key->sig.unhashed_data = NULL;
+    p_key->sig.specific.v4.hashed_data = NULL;
+    p_key->sig.specific.v4.unhashed_data = NULL;
 
     if( !( *pos & 0x80 ) )
     {   /* first byte is ASCII, unarmoring */
@@ -574,7 +728,8 @@ static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public
         int i_type = packet_type( *pos );
 
         int i_header_len = packet_header_len( *pos++ );
-        if( pos + i_header_len > max_pos )
+        if( pos + i_header_len > max_pos ||
+            ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) )
             goto error;
 
         int i_packet_len = scalar_number( pos, i_header_len );
@@ -585,29 +740,31 @@ static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public
 
         switch( i_type )
         {
-            uint8_t *p_issuer;
-
             case PUBLIC_KEY_PACKET:
                 i_status |= PUBLIC_KEY_FOUND;
                 if( parse_public_key_packet( &p_key->key, pos, i_packet_len ) != VLC_SUCCESS )
                     goto error;
                 break;
 
-            case SIGNATURE_PACKET:
-                if( !p_sig_issuer || i_status & SIGNATURE_FOUND ||
-                    parse_signature_v4_packet( &sig, pos, i_packet_len ) != VLC_SUCCESS )
+            case SIGNATURE_PACKET: /* we accept only v4 signatures here */
+                if( i_status & SIGNATURE_FOUND || !p_sig_issuer )
                     break;
-                p_issuer = get_issuer_from_signature_v4( &sig );
-                if( memcmp( p_issuer, p_sig_issuer, 8 ) == 0 )
+                int i_ret = parse_signature_packet( &p_key->sig, pos,
+                                                    i_packet_len );
+                if( i_ret == VLC_SUCCESS )
                 {
-                    memcpy( &p_key->sig, &sig, sizeof( signature_packet_v4_t ) );
+                    if( p_key->sig.version != 4 )
+                        break;
+                    if( memcmp( p_key->sig.issuer_longid, p_sig_issuer, 8 ) )
+                    {
+                        free( p_key->sig.specific.v4.hashed_data );
+                        free( p_key->sig.specific.v4.unhashed_data );
+                        p_key->sig.specific.v4.hashed_data = NULL;
+                        p_key->sig.specific.v4.unhashed_data = NULL;
+                        break;
+                    }
                     i_status |= SIGNATURE_FOUND;
                 }
-                else
-                {
-                    free( sig.hashed_data );
-                    free( sig.unhashed_data );
-                }
                 break;
 
             case USER_ID_PACKET:
@@ -629,7 +786,7 @@ static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public
     }
     free( p_key_unarmored );
 
-    if( !( i_status & ( PUBLIC_KEY_FOUND + USER_ID_FOUND ) ) )
+    if( !( i_status & ( PUBLIC_KEY_FOUND | USER_ID_FOUND ) ) )
         return VLC_EGENERIC;
 
     if( p_sig_issuer && !( i_status & SIGNATURE_FOUND ) )
@@ -638,8 +795,11 @@ static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public
     return VLC_SUCCESS;
 
 error:
-    free( p_key->sig.hashed_data );
-    free( p_key->sig.unhashed_data );
+    if( p_key->sig.version == 4 )
+    {
+        free( p_key->sig.specific.v4.hashed_data );
+        free( p_key->sig.specific.v4.unhashed_data );
+    }
     free( p_key->psz_username );
     free( p_key_unarmored );
     return VLC_EGENERIC;
@@ -649,8 +809,11 @@ error:
  * return a sha1 hash of a file
  */
 static uint8_t *hash_sha1_from_file( const char *psz_file,
-                            signature_packet_v3_t *p_sig )
+                            signature_packet_t *p_sig )
 {
+    if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE )
+        return NULL;
+
     FILE *f = utf8_fopen( psz_file, "r" );
     if( !f )
         return NULL;
@@ -668,8 +831,26 @@ static uint8_t *hash_sha1_from_file( const char *psz_file,
     while( ( i_read = fread( buffer, 1, sizeof(buffer), f ) ) > 0 )
         gcry_md_write( hd, buffer, i_read );
 
-    gcry_md_putc( hd, p_sig->type );
-    gcry_md_write( hd, &p_sig->timestamp, 4 );
+    if( p_sig->version == 3 )
+    {
+        gcry_md_putc( hd, p_sig->type );
+        gcry_md_write( hd, &p_sig->specific.v3.timestamp, 4 );
+    }
+    else if( p_sig->version == 4 )
+    {
+        gcry_md_putc( hd, p_sig->version );
+        gcry_md_putc( hd, p_sig->type );
+        gcry_md_putc( hd, p_sig->public_key_algo );
+        gcry_md_putc( hd, p_sig->digest_algo );
+        gcry_md_write( hd, p_sig->specific.v4.hashed_data_len, 2 );
+        size_t i_len = scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
+        gcry_md_write( hd, p_sig->specific.v4.hashed_data, i_len );
+    }
+    else
+    {   /* RFC 4880 only tells about versions 3 and 4 */
+        gcry_md_close( hd );
+        return NULL;
+    }
 
     fclose( f );
     gcry_md_final( hd );
@@ -685,7 +866,8 @@ static uint8_t *hash_sha1_from_file( const char *psz_file,
 /*
  * download a public key (the last one) from videolan server, and parse it
  */
-static public_key_t *download_key( vlc_object_t *p_this, const uint8_t *p_longid, const uint8_t *p_signature_issuer )
+static public_key_t *download_key( vlc_object_t *p_this,
+                    const uint8_t *p_longid, const uint8_t *p_signature_issuer )
 {
     char *psz_url;
     if( asprintf( &psz_url, "http://download.videolan.org/pub/keys/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X.asc",
@@ -729,6 +911,8 @@ static public_key_t *download_key( vlc_object_t *p_this, const uint8_t *p_longid
         return NULL;
     }
 
+    memcpy( p_pkey->longid, p_longid, 8 );
+
     int i_error = parse_public_key( p_buf, i_read, p_pkey, p_signature_issuer );
     free( p_buf );
 
@@ -743,11 +927,18 @@ static public_key_t *download_key( vlc_object_t *p_this, const uint8_t *p_longid
 }
 
 /*
- * Generate a SHA-1 hash on a public key, to verify a signature made on that hash
- * Note that we need the signature to compute the hash
+ * Generate a SHA1 hash on a public key, to verify a signature made on that hash
+ * Note that we need the signature (v4) to compute the hash
  */
 static uint8_t *key_sign_hash( public_key_t *p_pkey )
 {
+    if( p_pkey->sig.version != 4 )
+        return NULL;
+
+    if( p_pkey->sig.type < GENERIC_KEY_SIGNATURE ||
+        p_pkey->sig.type > POSITIVE_KEY_SIGNATURE )
+        return NULL;
+
     gcry_error_t error = 0;
     gcry_md_hd_t hd;
 
@@ -757,30 +948,35 @@ static uint8_t *key_sign_hash( public_key_t *p_pkey )
 
     gcry_md_putc( hd, 0x99 );
 
-    gcry_md_putc( hd, (418 >> 8) & 0xff );
-    gcry_md_putc( hd, 418 & 0xff );
+    size_t i_p_len = mpi_len( p_pkey->key.p );
+    size_t i_g_len = mpi_len( p_pkey->key.g );
+    size_t i_q_len = mpi_len( p_pkey->key.q );
+    size_t i_y_len = mpi_len( p_pkey->key.y );
+
+    size_t i_size = 6 + 2*4 + i_p_len + i_g_len + i_q_len + i_y_len;
 
-    gcry_md_write( hd, (uint8_t*)&p_pkey->key, 6 ); /* version,timestamp,algo */
+    gcry_md_putc( hd, (i_size >> 8) & 0xff );
+    gcry_md_putc( hd, i_size & 0xff );
+
+    gcry_md_putc( hd, p_pkey->key.version );
+    gcry_md_write( hd, p_pkey->key.timestamp, 4 );
+    gcry_md_putc( hd, p_pkey->key.algo );
 
-    int i_p_len = mpi_len( p_pkey->key.p );
     gcry_md_write( hd, (uint8_t*)&p_pkey->key.p, 2 );
     gcry_md_write( hd, (uint8_t*)&p_pkey->key.p + 2, i_p_len );
 
-    int i_g_len = mpi_len( p_pkey->key.g );
-    gcry_md_write( hd, (uint8_t*)&p_pkey->key.g, 2 );
-    gcry_md_write( hd, (uint8_t*)&p_pkey->key.g + 2, i_g_len );
-
-    int i_q_len = mpi_len( p_pkey->key.q );
     gcry_md_write( hd, (uint8_t*)&p_pkey->key.q, 2 );
     gcry_md_write( hd, (uint8_t*)&p_pkey->key.q + 2, i_q_len );
 
-    int i_y_len = mpi_len( p_pkey->key.y );
+    gcry_md_write( hd, (uint8_t*)&p_pkey->key.g, 2 );
+    gcry_md_write( hd, (uint8_t*)&p_pkey->key.g + 2, i_g_len );
+
     gcry_md_write( hd, (uint8_t*)&p_pkey->key.y, 2 );
     gcry_md_write( hd, (uint8_t*)&p_pkey->key.y + 2, i_y_len );
 
     gcry_md_putc( hd, 0xb4 );
 
-    int i_len = strlen((char*)p_pkey->psz_username);
+    size_t i_len = strlen((char*)p_pkey->psz_username);
 
     gcry_md_putc( hd, (i_len << 24) & 0xff );
     gcry_md_putc( hd, (i_len << 16) & 0xff );
@@ -789,14 +985,15 @@ static uint8_t *key_sign_hash( public_key_t *p_pkey )
 
     gcry_md_write( hd, p_pkey->psz_username, i_len );
 
-    size_t i_hashed_data_len = scalar_number( p_pkey->sig.hashed_data_len, 2 );
+    size_t i_hashed_data_len =
+        scalar_number( p_pkey->sig.specific.v4.hashed_data_len, 2 );
 
     gcry_md_putc( hd, p_pkey->sig.version );
     gcry_md_putc( hd, p_pkey->sig.type );
     gcry_md_putc( hd, p_pkey->sig.public_key_algo );
     gcry_md_putc( hd, p_pkey->sig.digest_algo );
-    gcry_md_write( hd, p_pkey->sig.hashed_data_len, 2 );
-    gcry_md_write( hd, p_pkey->sig.hashed_data, i_hashed_data_len );
+    gcry_md_write( hd, p_pkey->sig.specific.v4.hashed_data_len, 2 );
+    gcry_md_write( hd, p_pkey->sig.specific.v4.hashed_data, i_hashed_data_len );
 
     gcry_md_putc( hd, 0x04 );
     gcry_md_putc( hd, 0xff );
@@ -853,6 +1050,9 @@ update_t *__update_New( vlc_object_t *p_this )
     p_update->release.psz_url = NULL;
     p_update->release.psz_desc = NULL;
 
+    p_update->p_download = NULL;
+    p_update->p_check = NULL;
+
     p_update->p_pkey = NULL;
     vlc_gcrypt_init();
 
@@ -869,6 +1069,19 @@ void update_Delete( update_t *p_update )
 {
     assert( p_update );
 
+    if( p_update->p_check )
+    {
+        assert( !p_update->p_download );
+        vlc_object_kill( p_update->p_check );
+        vlc_thread_join( p_update->p_check );
+    }
+    else if( p_update->p_download )
+    {
+        vlc_object_kill( p_update->p_download );
+        vlc_thread_join( p_update->p_download );
+        vlc_object_release( p_update->p_download );
+    }
+
     vlc_mutex_destroy( &p_update->lock );
 
     free( p_update->release.psz_url );
@@ -908,7 +1121,6 @@ static bool GetUpdateFile( update_t *p_update )
     int i_minor = 0;
     int i_revision = 0;
     unsigned char extra;
-    char *psz_line = NULL;
     char *psz_version_line = NULL;
 
     p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
@@ -919,18 +1131,18 @@ static bool GetUpdateFile( update_t *p_update )
         goto error;
     }
 
-    /* Try to read three lines */
-    if( !( psz_line = stream_ReadLine( p_stream ) ) )
+    /* Start reading the status file */
+    if( !( psz_version_line = stream_ReadLine( p_stream ) ) )
     {
         msg_Err( p_update->p_libvlc, "Update file %s is corrupted : missing version",
                  UPDATE_VLC_STATUS_URL );
         goto error;
     }
 
-    psz_version_line = psz_line;
     /* first line : version number */
     p_update->release.extra = 0;
-    switch( sscanf( psz_line, "%i.%i.%i%c", &i_major, &i_minor, &i_revision, &extra ) )
+    switch( sscanf( psz_version_line, "%i.%i.%i%c",
+                    &i_major, &i_minor, &i_revision, &extra ) )
     {
         case 4:
             p_update->release.extra = extra;
@@ -944,31 +1156,42 @@ static bool GetUpdateFile( update_t *p_update )
             goto error;
     }
 
-    /* Second line : URL */
-    if( !( psz_line = stream_ReadLine( p_stream ) ) )
+    /* second line : URL */
+    if( !( p_update->release.psz_url = stream_ReadLine( p_stream ) ) )
     {
         msg_Err( p_update->p_libvlc, "Update file %s is corrupted : URL missing",
                  UPDATE_VLC_STATUS_URL );
         goto error;
     }
-    p_update->release.psz_url = psz_line;
 
+    /* Remaining data : description */
+    int i_read = stream_Size( p_stream ) - stream_Tell( p_stream );
+    if( i_read <= 0 )
+    {
+        msg_Err( p_update->p_libvlc,
+                "Update file %s is corrupted: description missing",
+                UPDATE_VLC_STATUS_URL );
+        goto error;
+    }
 
-    /* Third line : description */
-    if( !( psz_line = stream_ReadLine( p_stream ) ) )
+    p_update->release.psz_desc = (char*) malloc( i_read + 1 );
+    if( !p_update->release.psz_desc )
+        goto error;
+
+    if( stream_Read( p_stream, p_update->release.psz_desc, i_read ) != i_read )
     {
-        msg_Err( p_update->p_libvlc, "Update file %s is corrupted : description missing",
-                 UPDATE_VLC_STATUS_URL );
+        msg_Err( p_update->p_libvlc, "Couldn't download update file %s",
+                UPDATE_VLC_STATUS_URL );
         goto error;
     }
-    p_update->release.psz_desc = psz_line;
+    p_update->release.psz_desc[i_read] = '\0';
 
     stream_Delete( p_stream );
     p_stream = NULL;
 
     /* Now that we know the status is valid, we must download its signature
      * to authenticate it */
-    signature_packet_v3_t sign;
+    signature_packet_t sign;
     if( download_signature( VLC_OBJECT( p_update->p_libvlc ), &sign,
             UPDATE_VLC_STATUS_URL ) != VLC_SUCCESS )
     {
@@ -994,7 +1217,9 @@ static bool GetUpdateFile( update_t *p_update )
         goto error;
     }
 
-    if( memcmp( sign.issuer_longid, videolan_public_key_longid , 8 ) != 0 )
+    memcpy( p_update->p_pkey->longid, videolan_public_key_longid, 8 );
+
+    if( memcmp( sign.issuer_longid, p_update->p_pkey->longid , 8 ) != 0 )
     {
         msg_Dbg( p_update->p_libvlc, "Need to download the GPG key" );
         public_key_t *p_new_pkey = download_key(
@@ -1046,14 +1271,54 @@ static bool GetUpdateFile( update_t *p_update )
     if( sign.type == TEXT_SIGNATURE )
         gcry_md_putc( hd, '\r' );
     gcry_md_putc( hd, '\n' );
-    gcry_md_write( hd, p_update->release.psz_desc,
-                        strlen( p_update->release.psz_desc ) );
-    if( sign.type == TEXT_SIGNATURE )
-        gcry_md_putc( hd, '\r' );
-    gcry_md_putc( hd, '\n' );
 
-    gcry_md_putc( hd, sign.type );
-    gcry_md_write( hd, &sign.timestamp, 4 );
+    char *psz_desc = p_update->release.psz_desc;
+    while( *psz_desc )
+    {
+        size_t i_len = strcspn( psz_desc, "\r\n" );
+        if( !i_len )
+            break;
+
+        gcry_md_write( hd, psz_desc, i_len );
+        if( sign.type == TEXT_SIGNATURE )
+            gcry_md_putc( hd, '\r' );
+        gcry_md_putc( hd, '\n' );
+
+        psz_desc += i_len;
+        while( *psz_desc == '\r' || *psz_desc == '\n' )
+            psz_desc++;
+    }
+
+    if( sign.version == 3 )
+    {
+        gcry_md_putc( hd, sign.type );
+        gcry_md_write( hd, &sign.specific.v3.timestamp, 4 );
+    }
+    else if( sign.version == 4 )
+    {
+        gcry_md_putc( hd, sign.version );
+        gcry_md_putc( hd, sign.type );
+        gcry_md_putc( hd, sign.public_key_algo );
+        gcry_md_putc( hd, sign.digest_algo );
+        gcry_md_write( hd, sign.specific.v4.hashed_data_len, 2 );
+        size_t i_len = scalar_number( sign.specific.v4.hashed_data_len, 2 );
+        gcry_md_write( hd, sign.specific.v4.hashed_data, i_len );
+        gcry_md_putc( hd, 0x04 );
+        gcry_md_putc( hd, 0xFF );
+
+        i_len += 6; /* hashed data + 6 bytes header */
+
+        gcry_md_putc( hd, (i_len << 24) & 0xff);
+        gcry_md_putc( hd, (i_len << 16) &0xff );
+        gcry_md_putc( hd, (i_len << 8) & 0xff );
+        gcry_md_putc( hd, (i_len) & 0xff );
+    }
+    else
+    {   /* RFC 4880 only tells about versions 3 and 4 */
+        msg_Warn( p_update->p_libvlc, "Invalid signature version %d",
+                sign.version);
+        goto error_hd;
+    }
 
     gcry_md_final( hd );
 
@@ -1088,19 +1353,7 @@ error:
     return false;
 }
 
-
-/**
- * Struct to launch the check in an other thread
- */
-typedef struct
-{
-    VLC_COMMON_MEMBERS
-    update_t *p_update;
-    void (*pf_callback)( void *, bool );
-    void *p_data;
-} update_check_thread_t;
-
-void update_CheckReal( update_check_thread_t *p_uct );
+static void* update_CheckReal( vlc_object_t *p_this );
 
 /**
  * Check for updates
@@ -1114,15 +1367,13 @@ void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void
 {
     assert( p_update );
 
-    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;
-    }
+    update_check_thread_t *p_uct =
+        vlc_custom_create( p_update->p_libvlc, sizeof( *p_uct ),
+                           VLC_OBJECT_GENERIC, "update check" );
+    if( !p_uct ) return;
 
     p_uct->p_update = p_update;
+    p_update->p_check = p_uct;
     p_uct->pf_callback = pf_callback;
     p_uct->p_data = p_data;
 
@@ -1130,8 +1381,9 @@ void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void
                        VLC_THREAD_PRIORITY_LOW, false );
 }
 
-void update_CheckReal( update_check_thread_t *p_uct )
+void* update_CheckReal( vlc_object_t* p_this )
 {
+    update_check_thread_t *p_uct = (update_check_thread_t *)p_this;
     bool b_ret;
     vlc_mutex_lock( &p_uct->p_update->lock );
 
@@ -1142,7 +1394,10 @@ void update_CheckReal( update_check_thread_t *p_uct )
     if( p_uct->pf_callback )
         (p_uct->pf_callback)( p_uct->p_data, b_ret );
 
+    p_uct->p_update->p_check = NULL;
+
     vlc_object_release( p_uct );
+    return NULL;
 }
 
 /**
@@ -1151,14 +1406,32 @@ void update_CheckReal( update_check_thread_t *p_uct )
  * \param p_update structure
  * \return true if we have to upgrade to the given version to be up to date
  */
+static bool is_strictly_greater( int * a, int * b, int n)
+{
+    if( n <= 0 ) return false;
+    if(a[0] > b[0] ) return true;
+    if(a[0] == b[0] ) return is_strictly_greater( a+1, b+1, n-1 );
+    /* a[0] < b[0] */ return false;
+}
+
 bool update_NeedUpgrade( update_t *p_update )
 {
     assert( p_update );
 
-    return  p_update->release.i_major < *PACKAGE_VERSION_MAJOR - '0' ||
-            p_update->release.i_minor < *PACKAGE_VERSION_MINOR - '0' ||
-            p_update->release.i_revision < *PACKAGE_VERSION_REVISION ||
-            p_update->release.extra < *PACKAGE_VERSION_EXTRA;
+    int current_version[] = {
+        *PACKAGE_VERSION_MAJOR - '0',
+        *PACKAGE_VERSION_MINOR - '0',
+        *PACKAGE_VERSION_REVISION - '0',
+        *PACKAGE_VERSION_EXTRA
+    };
+    int latest_version[] = {
+        p_update->release.i_major,
+        p_update->release.i_minor,
+        p_update->release.i_revision,
+        p_update->release.extra
+    };
+
+    return is_strictly_greater( latest_version, current_version, 4 );
 }
 
 /**
@@ -1183,18 +1456,15 @@ static char *size_str( long int l_size )
     return i_retval == -1 ? NULL : psz_tmp;
 }
 
-
-/**
- * Struct to launch the download in a thread
- */
-typedef struct
+void update_WaitDownload( update_t *p_update )
 {
-    VLC_COMMON_MEMBERS
-    update_t *p_update;
-    char *psz_destdir;
-} update_download_thread_t;
+    if(p_update->p_download)
+        vlc_thread_join( p_update->p_download );
+    vlc_object_release( p_update->p_download );
+    p_update->p_download = NULL;
+}
 
-void update_DownloadReal( update_download_thread_t *p_udt );
+static void* update_DownloadReal( vlc_object_t *p_this );
 
 /**
  * Download the file given in the update_t
@@ -1203,27 +1473,27 @@ void update_DownloadReal( update_download_thread_t *p_udt );
  * \param dir to store the download file
  * \return nothing
  */
-void update_Download( update_t *p_update, char *psz_destdir )
+void update_Download( update_t *p_update, const char *psz_destdir )
 {
     assert( p_update );
 
-    update_download_thread_t *p_udt = vlc_object_create( p_update->p_libvlc,
-                                        sizeof( update_download_thread_t ) );
+    update_download_thread_t *p_udt =
+        vlc_custom_create( p_update->p_libvlc, sizeof( *p_udt ),
+                           VLC_OBJECT_GENERIC, "update download" );
     if( !p_udt )
-    {
-        msg_Err( p_update->p_libvlc, "out of memory" );
         return;
-    }
 
     p_udt->p_update = p_update;
+    p_update->p_download = p_udt;
     p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
 
     vlc_thread_create( p_udt, "download update", update_DownloadReal,
                        VLC_THREAD_PRIORITY_LOW, false );
 }
 
-void update_DownloadReal( update_download_thread_t *p_udt )
+static void* update_DownloadReal( vlc_object_t *p_this )
 {
+    update_download_thread_t *p_udt = (update_download_thread_t *)p_this;
     int i_progress = 0;
     long int l_size;
     long int l_downloaded = 0;
@@ -1242,6 +1512,8 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     update_t *p_update = p_udt->p_update;
     char *psz_destdir = p_udt->psz_destdir;
 
+    msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url );
+
     /* Open the stream */
     p_stream = stream_UrlNew( p_udt, p_update->release.psz_url );
     if( !p_stream )
@@ -1274,7 +1546,12 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     /* Create a buffer and fill it with the downloaded file */
     p_buffer = (void *)malloc( 1 << 10 );
     if( !p_buffer )
+    {
+        msg_Err( p_udt, "Can't malloc (1 << 10) bytes! download cancelled." );
         goto end;
+    }
+
+    msg_Dbg( p_udt, "Downloading Stream '%s'", p_update->release.psz_url );
 
     psz_size = size_str( l_size );
     if( asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done",
@@ -1284,9 +1561,12 @@ void update_DownloadReal( update_download_thread_t *p_udt )
         free( psz_status );
     }
 
-    while( ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
-                                   !intf_ProgressIsCancelled( p_udt, i_progress ) )
+    vlc_object_lock( p_udt );
+    while( vlc_object_alive( p_udt ) &&
+           ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
+           !intf_ProgressIsCancelled( p_udt, i_progress ) )
     {
+        vlc_object_unlock( p_udt );
         if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
         {
             msg_Err( p_udt, "Failed to write into %s", psz_destfile );
@@ -1305,36 +1585,41 @@ void update_DownloadReal( update_download_thread_t *p_udt )
             free( psz_status );
         }
         free( psz_downloaded );
+        vlc_object_lock( p_udt );
     }
 
     /* Finish the progress bar or delete the file if the user had canceled */
     fclose( p_file );
     p_file = NULL;
 
-    if( !intf_ProgressIsCancelled( p_udt, i_progress ) )
+    if( vlc_object_alive( p_udt ) &&
+        !intf_ProgressIsCancelled( p_udt, i_progress ) )
     {
+        vlc_object_unlock( p_udt );
         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 );
+            i_progress = 0;
             free( psz_status );
         }
     }
     else
     {
+        vlc_object_unlock( p_udt );
         utf8_unlink( psz_destfile );
         goto end;
     }
 
-    signature_packet_v3_t sign;
+    signature_packet_t sign;
     if( download_signature( VLC_OBJECT( p_udt ), &sign,
             p_update->release.psz_url ) != VLC_SUCCESS )
     {
         utf8_unlink( psz_destfile );
 
-        intf_UserFatal( p_udt, true, _("File can not be verified"),
+        intf_UserFatal( p_udt, true, _("File could not be verified"),
             _("It was not possible to download a cryptographic signature for "
-              "downloaded file \"%s\", and so VLC deleted it."),
+              "the downloaded file \"%s\". Thus, it was deleted."),
             psz_destfile );
         msg_Err( p_udt, "Couldn't download signature of downloaded file" );
         goto end;
@@ -1345,9 +1630,9 @@ void update_DownloadReal( update_download_thread_t *p_udt )
         utf8_unlink( psz_destfile );
         msg_Err( p_udt, "Invalid signature issuer" );
         intf_UserFatal( p_udt, 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."),
+            _("The cryptographic signature for the downloaded file \"%s\" was "
+              "invalid and could not be used to securely verify it. Thus, the "
+              "file was deleted."),
             psz_destfile );
         goto end;
     }
@@ -1357,9 +1642,9 @@ void update_DownloadReal( update_download_thread_t *p_udt )
         utf8_unlink( psz_destfile );
         msg_Err( p_udt, "Invalid signature type" );
         intf_UserFatal( p_udt, 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."),
+            _("The cryptographic signature for the downloaded file \"%s\" was "
+              "invalid and could not be used to securely verify it. Thus, the "
+              "file was deleted."),
             psz_destfile );
         goto end;
     }
@@ -1370,8 +1655,8 @@ void update_DownloadReal( update_download_thread_t *p_udt )
         msg_Err( p_udt, "Unable to hash %s", psz_destfile );
         utf8_unlink( psz_destfile );
         intf_UserFatal( p_udt, true, _("File not verifiable"),
-            _("It was not possible to securely verify downloaded file \"%s\", "
-              "and so VLC deleted it."),
+            _("It was not possible to securely verify the downloaded file"
+              " \"%s\". Thus, it was VLC deleted."),
             psz_destfile );
 
         goto end;
@@ -1382,7 +1667,7 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     {
         utf8_unlink( psz_destfile );
         intf_UserFatal( p_udt, true, _("File corrupted"),
-            _("Downloaded file \"%s\" was corrupted, and so VLC deleted it."),
+            _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
              psz_destfile );
         msg_Err( p_udt, "Bad SHA1 hash for %s", psz_destfile );
         free( p_hash );
@@ -1394,7 +1679,7 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     {
         utf8_unlink( psz_destfile );
         intf_UserFatal( p_udt, true, _("File corrupted"),
-            _("Downloaded file \"%s\" was corrupted, and so VLC deleted it."),
+            _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
              psz_destfile );
         msg_Err( p_udt, "BAD SIGNATURE for %s", psz_destfile );
         free( p_hash );
@@ -1405,6 +1690,10 @@ void update_DownloadReal( update_download_thread_t *p_udt )
     free( p_hash );
 
 end:
+    if( i_progress )
+    {
+        intf_ProgressUpdate( p_udt, i_progress, "Cancelled", 100.0, 0 );
+    }
     if( p_stream )
         stream_Delete( p_stream );
     if( p_file )
@@ -1414,7 +1703,51 @@ end:
     free( p_buffer );
     free( psz_size );
 
-    vlc_object_release( p_udt );
+    return NULL;
+}
+
+update_release_t *update_GetRelease( update_t *p_update )
+{
+    return &p_update->release;
+}
+
+#else
+update_t *__update_New( vlc_object_t *p_this )
+{
+    (void)p_this;
+    return NULL;
 }
 
+void update_Delete( update_t *p_update )
+{
+    (void)p_update;
+}
+
+void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ),
+                   void *p_data )
+{
+    (void)p_update; (void)pf_callback; (void)p_data;
+}
+
+bool update_NeedUpgrade( update_t *p_update )
+{
+    (void)p_update;
+    return false;
+}
+
+void update_WaitDownload( update_t *p_update )
+{
+    (void)p_update;
+}
+
+void update_Download( update_t *p_update, const char *psz_destdir )
+{
+    (void)p_update; (void)psz_destdir;
+}
+
+update_release_t *update_GetRelease( update_t *p_update )
+{
+    (void)p_update;
+    return NULL;
+}
 #endif