#!/usr/local/bin/perl

$|=1;

$name=&name();

print STDERR <<"EOF";
X.509-Certificate begin
CertificteInfo begin
- 0F
AlgorithmIdentifier begin
= 1 2 840 113549 1 1 4
= NULL
AlgorithmIdentifier end
EOF

print STDERR $name;

print STDERR <<"EOF";
Validity begin
= 941202235444Z
= 961201235444Z
Validity end
EOF

print STDERR $name;

print STDERR <<"EOF";
SubjectPublicKeyInfo begin
AlgorithmIdentifier begin
= 1 2 840 113549 1 1 1
= NULL
AlgorithmIdentifier end
- 00
SubjectPublicKeyInfo end
CertificteInfo end
AlgorithmIdentifier begin
= 1 2 840 113549 1 1 4
= NULL
AlgorithmIdentifier end
- 00
X.509-Certificate end
EOF

sub name
	{
	local($ret,$s);

	$ret="Name begin\n";
	print "Enter '.' to ignore the entry\n";
	$s=&get_info("Country Name [AU]:","AU");
	$ret.="= 2 5 4 6\n= ".$s."\n" if ($s ne "");

	$s=&get_info("State or Province [QLD]:","QLD");
	$ret.="= 2 5 4 8\n= ".$s."\n" if ($s ne ""); 

	$s=&get_info("locality Name []:",undef);
	$ret.="= 2 5 4 7\n= ".$s."\n" if ($s ne ""); 

	$s=&get_info("organization Name [Mincom Pty. Ltd.]:",
		"Mincom Pty. Ltd.");
	$ret.="= 2 5 4 10\n= ".$s."\n" if ($s ne ""); 

	$s=&get_info("organization Unit Name [CS]:","CS");
	$ret.="= 2 5 4 11\n= ".$s."\n" if ($s ne ""); 

	$s=&get_info("common Name []:",undef);
	$ret.="= 2 5 4 3\n= ".$s."\n" if ($s ne ""); 

	@a=split("\n",$ret);
	$a[$#a] =~ s#^= #\- #;
	$ret=join("\n",@a);
	$ret.="\nName end\n";
	return($ret);
	}

sub get_info
	{
	local($prompt,$def)=@_;
	local($_);

	print $prompt;
	$_=<>;
	$_ =~ s/^\s*(.*)\s*$/\1/;
	if ($_ eq "")
		{
		if ($def ne undef)
			{ return($def); }
		else
			{ return(undef); }
		}
	if ($_ eq ".")	{ return(undef); }
	return($_);
	}
