]> git.sesse.net Git - vlc/blob - include/vlc_update.h
Update: supports file v4 signatures
[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 /**
37  * \defgroup update Update
38  *
39  * @{
40  */
41
42 /* Go reading the rfc 4880 ! NOW !! */
43
44 /*
45  * XXX
46  *  When PGP-signing a file, we only sign a SHA-1 hash of this file
47  *
48  *  As soon as SHA-1 is broken, this method is not secure anymore, because an
49  *  attacker could generate a file with the same SHA-1 hash.
50  *
51  *  Whenever this happens, we need to use another algorithm / type of key.
52  * XXX
53  */
54
55 enum    /* Public key algorithms */
56 {
57     /* we will only use DSA public keys */
58     PUBLIC_KEY_ALGO_DSA = 0x11
59 };
60
61 enum    /* Digest algorithms */
62 {
63     /* and DSA use SHA-1 digest */
64     DIGEST_ALGO_SHA1    = 0x02
65 };
66
67 enum    /* Packet types */
68 {
69     SIGNATURE_PACKET    = 0x02,
70     PUBLIC_KEY_PACKET   = 0x06,
71     USER_ID_PACKET      = 0x0d
72 };
73
74 enum    /* Signature types */
75 {
76     BINARY_SIGNATURE        = 0x00,
77     TEXT_SIGNATURE          = 0x01,
78
79     /* Public keys signatures */
80     GENERIC_KEY_SIGNATURE   = 0x10, /* No assumption of verification */
81     PERSONA_KEY_SIGNATURE   = 0x11, /* No verification has been made */
82     CASUAL_KEY_SIGNATURE    = 0x12, /* Some casual verification */
83     POSITIVE_KEY_SIGNATURE  = 0x13  /* Substantial verification */
84 };
85
86 enum    /* Signature subpacket types */
87 {
88     ISSUER_SUBPACKET    = 0x10
89 };
90
91 struct public_key_packet_t
92 { /* a public key packet (DSA/SHA-1) is 418 bytes */
93
94     uint8_t version;      /* we use only version 4 */
95     uint8_t timestamp[4]; /* creation time of the key */
96     uint8_t algo;         /* we only use DSA */
97     /* the multi precision integers, with their 2 bytes length header */
98     uint8_t p[2+128];
99     uint8_t q[2+20];
100     uint8_t g[2+128];
101     uint8_t y[2+128];
102 };
103
104 /* used for public key and file signatures */
105 struct signature_packet_t
106 {
107     uint8_t version; /* 3 or 4 */
108
109     uint8_t type;
110     uint8_t public_key_algo;    /* DSA only */
111     uint8_t digest_algo;        /* SHA-1 only */
112
113     uint8_t hash_verification[2];
114     uint8_t issuer_longid[8];
115
116     union   /* version specific data */
117     {
118         struct
119         {
120             uint8_t hashed_data_len[2];     /* scalar number */
121             uint8_t *hashed_data;           /* hashed_data_len bytes */
122             uint8_t unhashed_data_len[2];   /* scalar number */
123             uint8_t *unhashed_data;         /* unhashed_data_len bytes */
124         } v4;
125         struct
126         {
127             uint8_t hashed_data_len;    /* MUST be 5 */
128             uint8_t timestamp[4];       /* 4 bytes scalar number */
129         } v3;
130     } specific;
131
132     /* The part below is made of consecutive MPIs, their number and size being
133      * public-key-algorithm dependant.
134      *
135      * Since we use DSA signatures only, there is 2 integers, r & s, made of:
136      *      2 bytes for the integer length (scalar number)
137      *      160 bits (20 bytes) for the integer itself
138      *
139      * Note: the integers may be less than 160 significant bits
140      */
141     uint8_t r[2+20];
142     uint8_t s[2+20];
143 };
144
145 typedef struct public_key_packet_t public_key_packet_t;
146 typedef struct signature_packet_t signature_packet_t;
147
148 struct public_key_t
149 {
150     uint8_t longid[8];       /* Long id */
151     uint8_t *psz_username;    /* USER ID */
152
153     public_key_packet_t key;       /* Public key packet */
154
155     signature_packet_t sig;     /* Signature packet, by the embedded key */
156 };
157
158 typedef struct public_key_t public_key_t;
159
160 /**
161  * Describes an update VLC release number
162  */
163 struct update_release_t
164 {
165     int i_major;        ///< Version major
166     int i_minor;        ///< Version minor
167     int i_revision;     ///< Version revision
168     unsigned char extra;///< Version extra
169     char* psz_url;      ///< Download URL
170     char* psz_desc;     ///< Release description
171 };
172
173 /**
174  * The update object. Stores (and caches) all information relative to updates
175  */
176 struct update_t
177 {
178     libvlc_int_t *p_libvlc;
179     vlc_mutex_t lock;
180     struct update_release_t release;    ///< Release (version)
181     public_key_t *p_pkey;
182 };
183
184 #define update_New( a ) __update_New( VLC_OBJECT( a ) )
185
186 VLC_EXPORT( update_t *, __update_New, ( vlc_object_t * ) );
187 VLC_EXPORT( void, update_Delete, ( update_t * ) );
188 VLC_EXPORT( void, update_Check, ( update_t *, void (*callback)( void*, bool ), void * ) );
189 VLC_EXPORT( bool, update_NeedUpgrade, ( update_t * ) );
190 VLC_EXPORT( void, update_Download, ( update_t *, char* ) );
191
192 /**
193  * @}
194  */
195
196 #endif
197
198 #endif