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