ACM: Put hash of XML policy into binary policy to tie them together

This patch extends the ACM binary policy format with an embedded hash
of the corresponding XML policy in order to tie them together. This
allows xend to determine whether it has the correct XML policy in its
repository and react appropriately if it does not have it.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
This commit is contained in:
Keir Fraser committed 2008-04-23 13:29:09 +01:00
1 parent 10ab43fd56
commit a7f2eeb898
5 files changed
+40 -4

No files matched your search

+24 -3
View File
@@ -17,6 +17,7 @@
#============================================================================
import os
import sha
import stat
import array
import struct
@@ -35,7 +36,7 @@ ACM_POLICIES_DIR = security.policy_dir_prefix + "/"
# Constants needed for generating a binary policy from its XML
# representation
ACM_POLICY_VERSION = 3 # Latest one
ACM_POLICY_VERSION = 4 # Latest one
ACM_CHWALL_VERSION = 1
ACM_STE_VERSION = 1
@@ -965,6 +966,10 @@ class ACMPolicy(XSPolicy):
return dom.toxml()
return None
def hash(self):
""" Calculate a SAH1 hash of the XML policy """
return sha.sha(self.toxml())
def save(self):
### Save the XML policy into a file ###
rc = -xsconstants.XSERR_FILE_ERROR
@@ -1403,7 +1408,7 @@ class ACMPolicy(XSPolicy):
ste_bin += "\x00"
#Write binary header:
headerformat="!iiiiiiiiii"
headerformat="!iiiiiiiiii20s"
totallen_bin = struct.calcsize(headerformat) + \
len(pr_bin) + len(chw_bin) + len(ste_bin)
polref_offset = struct.calcsize(headerformat)
@@ -1425,7 +1430,8 @@ class ACMPolicy(XSPolicy):
primpoloffset,
secpolcode,
secpoloffset,
major, minor)
major, minor,
self.hash().digest())
all_bin = array.array('B')
for s in [ hdr_bin, pr_bin, chw_bin, ste_bin ]:
@@ -1443,6 +1449,21 @@ class ACMPolicy(XSPolicy):
rc = -xsconstants.XSERR_BAD_LABEL
return rc, mapfile, all_bin.tostring()
def validate_enforced_policy_hash(self):
""" verify that the policy hash embedded in the binary policy
that is currently enforce matches the one of the XML policy.
"""
if self.hash().digest() != self.get_enforced_policy_hash():
raise Exception('Policy hashes do not match')
def get_enforced_policy_hash(self):
binpol = self.get_enforced_binary()
headerformat="!iiiiiiiiii20s"
res = struct.unpack(headerformat, binpol[:60])
if len(res) >= 11:
return res[10]
return None
def get_enforced_binary(self):
rc, binpol = security.hv_get_policy()
if rc != 0:
@@ -54,6 +54,7 @@ class XSPolicyAdmin:
try:
self.xsobjs[ref] = ACMPolicy(name=act_pol_name, ref=ref)
self.policies[ref] = (act_pol_name, xsconstants.ACM_POLICY_ID)
self.xsobjs[ref].validate_enforced_policy_hash()
except Exception, e:
log.error("Could not find XML representation of policy '%s': "
"%s" % (act_pol_name,e))
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.