29 |
29 |
"""
|
30 |
30 |
|
31 |
31 |
try:
|
|
32 |
if certificate.revocation_date != "" and certificate.revocation_reason == "":
|
|
33 |
certificate.revocation_reason = REV_REASON_UNSPECIFIED
|
|
34 |
elif certificate.revocation_date == "":
|
|
35 |
certificate.revocation_reason = ""
|
|
36 |
|
32 |
37 |
sql = (f"INSERT INTO {TAB_CERTIFICATES} "
|
33 |
38 |
f"({COL_COMMON_NAME},"
|
34 |
39 |
f"{COL_VALID_FROM},"
|
35 |
40 |
f"{COL_VALID_TO},"
|
36 |
41 |
f"{COL_PEM_DATA},"
|
37 |
|
f"{COL_REVOCATION_DATE},"
|
38 |
|
f"{COL_REVOCATION_REASON}"
|
39 |
42 |
f"{COL_PRIVATE_KEY_ID},"
|
40 |
43 |
f"{COL_TYPE_ID},"
|
41 |
44 |
f"{COL_PARENT_ID})"
|
... | ... | |
44 |
47 |
certificate.valid_from,
|
45 |
48 |
certificate.valid_to,
|
46 |
49 |
certificate.pem_data,
|
47 |
|
certificate.revocation_date,
|
48 |
|
certificate.revocation_reason,
|
49 |
50 |
certificate.private_key_id,
|
50 |
51 |
certificate.type_id,
|
51 |
52 |
certificate.parent_id]
|
... | ... | |
137 |
138 |
f"SELECT {COL_ID} FROM {TAB_CERTIFICATE_TYPES} WHERE {COL_ID} = ?)")
|
138 |
139 |
values = [filter_type]
|
139 |
140 |
|
140 |
|
sql = (f"SELECT * FROM {TAB_CERTIFICATES}{sql_extension}")
|
|
141 |
sql = f"SELECT * FROM {TAB_CERTIFICATES}{sql_extension}"
|
141 |
142 |
self.cursor.execute(sql, values)
|
142 |
143 |
certificate_rows = self.cursor.fetchall()
|
143 |
144 |
|
... | ... | |
185 |
186 |
"""
|
186 |
187 |
|
187 |
188 |
try:
|
|
189 |
if certificate.revocation_date != "" and certificate.revocation_reason == "":
|
|
190 |
certificate.revocation_reason = REV_REASON_UNSPECIFIED
|
|
191 |
elif certificate.revocation_date == "":
|
|
192 |
certificate.revocation_reason = ""
|
|
193 |
|
188 |
194 |
sql = (f"UPDATE {TAB_CERTIFICATES} "
|
189 |
195 |
f"SET {COL_COMMON_NAME} = ?, "
|
190 |
196 |
f"{COL_VALID_FROM} = ?, "
|
191 |
197 |
f"{COL_VALID_TO} = ?, "
|
192 |
198 |
f"{COL_PEM_DATA} = ?, "
|
193 |
|
f"{COL_REVOCATION_DATE} = ?, "
|
194 |
|
f"{COL_REVOCATION_REASON} = ?, "
|
195 |
199 |
f"{COL_PRIVATE_KEY_ID} = ?, "
|
196 |
200 |
f"{COL_TYPE_ID} = ?, "
|
197 |
201 |
f"{COL_PARENT_ID} = ? "
|
... | ... | |
200 |
204 |
certificate.valid_from,
|
201 |
205 |
certificate.valid_to,
|
202 |
206 |
certificate.pem_data,
|
203 |
|
certificate.revocation_date,
|
204 |
|
certificate.revocation_reason,
|
205 |
207 |
certificate.private_key_id,
|
206 |
208 |
certificate.type_id,
|
207 |
209 |
certificate.parent_id,
|
... | ... | |
228 |
230 |
except Error as e:
|
229 |
231 |
return e
|
230 |
232 |
|
231 |
|
return True
|
|
233 |
if self.cursor.rowcount > 0:
|
|
234 |
return True
|
|
235 |
|
|
236 |
return False
|
232 |
237 |
|
233 |
238 |
def delete(self, certificate_id: int):
|
234 |
239 |
"""
|
... | ... | |
251 |
256 |
return self.cursor.rowcount > 0
|
252 |
257 |
|
253 |
258 |
def set_certificate_revoked(
|
254 |
|
self, certificate_id: int, revocation_date: str, revocation_reason: str = "unspecified"):
|
|
259 |
self, certificate_id: int, revocation_date: str, revocation_reason: str = REV_REASON_UNSPECIFIED):
|
255 |
260 |
"""
|
256 |
261 |
Revoke a certificate
|
257 |
262 |
|
... | ... | |
259 |
264 |
:param revocation_date: Date, when the certificate is revoked
|
260 |
265 |
:param revocation_reason: Reason of the revocation
|
261 |
266 |
|
262 |
|
:return: the result of whether the revocation was successful
|
|
267 |
:return:
|
|
268 |
the result of whether the revocation was successful OR
|
|
269 |
sqlite3.Error if an exception is thrown
|
263 |
270 |
"""
|
264 |
271 |
|
265 |
272 |
try:
|
|
273 |
if revocation_date != "" and revocation_reason == "":
|
|
274 |
revocation_reason = REV_REASON_UNSPECIFIED
|
|
275 |
elif revocation_date == "":
|
|
276 |
return False
|
|
277 |
|
266 |
278 |
sql = (f"UPDATE {TAB_CERTIFICATES} "
|
267 |
279 |
f"SET {COL_REVOCATION_DATE} = ?, "
|
268 |
|
f"{COL_REVOCATION_REASON} = ?, "
|
|
280 |
f"{COL_REVOCATION_REASON} = ? "
|
269 |
281 |
f"WHERE {COL_ID} = ? AND ({COL_REVOCATION_DATE} IS NULL OR {COL_REVOCATION_DATE} = '')")
|
270 |
282 |
values = [revocation_date,
|
271 |
283 |
revocation_reason,
|
... | ... | |
275 |
287 |
except Error as e:
|
276 |
288 |
return e
|
277 |
289 |
|
278 |
|
return True
|
|
290 |
if self.cursor.rowcount > 0:
|
|
291 |
return True
|
|
292 |
|
|
293 |
return False
|
279 |
294 |
|
280 |
295 |
def clear_certificate_revocation(self, certificate_id: int):
|
281 |
296 |
"""
|
... | ... | |
283 |
298 |
|
284 |
299 |
:param certificate_id: ID of specific certificate
|
285 |
300 |
|
286 |
|
:return: the result of whether the clear revocation was successful
|
|
301 |
:return:
|
|
302 |
the result of whether the clear revocation was successful OR
|
|
303 |
sqlite3.Error if an exception is thrown
|
287 |
304 |
"""
|
288 |
305 |
|
289 |
306 |
try:
|
290 |
307 |
sql = (f"UPDATE {TAB_CERTIFICATES} "
|
291 |
308 |
f"SET {COL_REVOCATION_DATE} = '', "
|
292 |
|
f"{COL_REVOCATION_REASON} = '', "
|
|
309 |
f"{COL_REVOCATION_REASON} = '' "
|
293 |
310 |
f"WHERE {COL_ID} = ?")
|
294 |
311 |
values = [certificate_id]
|
295 |
312 |
self.cursor.execute(sql, values)
|
... | ... | |
306 |
323 |
:param certificate_id: ID of specific certificate
|
307 |
324 |
|
308 |
325 |
:return:
|
309 |
|
# list of the certificates
|
310 |
|
# None if the list is empty
|
311 |
|
# sqlite3.Error if an exception is thrown
|
|
326 |
list of the certificates OR
|
|
327 |
None if the list is empty OR
|
|
328 |
sqlite3.Error if an exception is thrown
|
312 |
329 |
"""
|
313 |
330 |
|
314 |
331 |
try:
|
... | ... | |
356 |
373 |
:param certificate_id: ID of specific certificate
|
357 |
374 |
|
358 |
375 |
:return:
|
359 |
|
# list of the certificates
|
360 |
|
# None if the list is empty
|
361 |
|
# sqlite3.Error if an exception is thrown
|
|
376 |
list of the certificates OR
|
|
377 |
None if the list is empty OR
|
|
378 |
sqlite3.Error if an exception is thrown
|
362 |
379 |
"""
|
363 |
380 |
|
364 |
381 |
try:
|
365 |
382 |
sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
|
366 |
|
f"WHERE {COL_PARENT_ID} = ?")
|
367 |
|
values = [certificate_id]
|
|
383 |
f"WHERE {COL_PARENT_ID} = ? AND {COL_ID} != ?")
|
|
384 |
values = [certificate_id, certificate_id]
|
368 |
385 |
self.cursor.execute(sql, values)
|
369 |
386 |
certificate_rows = self.cursor.fetchall()
|
370 |
387 |
|
Re #8578 - Updated certificate and certificate_repository
- certificate initialize revocation_date and revocation_reason on "" if input is None
- certificate_repository
- repaired error after tests
- edited comments (return)
- stylistics