Skip to content

Commit

Permalink
Aligned sign_script to regenerate.sh + to new default volatile KEY_ID
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Hadasz <[email protected]>
  • Loading branch information
ahasztag committed Oct 7, 2024
1 parent 35f1ab7 commit cad6e4e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ncs/sign_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
from collections import defaultdict
from enum import Enum, unique

import logging

logger = logging.getLogger(__name__)

#
# User note:
# Rename the files to 'key_private_<KEY>.der' if you are using keys in DER format.
#
DEFAULT_PRIVATE_KEY = Path(__file__).parent / "key_private.pem"

PRIVATE_KEYS = {
0x7FFFFFE0: Path(__file__).parent / "key_private.pem",
0x40000000: Path(__file__).parent / "key_private.pem",
0x4000AA00: Path(__file__).parent / "key_private_OEM_ROOT_GEN1.pem",
0x40022100: Path(__file__).parent / "key_private_APPLICATION_GEN1.pem",
0x40032100: Path(__file__).parent / "key_private_RADIO_GEN1.pem",
Expand Down Expand Up @@ -68,13 +74,13 @@ class SuitIds(Enum):
SUIT_MANIFEST_COMPONENT_ID = 5


DEFAULT_KEY_ID = 0x7FFFFFE0
DEFAULT_KEY_ID = 0x40000000

KEY_IDS = {
"nRF54H20_sample_root": 0x4000AA00, # MANIFEST_PUBKEY_OEM_ROOT_GEN1
"nRF54H20_sample_app": 0x40022100, # MANIFEST_PUBKEY_APPLICATION_GEN1
"nRF54H20_sample_rad": 0x40032100,
} # MANIFEST_PUBKEY_RADIO_GEN1
"nRF54H20_sample_rad": 0x40032100, # MANIFEST_PUBKEY_RADIO_GEN1
}

DOMAIN_NAME = "nordicsemi.com"

Expand Down Expand Up @@ -176,7 +182,12 @@ def _get_key_id_for_manifest_class(self):

def _get_private_key_path_for_manifest_class(self) -> Path:
key_id = self._key_ids[self._get_manifest_class_id()]
return PRIVATE_KEYS[key_id]
key_path = PRIVATE_KEYS[key_id]
if not key_path.exists():
logger.warning(f"Private key {key_path} not found. Using default key path {DEFAULT_PRIVATE_KEY}. "
"This is only for Nordic testing purposes - please provide the {key_path} file.")
key_path = DEFAULT_PRIVATE_KEY
return key_path

def sign(self, private_key_path: Path = None) -> None:
"""Add signature to the envelope."""
Expand Down

0 comments on commit cad6e4e

Please sign in to comment.