]> git.sesse.net Git - vlc/blob - src/misc/update.h
Swedish translation update by Daniel Nylander
[vlc] / src / misc / update.h
1 /*****************************************************************************
2  * update.h: VLC PGP update private API
3  *****************************************************************************
4  * Copyright © 2007-2008 the VideoLAN team
5  *
6  * Authors: Rafaël Carré <funman@videolanorg>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU 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 General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /* Go reading the rfc 4880 ! NOW !! */
24
25 /*
26  * XXX
27  *  When PGP-signing a file, we only sign a SHA-1 hash of this file
28  *  The DSA key size requires that we use an algorithm which produce
29  *  a 160 bits long hash
30  *  An alternative is RIPEMD160 , which you can use by giving the option
31  *      --digest-algo RIPEMD160 to GnuPG
32  *
33  *  As soon as SHA-1 is broken, this method is not secure anymore, because an
34  *  attacker could generate a file with the same SHA-1 hash.
35  *
36  *  Whenever this happens, we need to use another algorithm / type of key.
37  * XXX
38  */
39
40 enum    /* Public key algorithms */
41 {
42     /* we will only use DSA public keys */
43     PUBLIC_KEY_ALGO_DSA = 0x11
44 };
45
46 enum    /* Digest algorithms */
47 {
48     /* and DSA use SHA-1 digest */
49     DIGEST_ALGO_SHA1    = 0x02
50 };
51
52 enum    /* Packet types */
53 {
54     SIGNATURE_PACKET    = 0x02,
55     PUBLIC_KEY_PACKET   = 0x06,
56     USER_ID_PACKET      = 0x0d
57 };
58
59 enum    /* Signature types */
60 {
61     BINARY_SIGNATURE        = 0x00,
62     TEXT_SIGNATURE          = 0x01,
63
64     /* Public keys signatures */
65     GENERIC_KEY_SIGNATURE   = 0x10, /* No assumption of verification */
66     PERSONA_KEY_SIGNATURE   = 0x11, /* No verification has been made */
67     CASUAL_KEY_SIGNATURE    = 0x12, /* Some casual verification */
68     POSITIVE_KEY_SIGNATURE  = 0x13  /* Substantial verification */
69 };
70
71 enum    /* Signature subpacket types */
72 {
73     ISSUER_SUBPACKET    = 0x10
74 };
75
76 struct public_key_packet_t
77 { /* a public key packet (DSA/SHA-1) is 418 bytes */
78
79     uint8_t version;      /* we use only version 4 */
80     uint8_t timestamp[4]; /* creation time of the key */
81     uint8_t algo;         /* we only use DSA */
82     /* the multi precision integers, with their 2 bytes length header */
83     uint8_t p[2+128];
84     uint8_t q[2+20];
85     uint8_t g[2+128];
86     uint8_t y[2+128];
87 };
88
89 /* used for public key and file signatures */
90 struct signature_packet_t
91 {
92     uint8_t version; /* 3 or 4 */
93
94     uint8_t type;
95     uint8_t public_key_algo;    /* DSA only */
96     uint8_t digest_algo;        /* SHA-1 only */
97
98     uint8_t hash_verification[2];
99     uint8_t issuer_longid[8];
100
101     union   /* version specific data */
102     {
103         struct
104         {
105             uint8_t hashed_data_len[2];     /* scalar number */
106             uint8_t *hashed_data;           /* hashed_data_len bytes */
107             uint8_t unhashed_data_len[2];   /* scalar number */
108             uint8_t *unhashed_data;         /* unhashed_data_len bytes */
109         } v4;
110         struct
111         {
112             uint8_t hashed_data_len;    /* MUST be 5 */
113             uint8_t timestamp[4];       /* 4 bytes scalar number */
114         } v3;
115     } specific;
116
117 /* The part below is made of consecutive MPIs, their number and size being
118  * public-key-algorithm dependent.
119  *
120  * Since we use DSA signatures only, there is 2 integers, r & s, made of:
121  *      2 bytes for the integer length (scalar number)
122  *      160 bits (20 bytes) for the integer itself
123  *
124  * Note: the integers may be less than 160 significant bits
125  */
126     uint8_t r[2+20];
127     uint8_t s[2+20];
128 };
129
130 typedef struct public_key_packet_t public_key_packet_t;
131 typedef struct signature_packet_t signature_packet_t;
132
133 struct public_key_t
134 {
135     uint8_t longid[8];       /* Long id */
136     uint8_t *psz_username;    /* USER ID */
137
138     public_key_packet_t key;       /* Public key packet */
139
140     signature_packet_t sig;     /* Signature packet, by the embedded key */
141 };
142
143 typedef struct public_key_t public_key_t;
144
145 /**
146  * Non blocking binary download
147  */
148 typedef struct
149 {
150     VLC_COMMON_MEMBERS
151     update_t *p_update;
152     char *psz_destdir;
153 } update_download_thread_t;
154
155 /**
156  * Non blocking update availability verification
157  */
158 typedef struct
159 {
160     VLC_COMMON_MEMBERS
161     update_t *p_update;
162     void (*pf_callback)( void *, bool );
163     void *p_data;
164 } update_check_thread_t;
165 /**
166  * The update object. Stores (and caches) all information relative to updates
167  */
168 struct update_t
169 {
170     libvlc_int_t *p_libvlc;
171     vlc_mutex_t lock;
172     struct update_release_t release;    ///< Release (version)
173     public_key_t *p_pkey;
174     update_download_thread_t *p_download;
175     update_check_thread_t *p_check;
176 };
177