-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fitimagesign: add support for generic fitimage signing
* Add signing class for generic FIT images using U-Boot tools for signing * Add a documentation page
- Loading branch information
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import copy | ||
from typing import Optional | ||
from digsigserver.signers import Signer | ||
|
||
from sanic import Sanic | ||
from sanic.log import logger | ||
|
||
class FitImageSigner (Signer): | ||
|
||
keytag = 'fitimagesign' | ||
|
||
def __init__(self, app: Sanic, workdir: str): | ||
super().__init__(app, workdir, "imx") | ||
|
||
def _prepare_path(self) -> dict: | ||
env = dict(copy.deepcopy(os.environ)) | ||
curpath = env.get('PATH') | ||
if curpath: | ||
env['PATH'] += ':' + curpath | ||
return env | ||
|
||
def sign(self, fitimage: str, | ||
dtb: Optional[str], | ||
external_data_offset: Optional[str], | ||
mark_required: Optional[bool], | ||
algo: Optional[str], | ||
keyname: str = "dev.key") -> bool: | ||
private_key = self.keys.get("{}.key".format(keyname)) | ||
env = self._prepare_path() | ||
cmd = [ 'mkimage', '-F', '-k', os.path.dirname(private_key) ] | ||
if external_data_offset: | ||
cmd += [ '-p', external_data_offset ] | ||
if mark_required: | ||
cmd += [ '-r' ] | ||
if dtb: | ||
cmd += [ '-K', dtb ] | ||
if algo: | ||
cmd +=[ '-o', algo ] | ||
|
||
cmd += [ fitimage ] | ||
result = self.run_command(cmd, env=env) | ||
self.keys.cleanup() | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Signing fitimages | ||
|
||
## Prerequisites | ||
The only tool required is `mkimage` from `u-boot-tools`. | ||
|
||
## Keyfile storage layout | ||
The private key used for signing the fitImage is expected in the following location: | ||
|
||
${DIGSIGSERVER_KEYFILE_URI}/imx/dev.key | ||
|
||
The name of the key can be customized with a REST API parameter, otherwise `dev` is default. | ||
|
||
## REST API endpoint | ||
|
||
Request type: `POST` | ||
|
||
Endpoint: `/sign/fitimage` | ||
|
||
Expected parameters: | ||
* `artifact=<body>` - binary to be signed | ||
|
||
Optional parameters: | ||
* `external_data_offset=<offset>` - external data offset to be used during FIT signing | ||
* `mark_required=<any value>` - if this parameter exists the key will be marked as required | ||
* `algo=<signing algorithm>` - customize the signing algorithm | ||
* `keyname=<name of the key to use>` - specify a keyname other than `dev` | ||
|
||
Response: signed binary | ||
|
||
Example usage: | ||
curl --connect-timeout 30 --max-time 1800 --retry 1 --fail -X POST \ | ||
-F external_data_offset=2000 -F "artifact=@fitImage" \ | ||
-F mark_required=true -F keyname=devkey \ | ||
--output fitImage.signed http://$DIGSIG_SERVER_IP:$DIGSIG_SERVER_PORT/sign/fitimage | ||
|
||
|
||
## Future improvements | ||
* Enable including a device tree blob in which the public key is injected. | ||
* Change the `imx` "machine" to something more logical, this is not machine dependent | ||
|