Skip to content

Suppport to verify aboot swi image for secure boot#969

Merged
xumia merged 5 commits intosonic-net:masterfrom
xumia:verify_image
Jun 30, 2020
Merged

Suppport to verify aboot swi image for secure boot#969
xumia merged 5 commits intosonic-net:masterfrom
xumia:verify_image

Conversation

@xumia
Copy link
Copy Markdown
Collaborator

@xumia xumia commented Jun 28, 2020

- What I did
The feature is to verify the aboot swi image, it makes sure the installing image should be signed when secure boot enabled.

- How I did it

- How to verify it

- Previous command output (if the output of a command-line utility has changed)

- New command output (if the output of a command-line utility has changed)


import click

from M2Crypto import X509
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M2Crypto [](start = 5, length = 8)

Add this new dependency in setup.py?
#Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be add in build_debian.sh in sonic-buildimage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your statement is true. But by best practice, you need to add new dependency in setup.py


In reply to: 446767082 [](ancestors = 446767082)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

try:
subprocess.check_call(['/usr/bin/unzip', '-tq', image_path])
# TODO: secureboot check signature
if not self._verify_secureboot_image(image_path):
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._verify_secureboot_image(image_path) [](start = 19, length = 41)

Just return, no need to use if-block #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

else:
print( 'Unexpected format for line in swi[x]-signature file: %s' % line )
return None
except KeyError:
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except KeyError: [](start = 8, length = 16)

if only one line of code could raise exception, could you minimize your try-block? #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

signingCert = X509.load_cert_string(cert)
return signingCert
else:
print( 'Unexpected format for line in swi[x]-signature file: %s' % line )
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print [](start = 28, length = 5)

print to stderr #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

def base64Decode(cls, text):
try:
return base64.standard_b64decode(text)
except TypeError:
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeError [](start = 15, length = 9)

Is it better to catch in getCert() ? #Closed

@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Jun 29, 2020

This pull request introduces 1 alert when merging 7b12c00 into 16a33f2 - view on LGTM.com

new alerts:

  • 1 for Syntax error

return True

def _verify_secureboot_image(self, image_path):
if isSecureboot():
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isSecureboot(): [](start = 8, length = 18)

If not, should you return True? #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed.

if not cert or not current_cert:
return False
# Verify the signing certificates are from the same issuer
return str(cert.get_issuer()) == str(current_cert.get_issuer())
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is use case of change issuer in long run. Could you comment out this part of code? #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qiluo-msft , we only need to verify the image has been signed, not need to verify the issuer, right?

@qiluo-msft qiluo-msft requested a review from lguohan June 29, 2020 16:39
@qiluo-msft
Copy link
Copy Markdown
Contributor

qiluo-msft commented Jun 29, 2020

Fix the build environment in Azure/sonic-build-tools#128 #Closed

@qiluo-msft
Copy link
Copy Markdown
Contributor

qiluo-msft commented Jun 29, 2020

Retest this please #Closed

@xumia xumia merged commit aae89b7 into sonic-net:master Jun 30, 2020
abdosi pushed a commit to abdosi/sonic-utilities that referenced this pull request Aug 4, 2020
* Suppport to verify aboot swi image for secure boot

* Simplify the code

* Fix not return value bug

* Add m2crypto to setup.py

* Change to only verify the image signed by a correct certificate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants