function fetch_chain($leaf) { $result = array(); $cert = parse_certificate($leaf); if ($cert === false) { return false; } $certData = pem2der($leaf); while ($cert !== false && !is_root_certificate($cert)) { $result[] = $certData; $certData = fetch_certificate_parent($cert); $cert = parse_certificate($certData); } return $result; }
$api_url = 'https://oa4mp.xsede.org/oauth/getcert'; function pem2der($pem_data) { $begin = "-----BEGIN CERTIFICATE REQUEST-----"; $end = "-----END CERTIFICATE REQUEST-----"; $pem_data = substr($pem_data, strpos($pem_data, $begin) + strlen($begin)); $pem_data = substr($pem_data, 0, strpos($pem_data, $end)); return $pem_data; } //echo "file://".$pkeyfile; $privkey = openssl_pkey_get_private("file://" . $pkeyfile); //var_dump($privkey); $csrt = openssl_csr_new($dn, $privkey); //var_dump($csrt); openssl_csr_export($csrt, $csrout); $conscsr = pem2der($csrout); //var_dump($conscsr); $privrsakey = file_get_contents($pemfile); session_start(); // In state=1 the next request should include an oauth_token. // If it doesn't go back to 0 if (!isset($_GET['oauth_token']) && $_SESSION['state'] == 1) { $_SESSION['state'] = 0; } try { $oauth = new OAuth($conskey, '', OAUTH_SIG_METHOD_RSASHA1, OAUTH_AUTH_TYPE_URI); $oauth->setRSACertificate(file_get_contents($pkeyfile)); $oauth->enableDebug(); file_put_contents('php://stderr', print_r($oauth->debugInfo, TRUE)); if (!isset($_GET['oauth_token']) && !$_SESSION['state']) { $oauth->fetch($req_url, array("oauth_callback" => $callback_url, "certreq" => $conscsr));