Skip to content

Commit adf8594

Browse files
committed
oem-factory-reset: allow to set gpg key algorithm
* CONFIG_GPG_DEFAULT_ALGO defaults to RSA 3072 if not set * currently only p256 is supported as alternative * added p256 for nitropad ns50/nv41 boards
1 parent 3a7e759 commit adf8594

3 files changed

Lines changed: 50 additions & 18 deletions

File tree

boards/nitropad-ns50/nitropad-ns50.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export CONFIG_BOOTSCRIPT=/bin/gui-init
4141
export CONFIG_BOOT_KERNEL_ADD="intel_iommu=igfx_off"
4242
export CONFIG_BOOT_KERNEL_REMOVE="intel_iommu=on intel_iommu=igfx_off"
4343

44+
export CONFIG_GPG_DEFAULT_ALGO=p256
45+
4446
#TPM2 requirements
4547
export CONFIG_TPM2_TOOLS=y
4648
export CONFIG_PRIMARY_KEY_TYPE=ecc

boards/nitropad-nv41/nitropad-nv41.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export CONFIG_BOOTSCRIPT=/bin/gui-init
4141
export CONFIG_BOOT_KERNEL_ADD="intel_iommu=igfx_off"
4242
export CONFIG_BOOT_KERNEL_REMOVE="intel_iommu=on intel_iommu=igfx_off"
4343

44+
export CONFIG_GPG_DEFAULT_ALGO=p256
45+
4446
# TPM2 requirementspick
4547
export CONFIG_TPM2_TOOLS=y
4648
export CONFIG_PRIMARY_KEY_TYPE=ecc

initrd/bin/oem-factory-reset

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,52 @@ gpg_key_reset()
101101
whiptail_error_die "GPG Key forcesig toggle on failed!\n\n$ERROR"
102102
fi
103103
fi
104-
# Set RSA key length
105-
{
106-
echo admin
107-
echo key-attr
108-
echo 1 # RSA
109-
echo ${RSA_KEY_LENGTH} #Signing key size set to RSA_KEY_LENGTH
110-
echo ${ADMIN_PIN_DEF}
111-
echo 1 # RSA
112-
echo ${RSA_KEY_LENGTH} #Encryption key size set to RSA_KEY_LENGTH
113-
echo ${ADMIN_PIN_DEF}
114-
echo 1 # RSA
115-
echo ${RSA_KEY_LENGTH} #Authentication key size set to RSA_KEY_LENGTH
116-
echo ${ADMIN_PIN_DEF}
117-
} | gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback --card-edit \
118-
> /tmp/gpg_card_edit_output 2>&1
119-
if [ $? -ne 0 ]; then
120-
ERROR=`cat /tmp/gpg_card_edit_output`
121-
whiptail_error_die "Setting key attributed to RSA ${RSA_KEY_LENGTH} bits in USB security dongle failed."
104+
105+
# use p256 for key generation if requested
106+
if [ "$CONFIG_GPG_DEFAULT_ALGO" = "p256" ];then
107+
108+
{
109+
echo admin
110+
echo key-attr
111+
echo 2 # ECC
112+
echo 3 # P-256
113+
echo ${ADMIN_PIN_DEF}
114+
echo 2 # ECC
115+
echo 3 # P-256
116+
echo ${ADMIN_PIN_DEF}
117+
echo 2 # ECC
118+
echo 3 # P-256
119+
echo ${ADMIN_PIN_DEF}
120+
} | gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback --card-edit --expert \
121+
> /tmp/gpg_card_edit_output 2>&1
122+
if [ $? -ne 0 ]; then
123+
ERROR=`cat /tmp/gpg_card_edit_output`
124+
whiptail_error_die "Setting key to NIST-P256 in USB security dongle failed."
125+
fi
126+
127+
# fallback to RSA key generation by default
128+
else
129+
130+
# Set RSA key length
131+
{
132+
echo admin
133+
echo key-attr
134+
echo 1 # RSA
135+
echo ${RSA_KEY_LENGTH} #Signing key size set to RSA_KEY_LENGTH
136+
echo ${ADMIN_PIN_DEF}
137+
echo 1 # RSA
138+
echo ${RSA_KEY_LENGTH} #Encryption key size set to RSA_KEY_LENGTH
139+
echo ${ADMIN_PIN_DEF}
140+
echo 1 # RSA
141+
echo ${RSA_KEY_LENGTH} #Authentication key size set to RSA_KEY_LENGTH
142+
echo ${ADMIN_PIN_DEF}
143+
} | gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback --card-edit \
144+
> /tmp/gpg_card_edit_output 2>&1
145+
if [ $? -ne 0 ]; then
146+
ERROR=`cat /tmp/gpg_card_edit_output`
147+
whiptail_error_die "Setting key attributed to RSA ${RSA_KEY_LENGTH} bits in USB security dongle failed."
148+
fi
149+
122150
fi
123151
# Generate OEM GPG keys
124152
{

0 commit comments

Comments
 (0)