/*
LibreSSL - CAcert web application
Copyright (C) 2004-2008 CAcert Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ ?>
require_once("../includes/loggedin.php");
$id = 0; if(array_key_exists('id',$_REQUEST)) $id=intval($_REQUEST['id']);
$oldid = $_REQUEST['oldid'] = array_key_exists('oldid',$_REQUEST) ? intval($_REQUEST['oldid']) : 0;
if($_SESSION['profile']['points'] < 50)
{
header("location: /account.php");
exit;
}
loadem("account");
$CSR=""; if(array_key_exists('CSR',$_REQUEST)) $CSR=stripslashes($_REQUEST['CSR']);
if($oldid == "0")
{
if(array_key_exists('process',$_REQUEST) && $_REQUEST['process'] != "" && $CSR == "")
{
$_SESSION['_config']['errmsg'] = _("You failed to paste a valid GPG/PGP key.");
$id = $oldid;
$oldid=0;
}
}
$keyid="";
if(0)
{
if($_SESSION["profile"]["id"] != 5897)
{
showheader(_("Welcome to CAcert.org"));
echo "The OpenPGP signing system is currently shutdown due to a maintenance. We hope to get it fixed within the next few hours. We are very sorry for the inconvenience.";
exit(0);
}
}
function verifyName($name)
{
if($name == "") return 0;
if($name == $_SESSION['profile']['fname']." ".$_SESSION['profile']['lname']) return 1;
if($name == $_SESSION['profile']['fname']." ".$_SESSION['profile']['mname']." ".$_SESSION['profile']['lname']) return 1;
if($name == $_SESSION['profile']['fname']." ".$_SESSION['profile']['lname']." ".$_SESSION['profile']['suffix']) return 1;
if($name == $_SESSION['profile']['fname']." ".$_SESSION['profile']['mname']." ".$_SESSION['profile']['lname']." ".$_SESSION['profile']['suffix']) return 1;
return 0;
}
function verifyEmail($email)
{
if($email == "") return 0;
if(mysql_num_rows(mysql_query("select * from `email` where `memid`='".$_SESSION['profile']['id']."' and `email`='".mysql_real_escape_string($email)."' and `deleted`=0 and `hash`=''")) > 0) return 1;
return 0;
}
$ToBeDeleted=array();
$state=0;
if($oldid == "0" && $CSR != "")
{
$debugkey = $gpgkey = clean_gpgcsr($CSR);
$tnam = tempnam('/tmp/', '__gpg');
$fp = fopen($tnam, 'w');
fwrite($fp, $gpgkey);
fclose($fp);
$debugpg = $gpg = trim(`gpg --with-colons --homedir /tmp 2>&1 < $tnam`);
unlink($tnam);
$lines = "";
$gpgarr = explode("\n", $gpg);
foreach($gpgarr as $line)
{
#echo "Line[]: $line
\n";
if(substr($line, 0, 3) == "pub" || substr($line, 0, 3) == "uid")
{
if($lines != "")
$lines .= "\n";
$lines .= $line;
}
}
$gpg = $lines;
$expires = 0;
$nerr=0; $nok=0;
$multiple = 0;
$resulttable=_("The following UIDs were found in your key:")."
# | "._("Name")." | "._("Email")." | Result | "; $i=0; $lastvalidemail=""; $npubs=0; foreach(explode("\n", $gpg) as $line) { $bits = explode(":", $line); $resulttable.="|
".++$i." | "; $name = $comment = ""; if($bits[0] == "pub") { $npubs++; } if($npubs>1) { showheader(_("Welcome to CAcert.org")); echo ""._("Please upload only one key at a time.").""; unset($_REQUEST['process']); $id = $oldid; unset($oldid); exit(); } if($bits[0] == "pub" && (!$keyid || !$when)) { $keyid = $bits[4]; $when = $bits[5]; if($bits[6] != "") $expires = 1; } $name=""; $comm=""; $mail=""; $uidformatwrong=0; if(sizeof($bits)<10) $uidformatwrong=1; if(preg_match("/\@.*\@/",$bits[9])) { showheader(_("Welcome to CAcert.org")); echo ""._("Multiple Email Adresses per UID are not allowed.").""; unset($_REQUEST['process']); $id = $oldid; unset($oldid); exit(); } // Name (Comment)".sanitizeHTML($name)." | "; $resulttable.="".sanitizeHTML($mail)." | "; $uidok=0; if($bits[1]=="r") { $rmessage=_("Error: UID is revoked"); } elseif($uidformatwrong==1) { $rmessage=_("The format of the UID was not recognized. Please use 'Name (comment) <email@domain>'"); } elseif($mail=="" and $name=="") { $rmessage=_("Error: Both Name and Email address are empty"); } elseif($emailok and $nameok) { $uidok=1; $rmessage=_("Name and Email OK."); } elseif(!$emailok and !$nameok) { $rmessage=_("Name and Email both cannot be matched with your account."); } elseif($emailok and $name=="") { $uidok=1; $rmessage=_("The email is OK. The name is empty."); } elseif($nameok and $mail=="") { $uidok=1; $rmessage=_("The name is OK. The email is empty."); } elseif(!$emailok) { $rmessage=_("The email address has not been registered and verified in your account. Please add the email address to your account first."); } elseif(!$nameok) { $rmessage=_("The name in the UID does not match the name in your account. Please verify the name."); } else { $rmessage=_("Error"); } if($uidok) { $nok++; $resulttable.="$rmessage | "; $lastvalidemail=$mail; } else { $nerr++; //$ToBeDeleted[]=$i; //echo "Adding UID $i\n"; $resulttable.="$rmessage | "; } $resulttable.="
"; readfile(generatecertpath("crt","gpg",$id)); echo ""; } showfooter(); exit; } $id = intval($id); showheader(_("Welcome to CAcert.org")); includeit($id, "gpg"); showfooter(); ?>