@@ -233,6 +233,13 @@ def _create_bootstrap_configs(self, config_root: pathlib.Path):
233233 def _load_key (self , key : str , dest : pathlib .Path , name : str ):
234234 """Validate mirror keys, relocate to key_store, and update mirror config with new key paths."""
235235
236+ ASCII_PGP_HEADERS = (
237+ b"-----BEGIN PGP PRIVATE KEY BLOCK-----" ,
238+ b"-----BEGIN PGP PUBLIC KEY BLOCK-----" ,
239+ b"-----BEGIN PGP MESSAGE-----" ,
240+ b"-----BEGIN PGP SIGNATURE-----" ,
241+ )
242+
236243 # key will be saved under key_store/mirror_name.[pub/priv].gpg
237244
238245 # if path, check if abs path, if not, append sys config path in front and check again
@@ -256,20 +263,29 @@ def _load_key(self, key: str, dest: pathlib.Path, name: str):
256263 f"Check the key listed in mirrors.yaml in system config."
257264 )
258265
259- # private keys will evaluate as "application/octet-stream"
260- file_type = magic .from_buffer (binary_key , mime = True )
261- if file_type not in ("application/x-gnupg-keyring" , "application/pgp-keys" , "application/octet-stream" ):
266+ file_type = magic .from_buffer (binary_key )
267+
268+ if ((file_type in "application/x-gnupg-keyring" , "application/pgp-keys" , "application/octet-stream" ) or
269+ (binary_key .startswith (ASCII_PGP_HEADERS ))):
270+
271+ # copy key to new destination in key store
272+ with open (dest , "wb" ) as writer :
273+ writer .write (binary_key )
274+
275+ self ._keys .append (dest )
276+
277+ else :
262278 raise MirrorError (
263279 f"Key for mirror { name } is not a valid GPG key. \n "
264280 f"The file (or base64) was readable, but the data itself was not a PGP key.\n "
265281 f"Check the key listed in mirrors.yaml in system config."
266282 )
267283
268- # copy key to new destination in key store
269- with open (dest , "wb" ) as writer :
270- writer .write (binary_key )
284+ # # copy key to new destination in key store
285+ # with open(dest, "wb") as writer:
286+ # writer.write(binary_key)
271287
272- self ._keys .append (dest )
288+ # self._keys.append(dest)
273289
274290 def _key_setup (self , key_store : pathlib .Path ):
275291 """Iterate through mirror keys and load + relocate each one to key_store"""
0 commit comments