Automation of Certificate Uploads

Hi,

I’m trying to write a powershell script to upload a certificate into Octopus.This will be useful because we’ve got a large number of certs to upload and when they expire I need to enforce that the old certificate is replaced and that a new one is not just uploaded alongside it.
I can’t get this to work. The same pfx/password combination upload fine through the Octopus UI.

$Name = “Test Cert Upload”
$certificateData = Get-Content “” -Encoding Byte
$password = ‘***’
$sspassword = ConvertTo-SecureString $password -AsPlainText -Force
$certDataBase64 = [System.Convert]::ToBase64String($CertificateData)
$_cert = new-object Octopus.Client.Model.CertificateResource( $Name , $certDataBase64 , $sspassword )
$repository.Certificates.Create( $_cert )

It’s causing an error:
Exception calling “Create” with “1” argument(s): "There was a problem with your request.

  • Incorrect password (otherwise possible corrupt file)

Cheers,

Chris

1 Like

Hi Chris,

Thanks for getting in touch!

By the look of it, the password to pass to the CertificateResource constructor is a normal string, not a SecureString.

So, you should be able to get it to work with:

$Name = "Test Cert Upload"
$certificateData = Get-Content "" -Encoding Byte $password = '***'
$certDataBase64 = [System.Convert]::ToBase64String($CertificateData)
$_cert = new-object Octopus.Client.Model.CertificateResource( $Name , $certDataBase64 , $password )
$repository.Certificates.Create( $_cert )

Hope that helps!

Regards,
Matt

Hi,
I’ve resolved this now, the problem was some of our certificates were exported from Windows Server 2003 and these are the ones causing an error on uploading to Octopus. I’ve reexported the problem certs from Windows Server 2012 and it all works now.

I was going to send you a dummy certificate from Windows Server 2003 so you could test and improve your error message, but unfortunately I don’t have access to the server involved.

Thanks,

Chris

Whoops - that previous reply should have been on another problem I’ve raised ‘Error loading certificate pfx files through Octopus UI and .net method’

Hi Chris

No worries, I’ve moved the response to the other ticket - http://help.octopusdeploy.com/discussions/problems/54364-error-loading-certificate-pfx-files-through-octopus-ui-and-net-method

Regards,
Matt