-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.h
More file actions
158 lines (141 loc) · 8.88 KB
/
Copy pathdb.h
File metadata and controls
158 lines (141 loc) · 8.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***
Copyright 2010-2026 by Omar Alejandro Herrera Reyna
Caume Data Security Engine, also known as CaumeDSE is released under the
GNU General Public License by the Copyright holder, with the additional
exemption that compiling, linking, and/or using OpenSSL is allowed.
LICENSE
This file is part of Caume Data Security Engine, also called CaumeDSE.
CaumeDSE 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.
CaumeDSE 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 CaumeDSE. If not, see <http://www.gnu.org/licenses/>.
INCLUDED SOFTWARE
This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).
This product includes cryptographic software written by
Eric Young (eay@cryptsoft.com).
This product includes software written by
Tim Hudson (tjh@cryptsoft.com).
This product includes software from the SQLite library that is in
the public domain (http://www.sqlite.org/copyright.html).
This product includes software from the GNU Libmicrohttpd project, Copyright
© 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
2008, 2009, 2010 , 2011, 2012 Free Software Foundation, Inc.
This product includes software from Perl5, which is Copyright (C) 1993-2005,
by Larry Wall and others.
***/
#ifndef DBSQLITE_H_INCLUDED
#define DBSQLITE_H_INCLUDED
// Wrapper function for sqlite3_open_v2() to create a new database file
int cmeDBCreateOpen (const char *filename, sqlite3 **ppDB);
// Wrapper function for sqlite3_open_v2() to create a new memory database
int cmeMemDBCreateOpen (sqlite3 **ppDB);
// Wrapper function for sqlite3_open_v2() to open an esisting database file for R/W
int cmeDBOpen (const char *filename, sqlite3 **ppDB);
// Wrapper function for sqlite3_close()
int cmeDBClose (sqlite3 *ppDB);
// Wrapper function for sqlite3_backup_init(), sqlite3_backup_step() and sqlite3_backup_finish()
int cmeMemDBLoadOrSave(sqlite3 *pInMemory, const char *zFilename, int isSave);
int cmeMemDBLoadOrSaveVacuum(sqlite3 *pInMemory, const char *zFilename, int isSave, int vacuumBeforeSave);
// Iteration function for cmeSQLRows that wrapps cmePerlParserScriptFunction()
int cmeSQLIterate (const char *args,int numCols,char **pStrResults,char **pColNames);
// Wrapper function for sqlite3_exec() and cmeSQLIterate ()
int cmeSQLRows (sqlite3 *db, const char *sqlQuery, char *perlScriptName,
PerlInterpreter *myPerl);
// Wrapper function for sqlite3_get_table()
int cmeMemTable (sqlite3 *db, const char *sqlQuery,char ***pQueryResult,
int *numRows, int *numColumns);
// Wrapper function for sqlite3_free_table()
int cmeMemTableFinal (char **QueryResult);
// Function to import a Memory table (eg. result from cmeSQLTable() into a SQLite3 DB
int cmeMemTableToMemDB (sqlite3 *dstMemDB, const char **srcMemTable, const int numRows,
const int numCols, char *sqlTableName);
// Function to shuffle rows in a SQLite3 Memory table (resulting from cmeSQLTable()).
int cmeMemTableShuffle(char **sqlTable, const int numRows, const int numCols, const int skipHeaderRows,
const int skipIdCols);
// Function to (re)order shuffled rows in an unprotected, SQLite3 Memory table (resulting from cmeSQLTable()).
int cmeMemTableOrder(char **sqlTable, const int numRows, const int numCols, const int orderIdxCol, const int skipHeaderRows,
const int skipIdCols);
// Function to apply protections on individual secureDB Column Files.
int cmeMemSecureDBProtect (sqlite3 *memSecureDB, const char *orgKey);
// Function to remove protections on individual secureDB Column Files.
int cmeMemSecureDBUnprotect (sqlite3 *memSecureDB, const char *orgKey);
// Function to protect (encrypt and B64 codify) a text string. Note that source length is determined by strlen(). For byte strings use cmeProtectByteString() instead!
int cmeProtectDBValue (const char *value, char **protectedValue, const char *encAlg, char **salt,
const char *orgKey, int *protectedValueLen);
// Function to unprotect (decodify B64 and unencrypt) a text string. Note that source length is determined by strlen(). For byte strings use cmeUnprotectByteString() instead!
int cmeUnprotectDBValue (const char *protectedValue, char **value, const char *encAlg, char **salt,
const char *orgKey, int *valueLen);
// Function to salt+protect (add salt to value, encrypt and B64 codify) a text string.
int cmeProtectDBSaltedValue (const char *value, char **protectedValue, const char *encAlg, char **salt,
const char *orgKey, int *protectedValueLen);
// Function to unprotect+unsalt (decodify B64, unencrypt and remove salt from value) a salt+protected text string.
int cmeUnprotectDBSaltedValue (const char *protectedValue, char **value, const char *encAlg, char **salt,
const char *orgKey, int *valueLen);
typedef struct
{
int metaRows;
int dataRows;
int protectMetaRows;
int protectedValueRows;
int sourceProfileRows;
int targetProfileRows;
int legacyAESValueRows;
int herraduraValueRows;
int unknownValueRows;
char sourceProfile[64];
char targetProfile[64];
} cmeReprotectDBInventory;
typedef struct
{
cmeReprotectDBInventory before;
cmeReprotectDBInventory after;
int dataRowsReprotected;
int metaRowsReprotected;
int dryRun;
} cmeReprotectDBReport;
// Function to strictly unprotect+reprotect one salted DB value for explicit key/profile rotation workflows.
int cmeReprotectDBSaltedValue (const char *protectedValue, char **reprotectedValue,
const char *sourceEncAlg, const char *targetEncAlg,
char **sourceSalt, char **targetSalt,
const char *sourceOrgKey, const char *targetOrgKey,
int *reprotectedValueLen, int dryRun);
// Function to inventory a protected in-memory column-file DB before explicit key/profile rotation.
int cmeInventoryMemSecureDBReprotect (sqlite3 *memSecureDB, const char *orgKey,
const char *targetEncAlg,
cmeReprotectDBInventory *inventory);
// Function to explicitly re-protect protected values in an in-memory column-file DB.
int cmeReprotectMemSecureDB (sqlite3 *memSecureDB, const char *sourceOrgKey,
const char *targetOrgKey, const char *targetEncAlg,
cmeReprotectDBReport *report, int dryRun);
// Function to compute deterministic keyed lookup values for selected protected exact-match columns.
int cmeGetProtectDBLookupValue (const char *columnName, const char *value, const char *orgKey,
char **lookupValue);
// Function to ensure optional ResourcesDB document lookup columns and indexes exist.
int cmeEnsureResourcesDBDocumentLookups (sqlite3 *pDB);
// Function to write current internal schema metadata after explicit create/upgrade.
int cmeSetInternalDBSchemaVersion(sqlite3 *pDB, const char *dbClass);
// Function to fail closed on incompatible internal schemas. allowLegacy accepts structurally valid DBs without metadata.
int cmeCheckInternalDBSchema(sqlite3 *pDB, const char *dbClass, int allowLegacy);
// Function to explicitly upgrade legacy LogsDB transaction columns to the current schema.
int cmeEnsureLogsDBTransactionsSchema(sqlite3 *pDB);
// Function to reintegrate (before unprotecting) sliced DB columns of secure DB column files in memory.
int cmeMemSecureDBReintegrate (sqlite3 **memSecureDB, const char *orgKey,
const int dbNumCols, int *dbNumReintegratedCols);
// Function to wipe and free memory associated with global result database (used by cmeSQLRows, cmeSQLIterate).
int cmeResultMemTableClean ();
// Function to get (in cmeResultMemTable) a string array of column names for table tableName.
int cmeMemTableWithTableColumnNames (sqlite3 *db, const char *tableName);
// Function to validate a SQL identifier before embedding it in a query.
int cmeIsSafeSQLIdentifier(const char *identifier);
// Function to check for SQL metacharacters that are not accepted in direct web-service inputs.
int cmeHasUnsafeSQLInputChars(const char *sourceString);
// Function to sanitize an input string (doubles single quote characters) to avoid sql injection attacks in sql queries.
int cmeSanitizeStrForSQL (const char *sourceString, char **sanitizedString);
#endif // DBSQLITE_H_INCLUDED