-
Notifications
You must be signed in to change notification settings - Fork 818
Suppport to verify aboot swi image for secure boot #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f60b5c3
7b12c00
14bb55d
c526df2
d6679a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,17 @@ | |
| Bootloader implementation for Aboot used on Arista devices | ||
| """ | ||
|
|
||
| import base64 | ||
| import collections | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import zipfile | ||
|
|
||
| import click | ||
|
|
||
| from M2Crypto import X509 | ||
|
|
||
| from ..common import ( | ||
| HOST_PATH, | ||
| IMAGE_DIR_PREFIX, | ||
|
|
@@ -18,6 +22,12 @@ | |
| from .bootloader import Bootloader | ||
|
|
||
| _secureboot = None | ||
|
|
||
| # For the signature format, see: https://github.com/aristanetworks/swi-tools/tree/master/switools | ||
| SWI_SIG_FILE_NAME = 'swi-signature' | ||
| SWIX_SIG_FILE_NAME = 'swix-signature' | ||
| ISSUERCERT = 'IssuerCert' | ||
|
|
||
| def isSecureboot(): | ||
| global _secureboot | ||
| if _secureboot is None: | ||
|
|
@@ -114,11 +124,56 @@ def get_binary_image_version(self, image_path): | |
| def verify_binary_image(self, image_path): | ||
| try: | ||
| subprocess.check_call(['/usr/bin/unzip', '-tq', image_path]) | ||
| # TODO: secureboot check signature | ||
| if not self._verify_secureboot_image(image_path): | ||
|
||
| return False | ||
| except subprocess.CalledProcessError: | ||
| return False | ||
| return True | ||
|
|
||
| def _verify_secureboot_image(self, image_path): | ||
| if isSecureboot(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If not, should you return True? #Closed
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, fixed. |
||
| current_image_path = self.get_current_image() | ||
| current_swi_path = self._swi_image_path(current_image_path).replace('flash:', HOST_PATH + '/') | ||
| cert = self.getCert(image_path) | ||
| current_cert = self.getCert(current_swi_path) | ||
| 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()) | ||
|
||
|
|
||
| @classmethod | ||
| def getCert(cls, swiFile): | ||
| try: | ||
| with zipfile.ZipFile(swiFile, 'r') as swi: | ||
| sigInfo = swi.getinfo(cls.getSigFileName(swiFile)) | ||
| with swi.open(sigInfo, 'r') as sigFile: | ||
| for line in sigFile: | ||
| data = line.split(':') | ||
| if len(data) == 2: | ||
| if data[0] == ISSUERCERT: | ||
| cert = cls.base64Decode( data[1].strip() ) | ||
| signingCert = X509.load_cert_string(cert) | ||
| return signingCert | ||
| else: | ||
| print( 'Unexpected format for line in swi[x]-signature file: %s' % line ) | ||
|
||
| return None | ||
| except KeyError: | ||
|
||
| # Occurs if SIG_FILE_NAME is not in the swi (the SWI is not signed properly) | ||
| return None | ||
|
|
||
| @classmethod | ||
| def getSigFileName(cls, swiFile): | ||
| if swiFile.lower().endswith(".swix"): | ||
| return SWIX_SIG_FILE_NAME | ||
| return SWI_SIG_FILE_NAME | ||
|
|
||
| @classmethod | ||
| def base64Decode(cls, text): | ||
| try: | ||
| return base64.standard_b64decode(text) | ||
| except TypeError: | ||
|
||
| return "" | ||
|
|
||
| @classmethod | ||
| def detect(cls): | ||
| with open('/proc/cmdline') as f: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this new dependency in setup.py?
#Closed
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.