Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PolycentricAndroid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoStreaming
PolycentricAndroid
Commits
62328514
Commit
62328514
authored
1 year ago
by
Koen
Browse files
Options
Downloads
Patches
Plain Diff
Moved to upgradeOldSecrets.
parent
faaa7a6d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/com/futo/polycentric/core/SqlLiteDbHelper.kt
+36
-32
36 additions, 32 deletions
...rc/main/java/com/futo/polycentric/core/SqlLiteDbHelper.kt
with
36 additions
and
32 deletions
app/src/main/java/com/futo/polycentric/core/SqlLiteDbHelper.kt
+
36
−
32
View file @
62328514
...
...
@@ -19,44 +19,14 @@ class SqlLiteDbHelper : SQLiteOpenHelper {
Log
.
w
(
TAG
,
"This is version 1, no DB to update"
)
var
currentVersion
=
oldVersion
if
(
oldVersion
=
=
1
&&
newVersion
==
2
)
{
if
(
oldVersion
<
=
1
&&
newVersion
==
2
)
{
deleteTables
(
db
)
createTables
(
db
)
currentVersion
=
2
}
if
(
currentVersion
==
2
&&
newVersion
==
3
)
{
val
cursor
=
db
.
rawQuery
(
"SELECT value FROM process_secrets"
,
arrayOf
())
val
secrets
=
arrayListOf
<
ProcessSecret
>()
cursor
.
use
{
if
(
it
.
moveToFirst
())
{
do
{
val
value
=
it
.
getBlob
(
0
)
if
(
value
!=
null
)
{
try
{
val
secret
=
ProcessSecret
.
fromProto
(
Protocol
.
StorageTypeProcessSecret
.
parseFrom
(
PEncryptionProviderV0
.
instance
.
decrypt
(
value
)))
secrets
.
add
(
secret
)
}
catch
(
e
:
Throwable
)
{
Log
.
i
(
TAG
,
"Failed to convert secret, assuming it is V1 already and skipping"
,
e
)
}
}
}
while
(
cursor
.
moveToNext
())
}
}
db
.
beginTransaction
();
try
{
for
(
secret
in
secrets
)
{
db
.
execSQL
(
"DELETE FROM process_secrets WHERE public_key = ?"
,
arrayOf
(
secret
.
system
.
publicKey
.
key
.
toBase64
()))
val
value
=
PEncryptionProviderV1
.
instance
.
encrypt
(
secret
.
toProto
().
toByteArray
())
db
.
execSQL
(
"INSERT INTO process_secrets VALUES(?, ?)"
,
arrayOf
(
secret
.
system
.
publicKey
.
key
.
toBase64
(),
value
))
}
db
.
setTransactionSuccessful
();
}
finally
{
db
.
endTransaction
();
}
upgradeOldSecrets
(
db
)
currentVersion
=
3
}
...
...
@@ -86,6 +56,40 @@ class SqlLiteDbHelper : SQLiteOpenHelper {
}
}
fun
upgradeOldSecrets
(
db
:
SQLiteDatabase
)
{
val
cursor
=
db
.
rawQuery
(
"SELECT value FROM process_secrets"
,
arrayOf
())
val
secrets
=
arrayListOf
<
ProcessSecret
>()
cursor
.
use
{
if
(
it
.
moveToFirst
())
{
do
{
val
value
=
it
.
getBlob
(
0
)
if
(
value
!=
null
)
{
try
{
val
secret
=
ProcessSecret
.
fromProto
(
Protocol
.
StorageTypeProcessSecret
.
parseFrom
(
PEncryptionProviderV0
.
instance
.
decrypt
(
value
)))
Log
.
i
(
TAG
,
"Upgrading old secret system = ${secret.system.publicKey.key.toBase64()}"
)
secrets
.
add
(
secret
)
}
catch
(
e
:
Throwable
)
{
Log
.
i
(
TAG
,
"Failed to convert secret, assuming it is V1 already and skipping"
,
e
)
}
}
}
while
(
cursor
.
moveToNext
())
}
}
db
.
beginTransaction
();
try
{
for
(
secret
in
secrets
)
{
db
.
execSQL
(
"DELETE FROM process_secrets WHERE public_key = ?"
,
arrayOf
(
secret
.
system
.
publicKey
.
key
.
toBase64
()))
val
value
=
PEncryptionProviderV1
.
instance
.
encrypt
(
secret
.
toProto
().
toByteArray
())
db
.
execSQL
(
"INSERT INTO process_secrets VALUES(?, ?)"
,
arrayOf
(
secret
.
system
.
publicKey
.
key
.
toBase64
(),
value
))
}
db
.
setTransactionSuccessful
();
}
finally
{
db
.
endTransaction
();
}
}
private
fun
createTables
(
db
:
SQLiteDatabase
)
{
db
.
execSQL
(
"CREATE TABLE system_states (public_key VARCHAR PRIMARY KEY, value BLOB)"
)
db
.
execSQL
(
"CREATE TABLE process_states (public_key_process VARCHAR PRIMARY KEY, value BLOB)"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment