1 | <?php namespace Arcanedev\Stripe; |
||
9 | abstract class WebhookSignature |
||
10 | { |
||
11 | /* ----------------------------------------------------------------- |
||
12 | | Constants |
||
13 | | ----------------------------------------------------------------- |
||
14 | */ |
||
15 | |||
16 | const EXPECTED_SCHEME = 'v1'; |
||
17 | |||
18 | /* ----------------------------------------------------------------- |
||
19 | | Main Methods |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * Verifies the signature header sent by Stripe. |
||
25 | * Throws a SignatureVerification exception if the verification fails for any reason. |
||
26 | * |
||
27 | * @param string $payload The payload sent by Stripe. |
||
28 | * @param string $header The contents of the signature header sent by Stripe. |
||
29 | * @param string $secret Secret used to generate the signature. |
||
30 | * @param int $tolerance Maximum difference allowed between the header's timestamp and the current time |
||
31 | * |
||
32 | * @return bool |
||
33 | * |
||
34 | * @throws \Arcanedev\Stripe\Exceptions\SignatureVerificationException |
||
35 | */ |
||
36 | 27 | public static function verifyHeader($payload, $header, $secret, $tolerance = null) |
|
87 | |||
88 | /* ----------------------------------------------------------------- |
||
89 | | Other Methods |
||
90 | | ----------------------------------------------------------------- |
||
91 | */ |
||
92 | |||
93 | /** |
||
94 | * Extracts the timestamp in a signature header. |
||
95 | * |
||
96 | * @param string $header the signature header |
||
97 | * @return int the timestamp contained in the header, or -1 if no valid timestamp is found |
||
98 | */ |
||
99 | 27 | private static function getTimestamp($header) |
|
115 | |||
116 | /** |
||
117 | * Extracts the signatures matching a given scheme in a signature header. |
||
118 | * |
||
119 | * @param string $header The signature header |
||
120 | * @param string $scheme The signature scheme to look for. |
||
121 | * |
||
122 | * @return array The list of signatures matching the provided scheme. |
||
123 | */ |
||
124 | 27 | private static function getSignatures($header, $scheme) |
|
139 | |||
140 | /** |
||
141 | * Computes the signature for a given payload and secret. |
||
142 | * |
||
143 | * The current scheme used by Stripe ("v1") is HMAC/SHA-256. |
||
144 | * |
||
145 | * @param string $payload The payload to sign. |
||
146 | * @param string $secret The secret used to generate the signature. |
||
147 | * |
||
148 | * @return string The signature as a string. |
||
149 | */ |
||
150 | 18 | private static function computeSignature($payload, $secret) |
|
154 | } |
||
155 |