1079a7
From 984190eea01ac42cd1f97567a67dd9446e5b0bf9 Mon Sep 17 00:00:00 2001
1079a7
From: Francisco Trivino <ftrivino@redhat.com>
1079a7
Date: Fri, 11 Mar 2022 17:47:38 +0100
1079a7
Subject: [PATCH] Set AES as default for KRA archival wrapping
1079a7
1079a7
This commit sets AES-128-CBC as default wrapping algorithm as
1079a7
TripleDES (des-ede3-cbc) is not supported anymore in C9S.
1079a7
1079a7
Fixes: https://pagure.io/freeipa/issue/6524
1079a7
1079a7
Signed-off-by: Francisco Trivino <ftrivino@redhat.com>
1079a7
Reviewed-By: Christian Heimes <cheimes@redhat.com>
1079a7
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
1079a7
---
1079a7
 API.txt             |  6 +++---
1079a7
 ipalib/constants.py | 14 +++++++++-----
1079a7
 2 files changed, 12 insertions(+), 8 deletions(-)
1079a7
1079a7
diff --git a/API.txt b/API.txt
1079a7
index f95f2c8457e39f2268386a8a2336952d3285e008..1f27dcc616a6395c56ef91f3453e7620625c7645 100644
1079a7
--- a/API.txt
1079a7
+++ b/API.txt
1079a7
@@ -6559,7 +6559,7 @@ option: Flag('shared?', autofill=True, default=False)
1079a7
 option: Str('username?', cli_name='user')
1079a7
 option: Bytes('vault_data')
1079a7
 option: Str('version?')
1079a7
-option: StrEnum('wrapping_algo?', autofill=True, default=u'des-ede3-cbc', values=[u'des-ede3-cbc', u'aes-128-cbc'])
1079a7
+option: StrEnum('wrapping_algo?', autofill=True, default=u'aes-128-cbc', values=[u'aes-128-cbc', u'des-ede3-cbc'])
1079a7
 output: Entry('result')
1079a7
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
1079a7
 output: PrimaryKey('value')
1079a7
@@ -6659,7 +6659,7 @@ option: Bytes('session_key')
1079a7
 option: Flag('shared?', autofill=True, default=False)
1079a7
 option: Str('username?', cli_name='user')
1079a7
 option: Str('version?')
1079a7
-option: StrEnum('wrapping_algo?', autofill=True, default=u'des-ede3-cbc', values=[u'des-ede3-cbc', u'aes-128-cbc'])
1079a7
+option: StrEnum('wrapping_algo?', autofill=True, default=u'aes-128-cbc', values=[u'aes-128-cbc', u'des-ede3-cbc'])
1079a7
 output: Entry('result')
1079a7
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
1079a7
 output: PrimaryKey('value')
1079a7
@@ -7329,10 +7329,10 @@ default: vaultcontainer_del/1
1079a7
 default: vaultcontainer_remove_owner/1
1079a7
 default: vaultcontainer_show/1
1079a7
 default: whoami/1
1079a7
-capability: vault_aes_keywrap 2.246
1079a7
 capability: messages 2.52
1079a7
 capability: optional_uid_params 2.54
1079a7
 capability: permissions2 2.69
1079a7
 capability: primary_key_types 2.83
1079a7
 capability: datetime_values 2.84
1079a7
 capability: dns_name_values 2.88
1079a7
+capability: vault_aes_keywrap 2.246
1079a7
diff --git a/ipalib/constants.py b/ipalib/constants.py
1079a7
index 11171b2e8aeb6f7306299b2bd7db3a3f39d29d4a..68178004181bebcc8c093dac55e18d5afe0251e5 100644
1079a7
--- a/ipalib/constants.py
1079a7
+++ b/ipalib/constants.py
1079a7
@@ -29,6 +29,8 @@ from ipaplatform.constants import constants as _constants
1079a7
 from ipapython.dn import DN
1079a7
 from ipapython.fqdn import gethostfqdn
1079a7
 from ipapython.version import VERSION, API_VERSION
1079a7
+from cryptography.hazmat.primitives.ciphers import algorithms, modes
1079a7
+from cryptography.hazmat.backends.openssl.backend import backend
1079a7
 
1079a7
 
1079a7
 FQDN = gethostfqdn()
1079a7
@@ -379,10 +381,12 @@ ALLOWED_NETBIOS_CHARS = string.ascii_uppercase + string.digits + '-'
1079a7
 VAULT_WRAPPING_3DES = 'des-ede3-cbc'
1079a7
 VAULT_WRAPPING_AES128_CBC = 'aes-128-cbc'
1079a7
 VAULT_WRAPPING_SUPPORTED_ALGOS = (
1079a7
-    # old default was 3DES
1079a7
-    VAULT_WRAPPING_3DES,
1079a7
-    # supported since pki-kra >= 10.4
1079a7
+    # new default and supported since pki-kra >= 10.4
1079a7
     VAULT_WRAPPING_AES128_CBC,
1079a7
 )
1079a7
-# 3DES for backwards compatibility
1079a7
-VAULT_WRAPPING_DEFAULT_ALGO = VAULT_WRAPPING_3DES
1079a7
+VAULT_WRAPPING_DEFAULT_ALGO = VAULT_WRAPPING_AES128_CBC
1079a7
+
1079a7
+# Add 3DES for backwards compatibility if supported
1079a7
+if backend.cipher_supported(algorithms.TripleDES(b"\x00" * 8),
1079a7
+                            modes.CBC(b"\x00" * 8)):
1079a7
+    VAULT_WRAPPING_SUPPORTED_ALGOS += (VAULT_WRAPPING_3DES,)
1079a7
-- 
1079a7
2.34.1
1079a7