]> git.sesse.net Git - vlc/blob - src/misc/update.h
decoder: inline DecoderSignalWait()
[vlc] / src / misc / update.h
1 /*****************************************************************************
2  * update.h: VLC PGP update private API
3  *****************************************************************************
4  * Copyright © 2007-2008 VLC authors and VideoLAN
5  *
6  * Authors: Rafaël Carré <funman@videolanorg>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either release 2 of the License, or
11  * (at your option) any later release.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #include <vlc_update.h>
24 #include <vlc_atomic.h>
25
26 enum    /* Packet types */
27 {
28     SIGNATURE_PACKET    = 0x02,
29     PUBLIC_KEY_PACKET   = 0x06,
30     USER_ID_PACKET      = 0x0d
31 };
32
33 enum    /* Signature types */
34 {
35     BINARY_SIGNATURE        = 0x00,
36     TEXT_SIGNATURE          = 0x01,
37
38     /* Public keys signatures */
39     GENERIC_KEY_SIGNATURE   = 0x10, /* No assumption of verification */
40     PERSONA_KEY_SIGNATURE   = 0x11, /* No verification has been made */
41     CASUAL_KEY_SIGNATURE    = 0x12, /* Some casual verification */
42     POSITIVE_KEY_SIGNATURE  = 0x13  /* Substantial verification */
43 };
44
45 enum    /* Signature subpacket types */
46 {
47     ISSUER_SUBPACKET    = 0x10
48 };
49
50 struct public_key_packet_t
51 {
52
53     uint8_t version;      /* we use only version 4 */
54     uint8_t timestamp[4]; /* creation time of the key */
55     uint8_t algo;         /* DSA or RSA */
56
57     /* the multi precision integers, with their 2 bytes length header */
58     union {
59         struct {
60             uint8_t p[2+3072/8];
61             uint8_t q[2+256/8];
62             uint8_t g[2+3072/8];
63             uint8_t y[2+3072/8];
64         } dsa ;
65         struct {
66             uint8_t n[2+4096/8];
67             uint8_t e[2+4096/8];
68         } rsa;
69     } sig;
70 };
71
72 /* used for public key and file signatures */
73 struct signature_packet_t
74 {
75     uint8_t version; /* 3 or 4 */
76
77     uint8_t type;
78     uint8_t public_key_algo;    /* DSA or RSA */
79     uint8_t digest_algo;
80
81     uint8_t hash_verification[2];
82     uint8_t issuer_longid[8];
83
84     union   /* version specific data */
85     {
86         struct
87         {
88             uint8_t hashed_data_len[2];     /* scalar number */
89             uint8_t *hashed_data;           /* hashed_data_len bytes */
90             uint8_t unhashed_data_len[2];   /* scalar number */
91             uint8_t *unhashed_data;         /* unhashed_data_len bytes */
92         } v4;
93         struct
94         {
95             uint8_t hashed_data_len;    /* MUST be 5 */
96             uint8_t timestamp[4];       /* 4 bytes scalar number */
97         } v3;
98     } specific;
99
100 /* The part below is made of consecutive MPIs, their number and size being
101  * public-key-algorithm dependent.
102  */
103     union {
104         struct {
105             uint8_t r[2+256/8];
106             uint8_t s[2+256/8];
107         } dsa;
108         struct {
109             uint8_t s[2+4096/8];
110         } rsa;
111     } algo_specific;
112 };
113
114 typedef struct public_key_packet_t public_key_packet_t;
115 typedef struct signature_packet_t signature_packet_t;
116
117 struct public_key_t
118 {
119     uint8_t longid[8];       /* Long id */
120     uint8_t *psz_username;    /* USER ID */
121
122     public_key_packet_t key;       /* Public key packet */
123
124     signature_packet_t sig;     /* Signature packet, by the embedded key */
125 };
126
127 typedef struct public_key_t public_key_t;
128
129 /**
130  * Non blocking binary download
131  */
132 typedef struct
133 {
134     VLC_COMMON_MEMBERS
135
136     vlc_thread_t thread;
137     atomic_bool aborted;
138     update_t *p_update;
139     char *psz_destdir;
140 } update_download_thread_t;
141
142 /**
143  * Non blocking update availability verification
144  */
145 typedef struct
146 {
147     vlc_thread_t thread;
148
149     update_t *p_update;
150     void (*pf_callback)( void *, bool );
151     void *p_data;
152 } update_check_thread_t;
153
154 /**
155  * The update object. Stores (and caches) all information relative to updates
156  */
157 struct update_t
158 {
159     libvlc_int_t *p_libvlc;
160     vlc_mutex_t lock;
161     struct update_release_t release;    ///< Release (version)
162     public_key_t *p_pkey;
163     update_download_thread_t *p_download;
164     update_check_thread_t *p_check;
165 };
166
167 /*
168  * download a public key (the last one) from videolan server, and parse it
169  */
170 public_key_t *
171 download_key(
172         vlc_object_t *p_this, const uint8_t *p_longid,
173         const uint8_t *p_signature_issuer );
174
175 /*
176  * fill a public_key_t with public key data, including:
177  *   * public key packet
178  *   * signature packet issued by key which long id is p_sig_issuer
179  *   * user id packet
180  */
181 int
182 parse_public_key(
183         const uint8_t *p_key_data, size_t i_key_len, public_key_t *p_key,
184         const uint8_t *p_sig_issuer );
185
186 /*
187  * Verify an OpenPGP signature made on some hash, with some public key
188  */
189 int
190 verify_signature(signature_packet_t *sign, public_key_packet_t *p_key,
191         uint8_t *p_hash );
192
193 /*
194  * Download the signature associated to a document or a binary file.
195  * We're given the file's url, we just append ".asc" to it and download
196  */
197 int
198 download_signature(
199         vlc_object_t *p_this, signature_packet_t *p_sig, const char *psz_url );
200
201 /*
202  * return a hash of a text
203  */
204 uint8_t *
205 hash_from_text(
206         const char *psz_text, signature_packet_t *p_sig );
207
208 /*
209  * return a hash of a file
210  */
211 uint8_t *
212 hash_from_file(
213         const char *psz_file, signature_packet_t *p_sig );
214
215 /*
216  * return a hash of a public key
217  */
218 uint8_t *
219 hash_from_public_key( public_key_t *p_pkey );