Skip to content

Commit

Permalink
Merge 26eb5b7 into 2358830
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoTorres committed Jun 21, 2014
2 parents 2358830 + 26eb5b7 commit 8f4c563
Show file tree
Hide file tree
Showing 17 changed files with 2,125 additions and 0 deletions.
160 changes: 160 additions & 0 deletions tests/repository_data/generate_project_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env python

"""
<Program Name>
generate_project_data.py
<Author>
Santiago Torres <torresariass@gmail.com>
<Copyright>
See LICENSE for licensing information.
<Purpose>
Generate a pre-fabricated set of metadata files to use for the unit testing.
"""

import shutil
import datetime
import optparse
import os

from tuf.developer_tool import *
import tuf.util


parser = optparse.OptionParser()

parser.add_option("-d","--dry-run", action='store_true', dest="dry_run",
help="Do not write the files, just run", default=False)
(options, args) = parser.parse_args()


project_key_file = 'keystore/root_key'
targets_key_file = 'keystore/targets_key'
delegation_key_file = 'keystore/delegation_key'

# the files we use for signing in the unit tests should exist, if they are not
# populated, run generate.py
assert os.path.exists(project_key_file)
assert os.path.exists(targets_key_file)
assert os.path.exists(delegation_key_file)

# Import the public keys. These keys are needed so that metadata roles are
# assigned verification keys, which clients use to verify the signatures created
# by the corresponding private keys.
project_public = import_rsa_publickey_from_file(project_key_file+'.pub')
targets_public = import_rsa_publickey_from_file(targets_key_file+'.pub')
delegation_public = import_rsa_publickey_from_file(delegation_key_file+'.pub')

# Import the private keys. These private keys are needed to generate the
# signatures included in metadata.
project_private = import_rsa_privatekey_from_file(project_key_file, 'password')
targets_private = import_rsa_privatekey_from_file(targets_key_file, 'password')
delegation_private = import_rsa_privatekey_from_file(delegation_key_file, 'password')

os.mkdir("project")
os.mkdir("project/targets")

# Create the target files (downloaded by clients) whose file size and digest
# are specified in the 'targets.json' file.
target1_filepath = 'project/targets/file1.txt'
tuf.util.ensure_parent_dir(target1_filepath)
target2_filepath = 'project/targets/file2.txt'
tuf.util.ensure_parent_dir(target2_filepath)
target3_filepath = 'project/targets/file3.txt'
tuf.util.ensure_parent_dir(target2_filepath)

if not options.dry_run:
with open(target1_filepath, 'wt') as file_object:
file_object.write('This is an example target file.')

with open(target2_filepath, 'wt') as file_object:
file_object.write('This is an another example target file.')

with open(target3_filepath, 'wt') as file_object:
file_object.write('This is role1\'s target file.')


project = create_new_project("test-flat", 'project/test-flat', 'prefix',
'project/targets')

# Add target files to the top-level 'targets.json' role. These target files
# should already exist.
project.add_target(target1_filepath)
project.add_target(target2_filepath)

# add keys to the project
project.add_verification_key(project_public)
project.load_signing_key(project_private)

project.delegate('role1', [delegation_public], [target3_filepath])
project('role1').load_signing_key(delegation_private)

# Set the top-level expiration times far into the future so that
# they do not expire anytime soon, or else the tests fail. Unit tests may
# modify the expiration datetimes (of the copied files), if they wish.
project.expiration = datetime.datetime(2030, 1, 1, 0, 0)
project('role1').expiration = datetime.datetime(2030, 1, 1, 0, 0)

# Compress the 'targets.json' role so that the unit tests have a pre-generated
# example of compressed metadata.
project.compressions = ['gz']

# Create the actual metadata files, which are saved to 'metadata.staged'.
if not options.dry_run:
project.write()

tuf.roledb.clear_roledb()
tuf.keydb.clear_keydb()

project = create_new_project("test-repo-like", "project/test-repo", 'prefix')

# Create the target files (downloaded by clients) whose file size and digest
# are specified in the 'targets.json' file.
target1_filepath = 'project/test-repo/targets/file1.txt'
tuf.util.ensure_parent_dir(target1_filepath)
target2_filepath = 'project/test-repo/targets/file2.txt'
tuf.util.ensure_parent_dir(target2_filepath)
target3_filepath = 'project/test-repo/targets/file3.txt'
tuf.util.ensure_parent_dir(target2_filepath)

if not options.dry_run:
with open(target1_filepath, 'wt') as file_object:
file_object.write('This is an example target file.')

with open(target2_filepath, 'wt') as file_object:
file_object.write('This is an another example target file.')

with open(target3_filepath, 'wt') as file_object:
file_object.write('This is role1\'s target file.')


# Add target files to the top-level 'targets.json' role. These target files
# should already exist.
project.add_target(target1_filepath)
project.add_target(target2_filepath)

# add keys to the project
project.add_verification_key(project_public)
project.load_signing_key(project_private)

project.delegate('role1', [delegation_public], [target3_filepath])
project('role1').load_signing_key(delegation_private)

# Set the top-level expiration times far into the future so that
# they do not expire anytime soon, or else the tests fail. Unit tests may
# modify the expiration datetimes (of the copied files), if they wish.
project.expiration = datetime.datetime(2030, 1, 1, 0, 0)
project('role1').expiration = datetime.datetime(2030, 1, 1, 0, 0)

# Compress the 'targets.json' role so that the unit tests have a pre-generated
# example of compressed metadata.
project.compressions = ['gz']

# Create the actual metadata files, which are saved to 'metadata.staged'.
if not options.dry_run:
project.write()


1 change: 1 addition & 0 deletions tests/repository_data/project/targets/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an example target file.
1 change: 1 addition & 0 deletions tests/repository_data/project/targets/file2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an another example target file.
1 change: 1 addition & 0 deletions tests/repository_data/project/targets/file3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is role1's target file.
1 change: 1 addition & 0 deletions tests/repository_data/project/test-flat/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"project_name": "test-flat", "targets_location": "/home/santiago/Documents/v2014/TUF/tuf/tests/repository_data/project/targets", "prefix": "prefix", "metadata_location": "test-flat", "threshold": 1, "public_keys": {"6986b667c736a3b37471e030cf4ce7aa6c7e0d530325e64c2660276b77be3754": {"keytype": "rsa", "keyval": {"public": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7J15ZaeDQPrhQsRj29wB\nPhibH+Do59xsT2396L+uCg793gZlar5wZN2eHSh725cNQWyTAa9LwG+lXaKMukQ+\n8176CKR2J5sv3DezrGVu3x8V1qhyJyy79FlNZRVYTVqNaYzvJzxsVnFPpg7f8B7C\nffiqWJr9XkpqwRlCpxooXm4hplZ7uek5Ku21CzQ4OWg7hbuc+ZjCGzpXfm8NuosU\n7TipnKGpEt0Agiph5g6TB2/scoeFar1CKMONIl80maxzAQk+xkWgiJ00+Z2qFCsx\nESfis/YkILS6RMFyZz7oa1WwMtUjYmrsRuz+jlFcbNuxZpIkaISiG9a2YdGcJ1Aj\n3QIDAQAB\n-----END PUBLIC KEY-----"}}}, "layout_type": "flat"}
51 changes: 51 additions & 0 deletions tests/repository_data/project/test-flat/test-flat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"signatures": [
{
"keyid": "6986b667c736a3b37471e030cf4ce7aa6c7e0d530325e64c2660276b77be3754",
"method": "RSASSA-PSS",
"sig": "4c979969f2e1850be960d5e4dd4b344fbaa56f7a5cbc00de3e9f7f36e3e4be3787e55ceb790831955d9c6136376f383a7cb8f288d4d8f114abbdbf368d860ece3640178a1f9b75221a9a31e27cfc153f3dcf7417cbd45a503f6b025e679a69b75f30087faa855d2812023dc05d8eea477930ecd81ea4a19ff7985af8e18d20233bffcb6151fbf749ede1acecd6c9e7fe60c11cf89c49a0ec3b08770e2ef6d7669828f850c5631f6b09dbb977b059d88f32bd0d0bfa7e5bc9bf9197febe730a068de1426f6ead68a8199d2f8e62455d24a9f902679e489624df90c9c4d35e31fe605bd6bba07a7e01547bec85a3216826aaee942d907617583440cbaf5f7889e4"
}
],
"signed": {
"_type": "Targets",
"delegations": {
"keys": {
"a404d46b042a2eb92f0cc4b28849f8e9107c9e185c45c8ece64a302626af805f": {
"keytype": "rsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqKdTRVn3mLQFUf02Rpug\nwVEU4yJtechILLb6nM7+urfwLe6f7EsNCDFhkiTP7vKuQywdLYrhwZKYZMDmaVnI\nq4d/tBLvb/jGY/IPFVvWbAOWtwWG7apiAFrcp3Idq6EKGaVVLn7tyv74+nisssYJ\ncVKodlkzpgX1Ibrdq73BUlAxhEQNDAUM5bzyJUW0BU4OSjUoFKCgc8BSkNcSLwXO\nRpyqAwDpPWiL68N1Dch7R9uD6GE9aREY9SKoYsNCvUOraIcme4fJZ3NmxpN3SVnX\ntepoiJo2iAtORtEI1yTCv/dOPap/iebveeCjn667HkMezJodSR8X3pMgMKMVyxhJ\ngwIDAQAB\n-----END PUBLIC KEY-----"
}
}
},
"roles": [
{
"backtrack": true,
"keyids": [
"a404d46b042a2eb92f0cc4b28849f8e9107c9e185c45c8ece64a302626af805f"
],
"name": "test-flat/role1",
"paths": [
"/file3.txt"
],
"threshold": 1
}
]
},
"expires": "2030-01-01T00:00:00Z",
"targets": {
"prefix/file1.txt": {
"hashes": {
"sha256": "65b8c67f51c993d898250f40aa57a317d854900b3a04895464313e48785440da"
},
"length": 31
},
"prefix/file2.txt": {
"hashes": {
"sha256": "452ce8308500d83ef44248d8e6062359211992fd837ea9e370e561efb1a4ca99"
},
"length": 39
}
},
"version": 1
}
}
26 changes: 26 additions & 0 deletions tests/repository_data/project/test-flat/test-flat/role1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"signatures": [
{
"keyid": "a404d46b042a2eb92f0cc4b28849f8e9107c9e185c45c8ece64a302626af805f",
"method": "RSASSA-PSS",
"sig": "37b67f5fba59954c1e678bf21cc9ac84173656d3c5dc5b6b45830d1f00d33c2c9d251e14cea3f0f72eabeea8e050179c6eeb7e679fba754e2f7ae41503aed3527690a1d70a9a67aa15408b642062dff05f1e9d65cfa917c99042ae45e9e366aaf9caed4bad81435014ea4aaba8ecec8c2019574f7d1e57a8eef02dcb4511ceff6c2c877c21741a9ed12b519cff8007163bcaa3c57a9364bf0fff5d5aa50d8522ddaeaa70da617072a340b8ab7667c77ae34981eaa964a43349070cc00a1d380eb1ec9c5bf0202738d12578af50017cae2b0859e54359e86f23e2e2065a282903a6f25e3853ba916b9f79aded0bca71180c2357a593e220a7a82be8a7fb5edcb1"
}
],
"signed": {
"_type": "Targets",
"delegations": {
"keys": {},
"roles": []
},
"expires": "2030-01-01T00:00:00Z",
"targets": {
"prefix/file3.txt": {
"hashes": {
"sha256": "141f740f53781d1ca54b8a50af22cbf74e44c21a998fa2a8a05aaac2c002886b"
},
"length": 28
}
},
"version": 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"signatures": [
{
"keyid": "6986b667c736a3b37471e030cf4ce7aa6c7e0d530325e64c2660276b77be3754",
"method": "RSASSA-PSS",
"sig": "28bba2c262540c899d7d49896fac834744ff935891475ca793515bbff832c85778e624f4287bad19c962448f7f109d29b22d1ec74873e1a98e86f440302e8b0897490ce5bf23c7e4311f891073809efdb6b02e641fa4c0e29ba784a66b492e4c7e875298694b88655aec10e4fb43163690de10d32adec47984e0b765a85d49d8708c44f11731be24ef97b9d5e94bfd95ca7242a43dd761a858f51ddfb67f6318c3f1515f303a9ec4529a61a464cc0ed0f5087df17a2a9edabc26ae1335bdd45b1e9bed0b8713dbe244ec90d061f1f4ec8019d63dc563c27df2bed3ba8c9919264d7b9f66c648eca98fd3c47f9093ae8ac6d9abb5e93e5702c3d8f950b81f3e74"
}
],
"signed": {
"_type": "Targets",
"delegations": {
"keys": {
"a404d46b042a2eb92f0cc4b28849f8e9107c9e185c45c8ece64a302626af805f": {
"keytype": "rsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqKdTRVn3mLQFUf02Rpug\nwVEU4yJtechILLb6nM7+urfwLe6f7EsNCDFhkiTP7vKuQywdLYrhwZKYZMDmaVnI\nq4d/tBLvb/jGY/IPFVvWbAOWtwWG7apiAFrcp3Idq6EKGaVVLn7tyv74+nisssYJ\ncVKodlkzpgX1Ibrdq73BUlAxhEQNDAUM5bzyJUW0BU4OSjUoFKCgc8BSkNcSLwXO\nRpyqAwDpPWiL68N1Dch7R9uD6GE9aREY9SKoYsNCvUOraIcme4fJZ3NmxpN3SVnX\ntepoiJo2iAtORtEI1yTCv/dOPap/iebveeCjn667HkMezJodSR8X3pMgMKMVyxhJ\ngwIDAQAB\n-----END PUBLIC KEY-----"
}
}
},
"roles": [
{
"backtrack": true,
"keyids": [
"a404d46b042a2eb92f0cc4b28849f8e9107c9e185c45c8ece64a302626af805f"
],
"name": "test-repo-like/role1",
"paths": [
"/file3.txt"
],
"threshold": 1
}
]
},
"expires": "2030-01-01T00:00:00Z",
"targets": {
"prefix/file1.txt": {
"hashes": {
"sha256": "65b8c67f51c993d898250f40aa57a317d854900b3a04895464313e48785440da"
},
"length": 31
},
"prefix/file2.txt": {
"hashes": {
"sha256": "452ce8308500d83ef44248d8e6062359211992fd837ea9e370e561efb1a4ca99"
},
"length": 39
}
},
"version": 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"signatures": [
{
"keyid": "a404d46b042a2eb92f0cc4b28849f8e9107c9e185c45c8ece64a302626af805f",
"method": "RSASSA-PSS",
"sig": "36281e10b1643ab18d5a46ec4a87a103d451e329c53508ff54958bbf5f0806e18a1de7a9a77cc08b553f5337a49a6129fa47c70fb9312e82d66c6d3711c377f86af26143b469bdc32475a4cb1eb7cdeee6d1c7662df3181941a0aaa3b6d3320d0a48e6707a4dc845c6c5c9460d3329891617be3467d3e0bf23ec683c06fa1ca4fde91dee065d12b52b964cee10b3bf588184376bbae3316150de5830734c53889966bd2b1d6a72c834ea1706efe28e6b5d5f2479f2f8c76460067247212577b2e9da9954ee88940b814a83808c0fc6be513535ff616bf07e60992fe8831b41b09669058c1a75e82df3a11e63e5f86cd84af7014ef5e4db7b7ece0d62fee34c17"
}
],
"signed": {
"_type": "Targets",
"delegations": {
"keys": {},
"roles": []
},
"expires": "2030-01-01T00:00:00Z",
"targets": {
"prefix/file3.txt": {
"hashes": {
"sha256": "141f740f53781d1ca54b8a50af22cbf74e44c21a998fa2a8a05aaac2c002886b"
},
"length": 28
}
},
"version": 1
}
}
1 change: 1 addition & 0 deletions tests/repository_data/project/test-repo/project.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"project_name": "test-repo-like", "targets_location": "targets", "prefix": "prefix", "metadata_location": "metadata", "threshold": 1, "public_keys": {"6986b667c736a3b37471e030cf4ce7aa6c7e0d530325e64c2660276b77be3754": {"keytype": "rsa", "keyval": {"public": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7J15ZaeDQPrhQsRj29wB\nPhibH+Do59xsT2396L+uCg793gZlar5wZN2eHSh725cNQWyTAa9LwG+lXaKMukQ+\n8176CKR2J5sv3DezrGVu3x8V1qhyJyy79FlNZRVYTVqNaYzvJzxsVnFPpg7f8B7C\nffiqWJr9XkpqwRlCpxooXm4hplZ7uek5Ku21CzQ4OWg7hbuc+ZjCGzpXfm8NuosU\n7TipnKGpEt0Agiph5g6TB2/scoeFar1CKMONIl80maxzAQk+xkWgiJ00+Z2qFCsx\nESfis/YkILS6RMFyZz7oa1WwMtUjYmrsRuz+jlFcbNuxZpIkaISiG9a2YdGcJ1Aj\n3QIDAQAB\n-----END PUBLIC KEY-----"}}}, "layout_type": "repo-like"}
1 change: 1 addition & 0 deletions tests/repository_data/project/test-repo/targets/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an example target file.
1 change: 1 addition & 0 deletions tests/repository_data/project/test-repo/targets/file2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an another example target file.
1 change: 1 addition & 0 deletions tests/repository_data/project/test-repo/targets/file3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is role1's target file.

0 comments on commit 8f4c563

Please sign in to comment.