Fix handling of manifests with unicode in the backfill

Also adds a bunch of tests around manifests to ensure we get the same information in and out
This commit is contained in:
Joseph Schorr 2018-08-15 11:41:15 -04:00
parent a66a4d6a10
commit fa58f3b1d2
9 changed files with 176 additions and 7 deletions

View file

@ -183,10 +183,14 @@ class DockerSchema1Manifest(ManifestInterface):
if validate:
self._validate()
@classmethod
def for_latin1_bytes(cls, encoded_bytes, validate=True):
return DockerSchema1Manifest(encoded_bytes.encode('utf-8'), validate)
def _validate(self):
for signature in self._signatures:
bytes_to_verify = '{0}.{1}'.format(signature['protected'],
base64url_encode(self.payload))
base64url_encode(self._payload))
signer = SIGNER_ALGS[signature['header']['alg']]
key = keyrep(signature['header']['jwk'])
gk = key.get_key()
@ -241,7 +245,7 @@ class DockerSchema1Manifest(ManifestInterface):
@property
def digest(self):
return digest_tools.sha256_digest(self.payload)
return digest_tools.sha256_digest(self._payload)
@property
def image_ids(self):
@ -304,7 +308,7 @@ class DockerSchema1Manifest(ManifestInterface):
yield Schema1Layer(image_digest, extracted, metadata_string)
@property
def payload(self):
def _payload(self):
protected = str(self._signatures[0][DOCKER_SCHEMA1_PROTECTED_KEY])
parsed_protected = json.loads(base64url_decode(protected))
signed_content_head = self._bytes[:parsed_protected[DOCKER_SCHEMA1_FORMAT_LENGTH_KEY]]