azure-pipelines-tasks: [BUG]: InstallAppleCertificate STILL fails to install certificates

New issue checklist

Task name

InstallAppleCertificate@2

Task version

2.231.1

Issue Description

Hello Azure DevOps devs,

i’ve begun to rebuild my CD pipeline as part of an ongoing migration of my iOS app to .NET 8. Currently my pipeline keeps failing at the InstallAppleCertificate task.

I’ve made sure that the certificate and provisioning profile are up-to-date and i’ve looked up the issue on GitHub. People have suggested to pass the flag -legacy to the task whenever the issue was reported, however the -legacy flag is not recognized by openssl. The latest Github Issue ended with a user still facing this issue, however the issue was closed solely because the -legacy flag was passed on to openssl. (https://github.com/microsoft/azure-pipelines-tasks/issues/19436). The user still couldn’t install the certificate.

Another issue (https://github.com/microsoft/azure-pipelines-tasks/issues/19383) was closed because the user regenerated their certificate and yet another issue (https://github.com/microsoft/azure-pipelines-tasks/issues/18560) was closed because of… i don’t know, because nobody reported it as fixed or as going stale or whatever. Someone suggested that the OpenSSL version was outdated, however i don’t know how to update it or whether i can update it on hosted images. I tried out Microsoft’s images macos-11, macos-12 and macos-13 too.

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

macos-13

Relevant log output

Starting: Install Certificate
==============================================================================
Task         : Install Apple certificate
Description  : Install an Apple certificate required to build on a macOS agent machine
Version      : 2.231.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/install-apple-certificate
==============================================================================
/usr/local/bin/openssl pkcs12 -in /Users/runner/work/_temp/ios_distribution.p12 -nokeys -passin pass:*** -legacy | /usr/local/bin/openssl x509 -sha1 -noout -fingerprint -subject -dates -nameopt utf8,sep_semi_plus_space
pkcs12: Unrecognized flag legacy
pkcs12: Use -help for summary.
unable to load certificate
4657255936:error:0909006C:PEM routines:get_name:no start line:crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE
##[warning]Error parsing certificate. This might be caused by an unsupported algorithm. If you're using old certificate with a new OpenSSL version try to set -legacy flag in opensslPkcsArgs input.
##[error]Error: /usr/local/bin/openssl failed with return code: 1
Finishing: Install Certificate

Full task logs with system.debug enabled

 [REPLACE THIS WITH YOUR INFORMATION] 

Repro steps

- task: InstallAppleCertificate@2
  displayName: 'Install Certificate'
  inputs:
    certSecureFile: 'ios_distribution.p12'
    certPwd: '$(Passwort)'
    keychain: 'temp'
    deleteCert: true

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 9
  • Comments: 25 (1 by maintainers)

Most upvoted comments

@arnauZurich As @mjosipovic-tgr suggested in https://github.com/actions/runner-images/issues/10703#issuecomment-2472826230, you could use 2 copies of the InstallAppleCertificate task. One with -legacy, one without. Works fine on our side.

Uuuh… devs… When is “soon” happening? The build is still failing more than 60 days later.

Seems like Microsoft published a fix in macos-15 20241106.316.

With macos-15 20241022.244 I still see failing builds with “pkcs12: Unrecognized flag legacy” warning included.

The unfortunate thing: 20241106.316 does not seem to be published to all hosted agents as of now.

Edit: It seems like we need “-legacy” for 20241106.316, but need to omit it for 20241022.244. This way both configurations work fine. But as of now I do not see a way to determine the exact image version and decide if -legacy is added in yaml.

This a work around for me but I hardcoded the cert pass for now this script can’t read a variable even I add a env: parameter it always empty value.

  • task: DownloadSecureFile@1 name: downloadDefaultCert displayName: ‘Download Apple Certificate’ inputs: secureFile: ‘P12 FILE HERE’

  • task: Bash@3 displayName: Install Apple Certificate inputs: targetType: ‘inline’ script: | echo “Installing signing certificate…” CERT_PASSWORD=“YourHardcodedPasswordHere” # Hardcoded password for testing if [ -z “$CERT_PASSWORD” ]; then echo “ERROR: CERT_PASSWORD is empty. Please check your password.” exit 1 fi

    Import the certificate using the password

    security import $(downloadDefaultCert.secureFilePath) -k ~/Library/Keychains/login.keychain -P “$CERT_PASSWORD” -T /usr/bin/codesign echo “Certificate installed successfully.”

Same for me. Today the same config and certs worked well but a few hours later it fails with:

Starting: Install an Apple certificate

==============================================================================

Task : Install Apple certificate Description : Install an Apple certificate required to build on a macOS agent machine Version : 2.246.5 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/install-apple-certificate

==============================================================================

/usr/local/bin/openssl pkcs12 -in /Users/runner/work/_temp/Development.p12 -nokeys -passin pass:*** -legacy | /usr/local/bin/openssl x509 -sha1 -noout -fingerprint -subject -dates -nameopt utf8,sep_semi_plus_space pkcs12: Unrecognized flag legacy pkcs12: Use -help for summary. unable to load certificate 140704478854656:error:0909006C:PEM routines:get_name:no start line:crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE ##[warning]Error parsing certificate. This might be caused by an unsupported algorithm. If you’re using old certificate with a new OpenSSL version try to set -legacy flag in opensslPkcsArgs input. ##[error]Error: /usr/local/bin/openssl failed with return code: 1 Finishing: Install an Apple certificate

What happened? How can we fix this?

Yes it happens to me today, I cant build when I pass -legacy on openssl argument it solved for one succeeding build but when I rebuild my app is says

pkcs12: Unrecognized flag legacy pkcs12: Use -help for summary. unable to load certificate 140704456046208:error:0909006C:PEM routines:get_name:no start line:crypto/pem/pem_lib.c:745:Expecting: TRUSTED CERTIFICATE

This suddenly started happening for us today, with an Apple certificate created 7 months ago so not really that old. I assumed some CI agent tooling was upgraded and starting going through the various workarounds of passing -legacy flag, manually upgrading OpenSSL and manually installing the cert, but then it suddenly resolved itself again after a few hours.

I suspected maybe a particular macOS VM image version was bad, but I got both good and bad builds on the exact same versions:

  • Image: macos-14 Version: 20241022.254
  • Image: macos-14 Version: 20241106.300

When debugging, the bad builds used OpenSSL 1.1.1w

- script: |
    which openssl
    /usr/bin/openssl version
    openssl version
  displayName: OpenSSL stuff
  condition: always()

Output:

/usr/local/bin/openssl
OpenSSL 1.1.1w  11 Sep 2023
LibreSSL 3.3.6

Posting this for anyone else having similar, flaky issues.

Related: https://github.com/microsoft/azure-pipelines-tasks-common-packages/issues/353 https://github.com/openssl/openssl/discussions/23089#discussioncomment-7895826