annotate vendor/pear/crypt_gpg/Crypt/GPG.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents 1e000243b222
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 * Crypt_GPG is a package to use GPG from PHP
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 * This package provides an object oriented interface to GNU Privacy
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 * Guard (GPG). It requires the GPG executable to be on the system.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 * Though GPG can support symmetric-key cryptography, this package is intended
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 * only to facilitate public-key cryptography.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 * This file contains the main GPG class. The class in this file lets you
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 * encrypt, decrypt, sign and verify data; import and delete keys; and perform
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 * other useful GPG tasks.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 * Example usage:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 * <code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 * <?php
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 * // encrypt some data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 * $gpg = new Crypt_GPG();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 * $gpg->addEncryptKey($mySecretKeyId);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * $encryptedData = $gpg->encrypt($data);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * ?>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 * </code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 * PHP version 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 * LICENSE:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 * This library is free software; you can redistribute it and/or modify
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 * it under the terms of the GNU Lesser General Public License as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 * published by the Free Software Foundation; either version 2.1 of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 * License, or (at your option) any later version.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 * This library is distributed in the hope that it will be useful,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 * Lesser General Public License for more details.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 * You should have received a copy of the GNU Lesser General Public
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 * License along with this library; if not, see
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 * <http://www.gnu.org/licenses/>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 * @category Encryption
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 * @package Crypt_GPG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 * @author Nathan Fredrickson <nathan@silverorange.com>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 * @author Michael Gauthier <mike@silverorange.com>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 * @copyright 2005-2013 silverorange
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 * @link http://pear.php.net/package/Crypt_GPG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 * @link http://pear.php.net/manual/en/package.encryption.crypt-gpg.php
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 * @link http://www.gnupg.org/
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 * Base class for GPG methods
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 require_once 'Crypt/GPGAbstract.php';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 * GPG exception classes.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 require_once 'Crypt/GPG/Exceptions.php';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 // {{{ class Crypt_GPG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 * A class to use GPG from PHP
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 * This class provides an object oriented interface to GNU Privacy Guard (GPG).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 * Though GPG can support symmetric-key cryptography, this class is intended
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 * only to facilitate public-key cryptography.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 * @category Encryption
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 * @package Crypt_GPG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 * @author Nathan Fredrickson <nathan@silverorange.com>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 * @author Michael Gauthier <mike@silverorange.com>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 * @copyright 2005-2013 silverorange
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 * @link http://pear.php.net/package/Crypt_GPG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 * @link http://www.gnupg.org/
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 class Crypt_GPG extends Crypt_GPGAbstract
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 // {{{ class constants for data signing modes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 * Signing mode for normal signing of data. The signed message will not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 * be readable without special software.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 * This is the default signing mode.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 * @see Crypt_GPG::sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 * @see Crypt_GPG::signFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 const SIGN_MODE_NORMAL = 1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 * Signing mode for clearsigning data. Clearsigned signatures are ASCII
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 * armored data and are readable without special software. If the signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 * message is unencrypted, the message will still be readable. The message
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 * text will be in the original encoding.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 * @see Crypt_GPG::sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 * @see Crypt_GPG::signFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 const SIGN_MODE_CLEAR = 2;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 * Signing mode for creating a detached signature. When using detached
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 * signatures, only the signature data is returned. The original message
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 * text may be distributed separately from the signature data. This is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 * useful for miltipart/signed email messages as per
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 * {@link http://www.ietf.org/rfc/rfc3156.txt RFC 3156}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 * @see Crypt_GPG::sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 * @see Crypt_GPG::signFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 const SIGN_MODE_DETACHED = 3;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 // {{{ class constants for fingerprint formats
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 * No formatting is performed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 * Example: C3BC615AD9C766E5A85C1F2716D27458B1BBA1C4
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 * @see Crypt_GPG::getFingerprint()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 const FORMAT_NONE = 1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 * Fingerprint is formatted in the format used by the GnuPG gpg command's
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 * default output.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 * Example: C3BC 615A D9C7 66E5 A85C 1F27 16D2 7458 B1BB A1C4
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 * @see Crypt_GPG::getFingerprint()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 const FORMAT_CANONICAL = 2;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 * Fingerprint is formatted in the format used when displaying X.509
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 * certificates
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 * Example: C3:BC:61:5A:D9:C7:66:E5:A8:5C:1F:27:16:D2:74:58:B1:BB:A1:C4
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 * @see Crypt_GPG::getFingerprint()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 const FORMAT_X509 = 3;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 // {{{ class constants for boolean options
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 * Use to specify ASCII armored mode for returned data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 const ARMOR_ASCII = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 * Use to specify binary mode for returned data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 const ARMOR_BINARY = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 * Use to specify that line breaks in signed text should be normalized
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 const TEXT_NORMALIZED = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175 * Use to specify that line breaks in signed text should not be normalized
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 const TEXT_RAW = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 // {{{ protected class properties
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 * Keys used to encrypt
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 * The array is of the form:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 * <code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 * array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 * $key_id => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 * 'fingerprint' => $fingerprint,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 * 'passphrase' => null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 * )
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 * );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 * </code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 * @see Crypt_GPG::addEncryptKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 * @see Crypt_GPG::clearEncryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 protected $encryptKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 * Keys used to decrypt
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 * The array is of the form:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 * <code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 * array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 * $key_id => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 * 'fingerprint' => $fingerprint,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 * 'passphrase' => $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 * )
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 * );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 * </code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 * @see Crypt_GPG::addSignKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 * @see Crypt_GPG::clearSignKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 protected $signKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 * Keys used to sign
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 * The array is of the form:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 * <code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 * array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 * $key_id => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 * 'fingerprint' => $fingerprint,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 * 'passphrase' => $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 * )
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 * );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 * </code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 * @see Crypt_GPG::addDecryptKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 * @see Crypt_GPG::clearDecryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 protected $decryptKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 * Passphrases used on import/export of private keys in GnuPG 2.1
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 * The array is of the form:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 * <code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 * array($key_id => $passphrase);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 * </code>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 * @see Crypt_GPG::addPassphrase()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 * @see Crypt_GPG::clearPassphrases()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 protected $passphrases = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 // {{{ importKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 * Imports a public or private key into the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 * Keys may be removed from the keyring using
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260 * {@link Crypt_GPG::deletePublicKey()} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 * {@link Crypt_GPG::deletePrivateKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 * @param string $data the key data to be imported.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 * @return array an associative array containing the following elements:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 * - <kbd>fingerprint</kbd> - the fingerprint of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 * imported key,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 * - <kbd>public_imported</kbd> - the number of public
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 * keys imported,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 * - <kbd>public_unchanged</kbd> - the number of unchanged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 * public keys,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 * - <kbd>private_imported</kbd> - the number of private
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 * keys imported,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 * - <kbd>private_unchanged</kbd> - the number of unchanged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 * private keys.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 * @throws Crypt_GPG_NoDataException if the key data is missing or if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 * data is is not valid key data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 * {@link Crypt_GPG::addPassphrase()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 * @see Crypt_GPG::addPassphrase()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 * @see Crypt_GPG::clearPassphrases()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 public function importKey($data)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 return $this->_importKey($data, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 // {{{ importKeyFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 * Imports a public or private key file into the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 * Keys may be removed from the keyring using
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 * {@link Crypt_GPG::deletePublicKey()} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 * {@link Crypt_GPG::deletePrivateKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 * @param string $filename the key file to be imported.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 * @return array an associative array containing the following elements:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 * - <kbd>fingerprint</kbd> - the fingerprint of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 * imported key,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 * - <kbd>public_imported</kbd> - the number of public
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 * keys imported,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 * - <kbd>public_unchanged</kbd> - the number of unchanged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 * public keys,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315 * - <kbd>private_imported</kbd> - the number of private
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 * keys imported,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 * - <kbd>private_unchanged</kbd> - the number of unchanged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 * private keys.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 * private keys.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 * @throws Crypt_GPG_NoDataException if the key data is missing or if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 * data is is not valid key data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 * @throws Crypt_GPG_FileException if the key file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 * {@link Crypt_GPG::addPassphrase()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 public function importKeyFile($filename)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 return $this->_importKey($filename, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 // {{{ exportPrivateKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 * Exports a private key from the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 * The exported key remains on the keyring. To delete the key, use
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 * {@link Crypt_GPG::deletePrivateKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 * If more than one key fingerprint is available for the specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 * <kbd>$keyId</kbd> (for example, if you use a non-unique uid) only the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 * first private key is exported.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 * @param string $keyId either the full uid of the private key, the email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 * part of the uid of the private key or the key id of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 * the private key. For example,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 * "Test User (example) <test@example.com>",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 * "test@example.com" or a hexadecimal string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357 * @param boolean $armor optional. If true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 * otherwise, binary data is returned. Defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359 * true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 * @return string the private key data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 * @throws Crypt_GPG_KeyNotFoundException if a private key with the given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 * <kbd>$keyId</kbd> is not found.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 * {@link Crypt_GPG::addPassphrase()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 public function exportPrivateKey($keyId, $armor = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 return $this->_exportKey($keyId, $armor, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 // {{{ exportPublicKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 * Exports a public key from the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 * The exported key remains on the keyring. To delete the public key, use
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 * {@link Crypt_GPG::deletePublicKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 * If more than one key fingerprint is available for the specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 * <kbd>$keyId</kbd> (for example, if you use a non-unique uid) only the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 * first public key is exported.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 * @param string $keyId either the full uid of the public key, the email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 * part of the uid of the public key or the key id of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 * the public key. For example,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 * "Test User (example) <test@example.com>",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 * "test@example.com" or a hexadecimal string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 * @param boolean $armor optional. If true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 * otherwise, binary data is returned. Defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 * true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 * @return string the public key data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 * @throws Crypt_GPG_KeyNotFoundException if a public key with the given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 * <kbd>$keyId</kbd> is not found.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 public function exportPublicKey($keyId, $armor = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 return $this->_exportKey($keyId, $armor, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 // {{{ deletePublicKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 * Deletes a public key from the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421 * If more than one key fingerprint is available for the specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 * <kbd>$keyId</kbd> (for example, if you use a non-unique uid) only the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 * first public key is deleted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 * The private key must be deleted first or an exception will be thrown.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 * In GnuPG >= 2.1 this limitation does not exist.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 * See {@link Crypt_GPG::deletePrivateKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 * @param string $keyId either the full uid of the public key, the email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 * part of the uid of the public key or the key id of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 * the public key. For example,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 * "Test User (example) <test@example.com>",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 * "test@example.com" or a hexadecimal string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 * @throws Crypt_GPG_KeyNotFoundException if a public key with the given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 * <kbd>$keyId</kbd> is not found.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 * @throws Crypt_GPG_DeletePrivateKeyException if the specified public key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 * has an associated private key on the keyring. The private key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 * must be deleted first (when using GnuPG < 2.1).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448 public function deletePublicKey($keyId)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 $fingerprint = $this->getFingerprint($keyId);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 if ($fingerprint === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 'Public key not found: ' . $keyId,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 self::ERROR_KEY_NOT_FOUND,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 $keyId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460 $operation = '--delete-key ' . escapeshellarg($fingerprint);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 $arguments = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 '--batch',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 '--yes'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 $this->engine->setOperation($operation, $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 // {{{ deletePrivateKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 * Deletes a private key from the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 * If more than one key fingerprint is available for the specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 * <kbd>$keyId</kbd> (for example, if you use a non-unique uid) only the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 * first private key is deleted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481 * Calls GPG with the <kbd>--delete-secret-key</kbd> command.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483 * @param string $keyId either the full uid of the private key, the email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 * part of the uid of the private key or the key id of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 * the private key. For example,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 * "Test User (example) <test@example.com>",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487 * "test@example.com" or a hexadecimal string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 * @throws Crypt_GPG_KeyNotFoundException if a private key with the given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 * <kbd>$keyId</kbd> is not found.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 public function deletePrivateKey($keyId)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 $fingerprint = $this->getFingerprint($keyId);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 if ($fingerprint === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 'Private key not found: ' . $keyId,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505 self::ERROR_KEY_NOT_FOUND,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506 $keyId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 $operation = '--delete-secret-key ' . escapeshellarg($fingerprint);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 $arguments = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 '--batch',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513 '--yes'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 $this->engine->setOperation($operation, $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 // {{{ getKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525 * Gets the available keys in the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527 * Calls GPG with the <kbd>--list-keys</kbd> command and grabs keys. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 * the first section of <b>doc/DETAILS</b> in the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 * {@link http://www.gnupg.org/download/ GPG package} for a detailed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 * description of how the GPG command output is parsed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 * @param string $keyId optional. Only keys with that match the specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 * pattern are returned. The pattern may be part of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 * a user id, a key id or a key fingerprint. If not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 * specified, all keys are returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 * @return array an array of {@link Crypt_GPG_Key} objects. If no keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538 * match the specified <kbd>$keyId</kbd> an empty array is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 * returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 * @see Crypt_GPG_Key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 public function getKeys($keyId = '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549 return parent::_getKeys($keyId);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 // {{{ getFingerprint()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 * Gets a key fingerprint from the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 * If more than one key fingerprint is available (for example, if you use
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 * a non-unique user id) only the first key fingerprint is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 * Calls the GPG <kbd>--list-keys</kbd> command with the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 * <kbd>--with-fingerprint</kbd> option to retrieve a public key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 * fingerprint.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 * @param string $keyId either the full user id of the key, the email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 * part of the user id of the key, or the key id of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 * the key. For example,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568 * "Test User (example) <test@example.com>",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 * "test@example.com" or a hexadecimal string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 * @param integer $format optional. How the fingerprint should be formatted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 * Use {@link Crypt_GPG::FORMAT_X509} for X.509
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 * certificate format,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 * {@link Crypt_GPG::FORMAT_CANONICAL} for the format
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 * used by GnuPG output and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 * {@link Crypt_GPG::FORMAT_NONE} for no formatting.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576 * Defaults to <code>Crypt_GPG::FORMAT_NONE</code>.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 * @return string the fingerprint of the key, or null if no fingerprint
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 * is found for the given <kbd>$keyId</kbd>.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 public function getFingerprint($keyId, $format = self::FORMAT_NONE)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587 $output = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588 $operation = '--list-keys ' . escapeshellarg($keyId);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 $arguments = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 '--with-colons',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591 '--with-fingerprint'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 $this->engine->setOutput($output);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 $this->engine->setOperation($operation, $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 $fingerprint = null;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601 foreach (explode(PHP_EOL, $output) as $line) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 if (mb_substr($line, 0, 3, '8bit') == 'fpr') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 $lineExp = explode(':', $line);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 $fingerprint = $lineExp[9];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 switch ($format) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 case self::FORMAT_CANONICAL:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 $fingerprintExp = str_split($fingerprint, 4);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609 $format = '%s %s %s %s %s %s %s %s %s %s';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 $fingerprint = vsprintf($format, $fingerprintExp);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 case self::FORMAT_X509:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614 $fingerprintExp = str_split($fingerprint, 2);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615 $fingerprint = implode(':', $fingerprintExp);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 return $fingerprint;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 // {{{ getLastSignatureInfo()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 * Get information about the last signature that was created.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632 * @return Crypt_GPG_SignatureCreationInfo
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 public function getLastSignatureInfo()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 return $this->engine->getProcessData('SignatureInfo');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 // {{{ encrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 * Encrypts string data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 * Data is ASCII armored by default but may optionally be returned as
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 * binary.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648 * @param string $data the data to be encrypted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 * @param boolean $armor optional. If true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 * otherwise, binary data is returned. Defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651 * true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 * @return string the encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 * See {@link Crypt_GPG::addEncryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662 * @sensitive $data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664 public function encrypt($data, $armor = self::ARMOR_ASCII)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 return $this->_encrypt($data, false, null, $armor);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 // {{{ encryptFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 * Encrypts a file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675 * Encrypted data is ASCII armored by default but may optionally be saved
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676 * as binary.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678 * @param string $filename the filename of the file to encrypt.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 * @param string $encryptedFile optional. The filename of the file in
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
680 * which to store the encrypted data. If null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681 * or unspecified, the encrypted data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682 * returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 * @param boolean $armor optional. If true, ASCII armored data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 * returned; otherwise, binary data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 * returned. Defaults to true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687 * @return void|string if the <kbd>$encryptedFile</kbd> parameter is null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 * a string containing the encrypted data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691 * See {@link Crypt_GPG::addEncryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
693 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 public function encryptFile(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 $filename,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702 $encryptedFile = null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 $armor = self::ARMOR_ASCII
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 return $this->_encrypt($filename, true, $encryptedFile, $armor);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709 // {{{ encryptAndSign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 * Encrypts and signs data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714 * Data is encrypted and signed in a single pass.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716 * NOTE: Until GnuPG version 1.4.10, it was not possible to verify
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 * encrypted-signed data without decrypting it at the same time. If you try
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 * to use {@link Crypt_GPG::verify()} method on encrypted-signed data with
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 * earlier GnuPG versions, you will get an error. Please use
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720 * {@link Crypt_GPG::decryptAndVerify()} to verify encrypted-signed data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 * @param string $data the data to be encrypted and signed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723 * @param boolean $armor optional. If true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 * otherwise, binary data is returned. Defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725 * true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 * @return string the encrypted signed data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730 * or if no signing key is specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 * {@link Crypt_GPG::addEncryptKey()} and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732 * {@link Crypt_GPG::addSignKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734 * @throws Crypt_GPG_BadPassphraseException if a specified passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735 * incorrect or if a required passphrase is not specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741 * @see Crypt_GPG::decryptAndVerify()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 public function encryptAndSign($data, $armor = self::ARMOR_ASCII)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745 return $this->_encryptAndSign($data, false, null, $armor);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
746 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 // {{{ encryptAndSignFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752 * Encrypts and signs a file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 * The file is encrypted and signed in a single pass.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 * NOTE: Until GnuPG version 1.4.10, it was not possible to verify
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 * encrypted-signed files without decrypting them at the same time. If you
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 * try to use {@link Crypt_GPG::verify()} method on encrypted-signed files
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 * with earlier GnuPG versions, you will get an error. Please use
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 * {@link Crypt_GPG::decryptAndVerifyFile()} to verify encrypted-signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 * files.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763 * @param string $filename the name of the file containing the data to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 * be encrypted and signed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 * @param string $signedFile optional. The name of the file in which the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 * encrypted, signed data should be stored. If
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 * null or unspecified, the encrypted, signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 * data is returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769 * @param boolean $armor optional. If true, ASCII armored data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 * returned; otherwise, binary data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771 * Defaults to true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773 * @return void|string if the <kbd>$signedFile</kbd> parameter is null, a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 * string containing the encrypted, signed data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 * returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 * or if no signing key is specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779 * {@link Crypt_GPG::addEncryptKey()} and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 * {@link Crypt_GPG::addSignKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782 * @throws Crypt_GPG_BadPassphraseException if a specified passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 * incorrect or if a required passphrase is not specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792 * @see Crypt_GPG::decryptAndVerifyFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 public function encryptAndSignFile(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 $filename,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 $signedFile = null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 $armor = self::ARMOR_ASCII
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799 return $this->_encryptAndSign($filename, true, $signedFile, $armor);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 // {{{ decrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 * Decrypts string data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808 * This method assumes the required private key is available in the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 * and throws an exception if the private key is not available. To add a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 * private key to the keyring, use the {@link Crypt_GPG::importKey()} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 * {@link Crypt_GPG::importKeyFile()} methods.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 * @param string $encryptedData the data to be decrypted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 * @return string the decrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 * @throws Crypt_GPG_KeyNotFoundException if the private key needed to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 * decrypt the data is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 * @throws Crypt_GPG_NoDataException if specified data does not contain
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 * GPG encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 * {@link Crypt_GPG::addDecryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 public function decrypt($encryptedData)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 return $this->_decrypt($encryptedData, false, null);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837 // {{{ decryptFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 * Decrypts a file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842 * This method assumes the required private key is available in the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 * and throws an exception if the private key is not available. To add a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 * private key to the keyring, use the {@link Crypt_GPG::importKey()} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845 * {@link Crypt_GPG::importKeyFile()} methods.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 * @param string $encryptedFile the name of the encrypted file data to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 * decrypt.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849 * @param string $decryptedFile optional. The name of the file to which the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 * decrypted data should be written. If null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 * or unspecified, the decrypted data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 * returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 * @return void|string if the <kbd>$decryptedFile</kbd> parameter is null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 * a string containing the decrypted data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857 * @throws Crypt_GPG_KeyNotFoundException if the private key needed to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 * decrypt the data is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 * @throws Crypt_GPG_NoDataException if specified data does not contain
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 * GPG encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 * {@link Crypt_GPG::addDecryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 public function decryptFile($encryptedFile, $decryptedFile = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 return $this->_decrypt($encryptedFile, true, $decryptedFile);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 // {{{ decryptAndVerify()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 * Decrypts and verifies string data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885 * This method assumes the required private key is available in the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 * and throws an exception if the private key is not available. To add a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 * private key to the keyring, use the {@link Crypt_GPG::importKey()} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 * {@link Crypt_GPG::importKeyFile()} methods.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 * @param string $encryptedData the encrypted, signed data to be decrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 * and verified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 * @param boolean $ignoreVerifyErrors enables ignoring of signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 * verification errors caused by missing public key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 * When enabled Crypt_GPG_KeyNotFoundException
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 * will not be thrown.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 * @return array two element array. The array has an element 'data'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 * containing the decrypted data and an element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 * 'signatures' containing an array of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 * {@link Crypt_GPG_Signature} objects for the signed data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 * @throws Crypt_GPG_KeyNotFoundException if the private key needed to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 * decrypt the data or the public key to verify the signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 * is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 * @throws Crypt_GPG_NoDataException if specified data does not contain
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 * GPG encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 * {@link Crypt_GPG::addDecryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 public function decryptAndVerify($encryptedData, $ignoreVerifyErrors = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 return $this->_decryptAndVerify($encryptedData, false, null, $ignoreVerifyErrors);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923 // {{{ decryptAndVerifyFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 * Decrypts and verifies a signed, encrypted file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 * This method assumes the required private key is available in the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929 * and throws an exception if the private key is not available. To add a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930 * private key to the keyring, use the {@link Crypt_GPG::importKey()} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 * {@link Crypt_GPG::importKeyFile()} methods.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933 * @param string $encryptedFile the name of the signed, encrypted file to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 * to decrypt and verify.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 * @param string $decryptedFile optional. The name of the file to which the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936 * decrypted data should be written. If null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 * or unspecified, the decrypted data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 * returned in the results array.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 * @param boolean $ignoreVerifyErrors enables ignoring of signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 * verification errors caused by missing public key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 * When enabled Crypt_GPG_KeyNotFoundException
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 * will not be thrown.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 * @return array two element array. The array has an element 'data'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 * containing the decrypted data and an element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 * 'signatures' containing an array of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 * {@link Crypt_GPG_Signature} objects for the signed data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948 * If the decrypted data is written to a file, the 'data'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 * element is null.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 * @throws Crypt_GPG_KeyNotFoundException if the private key needed to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952 * decrypt the data or the public key to verify the signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 * is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 * @throws Crypt_GPG_NoDataException if specified data does not contain
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 * GPG encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960 * {@link Crypt_GPG::addDecryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 public function decryptAndVerifyFile($encryptedFile, $decryptedFile = null, $ignoreVerifyErrors = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 return $this->_decryptAndVerify($encryptedFile, true, $decryptedFile, $ignoreVerifyErrors);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 // {{{ sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 * Signs data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 * Data may be signed using any one of the three available signing modes:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981 * - {@link Crypt_GPG::SIGN_MODE_NORMAL}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 * - {@link Crypt_GPG::SIGN_MODE_CLEAR}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983 * - {@link Crypt_GPG::SIGN_MODE_DETACHED}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 * @param string $data the data to be signed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 * @param boolean $mode optional. The data signing mode to use. Should
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987 * be one of {@link Crypt_GPG::SIGN_MODE_NORMAL},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988 * {@link Crypt_GPG::SIGN_MODE_CLEAR} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 * {@link Crypt_GPG::SIGN_MODE_DETACHED}. If not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 * specified, defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 * <kbd>Crypt_GPG::SIGN_MODE_NORMAL</kbd>.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 * @param boolean $armor optional. If true, ASCII armored data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 * returned; otherwise, binary data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 * Defaults to true. This has no effect if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995 * mode <kbd>Crypt_GPG::SIGN_MODE_CLEAR</kbd> is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 * used.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 * @param boolean $textmode optional. If true, line-breaks in signed data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998 * are normalized. Use this option when signing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 * e-mail, or for greater compatibility between
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 * systems with different line-break formats.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 * Defaults to false. This has no effect if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 * mode <kbd>Crypt_GPG::SIGN_MODE_CLEAR</kbd> is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 * used as clear-signing always uses textmode.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 * @return string the signed data, or the signature data if a detached
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006 * signature is requested.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 * @throws Crypt_GPG_KeyNotFoundException if no signing key is specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 * See {@link Crypt_GPG::addSignKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 * @throws Crypt_GPG_BadPassphraseException if a specified passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012 * incorrect or if a required passphrase is not specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 public function sign(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019 $data,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 $mode = self::SIGN_MODE_NORMAL,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 $armor = self::ARMOR_ASCII,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 $textmode = self::TEXT_RAW
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 return $this->_sign($data, false, null, $mode, $armor, $textmode);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 // {{{ signFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 * Signs a file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 * The file may be signed using any one of the three available signing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 * modes:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 * - {@link Crypt_GPG::SIGN_MODE_NORMAL}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036 * - {@link Crypt_GPG::SIGN_MODE_CLEAR}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 * - {@link Crypt_GPG::SIGN_MODE_DETACHED}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 * @param string $filename the name of the file containing the data to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040 * be signed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 * @param string $signedFile optional. The name of the file in which the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042 * signed data should be stored. If null or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 * unspecified, the signed data is returned as a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 * string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045 * @param boolean $mode optional. The data signing mode to use. Should
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 * be one of {@link Crypt_GPG::SIGN_MODE_NORMAL},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 * {@link Crypt_GPG::SIGN_MODE_CLEAR} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048 * {@link Crypt_GPG::SIGN_MODE_DETACHED}. If not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 * specified, defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 * <kbd>Crypt_GPG::SIGN_MODE_NORMAL</kbd>.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 * @param boolean $armor optional. If true, ASCII armored data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052 * returned; otherwise, binary data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 * Defaults to true. This has no effect if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 * mode <kbd>Crypt_GPG::SIGN_MODE_CLEAR</kbd> is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 * used.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 * @param boolean $textmode optional. If true, line-breaks in signed data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 * are normalized. Use this option when signing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058 * e-mail, or for greater compatibility between
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 * systems with different line-break formats.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 * Defaults to false. This has no effect if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 * mode <kbd>Crypt_GPG::SIGN_MODE_CLEAR</kbd> is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 * used as clear-signing always uses textmode.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064 * @return void|string if the <kbd>$signedFile</kbd> parameter is null, a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065 * string containing the signed data (or the signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 * data if a detached signature is requested) is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 * returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 * @throws Crypt_GPG_KeyNotFoundException if no signing key is specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 * See {@link Crypt_GPG::addSignKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 * @throws Crypt_GPG_BadPassphraseException if a specified passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 * incorrect or if a required passphrase is not specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082 public function signFile(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083 $filename,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 $signedFile = null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 $mode = self::SIGN_MODE_NORMAL,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 $armor = self::ARMOR_ASCII,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087 $textmode = self::TEXT_RAW
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 return $this->_sign(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090 $filename,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091 true,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092 $signedFile,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 $mode,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 $armor,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095 $textmode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100 // {{{ verify()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 * Verifies signed data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 * The {@link Crypt_GPG::decrypt()} method may be used to get the original
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 * message if the signed data is not clearsigned and does not use a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107 * detached signature.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 * @param string $signedData the signed data to be verified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 * @param string $signature optional. If verifying data signed using a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111 * detached signature, this must be the detached
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 * signature data. The data that was signed is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 * specified in <kbd>$signedData</kbd>.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 * @return array an array of {@link Crypt_GPG_Signature} objects for the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116 * signed data. For each signature that is valid, the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 * {@link Crypt_GPG_Signature::isValid()} will return true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 * @throws Crypt_GPG_KeyNotFoundException if the public key needed for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120 * signature verification is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122 * @throws Crypt_GPG_NoDataException if the provided data is not signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 * data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1126 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1127 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1128 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1129 * @see Crypt_GPG_Signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1130 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1131 public function verify($signedData, $signature = '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1132 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133 return $this->_verify($signedData, false, $signature);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137 // {{{ verifyFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140 * Verifies a signed file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 * The {@link Crypt_GPG::decryptFile()} method may be used to get the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 * original message if the signed data is not clearsigned and does not use
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 * a detached signature.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 * @param string $filename the signed file to be verified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147 * @param string $signature optional. If verifying a file signed using a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148 * detached signature, this must be the detached
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 * signature data. The file that was signed is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150 * specified in <kbd>$filename</kbd>.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152 * @return array an array of {@link Crypt_GPG_Signature} objects for the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 * signed data. For each signature that is valid, the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154 * {@link Crypt_GPG_Signature::isValid()} will return true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156 * @throws Crypt_GPG_KeyNotFoundException if the public key needed for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 * signature verification is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1159 * @throws Crypt_GPG_NoDataException if the provided data is not signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 * data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162 * @throws Crypt_GPG_FileException if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 * @see Crypt_GPG_Signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170 public function verifyFile($filename, $signature = '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1171 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172 return $this->_verify($filename, true, $signature);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1173 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1174
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 // {{{ addDecryptKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1177
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1178 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1179 * Adds a key to use for decryption
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1180 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1181 * @param mixed $key the key to use. This may be a key identifier,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1182 * user id, fingerprint, {@link Crypt_GPG_Key} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1183 * {@link Crypt_GPG_SubKey}. The key must be able
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 * to encrypt.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185 * @param string $passphrase optional. The passphrase of the key required
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186 * for decryption.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190 * @see Crypt_GPG::decrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191 * @see Crypt_GPG::decryptFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192 * @see Crypt_GPG::clearDecryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 * @see Crypt_GPG::_addKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195 * @sensitive $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197 public function addDecryptKey($key, $passphrase = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199 $this->_addKey($this->decryptKeys, false, false, $key, $passphrase);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204 // {{{ addEncryptKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 * Adds a key to use for encryption
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209 * @param mixed $key the key to use. This may be a key identifier, user id
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 * user id, fingerprint, {@link Crypt_GPG_Key} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 * {@link Crypt_GPG_SubKey}. The key must be able to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212 * encrypt.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1214 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 * @see Crypt_GPG::encrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217 * @see Crypt_GPG::encryptFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1218 * @see Crypt_GPG::clearEncryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219 * @see Crypt_GPG::_addKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221 public function addEncryptKey($key)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 $this->_addKey($this->encryptKeys, true, false, $key);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228 // {{{ addSignKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 * Adds a key to use for signing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233 * @param mixed $key the key to use. This may be a key identifier,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234 * user id, fingerprint, {@link Crypt_GPG_Key} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235 * {@link Crypt_GPG_SubKey}. The key must be able
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 * to sign.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237 * @param string $passphrase optional. The passphrase of the key required
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238 * for signing.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1241 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242 * @see Crypt_GPG::sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243 * @see Crypt_GPG::signFile()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244 * @see Crypt_GPG::clearSignKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245 * @see Crypt_GPG::_addKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 * @sensitive $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249 public function addSignKey($key, $passphrase = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 $this->_addKey($this->signKeys, false, true, $key, $passphrase);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256 // {{{ addPassphrase()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259 * Register a private key passphrase for import/export (GnuPG 2.1)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261 * @param mixed $key The key to use. This must be a key identifier,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 * or fingerprint.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1263 * @param string $passphrase The passphrase of the key.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1267 * @see Crypt_GPG::clearPassphrases()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 * @see Crypt_GPG::importKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269 * @see Crypt_GPG::exportKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271 * @sensitive $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 public function addPassphrase($key, $passphrase)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1275 $this->passphrases[$key] = $passphrase;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280 // {{{ clearDecryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1281
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283 * Clears all decryption keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287 * @see Crypt_GPG::decrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288 * @see Crypt_GPG::addDecryptKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290 public function clearDecryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 $this->decryptKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 // {{{ clearEncryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300 * Clears all encryption keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 * @see Crypt_GPG::encrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305 * @see Crypt_GPG::addEncryptKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307 public function clearEncryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 $this->encryptKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314 // {{{ clearSignKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317 * Clears all signing keys
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1321 * @see Crypt_GPG::sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 * @see Crypt_GPG::addSignKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324 public function clearSignKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326 $this->signKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331 // {{{ clearPassphrases()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1334 * Clears all private key passphrases
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1336 * @return Crypt_GPG the current object, for fluent interface.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1337 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1338 * @see Crypt_GPG::importKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1339 * @see Crypt_GPG::exportKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1340 * @see Crypt_GPG::addPassphrase()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1341 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1342 public function clearPassphrases()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1343 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1344 $this->passphrases = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1345 return $this;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1346 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1347
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1348 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1349 // {{{ hasEncryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1350
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1351 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1352 * Tell if there are encryption keys registered
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1353 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1354 * @return boolean True if the data shall be encrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1355 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1356 public function hasEncryptKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1357 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1358 return count($this->encryptKeys) > 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1359 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1360
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1361 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1362 // {{{ hasSignKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1363
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1364 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1365 * Tell if there are signing keys registered
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1366 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1367 * @return boolean True if the data shall be signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1368 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1369 public function hasSignKeys()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1370 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1371 return count($this->signKeys) > 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1372 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1373
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1374 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1375 // {{{ _addKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1376
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1377 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1378 * Adds a key to one of the internal key arrays
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1379 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1380 * This handles resolving full key objects from the provided
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1381 * <kbd>$key</kbd> value.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1382 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1383 * @param array &$array the array to which the key should be added.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1384 * @param boolean $encrypt whether or not the key must be able to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1385 * encrypt.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1386 * @param boolean $sign whether or not the key must be able to sign.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1387 * @param mixed $key the key to add. This may be a key identifier,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1388 * user id, fingerprint, {@link Crypt_GPG_Key} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1389 * {@link Crypt_GPG_SubKey}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1390 * @param string $passphrase optional. The passphrase associated with the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1391 * key.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1392 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1393 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1394 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1395 * @sensitive $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1396 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1397 protected function _addKey(array &$array, $encrypt, $sign, $key,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1398 $passphrase = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1399 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1400 $subKeys = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1401
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1402 if (is_scalar($key)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1403 $keys = $this->getKeys($key);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1404 if (count($keys) == 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1405 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1406 'Key not found: ' . $key,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1407 self::ERROR_KEY_NOT_FOUND,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1408 $key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1409 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1410 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1411 $key = $keys[0];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1412 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1413
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1414 if ($key instanceof Crypt_GPG_Key) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1415 if ($encrypt && !$key->canEncrypt()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1416 throw new InvalidArgumentException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1417 'Key "' . $key . '" cannot encrypt.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1418 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1419 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1420
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1421 if ($sign && !$key->canSign()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1422 throw new InvalidArgumentException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1423 'Key "' . $key . '" cannot sign.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1424 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1425 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1426
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1427 foreach ($key->getSubKeys() as $subKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1428 $canEncrypt = $subKey->canEncrypt();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1429 $canSign = $subKey->canSign();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1430 if (($encrypt && $sign && $canEncrypt && $canSign)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1431 || ($encrypt && !$sign && $canEncrypt)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1432 || (!$encrypt && $sign && $canSign)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1433 || (!$encrypt && !$sign)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1434 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1435 // We add all subkeys that meet the requirements because we
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1436 // were not told which subkey is required.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1437 $subKeys[] = $subKey;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1438 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1439 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1440 } elseif ($key instanceof Crypt_GPG_SubKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1441 $subKeys[] = $key;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1442 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1443
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1444 if (count($subKeys) === 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1445 throw new InvalidArgumentException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1446 'Key "' . $key . '" is not in a recognized format.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1447 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1448 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1449
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1450 foreach ($subKeys as $subKey) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1451 if ($encrypt && !$subKey->canEncrypt()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1452 throw new InvalidArgumentException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1453 'Key "' . $key . '" cannot encrypt.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1454 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1455 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1456
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1457 if ($sign && !$subKey->canSign()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1458 throw new InvalidArgumentException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1459 'Key "' . $key . '" cannot sign.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1460 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1461 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1462
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1463 $array[$subKey->getId()] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1464 'fingerprint' => $subKey->getFingerprint(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1465 'passphrase' => $passphrase
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1466 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1467 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1468 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1469
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1470 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1471 // {{{ _importKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1472
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1473 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1474 * Imports a public or private key into the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1475 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1476 * @param string $key the key to be imported.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1477 * @param boolean $isFile whether or not the input is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1478 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1479 * @return array an associative array containing the following elements:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1480 * - <kbd>fingerprint</kbd> - the fingerprint of the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1481 * imported key,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1482 * - <kbd>public_imported</kbd> - the number of public
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1483 * keys imported,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1484 * - <kbd>public_unchanged</kbd> - the number of unchanged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1485 * public keys,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1486 * - <kbd>private_imported</kbd> - the number of private
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1487 * keys imported,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1488 * - <kbd>private_unchanged</kbd> - the number of unchanged
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1489 * private keys.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1490 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1491 * @throws Crypt_GPG_NoDataException if the key data is missing or if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1492 * data is is not valid key data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1493 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1494 * @throws Crypt_GPG_FileException if the key file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1495 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1496 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1497 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1498 * {@link Crypt_GPG::addPassphrase()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1499 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1500 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1501 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1502 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1503 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1504 protected function _importKey($key, $isFile)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1505 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1506 $result = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1507 $arguments = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1508 $input = $this->_prepareInput($key, $isFile, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1509 $version = $this->engine->getVersion();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1510
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1511 if (version_compare($version, '1.0.5', 'ge')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1512 && version_compare($version, '1.0.7', 'lt')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1513 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1514 $arguments[] = '--allow-secret-key-import';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1515 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1516
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1517 if (empty($this->passphrases)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1518 $arguments[] = '--batch';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1519 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1520
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1521 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1522 $this->engine->setPins($this->passphrases);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1523 $this->engine->setOperation('--import', $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1524 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1525 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1526
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1527 return $this->engine->getProcessData('Import');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1528 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1529
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1530 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1531 // {{{ _exportKey()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1532
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1533 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1534 * Exports a private or public key from the keyring
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1535 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1536 * If more than one key fingerprint is available for the specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1537 * <kbd>$keyId</kbd> (for example, if you use a non-unique uid) only the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1538 * first key is exported.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1539 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1540 * @param string $keyId either the full uid of the key, the email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1541 * part of the uid of the key or the key id.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1542 * @param boolean $armor optional. If true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1543 * otherwise, binary data is returned. Defaults to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1544 * true.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1545 * @param boolean $private return private instead of public key
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1546 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1547 * @return string the key data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1548 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1549 * @throws Crypt_GPG_KeyNotFoundException if a key with the given
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1550 * <kbd>$keyId</kbd> is not found.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1551 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1552 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1553 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1554 * {@link Crypt_GPG::addPassphrase()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1555 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1556 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1557 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1558 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1559 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1560 protected function _exportKey($keyId, $armor = true, $private = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1561 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1562 $fingerprint = $this->getFingerprint($keyId);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1563
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1564 if ($fingerprint === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1565 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1566 'Key not found: ' . $keyId,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1567 self::ERROR_KEY_NOT_FOUND,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1568 $keyId
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1569 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1570 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1571
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1572 $keyData = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1573 $operation = $private ? '--export-secret-keys' : '--export';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1574 $operation .= ' ' . escapeshellarg($fingerprint);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1575 $arguments = $armor ? array('--armor') : array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1576
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1577 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1578 $this->engine->setPins($this->passphrases);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1579 $this->engine->setOutput($keyData);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1580 $this->engine->setOperation($operation, $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1581 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1582
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1583 return $keyData;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1584 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1585
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1586 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1587 // {{{ _encrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1588
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1589 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1590 * Encrypts data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1591 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1592 * @param string $data the data to encrypt.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1593 * @param boolean $isFile whether or not the data is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1594 * @param string $outputFile the filename of the file in which to store
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1595 * the encrypted data. If null, the encrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1596 * data is returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1597 * @param boolean $armor if true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1598 * otherwise, binary data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1599 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1600 * @return void|string if the <kbd>$outputFile</kbd> parameter is null, a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1601 * string containing the encrypted data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1602 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1603 * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1604 * See {@link Crypt_GPG::addEncryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1605 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1606 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1607 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1608 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1609 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1610 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1611 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1612 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1613 protected function _encrypt($data, $isFile, $outputFile, $armor)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1614 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1615 if (!$this->hasEncryptKeys()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1616 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1617 'No encryption keys specified.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1618 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1619 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1620
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1621 $input = $this->_prepareInput($data, $isFile);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1622 $output = $this->_prepareOutput($outputFile, $input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1623 $arguments = $armor ? array('--armor') : array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1624
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1625 foreach ($this->encryptKeys as $key) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1626 $arguments[] = '--recipient ' . escapeshellarg($key['fingerprint']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1627 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1628
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1629 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1630 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1631 $this->engine->setOutput($output);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1632 $this->engine->setOperation('--encrypt', $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1633 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1634
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1635 if ($outputFile === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1636 return $output;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1637 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1638 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1639
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1640 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1641 // {{{ _decrypt()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1642
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1643 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1644 * Decrypts data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1645 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1646 * @param string $data the data to be decrypted.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1647 * @param boolean $isFile whether or not the data is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1648 * @param string $outputFile the name of the file to which the decrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1649 * data should be written. If null, the decrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1650 * data is returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1651 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1652 * @return void|string if the <kbd>$outputFile</kbd> parameter is null, a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1653 * string containing the decrypted data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1654 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1655 * @throws Crypt_GPG_KeyNotFoundException if the private key needed to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1656 * decrypt the data is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1657 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1658 * @throws Crypt_GPG_NoDataException if specified data does not contain
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1659 * GPG encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1660 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1661 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1662 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1663 * {@link Crypt_GPG::addDecryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1664 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1665 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1666 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1667 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1668 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1669 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1670 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1671 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1672 protected function _decrypt($data, $isFile, $outputFile)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1673 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1674 $input = $this->_prepareInput($data, $isFile, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1675 $output = $this->_prepareOutput($outputFile, $input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1676
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1677 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1678 $this->engine->setPins($this->decryptKeys);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1679 $this->engine->setOperation('--decrypt --skip-verify');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1680 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1681 $this->engine->setOutput($output);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1682 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1683
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1684 if ($outputFile === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1685 return $output;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1686 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1687 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1688
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1689 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1690 // {{{ _sign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1691
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1692 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1693 * Signs data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1694 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1695 * @param string $data the data to be signed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1696 * @param boolean $isFile whether or not the data is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1697 * @param string $outputFile the name of the file in which the signed data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1698 * should be stored. If null, the signed data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1699 * returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1700 * @param boolean $mode the data signing mode to use. Should be one of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1701 * {@link Crypt_GPG::SIGN_MODE_NORMAL},
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1702 * {@link Crypt_GPG::SIGN_MODE_CLEAR} or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1703 * {@link Crypt_GPG::SIGN_MODE_DETACHED}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1704 * @param boolean $armor if true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1705 * otherwise, binary data is returned. This has
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1706 * no effect if the mode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1707 * <kbd>Crypt_GPG::SIGN_MODE_CLEAR</kbd> is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1708 * used.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1709 * @param boolean $textmode if true, line-breaks in signed data be
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1710 * normalized. Use this option when signing
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1711 * e-mail, or for greater compatibility between
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1712 * systems with different line-break formats.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1713 * Defaults to false. This has no effect if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1714 * mode <kbd>Crypt_GPG::SIGN_MODE_CLEAR</kbd> is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1715 * used as clear-signing always uses textmode.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1716 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1717 * @return void|string if the <kbd>$outputFile</kbd> parameter is null, a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1718 * string containing the signed data (or the signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1719 * data if a detached signature is requested) is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1720 * returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1721 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1722 * @throws Crypt_GPG_KeyNotFoundException if no signing key is specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1723 * See {@link Crypt_GPG::addSignKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1724 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1725 * @throws Crypt_GPG_BadPassphraseException if a specified passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1726 * incorrect or if a required passphrase is not specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1727 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1728 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1729 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1730 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1731 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1732 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1733 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1734 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1735 protected function _sign($data, $isFile, $outputFile, $mode, $armor,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1736 $textmode
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1737 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1738 if (!$this->hasSignKeys()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1739 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1740 'No signing keys specified.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1741 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1742 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1743
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1744 $input = $this->_prepareInput($data, $isFile);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1745 $output = $this->_prepareOutput($outputFile, $input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1746
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1747 switch ($mode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1748 case self::SIGN_MODE_DETACHED:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1749 $operation = '--detach-sign';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1750 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1751 case self::SIGN_MODE_CLEAR:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1752 $operation = '--clearsign';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1753 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1754 case self::SIGN_MODE_NORMAL:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1755 default:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1756 $operation = '--sign';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1757 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1758 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1759
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1760 $arguments = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1761
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1762 if ($armor) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1763 $arguments[] = '--armor';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1764 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1765 if ($textmode) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1766 $arguments[] = '--textmode';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1767 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1768
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1769 foreach ($this->signKeys as $key) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1770 $arguments[] = '--local-user ' .
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1771 escapeshellarg($key['fingerprint']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1772 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1773
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1774 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1775 $this->engine->setPins($this->signKeys);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1776 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1777 $this->engine->setOutput($output);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1778 $this->engine->setOperation($operation, $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1779 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1780
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1781 if ($outputFile === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1782 return $output;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1783 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1784 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1785
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1786 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1787 // {{{ _encryptAndSign()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1788
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1789 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1790 * Encrypts and signs data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1791 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1792 * @param string $data the data to be encrypted and signed.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1793 * @param boolean $isFile whether or not the data is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1794 * @param string $outputFile the name of the file in which the encrypted,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1795 * signed data should be stored. If null, the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1796 * encrypted, signed data is returned as a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1797 * string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1798 * @param boolean $armor if true, ASCII armored data is returned;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1799 * otherwise, binary data is returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1800 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1801 * @return void|string if the <kbd>$outputFile</kbd> parameter is null, a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1802 * string containing the encrypted, signed data is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1803 * returned.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1804 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1805 * @throws Crypt_GPG_KeyNotFoundException if no encryption key is specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1806 * or if no signing key is specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1807 * {@link Crypt_GPG::addEncryptKey()} and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1808 * {@link Crypt_GPG::addSignKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1809 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1810 * @throws Crypt_GPG_BadPassphraseException if a specified passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1811 * incorrect or if a required passphrase is not specified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1812 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1813 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1814 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1815 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1816 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1817 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1818 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1819 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1820 protected function _encryptAndSign($data, $isFile, $outputFile, $armor)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1821 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1822 if (!$this->hasSignKeys()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1823 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1824 'No signing keys specified.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1825 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1826 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1827
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1828 if (!$this->hasEncryptKeys()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1829 throw new Crypt_GPG_KeyNotFoundException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1830 'No encryption keys specified.'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1831 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1832 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1833
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1834 $input = $this->_prepareInput($data, $isFile);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1835 $output = $this->_prepareOutput($outputFile, $input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1836 $arguments = $armor ? array('--armor') : array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1837
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1838 foreach ($this->signKeys as $key) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1839 $arguments[] = '--local-user ' .
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1840 escapeshellarg($key['fingerprint']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1841 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1842
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1843 foreach ($this->encryptKeys as $key) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1844 $arguments[] = '--recipient ' . escapeshellarg($key['fingerprint']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1845 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1846
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1847 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1848 $this->engine->setPins($this->signKeys);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1849 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1850 $this->engine->setOutput($output);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1851 $this->engine->setOperation('--encrypt --sign', $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1852 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1853
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1854 if ($outputFile === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1855 return $output;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1856 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1857 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1858
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1859 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1860 // {{{ _verify()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1861
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1862 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1863 * Verifies data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1864 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1865 * @param string $data the signed data to be verified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1866 * @param boolean $isFile whether or not the data is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1867 * @param string $signature if verifying a file signed using a detached
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1868 * signature, this must be the detached signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1869 * data. Otherwise, specify ''.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1870 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1871 * @return array an array of {@link Crypt_GPG_Signature} objects for the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1872 * signed data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1873 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1874 * @throws Crypt_GPG_KeyNotFoundException if the public key needed for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1875 * signature verification is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1876 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1877 * @throws Crypt_GPG_NoDataException if the provided data is not signed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1878 * data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1879 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1880 * @throws Crypt_GPG_FileException if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1881 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1882 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1883 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1884 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1885 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1886 * @see Crypt_GPG_Signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1887 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1888 protected function _verify($data, $isFile, $signature)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1889 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1890 if ($signature == '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1891 $operation = '--verify';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1892 $arguments = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1893 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1894 // Signed data goes in FD_MESSAGE, detached signature data goes in
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1895 // FD_INPUT.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1896 $operation = '--verify - "-&' . Crypt_GPG_Engine::FD_MESSAGE. '"';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1897 $arguments = array('--enable-special-filenames');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1898 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1899
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1900 $input = $this->_prepareInput($data, $isFile, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1901
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1902 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1903
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1904 if ($signature == '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1905 // signed or clearsigned data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1906 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1907 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1908 // detached signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1909 $this->engine->setInput($signature);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1910 $this->engine->setMessage($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1911 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1912
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1913 $this->engine->setOperation($operation, $arguments);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1914 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1915
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1916 return $this->engine->getProcessData('Signatures');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1917 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1918
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1919 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1920 // {{{ _decryptAndVerify()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1921
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1922 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1923 * Decrypts and verifies encrypted, signed data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1924 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1925 * @param string $data the encrypted signed data to be decrypted and
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1926 * verified.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1927 * @param boolean $isFile whether or not the data is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1928 * @param string $outputFile the name of the file to which the decrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1929 * data should be written. If null, the decrypted
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1930 * data is returned in the results array.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1931 * @param boolean $ignoreVerifyErrors enables ignoring of signature verification
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1932 * errors caused by missing public key.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1933 * When enabled Crypt_GPG_KeyNotFoundException
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1934 * will not be thrown.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1935 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1936 * @return array two element array. The array has an element 'data'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1937 * containing the decrypted data and an element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1938 * 'signatures' containing an array of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1939 * {@link Crypt_GPG_Signature} objects for the signed data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1940 * If the decrypted data is written to a file, the 'data'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1941 * element is null.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1942 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1943 * @throws Crypt_GPG_KeyNotFoundException if the private key needed to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1944 * decrypt the data is not in the user's keyring or if the public
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1945 * key needed for verification is not in the user's keyring.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1946 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1947 * @throws Crypt_GPG_NoDataException if specified data does not contain
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1948 * GPG signed, encrypted data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1949 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1950 * @throws Crypt_GPG_BadPassphraseException if a required passphrase is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1951 * incorrect or if a required passphrase is not specified. See
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1952 * {@link Crypt_GPG::addDecryptKey()}.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1953 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1954 * @throws Crypt_GPG_FileException if the output file is not writeable or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1955 * if the input file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1956 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1957 * @throws Crypt_GPG_Exception if an unknown or unexpected error occurs.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1958 * Use the <kbd>debug</kbd> option and file a bug report if these
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1959 * exceptions occur.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1960 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1961 * @see Crypt_GPG_Signature
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1962 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1963 protected function _decryptAndVerify($data, $isFile, $outputFile, $ignoreVerifyErrors = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1964 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1965 $input = $this->_prepareInput($data, $isFile, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1966 $output = $this->_prepareOutput($outputFile, $input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1967
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1968 $this->engine->reset();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1969 $this->engine->setPins($this->decryptKeys);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1970 $this->engine->setInput($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1971 $this->engine->setOutput($output);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1972 $this->engine->setOperation('--decrypt');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1973 $this->engine->setProcessData('IgnoreVerifyErrors', $ignoreVerifyErrors);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1974 $this->engine->run();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1975
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1976 $return = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1977 'data' => null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1978 'signatures' => $this->engine->getProcessData('Signatures')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1979 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1980
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1981 if ($outputFile === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1982 $return['data'] = $output;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1983 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1984
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1985 return $return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1986 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1987
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1988 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1989 // {{{ _prepareInput()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1990
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1991 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1992 * Prepares command input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1993 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1994 * @param string $data the input data.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1995 * @param boolean $isFile whether or not the input is a filename.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1996 * @param boolean $allowEmpty whether to check if the input is not empty.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1997 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1998 * @throws Crypt_GPG_NoDataException if the key data is missing.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1999 * @throws Crypt_GPG_FileException if the file is not readable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2000 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2001 protected function _prepareInput($data, $isFile = false, $allowEmpty = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2002 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2003 if ($isFile) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2004 $input = @fopen($data, 'rb');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2005 if ($input === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2006 throw new Crypt_GPG_FileException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2007 'Could not open input file "' . $data . '"',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2008 0,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2009 $data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2010 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2011 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2012 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2013 $input = strval($data);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2014 if (!$allowEmpty && $input === '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2015 throw new Crypt_GPG_NoDataException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2016 'No valid input data found.',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2017 self::ERROR_NO_DATA
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2018 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2019 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2020 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2021
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2022 return $input;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2023 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2024
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2025 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2026 // {{{ _prepareOutput()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2027
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2028 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2029 * Prepares command output
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2030 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2031 * @param string $outputFile the name of the file in which the output
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2032 * data should be stored. If null, the output
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2033 * data is returned as a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2034 * @param boolean $input the input resource, in case it would need
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2035 * to be released (closed) on exception.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2036 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2037 * @throws Crypt_GPG_FileException if the file is not writeable.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2038 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2039 protected function _prepareOutput($outputFile, $input = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2040 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2041 if ($outputFile === null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2042 $output = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2043 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2044 $output = @fopen($outputFile, 'wb');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2045 if ($output === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2046 if (is_resource($input)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2047 fclose($input);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2048 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2049 throw new Crypt_GPG_FileException(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2050 'Could not open output file "' . $outputFile . '"',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2051 0,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2052 $outputFile
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2053 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2054 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2055 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2056
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2057 return $output;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2058 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2059
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2060 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2061 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2062
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2063 // }}}
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2064
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2065 ?>