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 *****************************************************************************/
39 #include <vlc_common.h>
40 #include <vlc_update.h>
46 #include <vlc_pgpkey.h>
47 #include <vlc_stream.h>
48 #include <vlc_strings.h>
49 #include <vlc_charset.h>
50 #include <vlc_interface.h>
53 #include <vlc_gcrypt.h>
56 #include "../libvlc.h"
58 /*****************************************************************************
60 *****************************************************************************/
63 * Here is the format of these "status files" :
64 * First line is the last version: "X.Y.Ze" where:
65 * * X is the major number
66 * * Y is the minor number
67 * * Z is the revision number
68 * * e is an OPTIONAL extra letter
69 * * AKA "0.8.6d" or "0.9.0"
70 * Second line is an url of the binary for this last version
71 * Remaining text is a required description of the update
74 #if defined( UNDER_CE )
75 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-ce"
76 #elif defined( WIN32 )
77 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-win-x86"
78 #elif defined( __APPLE__ )
79 # if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
80 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-ppc"
82 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-x86"
84 #elif defined( SYS_BEOS )
85 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-beos-x86"
87 # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status"
91 /*****************************************************************************
93 *****************************************************************************/
94 static void EmptyRelease( update_t *p_update );
95 static bool GetUpdateFile( update_t *p_update );
96 static char * size_str( long int l_size );
99 /*****************************************************************************
101 *****************************************************************************/
103 #define packet_type( c ) ( ( c & 0x3c ) >> 2 ) /* 0x3C = 00111100 */
104 #define packet_header_len( c ) ( ( c & 0x03 ) + 1 ) /* number of bytes in a packet header */
106 static inline int scalar_number( uint8_t *p, int header_len )
108 assert( header_len == 1 || header_len == 2 || header_len == 4 );
110 if( header_len == 1 )
112 else if( header_len == 2 )
113 return( (p[0] << 8) + p[1] );
114 else if( header_len == 4 )
115 return( (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3] );
117 abort(); /* to shut up GCC warning */
120 /* number of data bytes in a MPI */
121 #define mpi_len( mpi ) ( ( scalar_number( mpi, 2 ) + 7 ) / 8 )
124 * fill a public_key_packet_t structure from public key packet data
125 * verify that it is a version 4 public key packet, using DSA
127 static int parse_public_key_packet( public_key_packet_t *p_key, uint8_t *p_buf,
128 size_t i_packet_len )
131 if( i_packet_len > 418 || i_packet_len < 6 )
136 p_key->version = *p_buf++; i_read++;
137 if( p_key->version != 4 )
140 /* XXX: warn when timestamp is > date ? */
141 memcpy( p_key->timestamp, p_buf, 4 ); p_buf += 4; i_read += 4;
143 p_key->algo = *p_buf++; i_read++;
144 if( p_key->algo != PUBLIC_KEY_ALGO_DSA )
148 if( i_read + 2 > i_packet_len )
151 int i_p_len = mpi_len( p_buf );
153 if( i_p_len > 128 || i_read + 2 + i_p_len > i_packet_len )
156 memcpy( p_key->p, p_buf, 2+i_p_len );
157 p_buf += 2+i_p_len; i_read += 2+i_p_len;
160 if( i_read + 2 > i_packet_len )
163 int i_q_len = mpi_len( p_buf );
165 if( i_q_len > 20 || i_read+2+i_q_len > i_packet_len )
168 memcpy( p_key->q, p_buf, 2+i_q_len );
169 p_buf += 2+i_q_len; i_read += 2+i_q_len;
172 if( i_read + 2 > i_packet_len )
175 int i_g_len = mpi_len( p_buf );
177 if( i_g_len > 128 || i_read+2+i_g_len > i_packet_len )
180 memcpy( p_key->g, p_buf, 2+i_g_len );
181 p_buf += 2+i_g_len; i_read += 2+i_g_len;
184 if( i_read + 2 > i_packet_len )
187 int i_y_len = mpi_len( p_buf );
190 if( i_y_len > 128 || i_read+2+i_y_len > i_packet_len )
193 memcpy( p_key->y, p_buf, 2+i_y_len );
196 if( i_read != i_packet_len ) /* some extra data eh ? */
202 static size_t parse_signature_v3_packet( signature_packet_t *p_sig,
203 uint8_t *p_buf, size_t i_sig_len )
205 size_t i_read = 1; /* we already read the version byte */
207 if( i_sig_len < 19 ) /* signature is at least 19 bytes + the 2 MPIs */
210 p_sig->specific.v3.hashed_data_len = *p_buf++; i_read++;
211 if( p_sig->specific.v3.hashed_data_len != 5 )
214 p_sig->type = *p_buf++; i_read++;
216 memcpy( p_sig->specific.v3.timestamp, p_buf, 4 );
217 p_buf += 4; i_read += 4;
219 memcpy( p_sig->issuer_longid, p_buf, 8 );
220 p_buf += 8; i_read += 8;
222 p_sig->public_key_algo = *p_buf++; i_read++;
224 p_sig->digest_algo = *p_buf++; i_read++;
226 p_sig->hash_verification[0] = *p_buf++; i_read++;
227 p_sig->hash_verification[1] = *p_buf++; i_read++;
229 assert( i_read == 19 );
235 * fill a signature_packet_v4_t from signature packet data
236 * verify that it was used with a DSA public key, using SHA-1 digest
238 static size_t parse_signature_v4_packet( signature_packet_t *p_sig,
239 uint8_t *p_buf, size_t i_sig_len )
241 size_t i_read = 1; /* we already read the version byte */
243 if( i_sig_len < 10 ) /* signature is at least 10 bytes + the 2 MPIs */
246 p_sig->type = *p_buf++; i_read++;
248 p_sig->public_key_algo = *p_buf++; i_read++;
250 p_sig->digest_algo = *p_buf++; i_read++;
252 memcpy( p_sig->specific.v4.hashed_data_len, p_buf, 2 );
253 p_buf += 2; i_read += 2;
255 size_t i_hashed_data_len =
256 scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
257 i_read += i_hashed_data_len;
258 if( i_read + 4 > i_sig_len )
261 p_sig->specific.v4.hashed_data = (uint8_t*) malloc( i_hashed_data_len );
262 if( !p_sig->specific.v4.hashed_data )
264 memcpy( p_sig->specific.v4.hashed_data, p_buf, i_hashed_data_len );
265 p_buf += i_hashed_data_len;
267 memcpy( p_sig->specific.v4.unhashed_data_len, p_buf, 2 );
268 p_buf += 2; i_read += 2;
270 size_t i_unhashed_data_len =
271 scalar_number( p_sig->specific.v4.unhashed_data_len, 2 );
272 i_read += i_unhashed_data_len;
273 if( i_read + 2 > i_sig_len )
276 p_sig->specific.v4.unhashed_data = (uint8_t*) malloc( i_unhashed_data_len );
277 if( !p_sig->specific.v4.unhashed_data )
280 memcpy( p_sig->specific.v4.unhashed_data, p_buf, i_unhashed_data_len );
281 p_buf += i_unhashed_data_len;
283 memcpy( p_sig->hash_verification, p_buf, 2 );
284 p_buf += 2; i_read += 2;
286 uint8_t *p, *max_pos;
287 p = p_sig->specific.v4.unhashed_data;
288 max_pos = p + scalar_number( p_sig->specific.v4.unhashed_data_len, 2 );
295 size_t i_subpacket_len;
298 if( p + 1 > max_pos )
300 i_subpacket_len = *p++;
304 if( p + 2 > max_pos )
306 i_subpacket_len = (*p++ - 192) << 8;
307 i_subpacket_len += *p++ + 192;
311 if( p + 4 > max_pos )
313 i_subpacket_len = *++p << 24;
314 i_subpacket_len += *++p << 16;
315 i_subpacket_len += *++p << 8;
316 i_subpacket_len += *++p;
319 if( *p == ISSUER_SUBPACKET )
321 if( p + 9 > max_pos )
324 memcpy( &p_sig->issuer_longid, p+1, 8 );
329 p += i_subpacket_len;
333 static int parse_signature_packet( signature_packet_t *p_sig,
334 uint8_t *p_buf, size_t i_sig_len )
336 if( !i_sig_len ) /* 1st sanity check, we need at least the version */
339 p_sig->version = *p_buf++;
342 switch( p_sig->version )
345 i_read = parse_signature_v3_packet( p_sig, p_buf, i_sig_len );
348 p_sig->specific.v4.hashed_data = NULL;
349 p_sig->specific.v4.unhashed_data = NULL;
350 i_read = parse_signature_v4_packet( p_sig, p_buf, i_sig_len );
356 if( i_read == 0 ) /* signature packet parsing has failed */
359 if( p_sig->public_key_algo != PUBLIC_KEY_ALGO_DSA )
362 if( p_sig->digest_algo != DIGEST_ALGO_SHA1 )
365 switch( p_sig->type )
367 case BINARY_SIGNATURE:
369 case GENERIC_KEY_SIGNATURE:
370 case PERSONA_KEY_SIGNATURE:
371 case CASUAL_KEY_SIGNATURE:
372 case POSITIVE_KEY_SIGNATURE:
378 p_buf--; /* rewind to the version byte */
381 if( i_read + 2 > i_sig_len )
384 size_t i_r_len = mpi_len( p_buf ); i_read += 2;
385 if( i_read + i_r_len > i_sig_len || i_r_len > 20 )
388 memcpy( p_sig->r, p_buf, 2 + i_r_len );
389 p_buf += 2 + i_r_len;
392 if( i_read + 2 > i_sig_len )
395 size_t i_s_len = mpi_len( p_buf ); i_read += 2;
396 if( i_read + i_s_len > i_sig_len || i_s_len > 20 )
399 memcpy( p_sig->s, p_buf, 2 + i_s_len );
400 p_buf += 2 + i_s_len;
403 assert( i_read == i_sig_len );
404 if( i_read < i_sig_len ) /* some extra data, hm ? */
411 if( p_sig->version == 4 )
413 free( p_sig->specific.v4.hashed_data );
414 free( p_sig->specific.v4.unhashed_data );
421 * crc_octets() was lamely copied from rfc 2440
422 * Copyright (C) The Internet Society (1998). All Rights Reserved.
424 #define CRC24_INIT 0xB704CEL
425 #define CRC24_POLY 0x1864CFBL
427 static long crc_octets( uint8_t *octets, size_t len )
429 long crc = CRC24_INIT;
433 crc ^= (*octets++) << 16;
434 for (i = 0; i < 8; i++)
441 return crc & 0xFFFFFFL;
445 * Transform an armored document in binary format
446 * Used on public keys and signatures
448 static int pgp_unarmor( char *p_ibuf, size_t i_ibuf_len,
449 uint8_t *p_obuf, size_t i_obuf_len )
451 char *p_ipos = p_ibuf;
452 uint8_t *p_opos = p_obuf;
454 int i_header_skipped = 0;
456 while( !i_end && p_ipos < p_ibuf + i_ibuf_len && *p_ipos != '=' )
458 if( *p_ipos == '\r' || *p_ipos == '\n' )
464 size_t i_line_len = strcspn( p_ipos, "\r\n" );
465 if( i_line_len == 0 )
468 if( !i_header_skipped )
470 if( !strncmp( p_ipos, "-----BEGIN PGP", 14 ) )
471 i_header_skipped = 1;
473 p_ipos += i_line_len + 1;
477 if( !strncmp( p_ipos, "Version:", 8 ) )
479 p_ipos += i_line_len + 1;
483 if( p_ipos[i_line_len - 1] == '=' )
486 p_ipos[i_line_len - 1] = '\0';
489 p_ipos[i_line_len] = '\0';
491 p_opos += vlc_b64_decode_binary_to_buffer( p_opos,
492 p_obuf - p_opos + i_obuf_len, p_ipos );
493 p_ipos += i_line_len + 1;
496 /* XXX: the CRC is OPTIONAL, really require it ? */
497 if( p_ipos + 5 > p_ibuf + i_ibuf_len || *p_ipos++ != '=' )
501 if( vlc_b64_decode_binary_to_buffer( p_crc, 3, p_ipos ) != 3 )
504 long l_crc = crc_octets( p_obuf, p_opos - p_obuf );
505 long l_crc2 = ( 0 << 24 ) + ( p_crc[0] << 16 ) + ( p_crc[1] << 8 ) + p_crc[2];
507 return l_crc2 == l_crc ? p_opos - p_obuf : 0;
511 * Download the signature associated to a document or a binary file.
512 * We're given the file's url, we just append ".asc" to it and download
514 static int download_signature( vlc_object_t *p_this,
515 signature_packet_t *p_sig,
516 const char *psz_url )
518 char *psz_sig = (char*) malloc( strlen( psz_url ) + 4 + 1 ); /* ".asc" + \0 */
522 strcpy( psz_sig, psz_url );
523 strcat( psz_sig, ".asc" );
525 stream_t *p_stream = stream_UrlNew( p_this, psz_sig );
531 int64_t i_size = stream_Size( p_stream );
533 msg_Dbg( p_this, "Downloading signature (%"PRId64" bytes)", i_size );
534 uint8_t *p_buf = (uint8_t*)malloc( i_size );
537 stream_Delete( p_stream );
541 int i_read = stream_Read( p_stream, p_buf, (int)i_size );
543 stream_Delete( p_stream );
545 if( i_read != (int)i_size )
548 "Couldn't download full signature (only %d bytes)", i_read );
553 if( (uint8_t)*p_buf < 0x80 ) /* ASCII */
555 msg_Dbg( p_this, "Unarmoring signature" );
557 uint8_t* p_unarmored = (uint8_t*) malloc( ( i_size * 3 ) / 4 + 1 );
564 int i_bytes = pgp_unarmor( (char*)p_buf, i_size, p_unarmored, i_size );
573 msg_Dbg( p_this, "Unarmoring failed : corrupted signature ?" );
578 if( packet_type( *p_buf ) != SIGNATURE_PACKET )
581 msg_Dbg( p_this, "Not a signature: %d", *p_buf );
585 size_t i_header_len = packet_header_len( *p_buf );
586 if( ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) ||
587 i_header_len + 1 > (size_t)i_size )
590 msg_Dbg( p_this, "Invalid signature packet header" );
594 size_t i_len = scalar_number( p_buf+1, i_header_len );
595 if( i_len + i_header_len + 1 != (size_t)i_size )
598 msg_Dbg( p_this, "Invalid signature packet" );
602 int i_ret = parse_signature_packet( p_sig, p_buf+1+i_header_len, i_len );
604 if( i_ret != VLC_SUCCESS )
606 msg_Dbg( p_this, "Couldn't parse signature" );
610 if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE )
612 msg_Dbg( p_this, "Invalid signature type: %d", p_sig->type );
613 if( p_sig->version == 4 )
615 free( p_sig->specific.v4.hashed_data );
616 free( p_sig->specific.v4.unhashed_data );
625 * Verify an OpenPGP signature made on some SHA-1 hash, with some DSA public key
627 static int verify_signature( uint8_t *p_r, uint8_t *p_s,
628 public_key_packet_t *p_key, uint8_t *p_hash )
630 /* the data to be verified (a SHA-1 hash) */
631 const char *hash_sexp_s = "(data(flags raw)(value %m))";
633 const char *key_sexp_s = "(public-key(dsa(p %m)(q %m)(g %m)(y %m)))";
635 const char *sig_sexp_s = "(sig-val(dsa(r %m )(s %m )))";
638 gcry_mpi_t p, q, g, y, r, s, hash;
639 p = q = g = y = r = s = hash = NULL;
640 gcry_sexp_t key_sexp, hash_sexp, sig_sexp;
641 key_sexp = hash_sexp = sig_sexp = NULL;
643 int i_p_len = mpi_len( p_key->p );
644 int i_q_len = mpi_len( p_key->q );
645 int i_g_len = mpi_len( p_key->g );
646 int i_y_len = mpi_len( p_key->y );
647 if( gcry_mpi_scan( &p, GCRYMPI_FMT_USG, p_key->p + 2, i_p_len, NULL ) ||
648 gcry_mpi_scan( &q, GCRYMPI_FMT_USG, p_key->q + 2, i_q_len, NULL ) ||
649 gcry_mpi_scan( &g, GCRYMPI_FMT_USG, p_key->g + 2, i_g_len, NULL ) ||
650 gcry_mpi_scan( &y, GCRYMPI_FMT_USG, p_key->y + 2, i_y_len, NULL ) ||
651 gcry_sexp_build( &key_sexp, &erroff, key_sexp_s, p, q, g, y ) )
654 int i_r_len = mpi_len( p_r );
655 int i_s_len = mpi_len( p_s );
656 if( gcry_mpi_scan( &r, GCRYMPI_FMT_USG, p_r + 2, i_r_len, NULL ) ||
657 gcry_mpi_scan( &s, GCRYMPI_FMT_USG, p_s + 2, i_s_len, NULL ) ||
658 gcry_sexp_build( &sig_sexp, &erroff, sig_sexp_s, r, s ) )
662 if( gcry_mpi_scan( &hash, GCRYMPI_FMT_USG, p_hash, i_hash_len, NULL ) ||
663 gcry_sexp_build( &hash_sexp, &erroff, hash_sexp_s, hash ) )
666 if( gcry_pk_verify( sig_sexp, hash_sexp, key_sexp ) )
672 if( p ) gcry_mpi_release( p );
673 if( q ) gcry_mpi_release( q );
674 if( g ) gcry_mpi_release( g );
675 if( y ) gcry_mpi_release( y );
676 if( r ) gcry_mpi_release( r );
677 if( s ) gcry_mpi_release( s );
678 if( hash ) gcry_mpi_release( hash );
679 if( key_sexp ) gcry_sexp_release( key_sexp );
680 if( sig_sexp ) gcry_sexp_release( sig_sexp );
681 if( hash_sexp ) gcry_sexp_release( hash_sexp );
686 * fill a public_key_t with public key data, including:
687 * * public key packet
688 * * signature packet issued by key which long id is p_sig_issuer
691 static int parse_public_key( const uint8_t *p_key_data, size_t i_key_len,
692 public_key_t *p_key, const uint8_t *p_sig_issuer )
694 uint8_t *pos = (uint8_t*) p_key_data;
695 uint8_t *max_pos = pos + i_key_len;
698 #define PUBLIC_KEY_FOUND 0x01
699 #define USER_ID_FOUND 0x02
700 #define SIGNATURE_FOUND 0X04
702 uint8_t *p_key_unarmored = NULL;
704 p_key->psz_username = NULL;
705 p_key->sig.specific.v4.hashed_data = NULL;
706 p_key->sig.specific.v4.unhashed_data = NULL;
708 if( !( *pos & 0x80 ) )
709 { /* first byte is ASCII, unarmoring */
710 p_key_unarmored = (uint8_t*)malloc( i_key_len );
711 if( !p_key_unarmored )
713 int i_len = pgp_unarmor( (char*)p_key_data, i_key_len,
714 p_key_unarmored, i_key_len );
719 pos = p_key_unarmored;
720 max_pos = pos + i_len;
723 while( pos < max_pos )
725 if( !(*pos & 0x80) || *pos & 0x40 )
728 int i_type = packet_type( *pos );
730 int i_header_len = packet_header_len( *pos++ );
731 if( pos + i_header_len > max_pos ||
732 ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) )
735 int i_packet_len = scalar_number( pos, i_header_len );
738 if( pos + i_packet_len > max_pos )
743 case PUBLIC_KEY_PACKET:
744 i_status |= PUBLIC_KEY_FOUND;
745 if( parse_public_key_packet( &p_key->key, pos, i_packet_len ) != VLC_SUCCESS )
749 case SIGNATURE_PACKET: /* we accept only v4 signatures here */
750 if( i_status & SIGNATURE_FOUND || !p_sig_issuer )
752 int i_ret = parse_signature_packet( &p_key->sig, pos,
754 if( i_ret == VLC_SUCCESS )
756 if( p_key->sig.version != 4 )
758 if( memcmp( p_key->sig.issuer_longid, p_sig_issuer, 8 ) )
760 free( p_key->sig.specific.v4.hashed_data );
761 free( p_key->sig.specific.v4.unhashed_data );
762 p_key->sig.specific.v4.hashed_data = NULL;
763 p_key->sig.specific.v4.unhashed_data = NULL;
766 i_status |= SIGNATURE_FOUND;
771 if( p_key->psz_username ) /* save only the first User ID */
773 i_status |= USER_ID_FOUND;
774 p_key->psz_username = (uint8_t*)malloc( i_packet_len + 1);
775 if( !p_key->psz_username )
778 memcpy( p_key->psz_username, pos, i_packet_len );
779 p_key->psz_username[i_packet_len] = '\0';
787 free( p_key_unarmored );
789 if( !( i_status & ( PUBLIC_KEY_FOUND | USER_ID_FOUND ) ) )
792 if( p_sig_issuer && !( i_status & SIGNATURE_FOUND ) )
798 if( p_key->sig.version == 4 )
800 free( p_key->sig.specific.v4.hashed_data );
801 free( p_key->sig.specific.v4.unhashed_data );
803 free( p_key->psz_username );
804 free( p_key_unarmored );
809 * return a sha1 hash of a file
811 static uint8_t *hash_sha1_from_file( const char *psz_file,
812 signature_packet_t *p_sig )
814 if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE )
817 FILE *f = utf8_fopen( psz_file, "r" );
821 uint8_t buffer[4096];
824 if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) )
831 while( ( i_read = fread( buffer, 1, sizeof(buffer), f ) ) > 0 )
832 gcry_md_write( hd, buffer, i_read );
834 if( p_sig->version == 3 )
836 gcry_md_putc( hd, p_sig->type );
837 gcry_md_write( hd, &p_sig->specific.v3.timestamp, 4 );
839 else if( p_sig->version == 4 )
841 gcry_md_putc( hd, p_sig->version );
842 gcry_md_putc( hd, p_sig->type );
843 gcry_md_putc( hd, p_sig->public_key_algo );
844 gcry_md_putc( hd, p_sig->digest_algo );
845 gcry_md_write( hd, p_sig->specific.v4.hashed_data_len, 2 );
846 size_t i_len = scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
847 gcry_md_write( hd, p_sig->specific.v4.hashed_data, i_len );
849 gcry_md_putc( hd, 0x04 );
850 gcry_md_putc( hd, 0xFF );
852 i_len += 6; /* hashed data + 6 bytes header */
854 gcry_md_putc( hd, (i_len >> 24) & 0xff );
855 gcry_md_putc( hd, (i_len >> 16) & 0xff );
856 gcry_md_putc( hd, (i_len >> 8) & 0xff );
857 gcry_md_putc( hd, (i_len) & 0xff );
860 { /* RFC 4880 only tells about versions 3 and 4 */
868 uint8_t *p_tmp = (uint8_t*) gcry_md_read( hd, GCRY_MD_SHA1);
869 uint8_t *p_hash = malloc( 20 );
871 memcpy( p_hash, p_tmp, 20 );
877 * download a public key (the last one) from videolan server, and parse it
879 static public_key_t *download_key( vlc_object_t *p_this,
880 const uint8_t *p_longid, const uint8_t *p_signature_issuer )
883 if( asprintf( &psz_url, "http://download.videolan.org/pub/keys/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X.asc",
884 p_longid[0], p_longid[1], p_longid[2], p_longid[3],
885 p_longid[4], p_longid[5], p_longid[6], p_longid[7] ) == -1 )
888 stream_t *p_stream = stream_UrlNew( p_this, psz_url );
893 int64_t i_size = stream_Size( p_stream );
896 stream_Delete( p_stream );
900 uint8_t *p_buf = (uint8_t*)malloc( i_size );
903 stream_Delete( p_stream );
907 int i_read = stream_Read( p_stream, p_buf, (int)i_size );
908 stream_Delete( p_stream );
910 if( i_read != (int)i_size )
912 msg_Dbg( p_this, "Couldn't read full GPG key" );
917 public_key_t *p_pkey = (public_key_t*) malloc( sizeof( public_key_t ) );
924 memcpy( p_pkey->longid, p_longid, 8 );
926 int i_error = parse_public_key( p_buf, i_read, p_pkey, p_signature_issuer );
929 if( i_error != VLC_SUCCESS )
931 msg_Dbg( p_this, "Couldn't parse GPG key" );
940 * Generate a SHA1 hash on a public key, to verify a signature made on that hash
941 * Note that we need the signature (v4) to compute the hash
943 static uint8_t *key_sign_hash( public_key_t *p_pkey )
945 if( p_pkey->sig.version != 4 )
948 if( p_pkey->sig.type < GENERIC_KEY_SIGNATURE ||
949 p_pkey->sig.type > POSITIVE_KEY_SIGNATURE )
952 gcry_error_t error = 0;
955 error = gcry_md_open( &hd, GCRY_MD_SHA1, 0 );
959 gcry_md_putc( hd, 0x99 );
961 size_t i_p_len = mpi_len( p_pkey->key.p );
962 size_t i_g_len = mpi_len( p_pkey->key.g );
963 size_t i_q_len = mpi_len( p_pkey->key.q );
964 size_t i_y_len = mpi_len( p_pkey->key.y );
966 size_t i_size = 6 + 2*4 + i_p_len + i_g_len + i_q_len + i_y_len;
968 gcry_md_putc( hd, (i_size >> 8) & 0xff );
969 gcry_md_putc( hd, i_size & 0xff );
971 gcry_md_putc( hd, p_pkey->key.version );
972 gcry_md_write( hd, p_pkey->key.timestamp, 4 );
973 gcry_md_putc( hd, p_pkey->key.algo );
975 gcry_md_write( hd, (uint8_t*)&p_pkey->key.p, 2 );
976 gcry_md_write( hd, (uint8_t*)&p_pkey->key.p + 2, i_p_len );
978 gcry_md_write( hd, (uint8_t*)&p_pkey->key.q, 2 );
979 gcry_md_write( hd, (uint8_t*)&p_pkey->key.q + 2, i_q_len );
981 gcry_md_write( hd, (uint8_t*)&p_pkey->key.g, 2 );
982 gcry_md_write( hd, (uint8_t*)&p_pkey->key.g + 2, i_g_len );
984 gcry_md_write( hd, (uint8_t*)&p_pkey->key.y, 2 );
985 gcry_md_write( hd, (uint8_t*)&p_pkey->key.y + 2, i_y_len );
987 gcry_md_putc( hd, 0xb4 );
989 size_t i_len = strlen((char*)p_pkey->psz_username);
991 gcry_md_putc( hd, (i_len >> 24) & 0xff );
992 gcry_md_putc( hd, (i_len >> 16) & 0xff );
993 gcry_md_putc( hd, (i_len >> 8) & 0xff );
994 gcry_md_putc( hd, (i_len) & 0xff );
996 gcry_md_write( hd, p_pkey->psz_username, i_len );
998 size_t i_hashed_data_len =
999 scalar_number( p_pkey->sig.specific.v4.hashed_data_len, 2 );
1001 gcry_md_putc( hd, p_pkey->sig.version );
1002 gcry_md_putc( hd, p_pkey->sig.type );
1003 gcry_md_putc( hd, p_pkey->sig.public_key_algo );
1004 gcry_md_putc( hd, p_pkey->sig.digest_algo );
1005 gcry_md_write( hd, p_pkey->sig.specific.v4.hashed_data_len, 2 );
1006 gcry_md_write( hd, p_pkey->sig.specific.v4.hashed_data, i_hashed_data_len );
1008 gcry_md_putc( hd, 0x04 );
1009 gcry_md_putc( hd, 0xff );
1011 i_hashed_data_len += 6; /* hashed data + 6 bytes header */
1013 gcry_md_putc( hd, (i_hashed_data_len >> 24) & 0xff );
1014 gcry_md_putc( hd, (i_hashed_data_len >> 16) & 0xff );
1015 gcry_md_putc( hd, (i_hashed_data_len >> 8) & 0xff );
1016 gcry_md_putc( hd, (i_hashed_data_len) & 0xff );
1018 gcry_md_final( hd );
1020 uint8_t *p_tmp = gcry_md_read( hd, GCRY_MD_SHA1 );
1023 p_tmp[0] != p_pkey->sig.hash_verification[0] ||
1024 p_tmp[1] != p_pkey->sig.hash_verification[1] )
1026 gcry_md_close( hd );
1030 uint8_t *p_hash = malloc( 20 );
1032 memcpy( p_hash, p_tmp, 20 );
1033 gcry_md_close( hd );
1038 /*****************************************************************************
1039 * Update_t functions
1040 *****************************************************************************/
1043 * Create a new update VLC struct
1045 * \param p_this the calling vlc_object
1046 * \return pointer to new update_t or NULL
1048 update_t *__update_New( vlc_object_t *p_this )
1053 p_update = (update_t *)malloc( sizeof( update_t ) );
1054 if( !p_update ) return NULL;
1056 vlc_mutex_init( &p_update->lock );
1058 p_update->p_libvlc = p_this->p_libvlc;
1060 p_update->release.psz_url = NULL;
1061 p_update->release.psz_desc = NULL;
1063 p_update->p_download = NULL;
1064 p_update->p_check = NULL;
1066 p_update->p_pkey = NULL;
1073 * Delete an update_t struct
1075 * \param p_update update_t* pointer
1078 void update_Delete( update_t *p_update )
1082 if( p_update->p_check )
1084 assert( !p_update->p_download );
1085 vlc_object_kill( p_update->p_check );
1086 vlc_thread_join( p_update->p_check );
1087 vlc_object_release( p_update->p_check );
1089 else if( p_update->p_download )
1091 vlc_object_kill( p_update->p_download );
1092 vlc_thread_join( p_update->p_download );
1093 vlc_object_release( p_update->p_download );
1096 vlc_mutex_destroy( &p_update->lock );
1098 free( p_update->release.psz_url );
1099 free( p_update->release.psz_desc );
1100 free( p_update->p_pkey );
1106 * Empty the release struct
1108 * \param p_update update_t* pointer
1111 static void EmptyRelease( update_t *p_update )
1113 p_update->release.i_major = 0;
1114 p_update->release.i_minor = 0;
1115 p_update->release.i_revision = 0;
1117 FREENULL( p_update->release.psz_url );
1118 FREENULL( p_update->release.psz_desc );
1122 * Get the update file and parse it
1123 * p_update has to be locked when calling this function
1125 * \param p_update pointer to update struct
1126 * \return true if the update is valid and authenticated
1128 static bool GetUpdateFile( update_t *p_update )
1130 stream_t *p_stream = NULL;
1134 unsigned char extra;
1135 char *psz_version_line = NULL;
1137 p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
1140 msg_Err( p_update->p_libvlc, "Failed to open %s for reading",
1141 UPDATE_VLC_STATUS_URL );
1145 /* Start reading the status file */
1146 if( !( psz_version_line = stream_ReadLine( p_stream ) ) )
1148 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : missing version",
1149 UPDATE_VLC_STATUS_URL );
1153 /* first line : version number */
1154 p_update->release.extra = 0;
1155 switch( sscanf( psz_version_line, "%i.%i.%i%c",
1156 &i_major, &i_minor, &i_revision, &extra ) )
1159 p_update->release.extra = extra;
1161 p_update->release.i_major = i_major;
1162 p_update->release.i_minor = i_minor;
1163 p_update->release.i_revision = i_revision;
1166 msg_Err( p_update->p_libvlc, "Update version false formated" );
1170 /* second line : URL */
1171 if( !( p_update->release.psz_url = stream_ReadLine( p_stream ) ) )
1173 msg_Err( p_update->p_libvlc, "Update file %s is corrupted : URL missing",
1174 UPDATE_VLC_STATUS_URL );
1178 /* Remaining data : description */
1179 int i_read = stream_Size( p_stream ) - stream_Tell( p_stream );
1182 msg_Err( p_update->p_libvlc,
1183 "Update file %s is corrupted: description missing",
1184 UPDATE_VLC_STATUS_URL );
1188 p_update->release.psz_desc = (char*) malloc( i_read + 1 );
1189 if( !p_update->release.psz_desc )
1192 if( stream_Read( p_stream, p_update->release.psz_desc, i_read ) != i_read )
1194 msg_Err( p_update->p_libvlc, "Couldn't download update file %s",
1195 UPDATE_VLC_STATUS_URL );
1198 p_update->release.psz_desc[i_read] = '\0';
1200 stream_Delete( p_stream );
1203 /* Now that we know the status is valid, we must download its signature
1204 * to authenticate it */
1205 signature_packet_t sign;
1206 if( download_signature( VLC_OBJECT( p_update->p_libvlc ), &sign,
1207 UPDATE_VLC_STATUS_URL ) != VLC_SUCCESS )
1209 msg_Err( p_update->p_libvlc, "Couldn't download signature of status file" );
1213 if( sign.type != BINARY_SIGNATURE && sign.type != TEXT_SIGNATURE )
1215 msg_Err( p_update->p_libvlc, "Invalid signature type" );
1219 p_update->p_pkey = (public_key_t*)malloc( sizeof( public_key_t ) );
1220 if( !p_update->p_pkey )
1223 if( parse_public_key( videolan_public_key, sizeof( videolan_public_key ),
1224 p_update->p_pkey, NULL ) != VLC_SUCCESS )
1226 msg_Err( p_update->p_libvlc, "Couldn't parse embedded public key, something went really wrong..." );
1227 FREENULL( p_update->p_pkey );
1231 memcpy( p_update->p_pkey->longid, videolan_public_key_longid, 8 );
1233 if( memcmp( sign.issuer_longid, p_update->p_pkey->longid , 8 ) != 0 )
1235 msg_Dbg( p_update->p_libvlc, "Need to download the GPG key" );
1236 public_key_t *p_new_pkey = download_key(
1237 VLC_OBJECT(p_update->p_libvlc),
1238 sign.issuer_longid, videolan_public_key_longid );
1241 msg_Err( p_update->p_libvlc, "Couldn't download GPG key" );
1242 FREENULL( p_update->p_pkey );
1246 uint8_t *p_hash = key_sign_hash( p_new_pkey );
1249 msg_Err( p_update->p_libvlc, "Failed to hash signature" );
1251 FREENULL( p_update->p_pkey );
1255 if( verify_signature( p_new_pkey->sig.r, p_new_pkey->sig.s,
1256 &p_update->p_pkey->key, p_hash ) == VLC_SUCCESS )
1259 msg_Info( p_update->p_libvlc, "Key authenticated" );
1260 free( p_update->p_pkey );
1261 p_update->p_pkey = p_new_pkey;
1266 msg_Err( p_update->p_libvlc, "Key signature invalid !\n" );
1272 if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) )
1275 gcry_md_write( hd, psz_version_line, strlen( psz_version_line ) );
1276 FREENULL( psz_version_line );
1277 if( sign.type == TEXT_SIGNATURE )
1278 gcry_md_putc( hd, '\r' );
1279 gcry_md_putc( hd, '\n' );
1280 gcry_md_write( hd, p_update->release.psz_url,
1281 strlen( p_update->release.psz_url ) );
1282 if( sign.type == TEXT_SIGNATURE )
1283 gcry_md_putc( hd, '\r' );
1284 gcry_md_putc( hd, '\n' );
1286 char *psz_desc = p_update->release.psz_desc;
1289 size_t i_len = strcspn( psz_desc, "\r\n" );
1293 gcry_md_write( hd, psz_desc, i_len );
1294 if( sign.type == TEXT_SIGNATURE )
1295 gcry_md_putc( hd, '\r' );
1296 gcry_md_putc( hd, '\n' );
1299 while( *psz_desc == '\r' || *psz_desc == '\n' )
1303 if( sign.version == 3 )
1305 gcry_md_putc( hd, sign.type );
1306 gcry_md_write( hd, &sign.specific.v3.timestamp, 4 );
1308 else if( sign.version == 4 )
1310 gcry_md_putc( hd, sign.version );
1311 gcry_md_putc( hd, sign.type );
1312 gcry_md_putc( hd, sign.public_key_algo );
1313 gcry_md_putc( hd, sign.digest_algo );
1314 gcry_md_write( hd, sign.specific.v4.hashed_data_len, 2 );
1315 size_t i_len = scalar_number( sign.specific.v4.hashed_data_len, 2 );
1316 gcry_md_write( hd, sign.specific.v4.hashed_data, i_len );
1317 gcry_md_putc( hd, 0x04 );
1318 gcry_md_putc( hd, 0xFF );
1320 i_len += 6; /* hashed data + 6 bytes header */
1322 gcry_md_putc( hd, (i_len >> 24) & 0xff );
1323 gcry_md_putc( hd, (i_len >> 16) & 0xff );
1324 gcry_md_putc( hd, (i_len >> 8) & 0xff );
1325 gcry_md_putc( hd, (i_len) & 0xff );
1328 { /* RFC 4880 only tells about versions 3 and 4 */
1329 msg_Warn( p_update->p_libvlc, "Invalid signature version %d",
1334 gcry_md_final( hd );
1336 uint8_t *p_hash = gcry_md_read( hd, GCRY_MD_SHA1 );
1338 if( p_hash[0] != sign.hash_verification[0] ||
1339 p_hash[1] != sign.hash_verification[1] )
1341 msg_Warn( p_update->p_libvlc, "Bad SHA1 hash for status file" );
1345 if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
1348 msg_Err( p_update->p_libvlc, "BAD SIGNATURE for status file" );
1353 msg_Info( p_update->p_libvlc, "Status file authenticated" );
1354 gcry_md_close( hd );
1359 gcry_md_close( hd );
1362 stream_Delete( p_stream );
1363 free( psz_version_line );
1367 static void* update_CheckReal( vlc_object_t *p_this );
1372 * \param p_update pointer to update struct
1373 * \param pf_callback pointer to a function to call when the update_check is finished
1374 * \param p_data pointer to some datas to give to the callback
1377 void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void *p_data )
1381 update_check_thread_t *p_uct =
1382 vlc_custom_create( p_update->p_libvlc, sizeof( *p_uct ),
1383 VLC_OBJECT_GENERIC, "update check" );
1384 if( !p_uct ) return;
1386 p_uct->p_update = p_update;
1387 p_update->p_check = p_uct;
1388 p_uct->pf_callback = pf_callback;
1389 p_uct->p_data = p_data;
1391 vlc_thread_create( p_uct, "check for update", update_CheckReal,
1392 VLC_THREAD_PRIORITY_LOW, false );
1395 void* update_CheckReal( vlc_object_t* p_this )
1397 update_check_thread_t *p_uct = (update_check_thread_t *)p_this;
1401 canc = vlc_savecancel ();
1402 vlc_mutex_lock( &p_uct->p_update->lock );
1404 EmptyRelease( p_uct->p_update );
1405 b_ret = GetUpdateFile( p_uct->p_update );
1406 vlc_mutex_unlock( &p_uct->p_update->lock );
1408 if( p_uct->pf_callback )
1409 (p_uct->pf_callback)( p_uct->p_data, b_ret );
1411 vlc_restorecancel (canc);
1416 * Compare a given release's version number to the current VLC's one
1418 * \param p_update structure
1419 * \return true if we have to upgrade to the given version to be up to date
1421 static bool is_strictly_greater( int * a, int * b, int n)
1423 if( n <= 0 ) return false;
1424 if(a[0] > b[0] ) return true;
1425 if(a[0] == b[0] ) return is_strictly_greater( a+1, b+1, n-1 );
1426 /* a[0] < b[0] */ return false;
1429 bool update_NeedUpgrade( update_t *p_update )
1433 int current_version[] = {
1434 *PACKAGE_VERSION_MAJOR - '0',
1435 *PACKAGE_VERSION_MINOR - '0',
1436 *PACKAGE_VERSION_REVISION - '0',
1437 *PACKAGE_VERSION_EXTRA
1439 int latest_version[] = {
1440 p_update->release.i_major,
1441 p_update->release.i_minor,
1442 p_update->release.i_revision,
1443 p_update->release.extra
1446 return is_strictly_greater( latest_version, current_version, 4 );
1450 * Convert a long int size in bytes to a string
1452 * \param l_size the size in bytes
1453 * \return the size as a string
1455 static char *size_str( long int l_size )
1457 char *psz_tmp = NULL;
1460 i_retval = asprintf( &psz_tmp, _("%.1f GB"), (float)l_size/(1<<30) );
1461 else if( l_size >> 20 )
1462 i_retval = asprintf( &psz_tmp, _("%.1f MB"), (float)l_size/(1<<20) );
1463 else if( l_size >> 10 )
1464 i_retval = asprintf( &psz_tmp, _("%.1f kB"), (float)l_size/(1<<10) );
1466 i_retval = asprintf( &psz_tmp, _("%ld B"), l_size );
1468 return i_retval == -1 ? NULL : psz_tmp;
1471 void update_WaitDownload( update_t *p_update )
1473 if(p_update->p_download)
1474 vlc_thread_join( p_update->p_download );
1475 vlc_object_release( p_update->p_download );
1476 p_update->p_download = NULL;
1479 static void* update_DownloadReal( vlc_object_t *p_this );
1482 * Download the file given in the update_t
1484 * \param p_update structure
1485 * \param dir to store the download file
1488 void update_Download( update_t *p_update, const char *psz_destdir )
1492 update_download_thread_t *p_udt =
1493 vlc_custom_create( p_update->p_libvlc, sizeof( *p_udt ),
1494 VLC_OBJECT_GENERIC, "update download" );
1498 p_udt->p_update = p_update;
1499 p_update->p_download = p_udt;
1500 p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
1502 vlc_thread_create( p_udt, "download update", update_DownloadReal,
1503 VLC_THREAD_PRIORITY_LOW, false );
1506 static void* update_DownloadReal( vlc_object_t *p_this )
1508 update_download_thread_t *p_udt = (update_download_thread_t *)p_this;
1511 long int l_downloaded = 0;
1513 char *psz_status = NULL;
1514 char *psz_downloaded = NULL;
1515 char *psz_size = NULL;
1516 char *psz_destfile = NULL;
1517 char *psz_tmpdestfile = NULL;
1519 FILE *p_file = NULL;
1520 stream_t *p_stream = NULL;
1521 void* p_buffer = NULL;
1525 update_t *p_update = p_udt->p_update;
1526 char *psz_destdir = p_udt->psz_destdir;
1528 msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url );
1529 canc = vlc_savecancel ();
1531 /* Open the stream */
1532 p_stream = stream_UrlNew( p_udt, p_update->release.psz_url );
1535 msg_Err( p_udt, "Failed to open %s for reading", p_update->release.psz_url );
1539 /* Get the stream size */
1540 l_size = stream_Size( p_stream );
1542 /* Get the file name and open it*/
1543 psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' );
1544 if( !psz_tmpdestfile )
1546 msg_Err( p_udt, "The URL %s is badly formated",
1547 p_update->release.psz_url );
1551 if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) == -1 )
1554 p_file = utf8_fopen( psz_destfile, "w" );
1557 msg_Err( p_udt, "Failed to open %s for writing", psz_destfile );
1561 /* Create a buffer and fill it with the downloaded file */
1562 p_buffer = (void *)malloc( 1 << 10 );
1565 msg_Err( p_udt, "Can't malloc (1 << 10) bytes! download cancelled." );
1569 msg_Dbg( p_udt, "Downloading Stream '%s'", p_update->release.psz_url );
1571 psz_size = size_str( l_size );
1572 if( asprintf( &psz_status, _("%s\nDownloading... %s/%s %.1f%% done"),
1573 p_update->release.psz_url, "0.0", psz_size, 0.0 ) != -1 )
1575 i_progress = intf_UserProgress( p_udt, _( "Downloading ..."),
1576 psz_status, 0.0, 0 );
1580 vlc_object_lock( p_udt );
1581 while( vlc_object_alive( p_udt ) &&
1582 ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
1583 !intf_ProgressIsCancelled( p_udt, i_progress ) )
1585 vlc_object_unlock( p_udt );
1586 if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
1588 msg_Err( p_udt, "Failed to write into %s", psz_destfile );
1592 l_downloaded += i_read;
1593 psz_downloaded = size_str( l_downloaded );
1594 f_progress = 100.0*(float)l_downloaded/(float)l_size;
1596 if( asprintf( &psz_status, _( "%s\nDownloading... %s/%s %.1f%% done" ),
1597 p_update->release.psz_url, psz_downloaded, psz_size,
1598 f_progress ) != -1 )
1600 intf_ProgressUpdate( p_udt, i_progress, psz_status, f_progress, 0 );
1603 free( psz_downloaded );
1604 vlc_object_lock( p_udt );
1607 /* Finish the progress bar or delete the file if the user had canceled */
1611 if( vlc_object_alive( p_udt ) &&
1612 !intf_ProgressIsCancelled( p_udt, i_progress ) )
1614 vlc_object_unlock( p_udt );
1615 if( asprintf( &psz_status, _("%s\nDone %s (100.0%%)"),
1616 p_update->release.psz_url, psz_size ) != -1 )
1618 intf_ProgressUpdate( p_udt, i_progress, psz_status, 100.0, 0 );
1625 vlc_object_unlock( p_udt );
1626 utf8_unlink( psz_destfile );
1630 signature_packet_t sign;
1631 if( download_signature( VLC_OBJECT( p_udt ), &sign,
1632 p_update->release.psz_url ) != VLC_SUCCESS )
1634 utf8_unlink( psz_destfile );
1636 intf_UserFatal( p_udt, true, _("File could not be verified"),
1637 _("It was not possible to download a cryptographic signature for "
1638 "the downloaded file \"%s\". Thus, it was deleted."),
1640 msg_Err( p_udt, "Couldn't download signature of downloaded file" );
1644 if( memcmp( sign.issuer_longid, p_update->p_pkey->longid, 8 ) )
1646 utf8_unlink( psz_destfile );
1647 msg_Err( p_udt, "Invalid signature issuer" );
1648 intf_UserFatal( p_udt, true, _("Invalid signature"),
1649 _("The cryptographic signature for the downloaded file \"%s\" was "
1650 "invalid and could not be used to securely verify it. Thus, the "
1651 "file was deleted."),
1656 if( sign.type != BINARY_SIGNATURE )
1658 utf8_unlink( psz_destfile );
1659 msg_Err( p_udt, "Invalid signature type" );
1660 intf_UserFatal( p_udt, true, _("Invalid signature"),
1661 _("The cryptographic signature for the downloaded file \"%s\" was "
1662 "invalid and could not be used to securely verify it. Thus, the "
1663 "file was deleted."),
1668 uint8_t *p_hash = hash_sha1_from_file( psz_destfile, &sign );
1671 msg_Err( p_udt, "Unable to hash %s", psz_destfile );
1672 utf8_unlink( psz_destfile );
1673 intf_UserFatal( p_udt, true, _("File not verifiable"),
1674 _("It was not possible to securely verify the downloaded file"
1675 " \"%s\". Thus, it was deleted."),
1681 if( p_hash[0] != sign.hash_verification[0] ||
1682 p_hash[1] != sign.hash_verification[1] )
1684 utf8_unlink( psz_destfile );
1685 intf_UserFatal( p_udt, true, _("File corrupted"),
1686 _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
1688 msg_Err( p_udt, "Bad SHA1 hash for %s", psz_destfile );
1693 if( verify_signature( sign.r, sign.s, &p_update->p_pkey->key, p_hash )
1696 utf8_unlink( psz_destfile );
1697 intf_UserFatal( p_udt, true, _("File corrupted"),
1698 _("Downloaded file \"%s\" was corrupted. Thus, it was deleted."),
1700 msg_Err( p_udt, "BAD SIGNATURE for %s", psz_destfile );
1705 msg_Info( p_udt, "%s authenticated", psz_destfile );
1711 intf_ProgressUpdate( p_udt, i_progress, _("Cancelled"), 100.0, 0 );
1714 stream_Delete( p_stream );
1717 free( psz_destdir );
1718 free( psz_destfile );
1722 p_udt->p_update->p_download = NULL;
1724 vlc_object_release( p_udt );
1725 vlc_restorecancel( canc );
1729 update_release_t *update_GetRelease( update_t *p_update )
1731 return &p_update->release;
1735 update_t *__update_New( vlc_object_t *p_this )
1741 void update_Delete( update_t *p_update )
1746 void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ),
1749 (void)p_update; (void)pf_callback; (void)p_data;
1752 bool update_NeedUpgrade( update_t *p_update )
1758 void update_WaitDownload( update_t *p_update )
1763 void update_Download( update_t *p_update, const char *psz_destdir )
1765 (void)p_update; (void)psz_destdir;
1768 update_release_t *update_GetRelease( update_t *p_update )