32
32
from click_option_group import RequiredMutuallyExclusiveOptionGroup , optgroup
33
33
from cryptography import x509
34
34
from cryptography .hazmat .primitives .asymmetric import ec
35
+ from cryptography .x509 .oid import NameOID
35
36
36
37
# Supported log levels, mapping string values required for argument
37
38
# parsing into logging constants
@@ -64,13 +65,14 @@ def extract_single_integer_attribute(subject, oid):
64
65
return None
65
66
66
67
67
- def extract_single_attribute_from_cn (cn , marker ):
68
+ def extract_fallback_tag_from_common_name (cn , marker ):
68
69
val_len = 4
69
70
start_idx = cn .find (marker )
70
71
71
72
if start_idx != - 1 :
72
73
val_start_idx = start_idx + len (marker )
73
- return int (cn [val_start_idx :val_start_idx + val_len ], 16 )
74
+ val = cn [val_start_idx :val_start_idx + val_len ]
75
+ return int (val , 16 ) if len (val ) == 4 else None
74
76
75
77
return None
76
78
@@ -82,9 +84,9 @@ def parse_vid_pid_from_distinguished_name(distinguished_name):
82
84
83
85
# Fallback method to get the VID/PID, encoded in CN as "Mvid:FFFF Mpid:1234"
84
86
if vid is None and pid is None :
85
- cn = distinguished_name .get_attributes_for_oid (x509 .ObjectIdentifier ("2.5.4.3" ))[0 ].value
86
- vid = extract_single_attribute_from_cn (cn , 'Mvid:' )
87
- pid = extract_single_attribute_from_cn (cn , 'Mpid:' )
87
+ cn = distinguished_name .get_attributes_for_oid (x509 .ObjectIdentifier (NameOID . COMMON_NAME ))[0 ].value
88
+ vid = extract_fallback_tag_from_common_name (cn , 'Mvid:' )
89
+ pid = extract_fallback_tag_from_common_name (cn , 'Mpid:' )
88
90
89
91
return vid , pid
90
92
0 commit comments