]> git.sesse.net Git - vlc/blobdiff - include/vlc_update.h
Alert the user when something wrong accure during the update.
[vlc] / include / vlc_update.h
index cc441b83728411c0823c45c5bf6c8ee230793ae1..ed87a863a8f08a4b3a60e038570bb8b217ffea1c 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * vlc_update.h: VLC update and plugins download
  *****************************************************************************
- * Copyright (C) 2005 the VideoLAN team
- * $Id$
+ * Copyright © 2005-2007 the VideoLAN team
+ * $Id$
  *
  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
+ *          Rafaël Carré <funman@videolanorg>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#if !defined( __LIBVLC__ )
+  #error You are not libvlc or one of its plugins. You cannot include this file
+#endif
+
+#ifdef UPDATE_CHECK
+
 #ifndef _VLC_UPDATE_H
 #define _VLC_UPDATE_H
 
 #include <vlc/vlc.h>
 
+#include <vlc_stream.h>     /* key & signature downloading */
+#include <vlc_strings.h>    /* b64 decoding */
+#include <vlc_charset.h>    /* utf8_fopen() */
+#include <gcrypt.h>         /* cryptography and digest algorithms */
+
 /**
  * \defgroup update Update
  *
  * @{
  */
 
-#define UPDATE_FILE_TYPE_ALL    (~0)
-#define UPDATE_FILE_TYPE_NONE   0
-
-#define UPDATE_FILE_TYPE_UNDEF      1
-#define UPDATE_FILE_TYPE_INFO       2
-#define UPDATE_FILE_TYPE_SOURCE     4
-#define UPDATE_FILE_TYPE_BINARY     8
-#define UPDATE_FILE_TYPE_PLUGIN     16
+enum    /* Public key algorithms */
+{
+    /* we will only use DSA public keys */
+    PUBLIC_KEY_ALGO_DSA = 0x11
+};
 
-#define UPDATE_RELEASE_STATUS_ALL       (~0)
-#define UPDATE_RELEASE_STATUS_NONE      0
+enum    /* Digest algorithms */
+{
+    /* and DSA use SHA-1 digest */
+    DIGEST_ALGO_SHA1    = 0x02
+};
 
-#define UPDATE_RELEASE_STATUS_OLDER     1
-#define UPDATE_RELEASE_STATUS_EQUAL     2
-#define UPDATE_RELEASE_STATUS_NEWER     4
+enum    /* Packet types */
+{
+    SIGNATURE_PACKET    = 0x02,
+    PUBLIC_KEY_PACKET   = 0x06,
+    USER_ID_PACKET      = 0x0d
+};
 
-#define UPDATE_RELEASE_TYPE_STABLE      1
-#define UPDATE_RELEASE_TYPE_TESTING     2
-#define UPDATE_RELEASE_TYPE_UNSTABLE    4
+enum    /* Signature types */
+{
+    BINARY_SIGNATURE        = 0x00,
+    TEXT_SIGNATURE          = 0x01,
+
+    /* Public keys signatures */
+    GENERIC_KEY_SIGNATURE   = 0x10, /* No assumption of verification */
+    PERSONA_KEY_SIGNATURE   = 0x11, /* No verification has been made */
+    CASUAL_KEY_SIGNATURE    = 0x12, /* Some casual verification */
+    POSITIVE_KEY_SIGNATURE  = 0x13  /* Substantial verification */
+};
 
-#define UPDATE_FAIL     0
-#define UPDATE_SUCCESS  1
-#define UPDATE_NEXT     0
-#define UPDATE_PREV     2
-#define UPDATE_MIRROR   4
-#define UPDATE_RELEASE  8
-#define UPDATE_FILE     16
-#define UPDATE_RESET    32
 
-/**
- * Describes an update file
- */
-struct update_file_t
+enum    /* Signature subpacket types */
 {
-    int i_type;             ///< File type
-    char* psz_md5;          ///< MD5 hash
-    long int l_size;        ///< File size in bytes
-    char* psz_url;          ///< Relative (to a mirror) or absolute url
-    char* psz_description;  ///< Plain text description
+    ISSUER_SUBPACKET    = 0x10
 };
 
-/**
- * Describes an update VLC release number
- */
-struct update_release_t
-{
-    char* psz_major;        ///< Version major string
-    char* psz_minor;        ///< Version minor string
-    char* psz_revision;     ///< Version revision string
-    char* psz_extra;        ///< Version extra string
 
-    char* psz_svn_revision; ///< SVN revision
 
-    int i_type;             ///< Release type
+struct public_key_packet_t
+{ /* a public key packet (DSA/SHA-1) is 418 bytes */
 
-    int i_status;           ///< Release status compared to current VLC version
+    uint8_t version;      /* we use only version 4 */
+    uint8_t timestamp[4]; /* creation time of the key */
+    uint8_t algo;         /* we only use DSA */
+    /* the multi precision integers, with their 2 bytes length header */
+    uint8_t p[2+128];
+    uint8_t q[2+20];
+    uint8_t g[2+128];
+    uint8_t y[2+128];
+};
 
-    struct update_file_t* p_files; ///< Files list
-    int i_files;            ///< Number of files in the files list
+/* used for public key signatures */
+struct signature_packet_v4_t
+{ /* hashed_data or unhashed_data can be empty, so the signature packet is
+   * theorically at least 54 bytes long, but always more than that. */
+
+    uint8_t version;
+    uint8_t type;
+    uint8_t public_key_algo;
+    uint8_t digest_algo;
+    uint8_t hashed_data_len[2];
+    uint8_t *hashed_data;
+    uint8_t unhashed_data_len[2];
+    uint8_t *unhashed_data;
+    uint8_t hash_verification[2];
+
+    /* The part below is made of consecutive MPIs, their number and size being
+     * public-key-algorithm dependant.
+     * But since we use DSA signatures only, we fix it. */
+    uint8_t r[2+20];
+    uint8_t s[2+20];
 };
 
-/**
- * Describes a mirror
- */
-struct update_mirror_t
+/* Used for binary document signatures (to be compatible with older software)
+ * DSA/SHA-1 is always 65 bytes */
+struct signature_packet_v3_t
 {
-    char *psz_name;         ///< Mirror name
-    char *psz_location;     ///< Mirror geographical location
-    char *psz_type;         ///< Mirror type (FTP, HTTP, ...)
+    uint8_t header[2];
+    uint8_t version;            /* 3 */
+    uint8_t hashed_data_len;    /* MUST be 5 */
+    uint8_t type;
+    uint8_t timestamp[4];       /* 4 bytes scalar number */
+    uint8_t issuer_longid[8];  /* The key which signed the document */
+    uint8_t public_key_algo;    /* we only know about DSA */
+    uint8_t digest_algo;        /* and his little sister SHA-1 */
+    uint8_t hash_verification[2];/* the 2 1st bytes of the SHA-1 hash */
+
+    /* The part below is made of consecutive MPIs, their number and size being
+     * public-key-algorithm dependant.
+     * But since we use DSA signatures only, we fix it. */
+    uint8_t r[2+20];
+    uint8_t s[2+20];
+};
 
-    char *psz_base_url;     ///< Mirror base url
+typedef struct public_key_packet_t public_key_packet_t;
+typedef struct signature_packet_v4_t signature_packet_v4_t;
+typedef struct signature_packet_v3_t signature_packet_v3_t;
 
+struct public_key_t
+{
+    uint8_t longid[8];       /* Long id */
+    uint8_t *psz_username;    /* USER ID */
+
+    public_key_packet_t key;       /* Public key packet */
+
+    signature_packet_v4_t sig;     /* Signature packet, by the embedded key */
 };
 
-/**
- * The update object. Stores (and caches) all information relative to updates
- */
-struct update_t
-{
-    libvlc_int_t *p_libvlc; 
+typedef struct public_key_t public_key_t;
 
-    vlc_mutex_t lock;
+/* We trust this public key, and by extension, also keys signed by it. */
+static uint8_t videolan_public_key_longid[8] = {
+  0x90, 0x28, 0x17, 0xE4, 0xAA, 0x5F, 0x4D, 0xE6 
+};
 
-    struct update_release_t *p_releases;    ///< Releases (version) list
-    int i_releases;                         ///< Number of releases
-    vlc_bool_t b_releases;                  ///< True if we have a releases list
+static uint8_t videolan_public_key[] = {
+"-----BEGIN PGP PUBLIC KEY BLOCK-----\n"
+"Version: GnuPG v2.0.4 (FreeBSD)\n"
+"\n"
+"mQGiBEWbjf8RBAC+4m2yYYzuA0+D5JQatKmoxG4z3+bat08tMz0YvBUp1UU+95i4\n"
+"cP9ndklv3yzhtZ4MIx5yy64FXtPi0/NQiikEVYPYn2KMO4LCfZCwYBEizVWzABya\n"
+"LZcffCP/3VhoR90NUluWyi+zVAn9KNIRlnhnYpDDlI76fCrTTHDCtgpImwCg7VzB\n"
+"4L6O0JpUJBCZOCAPJNYirUkD/3uCZe4vK4kLW+W3HB+grMCI1uFULmVSKMBQZc+p\n"
+"dqDq++u3zYGqiMNaVrLg/J4GSH/P0ossXEtmTVjLHF4nJ7HXfIjqkqdkxq7g9odY\n"
+"/dkA/aC7z4JBgcYfRnDMqfL12C+3b+KSwxQSzPcbvsFYm2KTgteLwG3mRlpL7Dh5\n"
+"S70nBAC1PkIl7mP4OL7vpQk9dkdQCARJLgyn5pu/pZV7He4fDLHkUr/atnYaIHk1\n"
+"15xl/ziHcBql2WmF0Uff9SuuNOi/hFCuWZSwPKsgt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FW6DKFrbOvd01EWkaP\n"
+"4PWJNW7b7OZqzK+UWzlWTgtV/2iUJtHg3+euZRdc5V9gqW17+HIAxjJVE53Syn8u\n"
+"kiJpk7HebtQo/v/pk3jtxdeJU3fY8ZAKJFl8V9aAj7ATFaAhYohzyKTRYc04F0n6\n"
+"VJDtwQkobdhq2//+5hSVrJ9wXRRF6XFVxc32NinqDEYrJUvTVayYu28Ivg4CTlts\n"
+"a+R7x92aDVT2KT+voPIGZxPYjALGa/I2hrlEYD9CiRFNBKAzRiNGAOo67SNI4hDu\n"
+"rFWRmMNOONWpIIhPBBgRAgAPBQJFm44DAhsMBQkB4TOAAAoJEJAoF+SqX03m57kA\n"
+"oMPb2o2D9gSwQFKXhamx2YdrykHOAKDqQ1tHH3ULY5cLLAKVaQtsNhVEtQ==\n"
+"=qrc1\n"
+"-----END PGP PUBLIC KEY BLOCK-----\n"
+};
+
+enum
+{
+    UpdateReleaseStatusOlder,
+    UpdateReleaseStatusEqual,
+    UpdateReleaseStatusNewer
+};
 
-    struct update_mirror_t *p_mirrors;      ///< Mirrors list
-    int i_mirrors;                          ///< Number of mirrors
-    vlc_bool_t b_mirrors;                   ///< True if we have a mirrors list
+/**
+ * Describes an update VLC release number
+ */
+struct update_release_t
+{
+    int i_major;        ///< Version major
+    int i_minor;        ///< Version minor
+    int i_revision;     ///< Version revision
+    unsigned char extra;///< Version extra
+    char* psz_url;      ///< Download URL
+    char* psz_desc;     ///< Release description
 };
 
 /**
- * The update iterator structure. Usefull to browse the update object seamlessly
+ * The update object. Stores (and caches) all information relative to updates
  */
-struct update_iterator_t
+struct update_t
 {
-    update_t *p_u;  ///< Pointer to VLC update object
-
-    int i_r;        ///< Position in the releases list
-    int i_f;        ///< Position in the release's files list
-    int i_m;        ///< Position in the mirrors list
-
-    int i_t;        ///< File type bitmask
-    int i_rs;       ///< Release status bitmask
-    int i_rt;       ///< Release type bitmask
-
-    struct
-    {
-        int i_type;             ///< Type
-        char* psz_md5;          ///< MD5 hash
-        long int l_size;        ///< Size in bytes
-        char* psz_url;          ///< Absolute URL
-        char* psz_description;  ///< Description
-    } file;         ///< Local 'copy' of the current file's information
-    struct
-    {
-        char *psz_version;      ///< Version string
-        char *psz_svn_revision; ///< SVN revision
-        int i_status;           ///< Status
-        int i_type;             ///< Type
-    } release;      ///< Local 'copy' of the current release's information
-    struct
-    {
-        char *psz_name;         ///< Name
-        char *psz_location;     ///< Geographical location
-        char *psz_type;         ///< Type (HTTP, FTP, ...)
-    } mirror;       ///< Local 'copy' of the current mirror's information
+    libvlc_int_t *p_libvlc;
+    vlc_mutex_t lock;
+    struct update_release_t release;    ///< Release (version)
+    public_key_t *p_pkey;
 };
 
 #define update_New( a ) __update_New( VLC_OBJECT( a ) )
 
 VLC_EXPORT( update_t *, __update_New, ( vlc_object_t * ) );
-VLC_EXPORT( void, update_Delete, (update_t * ) );
-VLC_EXPORT( void, update_Check, ( update_t *, vlc_bool_t ) );
-
-VLC_EXPORT( update_iterator_t *, update_iterator_New, ( update_t * ) );
-VLC_EXPORT( void, update_iterator_Delete, ( update_iterator_t * ) );
-VLC_EXPORT( unsigned int, update_iterator_Action, ( update_iterator_t *, int ) );
-VLC_EXPORT( unsigned int, update_iterator_ChooseMirrorAndFile, ( update_iterator_t *, int, int, int ) );
-VLC_EXPORT( void, update_download, ( update_iterator_t *, char * ) );
+VLC_EXPORT( void, update_Delete, ( update_t * ) );
+VLC_EXPORT( void, update_Check, ( update_t *, void (*callback)( void*, vlc_bool_t ), void * ) );
+VLC_EXPORT( int, update_CompareReleaseToCurrent, ( update_t * ) );
+VLC_EXPORT( void, update_Download, ( update_t *, char* ) );
 
 /**
  * @}
  */
 
 #endif
+
+#endif