示例#1
0
	def __init__(self, _id=None, inflate=None, emit_sentinels=None):
	
		if inflate is not None:
			import os
			from lib.Core.Utils.funcs import hashEntireFile
			from conf import UUID, ANNEX_DIR
			from vars import UV_DOC_TYPE
		
			inflate['_id'] = hashEntireFile(os.path.join(ANNEX_DIR, inflate['file_name']))
			inflate['farm'] = UUID
			inflate['uv_doc_type'] = UV_DOC_TYPE['DOC']
		
		super(UnveillanceDocument, self).__init__(_id=_id, inflate=inflate,
			emit_sentinels=emit_sentinels)
		
		if inflate is not None:
			if not self.queryFile(self.file_name):
				self.invalidate(error="COULD NOT GET DOCUMENT FROM ANNEX")
				return
				
			self.mime_type = self.query_mime_type()

			alias = self.getFileMetadata("uv_file_alias")
			if alias is not None:
				self.file_alias = alias
			
			self.save()
	def get_new_hash(self, file):
		if type(file) in [str, unicode]:
			new_hash = hashEntireFile(file)
		else:
			new_hash = hashEntireStream(file)

		if DEBUG:
			print "NEW HASH: %s" % new_hash

		return new_hash
    def get_new_hash(self, file):
        if type(file) in [str, unicode]:
            new_hash = hashEntireFile(file)
        else:
            new_hash = hashEntireStream(file)

        if DEBUG:
            print "NEW HASH: %s" % new_hash

        return new_hash
示例#4
0
	def notarize(self):
		if hasattr(self, "notarized") and self.notarized:
			print "ALREADY NOTARIZED: (%s)" % self.notarized
			return False

		if not self.get_provenance():
			print "NO PROVENANCE YET"
			return False

		j3m = self.getAsset("j3m_raw.json", return_only="path")
		if j3m is None:
			print "NO RAW J3M TO NOTARIZE."
			return False

		from lib.Core.Utils.funcs import hashEntireFile
		j3m_hash = hashEntireFile(j3m, hfunc="sha256")
		
		if j3m_hash is None:
			print "WHY DIDN'T HASH WORK?"
			return False

		import gnupg
		from vars import ASSET_TAGS
		from conf import getConfig, getSecrets

		try:
			gpg = gnupg.GPG(homedir=getConfig('gpg_homedir'))
			gpg_pwd = getSecrets('gpg_pwd')

			notarization_doc = gpg.sign(j3m_hash, \
				default_key=getSecrets('org_fingerprint')[-8:], passphrase=gpg_pwd)

			del gpg_pwd

			if len(notarization_doc.data) == 0:
				print "NO NOTARIZATION DOC"
				return False

			self.addAsset(notarization_doc.data, "j3m_notarized.asc", tags=[ASSET_TAGS['IC_NOTARIZE']],
				description="Signed Notarization Doc, ready to publish.")
			
			self.notarized = True
			self.saveFields("notarized")
			return True

		except Exception as e:
			print "PROBLEM SIGNING DOC:"
			print e, type(e)

		return False