AnyCert

Some examples of how to access https://api.anycert.org/


Javascript

<script>

	var domain = "example.com";
	
	$.get("https://api.anycert.org/"+domain, function(data)
	{
		var certs = data.split("\n\n");
		
		/* root ca crt */
		console.log(certs[0].trim());
		
		/* domain key */
		console.log(certs[1].trim());
		
		/* domain crt */
		console.log(certs[2].trim());
	});

</script>

C#

using System;
using System.Net;

namespace AnyCert
{
    class Program
    {
        static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("\nUsage: anycert.exe domain\n");
                return 1;
            }

            String hostname = args[0];

            WebClient w = new WebClient();

            try
            {
                String data = w.DownloadString("https://api.anycert.org/" + hostname);

                if (data.Contains("ERROR: "))
                {
                    Console.WriteLine(data);
                    return 1;
                }

                string[] lines = data.Split(new string[] { "\n\n" }, StringSplitOptions.None);

                System.IO.File.WriteAllText("anycert.org.crt", lines[0].Trim());
                System.IO.File.WriteAllText(hostname + ".crt", lines[1].Trim());
                System.IO.File.WriteAllText(hostname + ".key", lines[2].Trim());

                return 0;
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                return 1;
            }            
        }
    }
}

PHP

<?php

/**
 * AnyCert CA Client (anycert.org)
 */

# argc must be > 1 else domain not specified
($argc > 1) or usage();

# Set last argument to domain
$domain = $argv[count($argv)-1];

# Output certificates to cwd by default
$output = './';

# Don't output root certificate by default
$create_root = false;

foreach (getopt("ho:r") as $key=>$val)
{
	switch ($key)
	{
		case 'h': usage(); break;
		case 'o': $output = $val; break;
		case 'r': $create_root = true; break;
	}
}

is_dir($output) or die("ERROR: output path doesn't exist\n");

# Request certificate into $obj
$obj = fetch($domain);

(!$create_root) or file_put_contents($output."anycert.crt", $obj->anycert_crt);
file_put_contents($output."$domain.key", $obj->domain_key);
file_put_contents($output."$domain.crt", $obj->domain_crt);

function fetch($domain)
{
	$data = @file_get_contents("https://api.anycert.org/$domain");
	($data) or die("ERROR: could not access the anycert.org service.\n");
	(strpos($data, 'ERROR: ') !== 0) or die("$data\n");
	$keys = explode("\n\n", $data);
	$o = new stdClass();
	$o->anycert_crt = trim($keys[0]);
	$o->domain_key  = trim($keys[1]);
	$o->domain_crt  = trim($keys[2]);
	return $o;
}

function usage()
{
	echo "AnyCert CA Client (anycert.org)";
	echo "\n";
	echo "\nUsage:";
	echo "\n  anycert [options] <domain>";
	echo "\n";
	echo "\nOptions:";
	echo "\n  -h 		Displays this output.";
	echo "\n  -r 		Create root certificate.";
	echo "\n  -o path 	If specified, certificates will be created in this path.";
	echo "\n";
	exit;
}