[SRU] Strongswan pki creates CA certificates with invalid Key Usage flags

Bug #1879692 reported by Alexander Schulz
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
strongSwan
Unknown
Unknown
strongswan (Ubuntu)
Fix Released
Undecided
Unassigned
Focal
Fix Released
High
Lucas Kanashiro

Bug Description

[Impact]

Strongswan pki/x509 modules create CA certificates with invalid Key Usage flags when compiling with GCC 9+. Actually this is an issue when calling the chunk_from_chars() macro, not impacting only the mentioned modules. The newer compilers might optimize out the assignment leading to invalid values. More information here:

https://wiki.strongswan.org/issues/3249

In the case of the CA certificate creation, the NSS library using RFC 4945 IPsec profiles will reject the certificate validation because of the empty yet critical Key Usage section.

[Test Case]

$ lxc launch ubuntu-daily:focal strongswan-sru
$ lxc shell strongswan-sru
$ apt update && apt upgrade -y
$ apt install strongswan strongswan-pki -y

# Generate key an certificate
$ pki --gen --type ecdsa --size 384 > strongCAkey.der
$ pki --self --in strongCAkey.der --dn "C=CH, O=strongSwan, CN=strongSwan CA" --ca > strongCAcert.der

# Check the certificate with openssl, note the '....' in the Key Usage extension, this is not valid
$ openssl x509 -inform DER -in strongCAcert.der -noout -text | grep -A3 -B3 'Key Usage'
        X509v3 extensions:
            X509v3 Basic Constraints: critical
                CA:TRUE
            X509v3 Key Usage: critical
                ....
            X509v3 Subject Key Identifier:
                D2:F5:58:B3:2A:3F:11:68:8E:AA:47:7A:29:9F:AC:8E:70:9E:EA:25

[Regression Potential]

The upstream patches touch many places of the code base, look here:

https://git.strongswan.org/?p=strongswan.git&a=search&h=HEAD&st=commit&s=3249

So a possible regression because of this SRU would be expected in one of those modules: pki, x509, libtpmtss, tls-crypto and lgtm. However, the changes are trivial and the risk is low.

[Original Description]

This bug is already fixed in upstream.
For explanation and steps to reproduce seee https://wiki.strongswan.org/issues/3249

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: strongswan-pki 5.8.2-1ubuntu3
ProcVersionSignature: User Name 5.4.0-1010.10-azure 5.4.30
Uname: Linux 5.4.0-1010-azure x86_64
ApportVersion: 2.20.11-0ubuntu27
Architecture: amd64
CasperMD5CheckResult: skip
Date: Wed May 20 12:09:33 2020
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=C.UTF-8
 SHELL=/bin/bash
SourcePackage: strongswan
UpgradeStatus: No upgrade log present (probably fresh install)

Related branches

Revision history for this message
Alexander Schulz (aschulz1) wrote :
Revision history for this message
Paride Legovini (paride) wrote :

Thanks Alexander for this bug report and for finding the upstream bug report, I linked it to this report.

The bug is fixed upstream, but the required patches are spread across at least 5 commits:

https://git.strongswan.org/?p=strongswan.git&a=search&h=HEAD&st=commit&s=3249

It is not totally straightforward to understand the scope of those changes, but the bug is valid and actionable.

Changed in strongswan (Ubuntu):
status: New → Triaged
tags: added: server-next
Changed in strongswan (Ubuntu Focal):
status: New → Triaged
Changed in strongswan (Ubuntu):
status: Triaged → Fix Released
Changed in strongswan (Ubuntu Focal):
assignee: nobody → Lucas Kanashiro (lucaskanashiro)
importance: Undecided → High
Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

As @Paride mentioned this issue requires 5 upstream commits because it does not affect only the pki module. This issue is affecting some chunk_from_chars calls throughout the code base.

I am working to backport the 5 upstream commits to Focal.

Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

The proposed package is available here:

https://launchpad.net/~lucaskanashiro/+archive/ubuntu/focal-strongswan-bug-fixes

I performed the test above to check if the CA certificate is generated correctly:

[in the same container I was using to describe the Test Case section in the description]
$ add-apt-repository ppa:lucaskanashiro/focal-strongswan-bug-fixes -y
$ apt install strongswan strongswan-pki -y

# Generate key an certificate
$ pki --gen --type ecdsa --size 384 > strongCAkey2.der
$ pki --self --in strongCAkey2.der --dn "C=CH, O=strongSwan, CN=strongSwan CA" --ca > strongCAcert2.der

# Check the certificate with openssl, note the the CertificateSign and CRLsign flags are set in the Key Usage extension
$ openssl x509 -inform DER -in strongCAcert2.der -noout -text | grep -A3 -B3 'Key Usage'
        X509v3 extensions:
            X509v3 Basic Constraints: critical
                CA:TRUE
            X509v3 Key Usage: critical
                Certificate Sign, CRL Sign
            X509v3 Subject Key Identifier:
                AF:A0:08:A7:E1:C7:12:31:77:E1:01:24:23:00:5B:0A:1F:D1:2A:1A

description: updated
summary: - Strongswan pki creates CA certificates with invalid Key Usage flags
+ [SRU] Strongswan pki creates CA certificates with invalid Key Usage
+ flags
Changed in strongswan (Ubuntu Focal):
status: Triaged → In Progress
tags: added: verification-done verification-done-focal
Revision history for this message
Chris Halse Rogers (raof) wrote : Please test proposed package

Hello Alexander, or anyone else affected,

Accepted strongswan into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/strongswan/5.8.2-1ubuntu3.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in strongswan (Ubuntu Focal):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-focal
removed: verification-done verification-done-focal
Revision history for this message
Alexander Schulz (aschulz1) wrote :

I just tested the package from focal-proposed and generated a new CA certificate with correct Key-Extension Flags.
This fixes the bug for me.

See https://paste.ubuntu.com/p/z5pPDSZHHH/

tags: added: verification-done-focal
removed: verification-needed-focal
tags: added: verification-done
removed: verification-needed
Revision history for this message
Jamon Camisso (jamon) wrote :

Another +1 for what it's worth, this fixes things nicely.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package strongswan - 5.8.2-1ubuntu3.1

---------------
strongswan (5.8.2-1ubuntu3.1) focal; urgency=medium

  * Re-enable eap-{dynamic,peap} libcharon plugins (LP: #1878887)
    - d/control: update libcharon-extra-plugins description.
    - d/libcharon-extra-plugins.install: install .so and conf files.
    - d/rules: add plugins to the configuration arguments.
  * Remove conf files of plugins removed from libcharon-extra-plugins
    - The conf file of the following plugins were removed: eap-aka-3gpp2,
      eap-sim-file, eap-sim-pcsc, eap-sim, eap-simaka-pseudonym,
      eap-simaka-reauth, eap-simaka-sql, xauth-noauth.
    - Created d/libcharon-extra-plugins.maintscript to handle the removals
      properly.
  * Add patches to fix the chunk_from_chars() macro compiled with GCC 9+
    (LP: #1879692)
    - Patches backported from upstream: lp-1879692-{1,2,3,4,5}.patch.
    - Fix the pki CA certificate creation issue.

 -- Lucas Kanashiro <email address hidden> Fri, 22 May 2020 10:53:07 -0300

Changed in strongswan (Ubuntu Focal):
status: Fix Committed → Fix Released
Revision history for this message
Łukasz Zemczak (sil2100) wrote : Update Released

The verification of the Stable Release Update for strongswan has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.