Forum Discussion
How to upload cert through Management :: KeyCertificate :: certificate_import_from_file
I adopted the Perl Certificate Info script https://devcentral.f5.com/wiki/iControl.PlCertificateInfo.ashx, and attempt to add new feature like uploading certificate to BIGIP according to https://devcentral.f5.com/wiki/iControl.Management__KeyCertificate__certificate_import_from_file.ashx, sample code below, the script is not working and there is no error reports, anyone can shed some light on what's going on?
use SOAP::Lite;
use MIME::Base64;
use Math::BigInt;
BEGIN { push (@INC, ".."); }
use iControlTypeCast;
----------------------------------------------------------------------------
Validate Arguments
----------------------------------------------------------------------------
my $sHost = $ARGV[0];
my $sPort = $ARGV[1];
my $sUID = $ARGV[2];
my $sPWD = $ARGV[3];
my $sCommand = $ARGV[4];
my $sProtocol = "https";
my $sMode = "MANAGEMENT_MODE_DEFAULT";
my $sCert_ids = "vli_cert";
my $sFile_names = "/home/vincent/vli_webselfsigncrt.pem"; <==where cert stored in my local linux
if ( ("80" eq $sPort) or ("8080" eq $sPort) )
{
$sProtocol = "http";
}
if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") )
{
&usage();
}
sub usage()
{
my ($sCmd) = @_;
print "Usage: CertAdmin.pl host port uid pwd command [options]\n";
print " -----------------------------------------------------------\n";
if ( ($sCmd eq "") or ($sCmd eq "upload") )
{
print " upload - upload certificate\n";
}
if ( ($sCmd eq "") or ($sCmd eq "info") )
{
print " info - List certificate info\n";
}
if ( ($sCmd eq "") or ($sCmd eq "version") )
{
print " version - Gets the version of this interface\n";
}
exit();
}
----------------------------------------------------------------------------
Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
$KeyCertificate = SOAP::Lite
-> uri('urn:iControl:Management/KeyCertificate')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval { $KeyCertificate->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
if ( $sCommand eq "upload" )
{
&UPLoadCert($sMode);
}
elsif ( $sCommand eq "info" )
{
&GetCertInfo($sMode);;
}
elsif ( $sCommand eq "version" )
{
&handle_version();
}
else
{
&usage();
}
sub UPLoadCert()
{
my $mode = (@_);
$soapResponse = $KeyCertificate->certificate_import_from_file(
SOAP::Data->name(mode => $sMode),
SOAP::Data->name(cert_ids => $sCert_ids),
SOAP::Data->name(file_names => $sFile_names),
SOAP::Data->name(overwrite => 1),
);
&checkResponse($soapResponse);
}
sub GetCertInfo()
{
my ($mode) = (@_);
$soapResponse = $KeyCertificate->get_certificate_list(
SOAP::Data->name(mode => $mode)
);
............SNIP......
}
so if I run "./CertAdmin.pl host port user pass info", it work fine to list existing cert info
but if I run "./CertAdmin host port user pass upload", no errors, but nothing happens to the cert uploading, the function certificate_import_from_file() is bit unclear on where to put the originate certificate, on local box or on bigip.
Vincent
- hooleylistCirrostratusHi Vincent,
- Travis_Collavo_Historic F5 AccountHello,
- Travis_Collavo_Historic F5 AccountPS - I've tried referencing the local file on my laptop as well as an uploaded copy in /var/tmp and /config/ssl/ssl.crt with no difference in the end result.
- Alex__ApplebaumEmployee1) The method expects you to pass an array for the cert_ids and file_names fields
- mhite_60883CirrocumulusThis is what I do.
derive identifier from cert_pem_data log.info("Determining certificate subject CN...") x509 = crypto.load_certificate(crypto.FILETYPE_PEM, cert_pem_data) for component in x509.get_subject().get_components(): if component[0].lower() == "cn": subject_cn = component[1] log.info("CN is \"%s\"." % subject_cn) log.debug("Scrubbing subject CN to create certificate/key identifier...") identifier = replace_all(subject_cn, {'*': 'wildcard'}).strip() log.debug("identifier = %s" % identifier) - Upload the pem key / cert management_mode_type = b.Management.KeyCertificate.typefactory.create("Management.KeyCertificate.ManagementModeType") b.Management.KeyCertificate.certificate_import_from_pem(mode=management_mode_type.MANAGEMENT_MODE_DEFAULT, cert_ids=[identifier], pem_data=[pem_data], overwrite=True) time.sleep(3) b.Management.KeyCertificate.key_import_from_pem(mode=management_mode_type.MANAGEMENT_MODE_DEFAULT, key_ids=[identifier], pem_data=[pem_data], overwrite=True)
- hooleylistCirrostratusThanks for the info Matt and Alex.
- spuds23_86950Nimbostratus
Hi,
I am starting to work with iControl to provision/manage ssl certs. Can you please provide your code which generates the client SSL profile/bundle (intermediate cert).
Thank you.
- Spuds23
- VernonWellsEmployee
I've posted an example script using the
andManagement::KeyCertificate::certificate_import_from_file
methods in Perl:Management::KeyCertificate::key_import_from_file
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com