Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/attcertissuer-tagging-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Jan 27, 2022
2 parents f8214f9 + c6fe6cd commit f9133f0
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -173,10 +173,16 @@ jobs:
run: python2 run.py deps
- name: Run test suite (2.7)
run: python2 run.py ci-driver
- name: Cleanup deps (2.7)
if: always()
run: python2 run.py ci-cleanup
- name: Install dependencies (3.8)
run: python3 run.py deps
- name: Run test suite (3.8)
run: python3 run.py ci-driver
- name: Cleanup deps (3.8)
if: always()
run: python3 run.py ci-cleanup

build-arm64:
name: Python 2.7/3.8 on arm64
Expand All @@ -187,7 +193,13 @@ jobs:
run: python2 run.py deps
- name: Run test suite (2.7)
run: python2 run.py ci-driver
- name: Cleanup deps (2.7)
if: always()
run: python2 run.py ci-cleanup
- name: Install dependencies (3.8)
run: python3 run.py deps
- name: Run test suite (3.8)
run: python3 run.py ci-driver
- name: Cleanup deps (3.8)
if: always()
run: python3 run.py ci-cleanup
10 changes: 5 additions & 5 deletions asn1crypto/cms.py
Expand Up @@ -315,7 +315,7 @@ class SetOfSvceAuthInfo(SetOf):
class RoleSyntax(Sequence):
_fields = [
('role_authority', GeneralNames, {'implicit': 0, 'optional': True}),
('role_name', GeneralName, {'implicit': 1}),
('role_name', GeneralName, {'explicit': 1}),
]


Expand All @@ -337,7 +337,7 @@ class ClassList(BitString):
class SecurityCategory(Sequence):
_fields = [
('type', ObjectIdentifier, {'implicit': 0}),
('value', Any, {'implicit': 1}),
('value', Any, {'explicit': 1}),
]


Expand All @@ -347,9 +347,9 @@ class SetOfSecurityCategory(SetOf):

class Clearance(Sequence):
_fields = [
('policy_id', ObjectIdentifier, {'implicit': 0}),
('class_list', ClassList, {'implicit': 1, 'default': 'unclassified'}),
('security_categories', SetOfSecurityCategory, {'implicit': 2, 'optional': True}),
('policy_id', ObjectIdentifier),
('class_list', ClassList, {'default': set(['unclassified'])}),
('security_categories', SetOfSecurityCategory, {'optional': True}),
]


Expand Down
28 changes: 28 additions & 0 deletions dev/ci-cleanup.py
@@ -0,0 +1,28 @@
# coding: utf-8
from __future__ import unicode_literals, division, absolute_import, print_function

import os
import shutil

from . import build_root, other_packages


def run():
"""
Cleans up CI dependencies - used for persistent GitHub Actions
Runners since they don't clean themselves up.
"""

print("Removing ci dependencies")
deps_dir = os.path.join(build_root, 'modularcrypto-deps')
if os.path.exists(deps_dir):
shutil.rmtree(deps_dir, ignore_errors=True)

print("Removing modularcrypto packages")
for other_package in other_packages:
pkg_dir = os.path.join(build_root, other_package)
if os.path.exists(pkg_dir):
shutil.rmtree(pkg_dir, ignore_errors=True)
print()

return True
34 changes: 34 additions & 0 deletions tests/test_cms.py
Expand Up @@ -21,6 +21,30 @@
fixtures_dir = os.path.join(tests_root, 'fixtures')


class ClearanceTests(unittest.TestCase):

def test_clearance_decode_bad_tagging(self):
rfc_3281_wrong_tagging = b'\x30\x08\x80\x02\x88\x37\x81\x02\x02\x4c'
# This test documents the fact that we can't deal with the "wrong"
# version of Clearance in RFC 3281
self.assertRaises(
ValueError,
lambda: cms.Clearance.load(rfc_3281_wrong_tagging).native
)

def test_clearance_decode_correct_tagging(self):
correct_tagging = b'\x30\x08\x06\x02\x88\x37\x03\x02\x02\x4c'
clearance_obj = cms.Clearance.load(correct_tagging)
self.assertEqual(
util.OrderedDict([
('policy_id', '2.999'),
('class_list', set(['secret', 'top_secret', 'unclassified'])),
('security_categories', None)
]),
clearance_obj.native
)


class CMSTests(unittest.TestCase):

def test_create_content_info_data(self):
Expand Down Expand Up @@ -913,3 +937,13 @@ def test_parse_attribute_cert(self):
ac_info = ac_parsed['ac_info']
self.assertIsInstance(ac_info['issuer'].chosen, cms.V2Form)
self.assertEqual(1, len(ac_info['issuer'].chosen['issuer_name']))

def test_create_role_syntax(self):
rs = cms.RoleSyntax({'role_name': {'rfc822_name': 'test@example.com'}})
self.assertEqual(
util.OrderedDict([
('role_authority', None),
('role_name', 'test@example.com')
]),
rs.native
)

0 comments on commit f9133f0

Please sign in to comment.