summaryrefslogtreecommitdiffstats
path: root/meta-signing-key
diff options
context:
space:
mode:
authorLans Zhang <jia.zhang@windriver.com>2017-07-03 15:51:30 +0800
committerLans Zhang <jia.zhang@windriver.com>2017-07-03 15:51:30 +0800
commit70e33652e55da13d6d5ec1327fef71ea0b0b3784 (patch)
tree21cd6df51fc71efdd62e56500cb3df8dc990adff /meta-signing-key
parent353a003f1bd422ea71ed7009e2d7ed04476bc6e2 (diff)
downloadmeta-secure-core-70e33652e55da13d6d5ec1327fef71ea0b0b3784.tar.gz
user-key-store: clean up the code style
Signed-off-by: Lans Zhang <jia.zhang@windriver.com>
Diffstat (limited to 'meta-signing-key')
-rw-r--r--meta-signing-key/classes/user-key-store.bbclass96
1 files changed, 16 insertions, 80 deletions
diff --git a/meta-signing-key/classes/user-key-store.bbclass b/meta-signing-key/classes/user-key-store.bbclass
index da99064..08a77e3 100644
--- a/meta-signing-key/classes/user-key-store.bbclass
+++ b/meta-signing-key/classes/user-key-store.bbclass
@@ -63,8 +63,8 @@ def check_uefi_sb_user_keys(d):
63 vprint("%s.key is unavailable" % _, d) 63 vprint("%s.key is unavailable" % _, d)
64 return False 64 return False
65 65
66 if not os.path.exists(dir + _ + '.pem'): 66 if not os.path.exists(dir + _ + '.crt'):
67 vprint("%s.pem is unavailable" % _, d) 67 vprint("%s.crt is unavailable" % _, d)
68 return False 68 return False
69 69
70def uefi_sb_sign(input, output, d): 70def uefi_sb_sign(input, output, d):
@@ -72,7 +72,7 @@ def uefi_sb_sign(input, output, d):
72 return 72 return
73 73
74 _ = uefi_sb_keys_dir(d) 74 _ = uefi_sb_keys_dir(d)
75 sign_efi_image(_ + 'DB.key', _ + 'DB.pem', input, output, d) 75 sign_efi_image(_ + 'DB.key', _ + 'DB.crt', input, output, d)
76 76
77def mok_sb_keys_dir(d): 77def mok_sb_keys_dir(d):
78 if d.getVar('MOK_SB', True) != '1': 78 if d.getVar('MOK_SB', True) != '1':
@@ -87,11 +87,11 @@ def sb_sign(input, output, d):
87 87
88 if uks_signing_model(d) in ('sample', 'user'): 88 if uks_signing_model(d) in ('sample', 'user'):
89 # Deal with MOK_SB firstly, as MOK_SB implies UEFI_SB == 1. 89 # Deal with MOK_SB firstly, as MOK_SB implies UEFI_SB == 1.
90 # On this scenario, bootloader is verified by shim_cert.pem 90 # On this scenario, bootloader is verified by shim_cert.crt
91 if d.getVar('MOK_SB', True) == '1': 91 if d.getVar('MOK_SB', True) == '1':
92 mok_sb_sign(input, output, d) 92 mok_sb_sign(input, output, d)
93 # UEFI_SB is defined, but MOK_SB is not defined 93 # UEFI_SB is defined, but MOK_SB is not defined
94 # On this scenario, shim is not used, and DB.pem is used to 94 # On this scenario, shim is not used, and DB.crt is used to
95 # verify bootloader directly. 95 # verify bootloader directly.
96 else: 96 else:
97 uefi_sb_sign(input, output, d) 97 uefi_sb_sign(input, output, d)
@@ -106,8 +106,8 @@ def check_mok_sb_user_keys(d):
106 vprint("%s.key is unavailable" % _, d) 106 vprint("%s.key is unavailable" % _, d)
107 return False 107 return False
108 108
109 if not os.path.exists(dir + _ + '.pem'): 109 if not os.path.exists(dir + _ + '.crt'):
110 vprint("%s.pem is unavailable" % _, d) 110 vprint("%s.crt is unavailable" % _, d)
111 return False 111 return False
112 112
113def mok_sb_sign(input, output, d): 113def mok_sb_sign(input, output, d):
@@ -115,7 +115,7 @@ def mok_sb_sign(input, output, d):
115 return 115 return
116 116
117 _ = mok_sb_keys_dir(d) 117 _ = mok_sb_keys_dir(d)
118 sign_efi_image(_ + 'vendor_cert.key', _ + 'vendor_cert.pem', input, output, d) 118 sign_efi_image(_ + 'vendor_cert.key', _ + 'vendor_cert.crt', input, output, d)
119 119
120def sel_sign(key, cert, input, d): 120def sel_sign(key, cert, input, d):
121 import bb.process 121 import bb.process
@@ -137,11 +137,11 @@ def uks_sel_sign(input, d):
137 if d.getVar('MOK_SB', True) == '1': 137 if d.getVar('MOK_SB', True) == '1':
138 _ = mok_sb_keys_dir(d) 138 _ = mok_sb_keys_dir(d)
139 key = _ + 'vendor_cert.key' 139 key = _ + 'vendor_cert.key'
140 cert = _ + 'vendor_cert.pem' 140 cert = _ + 'vendor_cert.crt'
141 else: 141 else:
142 _ = uefi_sb_keys_dir(d) 142 _ = uefi_sb_keys_dir(d)
143 key = _ + 'DB.key' 143 key = _ + 'DB.key'
144 cert = _ + 'DB.pem' 144 cert = _ + 'DB.crt'
145 145
146 sel_sign(key, cert, input, d) 146 sel_sign(key, cert, input, d)
147 147
@@ -150,7 +150,7 @@ def check_ima_user_keys(d):
150 150
151 for _ in ('key', 'der'): 151 for _ in ('key', 'der'):
152 if not os.path.exists(dir + 'x509_ima.' + _): 152 if not os.path.exists(dir + 'x509_ima.' + _):
153 vprint("%s.pem is unavailable" % _, d) 153 vprint("%s.crt is unavailable" % _, d)
154 return False 154 return False
155 155
156def check_system_trusted_keys(d): 156def check_system_trusted_keys(d):
@@ -161,8 +161,8 @@ def check_system_trusted_keys(d):
161 vprint("%s.key is unavailable" % _, d) 161 vprint("%s.key is unavailable" % _, d)
162 return False 162 return False
163 163
164 if not os.path.exists(dir + _ + '.pem'): 164 if not os.path.exists(dir + _ + '.der'):
165 vprint("%s.pem is unavailable" % _, d) 165 vprint("%s.der is unavailable" % _, d)
166 return False 166 return False
167 167
168# Convert the PEM to DER format. 168# Convert the PEM to DER format.
@@ -185,10 +185,10 @@ __pem2esl() {
185 185
186# Blacklist the sample DB, shim_cert, vendor_cert by default. 186# Blacklist the sample DB, shim_cert, vendor_cert by default.
187__create_default_mok_sb_blacklist() { 187__create_default_mok_sb_blacklist() {
188 __pem2esl "${SAMPLE_MOK_SB_KEYS_DIR}/shim_cert.pem" \ 188 __pem2esl "${SAMPLE_MOK_SB_KEYS_DIR}/shim_cert.crt" \
189 "${TMPDIR}/sample_shim_cert.esl" 189 "${TMPDIR}/sample_shim_cert.esl"
190 190
191 __pem2esl "${SAMPLE_MOK_SB_KEYS_DIR}/vendor_cert.pem" \ 191 __pem2esl "${SAMPLE_MOK_SB_KEYS_DIR}/vendor_cert.crt" \
192 "${TMPDIR}/sample_vendor_cert.esl" 192 "${TMPDIR}/sample_vendor_cert.esl"
193 193
194 # Cascade the sample DB, shim_cert and vendor_cert to 194 # Cascade the sample DB, shim_cert and vendor_cert to
@@ -198,7 +198,7 @@ __create_default_mok_sb_blacklist() {
198} 198}
199 199
200__create_default_uefi_sb_blacklist() { 200__create_default_uefi_sb_blacklist() {
201 __pem2esl "${SAMPLE_UEFI_SB_KEYS_DIR}/DB.pem" \ 201 __pem2esl "${SAMPLE_UEFI_SB_KEYS_DIR}/DB.crt" \
202 "${TMPDIR}/sample_DB.esl" 202 "${TMPDIR}/sample_DB.esl"
203 203
204 cat "${TMPDIR}/sample_DB.esl" > "${TMPDIR}/blacklist.esl" 204 cat "${TMPDIR}/sample_DB.esl" > "${TMPDIR}/blacklist.esl"
@@ -284,70 +284,6 @@ def create_uefi_dbx(d):
284 284
285 return dst 285 return dst
286 286
287create_uefi_sb_user_keys() {
288 local deploy_dir="${DEPLOY_DIR_IMAGE}/user-keys/uefi_sb_keys"
289
290 install -d "$deploy_dir"
291
292 # PK is self-signed.
293 "${STAGING_BINDIR_NATIVE}/openssl" req -new -x509 -newkey rsa:2048 \
294 -sha256 -nodes -days 3650 \
295 -subj "/CN=PK Certificate for $USER@`hostname`/" \
296 -keyout "$deploy_dir/PK.key" \
297 -out "$deploy_dir/PK.pem"
298
299 # KEK is signed by PK.
300 "${STAGING_BINDIR_NATIVE}/openssl" req -new -newkey rsa:2048 \
301 -sha256 -nodes \
302 -subj "/CN=KEK Certificate for $USER@`hostname`" \
303 -keyout "$deploy_dir/KEK.key" \
304 -out "${TMPDIR}/KEK.csr"
305
306 "${STAGING_BINDIR_NATIVE}/openssl" x509 -req -in "${TMPDIR}/KEK.csr" \
307 -CA "$deploy_dir/PK.pem" -CAkey "$deploy_dir/PK.key" \
308 -set_serial 1 -days 3650 -out "$deploy_dir/KEK.pem"
309
310 # DB is signed by KEK.
311 "${STAGING_BINDIR_NATIVE}/openssl" req -new -newkey rsa:2048 \
312 -sha256 -nodes \
313 -subj "/CN=DB Certificate for $USER@`hostname`" \
314 -keyout "$deploy_dir/DB.key" \
315 -out "${TMPDIR}/DB.csr"
316
317 "${STAGING_BINDIR_NATIVE}/openssl" x509 -req -in "${TMPDIR}/DB.csr" \
318 -CA "$deploy_dir/KEK.pem" -CAkey "$deploy_dir/KEK.key" \
319 -set_serial 1 -days 3650 -out "$deploy_dir/DB.pem"
320}
321
322create_mok_sb_user_keys() {
323 local deploy_dir="${DEPLOY_DIR_IMAGE}/user-keys/mok_sb_keys"
324
325 install -d "$deploy_dir"
326
327 "${STAGING_BINDIR_NATIVE}/openssl" req -new -x509 -newkey rsa:2048 \
328 -sha256 -nodes -days 3650 -subj "/CN=Shim Certificate for $USER@`hostname`/" \
329 -keyout "$deploy_dir/shim_cert.key" -out "$deploy_dir/shim_cert.pem"
330
331 "${STAGING_BINDIR_NATIVE}/openssl" req -new -x509 -newkey rsa:2048 \
332 -sha256 -nodes -days 3650 -subj "/CN=Vendor Certificate for $USER@`hostname`/" \
333 -keyout "$deploy_dir/vendor_cert.key" -out "$deploy_dir/vendor_cert.pem" \
334}
335
336create_ima_user_keys() {
337 local deploy_dir="${DEPLOY_DIR_IMAGE}/user-keys/ima_keys"
338
339 install -d "$deploy_dir"
340
341 "${STAGING_BINDIR_NATIVE}/openssl" genrsa -out "$deploy_dir/ima_privkey.pem" 2048
342
343 "${STAGING_BINDIR_NATIVE}/openssl" rsa -in "$deploy_dir/ima_privkey.pem" -pubout \
344 -out "$deploy_dir/ima_pubkey.pem"
345}
346
347def create_user_keys(name, d):
348 vprint('Creating the user keys for %s ...' % name, d)
349 bb.build.exec_func('create_' + name.lower() + '_user_keys', d)
350
351deploy_uefi_sb_keys() { 287deploy_uefi_sb_keys() {
352 local deploy_dir="${DEPLOY_KEYS_DIR}/uefi_sb_keys" 288 local deploy_dir="${DEPLOY_KEYS_DIR}/uefi_sb_keys"
353 289