Get rid of unicode and long helpers in ipa-otptoken-import

Related: https://pagure.io/freeipa/issue/9641

Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Alexander Bokovoy 2024-07-31 11:48:40 +03:00 committed by Rob Crittenden
parent fc02904340
commit 7b5f3d7971

View File

@ -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,40 +290,44 @@ class XMLDecryptor:
class PSKCKeyPackage:
_XML = {
'pskc:DeviceInfo': {
'pskc:IssueNo/text()': ('issueno', unicode),
'pskc:IssueNo/text()': ('issueno', str),
'pskc:ExpiryDate/text()': ('notafter.hw', convertDate),
'pskc:Manufacturer/text()': ('vendor', unicode),
'pskc:Model/text()': ('model', unicode),
'pskc:SerialNo/text()': ('serial', unicode),
'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', unicode),
'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),
'@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/@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: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: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: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: