1 /*****************************************************************************
2 * update.c: VLC update checking and downloading
3 *****************************************************************************
4 * Copyright © 2005-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8 * Rémi Duraffort <ivoire at via.ecp.fr>
9 Rafaël Carré <funman@videolanorg>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either release 2 of the License, or
14 * (at your option) any later release.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
28 * This file contains functions related to VLC update management
31 /*****************************************************************************
33 *****************************************************************************/
38 #ifdef HAVE_SYS_STAT_H
39 # include <sys/stat.h>
42 #include <vlc_common.h>
43 #include <vlc_update.h>
49 #include <vlc_pgpkey.h>
50 #include <vlc_stream.h>
51 #include <vlc_strings.h>
52 #include <vlc_charset.h>
53 #include <vlc_interface.h>
56 #include <vlc_gcrypt.h>
59 #include "../libvlc.h"
61 /*****************************************************************************
63 *****************************************************************************/
66 * Here is the format of these "status files" :
67 * First line is the last version: "X.Y.Ze" where:
68 * * X is the major number
69 * * Y is the minor number
70 * * Z is the revision number
71 * * e is an OPTIONAL extra letter
72 * * AKA "0.8.6d" or "0.9.0"
73 * Second line is an url of the binary for this last version
74 * Remaining text is a required description of the update
77 #if defined( UNDER_CE )
78 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-ce"
79 #elif defined( WIN32 )
80 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-win-x86"
81 #elif defined( __APPLE__ )
82 # if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
83 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-ppc"
85 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-x86"
87 #elif defined( SYS_BEOS )
88 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-beos-x86"
90 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status"
94 /*****************************************************************************
96 *****************************************************************************/
97 static void EmptyRelease( update_t *p_update );
98 static bool GetUpdateFile( update_t *p_update );
99 static char * size_str( long int l_size );
102 /*****************************************************************************
104 *****************************************************************************/
106 #define packet_type( c ) ( ( c & 0x3c ) >> 2 ) /* 0x3C = 00111100 */
107 #define packet_header_len( c ) ( ( c & 0x03 ) + 1 ) /* number of bytes in a packet header */
109 static inline int scalar_number( uint8_t *p, int header_len )
111 assert( header_len == 1 || header_len == 2 || header_len == 4 );
113 if( header_len == 1 )
115 else if( header_len == 2 )
116 return( (p[0] << 8) + p[1] );
117 else if( header_len == 4 )
118 return( (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3] );
120 abort(); /* to shut up GCC warning */
123 /* number of data bytes in a MPI */
124 #define mpi_len( mpi ) ( ( scalar_number( mpi, 2 ) + 7 ) / 8 )
127 * fill a public_key_packet_t structure from public key packet data
128 * verify that it is a version 4 public key packet, using DSA
130 static int parse_public_key_packet( public_key_packet_t *p_key, uint8_t *p_buf,
131 size_t i_packet_len )
134 if( i_packet_len > 418 || i_packet_len < 6 )
139 p_key->version = *p_buf++; i_read++;
140 if( p_key->version != 4 )
143 /* XXX: warn when timestamp is > date ? */
144 memcpy( p_key->timestamp, p_buf, 4 ); p_buf += 4; i_read += 4;
146 p_key->algo = *p_buf++; i_read++;
147 if( p_key->algo != PUBLIC_KEY_ALGO_DSA )
151 if( i_read + 2 > i_packet_len )
154 int i_p_len = mpi_len( p_buf );
156 if( i_p_len > 128 || i_read + 2 + i_p_len > i_packet_len )
159 memcpy( p_key->p, p_buf, 2+i_p_len );
160 p_buf += 2+i_p_len; i_read += 2+i_p_len;
163 if( i_read + 2 > i_packet_len )
166 int i_q_len = mpi_len( p_buf );
168 if( i_q_len > 20 || i_read+2+i_q_len > i_packet_len )
171 memcpy( p_key->q, p_buf, 2+i_q_len );
172 p_buf += 2+i_q_len; i_read += 2+i_q_len;
175 if( i_read + 2 > i_packet_len )
178 int i_g_len = mpi_len( p_buf );
180 if( i_g_len > 128 || i_read+2+i_g_len > i_packet_len )
183 memcpy( p_key->g, p_buf, 2+i_g_len );
184 p_buf += 2+i_g_len; i_read += 2+i_g_len;
187 if( i_read + 2 > i_packet_len )
190 int i_y_len = mpi_len( p_buf );
193 if( i_y_len > 128 || i_read+2+i_y_len > i_packet_len )
196 memcpy( p_key->y, p_buf, 2+i_y_len );
199 if( i_read != i_packet_len ) /* some extra data eh ? */
205 static size_t parse_signature_v3_packet( signature_packet_t *p_sig,
206 uint8_t *p_buf, size_t i_sig_len )
208 size_t i_read = 1; /* we already read the version byte */
210 if( i_sig_len < 19 ) /* signature is at least 19 bytes + the 2 MPIs */
213 p_sig->specific.v3.hashed_data_len = *p_buf++; i_read++;
214 if( p_sig->specific.v3.hashed_data_len != 5 )
217 p_sig->type = *p_buf++; i_read++;
219 memcpy( p_sig->specific.v3.timestamp, p_buf, 4 );
220 p_buf += 4; i_read += 4;
222 memcpy( p_sig->issuer_longid, p_buf, 8 );
223 p_buf += 8; i_read += 8;
225 p_sig->public_key_algo = *p_buf++; i_read++;
227 p_sig->digest_algo = *p_buf++; i_read++;
229 p_sig->hash_verification[0] = *p_buf++; i_read++;
230 p_sig->hash_verification[1] = *p_buf++; i_read++;
232 assert( i_read == 19 );
238 * fill a signature_packet_v4_t from signature packet data
239 * verify that it was used with a DSA public key, using SHA-1 digest
241 static size_t parse_signature_v4_packet( signature_packet_t *p_sig,
242 uint8_t *p_buf, size_t i_sig_len )
244 size_t i_read = 1; /* we already read the version byte */
246 if( i_sig_len < 10 ) /* signature is at least 10 bytes + the 2 MPIs */
249 p_sig->type = *p_buf++; i_read++;
251 p_sig->public_key_algo = *p_buf++; i_read++;
253 p_sig->digest_algo = *p_buf++; i_read++;
255 memcpy( p_sig->specific.v4.hashed_data_len, p_buf, 2 );
256 p_buf += 2; i_read += 2;
258 size_t i_hashed_data_len =
259 scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
260 i_read += i_hashed_data_len;
261 if( i_read + 4 > i_sig_len )
264 p_sig->specific.v4.hashed_data = (uint8_t*) malloc( i_hashed_data_len );
265 if( !p_sig->specific.v4.hashed_data )
267 memcpy( p_sig->specific.v4.hashed_data, p_buf, i_hashed_data_len );
268 p_buf += i_hashed_data_len;
270 memcpy( p_sig->specific.v4.unhashed_data_len, p_buf, 2 );
271 p_buf += 2; i_read += 2;
273 size_t i_unhashed_data_len =
274 scalar_number( p_sig->specific.v4.unhashed_data_len, 2 );
275 i_read += i_unhashed_data_len;
276 if( i_read + 2 > i_sig_len )
279 p_sig->specific.v4.unhashed_data = (uint8_t*) malloc( i_unhashed_data_len );
280 if( !p_sig->specific.v4.unhashed_data )
283 memcpy( p_sig->specific.v4.unhashed_data, p_buf, i_unhashed_data_len );
284 p_buf += i_unhashed_data_len;
286 memcpy( p_sig->hash_verification, p_buf, 2 );
287 p_buf += 2; i_read += 2;
289 uint8_t *p, *max_pos;
290 p = p_sig->specific.v4.unhashed_data;
291 max_pos = p + scalar_number( p_sig->specific.v4.unhashed_data_len, 2 );
298 size_t i_subpacket_len;
301 if( p + 1 > max_pos )
303 i_subpacket_len = *p++;
307 if( p + 2 > max_pos )
309 i_subpacket_len = (*p++ - 192) << 8;
310 i_subpacket_len += *p++ + 192;
314 if( p + 4 > max_pos )
316 i_subpacket_len = *++p << 24;
317 i_subpacket_len += *++p << 16;
318 i_subpacket_len += *++p << 8;
319 i_subpacket_len += *++p;
322 if( *p == ISSUER_SUBPACKET )
324 if( p + 9 > max_pos )
327 memcpy( &p_sig->issuer_longid, p+1, 8 );
332 p += i_subpacket_len;
336 static int parse_signature_packet( signature_packet_t *p_sig,
337 uint8_t *p_buf, size_t i_sig_len )
339 if( !i_sig_len ) /* 1st sanity check, we need at least the version */
342 p_sig->version = *p_buf++;
345 switch( p_sig->version )
348 i_read = parse_signature_v3_packet( p_sig, p_buf, i_sig_len );
351 p_sig->specific.v4.hashed_data = NULL;
352 p_sig->specific.v4.unhashed_data = NULL;
353 i_read = parse_signature_v4_packet( p_sig, p_buf, i_sig_len );
359 if( i_read == 0 ) /* signature packet parsing has failed */
362 if( p_sig->public_key_algo != PUBLIC_KEY_ALGO_DSA )
365 if( p_sig->digest_algo != DIGEST_ALGO_SHA1 )
368 switch( p_sig->type )
370 case BINARY_SIGNATURE:
372 case GENERIC_KEY_SIGNATURE:
373 case PERSONA_KEY_SIGNATURE:
374 case CASUAL_KEY_SIGNATURE:
375 case POSITIVE_KEY_SIGNATURE:
381 p_buf--; /* rewind to the version byte */
384 if( i_read + 2 > i_sig_len )
387 size_t i_r_len = mpi_len( p_buf ); i_read += 2;
388 if( i_read + i_r_len > i_sig_len || i_r_len > 20 )
391 memcpy( p_sig->r, p_buf, 2 + i_r_len );
392 p_buf += 2 + i_r_len;
395 if( i_read + 2 > i_sig_len )
398 size_t i_s_len = mpi_len( p_buf ); i_read += 2;
399 if( i_read + i_s_len > i_sig_len || i_s_len > 20 )
402 memcpy( p_sig->s, p_buf, 2 + i_s_len );
403 p_buf += 2 + i_s_len;
406 assert( i_read == i_sig_len );
407 if( i_read < i_sig_len ) /* some extra data, hm ? */
414 if( p_sig->version == 4 )
416 free( p_sig->specific.v4.hashed_data );
417 free( p_sig->specific.v4.unhashed_data );
424 * crc_octets() was lamely copied from rfc 2440
425 * Copyright (C) The Internet Society (1998). All Rights Reserved.
427 #define CRC24_INIT 0xB704CEL
428 #define CRC24_POLY 0x1864CFBL
430 static long crc_octets( uint8_t *octets, size_t len )
432 long crc = CRC24_INIT;
436 crc ^= (*octets++) << 16;
437 for (i = 0; i < 8; i++)
444 return crc & 0xFFFFFFL;
448 * Transform an armored document in binary format
449 * Used on public keys and signatures
451 static int pgp_unarmor( char *p_ibuf, size_t i_ibuf_len,
452 uint8_t *p_obuf, size_t i_obuf_len )
454 char *p_ipos = p_ibuf;
455 uint8_t *p_opos = p_obuf;
457 int i_header_skipped = 0;
459 while( !i_end && p_ipos < p_ibuf + i_ibuf_len && *p_ipos != '=' )
461 if( *p_ipos == '\r' || *p_ipos == '\n' )
467 size_t i_line_len = strcspn( p_ipos, "\r\n" );
468 if( i_line_len == 0 )
471 if( !i_header_skipped )
473 if( !strncmp( p_ipos, "-----BEGIN PGP", 14 ) )
474 i_header_skipped = 1;
476 p_ipos += i_line_len + 1;
480 if( !strncmp( p_ipos, "Version:", 8 ) )
482 p_ipos += i_line_len + 1;
486 if( p_ipos[i_line_len - 1] == '=' )
489 p_ipos[i_line_len - 1] = '\0';
492 p_ipos[i_line_len] = '\0';
494 p_opos += vlc_b64_decode_binary_to_buffer( p_opos,
495 p_obuf - p_opos + i_obuf_len, p_ipos );
496 p_ipos += i_line_len + 1;
499 /* XXX: the CRC is OPTIONAL, really require it ? */
500 if( p_ipos + 5 > p_ibuf + i_ibuf_len || *p_ipos++ != '=' )
504 if( vlc_b64_decode_binary_to_buffer( p_crc, 3, p_ipos ) != 3 )
507 long l_crc = crc_octets( p_obuf, p_opos - p_obuf );
508 long l_crc2 = ( 0 << 24 ) + ( p_crc[0] << 16 ) + ( p_crc[1] << 8 ) + p_crc[2];
510 return l_crc2 == l_crc ? p_opos - p_obuf : 0;
514 * Download the signature associated to a document or a binary file.
515 * We're given the file's url, we just append ".asc" to it and download
517 static int download_signature( vlc_object_t *p_this,
518 signature_packet_t *p_sig,
519 const char *psz_url )
521 char *psz_sig = (char*) malloc( strlen( psz_url ) + 4 + 1 ); /* ".asc" + \0 */
525 strcpy( psz_sig, psz_url );
526 strcat( psz_sig, ".asc" );
528 stream_t *p_stream = stream_UrlNew( p_this, psz_sig );
534 int64_t i_size = stream_Size( p_stream );
536 msg_Dbg( p_this, "Downloading signature (%"PRId64" bytes)", i_size );
537 uint8_t *p_buf = (uint8_t*)malloc( i_size );
540 stream_Delete( p_stream );
544 int i_read = stream_Read( p_stream, p_buf, (int)i_size );
546 stream_Delete( p_stream );
548 if( i_read != (int)i_size )
551 "Couldn't download full signature (only %d bytes)", i_read );
556 if( (uint8_t)*p_buf < 0x80 ) /* ASCII */
558 msg_Dbg( p_this, "Unarmoring signature" );
560 uint8_t* p_unarmored = (uint8_t*) malloc( ( i_size * 3 ) / 4 + 1 );
567 int i_bytes = pgp_unarmor( (char*)p_buf, i_size, p_unarmored, i_size );
576 msg_Dbg( p_this, "Unarmoring failed : corrupted signature ?" );
581 if( packet_type( *p_buf ) != SIGNATURE_PACKET )
584 msg_Dbg( p_this, "Not a signature: %d", *p_buf );
588 size_t i_header_len = packet_header_len( *p_buf );
589 if( ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) ||
590 i_header_len + 1 > (size_t)i_size )
593 msg_Dbg( p_this, "Invalid signature packet header" );
597 size_t i_len = scalar_number( p_buf+1, i_header_len );
598 if( i_len + i_header_len + 1 != (size_t)i_size )
601 msg_Dbg( p_this, "Invalid signature packet" );
605 int i_ret = parse_signature_packet( p_sig, p_buf+1+i_header_len, i_len );
607 if( i_ret != VLC_SUCCESS )
609 msg_Dbg( p_this, "Couldn't parse signature" );
613 if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE )
615 msg_Dbg( p_this, "Invalid signature type: %d", p_sig->type );
616 if( p_sig->version == 4 )
618 free( p_sig->specific.v4.hashed_data );
619 free( p_sig->specific.v4.unhashed_data );
628 * Verify an OpenPGP signature made on some SHA-1 hash, with some DSA public key
630 static int verify_signature( uint8_t *p_r, uint8_t *p_s,
631 public_key_packet_t *p_key, uint8_t *p_hash )
633 /* the data to be verified (a SHA-1 hash) */
634 const char *hash_sexp_s = "(data(flags raw)(value %m))";
636 const char *key_sexp_s = "(public-key(dsa(p %m)(q %m)(g %m)(y %m)))";
638 const char *sig_sexp_s = "(sig-val(dsa(r %m )(s %m )))";
641 gcry_mpi_t p, q, g, y, r, s, hash;
642 p = q = g = y = r = s = hash = NULL;
643 gcry_sexp_t key_sexp, hash_sexp, sig_sexp;
644 key_sexp = hash_sexp = sig_sexp = NULL;
646 int i_p_len = mpi_len( p_key->p );
647 int i_q_len = mpi_len( p_key->q );
648 int i_g_len = mpi_len( p_key->g );
649 int i_y_len = mpi_len( p_key->y );
650 if( gcry_mpi_scan( &p, GCRYMPI_FMT_USG, p_key->p + 2, i_p_len, NULL ) ||
651 gcry_mpi_scan( &q, GCRYMPI_FMT_USG, p_key->q + 2, i_q_len, NULL ) ||
652 gcry_mpi_scan( &g, GCRYMPI_FMT_USG, p_key->g + 2, i_g_len, NULL ) ||
653 gcry_mpi_scan( &y, GCRYMPI_FMT_USG, p_key->y + 2, i_y_len, NULL ) ||
654 gcry_sexp_build( &key_sexp, &erroff, key_sexp_s, p, q, g, y ) )
657 int i_r_len = mpi_len( p_r );
658 int i_s_len = mpi_len( p_s );
659 if( gcry_mpi_scan( &r, GCRYMPI_FMT_USG, p_r + 2, i_r_len, NULL ) ||
660 gcry_mpi_scan( &s, GCRYMPI_FMT_USG, p_s + 2, i_s_len, NULL ) ||
661 gcry_sexp_build( &sig_sexp, &erroff, sig_sexp_s, r, s ) )
665 if( gcry_mpi_scan( &hash, GCRYMPI_FMT_USG, p_hash, i_hash_len, NULL ) ||
666 gcry_sexp_build( &hash_sexp, &erroff, hash_sexp_s, hash ) )
669 if( gcry_pk_verify( sig_sexp, hash_sexp, key_sexp ) )
675 if( p ) gcry_mpi_release( p );
676 if( q ) gcry_mpi_release( q );
677 if( g ) gcry_mpi_release( g );
678 if( y ) gcry_mpi_release( y );
679 if( r ) gcry_mpi_release( r );
680 if( s ) gcry_mpi_release( s );
681 if( hash ) gcry_mpi_release( hash );
682 if( key_sexp ) gcry_sexp_release( key_sexp );
683 if( sig_sexp ) gcry_sexp_release( sig_sexp );
684 if( hash_sexp ) gcry_sexp_release( hash_sexp );
689 * fill a public_key_t with public key data, including:
690 * * public key packet
691 * * signature packet issued by key which long id is p_sig_issuer
694 static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len,
695 public_key_t *p_key, const uint8_t *p_sig_issuer )
697 uint8_t *pos = (uint8_t*) p_key_data;
698 uint8_t *max_pos = pos + i_key_len;
701 #define PUBLIC_KEY_FOUND 0x01
702 #define USER_ID_FOUND 0x02
703 #define SIGNATURE_FOUND 0X04
705 uint8_t *p_key_unarmored = NULL;
707 p_key->psz_username = NULL;
708 p_key->sig.specific.v4.hashed_data = NULL;
709 p_key->sig.specific.v4.unhashed_data = NULL;
711 if( !( *pos & 0x80 ) )
712 { /* first byte is ASCII, unarmoring */
713 p_key_unarmored = (uint8_t*)malloc( i_key_len );
714 if( !p_key_unarmored )
716 int i_len = pgp_unarmor( (char*)p_key_data, i_key_len,
717 p_key_unarmored, i_key_len );
722 pos = p_key_unarmored;
723 max_pos = pos + i_len;
726 while( pos < max_pos )
728 if( !(*pos & 0x80) || *pos & 0x40 )
731 int i_type = packet_type( *pos );
733 int i_header_len = packet_header_len( *pos++ );
734 if( pos + i_header_len > max_pos ||
735 ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) )
738 int i_packet_len = scalar_number( pos, i_header_len );
741 if( pos + i_packet_len > max_pos )
746 case PUBLIC_KEY_PACKET:
747 i_status |= PUBLIC_KEY_FOUND;
748 if( parse_public_key_packet( &p_key->key, pos, i_packet_len ) != VLC_SUCCESS )
752 case SIGNATURE_PACKET: /* we accept only v4 signatures here */
753 if( i_status & SIGNATURE_FOUND || !p_sig_issuer )
755 int i_ret = parse_signature_packet( &p_key->sig, pos,
757 if( i_ret == VLC_SUCCESS )
759 if( p_key->sig.version != 4 )
761 if( memcmp( p_key->sig.issuer_longid, p_sig_issuer, 8 ) )
763 free( p_key->sig.specific.v4.hashed_data );
764 free( p_key->sig.specific.v4.unhashed_data );
765 p_key->sig.specific.v4.hashed_data = NULL;
766 p_key->sig.specific.v4.unhashed_data = NULL;
769 i_status |= SIGNATURE_FOUND;
774 if( p_key->psz_username ) /* save only the first User ID */
776 i_status |= USER_ID_FOUND;
777 p_key->psz_username = (uint8_t*)malloc( i_packet_len + 1);
778 if( !p_key->psz_username )
781 memcpy( p_key->psz_username, pos, i_packet_len );
782 p_key->psz_username[i_packet_len] = '\0';
790 free( p_key_unarmored );
792 if( !( i_status & ( PUBLIC_KEY_FOUND | USER_ID_FOUND ) ) )
795 if( p_sig_issuer && !( i_status & SIGNATURE_FOUND ) )
801 if( p_key->sig.version == 4 )
803 free( p_key->sig.specific.v4.hashed_data );
804 free( p_key->sig.specific.v4.unhashed_data );
806 free( p_key->psz_username );
807 free( p_key_unarmored );
812 * return a sha1 hash of a file
814 static uint8_t *hash_sha1_from_file( const char *psz_file,
815 signature_packet_t *p_sig )
817 if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE )
820 FILE *f = utf8_fopen( psz_file, "r" );
824 uint8_t buffer[4096];
827 if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) )
834 while( ( i_read = fread( buffer, 1, sizeof(buffer), f ) ) > 0 )
835 gcry_md_write( hd, buffer, i_read );
837 if( p_sig->version == 3 )
839 gcry_md_putc( hd, p_sig->type );
840 gcry_md_write( hd, &p_sig->specific.v3.timestamp, 4 );
842 else if( p_sig->version == 4 )
844 gcry_md_putc( hd, p_sig->version );
845 gcry_md_putc( hd, p_sig->type );
846 gcry_md_putc( hd, p_sig->public_key_algo );
847 gcry_md_putc( hd, p_sig->digest_algo );
848 gcry_md_write( hd, p_sig->specific.v4.hashed_data_len, 2 );
849 size_t i_len = scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
850 gcry_md_write( hd, p_sig->specific.v4.hashed_data, i_len );
852 gcry_md_putc( hd, 0x04 );
853 gcry_md_putc( hd, 0xFF );
855 i_len += 6; /* hashed data + 6 bytes header */
857 gcry_md_putc( hd, (i_len >> 24) & 0xff );
858 gcry_md_putc( hd, (i_len >> 16) & 0xff );
859 gcry_md_putc( hd, (i_len >> 8) & 0xff );
860 gcry_md_putc( hd, (i_len) & 0xff );
863 { /* RFC 4880 only tells about versions 3 and 4 */
871 uint8_t *p_tmp = (uint8_t*) gcry_md_read( hd, GCRY_MD_SHA1);
872 uint8_t *p_hash = malloc( 20 );
874 memcpy( p_hash, p_tmp, 20 );
880 * download a public key (the last one) from videolan server, and parse it
882 static public_key_t *download_key( vlc_object_t *p_this,
883 const uint8_t *p_longid, const uint8_t *p_signature_issuer )
886 if( asprintf( &psz_url, "http://download.videolan.org/pub/keys/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X.asc",
887 p_longid[0], p_longid[1], p_longid[2], p_longid[3],
888 p_longid[4], p_longid[5], p_longid[6], p_longid[7] ) == -1 )
891 stream_t *p_stream = stream_UrlNew( p_this, psz_url );
896 int64_t i_size = stream_Size( p_stream );
899 stream_Delete( p_stream );
903 uint8_t *p_buf = (uint8_t*)malloc( i_size );
906 stream_Delete( p_stream );
910 int i_read = stream_Read( p_stream, p_buf, (int)i_size );
911 stream_Delete( p_stream );
913 if( i_read != (int)i_size )
915 msg_Dbg( p_this, "Couldn't read full GPG key" );
920 public_key_t *p_pkey = (public_key_t*) malloc( sizeof( public_key_t ) );
927 memcpy( p_pkey->longid, p_longid, 8 );
929 int i_error = parse_public_key( p_buf, i_read, p_pkey, p_signature_issuer );
932 if( i_error != VLC_SUCCESS )
934 msg_Dbg( p_this, "Couldn't parse GPG key" );
943 * Generate a SHA1 hash on a public key, to verify a signature made on that hash
944 * Note that we need the signature (v4) to compute the hash
946 static uint8_t *key_sign_hash( public_key_t *p_pkey )
948 if( p_pkey->sig.version != 4 )
951 if( p_pkey->sig.type < GENERIC_KEY_SIGNATURE ||
952 p_pkey->sig.type > POSITIVE_KEY_SIGNATURE )
955 gcry_error_t error = 0;
958 error = gcry_md_open( &hd, GCRY_MD_SHA1, 0 );
962 gcry_md_putc( hd, 0x99 );
964 size_t i_p_len = mpi_len( p_pkey->key.p );
965 size_t i_g_len = mpi_len( p_pkey->key.g );
966 size_t i_q_len = mpi_len( p_pkey->key.q );
967 size_t i_y_len = mpi_len( p_pkey->key.y );
969 size_t i_size = 6 + 2*4 + i_p_len + i_g_len + i_q_len + i_y_len;
971 gcry_md_putc( hd, (i_size >> 8) & 0xff );
972 gcry_md_putc( hd, i_size & 0xff );
974 gcry_md_putc( hd, p_pkey->key.version );
975 gcry_md_write( hd, p_pkey->key.timestamp, 4 );
976 gcry_md_putc( hd, p_pkey->key.algo );
978 gcry_md_write( hd, (uint8_t*)&p_pkey->key.p, 2 );
979 gcry_md_write( hd, (uint8_t*)&p_pkey->key.p + 2, i_p_len );
981 gcry_md_write( hd, (uint8_t*)&p_pkey->key.q, 2 );
982 gcry_md_write( hd, (uint8_t*)&p_pkey->key.q + 2, i_q_len );
984 gcry_md_write( hd, (uint8_t*)&p_pkey->key.g, 2 );
985 gcry_md_write( hd, (uint8_t*)&p_pkey->key.g + 2, i_g_len );
987 gcry_md_write( hd, (uint8_t*)&p_pkey->key.y, 2 );
988 gcry_md_write( hd, (uint8_t*)&p_pkey->key.y + 2, i_y_len );
990 gcry_md_putc( hd, 0xb4 );
992 size_t i_len = strlen((char*)p_pkey->psz_username);
994 gcry_md_putc( hd, (i_len >> 24) & 0xff );
995 gcry_md_putc( hd, (i_len >> 16) & 0xff );
996 gcry_md_putc( hd, (i_len >> 8) & 0xff );
997 gcry_md_putc( hd, (i_len) & 0xff );
999 gcry_md_write( hd, p_pkey->psz_username, i_len );
1001 size_t i_hashed_data_len =
1002 scalar_number( p_pkey->sig.specific.v4.hashed_data_len, 2 );
1004 gcry_md_putc( hd, p_pkey->sig.version );
1005 gcry_md_putc( hd, p_pkey->sig.type );
1006 gcry_md_putc( hd, p_pkey->sig.public_key_algo );
1007 gcry_md_putc( hd, p_pkey->sig.digest_algo );
1008 gcry_md_write( hd, p_pkey->sig.specific.v4.hashed_data_len, 2 );
1009 gcry_md_write( hd, p_pkey->sig.specific.v4.hashed_data, i_hashed_data_len );
1011 gcry_md_putc( hd, 0x04 );
1012 gcry_md_putc( hd, 0xff );
1014 i_hashed_data_len += 6; /* hashed data + 6 bytes header */
1016 gcry_md_putc( hd, (i_hashed_data_len >> 24) & 0xff );
1017 gcry_md_putc( hd, (i_hashed_data_len >> 16) & 0xff );
1018 gcry_md_putc( hd, (i_hashed_data_len >> 8) & 0xff );
1019 gcry_md_putc( hd, (i_hashed_data_len) & 0xff );
1021 gcry_md_final( hd );
1023 uint8_t *p_tmp = gcry_md_read( hd, GCRY_MD_SHA1 );
1026 p_tmp[0] != p_pkey->sig.hash_verification[0] ||
1027 p_tmp[1] != p_pkey->sig.hash_verification[1] )
1029 gcry_md_close( hd );
1033 uint8_t *p_hash = malloc( 20 );
1035 memcpy( p_hash, p_tmp, 20 );
1036 gcry_md_close( hd );
1041 /*****************************************************************************
1042 * Update_t functions
1043 *****************************************************************************/
1046 * Create a new update VLC struct
1048 * \param p_this the calling vlc_object
1049 * \return pointer to new update_t or NULL
1051 update_t *__update_New( vlc_object_t *p_this )
1056 p_update = (update_t *)malloc( sizeof( update_t ) );
1057 if( !p_update ) return NULL;
1059 vlc_mutex_init( &p_update->lock );
1061 p_update->p_libvlc = p_this->p_libvlc;
1063 p_update->release.psz_url = NULL;
1064 p_update->release.psz_desc = NULL;
1066 p_update->p_download = NULL;
1067 p_update->p_check = NULL;
1069 p_update->p_pkey = NULL;
1076 * Delete an update_t struct
1078 * \param p_update update_t* pointer
1081 void update_Delete( update_t *p_update )
1085 if( p_update->p_check )
1087 assert( !p_update->p_download );
1088 vlc_object_kill( p_update->p_check );
1089 vlc_thread_join( p_update->p_check );
1090 vlc_object_release( p_update->p_check );
1092 else if( p_update->p_download )
1094 vlc_object_kill( p_update->p_download );
1095 vlc_thread_join( p_update->p_download );
1096 vlc_object_release( p_update->p_download );
1099 vlc_mutex_destroy( &p_update->lock );
1101 free( p_update->release.psz_url );
1102 free( p_update->release.psz_desc );
1103 free( p_update->p_pkey );
1109 * Empty the release struct
1111 * \param p_update update_t* pointer
1114 static void EmptyRelease( update_t *p_update )
1116 p_update->release.i_major = 0;
1117 p_update->release.i_minor = 0;
1118 p_update->release.i_revision = 0;
1120 FREENULL( p_update->release.psz_url );
1121 FREENULL( p_update->release.psz_desc );
1125 * Get the update file and parse it
1126 * p_update has to be locked when calling this function
1128 * \param p_update pointer to update struct
1129 * \return true if the update is valid and authenticated
1131 static bool GetUpdateFile( update_t *p_update )
1133 stream_t *p_stream = NULL;
1137 unsigned char extra;
1138 char *psz_version_line = NULL;
1140 p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
1143 msg_Err( p_update->p_libvlc, "Failed to open %s for reading",
1144 UPDATE_VLC_STATUS_URL );
1148 /* Start reading the status file */
1149 if( !( psz_version_line = stream_ReadLine( p_stream ) ) )
1151 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : missing version",
1152 UPDATE_VLC_STATUS_URL );
1156 /* first line : version number */
1157 p_update->release.extra = 0;
1158 switch( sscanf( psz_version_line, "%i.%i.%i%c",
1159 &i_major, &i_minor, &i_revision, &extra ) )
1162 p_update->release.extra = extra;
1164 p_update->release.i_major = i_major;
1165 p_update->release.i_minor = i_minor;
1166 p_update->release.i_revision = i_revision;
1169 msg_Err( p_update->p_libvlc, "Update version false formated" );
1173 /* second line : URL */
1174 if( !( p_update->release.psz_url = stream_ReadLine( p_stream ) ) )
1176 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : URL missing",
1177 UPDATE_VLC_STATUS_URL );
1181 /* Remaining data : description */
1182 int i_read = stream_Size( p_stream ) - stream_Tell( p_stream );
1185 msg_Err( p_update->p_libvlc,
1186 "Update file %s is corrupted: description missing",
1187 UPDATE_VLC_STATUS_URL );
1191 p_update->release.psz_desc = (char*) malloc( i_read + 1 );
1192 if( !p_update->release.psz_desc )
1195 if( stream_Read( p_stream, p_update->release.psz_desc, i_read ) != i_read )
1197 msg_Err( p_update->p_libvlc, "Couldn't download update file %s",
1198 UPDATE_VLC_STATUS_URL );
1201 p_update->release.psz_desc[i_read] = '\0';
1203 stream_Delete( p_stream );
1206 /* Now that we know the status is valid, we must download its signature
1207 * to authenticate it */
1208 signature_packet_t sign;
1209 if( download_signature( VLC_OBJECT( p_update->p_libvlc ), &sign,
1210 UPDATE_VLC_STATUS_URL ) != VLC_SUCCESS )
1212 msg_Err( p_update->p_libvlc, "Couldn't download signature of status file" );
1216 if( sign.type != BINARY_SIGNATURE && sign.type != TEXT_SIGNATURE )
1218 msg_Err( p_update->p_libvlc, "Invalid signature type" );
1222 p_update->p_pkey = (public_key_t*)malloc( sizeof( public_key_t ) );
1223 if( !p_update->p_pkey )
1226 if( parse_public_key( videolan_public_key, sizeof( videolan_public_key ),
1227 p_update->p_pkey, NULL ) != VLC_SUCCESS )
1229 msg_Err( p_update->p_libvlc, "Couldn't parse embedded public key, something went really wrong..." );
1230 FREENULL( p_update->p_pkey );
1234 memcpy( p_update->p_pkey->longid, videolan_public_key_longid, 8 );
1236 if( memcmp( sign.issuer_longid, p_update->p_pkey->longid , 8 ) != 0 )
1238 msg_Dbg( p_update->p_libvlc, "Need to download the GPG key" );
1239 public_key_t *p_new_pkey = download_key(
1240 VLC_OBJECT(p_update->p_libvlc),
1241 sign.issuer_longid, videolan_public_key_longid );
1244 msg_Err( p_update->p_libvlc, "Couldn't download GPG key" );
1245 FREENULL( p_update->p_pkey );
1249 uint8_t *p_hash = key_sign_hash( p_new_pkey );
1252 msg_Err( p_update->p_libvlc, "Failed to hash signature" );
1254 FREENULL( p_update->p_pkey );
1258 if( verify_signature( p_new_pkey->sig.r, p_new_pkey->sig.s,
1259 &p_update->p_pkey->key, p_hash ) == VLC_SUCCESS )
1262 msg_Info( p_update->p_libvlc, "Key authenticated" );
1263 free( p_update->p_pkey );
1264 p_update->p_pkey = p_new_pkey;
1269 msg_Err( p_update->p_libvlc, "Key signature invalid !\n" );
1275 if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) )
1278 gcry_md_write( hd, psz_version_line, strlen( psz_version_line ) );
1279 FREENULL( psz_version_line );
1280 if( sign.type == TEXT_SIGNATURE )
1281 gcry_md_putc( hd, '\r' );
1282 gcry_md_putc( hd, '\n' );
1283 gcry_md_write( hd, p_update->release.psz_url,
1284 strlen( p_update->release.psz_url ) );
1285 if( sign.type == TEXT_SIGNATURE )
1286 gcry_md_putc( hd, '\r' );
1287 gcry_md_putc( hd, '\n' );
1289 char *psz_desc = p_update->release.psz_desc;
1292 size_t i_len = strcspn( psz_desc, "\r\n" );
1296 gcry_md_write( hd, psz_desc, i_len );
1297 if( sign.type == TEXT_SIGNATURE )
1298 gcry_md_putc( hd, '\r' );
1299 gcry_md_putc( hd, '\n' );
1302 while( *psz_desc == '\r' || *psz_desc == '\n' )
1306 if( sign.version == 3 )
1308 gcry_md_putc( hd, sign.type );
1309 gcry_md_write( hd, &sign.specific.v3.timestamp, 4 );
1311 else if( sign.version == 4 )
1313 gcry_md_putc( hd, sign.version );
1314 gcry_md_putc( hd, sign.type );
1315 gcry_md_putc( hd, sign.public_key_algo );
1316 gcry_md_putc( hd, sign.digest_algo );
1317 gcry_md_write( hd, sign.specific.v4.hashed_data_len, 2 );
1318 size_t i_len = scalar_number( sign.specific.v4.hashed_data_len, 2 );
1319 gcry_md_write( hd, sign.specific.v4.hashed_data, i_len );
1320 gcry_md_putc( hd, 0x04 );
1321 gcry_md_putc( hd, 0xFF );
1323 i_len += 6; /* hashed data + 6 bytes header */
1325 gcry_md_putc( hd, (i_len >> 24) & 0xff );
1326 gcry_md_putc( hd, (i_len >> 16) & 0xff );
1327 gcry_md_putc( hd, (i_len >> 8) & 0xff );
1328 gcry_md_putc( hd, (i_len) & 0xff );
1331 { /* RFC 4880 only tells about versions 3 and 4 */
1332 msg_Warn( p_update->p_libvlc, "Invalid signature version %d",
1337 gcry_md_final( hd );
1339 uint8_t *p_hash = gcry_md_read( hd, GCRY_MD_SHA1 );
1341 if( p_hash[0] != sign.hash_verification[0] ||
1342 p_hash[1] != sign.hash_verification[1] )
1344 msg_Warn( p_update->p_libvlc, "Bad SHA1 hash for status file" );
1348 if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
1351 msg_Err( p_update->p_libvlc, "BAD SIGNATURE for status file" );
1356 msg_Info( p_update->p_libvlc, "Status file authenticated" );
1357 gcry_md_close( hd );
1362 gcry_md_close( hd );
1365 stream_Delete( p_stream );
1366 free( psz_version_line );
1370 static void* update_CheckReal( vlc_object_t *p_this );
1375 * \param p_update pointer to update struct
1376 * \param pf_callback pointer to a function to call when the update_check is finished
1377 * \param p_data pointer to some datas to give to the callback
1380 void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void *p_data )
1384 update_check_thread_t *p_uct =
1385 vlc_custom_create( p_update->p_libvlc, sizeof( *p_uct ),
1386 VLC_OBJECT_GENERIC, "update check" );
1387 if( !p_uct ) return;
1389 p_uct->p_update = p_update;
1390 p_update->p_check = p_uct;
1391 p_uct->pf_callback = pf_callback;
1392 p_uct->p_data = p_data;
1394 vlc_thread_create( p_uct, "check for update", update_CheckReal,
1395 VLC_THREAD_PRIORITY_LOW, false );
1398 void* update_CheckReal( vlc_object_t* p_this )
1400 update_check_thread_t *p_uct = (update_check_thread_t *)p_this;
1404 canc = vlc_savecancel ();
1405 vlc_mutex_lock( &p_uct->p_update->lock );
1407 EmptyRelease( p_uct->p_update );
1408 b_ret = GetUpdateFile( p_uct->p_update );
1409 vlc_mutex_unlock( &p_uct->p_update->lock );
1411 if( p_uct->pf_callback )
1412 (p_uct->pf_callback)( p_uct->p_data, b_ret );
1414 vlc_restorecancel (canc);
1419 * Compare a given release's version number to the current VLC's one
1421 * \param p_update structure
1422 * \return true if we have to upgrade to the given version to be up to date
1424 static bool is_strictly_greater( int * a, int * b, int n)
1426 if( n <= 0 ) return false;
1427 if(a[0] > b[0] ) return true;
1428 if(a[0] == b[0] ) return is_strictly_greater( a+1, b+1, n-1 );
1429 /* a[0] < b[0] */ return false;
1432 bool update_NeedUpgrade( update_t *p_update )
1436 int current_version[] = {
1437 *PACKAGE_VERSION_MAJOR - '0',
1438 *PACKAGE_VERSION_MINOR - '0',
1439 *PACKAGE_VERSION_REVISION - '0',
1440 *PACKAGE_VERSION_EXTRA
1442 int latest_version[] = {
1443 p_update->release.i_major,
1444 p_update->release.i_minor,
1445 p_update->release.i_revision,
1446 p_update->release.extra
1449 return is_strictly_greater( latest_version, current_version, 4 );
1453 * Convert a long int size in bytes to a string
1455 * \param l_size the size in bytes
1456 * \return the size as a string
1458 static char *size_str( long int l_size )
1460 char *psz_tmp = NULL;
1463 i_retval = asprintf( &psz_tmp, _("%.1f GB"), (float)l_size/(1<<30) );
1464 else if( l_size >> 20 )
1465 i_retval = asprintf( &psz_tmp, _("%.1f MB"), (float)l_size/(1<<20) );
1466 else if( l_size >> 10 )
1467 i_retval = asprintf( &psz_tmp, _("%.1f kB"), (float)l_size/(1<<10) );
1469 i_retval = asprintf( &psz_tmp, _("%ld B"), l_size );
1471 return i_retval == -1 ? NULL : psz_tmp;
1474 void update_WaitDownload( update_t *p_update )
1476 if(p_update->p_download)
1477 vlc_thread_join( p_update->p_download );
1478 vlc_object_release( p_update->p_download );
1479 p_update->p_download = NULL;
1482 static void* update_DownloadReal( vlc_object_t *p_this );
1485 * Download the file given in the update_t
1487 * \param p_update structure
1488 * \param destination to store the download file
1489 * This can be an existing dir, a (non)existing target fullpath filename or
1490 * NULL for the current working dir.
1493 void update_Download( update_t *p_update, const char *destination )
1497 update_download_thread_t *p_udt =
1498 vlc_custom_create( p_update->p_libvlc, sizeof( *p_udt ),
1499 VLC_OBJECT_GENERIC, "update download" );
1503 p_udt->p_update = p_update;
1504 p_update->p_download = p_udt;
1505 p_udt->psz_destination = destination ? strdup( destination ) : NULL;
1507 vlc_thread_create( p_udt, "download update", update_DownloadReal,
1508 VLC_THREAD_PRIORITY_LOW, false );
1511 static void* update_DownloadReal( vlc_object_t *p_this )
1513 update_download_thread_t *p_udt = (update_download_thread_t *)p_this;
1516 long int l_downloaded = 0;
1518 char *psz_status = NULL;
1519 char *psz_downloaded = NULL;
1520 char *psz_size = NULL;
1521 char *psz_destfile = NULL;
1522 char *psz_tmpdestfile = NULL;
1524 FILE *p_file = NULL;
1526 stream_t *p_stream = NULL;
1527 void* p_buffer = NULL;
1531 update_t *p_update = p_udt->p_update;
1532 char *psz_destination = p_udt->psz_destination;
1534 msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url );
1535 canc = vlc_savecancel ();
1537 /* Open the stream */
1538 p_stream = stream_UrlNew( p_udt, p_update->release.psz_url );
1541 msg_Err( p_udt, "Failed to open %s for reading", p_update->release.psz_url );
1545 /* Get the stream size */
1546 l_size = stream_Size( p_stream );
1548 /* Get the file name and open it*/
1549 psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' );
1550 if( !psz_tmpdestfile )
1552 msg_Err( p_udt, "The URL %s is badly formated",
1553 p_update->release.psz_url );
1558 if( utf8_stat( psz_destination, &p_stat) == 0 && (p_stat.st_mode & S_IFDIR) )
1560 if( asprintf( &psz_destfile, "%s%c%s", psz_destination, DIR_SEP_CHAR, psz_tmpdestfile ) == -1 )
1563 else if( psz_destination )
1564 psz_destfile = strdup( psz_destination );
1566 psz_destfile = strdup( psz_tmpdestfile );
1568 p_file = utf8_fopen( psz_destfile, "w" );
1571 msg_Err( p_udt, "Failed to open %s for writing", psz_destfile );
1572 intf_UserFatal( p_udt, true, _("Saving file failed"),
1573 _("Failed to open \"%s\" for writing"),
1578 /* Create a buffer and fill it with the downloaded file */
1579 p_buffer = (void *)malloc( 1 << 10 );
1582 msg_Err( p_udt, "Can't malloc (1 << 10) bytes! download cancelled." );
1586 msg_Dbg( p_udt, "Downloading Stream '%s'", p_update->release.psz_url );
1588 psz_size = size_str( l_size );
1589 if( asprintf( &psz_status, _("%s\nDownloading... %s/%s %.1f%% done"),
1590 p_update->release.psz_url, "0.0", psz_size, 0.0 ) != -1 )
1592 i_progress = intf_UserProgress( p_udt, _( "Downloading ..."),
1593 psz_status, 0.0, 0 );
1597 vlc_object_lock( p_udt );
1598 while( vlc_object_alive( p_udt ) &&
1599 ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
1600 !intf_ProgressIsCancelled( p_udt, i_progress ) )
1602 vlc_object_unlock( p_udt );
1603 if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
1605 msg_Err( p_udt, "Failed to write into %s", psz_destfile );
1609 l_downloaded += i_read;
1610 psz_downloaded = size_str( l_downloaded );
1611 f_progress = 100.0*(float)l_downloaded/(float)l_size;
1613 if( asprintf( &psz_status, _( "%s\nDownloading... %s/%s %.1f%% done" ),
1614 p_update->release.psz_url, psz_downloaded, psz_size,
1615 f_progress ) != -1 )
1617 intf_ProgressUpdate( p_udt, i_progress, psz_status, f_progress, 0 );
1620 free( psz_downloaded );
1621 vlc_object_lock( p_udt );
1624 /* Finish the progress bar or delete the file if the user had canceled */
1628 if( vlc_object_alive( p_udt ) &&
1629 !intf_ProgressIsCancelled( p_udt, i_progress ) )
1631 vlc_object_unlock( p_udt );
1632 if( asprintf( &psz_status, _("%s\nDone %s (100.0%%)"),
1633 p_update->release.psz_url, psz_size ) != -1 )
1635 intf_ProgressUpdate( p_udt, i_progress, psz_status, 100.0, 0 );
1642 vlc_object_unlock( p_udt );
1643 utf8_unlink( psz_destfile );
1647 signature_packet_t sign;
1648 if( download_signature( VLC_OBJECT( p_udt ), &sign,
1649 p_update->release.psz_url ) != VLC_SUCCESS )
1651 utf8_unlink( psz_destfile );
1653 intf_UserFatal( p_udt, true, _("File could not be verified"),
1654 _("It was not possible to download a cryptographic signature for "
1655 "the downloaded file \"%s\". Thus, it was deleted."),
1657 msg_Err( p_udt, "Couldn't download signature of downloaded file" );
1661 if( memcmp( sign.issuer_longid, p_update->p_pkey->longid, 8 ) )
1663 utf8_unlink( psz_destfile );
1664 msg_Err( p_udt, "Invalid signature issuer" );
1665 intf_UserFatal( p_udt, true, _("Invalid signature"),
1666 _("The cryptographic signature for the downloaded file \"%s\" was "
1667 "invalid and could not be used to securely verify it. Thus, the "
1668 "file was deleted."),
1673 if( sign.type != BINARY_SIGNATURE )
1675 utf8_unlink( psz_destfile );
1676 msg_Err( p_udt, "Invalid signature type" );
1677 intf_UserFatal( p_udt, true, _("Invalid signature"),
1678 _("The cryptographic signature for the downloaded file \"%s\" was "
1679 "invalid and could not be used to securely verify it. Thus, the "
1680 "file was deleted."),
1685 uint8_t *p_hash = hash_sha1_from_file( psz_destfile, &sign );
1688 msg_Err( p_udt, "Unable to hash %s", psz_destfile );
1689 utf8_unlink( psz_destfile );
1690 intf_UserFatal( p_udt, true, _("File not verifiable"),
1691 _("It was not possible to securely verify the downloaded file"
1692 " \"%s\". Thus, it was deleted."),
1698 if( p_hash[0] != sign.hash_verification[0] ||
1699 p_hash[1] != sign.hash_verification[1] )
1701 utf8_unlink( psz_destfile );
1702 intf_UserFatal( p_udt, true, _("File corrupted"),
1703 _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
1705 msg_Err( p_udt, "Bad SHA1 hash for %s", psz_destfile );
1710 if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
1713 utf8_unlink( psz_destfile );
1714 intf_UserFatal( p_udt, true, _("File corrupted"),
1715 _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
1717 msg_Err( p_udt, "BAD SIGNATURE for %s", psz_destfile );
1722 msg_Info( p_udt, "%s authenticated", psz_destfile );
1728 intf_ProgressUpdate( p_udt, i_progress, _("Cancelled"), 100.0, 0 );
1731 stream_Delete( p_stream );
1734 free( psz_destination );
1735 free( psz_destfile );
1739 p_udt->p_update->p_download = NULL;
1741 vlc_object_release( p_udt );
1742 vlc_restorecancel( canc );
1746 update_release_t *update_GetRelease( update_t *p_update )
1748 return &p_update->release;
1752 update_t *__update_New( vlc_object_t *p_this )
1758 void update_Delete( update_t *p_update )
1763 void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ),
1766 (void)p_update; (void)pf_callback; (void)p_data;
1769 bool update_NeedUpgrade( update_t *p_update )
1775 void update_WaitDownload( update_t *p_update )
1780 void update_Download( update_t *p_update, const char *psz_destdir )
1782 (void)p_update; (void)psz_destdir;
1785 update_release_t *update_GetRelease( update_t *p_update )