Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AndroidSystemSEPolicy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matombo
AndroidSystemSEPolicy
Commits
ce90fc4f
Commit
ce90fc4f
authored
Oct 9, 2013
by
Nick Kralevich
Committed by
Gerrit Code Review
Oct 9, 2013
Browse files
Options
Downloads
Plain Diff
Merge "tools: Correct insert keys behavior on pem files"
parents
85c5fc21
1ecb4e8a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/insertkeys.py
+55
-9
55 additions, 9 deletions
tools/insertkeys.py
with
55 additions
and
9 deletions
tools/insertkeys.py
+
55
−
9
View file @
ce90fc4f
...
@@ -34,19 +34,65 @@ class GenerateKeys(object):
...
@@ -34,19 +34,65 @@ class GenerateKeys(object):
pkFile
=
open
(
path
,
'
rb
'
).
readlines
()
pkFile
=
open
(
path
,
'
rb
'
).
readlines
()
base64Key
=
""
base64Key
=
""
lineNo
=
1
certNo
=
1
inCert
=
False
inCert
=
False
for
line
in
pkFile
:
for
line
in
pkFile
:
if
line
.
startswith
(
"
-
"
):
line
=
line
.
strip
()
inCert
=
not
inCert
# Are we starting the certificate?
continue
if
line
.
startswith
(
"
-----BEGIN CERTIFICATE-----
"
):
if
inCert
:
sys
.
exit
(
"
Encountered another BEGIN CERTIFICATE without END CERTIFICATE on
"
+
"
line:
"
+
str
(
lineNo
))
inCert
=
True
# Are we ending the ceritifcate?
elif
line
.
startswith
(
"
-----END CERTIFICATE-----
"
):
if
not
inCert
:
sys
.
exit
(
"
Encountered END CERTIFICATE before BEGIN CERTIFICATE on line:
"
+
str
(
lineNo
))
# If we ended the certificate trip the flag
inCert
=
False
base64Key
+=
line
.
strip
()
# Sanity check the input
if
len
(
base64Key
)
==
0
:
sys
.
exit
(
"
Empty certficate , certificate
"
+
str
(
certNo
)
+
"
found in file:
"
+
path
)
# ... and append the certificate to the list
# Base 64 includes uppercase. DO NOT tolower()
# Base 64 includes uppercase. DO NOT tolower()
self
.
_base64Key
.
append
(
base64Key
)
self
.
_base64Key
.
append
(
base64Key
)
try
:
# Pkgmanager and setool see hex strings with lowercase, lets be consistent
.
# Pkgmanager and setool see hex strings with lowercase, lets be consistent
self
.
_base16Key
.
append
(
base64
.
b16encode
(
base64
.
b64decode
(
base64Key
)).
lower
())
self
.
_base16Key
.
append
(
base64
.
b16encode
(
base64
.
b64decode
(
base64Key
)).
lower
())
except
TypeError
:
sys
.
exit
(
"
Invalid certificate, certificate
"
+
str
(
certNo
)
+
"
found in file:
"
+
path
)
# After adding the key, reset the accumulator as pem files may have subsequent keys
base64Key
=
""
# And increment your cert number
certNo
=
certNo
+
1
# If we haven't started the certificate, then we should not encounter any data
elif
not
inCert
:
sys
.
exit
(
"
Detected erroneous line
\"
"
+
line
+
"
\"
on
"
+
str
(
lineNo
)
+
"
in pem file:
"
+
path
)
# else we have started the certicate and need to append the data
elif
inCert
:
base64Key
+=
line
else
:
# We should never hit this assert, if we do then an unaccounted for state
# was entered that was NOT addressed by the if/elif statements above
assert
(
False
==
True
)
# The last thing to do before looping up is to increment line number
lineNo
=
lineNo
+
1
def
__len__
(
self
):
def
__len__
(
self
):
return
len
(
self
.
_base16Key
)
return
len
(
self
.
_base16Key
)
...
...
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
sign in
to comment