2 namespace PayPal\Auth\Oauth;
4 * The RSA-SHA1 signature method uses the RSASSA-PKCS1-v1_5 signature algorithm as defined in
5 * [RFC3447] section 8.2 (more simply known as PKCS#1), using SHA-1 as the hash function for
6 * EMSA-PKCS1-v1_5. It is assumed that the Consumer has provided its RSA public key in a
7 * verified way to the Service Provider, in a manner which is beyond the scope of this
9 * - Chapter 9.3 ("RSA-SHA1")
11 abstract class OAuthSignatureMethodRsaSha1 extends OAuthSignatureMethod {
12 public function get_name() {
16 // Up to the SP to implement this lookup of keys. Possible ideas are:
17 // (1) do a lookup in a table of trusted certs keyed off of consumer
18 // (2) fetch via http using a url provided by the requester
19 // (3) some sort of specific discovery code based on request
21 // Either way should return a string representation of the certificate
22 protected abstract function fetch_public_cert(&$request);
24 // Up to the SP to implement this lookup of keys. Possible ideas are:
25 // (1) do a lookup in a table of trusted certs keyed off of consumer
27 // Either way should return a string representation of the certificate
28 protected abstract function fetch_private_cert(&$request);
30 public function build_signature($request, $consumer, $token) {
31 $base_string = $request->get_signature_base_string();
32 $request->base_string = $base_string;
34 // Fetch the private key cert based on the request
35 $cert = $this->fetch_private_cert($request);
37 // Pull the private key ID from the certificate
38 $privatekeyid = openssl_get_privatekey($cert);
41 $ok = openssl_sign($base_string, $signature, $privatekeyid);
43 // Release the key resource
44 openssl_free_key($privatekeyid);
46 return base64_encode($signature);
49 public function check_signature($request, $consumer, $token, $signature) {
50 $decoded_sig = base64_decode($signature);
52 $base_string = $request->get_signature_base_string();
54 // Fetch the public key cert based on the request
55 $cert = $this->fetch_public_cert($request);
57 // Pull the public key ID from the certificate
58 $publickeyid = openssl_get_publickey($cert);
60 // Check the computed signature against the one passed in the query
61 $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
63 // Release the key resource
64 openssl_free_key($publickeyid);