Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC 7468 allows a larger character set in PEM label #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions asn1crypto/pem.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ def armor(type_name, der_bytes, headers=None):
return output.getvalue()


# RFC 7468#page-5
LABEL_CHARS = '[!-,.-~]' # 0x21-0x2C, 0x2E-0x7E
LABEL_PAT = re.compile(f'^(?:---- |-----)BEGIN ({LABEL_CHARS}([- ]?{LABEL_CHARS})*)?(?: ----|-----)'.encode('ascii'))


def _unarmor(pem_bytes):
"""
Convert a PEM-encoded byte string into one or more DER-encoded byte strings
Expand Down Expand Up @@ -150,8 +155,9 @@ def _unarmor(pem_bytes):

if state == "trash":
# Look for a starting line since some CA cert bundle show the cert
# into in a parsed format above each PEM block
type_name_match = re.match(b'^(?:---- |-----)BEGIN ([A-Z0-9 ]+)(?: ----|-----)', line)
# info in a parsed format above each PEM block

type_name_match = LABEL_PAT.match(line)
if not type_name_match:
continue
object_type = type_name_match.group(1).decode('ascii')
Expand Down
Loading