SCAutolib 1.1.0__py3-none-any.whl → 3.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of SCAutolib might be problematic. Click here for more details.
- SCAutolib/__init__.py +20 -21
- SCAutolib/cli_commands.py +2 -1
- SCAutolib/controller.py +168 -106
- SCAutolib/enums.py +40 -0
- SCAutolib/models/CA.py +111 -39
- SCAutolib/models/card.py +222 -62
- SCAutolib/models/file.py +15 -12
- SCAutolib/models/gui.py +2 -1
- SCAutolib/models/user.py +27 -194
- SCAutolib/templates/user.cnf +1 -1
- SCAutolib/utils.py +73 -50
- {SCAutolib-1.1.0.dist-info → SCAutolib-3.0.0.dist-info}/METADATA +10 -10
- SCAutolib-3.0.0.dist-info/RECORD +27 -0
- {SCAutolib-1.1.0.dist-info → SCAutolib-3.0.0.dist-info}/WHEEL +1 -1
- SCAutolib-1.1.0.dist-info/RECORD +0 -26
- {SCAutolib-1.1.0.dist-info → SCAutolib-3.0.0.dist-info}/LICENSE +0 -0
- {SCAutolib-1.1.0.dist-info → SCAutolib-3.0.0.dist-info}/entry_points.txt +0 -0
- {SCAutolib-1.1.0.dist-info → SCAutolib-3.0.0.dist-info}/top_level.txt +0 -0
SCAutolib/models/file.py
CHANGED
|
@@ -49,7 +49,7 @@ class File:
|
|
|
49
49
|
_simple_content = None
|
|
50
50
|
_backup: dict = dict()
|
|
51
51
|
|
|
52
|
-
def __init__(self, filepath: Union[str, Path], template:
|
|
52
|
+
def __init__(self, filepath: Union[str, Path], template: Path = None):
|
|
53
53
|
"""
|
|
54
54
|
Init of File
|
|
55
55
|
|
|
@@ -60,7 +60,7 @@ class File:
|
|
|
60
60
|
"""
|
|
61
61
|
self._conf_file = Path(filepath)
|
|
62
62
|
if template is not None:
|
|
63
|
-
self._template =
|
|
63
|
+
self._template = template
|
|
64
64
|
|
|
65
65
|
@property
|
|
66
66
|
def path(self):
|
|
@@ -492,13 +492,13 @@ class OpensslCnf(File):
|
|
|
492
492
|
# templates are needed for specific config files types. mapping:
|
|
493
493
|
types = {
|
|
494
494
|
"CA": {"template": Path(TEMPLATES_DIR, 'ca.cnf'),
|
|
495
|
-
"replace": "{ROOT_DIR}"},
|
|
495
|
+
"replace": ["{ROOT_DIR}"]},
|
|
496
496
|
"user": {"template": Path(TEMPLATES_DIR, 'user.cnf'),
|
|
497
|
-
"replace": "{user}"}
|
|
497
|
+
"replace": ["{user}", "{cn}"]}
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
def __init__(self, filepath: Union[str, Path], conf_type: str,
|
|
501
|
-
replace: str):
|
|
501
|
+
replace: Union[str, list]):
|
|
502
502
|
"""
|
|
503
503
|
Init of opensslCNF
|
|
504
504
|
|
|
@@ -506,13 +506,16 @@ class OpensslCnf(File):
|
|
|
506
506
|
:type filepath: str or pathlib.Path
|
|
507
507
|
:param conf_type: Identifier of cnf file
|
|
508
508
|
:type conf_type: basestring
|
|
509
|
-
:param replace:
|
|
510
|
-
|
|
509
|
+
:param replace: list of strings that will replace specific strings from
|
|
510
|
+
template
|
|
511
|
+
:type replace: list
|
|
511
512
|
"""
|
|
512
513
|
self._conf_file = Path(filepath)
|
|
513
514
|
self._template = Path(self.types[conf_type]["template"])
|
|
514
|
-
self.
|
|
515
|
-
|
|
515
|
+
self._old_strings = self.types[conf_type]["replace"]
|
|
516
|
+
if isinstance(replace, str):
|
|
517
|
+
replace = [replace]
|
|
518
|
+
self._new_strings = replace
|
|
516
519
|
|
|
517
520
|
def create(self):
|
|
518
521
|
"""
|
|
@@ -520,9 +523,9 @@ class OpensslCnf(File):
|
|
|
520
523
|
and update specific strings
|
|
521
524
|
"""
|
|
522
525
|
with self._template.open('r') as template:
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
+
self._content = template.read()
|
|
527
|
+
for old, new in zip(self._old_strings, self._new_strings):
|
|
528
|
+
self._content = self._content.replace(old, new)
|
|
526
529
|
|
|
527
530
|
def save(self):
|
|
528
531
|
"""
|
SCAutolib/models/gui.py
CHANGED
|
@@ -89,7 +89,8 @@ class Mouse:
|
|
|
89
89
|
|
|
90
90
|
for uinput_axis, value in [(uinput.ABS_X, x), (uinput.ABS_Y, y)]:
|
|
91
91
|
# Check if value between 0 and 1
|
|
92
|
-
|
|
92
|
+
if not (0 <= value <= 1):
|
|
93
|
+
raise ValueError("Values must be floats between 0 and 1")
|
|
93
94
|
converted = int(value * self.ABS_MAX)
|
|
94
95
|
self.device.emit(uinput_axis, converted, syn=False)
|
|
95
96
|
|
SCAutolib/models/user.py
CHANGED
|
@@ -3,13 +3,11 @@ This module defines the User and IPAUser classes which can be used
|
|
|
3
3
|
to represent system and IPA users.
|
|
4
4
|
|
|
5
5
|
The classes contain the usual properties that defines a user, like username,
|
|
6
|
-
password,
|
|
6
|
+
password, etc.
|
|
7
7
|
|
|
8
8
|
The classes implement add_user and delete_user methods which can be used to
|
|
9
9
|
create or remove a specified user in the system or in the specified IPA server.
|
|
10
10
|
"""
|
|
11
|
-
from shutil import rmtree
|
|
12
|
-
|
|
13
11
|
import json
|
|
14
12
|
import pwd
|
|
15
13
|
import python_freeipa
|
|
@@ -17,37 +15,29 @@ from pathlib import Path, PosixPath
|
|
|
17
15
|
|
|
18
16
|
from SCAutolib import run, logger, LIB_DUMP_USERS
|
|
19
17
|
from SCAutolib.exceptions import SCAutolibException
|
|
20
|
-
from SCAutolib.models import card as card_model
|
|
21
18
|
from SCAutolib.models.CA import IPAServerCA
|
|
22
|
-
from SCAutolib.
|
|
19
|
+
from SCAutolib.enums import UserType
|
|
23
20
|
|
|
24
21
|
|
|
25
|
-
class
|
|
22
|
+
class User:
|
|
23
|
+
"""
|
|
24
|
+
User represents general system user.
|
|
25
|
+
"""
|
|
26
26
|
username: str = None
|
|
27
27
|
password: str = None
|
|
28
|
-
pin: str = None
|
|
29
28
|
dump_file: Path = None
|
|
30
|
-
|
|
31
|
-
_key: Path = None
|
|
32
|
-
_cert: Path = None
|
|
33
|
-
card_dir: Path = None
|
|
34
|
-
_card: card_model.Card = None
|
|
35
|
-
local: bool = None
|
|
29
|
+
user_type: str = None
|
|
36
30
|
|
|
37
31
|
def __init__(self, username, password):
|
|
38
32
|
self.username = username
|
|
39
33
|
self.password = password
|
|
34
|
+
self.user_type = UserType.local
|
|
40
35
|
self.dump_file = LIB_DUMP_USERS.joinpath(f"{self.username}.json")
|
|
41
36
|
|
|
42
37
|
def to_dict(self):
|
|
43
38
|
# Retype patlib.Path object to str
|
|
44
39
|
d = {k: str(v) if type(v) in (PosixPath, Path) else v
|
|
45
40
|
for k, v in self.__dict__.items()}
|
|
46
|
-
|
|
47
|
-
if self._card and isinstance(self._card, card_model.VirtualCard):
|
|
48
|
-
d.pop("_card")
|
|
49
|
-
d["card"] = str(self._card.dump_file)
|
|
50
|
-
|
|
51
41
|
return d
|
|
52
42
|
|
|
53
43
|
@staticmethod
|
|
@@ -59,45 +49,37 @@ class BaseUser:
|
|
|
59
49
|
:type json_file: pathlib.Path
|
|
60
50
|
:param kwargs: dictionary of additional values needed to initialise the
|
|
61
51
|
object
|
|
62
|
-
:
|
|
52
|
+
:type kwargs: dict
|
|
53
|
+
:return: user object
|
|
63
54
|
:rtype: SCAutolib.models.user.User or SCAutolib.models.user.IPAUser
|
|
64
55
|
"""
|
|
65
56
|
with json_file.open("r") as f:
|
|
66
57
|
cnt = json.load(f)
|
|
67
58
|
|
|
68
|
-
if "
|
|
69
|
-
user =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
card_dir=Path(cnt["card_dir"]),
|
|
74
|
-
password=cnt["password"],
|
|
75
|
-
pin=cnt["pin"],
|
|
76
|
-
key=cnt["_key"],
|
|
77
|
-
cert=cnt["_cert"])
|
|
78
|
-
else:
|
|
59
|
+
if cnt["user_type"] == UserType.local:
|
|
60
|
+
user = User(username=cnt["username"],
|
|
61
|
+
password=cnt["password"])
|
|
62
|
+
|
|
63
|
+
elif cnt["user_type"] == UserType.ipa:
|
|
79
64
|
if "ipa_server" not in kwargs:
|
|
80
|
-
raise SCAutolibException("IPA Server object
|
|
65
|
+
raise SCAutolibException("IPA Server object was not provided. "
|
|
81
66
|
"Can't load IPA user.")
|
|
82
67
|
|
|
83
68
|
user = IPAUser(ipa_server=kwargs["ipa_server"],
|
|
84
|
-
local=cnt["local"],
|
|
85
69
|
username=cnt["username"],
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
password=cnt["password"])
|
|
71
|
+
|
|
72
|
+
else:
|
|
73
|
+
raise SCAutolibException(f"Unknown user type: {cnt['user_type']}")
|
|
74
|
+
|
|
91
75
|
logger.debug(f"User {user.__class__} is loaded: {user.__dict__}")
|
|
92
|
-
|
|
93
|
-
return user, Path(cnt["card"])
|
|
76
|
+
|
|
94
77
|
return user
|
|
95
78
|
|
|
96
79
|
def add_user(self):
|
|
97
80
|
"""
|
|
98
81
|
Add user to the local system with `useradd` bash command and set
|
|
99
82
|
password for created user.
|
|
100
|
-
:return:
|
|
101
83
|
"""
|
|
102
84
|
try:
|
|
103
85
|
pwd.getpwnam(self.username)
|
|
@@ -112,148 +94,24 @@ class BaseUser:
|
|
|
112
94
|
run(cmd, check=True)
|
|
113
95
|
cmd = ["passwd", self.username, "--stdin"]
|
|
114
96
|
run(cmd, input=self.password)
|
|
115
|
-
logger.info(f"User {self.username}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
class User(BaseUser):
|
|
119
|
-
"""
|
|
120
|
-
Generic class to represent system users.
|
|
121
|
-
"""
|
|
122
|
-
|
|
123
|
-
def __init__(self, username: str, password: str, pin: str,
|
|
124
|
-
cnf: Path = None, key: Path = None, cert: Path = None,
|
|
125
|
-
card_dir: Path = None, local: bool = True):
|
|
126
|
-
|
|
127
|
-
"""
|
|
128
|
-
:param username: Username for the system user
|
|
129
|
-
:type username: str
|
|
130
|
-
:param password: Password for the system user
|
|
131
|
-
:type password: str
|
|
132
|
-
:param pin: Smart card pin for the system user
|
|
133
|
-
:type pin: str
|
|
134
|
-
:param cnf: CNF file to be associated with the user
|
|
135
|
-
:type cnf: Path
|
|
136
|
-
:param key: Key to be associated with the user
|
|
137
|
-
:type key: Path
|
|
138
|
-
:param cert: Certificate to be associated with the user.
|
|
139
|
-
:type cert: Path
|
|
140
|
-
:param card_dir: Directory for the card. If None, standard
|
|
141
|
-
home directory would be used (/home/<username>)
|
|
142
|
-
:type card_dir: Path
|
|
143
|
-
"""
|
|
144
|
-
|
|
145
|
-
self.username = username
|
|
146
|
-
self.password = password
|
|
147
|
-
self.pin = pin
|
|
148
|
-
self.dump_file = LIB_DUMP_USERS.joinpath(f"{self.username}.json")
|
|
149
|
-
self._cnf = cnf
|
|
150
|
-
self.card_dir = card_dir if card_dir is not None \
|
|
151
|
-
else Path("/home", self.username)
|
|
152
|
-
self._key = key if key else self.card_dir.joinpath(f"key-{username}.pem")
|
|
153
|
-
self._cert = cert \
|
|
154
|
-
if cert else self.card_dir.joinpath(f"cert-{username}.pem")
|
|
155
|
-
self.local = local
|
|
156
|
-
|
|
157
|
-
@property
|
|
158
|
-
def card(self):
|
|
159
|
-
return self._card
|
|
160
|
-
|
|
161
|
-
@card.setter
|
|
162
|
-
def card(self, card: card_model.Card):
|
|
163
|
-
if self._card:
|
|
164
|
-
logger.error("Delete the existing card before adding a new one.")
|
|
165
|
-
raise ValueError("A card is already assigned to this user")
|
|
166
|
-
self._card = card
|
|
167
|
-
|
|
168
|
-
@card.deleter
|
|
169
|
-
def card(self):
|
|
170
|
-
logger.info(f"Deleting the existing card from {self.username}")
|
|
171
|
-
self._card = None
|
|
172
|
-
|
|
173
|
-
@property
|
|
174
|
-
def key(self):
|
|
175
|
-
return self._key
|
|
176
|
-
|
|
177
|
-
@key.setter
|
|
178
|
-
def key(self, key: Path):
|
|
179
|
-
logger.warning("Make sure to remove the existing key/cert "
|
|
180
|
-
"pairs before adding a new one.")
|
|
181
|
-
self._key = key
|
|
182
|
-
if self.card:
|
|
183
|
-
self.card._private_key = key
|
|
184
|
-
|
|
185
|
-
@key.deleter
|
|
186
|
-
def key(self):
|
|
187
|
-
logger.info("Deleting the current user key.")
|
|
188
|
-
self._key = None
|
|
189
|
-
|
|
190
|
-
@property
|
|
191
|
-
def cert(self):
|
|
192
|
-
return self._cert
|
|
193
|
-
|
|
194
|
-
@cert.setter
|
|
195
|
-
def cert(self, cert: Path):
|
|
196
|
-
logger.warning("Make sure to remove the existing key/cert "
|
|
197
|
-
"pairs before adding a new one.")
|
|
198
|
-
self._cert = cert
|
|
199
|
-
if self.card:
|
|
200
|
-
self.card._cert = cert
|
|
201
|
-
|
|
202
|
-
@cert.deleter
|
|
203
|
-
def cert(self):
|
|
204
|
-
logger.info("Deleting the current user cert.")
|
|
205
|
-
self._cert = None
|
|
206
|
-
|
|
207
|
-
@property
|
|
208
|
-
def cnf(self):
|
|
209
|
-
return self._cnf
|
|
210
|
-
|
|
211
|
-
@cnf.setter
|
|
212
|
-
def cnf(self, cnf: Path):
|
|
213
|
-
if self._cnf:
|
|
214
|
-
logger.warning("Overriding current CNF file.")
|
|
215
|
-
self._cnf = cnf
|
|
216
|
-
|
|
217
|
-
@cnf.deleter
|
|
218
|
-
def cnf(self):
|
|
219
|
-
logger.info("Removing current CNF file.")
|
|
220
|
-
self._cnf = None
|
|
97
|
+
logger.info(f"User {self.username} was added to the system")
|
|
221
98
|
|
|
222
99
|
def delete_user(self):
|
|
223
100
|
"""
|
|
224
|
-
Deletes the user
|
|
225
|
-
|
|
226
|
-
Note: card directory would be recursively deleted with a directory
|
|
227
|
-
by itself.
|
|
101
|
+
Deletes the user
|
|
228
102
|
"""
|
|
229
103
|
try:
|
|
230
104
|
pwd.getpwnam(self.username)
|
|
231
105
|
logger.info(f"Deleting the user {self.username}")
|
|
232
106
|
run(['userdel', '-f', self.username], check=True)
|
|
233
|
-
if self.card_dir.exists():
|
|
234
|
-
rmtree(self.card_dir)
|
|
235
|
-
logger.debug("User's card directory "
|
|
236
|
-
f"{str(self.card_dir)} is removed")
|
|
237
107
|
except KeyError:
|
|
238
108
|
pass
|
|
239
109
|
logger.info(f"User {self.username} is not present on the system")
|
|
240
110
|
|
|
241
|
-
def gen_csr(self):
|
|
242
|
-
"""
|
|
243
|
-
Method for generating local user specific CSR file that would be sent to
|
|
244
|
-
the local CA for generating the certificate. CSR is generated using
|
|
245
|
-
`openssl` command based on template CNF file.
|
|
246
|
-
"""
|
|
247
|
-
csr_path = self.card_dir.joinpath(f"csr-{self.username}.csr")
|
|
248
|
-
cmd = ["openssl", "req", "-new", "-nodes", "-key", self._key,
|
|
249
|
-
"-reqexts", "req_exts", "-config", self._cnf, "-out", csr_path]
|
|
250
|
-
run(cmd)
|
|
251
|
-
return csr_path
|
|
252
|
-
|
|
253
111
|
|
|
254
112
|
class IPAUser(User):
|
|
255
113
|
"""
|
|
256
|
-
This class
|
|
114
|
+
This class represents an IPA user.
|
|
257
115
|
"""
|
|
258
116
|
default_password = "redhat"
|
|
259
117
|
|
|
@@ -268,10 +126,6 @@ class IPAUser(User):
|
|
|
268
126
|
:type username: str
|
|
269
127
|
:param password: Password for the system user
|
|
270
128
|
:type password: str
|
|
271
|
-
:param pin: Smart card pin for the system user
|
|
272
|
-
:type pin: str
|
|
273
|
-
:param cnf: CNF file to be associated with the user
|
|
274
|
-
:type cnf: Path
|
|
275
129
|
:param key: Key to be associated with the user
|
|
276
130
|
:type key: Path
|
|
277
131
|
:param cert: Certificate to be associated with the user.
|
|
@@ -279,6 +133,7 @@ class IPAUser(User):
|
|
|
279
133
|
"""
|
|
280
134
|
|
|
281
135
|
super().__init__(*args, **kwargs)
|
|
136
|
+
self.user_type = UserType.ipa
|
|
282
137
|
self._meta_client = ipa_server.meta_client
|
|
283
138
|
self._ipa_hostname = ipa_server.ipa_server_hostname
|
|
284
139
|
|
|
@@ -314,10 +169,7 @@ class IPAUser(User):
|
|
|
314
169
|
|
|
315
170
|
def delete_user(self):
|
|
316
171
|
"""
|
|
317
|
-
Deletes the user
|
|
318
|
-
|
|
319
|
-
Note: card directory would be recursively deleted with a directory
|
|
320
|
-
by itself.
|
|
172
|
+
Deletes the user
|
|
321
173
|
"""
|
|
322
174
|
try:
|
|
323
175
|
r = self._meta_client.user_del(self.username)["result"]
|
|
@@ -325,22 +177,3 @@ class IPAUser(User):
|
|
|
325
177
|
logger.debug(r)
|
|
326
178
|
except python_freeipa.exceptions.NotFound:
|
|
327
179
|
pass
|
|
328
|
-
if self.card_dir.exists():
|
|
329
|
-
rmtree(self.card_dir)
|
|
330
|
-
logger.info(f"User {self.username} directory is removed.")
|
|
331
|
-
|
|
332
|
-
def gen_csr(self):
|
|
333
|
-
"""
|
|
334
|
-
Method for generating IPA user specific CSR file that would be sent to
|
|
335
|
-
the IPA server for generating the certificate. CSR is generated using
|
|
336
|
-
`openssl` command.
|
|
337
|
-
"""
|
|
338
|
-
if not self._key:
|
|
339
|
-
raise SCAutolibException("Can't generate CSR because private key "
|
|
340
|
-
"is not set")
|
|
341
|
-
csr_path = self.card_dir.joinpath(f"csr-{self.username}.csr")
|
|
342
|
-
cmd = ["openssl", "req", "-new", "-days", "365",
|
|
343
|
-
"-nodes", "-key", self._key, "-out",
|
|
344
|
-
str(csr_path), "-subj", f"/CN={self.username}"]
|
|
345
|
-
run(cmd)
|
|
346
|
-
return csr_path
|
SCAutolib/templates/user.cnf
CHANGED
SCAutolib/utils.py
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
"""
|
|
2
2
|
This module provides a set of additional helping functions that are used
|
|
3
|
-
across the library. These functions are
|
|
4
|
-
not
|
|
3
|
+
across the library. These functions are based on library demands and are
|
|
4
|
+
not aimed to cover some general use-cases or specific corner cases.
|
|
5
5
|
"""
|
|
6
6
|
import json
|
|
7
7
|
from cryptography.hazmat.primitives import serialization
|
|
8
8
|
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
9
|
-
from enum import Enum
|
|
10
9
|
from pathlib import Path
|
|
11
10
|
|
|
12
|
-
from SCAutolib import run, logger, TEMPLATES_DIR, LIB_DUMP_USERS, LIB_DUMP_CAS
|
|
11
|
+
from SCAutolib import (run, logger, TEMPLATES_DIR, LIB_DUMP_USERS, LIB_DUMP_CAS,
|
|
12
|
+
LIB_DUMP_CARDS)
|
|
13
|
+
from SCAutolib.enums import OSVersion
|
|
13
14
|
from SCAutolib.exceptions import SCAutolibException
|
|
14
|
-
from SCAutolib.models.CA import LocalCA, BaseCA, IPAServerCA
|
|
15
|
+
from SCAutolib.models.CA import LocalCA, BaseCA, CustomCA, IPAServerCA
|
|
15
16
|
from SCAutolib.models.card import Card
|
|
16
|
-
from SCAutolib.models.file import OpensslCnf
|
|
17
|
-
from SCAutolib.models.user import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class OSVersion(Enum):
|
|
21
|
-
"""
|
|
22
|
-
Enumeration for Linux versions. Used for more convenient checks.
|
|
23
|
-
"""
|
|
24
|
-
Fedora = 1
|
|
25
|
-
RHEL_9 = 2
|
|
26
|
-
RHEL_8 = 3
|
|
27
|
-
CentOS_8 = 4
|
|
28
|
-
CentOS_9 = 5
|
|
17
|
+
from SCAutolib.models.file import OpensslCnf, SSSDConf
|
|
18
|
+
from SCAutolib.models.user import User
|
|
29
19
|
|
|
30
20
|
|
|
31
21
|
def _check_selinux():
|
|
@@ -132,10 +122,9 @@ def dump_to_json(obj):
|
|
|
132
122
|
logger.debug(f"Object {type(obj)} is stored to the {obj.dump_file} file")
|
|
133
123
|
|
|
134
124
|
|
|
135
|
-
def
|
|
125
|
+
def load_user(username, **kwargs):
|
|
136
126
|
"""
|
|
137
|
-
Load user with given username from JSON file.
|
|
138
|
-
linked, then load it as well.
|
|
127
|
+
Load user with given username from JSON file.
|
|
139
128
|
|
|
140
129
|
:param username: username of the user
|
|
141
130
|
:type username: str
|
|
@@ -145,19 +134,44 @@ def user_factory(username, **kwargs):
|
|
|
145
134
|
"""
|
|
146
135
|
user_file = LIB_DUMP_USERS.joinpath(f"{username}.json")
|
|
147
136
|
logger.debug(f"Loading user {username} from {user_file}")
|
|
148
|
-
result = None
|
|
149
137
|
user = None
|
|
150
138
|
if user_file.exists():
|
|
151
|
-
|
|
152
|
-
if type(result) == tuple:
|
|
153
|
-
user, card_file = result
|
|
154
|
-
logger.debug(f"Loading card from {card_file}")
|
|
155
|
-
user.card = Card.load(card_file, user=user)
|
|
139
|
+
user = User.load(user_file, **kwargs)
|
|
156
140
|
else:
|
|
157
|
-
|
|
141
|
+
raise SCAutolibException(f"{user_file} does not exist")
|
|
158
142
|
return user
|
|
159
143
|
|
|
160
144
|
|
|
145
|
+
def load_token(card_name: str = None, update_sssd: bool = False):
|
|
146
|
+
"""
|
|
147
|
+
Load card with given name from JSON file. This function is intended to load
|
|
148
|
+
card objects to tests during pytest configuration. If update_sssd param is
|
|
149
|
+
True sssd.conf file will be updated based on card data
|
|
150
|
+
|
|
151
|
+
:param card_name: name of the card to be loaded
|
|
152
|
+
:type card_name: str
|
|
153
|
+
:param update_sssd: indicates if sssd.conf matchrule should be updated based
|
|
154
|
+
on card data
|
|
155
|
+
:type update_sssd bool
|
|
156
|
+
|
|
157
|
+
:return: card object
|
|
158
|
+
:rtype: Card
|
|
159
|
+
"""
|
|
160
|
+
card_file = LIB_DUMP_CARDS.joinpath(f"{card_name}.json")
|
|
161
|
+
logger.debug(f"Loading card {card_name} from {card_file}")
|
|
162
|
+
card = None
|
|
163
|
+
if card_file.exists():
|
|
164
|
+
card = Card.load(card_file)
|
|
165
|
+
if update_sssd:
|
|
166
|
+
sssd_conf = SSSDConf()
|
|
167
|
+
sssd_conf.set(section=f"certmap/shadowutils/{card.cardholder}",
|
|
168
|
+
key="matchrule",
|
|
169
|
+
value=f"<SUBJECT>.*CN={card.CN}.*")
|
|
170
|
+
sssd_conf.save()
|
|
171
|
+
run(["systemctl", "restart", "sssd"])
|
|
172
|
+
return card
|
|
173
|
+
|
|
174
|
+
|
|
161
175
|
def ipa_factory():
|
|
162
176
|
"""
|
|
163
177
|
Create a new IPAServerCA object.
|
|
@@ -183,29 +197,38 @@ def ipa_factory():
|
|
|
183
197
|
return ca
|
|
184
198
|
|
|
185
199
|
|
|
186
|
-
def
|
|
200
|
+
def ca_factory(path: Path = None, cnf: OpensslCnf = None,
|
|
201
|
+
card_data: dict = None, ca_name: str = None,
|
|
202
|
+
create: bool = False):
|
|
187
203
|
"""
|
|
188
|
-
Create
|
|
204
|
+
Create CA object. If certain CA object was created in previous run of
|
|
205
|
+
SCAutolib and it was serialized and saved in .json file, then such CA object
|
|
206
|
+
would be initialized based on the file. If create param is True new CA
|
|
207
|
+
object will be created regardless the presence of the .json file.
|
|
189
208
|
|
|
190
209
|
:param path: path to the CA directory
|
|
191
210
|
:type path: Path
|
|
192
|
-
:param
|
|
193
|
-
:type
|
|
194
|
-
:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
:param cnf: object representing openssl cnf file
|
|
212
|
+
:type cnf: OpensslCnf object
|
|
213
|
+
:param card_data: dictionary with various attributes of the card as PIN,
|
|
214
|
+
cardholder, slot, etc.
|
|
215
|
+
:type card_data: dict
|
|
216
|
+
:param ca_name: name of CA that identifies CA file to be loaded if create
|
|
217
|
+
parameter is set to False
|
|
218
|
+
:type ca_name: str
|
|
219
|
+
:param create: indicator to create new CA. If it's false existing CA files
|
|
220
|
+
will be loaded
|
|
221
|
+
:type create: bool
|
|
222
|
+
:return: CA object
|
|
223
|
+
:rtype: SCAutolib.models.CA object
|
|
224
|
+
"""
|
|
225
|
+
if not create:
|
|
226
|
+
ca = BaseCA.load(LIB_DUMP_CAS.joinpath(f"{ca_name}.json"))
|
|
227
|
+
return ca
|
|
228
|
+
|
|
229
|
+
if not path: # create CA for physical card
|
|
230
|
+
ca = CustomCA(card_data)
|
|
231
|
+
return ca
|
|
232
|
+
else: # create new CA object for virtual card
|
|
233
|
+
ca = LocalCA(root_dir=path, cnf=cnf)
|
|
234
|
+
return ca
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: SCAutolib
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Python library for automation tests of smart cards using virtualization.
|
|
5
5
|
Home-page: https://github.com/redhat-qe-security/SCAutolib
|
|
6
6
|
Author: Pavel Yadlouski
|
|
@@ -16,15 +16,15 @@ Classifier: Topic :: Software Development :: Testing :: Acceptance
|
|
|
16
16
|
Requires-Python: >=3
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: click
|
|
20
|
-
Requires-Dist: coloredlogs
|
|
21
|
-
Requires-Dist: paramiko
|
|
22
|
-
Requires-Dist: fabric
|
|
23
|
-
Requires-Dist: invoke
|
|
24
|
-
Requires-Dist: pytest
|
|
25
|
-
Requires-Dist: schema
|
|
26
|
-
Requires-Dist: python-freeipa
|
|
27
|
-
Requires-Dist: pexpect
|
|
19
|
+
Requires-Dist: click >=8
|
|
20
|
+
Requires-Dist: coloredlogs >=15
|
|
21
|
+
Requires-Dist: paramiko >=2.10
|
|
22
|
+
Requires-Dist: fabric >=2.7
|
|
23
|
+
Requires-Dist: invoke >=1.7
|
|
24
|
+
Requires-Dist: pytest >=7
|
|
25
|
+
Requires-Dist: schema >=0.7
|
|
26
|
+
Requires-Dist: python-freeipa >=1.0
|
|
27
|
+
Requires-Dist: pexpect >=4
|
|
28
28
|
Provides-Extra: graphical
|
|
29
29
|
Requires-Dist: python-uinput ; extra == 'graphical'
|
|
30
30
|
Requires-Dist: opencv-python ; extra == 'graphical'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
SCAutolib/__init__.py,sha256=l_TOwM1Zpcve60Q7NIboekI6OzP3HUN0lK0RF43sCxg,5446
|
|
2
|
+
SCAutolib/cli_commands.py,sha256=Po3k5sg-cXCSqKtHIDKwoxBKd4BInWggqODnfncJj8s,5632
|
|
3
|
+
SCAutolib/controller.py,sha256=x5YMOHwIBkFxGdzRIHUg89EkPgnLrYwJdatLQVTx5pE,21350
|
|
4
|
+
SCAutolib/enums.py,sha256=3t3N2RRjZeZW2EMhNf1kk5S-FgarabBEo1qLlf6uIzE,638
|
|
5
|
+
SCAutolib/exceptions.py,sha256=-Jsj80CXOSXQacCI46PYXEIh6-tdHSOw3FE4itE_e5w,857
|
|
6
|
+
SCAutolib/utils.py,sha256=4BdttTsNzZtletfeoIuIERrdd5BNiJGlcHa1mOFIuSY,8026
|
|
7
|
+
SCAutolib/models/CA.py,sha256=wykB5-bCwHdSK5kjrWQ1Qr3kwqG9cOeFoaei9hmU4zU,28557
|
|
8
|
+
SCAutolib/models/__init__.py,sha256=8NZySkDbAn2sktD1L3__Y37kY9kEXM2o4TnN3hiIsfk,48
|
|
9
|
+
SCAutolib/models/authselect.py,sha256=PqRcxB9RSAWmGSF1Z8u1YrE7OLrD9oj-sCzGJEAWHa8,3443
|
|
10
|
+
SCAutolib/models/card.py,sha256=tL3_ITcaGwCxqrbMzYu1vsCM4zJmYqsIO6O4zp7G2b8,15524
|
|
11
|
+
SCAutolib/models/file.py,sha256=VWDxaYf25QV3GCyqhE4DpJGkvPd8I2A5GyNfHuqVepQ,20934
|
|
12
|
+
SCAutolib/models/gui.py,sha256=YLzmIHIreolA0gtIYH96LUHDT-d5outEIjAvU-W4UHQ,12253
|
|
13
|
+
SCAutolib/models/log.py,sha256=6EoiehIIJjCXZqbT_X3eQyKWCS-_yZ5RdJcX5HVTJXI,1499
|
|
14
|
+
SCAutolib/models/user.py,sha256=qbiKn6kO2-nJSvItd2wukpv0rMXHndmlrGh88lzases,6266
|
|
15
|
+
SCAutolib/templates/ca.cnf,sha256=9oqUZUSy_lEtNLDViD8SwgJl1ZKCI1-DMri1feF6vjQ,1047
|
|
16
|
+
SCAutolib/templates/gnome_disable_welcome,sha256=POtfU_SrgKGn4RmgLrFtg0K3MTetSFAmUo9HWidi5W0,60
|
|
17
|
+
SCAutolib/templates/softhsm2.conf,sha256=WAlZpRSLzssZ0-dnUZcz2pig9RGIJD0oQg_t5B1X3Fo,108
|
|
18
|
+
SCAutolib/templates/sssd.conf,sha256=eBQJu9AY7LG4OsHRxinUjUeQOIxSu_MksWPKfqZswYo,236
|
|
19
|
+
SCAutolib/templates/user.cnf,sha256=pyyJhxFdOVlFqoVGVwjomOq-W4wEt3YWfRGZEXprwto,452
|
|
20
|
+
SCAutolib/templates/virt_cacard.service,sha256=31NrSKUspYIKNOVhL4Usc62CImlu3heNZprJ8sdw11Y,299
|
|
21
|
+
SCAutolib/templates/virtcacard.cil,sha256=TwxknjxnTtDK_KR3-MbKcLM0VrB76JVSlY-j84VaNZY,167
|
|
22
|
+
SCAutolib-3.0.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
23
|
+
SCAutolib-3.0.0.dist-info/METADATA,sha256=FziTVWvVhPJe1dCRNXkEPb5LXdaTSW_FIhO336hjOKc,2365
|
|
24
|
+
SCAutolib-3.0.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
25
|
+
SCAutolib-3.0.0.dist-info/entry_points.txt,sha256=SyEBTEHEsfYmYZ4L3mQ_RUkW_PRTEWurYgITxGkFLe4,54
|
|
26
|
+
SCAutolib-3.0.0.dist-info/top_level.txt,sha256=z2XZ0S23vykXV_dZYNlLcgcSERgBDIWxmNsiiQBL-wQ,10
|
|
27
|
+
SCAutolib-3.0.0.dist-info/RECORD,,
|
SCAutolib-1.1.0.dist-info/RECORD
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
SCAutolib/__init__.py,sha256=cg5FH7qE3pmuVDmTujexIxzVPAEMTrlXk8t2zKAMj8A,5050
|
|
2
|
-
SCAutolib/cli_commands.py,sha256=T-Qxf6iRqgvp1UdA5YGRVYa69rq4MNLCPkuejxvwy00,5605
|
|
3
|
-
SCAutolib/controller.py,sha256=c3p_JHORFYoM6D39LTdWKeNoXJzfjnbn0PIEt1x_16I,18554
|
|
4
|
-
SCAutolib/exceptions.py,sha256=-Jsj80CXOSXQacCI46PYXEIh6-tdHSOw3FE4itE_e5w,857
|
|
5
|
-
SCAutolib/utils.py,sha256=Npnr0LkkwNv6-Jwa2H566Phvgtj20wuVbcbY8OBZrNU,6738
|
|
6
|
-
SCAutolib/models/CA.py,sha256=oNOtHEtGCc2hRTYdtfSh0f2QO34B7zemTOB0MEJc2uo,26006
|
|
7
|
-
SCAutolib/models/__init__.py,sha256=8NZySkDbAn2sktD1L3__Y37kY9kEXM2o4TnN3hiIsfk,48
|
|
8
|
-
SCAutolib/models/authselect.py,sha256=PqRcxB9RSAWmGSF1Z8u1YrE7OLrD9oj-sCzGJEAWHa8,3443
|
|
9
|
-
SCAutolib/models/card.py,sha256=Ms7QAkCbcl532-WPJ-5zQtTjSJVBIVmFO7I1eRYY5VA,9885
|
|
10
|
-
SCAutolib/models/file.py,sha256=g52yCJpJEMTN5tSAbv5tC_2-gJx_l4DOfYB4GyVZ6Z4,20818
|
|
11
|
-
SCAutolib/models/gui.py,sha256=3xb-svzUY3r0D00nshNqmW8bfhrqNb-J1unQcgqIzPw,12192
|
|
12
|
-
SCAutolib/models/log.py,sha256=6EoiehIIJjCXZqbT_X3eQyKWCS-_yZ5RdJcX5HVTJXI,1499
|
|
13
|
-
SCAutolib/models/user.py,sha256=9QptJvMXcwOQEj8UHkBmfKJEnl6KkHTpDqs-vB6DZPo,12112
|
|
14
|
-
SCAutolib/templates/ca.cnf,sha256=9oqUZUSy_lEtNLDViD8SwgJl1ZKCI1-DMri1feF6vjQ,1047
|
|
15
|
-
SCAutolib/templates/gnome_disable_welcome,sha256=POtfU_SrgKGn4RmgLrFtg0K3MTetSFAmUo9HWidi5W0,60
|
|
16
|
-
SCAutolib/templates/softhsm2.conf,sha256=WAlZpRSLzssZ0-dnUZcz2pig9RGIJD0oQg_t5B1X3Fo,108
|
|
17
|
-
SCAutolib/templates/sssd.conf,sha256=eBQJu9AY7LG4OsHRxinUjUeQOIxSu_MksWPKfqZswYo,236
|
|
18
|
-
SCAutolib/templates/user.cnf,sha256=PThyHgVYjmZvGFoqgEirpUKhA0PiyRnWNkAVvkuhkUA,454
|
|
19
|
-
SCAutolib/templates/virt_cacard.service,sha256=31NrSKUspYIKNOVhL4Usc62CImlu3heNZprJ8sdw11Y,299
|
|
20
|
-
SCAutolib/templates/virtcacard.cil,sha256=TwxknjxnTtDK_KR3-MbKcLM0VrB76JVSlY-j84VaNZY,167
|
|
21
|
-
SCAutolib-1.1.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
22
|
-
SCAutolib-1.1.0.dist-info/METADATA,sha256=5rF_aXCJyLKau-JmxTWR2mZwC9oO8HqGTGIwzCfPz2Y,2383
|
|
23
|
-
SCAutolib-1.1.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
24
|
-
SCAutolib-1.1.0.dist-info/entry_points.txt,sha256=SyEBTEHEsfYmYZ4L3mQ_RUkW_PRTEWurYgITxGkFLe4,54
|
|
25
|
-
SCAutolib-1.1.0.dist-info/top_level.txt,sha256=z2XZ0S23vykXV_dZYNlLcgcSERgBDIWxmNsiiQBL-wQ,10
|
|
26
|
-
SCAutolib-1.1.0.dist-info/RECORD,,
|