0
|
1 <?php
|
|
2
|
|
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
4
|
|
5 /**
|
|
6 * A class representing GPG signatures
|
|
7 *
|
|
8 * This file contains a data class representing a GPG signature.
|
|
9 *
|
|
10 * PHP version 5
|
|
11 *
|
|
12 * LICENSE:
|
|
13 *
|
|
14 * This library is free software; you can redistribute it and/or modify
|
|
15 * it under the terms of the GNU Lesser General Public License as
|
|
16 * published by the Free Software Foundation; either version 2.1 of the
|
|
17 * License, or (at your option) any later version.
|
|
18 *
|
|
19 * This library is distributed in the hope that it will be useful,
|
|
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 * Lesser General Public License for more details.
|
|
23 *
|
|
24 * You should have received a copy of the GNU Lesser General Public
|
|
25 * License along with this library; if not, see
|
|
26 * <http://www.gnu.org/licenses/>
|
|
27 *
|
|
28 * @category Encryption
|
|
29 * @package Crypt_GPG
|
|
30 * @author Nathan Fredrickson <nathan@silverorange.com>
|
|
31 * @author Michael Gauthier <mike@silverorange.com>
|
|
32 * @copyright 2005-2013 silverorange
|
|
33 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
|
34 * @link http://pear.php.net/package/Crypt_GPG
|
|
35 */
|
|
36
|
|
37 /**
|
|
38 * User id class definition
|
|
39 */
|
|
40 require_once 'Crypt/GPG/UserId.php';
|
|
41
|
|
42 // {{{ class Crypt_GPG_Signature
|
|
43
|
|
44 /**
|
|
45 * A class for GPG signature information
|
|
46 *
|
|
47 * This class is used to store the results of the Crypt_GPG::verify() method.
|
|
48 *
|
|
49 * @category Encryption
|
|
50 * @package Crypt_GPG
|
|
51 * @author Nathan Fredrickson <nathan@silverorange.com>
|
|
52 * @author Michael Gauthier <mike@silverorange.com>
|
|
53 * @copyright 2005-2013 silverorange
|
|
54 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
|
55 * @link http://pear.php.net/package/Crypt_GPG
|
|
56 * @see Crypt_GPG::verify()
|
|
57 */
|
|
58 class Crypt_GPG_Signature
|
|
59 {
|
|
60 // {{{ class properties
|
|
61
|
|
62 /**
|
|
63 * A base64-encoded string containing a unique id for this signature if
|
|
64 * this signature has been verified as ok
|
|
65 *
|
|
66 * This id is used to prevent replay attacks and is not present for all
|
|
67 * types of signatures.
|
|
68 *
|
|
69 * @var string
|
|
70 */
|
|
71 private $_id = '';
|
|
72
|
|
73 /**
|
|
74 * The fingerprint of the key used to create the signature
|
|
75 *
|
|
76 * @var string
|
|
77 */
|
|
78 private $_keyFingerprint = '';
|
|
79
|
|
80 /**
|
|
81 * The id of the key used to create the signature
|
|
82 *
|
|
83 * @var string
|
|
84 */
|
|
85 private $_keyId = '';
|
|
86
|
|
87 /**
|
|
88 * The creation date of this signature
|
|
89 *
|
|
90 * This is a Unix timestamp.
|
|
91 *
|
|
92 * @var integer
|
|
93 */
|
|
94 private $_creationDate = 0;
|
|
95
|
|
96 /**
|
|
97 * The expiration date of the signature
|
|
98 *
|
|
99 * This is a Unix timestamp. If this signature does not expire, this will
|
|
100 * be zero.
|
|
101 *
|
|
102 * @var integer
|
|
103 */
|
|
104 private $_expirationDate = 0;
|
|
105
|
|
106 /**
|
|
107 * The user id associated with this signature
|
|
108 *
|
|
109 * @var Crypt_GPG_UserId
|
|
110 */
|
|
111 private $_userId = null;
|
|
112
|
|
113 /**
|
|
114 * Whether or not this signature is valid
|
|
115 *
|
|
116 * @var boolean
|
|
117 */
|
|
118 private $_isValid = false;
|
|
119
|
|
120 // }}}
|
|
121 // {{{ __construct()
|
|
122
|
|
123 /**
|
|
124 * Creates a new signature
|
|
125 *
|
|
126 * Signatures can be initialized from an array of named values. Available
|
|
127 * names are:
|
|
128 *
|
|
129 * - <kbd>string id</kbd> - the unique id of this signature.
|
|
130 * - <kbd>string fingerprint</kbd> - the fingerprint of the key used to
|
|
131 * create the signature. The fingerprint
|
|
132 * should not contain formatting
|
|
133 * characters.
|
|
134 * - <kbd>string keyId</kbd> - the id of the key used to create the
|
|
135 * the signature.
|
|
136 * - <kbd>integer creation</kbd> - the date the signature was created.
|
|
137 * This is a UNIX timestamp.
|
|
138 * - <kbd>integer expiration</kbd> - the date the signature expired. This
|
|
139 * is a UNIX timestamp. If the signature
|
|
140 * does not expire, use 0.
|
|
141 * - <kbd>boolean valid</kbd> - whether or not the signature is valid.
|
|
142 * - <kbd>string userId</kbd> - the user id associated with the
|
|
143 * signature. This may also be a
|
|
144 * {@link Crypt_GPG_UserId} object.
|
|
145 *
|
|
146 * @param Crypt_GPG_Signature|array $signature optional. Either an existing
|
|
147 * signature object, which is copied; or an array of initial values.
|
|
148 */
|
|
149 public function __construct($signature = null)
|
|
150 {
|
|
151 // copy from object
|
|
152 if ($signature instanceof Crypt_GPG_Signature) {
|
|
153 $this->_id = $signature->_id;
|
|
154 $this->_keyFingerprint = $signature->_keyFingerprint;
|
|
155 $this->_keyId = $signature->_keyId;
|
|
156 $this->_creationDate = $signature->_creationDate;
|
|
157 $this->_expirationDate = $signature->_expirationDate;
|
|
158 $this->_isValid = $signature->_isValid;
|
|
159
|
|
160 if ($signature->_userId instanceof Crypt_GPG_UserId) {
|
|
161 $this->_userId = clone $signature->_userId;
|
|
162 }
|
|
163 }
|
|
164
|
|
165 // initialize from array
|
|
166 if (is_array($signature)) {
|
|
167 if (array_key_exists('id', $signature)) {
|
|
168 $this->setId($signature['id']);
|
|
169 }
|
|
170
|
|
171 if (array_key_exists('fingerprint', $signature)) {
|
|
172 $this->setKeyFingerprint($signature['fingerprint']);
|
|
173 }
|
|
174
|
|
175 if (array_key_exists('keyId', $signature)) {
|
|
176 $this->setKeyId($signature['keyId']);
|
|
177 }
|
|
178
|
|
179 if (array_key_exists('creation', $signature)) {
|
|
180 $this->setCreationDate($signature['creation']);
|
|
181 }
|
|
182
|
|
183 if (array_key_exists('expiration', $signature)) {
|
|
184 $this->setExpirationDate($signature['expiration']);
|
|
185 }
|
|
186
|
|
187 if (array_key_exists('valid', $signature)) {
|
|
188 $this->setValid($signature['valid']);
|
|
189 }
|
|
190
|
|
191 if (array_key_exists('userId', $signature)) {
|
|
192 $userId = new Crypt_GPG_UserId($signature['userId']);
|
|
193 $this->setUserId($userId);
|
|
194 }
|
|
195 }
|
|
196 }
|
|
197
|
|
198 // }}}
|
|
199 // {{{ getId()
|
|
200
|
|
201 /**
|
|
202 * Gets the id of this signature
|
|
203 *
|
|
204 * @return string a base64-encoded string containing a unique id for this
|
|
205 * signature. This id is used to prevent replay attacks and
|
|
206 * is not present for all types of signatures.
|
|
207 */
|
|
208 public function getId()
|
|
209 {
|
|
210 return $this->_id;
|
|
211 }
|
|
212
|
|
213 // }}}
|
|
214 // {{{ getKeyFingerprint()
|
|
215
|
|
216 /**
|
|
217 * Gets the fingerprint of the key used to create this signature
|
|
218 *
|
|
219 * @return string the fingerprint of the key used to create this signature.
|
|
220 */
|
|
221 public function getKeyFingerprint()
|
|
222 {
|
|
223 return $this->_keyFingerprint;
|
|
224 }
|
|
225
|
|
226 // }}}
|
|
227 // {{{ getKeyId()
|
|
228
|
|
229 /**
|
|
230 * Gets the id of the key used to create this signature
|
|
231 *
|
|
232 * Whereas the fingerprint of the signing key may not always be available
|
|
233 * (for example if the signature is bad), the id should always be
|
|
234 * available.
|
|
235 *
|
|
236 * @return string the id of the key used to create this signature.
|
|
237 */
|
|
238 public function getKeyId()
|
|
239 {
|
|
240 return $this->_keyId;
|
|
241 }
|
|
242
|
|
243 // }}}
|
|
244 // {{{ getCreationDate()
|
|
245
|
|
246 /**
|
|
247 * Gets the creation date of this signature
|
|
248 *
|
|
249 * @return integer the creation date of this signature. This is a Unix
|
|
250 * timestamp.
|
|
251 */
|
|
252 public function getCreationDate()
|
|
253 {
|
|
254 return $this->_creationDate;
|
|
255 }
|
|
256
|
|
257 // }}}
|
|
258 // {{{ getExpirationDate()
|
|
259
|
|
260 /**
|
|
261 * Gets the expiration date of the signature
|
|
262 *
|
|
263 * @return integer the expiration date of this signature. This is a Unix
|
|
264 * timestamp. If this signature does not expire, this will
|
|
265 * be zero.
|
|
266 */
|
|
267 public function getExpirationDate()
|
|
268 {
|
|
269 return $this->_expirationDate;
|
|
270 }
|
|
271
|
|
272 // }}}
|
|
273 // {{{ getUserId()
|
|
274
|
|
275 /**
|
|
276 * Gets the user id associated with this signature
|
|
277 *
|
|
278 * @return Crypt_GPG_UserId the user id associated with this signature.
|
|
279 */
|
|
280 public function getUserId()
|
|
281 {
|
|
282 return $this->_userId;
|
|
283 }
|
|
284
|
|
285 // }}}
|
|
286 // {{{ isValid()
|
|
287
|
|
288 /**
|
|
289 * Gets whether or no this signature is valid
|
|
290 *
|
|
291 * @return boolean true if this signature is valid and false if it is not.
|
|
292 */
|
|
293 public function isValid()
|
|
294 {
|
|
295 return $this->_isValid;
|
|
296 }
|
|
297
|
|
298 // }}}
|
|
299 // {{{ setId()
|
|
300
|
|
301 /**
|
|
302 * Sets the id of this signature
|
|
303 *
|
|
304 * @param string $id a base64-encoded string containing a unique id for
|
|
305 * this signature.
|
|
306 *
|
|
307 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
308 *
|
|
309 * @see Crypt_GPG_Signature::getId()
|
|
310 */
|
|
311 public function setId($id)
|
|
312 {
|
|
313 $this->_id = strval($id);
|
|
314 return $this;
|
|
315 }
|
|
316
|
|
317 // }}}
|
|
318 // {{{ setKeyFingerprint()
|
|
319
|
|
320 /**
|
|
321 * Sets the key fingerprint of this signature
|
|
322 *
|
|
323 * @param string $fingerprint the key fingerprint of this signature. This
|
|
324 * is the fingerprint of the primary key used to
|
|
325 * create this signature.
|
|
326 *
|
|
327 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
328 */
|
|
329 public function setKeyFingerprint($fingerprint)
|
|
330 {
|
|
331 $this->_keyFingerprint = strval($fingerprint);
|
|
332 return $this;
|
|
333 }
|
|
334
|
|
335 // }}}
|
|
336 // {{{ setKeyId()
|
|
337
|
|
338 /**
|
|
339 * Sets the key id of this signature
|
|
340 *
|
|
341 * @param string $id the key id of this signature. This is the id of the
|
|
342 * primary key used to create this signature.
|
|
343 *
|
|
344 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
345 */
|
|
346 public function setKeyId($id)
|
|
347 {
|
|
348 $this->_keyId = strval($id);
|
|
349 return $this;
|
|
350 }
|
|
351
|
|
352 // }}}
|
|
353 // {{{ setCreationDate()
|
|
354
|
|
355 /**
|
|
356 * Sets the creation date of this signature
|
|
357 *
|
|
358 * @param integer $creationDate the creation date of this signature. This
|
|
359 * is a Unix timestamp.
|
|
360 *
|
|
361 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
362 */
|
|
363 public function setCreationDate($creationDate)
|
|
364 {
|
|
365 $this->_creationDate = intval($creationDate);
|
|
366 return $this;
|
|
367 }
|
|
368
|
|
369 // }}}
|
|
370 // {{{ setExpirationDate()
|
|
371
|
|
372 /**
|
|
373 * Sets the expiration date of this signature
|
|
374 *
|
|
375 * @param integer $expirationDate the expiration date of this signature.
|
|
376 * This is a Unix timestamp. Specify zero if
|
|
377 * this signature does not expire.
|
|
378 *
|
|
379 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
380 */
|
|
381 public function setExpirationDate($expirationDate)
|
|
382 {
|
|
383 $this->_expirationDate = intval($expirationDate);
|
|
384 return $this;
|
|
385 }
|
|
386
|
|
387 // }}}
|
|
388 // {{{ setUserId()
|
|
389
|
|
390 /**
|
|
391 * Sets the user id associated with this signature
|
|
392 *
|
|
393 * @param Crypt_GPG_UserId $userId the user id associated with this
|
|
394 * signature.
|
|
395 *
|
|
396 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
397 */
|
|
398 public function setUserId(Crypt_GPG_UserId $userId)
|
|
399 {
|
|
400 $this->_userId = $userId;
|
|
401 return $this;
|
|
402 }
|
|
403
|
|
404 // }}}
|
|
405 // {{{ setValid()
|
|
406
|
|
407 /**
|
|
408 * Sets whether or not this signature is valid
|
|
409 *
|
|
410 * @param boolean $isValid true if this signature is valid and false if it
|
|
411 * is not.
|
|
412 *
|
|
413 * @return Crypt_GPG_Signature the current object, for fluent interface.
|
|
414 */
|
|
415 public function setValid($isValid)
|
|
416 {
|
|
417 $this->_isValid = ($isValid) ? true : false;
|
|
418 return $this;
|
|
419 }
|
|
420
|
|
421 // }}}
|
|
422 }
|
|
423
|
|
424 // }}}
|
|
425
|
|
426 ?>
|