-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeybaseUsernameToEmail.php
47 lines (37 loc) · 1.12 KB
/
KeybaseUsernameToEmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
header('Content-Type: application/json');
if (!isset($_GET['username'])) {
http_response_code(400);
echo json_encode(array("error" => "Username parameter is required"));
exit();
}
$username = $_GET['username'];
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, "https://keybase.io/" . $username . "/key.asc");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($handle);
$status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if ($status === 404) {
http_response_code(404);
echo json_encode(array("error" => "Unable To Retrieve Data"));
exit();
}
if (preg_match("/SELF-SIGNED PUBLIC KEY NOT FOUND/i", $output)) {
http_response_code(404);
echo json_encode(array("error" => "Unable To Retrieve Data"));
exit();
}
$body = explode("\n\n", $output);
$key = explode("-----", $body[1]);
preg_match_all("/ <(.*?)>/", base64_decode($key[0]), $matches);
$emails = array();
foreach ($matches[1] as $email) {
$emails[] = $email;
}
$result = array(
"username" => $username,
"emails" => $emails
);
echo json_encode($result, JSON_PRETTY_PRINT);
?>