Once the OpenCA is installed and the CA Certificate is issued, clicking serial number of the CA Certificate throws below error.
Error Code: 6295020 [initServer:314] Cannot load certificate 404576247583593287078701 from the database.
In-spite of enabling debug option, I couldn’t find any relevant error messages in stderror.log.
- The interface lists CA certificate, but fails to display the certificate information while performing
viewCert or viewCertFullcmd operations. - I verified the CA_Certificate stored in the PostgreSQL database and it appears to be fine and VALID.
- The query string in URI seems to be fine with the
dataTypeproperly mentioned as below:
cmd=viewCert&dataType=VALID_CA_CERTIFICATE&key=4045762475835932870787014.
- Usually the commands executed from
lib/cmdsis configured inetc/openca/access_control/*.xmlfiles and everything seems to be properly configured.
So why does this error occur? Fortunately found a solution and here it’s.
How to fix the error – OpenCA Error Cannot load certificate from the database
- The
listCertsfile contains the sub-routinecmdListCertswhich takes the$queryand parses it. $dataTypeis one of the things it extracts.@certsListis filled by the database query, which seems to work for listing theCA_CERTIFICATE.$typeis filled out by$dataTypeparsed from the link calling the script. So, this should appear as query argument"dataType"in the link behind theserialand by clicking that link it should be sent to theviewCert. There again,$dataTypeis parsed from$queryjust as it was forlistCerts, but somehow this doesn’t work correctly in my OpenCA setup.
I suspected the way viewCert distinguishes between CERTIFICATE and
CA_CERTIFICATE and the way various queries for valid, expired,
suspended, and revoked certificates are handled.
So here is a modification to the viewCert cmd in the file lib/openca/perl_modules/perl5/OpenCA/AC.pm
Navigate to the sub-routine getOwner where you will find the following:
sub getOwner {Locate the line: # load the certificate
Replace the below lines
my @certs;
my $certype = "CERTIFICATE";
if( not (@certs = $self->{db}->searchItems (
KEY => $self->{acl}->{object},
DATATYPE => "CERTIFICATE"))) {
# if (length ($self->{acl}->{object}) < 60 ) { # @certs = $self->{db}->searchItems (KEY => $self->{acl}->{object}, DATATYPE => "CERTIFICATE");
#}
$certtype = "CA_CERTIFICATE";
@certs = $self->{db}->searchItems (
KEY => $self->{acl}->{object},
DATATYPE => "CERTIFICATE");
}With:
my @certs;
my $certtype = "CERTIFICATE";
if( $self->{db}->searchItems (
KEY => $self->{acl}->{object},
DATATYPE => "CERTIFICATE")) {
$certtype = "CA_CERTIFICATE";
@certs = $self->{db}->searchItems (
KEY => $self->{acl}->{object},
DATATYPE => "CERTIFICATE");
} else {
$certtype = "CA_CERTIFICATE";
@certs = $self->{db}->searchItems (
KEY => $self->{acl}->{object},
DATATYPE => "CA_CERTIFICATE");
}The issue was with the line: if( not (@certs = $self->{db}->searchItems (.
That’s it! Hope it helps someone out there.
