]> git.sesse.net Git - vlc/blob - include/vlc_update.h
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / include / vlc_update.h
1 /*****************************************************************************
2  * vlc_update.h: VLC update and plugins download
3  *****************************************************************************
4  * Copyright © 2005-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8  *          Rafaël Carré <funman@videolanorg>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either release 2 of the License, or
13  * (at your option) any later release.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #if !defined( __LIBVLC__ )
26   #error You are not libvlc or one of its plugins. You cannot include this file
27 #endif
28
29 #ifdef UPDATE_CHECK
30
31 #ifndef _VLC_UPDATE_H
32 #define _VLC_UPDATE_H
33
34 #include <vlc/vlc.h>
35
36 #include <vlc_stream.h>     /* key & signature downloading */
37 #include <vlc_strings.h>    /* b64 decoding */
38 #include <vlc_charset.h>    /* utf8_fopen() */
39 #include <gcrypt.h>         /* cryptography and digest algorithms */
40
41 /**
42  * \defgroup update Update
43  *
44  * @{
45  */
46
47 enum    /* Public key algorithms */
48 {
49     /* we will only use DSA public keys */
50     PUBLIC_KEY_ALGO_DSA = 0x11
51 };
52
53 enum    /* Digest algorithms */
54 {
55     /* and DSA use SHA-1 digest */
56     DIGEST_ALGO_SHA1    = 0x02
57 };
58
59 enum    /* Packet types */
60 {
61     SIGNATURE_PACKET    = 0x02,
62     PUBLIC_KEY_PACKET   = 0x06,
63     USER_ID_PACKET      = 0x0d
64 };
65
66 enum    /* Signature types */
67 {
68     BINARY_SIGNATURE        = 0x00,
69     TEXT_SIGNATURE          = 0x01,
70
71     /* Public keys signatures */
72     GENERIC_KEY_SIGNATURE   = 0x10, /* No assumption of verification */
73     PERSONA_KEY_SIGNATURE   = 0x11, /* No verification has been made */
74     CASUAL_KEY_SIGNATURE    = 0x12, /* Some casual verification */
75     POSITIVE_KEY_SIGNATURE  = 0x13  /* Substantial verification */
76 };
77
78
79 enum    /* Signature subpacket types */
80 {
81     ISSUER_SUBPACKET    = 0x10
82 };
83
84
85
86 struct public_key_packet_t
87 { /* a public key packet (DSA/SHA-1) is 418 bytes */
88
89     uint8_t version;      /* we use only version 4 */
90     uint8_t timestamp[4]; /* creation time of the key */
91     uint8_t algo;         /* we only use DSA */
92     /* the multi precision integers, with their 2 bytes length header */
93     uint8_t p[2+128];
94     uint8_t q[2+20];
95     uint8_t g[2+128];
96     uint8_t y[2+128];
97 };
98
99 /* used for public key signatures */
100 struct signature_packet_v4_t
101 { /* hashed_data or unhashed_data can be empty, so the signature packet is
102    * theorically at least 54 bytes long, but always more than that. */
103
104     uint8_t version;
105     uint8_t type;
106     uint8_t public_key_algo;
107     uint8_t digest_algo;
108     uint8_t hashed_data_len[2];
109     uint8_t *hashed_data;
110     uint8_t unhashed_data_len[2];
111     uint8_t *unhashed_data;
112     uint8_t hash_verification[2];
113
114     /* The part below is made of consecutive MPIs, their number and size being
115      * public-key-algorithm dependant.
116      * But since we use DSA signatures only, we fix it. */
117     uint8_t r[2+20];
118     uint8_t s[2+20];
119 };
120
121 /* Used for binary document signatures (to be compatible with older software)
122  * DSA/SHA-1 is always 65 bytes */
123 struct signature_packet_v3_t
124 {
125     uint8_t header[2];
126     uint8_t version;            /* 3 */
127     uint8_t hashed_data_len;    /* MUST be 5 */
128     uint8_t type;
129     uint8_t timestamp[4];       /* 4 bytes scalar number */
130     uint8_t issuer_longid[8];  /* The key which signed the document */
131     uint8_t public_key_algo;    /* we only know about DSA */
132     uint8_t digest_algo;        /* and his little sister SHA-1 */
133     uint8_t hash_verification[2];/* the 2 1st bytes of the SHA-1 hash */
134
135     /* The part below is made of consecutive MPIs, their number and size being
136      * public-key-algorithm dependant.
137      * But since we use DSA signatures only, we fix it. */
138     uint8_t r[2+20];
139     uint8_t s[2+20];
140 };
141
142 typedef struct public_key_packet_t public_key_packet_t;
143 typedef struct signature_packet_v4_t signature_packet_v4_t;
144 typedef struct signature_packet_v3_t signature_packet_v3_t;
145
146 struct public_key_t
147 {
148     uint8_t longid[8];       /* Long id */
149     uint8_t *psz_username;    /* USER ID */
150
151     public_key_packet_t key;       /* Public key packet */
152
153     signature_packet_v4_t sig;     /* Signature packet, by the embedded key */
154 };
155
156 typedef struct public_key_t public_key_t;
157
158 enum
159 {
160     UpdateReleaseStatusOlder,
161     UpdateReleaseStatusEqual,
162     UpdateReleaseStatusNewer
163 };
164
165 /**
166  * Describes an update VLC release number
167  */
168 struct update_release_t
169 {
170     int i_major;        ///< Version major
171     int i_minor;        ///< Version minor
172     int i_revision;     ///< Version revision
173     unsigned char extra;///< Version extra
174     char* psz_url;      ///< Download URL
175     char* psz_desc;     ///< Release description
176 };
177
178 /**
179  * The update object. Stores (and caches) all information relative to updates
180  */
181 struct update_t
182 {
183     libvlc_int_t *p_libvlc;
184     vlc_mutex_t lock;
185     struct update_release_t release;    ///< Release (version)
186     public_key_t *p_pkey;
187 };
188
189 #define update_New( a ) __update_New( VLC_OBJECT( a ) )
190
191 VLC_EXPORT( update_t *, __update_New, ( vlc_object_t * ) );
192 VLC_EXPORT( void, update_Delete, ( update_t * ) );
193 VLC_EXPORT( void, update_Check, ( update_t *, void (*callback)( void*, bool ), void * ) );
194 VLC_EXPORT( int, update_CompareReleaseToCurrent, ( update_t * ) );
195 VLC_EXPORT( void, update_Download, ( update_t *, char* ) );
196
197 /**
198  * @}
199  */
200
201 #endif
202
203 #endif