From 7b5f3d79712a84f88ced6e9055bc96c9980b0b20 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Wed, 31 Jul 2024 11:48:40 +0300 Subject: [PATCH] Get rid of unicode and long helpers in ipa-otptoken-import Related: https://pagure.io/freeipa/issue/9641 Signed-off-by: Alexander Bokovoy Reviewed-By: Rob Crittenden --- ipaserver/install/ipa_otptoken_import.py | 63 ++++++++++++------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py index e8a3a2457..279a7502d 100644 --- a/ipaserver/install/ipa_otptoken_import.py +++ b/ipaserver/install/ipa_otptoken_import.py @@ -45,10 +45,6 @@ from ipalib import api, errors from ipalib.constants import VAULT_WRAPPING_SUPPORTED_ALGOS, VAULT_WRAPPING_3DES from ipaserver.plugins.ldap2 import AUTOBIND_DISABLED -if six.PY3: - unicode = str - long = int - logger = logging.getLogger(__name__) @@ -294,43 +290,47 @@ class XMLDecryptor: class PSKCKeyPackage: _XML = { 'pskc:DeviceInfo': { - 'pskc:IssueNo/text()': ('issueno', unicode), - 'pskc:ExpiryDate/text()': ('notafter.hw', convertDate), - 'pskc:Manufacturer/text()': ('vendor', unicode), - 'pskc:Model/text()': ('model', unicode), - 'pskc:SerialNo/text()': ('serial', unicode), - 'pskc:StartDate/text()': ('notbefore.hw', convertDate), - 'pskc:UserId/text()': ('owner', unicode), + 'pskc:IssueNo/text()': ('issueno', str), + 'pskc:ExpiryDate/text()': ('notafter.hw', convertDate), + 'pskc:Manufacturer/text()': ('vendor', str), + 'pskc:Model/text()': ('model', str), + 'pskc:SerialNo/text()': ('serial', str), + 'pskc:StartDate/text()': ('notbefore.hw', convertDate), + 'pskc:UserId/text()': ('owner', str), }, 'pskc:Key': { - '@Algorithm': ('type', convertTokenType), - '@Id': ('id', unicode), - 'pskc:FriendlyName/text()': ('description', unicode), - 'pskc:Issuer/text()': ('issuer', unicode), - 'pskc:KeyReference/text()': ('keyref', unicode), + '@Algorithm': ('type', convertTokenType), + '@Id': ('id', str), + 'pskc:FriendlyName/text()': ('description', str), + 'pskc:Issuer/text()': ('issuer', str), + 'pskc:KeyReference/text()': ('keyref', str), 'pskc:AlgorithmParameters': { - 'pskc:Suite/text()': ('algorithm', convertHashName), - 'pskc:ResponseFormat/@CheckDigit': ('checkdigit', unicode), - 'pskc:ResponseFormat/@Encoding': ('encoding', unicode), - 'pskc:ResponseFormat/@Length': ('digits', int), + 'pskc:Suite/text()': ('algorithm', convertHashName), + 'pskc:ResponseFormat/@CheckDigit': ('checkdigit', str), + 'pskc:ResponseFormat/@Encoding': ('encoding', str), + 'pskc:ResponseFormat/@Length': ('digits', int), }, 'pskc:Data': { - 'pskc:Counter': ('counter', lambda v, d: convertEncrypted(v, d, long, long)), - 'pskc:Secret': ('key', convertEncrypted), - 'pskc:Time': ('time', lambda v, d: convertEncrypted(v, d, int, int)), - 'pskc:TimeDrift': ('offset', lambda v, d: convertEncrypted(v, d, int, int)), - 'pskc:TimeInterval': ('interval', lambda v, d: convertEncrypted(v, d, int, int)), + 'pskc:Counter': + ('counter', lambda v, d: convertEncrypted(v, d, int, int)), + 'pskc:Secret': ('key', convertEncrypted), + 'pskc:Time': + ('time', lambda v, d: convertEncrypted(v, d, int, int)), + 'pskc:TimeDrift': + ('offset', lambda v, d: convertEncrypted(v, d, int, int)), + 'pskc:TimeInterval': + ('interval', lambda v, d: convertEncrypted(v, d, int, int)) }, 'pskc:Policy': { - 'pskc:ExpiryDate/text()': ('notafter.sw', convertDate), - 'pskc:KeyUsage/text()': ('keyusage', unicode), - 'pskc:NumberOfTransactions': ('maxtransact', lambda v: v), - 'pskc:PINPolicy': ('pinpolicy', lambda v: v), - 'pskc:StartDate/text()': ('notbefore.sw', convertDate), + 'pskc:ExpiryDate/text()': ('notafter.sw', convertDate), + 'pskc:KeyUsage/text()': ('keyusage', str), + 'pskc:NumberOfTransactions': ('maxtransact', lambda v: v), + 'pskc:PINPolicy': ('pinpolicy', lambda v: v), + 'pskc:StartDate/text()': ('notbefore.sw', convertDate), }, }, } @@ -454,7 +454,8 @@ class PSKCKeyPackage: dates = (data.get(key + '.sw', None), data.get(key + '.hw', None)) dates = [x for x in dates if x is not None] if dates: - out['ipatoken' + key] = unicode(reducer(dates).strftime("%Y%m%d%H%M%SZ")) + out['ipatoken' + key] = str( + reducer(dates).strftime("%Y%m%d%H%M%SZ")) class PSKCDocument: