dvbpsi: add sys/types.h as appropriate
[vlc.git] / src / misc / update.h
blob0d5b5a2fa38f27b104f50281bb6799e85995ff39
1 /*****************************************************************************
2 * update.h: VLC PGP update private API
3 *****************************************************************************
4 * Copyright © 2007-2008 VLC authors and VideoLAN
6 * Authors: Rafaël Carré <funman@videolanorg>
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.
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.
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 *****************************************************************************/
23 #include <vlc_update.h>
24 #include <vlc_atomic.h>
26 enum /* Packet types */
28 SIGNATURE_PACKET = 0x02,
29 PUBLIC_KEY_PACKET = 0x06,
30 USER_ID_PACKET = 0x0d
33 enum /* Signature types */
35 BINARY_SIGNATURE = 0x00,
36 TEXT_SIGNATURE = 0x01,
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 */
45 enum /* Signature subpacket types */
47 ISSUER_SUBPACKET = 0x10
50 struct public_key_packet_t
53 uint8_t version; /* we use only version 4 */
54 uint8_t timestamp[4]; /* creation time of the key */
55 uint8_t algo; /* we only use DSA */
56 /* the multi precision integers, with their 2 bytes length header */
57 uint8_t p[2+3072/8];
58 uint8_t q[2+256/8];
59 uint8_t g[2+3072/8];
60 uint8_t y[2+3072/8];
63 /* used for public key and file signatures */
64 struct signature_packet_t
66 uint8_t version; /* 3 or 4 */
68 uint8_t type;
69 uint8_t public_key_algo; /* DSA only */
70 uint8_t digest_algo;
72 uint8_t hash_verification[2];
73 uint8_t issuer_longid[8];
75 union /* version specific data */
77 struct
79 uint8_t hashed_data_len[2]; /* scalar number */
80 uint8_t *hashed_data; /* hashed_data_len bytes */
81 uint8_t unhashed_data_len[2]; /* scalar number */
82 uint8_t *unhashed_data; /* unhashed_data_len bytes */
83 } v4;
84 struct
86 uint8_t hashed_data_len; /* MUST be 5 */
87 uint8_t timestamp[4]; /* 4 bytes scalar number */
88 } v3;
89 } specific;
91 /* The part below is made of consecutive MPIs, their number and size being
92 * public-key-algorithm dependent.
94 * Since we use DSA signatures only, there is 2 integers, r & s.
95 * They range from 160 for 1k keys to 256 bits for 3k keys.
97 uint8_t r[2+256/8];
98 uint8_t s[2+256/8];
101 typedef struct public_key_packet_t public_key_packet_t;
102 typedef struct signature_packet_t signature_packet_t;
104 struct public_key_t
106 uint8_t longid[8]; /* Long id */
107 uint8_t *psz_username; /* USER ID */
109 public_key_packet_t key; /* Public key packet */
111 signature_packet_t sig; /* Signature packet, by the embedded key */
114 typedef struct public_key_t public_key_t;
117 * Non blocking binary download
119 typedef struct
121 VLC_COMMON_MEMBERS
123 vlc_thread_t thread;
124 atomic_bool aborted;
125 update_t *p_update;
126 char *psz_destdir;
127 } update_download_thread_t;
130 * Non blocking update availability verification
132 typedef struct
134 vlc_thread_t thread;
136 update_t *p_update;
137 void (*pf_callback)( void *, bool );
138 void *p_data;
139 } update_check_thread_t;
142 * The update object. Stores (and caches) all information relative to updates
144 struct update_t
146 libvlc_int_t *p_libvlc;
147 vlc_mutex_t lock;
148 struct update_release_t release; ///< Release (version)
149 public_key_t *p_pkey;
150 update_download_thread_t *p_download;
151 update_check_thread_t *p_check;
155 * download a public key (the last one) from videolan server, and parse it
157 public_key_t *
158 download_key(
159 vlc_object_t *p_this, const uint8_t *p_longid,
160 const uint8_t *p_signature_issuer );
163 * fill a public_key_t with public key data, including:
164 * * public key packet
165 * * signature packet issued by key which long id is p_sig_issuer
166 * * user id packet
169 parse_public_key(
170 const uint8_t *p_key_data, size_t i_key_len, public_key_t *p_key,
171 const uint8_t *p_sig_issuer );
174 * Verify an OpenPGP signature made on some hash, with some DSA public key
177 verify_signature(signature_packet_t *sign, public_key_packet_t *p_key,
178 uint8_t *p_hash );
181 * Download the signature associated to a document or a binary file.
182 * We're given the file's url, we just append ".asc" to it and download
185 download_signature(
186 vlc_object_t *p_this, signature_packet_t *p_sig, const char *psz_url );
189 * return a hash of a text
191 uint8_t *
192 hash_from_text(
193 const char *psz_text, signature_packet_t *p_sig );
196 * return a hash of a file
198 uint8_t *
199 hash_from_file(
200 const char *psz_file, signature_packet_t *p_sig );
203 * return a hash of a public key
205 uint8_t *
206 hash_from_public_key( public_key_t *p_pkey );