<?PHP
#This is the secure site for reloid.com.
##include (".htfunctions.php");

echo "<HTML><HEAD>";
?>

<object id="class_factory" classid="clsid:884e2049-217d-11da-b2a4-000e7bbb2b09">
</object>
<script language="VBScript">
	<!--//
Sub Submit_OnClick()
    Dim TheForm
    Set TheForm = frames("keyFrame").document.keyGen
 
    Dim distinguished_name
    Dim private_key
    Dim pkcs10_request
    Dim enrollment
     
    set enrollment = class_factory.CreateObject("X509Enrollment.CX509Enrollment")
    set pkcs10_request = class_factory.CreateObject("X509Enrollment.CX509CertificateRequestPkcs10")
    set private_key = class_factory.CreateObject("X509Enrollment.CX509privateKey")
    set distinguished_name = class_factory.CreateObject("X509Enrollment.CX500DistinguishedName")
    set csps = class_factory.CreateObject("X509Enrollment.CCspInformations")
 
    GenerateRequest TheForm, pkcs10_request, private_key, distinguished_name
 
    enrollment.InitializeFromRequest( pkcs10_request )
     
    'MsgBox "Generated?", 0, "Credentials Enrollment"
    If Err.Number <> 0 Then
        'MsgBox "error" & Err.Description, 0, "Credentials Enrollment"
        MsgBox "Error generating private key! Make sure to run Internet Explorer as Administrator, adjust the security settings to a lower level and try a smaller key size!", 0, "Error"
    Else
        'x509Key is actually not a key, but a signed PKCS10 request
        TheForm.x509Key.value = enrollment.createRequest(1)
        TheForm.submit()
    End If
End Sub
 
function GenerateKey( length, key )
 
    XCN_NCRYPT_ALLOW_EXPORT_FLAG = 1
    XCN_NCRYPT_UI_NO_PROTECTION_FLAG = 0
    XCN_NCRYPT_UI_PROTECT_KEY_FLAG = 1
     
    key.ProviderName = "Microsoft Strong Cryptographic Provider"
    key.ProviderType = "24"
    key.KeySpec = "1"
    key.KeyProtection = XCN_NCRYPT_UI_NO_PROTECTION_FLAG
    key.ExportPolicy = XCN_NCRYPT_ALLOW_EXPORT_FLAG
    key.Length = length
     
end function
 
function GenerateRequest( form, request, key, dn )
    CONTEXT_USER = 1
    CONTEXT_MACHINE = 2
    XCN_CERT_NAME_STR_NONE = 0
     
    GenerateKey form.keySize.value, key 
    hresult = request.InitializeFromPrivateKey(CONTEXT_USER, key, "")
    name = "CN=OMSIO CERTIFICATE"
    dn.Encode name, XCN_CERT_NAME_STR_NONE
    request.Subject = dn
end function

function SetProviders( )
    On Error Resume Next
    Set csps = CreateObject("X509Enrollment.CCspInformations")
      If IsObject(csps) Then
            csps.AddAvailableCsps()
            For j = 0 to csps.Count-1
                  Set oOption = frames("keyFrame").document.createElement("OPTION")
                  oOption.text = csps.ItemByIndex(j).Name
                  oOption.value = j
                  frames("keyFrame").document.keyGen.CspProvider.add(oOption)
            Next
    End If
end function

Function Submit_GetCert(sz10)
    Dim Enroll
    Dim result, msg

    Set Enroll = class_factory.CreateObject("X509Enrollment.CX509Enrollment")
    Enroll.Initialize(1)
    'Enroll.Initialize(X509CertificateEnrollmentContext.ContextUser);

    On Error Resume Next
        a = Enroll.InstallResponse(0, sz10, 0, "")
        If Err.Number <> 0 Then
        msg = "There was an error installing your certificate!" & _
            chr(10)                                    & _
            chr(10)                                    & _
            Err.Description                                            & _
            chr(10)                                    & _
            chr(10)                                    & _
            "Please retrieve the certificate from the Tool Box -> Retreive Certificate section."
        result = MsgBox(msg, 0, Err.Description)
    Else
            msg = "Congratulations! Your certificate installed successfully into your browser."  & _
            chr(10)                                & _
            "Please make a backup copy of the certificate and private key and save the file at an external media!"
            result = MsgBox(msg, 0, "Congratulations")
    End If
End function

//-->
</script>

<?PHP
echo "</HEAD><BODY>";
		$ref=$_SERVER["HTTP_REFERER"];
		$pos1=strpos($ref,"//")+2;
		$pos2=min(strpos($ref,"/",$pos1),strpos($ref,":",$pos1));
		$refdom=substr($ref,$pos1,$pos2-$pos1);
		switch($refdom)
		{
			case "www.instigations.com":
				$refsite="Wes";
				break;
			case "www.4-realz.com":
				$refsite="Iggy";
				break;
			default:
				$refsite="some unscrupulous actor";
				#yalnis("reloid approached from an unregistered site",ERRLEVELBAD);
		}
		if (strlen($refdom) > 0)
			echo "You are here because $refsite (at $refdom) sent you to us to obtain your provisional certificate. ";
		else
			echo "You are here probably because somebody told you it was a good site for obtaining a provisional identity certificate.  ";
		echo "You are about to embark on a magical tour which will result in your being a poorly authenticate person. ";
		echo "If you ready to start, you can first give us your email address so that we can send you an email. ";
		echo "When you get it, copy the magical code we gave you and come back here. ";
		echo "We shall give you a box to paste it into and that way we will know that it is, indeed, your email address. ";
		echo "This will enable us to give you a provisional certificate that will get you through the rest of the process. ";
		echo "If you put this certificate in your email client, you can sign emails and your friends and enemies can send you encrypted mail. ";
		echo "So if you're ready, here we go.";
		echo "\n<BR><script type=\"text/javascript\" src=\"https://www.startssl.com/validation.js\"></script>";
		echo "</P><P>";
		echo "\n<iframe src=\"https://reloid.startcom.org/\" width=\"600\" height=\"250\">";
		echo "</P>";
echo "</BODY></HTML>";
?>