#!perl -w package App::CamelPKI::CertTemplate; use strict; =head1 NAME App::CamelPKI::CertTemplate - A certificate template for Camel-PKI (abstract class - not instanciable). =head1 SYNOPSIS =for My::Tests::Below "synopsis" begin package App::CamelPKI::CertTemplate::Foo; use base "App::CamelPKI::CertTemplate"; use Crypt::OpenSSL::CA; sub list_keys { qw(name uid) } sub prepare_certificate { my ($class, $cacert, $cert, %opts) = @_; $class->copy_from_ca_cert($cacert, $cert); $cert->set_notBefore($opts{time}); $cert->set_notAfter($cacert->get_notAfter()); $cert->set_subject_DN (Crypt::OpenSSL::CA::X509_NAME->new_utf8 ("2.5.4.11" => "Internet widgets", CN => $opts{name}, x500UniqueIdentifier => $opts{uid})); # ... } # Only one certificate must be valid for a given UID: sub test_certificate_conflict { my ($class, $db, %opts) = @_; return $db->search(uid => $opts{uid}); } # Sample coherency enforcement: no duplicate names, no duplicate # UIDs. sub test_issued_certs_coherent { my ($class, $db, @opts_array) = @_; $class->test_no_duplicates(["uid"], @opts_array); $class->test_no_duplicates(["name"], @opts_array); } =for My::Tests::Below "synopsis" end =head1 DESCRIPTION A B is a certificate "with holes": it fix the rules used to generate certificates (see L). Each subclasses of I represent a certificate template, to be (mainly) used as classes; no object is created as instance of I or one of its subclasses. Moreover, I is an abstract class; only its subclasses must be used as templates. =head1 CAPABILITY DISCIPLINE Classes inherited from I do not encapsulate any state; they are therefore neutral from a security point of view and don't carry any privileges. On the other hand, an I may be used to restrict the rights of an I instance; see L. =head1 METHODS TO OVERLOAD Barring an explicit contrary statement, every class that inherits from I must define the following methods: =head2 prepare_certificate($cacertobj, $eecertobj, $key1 => $val1, ...) Prepares a certificate for L, using $key1 => $val1, ... to fill out the variable fields. Keys ($key1, etc.) are always among those listed by L. Values are character strings or references to lists of character strings for templates allowing multi-valued fields (not implemented yet). The method is called in a scalar context; it shall modify I<$eecertobj>, an instance of L initially empty, by calling mutator methods on it, until $eecertobj is ready to be signed by the CA. To perform this task, I may use $cacertobj, an instance of L (B I) which represents the CA certificate, and/or the key-value data passed in parameters. Keys names ($key1, ...) are mostly chosen freely by the certificate template implementor, except for a short number that are "well known" and always provided by L: =over =item I<< time => $zulutime >> The date and time to be considered as the current time, in "Zulu" format. Typically, the certificate validity period start at $zulutime. =back =cut # abstract method =head2 list_keys() Called in list context, returns the valid nominative informations keys list to be passed to L and L. The CA will not give any key to this methods unless these keys are present in the return value of I, excepted C