Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0e7c3096

Přidáno uživatelem David Friesecký před téměř 4 roky(ů)

Re #8590 - Implemented all fields of subject into DB

Zobrazit rozdíly:

SQLite_database.sql
1 1
/* ---------------------------------------------------- */
2 2
/*  Generated by Enterprise Architect Version 13.5 		*/
3
/*  Created On : 27-dub-2021 11:31:54 				*/
3
/*  Created On : 29-dub-2021 11:55:46 				*/
4 4
/*  DBMS       : SQLite 								*/
5 5
/* ---------------------------------------------------- */
6 6

  
......
26 26
CREATE TABLE 'Certificates'
27 27
(
28 28
	'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
29
	'common_name' TEXT NOT NULL,
30 29
	'valid_from' TEXT NOT NULL,
31 30
	'valid_to' TEXT NOT NULL,
32 31
	'pem_data' TEXT NOT NULL,
32
	'common_name' TEXT NOT NULL,
33
	'country_code' TEXT NULL,
34
	'locality' TEXT NULL,
35
	'province' TEXT NULL,
36
	'organization' TEXT NULL,
37
	'organizational_unit' TEXT NULL,
38
	'email_address' TEXT NULL,
33 39
	'revocation_date' TEXT NULL,
34 40
	'revocation_reason' TEXT NULL,
35 41
	'deletion_date' TEXT NULL,
36
	'private_key_id' INTEGER NOT NULL,
37 42
	'certificate_type_id' INTEGER NOT NULL,
38 43
	'parent_certificate_id' INTEGER NOT NULL,
44
	'private_key_id' INTEGER NOT NULL,
39 45
	CONSTRAINT 'FK_Certificates' FOREIGN KEY ('parent_certificate_id') REFERENCES 'Certificates' ('id') ON DELETE No Action ON UPDATE No Action,
40 46
	CONSTRAINT 'FK_CertificateTypes' FOREIGN KEY ('certificate_type_id') REFERENCES 'CertificateTypes' ('id') ON DELETE No Action ON UPDATE No Action,
41 47
	CONSTRAINT 'FK_PrivateKeys' FOREIGN KEY ('private_key_id') REFERENCES 'PrivateKeys' ('id') ON DELETE No Action ON UPDATE No Action
src/constants.py
37 37
COL_ID = "id"
38 38

  
39 39
# DB column names of Certificates table
40
COL_COMMON_NAME = "common_name"
41 40
COL_VALID_FROM = "valid_from"
42 41
COL_VALID_TO = "valid_to"
43 42
COL_PEM_DATA = "pem_data"
43
COL_COMMON_NAME = "common_name"
44
COL_COUNTRY_CODE = "country_code"
45
COL_LOCALITY = "locality"
46
COL_PROVINCE = "province"
47
COL_ORGANIZATION = "organization"
48
COL_ORGANIZATIONAL_UNIT = "organizational_unit"
49
COL_EMAIL_ADDRESS = "email_address"
44 50
COL_REVOCATION_DATE = "revocation_date"
45 51
COL_REVOCATION_REASON = "revocation_reason"
46 52
COL_DELETION_DATE = "deletion_date"
47
COL_PRIVATE_KEY_ID = "private_key_id"
48 53
COL_TYPE_ID = "certificate_type_id"
49 54
COL_PARENT_ID = "parent_certificate_id"
55
COL_PRIVATE_KEY_ID = "private_key_id"
50 56

  
51 57
# DB column names of PrivateKeys table
52 58
COL_PRIVATE_KEY = "private_key"
src/dao/certificate_repository.py
42 42

  
43 43
        try:
44 44
            sql = (f"INSERT INTO {TAB_CERTIFICATES} "
45
                   f"({COL_COMMON_NAME},"
46
                   f"{COL_VALID_FROM},"
45
                   f"({COL_VALID_FROM},"
47 46
                   f"{COL_VALID_TO},"
48 47
                   f"{COL_PEM_DATA},"
49
                   f"{COL_PRIVATE_KEY_ID},"
48
                   f"{COL_COMMON_NAME},"
49
                   f"{COL_COUNTRY_CODE},"
50
                   f"{COL_LOCALITY},"
51
                   f"{COL_PROVINCE},"
52
                   f"{COL_ORGANIZATION},"
53
                   f"{COL_ORGANIZATIONAL_UNIT},"
54
                   f"{COL_EMAIL_ADDRESS},"
50 55
                   f"{COL_TYPE_ID},"
51
                   f"{COL_PARENT_ID})"
52
                   f"VALUES(?,?,?,?,?,?,?)")
53
            values = [certificate.common_name,
54
                      certificate.valid_from,
56
                   f"{COL_PARENT_ID},"
57
                   f"{COL_PRIVATE_KEY_ID}) "
58
                   f"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)")
59
            values = [certificate.valid_from,
55 60
                      certificate.valid_to,
56 61
                      certificate.pem_data,
57
                      certificate.private_key_id,
62
                      certificate.common_name,
63
                      certificate.country_code,
64
                      certificate.locality,
65
                      certificate.province,
66
                      certificate.organization,
67
                      certificate.organizational_unit,
68
                      certificate.email_address,
58 69
                      certificate.type_id,
59
                      certificate.parent_id]
70
                      certificate.parent_id,
71
                      certificate.private_key_id]
60 72
            self.cursor.execute(sql, values)
61 73
            self.connection.commit()
62 74

  
63 75
            last_id: int = self.cursor.lastrowid
64 76

  
65
            # TODO assure that this is correct
66 77
            if certificate.type_id == ROOT_CA_ID:
67 78
                certificate.parent_id = last_id
68 79
                self.update(last_id, certificate)
......
127 138
            for usage_row in usage_rows:
128 139
                usage_dict[usage_row[2]] = True
129 140

  
130
            certificate: Certificate = Certificate(certificate_row[0],
131
                                                   certificate_row[1],
132
                                                   certificate_row[2],
133
                                                   certificate_row[3],
134
                                                   certificate_row[4],
135
                                                   certificate_row[8],
136
                                                   certificate_row[9],
137
                                                   certificate_row[10],
141
            certificate: Certificate = Certificate(certificate_row[0],      # ID
142
                                                   certificate_row[1],      # valid from
143
                                                   certificate_row[2],      # valid to
144
                                                   certificate_row[3],      # pem data
145
                                                   certificate_row[14],     # type ID
146
                                                   certificate_row[15],     # parent ID
147
                                                   certificate_row[16],     # private key ID
138 148
                                                   usage_dict,
139
                                                   certificate_row[5],
140
                                                   certificate_row[6])
149
                                                   certificate_row[4],      # common name
150
                                                   certificate_row[5],      # country code
151
                                                   certificate_row[6],      # locality
152
                                                   certificate_row[7],      # province
153
                                                   certificate_row[8],      # organization
154
                                                   certificate_row[9],      # organizational unit
155
                                                   certificate_row[10],     # email address
156
                                                   certificate_row[11],     # revocation date
157
                                                   certificate_row[12])     # revocation reason
158

  
141 159
        except IntegrityError:
142 160
            Logger.error(INTEGRITY_ERROR_MSG)
143 161
            raise DatabaseException(INTEGRITY_ERROR_MSG)
......
195 213
                for usage_row in usage_rows:
196 214
                    usage_dict[usage_row[2]] = True
197 215

  
198
                certificates.append(Certificate(certificate_row[0],
199
                                                certificate_row[1],
200
                                                certificate_row[2],
201
                                                certificate_row[3],
202
                                                certificate_row[4],
203
                                                certificate_row[8],
204
                                                certificate_row[9],
205
                                                certificate_row[10],
216
                certificates.append(Certificate(certificate_row[0],      # ID
217
                                                certificate_row[1],      # valid from
218
                                                certificate_row[2],      # valid to
219
                                                certificate_row[3],      # pem data
220
                                                certificate_row[14],     # type ID
221
                                                certificate_row[15],     # parent ID
222
                                                certificate_row[16],     # private key ID
206 223
                                                usage_dict,
207
                                                certificate_row[5],
208
                                                certificate_row[6]))
224
                                                certificate_row[4],      # common name
225
                                                certificate_row[5],      # country code
226
                                                certificate_row[6],      # locality
227
                                                certificate_row[7],      # province
228
                                                certificate_row[8],      # organization
229
                                                certificate_row[9],      # organizational unit
230
                                                certificate_row[10],     # email address
231
                                                certificate_row[11],     # revocation date
232
                                                certificate_row[12]))    # revocation reason
209 233
        except IntegrityError:
210 234
            Logger.error(INTEGRITY_ERROR_MSG)
211 235
            raise DatabaseException(INTEGRITY_ERROR_MSG)
......
243 267

  
244 268
        try:
245 269
            sql = (f"UPDATE {TAB_CERTIFICATES} "
246
                   f"SET {COL_COMMON_NAME} = ?, "
247
                   f"{COL_VALID_FROM} = ?, "
270
                   f"SET {COL_VALID_FROM} = ?, "
248 271
                   f"{COL_VALID_TO} = ?, "
249 272
                   f"{COL_PEM_DATA} = ?, "
250
                   f"{COL_PRIVATE_KEY_ID} = ?, "
273
                   f"{COL_COMMON_NAME} = ?, "
274
                   f"{COL_COUNTRY_CODE} = ?, "
275
                   f"{COL_LOCALITY} = ?, "
276
                   f"{COL_PROVINCE} = ?, "
277
                   f"{COL_ORGANIZATION} = ?, "
278
                   f"{COL_ORGANIZATIONAL_UNIT} = ?, "
279
                   f"{COL_EMAIL_ADDRESS} = ?, "
251 280
                   f"{COL_TYPE_ID} = ?, "
252
                   f"{COL_PARENT_ID} = ? "
281
                   f"{COL_PARENT_ID} = ?, "
282
                   f"{COL_PRIVATE_KEY_ID} = ? "
253 283
                   f"WHERE {COL_ID} = ?")
254
            values = [certificate.common_name,
255
                      certificate.valid_from,
284
            values = [certificate.valid_from,
256 285
                      certificate.valid_to,
257 286
                      certificate.pem_data,
258
                      certificate.private_key_id,
287
                      certificate.common_name,
288
                      certificate.country_code,
289
                      certificate.locality,
290
                      certificate.province,
291
                      certificate.organization,
292
                      certificate.organizational_unit,
293
                      certificate.email_address,
259 294
                      certificate.type_id,
260 295
                      certificate.parent_id,
296
                      certificate.private_key_id,
261 297
                      certificate_id]
262 298

  
263 299
            self.cursor.execute(sql, values)
......
409 445

  
410 446
        try:
411 447
            sql = (f"UPDATE {TAB_CERTIFICATES} "
412
                   f"SET {COL_REVOCATION_DATE} = '', "
413
                   f"{COL_REVOCATION_REASON} = '' "
448
                   f"SET {COL_REVOCATION_DATE} = NULL, "
449
                   f"{COL_REVOCATION_REASON} = NULL "
414 450
                   f"WHERE {COL_ID} = ?")
415 451
            values = [certificate_id]
416 452
            self.cursor.execute(sql, values)
......
469 505
                for usage_row in usage_rows:
470 506
                    usage_dict[usage_row[2]] = True
471 507

  
472
                certificates.append(Certificate(certificate_row[0],
473
                                                certificate_row[1],
474
                                                certificate_row[2],
475
                                                certificate_row[3],
476
                                                certificate_row[4],
477
                                                certificate_row[8],
478
                                                certificate_row[9],
479
                                                certificate_row[10],
508
                certificates.append(Certificate(certificate_row[0],      # ID
509
                                                certificate_row[1],      # valid from
510
                                                certificate_row[2],      # valid to
511
                                                certificate_row[3],      # pem data
512
                                                certificate_row[14],     # type ID
513
                                                certificate_row[15],     # parent ID
514
                                                certificate_row[16],     # private key ID
480 515
                                                usage_dict,
481
                                                certificate_row[5],
482
                                                certificate_row[6]))
516
                                                certificate_row[4],      # common name
517
                                                certificate_row[5],      # country code
518
                                                certificate_row[6],      # locality
519
                                                certificate_row[7],      # province
520
                                                certificate_row[8],      # organization
521
                                                certificate_row[9],      # organizational unit
522
                                                certificate_row[10],     # email address
523
                                                certificate_row[11],     # revocation date
524
                                                certificate_row[12]))    # revocation reason
483 525
        except IntegrityError:
484 526
            Logger.error(INTEGRITY_ERROR_MSG)
485 527
            raise DatabaseException(INTEGRITY_ERROR_MSG)
......
535 577
                for usage_row in usage_rows:
536 578
                    usage_dict[usage_row[2]] = True
537 579

  
538
                certificates.append(Certificate(certificate_row[0],
539
                                                certificate_row[1],
540
                                                certificate_row[2],
541
                                                certificate_row[3],
542
                                                certificate_row[4],
543
                                                certificate_row[8],
544
                                                certificate_row[9],
545
                                                certificate_row[10],
580
                certificates.append(Certificate(certificate_row[0],      # ID
581
                                                certificate_row[1],      # valid from
582
                                                certificate_row[2],      # valid to
583
                                                certificate_row[3],      # pem data
584
                                                certificate_row[14],     # type ID
585
                                                certificate_row[15],     # parent ID
586
                                                certificate_row[16],     # private key ID
546 587
                                                usage_dict,
547
                                                certificate_row[5],
548
                                                certificate_row[6]))
588
                                                certificate_row[4],      # common name
589
                                                certificate_row[5],      # country code
590
                                                certificate_row[6],      # locality
591
                                                certificate_row[7],      # province
592
                                                certificate_row[8],      # organization
593
                                                certificate_row[9],      # organizational unit
594
                                                certificate_row[10],     # email address
595
                                                certificate_row[11],     # revocation date
596
                                                certificate_row[12]))    # revocation reason
549 597
        except IntegrityError:
550 598
            Logger.error(INTEGRITY_ERROR_MSG)
551 599
            raise DatabaseException(INTEGRITY_ERROR_MSG)
src/db/init_queries.py
1 1
SCHEMA_SQL = """
2 2
/* ---------------------------------------------------- */
3 3
/*  Generated by Enterprise Architect Version 13.5 		*/
4
/*  Created On : 27-dub-2021 11:31:54 				*/
4
/*  Created On : 29-dub-2021 11:55:46 				*/
5 5
/*  DBMS       : SQLite 								*/
6 6
/* ---------------------------------------------------- */
7 7

  
......
27 27
CREATE TABLE 'Certificates'
28 28
(
29 29
	'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
30
	'common_name' TEXT NOT NULL,
31 30
	'valid_from' TEXT NOT NULL,
32 31
	'valid_to' TEXT NOT NULL,
33 32
	'pem_data' TEXT NOT NULL,
33
	'common_name' TEXT NOT NULL,
34
	'country_code' TEXT NULL,
35
	'locality' TEXT NULL,
36
	'province' TEXT NULL,
37
	'organization' TEXT NULL,
38
	'organizational_unit' TEXT NULL,
39
	'email_address' TEXT NULL,
34 40
	'revocation_date' TEXT NULL,
35 41
	'revocation_reason' TEXT NULL,
36 42
	'deletion_date' TEXT NULL,
37
	'private_key_id' INTEGER NOT NULL,
38 43
	'certificate_type_id' INTEGER NOT NULL,
39 44
	'parent_certificate_id' INTEGER NOT NULL,
45
	'private_key_id' INTEGER NOT NULL,
40 46
	CONSTRAINT 'FK_Certificates' FOREIGN KEY ('parent_certificate_id') REFERENCES 'Certificates' ('id') ON DELETE No Action ON UPDATE No Action,
41 47
	CONSTRAINT 'FK_CertificateTypes' FOREIGN KEY ('certificate_type_id') REFERENCES 'CertificateTypes' ('id') ON DELETE No Action ON UPDATE No Action,
42 48
	CONSTRAINT 'FK_PrivateKeys' FOREIGN KEY ('private_key_id') REFERENCES 'PrivateKeys' ('id') ON DELETE No Action ON UPDATE No Action
src/model/certificate.py
3 3

  
4 4

  
5 5
class Certificate:
6

  
6 7
    def __init__(self,
7 8
                 certificate_id: int,
8
                 common_name: str,
9 9
                 valid_from: str,
10 10
                 valid_to: str,
11 11
                 pem_data: str,
12
                 private_key_id: int,
13 12
                 type_id: int,
14 13
                 parent_id: int,
14
                 private_key_id: int,
15 15
                 usages: Dict[int, bool],
16
                 revocation_date: str = "",
17
                 revocation_reason: str = ""):
16
                 common_name: str,
17
                 country_code: str = None,
18
                 locality: str = None,
19
                 province: str = None,
20
                 organization: str = None,
21
                 organizational_unit: str = None,
22
                 email_address: str = None,
23
                 revocation_date: str = None,
24
                 revocation_reason: str = None):
18 25
        self.certificate_id: int = certificate_id
19
        self.common_name: str = common_name
20 26
        self.valid_from: str = valid_from
21 27
        self.valid_to: str = valid_to
22 28
        self.pem_data: str = pem_data
23
        self.revocation_date = revocation_date
24
        self.revocation_reason = revocation_reason
25
        self.private_key_id: int = private_key_id
26 29
        self.type_id: int = type_id
27 30
        self.parent_id: int = parent_id
31
        self.private_key_id: int = private_key_id
32
        self.common_name: str = common_name
33
        self.country_code: str = country_code
34
        self.locality: str = locality
35
        self.province: str = province
36
        self.organization: str = organization
37
        self.organizational_unit: str = organizational_unit
38
        self.email_address: str = email_address
39
        self.revocation_date: str = revocation_date
40
        self.revocation_reason: str = revocation_reason
28 41
        self.usages: Dict[int, bool] = DICT_USAGES.copy()
29 42

  
30
        if revocation_date is None:
31
            self.revocation_date = ""
43
        #if revocation_date is None:
44
        #    self.revocation_date = ""
32 45

  
33
        if revocation_reason is None:
34
            self.revocation_reason = ""
46
        #if revocation_reason is None:
47
        #    self.revocation_reason = ""
35 48

  
36 49
        for usage_id, usage_value in usages.items():
37 50
            self.usages[usage_id] = usage_value

Také k dispozici: Unified diff