58
58
class Manifest(object):
59
59
def __init__(self, profile_name):
60
60
self.security = dict()
61
self.security['profiles'] = dict()
61
62
self.profile_name = profile_name
62
self.security[self.profile_name] = dict()
63
self.security['profiles'][self.profile_name] = dict()
64
65
def add_policygroups(self, policy_list):
65
self.security[self.profile_name]['policy_groups'] = policy_list.split(",")
66
self.security['profiles'][self.profile_name]['policy_groups'] = policy_list.split(",")
67
68
def add_author(self, author):
68
self.security[self.profile_name]['author'] = author
69
self.security['profiles'][self.profile_name]['author'] = author
70
71
def add_copyright(self, copyright):
71
self.security[self.profile_name]['copyright'] = copyright
72
self.security['profiles'][self.profile_name]['copyright'] = copyright
73
74
def add_comment(self, comment):
74
self.security[self.profile_name]['comment'] = comment
75
self.security['profiles'][self.profile_name]['comment'] = comment
76
77
def add_binary(self, binary):
77
self.security[self.profile_name]['binary'] = binary
78
self.security['profiles'][self.profile_name]['binary'] = binary
79
80
def add_template(self, template):
80
self.security[self.profile_name]['template'] = template
81
self.security['profiles'][self.profile_name]['template'] = template
82
83
def add_template_variable(self, name, value):
83
if not 'template_variables' in self.security[self.profile_name]:
84
self.security[self.profile_name]['template_variables'] = dict()
84
if not 'template_variables' in self.security['profiles'][self.profile_name]:
85
self.security['profiles'][self.profile_name]['template_variables'] = dict()
86
self.security[self.profile_name]['template_variables'][name] = value
87
self.security['profiles'][self.profile_name]['template_variables'][name] = value
88
89
def emit_json(self, use_security_prefix=True):
1403
1404
# this should come from manpage
1406
"com.example.foo": {
1411
"author": "Your Name",
1412
"binary": "/opt/foo/**",
1413
"comment": "Unstructured single-line comment",
1414
"copyright": "Unstructured single-line copyright statement",
1415
"name": "My Foo App",
1420
"policy_vendor": "somevendor",
1421
"policy_version": 1.0,
1426
"template": "user-application",
1427
"template_variables": {
1408
"com.example.foo": {
1413
"author": "Your Name",
1414
"binary": "/opt/foo/**",
1415
"comment": "Unstructured single-line comment",
1416
"copyright": "Unstructured single-line copyright statement",
1417
"name": "My Foo App",
1422
"policy_vendor": "somevendor",
1423
"policy_version": 1.0,
1428
"template": "user-application",
1429
"template_variables": {
1461
"com.ubuntu.developer.myusername.MyCoolApp": {
1462
"name": "MyCoolApp",
1467
"policy_vendor": "ubuntu",
1468
"policy_version": 1.0,
1469
"template": "user-application",
1470
"template_variables": {
1471
"APPNAME": "MyCoolApp"
1465
"com.ubuntu.developer.myusername.MyCoolApp": {
1466
"name": "MyCoolApp",
1471
"policy_vendor": "ubuntu",
1472
"policy_version": 1.0,
1473
"template": "user-application",
1474
"template_variables": {
1475
"APPNAME": "MyCoolApp",
1476
"APPVERSION": "0.1.2"
1494
1500
# this should come from manpage
1497
"com.ubuntu.developer.myusername.MyCoolApp": {
1498
"name": "MyCoolApp",
1503
"policy_vendor": "ubuntu",
1504
"template": "user-application",
1505
"template_variables": {
1506
"APPNAME": "MyCoolApp"
1504
"com.ubuntu.developer.myusername.MyCoolApp": {
1509
"policy_vendor": "ubuntu",
1510
"template": "user-application",
1511
"template_variables": {
1512
"APPNAME": "MyCoolApp",
1513
"APPVERSION": "0.1.2"
1524
1532
# this should come from manpage
1527
"com.ubuntu.developer.myusername.MyCoolApp": {
1528
"name": "MyCoolApp",
1533
"policy_version": 1.0,
1534
"template": "user-application",
1535
"template_variables": {
1536
"APPNAME": "MyCoolApp"
1536
"com.ubuntu.developer.myusername.MyCoolApp": {
1541
"policy_version": 1.0,
1542
"template": "user-application",
1543
"template_variables": {
1544
"APPNAME": "MyCoolApp",
1545
"APPVERSION": "0.1.2"
1553
1563
'''Test parse_manifest_multiple'''
1556
"com.example.foo": {
1561
"author": "Your Name",
1562
"binary": "/opt/foo/**",
1563
"comment": "Unstructured single-line comment",
1564
"copyright": "Unstructured single-line copyright statement",
1565
"name": "My Foo App",
1574
"template": "user-application",
1575
"template_variables": {
1567
"com.example.foo": {
1572
"author": "Your Name",
1573
"binary": "/opt/foo/**",
1574
"comment": "Unstructured single-line comment",
1575
"copyright": "Unstructured single-line copyright statement",
1576
"name": "My Foo App",
1585
"template": "user-application",
1586
"template_variables": {
1585
"com.ubuntu.developer.myusername.MyCoolApp": {
1586
"name": "MyCoolApp",
1590
"policy_vendor": "ubuntu",
1591
"policy_version": 1.0,
1592
"template": "user-application",
1593
"template_variables": {
1594
"APPNAME": "MyCoolApp"
1596
"com.ubuntu.developer.myusername.MyCoolApp": {
1600
"policy_vendor": "ubuntu",
1601
"policy_version": 1.0,
1602
"template": "user-application",
1603
"template_variables": {
1604
"APPNAME": "MyCoolApp",
1605
"APPVERSION": "0.1.2"
1633
1645
'''Test verify_manifest (full)'''
1636
"com.example.foo": {
1640
"author": "Your Name",
1641
"binary": "/opt/com.example/foo/**",
1642
"comment": "some free-form single-line comment",
1643
"copyright": "Unstructured single-line copyright statement",
1649
"template": "user-application",
1650
"template_variables": {
1652
"OK2": "com.example.foo"
1649
"com.example.foo": {
1653
"author": "Your Name",
1654
"binary": "/opt/com.example/foo/**",
1655
"comment": "some free-form single-line comment",
1656
"copyright": "Unstructured single-line copyright statement",
1662
"template": "user-application",
1663
"template_variables": {
1665
"OK2": "com.example.foo"
1657
1671
self._verify_manifest(m, expected=True)
1660
1674
'''Test verify_manifest (full bad)'''
1663
"/com.example.foo": {
1668
"author": "Your Name",
1669
"binary": "/usr/foo/**",
1670
"comment": "some free-form single-line comment",
1671
"copyright": "Unstructured single-line copyright statement",
1681
"template": "user-application",
1682
"template_variables": {
1691
"VAR9": "/tmp/../etc/passwd"
1678
"/com.example.foo": {
1683
"author": "Your Name",
1684
"binary": "/usr/foo/**",
1685
"comment": "some free-form single-line comment",
1686
"copyright": "Unstructured single-line copyright statement",
1696
"template": "user-application",
1697
"template_variables": {
1706
"VAR9": "/tmp/../etc/passwd"
1716
1734
'''Test verify_manifest (bad profile_name)'''
1720
"binary": "/opt/com.example/foo/**",
1721
"template": "user-application"
1739
"binary": "/opt/com.example/foo/**",
1740
"template": "user-application"
1730
"binary": "/opt/com.example/foo/**",
1731
"template": "user-application"
1751
"binary": "/opt/com.example/foo/**",
1752
"template": "user-application"
1738
1760
'''Test verify_manifest (profile_name)'''
1741
"com.example.foo": {
1742
"binary": "/opt/com.example/foo/**",
1743
"template": "user-application"
1764
"com.example.foo": {
1765
"binary": "/opt/com.example/foo/**",
1766
"template": "user-application"
1750
1774
'''Test verify_manifest (abstractions)'''
1753
"com.example.foo": {
1754
"binary": "/opt/com.example/foo/**",
1755
"template": "user-application",
1778
"com.example.foo": {
1779
"binary": "/opt/com.example/foo/**",
1780
"template": "user-application",
1765
1791
'''Test verify_manifest (bad abstractions)'''
1768
"com.example.foo": {
1769
"binary": "/opt/com.example/foo/**",
1770
"template": "user-application",
1795
"com.example.foo": {
1796
"binary": "/opt/com.example/foo/**",
1797
"template": "user-application",
1780
1808
'''Test verify_manifest (good template_var)'''
1783
"com.example.foo": {
1784
"binary": "/opt/com.example/something with spaces/**",
1785
"template": "user-application",
1786
"template_variables": {
1788
"OK2": "com.example.foo",
1789
"OK3": "something with spaces"
1812
"com.example.foo": {
1813
"binary": "/opt/com.example/something with spaces/**",
1814
"template": "user-application",
1815
"template_variables": {
1817
"OK2": "com.example.foo",
1818
"OK3": "something with spaces"
1870
"com.example.foo": {
1871
"binary": "/opt/com.example/foo/**",
1872
"template": "user-application",
1873
"template_variables": {
1903
"com.example.foo": {
1904
"binary": "/opt/com.example/foo/**",
1905
"template": "user-application",
1906
"template_variables": {
1894
1928
'''Test policy vendor via manifest (nonexistent)'''
1897
"com.example.foo": {
1898
"policy_vendor": "nonexistent",
1899
"policy_version": 1.0,
1900
"binary": "/opt/com.example/foo/**",
1901
"template": "user-application"
1932
"com.example.foo": {
1933
"policy_vendor": "nonexistent",
1934
"policy_version": 1.0,
1935
"binary": "/opt/com.example/foo/**",
1936
"template": "user-application"
1922
1958
policy_subdir = "%s/%s" % (policy_vendor, policy_version)
1925
"com.example.foo": {
1926
"policy_vendor": "%s",
1927
"policy_version": %s,
1928
"binary": "/opt/com.example/foo/**",
1929
"template": "user-application"
1962
"com.example.foo": {
1963
"policy_vendor": "%s",
1964
"policy_version": %s,
1965
"binary": "/opt/com.example/foo/**",
1966
"template": "user-application"
1932
1970
}''' % (policy_vendor, policy_version)