YOGYUI

Let's Encrypt(certbot) - bad marshal data 오류 해결 방법 본문

홈네트워크(IoT)/일반

Let's Encrypt(certbot) - bad marshal data 오류 해결 방법

요겨 2024. 9. 19. 00:27
반응형

Resolving 'bad marshal data' error on certbot (Let's Encrypt)

1. 문제상황

라즈베리파이4에서 구글홈 연동을 위해 사용중인 무료 SSL 인증서 발급 서비스인 Let's Encrypt의 CLI 툴인 certbot을 사용하다보면 간혹 아래와 같은 오류메시지를 마주치게 될 때가 있다

오류 사항: 'bad marshal data (unknown type code)'

2. 원인

bad marshal data는 certbot 자체의 문제가 아니라 certbot이 사용하는 언어인 python의 문제다

- certbot에서 발생하는 Full error log는 아래와 같다


2024-09-18 22:12:09,133:WARNING:certbot.renewal:Attempting to renew cert (yogyui.duckdns.org) from /etc/letsencrypt/renewal/yogyui.duckdns.org.conf produced an unexpected error: bad marshal data (unknown type code). Skipping.
2024-09-18 22:12:09,156:DEBUG:certbot.renewal:Traceback was:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/certbot/renewal.py", line 465, in handle_renewal_request
    main.renew_cert(lineage_config, plugins, renewal_candidate)
  File "/usr/lib/python3/dist-packages/certbot/main.py", line 1191, in renew_cert
    le_client = _init_le_client(config, auth, installer)
  File "/usr/lib/python3/dist-packages/certbot/main.py", line 605, in _init_le_client
    acc, acme = _determine_account(config)
  File "/usr/lib/python3/dist-packages/certbot/main.py", line 509, in _determine_account
    acc = account_storage.load(config.account)
  File "/usr/lib/python3/dist-packages/certbot/account.py", line 246, in load
    return self._load_for_server_path(account_id, self.config.server_path)
  File "/usr/lib/python3/dist-packages/certbot/account.py", line 232, in _load_for_server_path
    key = jose.JWK.json_loads(key_file.read())
  File "/usr/lib/python3/dist-packages/josepy/interfaces.py", line 179, in json_loads
    return cls.from_json(loads)
  File "/usr/lib/python3/dist-packages/josepy/json_util.py", line 481, in from_json
    return type_cls(**type_cls.fields_from_json(jobj))
  File "/usr/lib/python3/dist-packages/josepy/jwk.py", line 251, in fields_from_json
    default_backend())
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/backends/__init__.py", line 15, in default_backend
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 46, in <module>
    from cryptography.hazmat.backends.openssl.encode_asn1 import (
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 857, in get_code
  File "<frozen importlib._bootstrap_external>", line 525, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

2024-09-18 22:12:09,158:ERROR:certbot.renewal:All renewal attempts failed. The following certs could not be renewed:
2024-09-18 22:12:09,159:ERROR:certbot.renewal:  /etc/letsencrypt/live/yogyui.duckdns.org/fullchain.pem (failure)
2024-09-18 22:12:09,163:DEBUG:certbot.log:Exiting abnormally:
Traceback (most recent call last):
  File "/usr/bin/certbot", line 11, in <module>
    load_entry_point('certbot==0.31.0', 'console_scripts', 'certbot')()
  File "/usr/lib/python3/dist-packages/certbot/main.py", line 1365, in main
    return config.func(config, plugins)
  File "/usr/lib/python3/dist-packages/certbot/main.py", line 1272, in renew
    renewal.handle_renewal_request(config)
  File "/usr/lib/python3/dist-packages/certbot/renewal.py", line 490, in handle_renewal_request
    len(renew_failures), len(parse_failures)))
certbot.errors.Error: 1 renew failure(s), 0 parse failure(s)


certbot이 사용하는 백엔드(backend) SSL 패키지는 cryptography의 hazmat/backend/opensssl인데, 해당 스크립트의 byte-code로 컴파일된 pyc파일이 certbot이 정상 작동할 때와는 다르게 컴파일되어 오류가 발생하는 것으로 추정된다 (SSL 관련 파이썬 개발 작업을 한 적이 있었는데, 이 때 뭔가 나도 모르게 sudo upgrade 등의 작업을 하면서 꼬였나보다...)

3. 해결책

라즈베리파이의 경우 /usr 디렉터리 내부에 여러 바이너리 파일, 라이브러리 파일들이 모여있는데, 여기 존재하는 .pyc 파일을 아래 명령어를 사용해 전부 삭제하면 된다

$ sudo find /usr -name '*.pyc' -delete

 

전부 삭제 후 certbot CLI를 다시 실행하면 다시 pyc파일을 컴파일하기 때문에 정상 작동하게 된다

 

결론: 'bad marshal data' 오류가 발생하면 .pyc 파일을 삭제해버리도록 하자


[참고]

https://stackoverflow.com/questions/30861493/how-to-fix-python-valueerrorbad-marshal-data

반응형