2014-05-08 11:06:16 -04:00
|
|
|
# Authors:
|
|
|
|
|
# Nathaniel McCallum <npmccallum@redhat.com>
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2014 Red Hat
|
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2017-06-20 10:21:05 +02:00
|
|
|
import codecs
|
2014-05-08 11:06:16 -04:00
|
|
|
import os
|
2015-08-17 09:06:24 +02:00
|
|
|
import pytest
|
2014-05-08 11:06:16 -04:00
|
|
|
|
|
|
|
|
from ipaserver.install.ipa_otptoken_import import PSKCDocument, ValidationError
|
2017-09-14 17:31:57 +03:00
|
|
|
from ipaserver.install.ipa_otptoken_import import convertHashName
|
2014-05-08 11:06:16 -04:00
|
|
|
|
|
|
|
|
basename = os.path.join(os.path.dirname(__file__), "data")
|
|
|
|
|
|
2015-04-24 14:39:48 +02:00
|
|
|
@pytest.mark.tier1
|
2018-09-26 11:59:50 +02:00
|
|
|
class test_otptoken_import:
|
2014-05-08 11:06:16 -04:00
|
|
|
def test_figure3(self):
|
|
|
|
|
doc = PSKCDocument(os.path.join(basename, "pskc-figure3.xml"))
|
|
|
|
|
assert doc.keyname is None
|
|
|
|
|
assert [(t.id, t.options) for t in doc.getKeyPackages()] == \
|
|
|
|
|
[(u'12345678', {
|
|
|
|
|
'ipatokenotpkey': u'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ',
|
|
|
|
|
'ipatokenvendor': u'Manufacturer',
|
|
|
|
|
'ipatokenserial': u'987654321',
|
2015-07-15 16:38:06 +02:00
|
|
|
'ipatokenhotpcounter': 0,
|
2014-05-08 11:06:16 -04:00
|
|
|
'ipatokenotpdigits': 8,
|
|
|
|
|
'type': u'hotp',
|
|
|
|
|
})]
|
|
|
|
|
|
|
|
|
|
def test_figure4(self):
|
|
|
|
|
doc = PSKCDocument(os.path.join(basename, "pskc-figure4.xml"))
|
|
|
|
|
assert doc.keyname is None
|
|
|
|
|
try:
|
|
|
|
|
[(t.id, t.options) for t in doc.getKeyPackages()]
|
|
|
|
|
except ValidationError: # Referenced keys are not supported.
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
def test_figure5(self):
|
|
|
|
|
doc = PSKCDocument(os.path.join(basename, "pskc-figure5.xml"))
|
|
|
|
|
assert doc.keyname is None
|
|
|
|
|
try:
|
|
|
|
|
[(t.id, t.options) for t in doc.getKeyPackages()]
|
|
|
|
|
except ValidationError: # PIN Policy is not supported.
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
def test_figure6(self):
|
2015-08-31 10:46:19 -04:00
|
|
|
doc = PSKCDocument(os.path.join(basename, "pskc-figure6.xml"))
|
|
|
|
|
assert doc.keyname == 'Pre-shared-key'
|
2017-06-20 10:21:05 +02:00
|
|
|
doc.setKey(codecs.decode('12345678901234567890123456789012', 'hex'))
|
2015-08-31 10:46:19 -04:00
|
|
|
assert [(t.id, t.options) for t in doc.getKeyPackages()] == \
|
|
|
|
|
[(u'12345678', {
|
|
|
|
|
'ipatokenotpkey': u'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ',
|
|
|
|
|
'ipatokenvendor': u'Manufacturer',
|
|
|
|
|
'ipatokenserial': u'987654321',
|
|
|
|
|
'ipatokenhotpcounter': 0,
|
|
|
|
|
'ipatokenotpdigits': 8,
|
|
|
|
|
'type': u'hotp'})]
|
2014-05-08 11:06:16 -04:00
|
|
|
|
|
|
|
|
def test_figure7(self):
|
2015-08-31 10:46:19 -04:00
|
|
|
doc = PSKCDocument(os.path.join(basename, "pskc-figure7.xml"))
|
|
|
|
|
assert doc.keyname == 'My Password 1'
|
2017-06-20 10:41:28 +02:00
|
|
|
doc.setKey(b'qwerty')
|
2015-08-31 10:46:19 -04:00
|
|
|
assert [(t.id, t.options) for t in doc.getKeyPackages()] == \
|
|
|
|
|
[(u'123456', {
|
|
|
|
|
'ipatokenotpkey': u'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ',
|
|
|
|
|
'ipatokenvendor': u'TokenVendorAcme',
|
|
|
|
|
'ipatokenserial': u'987654321',
|
|
|
|
|
'ipatokenotpdigits': 8,
|
|
|
|
|
'type': u'hotp'})]
|
2014-05-08 11:06:16 -04:00
|
|
|
|
|
|
|
|
def test_figure8(self):
|
|
|
|
|
try:
|
2016-09-26 18:22:22 +02:00
|
|
|
PSKCDocument(os.path.join(basename, "pskc-figure8.xml"))
|
2014-05-08 11:06:16 -04:00
|
|
|
except NotImplementedError: # X.509 is not supported.
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
def test_invalid(self):
|
|
|
|
|
try:
|
2016-09-26 18:22:22 +02:00
|
|
|
PSKCDocument(os.path.join(basename, "pskc-invalid.xml"))
|
2014-05-08 11:06:16 -04:00
|
|
|
except ValueError: # File is invalid.
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
def test_mini(self):
|
|
|
|
|
try:
|
|
|
|
|
doc = PSKCDocument(os.path.join(basename, "pskc-mini.xml"))
|
Enable pylint expression-not-assigned check
Enables check and fixes:
************* Module ipa-replica-conncheck
install/tools/ipa-replica-conncheck:150:
[W0106(expression-not-assigned), parse_options] Expression
"(replica_group.add_option('-w', '--password', dest='password',
sensitive=True, help='Password for the principal'), )" is assigned to
nothing)
************* Module ipatests.test_xmlrpc.test_automount_plugin
ipatests/test_xmlrpc/test_automount_plugin.py:437:
[W0106(expression-not-assigned),
test_automount_indirect.test_1a_automountmap_add_indirect] Expression
"api.Command['automountmap_add_indirect'](self.locname, self.mapname,
**self.map_kw)['result']" is assigned to nothing)
************* Module ipatests.test_ipaserver.test_otptoken_import
ipatests/test_ipaserver/test_otptoken_import.py:128:
[W0106(expression-not-assigned), test_otptoken_import.test_mini]
Expression "[(t.id, t.options) for t in doc.getKeyPackages()]" is
assigned to nothing)
************* Module ipatests.test_ipaserver.test_ldap
ipatests/test_ipaserver/test_ldap.py:221:
[W0106(expression-not-assigned), test_LDAPEntry.test_popitem] Expression
"list(e) == []" is assigned to nothing)
************* Module ipa-client-install
ipa-client/ipa-install/ipa-client-install:114:
[W0106(expression-not-assigned), parse_options] Expression
"(basic_group.add_option('-p', '--principal', dest='principal',
help='principal to use to join the IPA realm'), )" is assigned to
nothing)
ipa-client/ipa-install/ipa-client-install:116:
[W0106(expression-not-assigned), parse_options] Expression
"(basic_group.add_option('-w', '--password', dest='password',
sensitive=True, help='password to join the IPA realm (assumes bulk
password unless principal is also set)'), )" is assigned to nothing)
ipa-client/ipa-install/ipa-client-install:118:
[W0106(expression-not-assigned), parse_options] Expression
"(basic_group.add_option('-k', '--keytab', dest='keytab', help='path to
backed up keytab from previous enrollment'), )" is assigned to nothing)
ipa-client/ipa-install/ipa-client-install:120:
[W0106(expression-not-assigned), parse_options] Expression
"(basic_group.add_option('-W', dest='prompt_password',
action='store_true', default=False, help='Prompt for a password to join
the IPA realm'), )" is assigned to nothing)
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
2015-12-17 00:33:57 +01:00
|
|
|
for t in doc.getKeyPackages():
|
|
|
|
|
t._PSKCKeyPackage__process()
|
2014-05-08 11:06:16 -04:00
|
|
|
except ValidationError: # Unsupported token type.
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
assert False
|
|
|
|
|
|
|
|
|
|
def test_full(self):
|
2015-08-31 10:46:19 -04:00
|
|
|
doc = PSKCDocument(os.path.join(basename, "full.xml"))
|
|
|
|
|
assert [(t.id, t.options) for t in doc.getKeyPackages()] == \
|
|
|
|
|
[(u'KID1', {
|
|
|
|
|
'ipatokenotpkey': u'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ',
|
|
|
|
|
'ipatokennotafter': u'20060531000000Z',
|
|
|
|
|
'ipatokennotbefore': u'20060501000000Z',
|
|
|
|
|
'ipatokenserial': u'SerialNo-IssueNo',
|
|
|
|
|
'ipatokentotpclockoffset': 60000,
|
|
|
|
|
'ipatokenotpalgorithm': u'sha1',
|
|
|
|
|
'ipatokenvendor': u'iana.dummy',
|
|
|
|
|
'description': u'FriendlyName',
|
|
|
|
|
'ipatokentotptimestep': 200,
|
|
|
|
|
'ipatokenhotpcounter': 0,
|
|
|
|
|
'ipatokenmodel': u'Model',
|
|
|
|
|
'ipatokenotpdigits': 8,
|
|
|
|
|
'type': u'hotp',
|
|
|
|
|
})]
|
2017-09-14 17:31:57 +03:00
|
|
|
|
|
|
|
|
def test_valid_tokens(self):
|
|
|
|
|
assert convertHashName('sha1') == u'sha1'
|
|
|
|
|
assert convertHashName('hmac-sha1') == u'sha1'
|
|
|
|
|
assert convertHashName('sha224') == u'sha224'
|
|
|
|
|
assert convertHashName('hmac-sha224') == u'sha224'
|
|
|
|
|
assert convertHashName('sha256') == u'sha256'
|
|
|
|
|
assert convertHashName('hmac-sha256') == u'sha256'
|
|
|
|
|
assert convertHashName('sha384') == u'sha384'
|
|
|
|
|
assert convertHashName('hmac-sha384') == u'sha384'
|
|
|
|
|
assert convertHashName('sha512') == u'sha512'
|
|
|
|
|
assert convertHashName('hmac-sha512') == u'sha512'
|
|
|
|
|
|
|
|
|
|
def test_invalid_tokens(self):
|
|
|
|
|
"""The conversion defaults to sha1 on unknown hashing"""
|
|
|
|
|
assert convertHashName('something-sha256') == u'sha1'
|
|
|
|
|
assert convertHashName('') == u'sha1'
|
|
|
|
|
assert convertHashName(None) == u'sha1'
|