1
|
SCHEMA_SQL = """
|
2
|
/* ---------------------------------------------------- */
|
3
|
/* Generated by Enterprise Architect Version 13.5 */
|
4
|
/* Created On : 29-dub-2021 11:55:46 */
|
5
|
/* DBMS : SQLite */
|
6
|
/* ---------------------------------------------------- */
|
7
|
|
8
|
/* Drop Tables */
|
9
|
|
10
|
DROP TABLE IF EXISTS 'Certificates'
|
11
|
;
|
12
|
|
13
|
DROP TABLE IF EXISTS 'CertificateTypes'
|
14
|
;
|
15
|
|
16
|
DROP TABLE IF EXISTS 'CertificateUsages'
|
17
|
;
|
18
|
|
19
|
DROP TABLE IF EXISTS 'PrivateKeys'
|
20
|
;
|
21
|
|
22
|
DROP TABLE IF EXISTS 'UsageTypes'
|
23
|
;
|
24
|
|
25
|
/* Create Tables with Primary and Foreign Keys, Check and Unique Constraints */
|
26
|
|
27
|
CREATE TABLE 'Certificates'
|
28
|
(
|
29
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
30
|
'valid_from' TEXT NOT NULL,
|
31
|
'valid_to' TEXT NOT NULL,
|
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,
|
40
|
'revocation_date' TEXT NULL,
|
41
|
'revocation_reason' TEXT NULL,
|
42
|
'deletion_date' TEXT NULL,
|
43
|
'certificate_type_id' INTEGER NOT NULL,
|
44
|
'parent_certificate_id' INTEGER NOT NULL,
|
45
|
'private_key_id' INTEGER NOT NULL,
|
46
|
CONSTRAINT 'FK_Certificates' FOREIGN KEY ('parent_certificate_id') REFERENCES 'Certificates' ('id') ON DELETE No Action ON UPDATE No Action,
|
47
|
CONSTRAINT 'FK_CertificateTypes' FOREIGN KEY ('certificate_type_id') REFERENCES 'CertificateTypes' ('id') ON DELETE No Action ON UPDATE No Action,
|
48
|
CONSTRAINT 'FK_PrivateKeys' FOREIGN KEY ('private_key_id') REFERENCES 'PrivateKeys' ('id') ON DELETE No Action ON UPDATE No Action
|
49
|
)
|
50
|
;
|
51
|
|
52
|
CREATE TABLE 'CertificateTypes'
|
53
|
(
|
54
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
55
|
'certificate_type' TEXT NOT NULL
|
56
|
)
|
57
|
;
|
58
|
|
59
|
CREATE TABLE 'CertificateUsages'
|
60
|
(
|
61
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
62
|
'certificate_id' INTEGER NOT NULL,
|
63
|
'usage_type_id' INTEGER NOT NULL,
|
64
|
CONSTRAINT 'FK_Certificates' FOREIGN KEY ('certificate_id') REFERENCES 'Certificates' ('id') ON DELETE Cascade ON UPDATE No Action,
|
65
|
CONSTRAINT 'FK_UsageTypes' FOREIGN KEY ('usage_type_id') REFERENCES 'UsageTypes' ('id') ON DELETE No Action ON UPDATE No Action
|
66
|
)
|
67
|
;
|
68
|
|
69
|
CREATE TABLE 'PrivateKeys'
|
70
|
(
|
71
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
72
|
'private_key' TEXT NOT NULL,
|
73
|
'password' TEXT NULL
|
74
|
)
|
75
|
;
|
76
|
|
77
|
CREATE TABLE 'UsageTypes'
|
78
|
(
|
79
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
80
|
'usage_type' TEXT NOT NULL
|
81
|
)
|
82
|
;
|
83
|
|
84
|
"""
|
85
|
|
86
|
# TODO static tables are dropped
|
87
|
CHECK_SCHEMA_SQL = """
|
88
|
/* Drop Tables */
|
89
|
DROP TABLE IF EXISTS 'CertificateTypes'
|
90
|
;
|
91
|
|
92
|
DROP TABLE IF EXISTS 'CertificateUsages'
|
93
|
;
|
94
|
|
95
|
/* Create Tables with Primary and Foreign Keys, Check and Unique Constraints */
|
96
|
|
97
|
CREATE TABLE IF NOT EXISTS 'Certificates'
|
98
|
(
|
99
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
100
|
'valid_from' INTEGER NOT NULL,
|
101
|
'valid_to' INTEGER NOT NULL,
|
102
|
'pem_data' TEXT NOT NULL,
|
103
|
'common_name' TEXT NOT NULL,
|
104
|
'country_code' TEXT NULL,
|
105
|
'locality' TEXT NULL,
|
106
|
'province' TEXT NULL,
|
107
|
'organization' TEXT NULL,
|
108
|
'organizational_unit' TEXT NULL,
|
109
|
'email_address' TEXT NULL,
|
110
|
'revocation_date' INTEGER NULL,
|
111
|
'revocation_reason' TEXT NULL,
|
112
|
'deletion_date' INTEGER NULL,
|
113
|
'certificate_type_id' INTEGER NOT NULL,
|
114
|
'parent_certificate_id' INTEGER NOT NULL,
|
115
|
'private_key_id' INTEGER NOT NULL,
|
116
|
CONSTRAINT 'FK_Certificates' FOREIGN KEY ('parent_certificate_id') REFERENCES 'Certificates' ('id') ON DELETE No Action ON UPDATE No Action,
|
117
|
CONSTRAINT 'FK_CertificateTypes' FOREIGN KEY ('certificate_type_id') REFERENCES 'CertificateTypes' ('id') ON DELETE No Action ON UPDATE No Action,
|
118
|
CONSTRAINT 'FK_PrivateKeys' FOREIGN KEY ('private_key_id') REFERENCES 'PrivateKeys' ('id') ON DELETE No Action ON UPDATE No Action
|
119
|
)
|
120
|
;
|
121
|
|
122
|
CREATE TABLE IF NOT EXISTS 'CertificateTypes'
|
123
|
(
|
124
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
125
|
'certificate_type' TEXT NOT NULL
|
126
|
)
|
127
|
;
|
128
|
|
129
|
CREATE TABLE IF NOT EXISTS 'CertificateUsages'
|
130
|
(
|
131
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
132
|
'certificate_id' INTEGER NOT NULL,
|
133
|
'usage_type_id' INTEGER NOT NULL,
|
134
|
CONSTRAINT 'FK_Certificates' FOREIGN KEY ('certificate_id') REFERENCES 'Certificates' ('id') ON DELETE Cascade ON UPDATE No Action,
|
135
|
CONSTRAINT 'FK_UsageTypes' FOREIGN KEY ('usage_type_id') REFERENCES 'UsageTypes' ('id') ON DELETE No Action ON UPDATE No Action
|
136
|
)
|
137
|
;
|
138
|
|
139
|
CREATE TABLE IF NOT EXISTS 'PrivateKeys'
|
140
|
(
|
141
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
142
|
'private_key' TEXT NOT NULL,
|
143
|
'password' TEXT NULL
|
144
|
)
|
145
|
;
|
146
|
|
147
|
CREATE TABLE IF NOT EXISTS 'UsageTypes'
|
148
|
(
|
149
|
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
150
|
'usage_type' TEXT NOT NULL
|
151
|
)
|
152
|
;
|
153
|
|
154
|
"""
|
155
|
|
156
|
DEFAULT_VALUES_SQL = """
|
157
|
/* Insert default values */
|
158
|
|
159
|
INSERT INTO CertificateTypes(certificate_type) VALUES('ROOT_CA');
|
160
|
INSERT INTO CertificateTypes(certificate_type) VALUES('INTERMEDIATE_CA');
|
161
|
INSERT INTO CertificateTypes(certificate_type) VALUES('CERTIFICATE');
|
162
|
|
163
|
INSERT INTO UsageTypes(usage_type) VALUES('CA');
|
164
|
INSERT INTO UsageTypes(usage_type) VALUES('SSL');
|
165
|
INSERT INTO UsageTypes(usage_type) VALUES('SIGNATURE');
|
166
|
INSERT INTO UsageTypes(usage_type) VALUES('AUTHENTICATION');
|
167
|
|
168
|
"""
|