1<?php
2/*
3 * Copyright 2008-2010 GuardTime AS
4 *
5 * This file is part of the GuardTime PHP SDK.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20/**
21 * @package tsp
22 */
23
24/**
25 * Represents the result of full verification procedure, possibly including
26 * interaction with the online verification service.
27 *
28 * @package tsp
29 */
30class GTVerificationResultHttp extends GTVerifificationResultBase {
31
32    /******************************************* STATUS CODES *******************************************/
33
34    /**
35     * Reserved as alias for <samp>PKIStatusInfo status = granted (0)</samp>
36     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
37     *
38     * @see getStatusCode, hasStatus
39     */
40    const TIMESTAMP_GRANTED = 1;
41
42    /**
43     * Reserved as alias for <samp>PKIStatusInfo status = grantedWithMods (1)</samp>
44     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
45     *
46     * @see getStatusCode, hasStatus
47     */
48    const TIMESTAMP_GRANTED_WITH_MODS = 2;
49
50    /**
51     * Reserved as alias for <samp>PKIStatusInfo status = rejection (2)</samp>
52     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
53     *
54     * @see getStatusCode, hasStatus
55     */
56    const TIMESTAMP_REJECTED = 4;
57
58    /**
59     * Reserved as alias for <samp>PKIStatusInfo status = waiting (3)</samp>
60     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
61     *
62     * @see getStatusCode, hasStatus
63     */
64    const TIMESTAMP_WAITING = 8;
65
66    /**
67     * Reserved as alias for <samp>PKIStatusInfo status = revocationWarning (4)</samp>
68     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
69     *
70     * @see getStatusCode, hasStatus
71     */
72    const REVOCATION_WARNING = 16;
73
74    /**
75     * Reserved as alias for <samp>PKIStatusInfo status = revocationNotification (5)</samp>
76     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
77     *
78     * @see getStatusCode, hasStatus
79     */
80    const REVOCATION_NOTIFICATION = 32;
81
82    /**
83     * Timestamp extension was attempted during verification.
84     *
85     * @see getStatusCode, hasStatus
86     */
87    const EXTENSION_ATTEMPTED = 128;
88
89    /**
90     * Timestamp was successfully extended during verification.
91     *
92     * @see getStatusCode, hasStatus
93     */
94    const TIMESTAMP_EXTENDED = 256;
95
96    /******************************************* ERROR CODES *******************************************/
97
98    /**
99     * Reserved as alias for <samp>PKIStatusInfo fail = badAlg (0)</samp>
100     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
101     *
102     * @see getErrorCode, hasError
103     */
104    const INVALID_ALGORITHM_FAILURE = 1;
105
106    /**
107     * Reserved as alias for <samp>PKIStatusInfo fail = badRequest (2)</samp>
108     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
109     *
110     * @see getErrorCode, hasError
111     */
112    const  INVALID_REQUEST_FAILURE = 2;
113
114    /**
115     * Reserved as alias for <samp>PKIStatusInfo fail = badDataFormat (5)</samp>
116     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
117     *
118     * @see getErrorCode, hasError
119     */
120    const INVALID_DATA_FORMAT_FAILURE = 4;
121
122    /**
123     * Reserved as alias for <samp>PKIStatusInfo fail = timeNotAvailalble (14)</samp>
124     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
125     *
126     * @see getErrorCode, hasError
127     */
128    const TIME_NOT_AVAILBLE_FAILURE = 8;
129
130    /**
131     * Reserved as alias for <samp>PKIStatusInfo fail = unacceptedPolicy (15)</samp>
132     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
133     *
134     * @see getErrorCode, hasError
135     */
136    const UNACCEPTED_POLICY_FAILURE = 16;
137
138    /**
139     * Reserved as alias for <samp>PKIStatusInfo fail = unacceptedExtension (16)</samp>
140     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
141     *
142     * @see getErrorCode, hasError
143     */
144    const UNACCEPTED_EXTENSION_FAILURE = 32;
145
146    /**
147     * Reserved as alias for <samp>PKIStatusInfo fail = addInfoNotAvailalble (17)</samp>
148     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
149     *
150     * @see getErrorCode, hasError
151     */
152    const ADDITIONAL_INFO_NOT_AVAILABLE_FAILURE = 64;
153
154    /**
155     * Reserved as alias for <samp>PKIStatusInfo fail = systemFailure (25)</samp>
156     * from {@link http://tools.ietf.org/html/rfc3161#section-2.4.2 RFC 3161}.
157     *
158     * @see getErrorCode, hasError
159     */
160    const SYSTEM_FAILURE = 128;
161
162    /**
163     * Timestamp is too new to be extended.
164     *
165     * @see getErrorCode, hasError
166     */
167    const TIMESTAMP_TOO_NEW_FAILURE = 256;
168
169    /**
170     * Timestamp is too old to be extended.
171     *
172     * @see getErrorCode, hasError
173     */
174    const TIMESTAMP_TOO_OLD_FAILURE = 512;
175
176    /**
177     * Service response has invalid format.
178     *
179     * @see getErrorCode, hasError
180     */
181    const RESPONSE_FORMAT_FAILURE = 2048;
182
183    /**
184     * Service is unreachable, possibly network error or malformed URL.
185     *
186     * @see getErrorCode, hasError
187     */
188    const SERVICE_UNREACHABLE_FAILURE = 8192;
189
190    private $gtResult = null;
191
192    /**
193     * Sets the timestamp verification result.
194     *
195     * @param  GTVerificationResult $gtResult timestamp verification result
196     * @return void
197     */
198    public function setGtResult(GTVerificationResult $gtResult) {
199        $this->gtResult = $gtResult;
200    }
201
202    /**
203     * Gets the timestamp verification result.
204     *
205     * @return GTVerificationResult timestamp verification result
206     */
207    public function getGtResult() {
208        return $this->gtResult;
209    }
210
211    /**
212     * Checks if this verification result is valid.
213     *
214     * @return bool true if verification was successful
215     */
216    public function isValid() {
217
218        $errorCode = $this->getErrorCode();
219
220        if ($errorCode == self::NO_FAILURES ||
221            $errorCode == self::TIMESTAMP_TOO_NEW_FAILURE ||
222            $errorCode == self::TIMESTAMP_TOO_OLD_FAILURE ||
223            $errorCode == self::SERVICE_UNREACHABLE_FAILURE) {
224
225            if ($this->gtResult === null) {
226                return false;
227
228            } else {
229                return $this->gtResult->isValid();
230
231            }
232
233        } else {
234
235            return false;
236        }
237
238    }
239
240}
241
242?>
243