From 07e8ef0be78934da6790c4c4eabcb800289e2b40 Mon Sep 17 00:00:00 2001 From: Santiago Torres Date: Fri, 20 Jun 2014 19:36:42 -0400 Subject: [PATCH] Added the generate_repository_data.py script and its produce The generate_repository_data script works in the exact same way as the generate script and it generates a fresh batch of pre-signed metadata to test the load_project function. --- .../repository_data/generate_project_data.py | 160 ++++++++++++++++++ .../repository_data/project/targets/file1.txt | 1 + .../repository_data/project/targets/file2.txt | 1 + .../repository_data/project/targets/file3.txt | 1 + .../project/test-flat/project.cfg | 1 + .../project/test-flat/test-flat.json | Bin 0 -> 1974 bytes .../project/test-flat/test-flat/role1.json | Bin 0 -> 980 bytes .../test-repo/metadata/test-repo-like.json | Bin 0 -> 1979 bytes .../metadata/test-repo-like/role1.json | Bin 0 -> 980 bytes .../project/test-repo/project.cfg | 1 + .../project/test-repo/targets/file1.txt | 1 + .../project/test-repo/targets/file2.txt | 1 + .../project/test-repo/targets/file3.txt | 1 + 13 files changed, 168 insertions(+) create mode 100755 tests/repository_data/generate_project_data.py create mode 100644 tests/repository_data/project/targets/file1.txt create mode 100644 tests/repository_data/project/targets/file2.txt create mode 100644 tests/repository_data/project/targets/file3.txt create mode 100644 tests/repository_data/project/test-flat/project.cfg create mode 100644 tests/repository_data/project/test-flat/test-flat.json create mode 100644 tests/repository_data/project/test-flat/test-flat/role1.json create mode 100644 tests/repository_data/project/test-repo/metadata/test-repo-like.json create mode 100644 tests/repository_data/project/test-repo/metadata/test-repo-like/role1.json create mode 100644 tests/repository_data/project/test-repo/project.cfg create mode 100644 tests/repository_data/project/test-repo/targets/file1.txt create mode 100644 tests/repository_data/project/test-repo/targets/file2.txt create mode 100644 tests/repository_data/project/test-repo/targets/file3.txt diff --git a/tests/repository_data/generate_project_data.py b/tests/repository_data/generate_project_data.py new file mode 100755 index 00000000..19d6a8db --- /dev/null +++ b/tests/repository_data/generate_project_data.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python + +""" + + generate_project_data.py + + + Santiago Torres + + + + See LICENSE for licensing information. + + + 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() + + diff --git a/tests/repository_data/project/targets/file1.txt b/tests/repository_data/project/targets/file1.txt new file mode 100644 index 00000000..7bf3499f --- /dev/null +++ b/tests/repository_data/project/targets/file1.txt @@ -0,0 +1 @@ +This is an example target file. \ No newline at end of file diff --git a/tests/repository_data/project/targets/file2.txt b/tests/repository_data/project/targets/file2.txt new file mode 100644 index 00000000..606f18ef --- /dev/null +++ b/tests/repository_data/project/targets/file2.txt @@ -0,0 +1 @@ +This is an another example target file. \ No newline at end of file diff --git a/tests/repository_data/project/targets/file3.txt b/tests/repository_data/project/targets/file3.txt new file mode 100644 index 00000000..60464604 --- /dev/null +++ b/tests/repository_data/project/targets/file3.txt @@ -0,0 +1 @@ +This is role1's target file. \ No newline at end of file diff --git a/tests/repository_data/project/test-flat/project.cfg b/tests/repository_data/project/test-flat/project.cfg new file mode 100644 index 00000000..61b14806 --- /dev/null +++ b/tests/repository_data/project/test-flat/project.cfg @@ -0,0 +1 @@ +{"project_name": "test-flat", "targets_location": "/home/santiago/Documents/v2014/TUF/tuf/tests/repository_data/project/targets", "prefix": "prefix", "metadata_location": "/home/santiago/Documents/v2014/TUF/tuf/tests/repository_data/project/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"} \ No newline at end of file diff --git a/tests/repository_data/project/test-flat/test-flat.json b/tests/repository_data/project/test-flat/test-flat.json new file mode 100644 index 0000000000000000000000000000000000000000..147417248d707c8c92e95f3f7784a2c926689368 GIT binary patch literal 1974 zcmbtV+ioI95PkPoAYM0)`+nKC!C(h-u?+@a;#Jg_YQV+=hB263`QKAB*xn>kq)2HE zqoI4I`c$1$r+*yO>g(Agcg4#J*7dKo-w$fFANZ@)A7M9(I8#^FD6fTB`+EABiR$j3XG(2NfL`k~`rwB~BYllu*=Z9ZXV81|mhW#s`^n^u$Wb;W&zMz)1s{dBK}Jcna*|6bl%@_irIIi!5VTRk8{9>4!IG08C09aw z8z}M2b7zy}7E&ZGTF$^k<8(;LQ-L|eg!PCaStP>=PK*hVG}6J6FviKKOuaVjLBa0>com)Ktp^8ViRJf&)Q-%JO?|9g-lx zSQnz_++vnoa1dHVB;6aqm5#zwV-Y*ZBy0_g(@;GCeiKleYQ2*NXCgiQu4B|2E3n4yrtKtTCAPMBiKB|~KT2)l2G4-l)h+Y5I;y>auO@73zd z7eAkc66|3)8m-fIzjiTdblbcBB1}^&6AN=jr3@)NV;5yKJ3g+4*sH zX|i(tc+$b=R`%S9SA%iRpSqVPqeR$X`7*iBx8v4G?9K`Z({{J(Ro>HIURG(_1(kGb z-9K)gVBo6@z3IGM?zXXeyP9tAI=6Sd=93%e?fd*$#G|6o-T0%2)7zu=#mRVc?X&ai zVtak6-Ex+ltiqDF=ZJBv7f{Jxyr(6(R2XU!X< zdGeG^8%KO+1Y~4vf_MD zwAyrcb-X!>=NE2yGy}f@IDW{{zJ7b`!S}O891hG4U-l-wPH((>onjV~ZM&IWW{vy2 zBB#}F{*$j#nK)3KANRMtsjU|CPuqMqP85ZA;jviZ4OLLAUZ8q+FP2&SaM?1{{}<>U zSlKdFyxcuieNw=>I81X_9F+*^r(Bn=nEnmGQJT$x|605j?>T;kDyDcMOc(RA3F*(o zzu{w*d>vkwv;Cn_XLuYO5{lOqAz!QOZr`KDd&7S8=W+#U_FC;qt6kq0YW1mGPpev1 zjf}NfPtjmi*+@#3R;`nyXi(_p=){sFL7YPq=2S-`g(U=ylL%v_Q0UX>NJitlKy%-x zwx_ICpF=(=rWlu3Y3--$e*wn+GcX}p0D~4R35kY75`qbIYfwZnE-j;YsIY`f8l1(` jkbqPaEtfhGoVEW3%$D^o)wZwn23BiyxjhkY2XB7@#;hCA literal 0 HcmV?d00001 diff --git a/tests/repository_data/project/test-flat/test-flat/role1.json b/tests/repository_data/project/test-flat/test-flat/role1.json new file mode 100644 index 0000000000000000000000000000000000000000..4e38e30f124edd9b78248a88d834468ea0145b4b GIT binary patch literal 980 zcmX|=(QXtm3`O7j6{~rs5Ic_J@Wvk?wof30?8ND=C~dVnpd!?N$FnU+8EMB}-Fxkv z`E#{f&d1w(U4NeZyu9Cix!Udi#Iswz`|sn3%A%BL5L+TtbZau`nElz|Ej(=<3wDJreZA*p4l+SE%o<_esW zdj+V?m8%!5WSz}1CSq+kB9L&ju@BFXGie3OHG`x~)e1&NVl^dBZKfEDTOMsVA61x#ElZ#$Zpv| z%|?kV5j%DRB$3%m#hiGe+AW#%`*JXZ*@IB+;8Om zr}pyl`~uzS;qC?NubcK(Tm0$q_`>>vDW~fMac)w2e>tCDq}NxUf3lA!pU07yr;d9~293VIl6IQVK+?1hQQVnP>@`5W7Xoi8_L|CR0&GQ&H89 nJ*D`#*tUJVrViaZzrS4%p^LKBV^OaI{qoZ}b`Tx7it_Vcg69Ja literal 0 HcmV?d00001 diff --git a/tests/repository_data/project/test-repo/metadata/test-repo-like.json b/tests/repository_data/project/test-repo/metadata/test-repo-like.json new file mode 100644 index 0000000000000000000000000000000000000000..cad9c4c1ba6b25a216eb24187c965e8beda05de3 GIT binary patch literal 1979 zcmbtVYj5I46#brGf%v*jGw;WKGl8UpM-m9+(X6U@+yN3|2sjXSmH*yrlVsaUl`3^) zTlUQO&bepKJ@ezBR$tF1xhq~)u&#ft{eDoZ{lL3ce}vsEVozOJqr6f&Xs#UhTnkNs za1xRTpq*1e1BsFo&Lk)im{Npk<+b*}wG{PVs(4ROOczza!7v*Rv%`zw@O=molnaGm zU6M3t5-jsBMMZ^U8U(WUPr3pb>rxY_F2q8E>fFzVs4?r~% z>n3RC10@&muSKJV#feVUzW_|UmQ9@e?l3|C_n5|YW678sulpAeKAk;WZ zC~=GgN`s3*MIQmdC7dRbr%qchEXBl()S5fbqEI3N^23>>k_ZwtCmOu;Rw%7ZsH0Ba z4r<>}FO?{vR7)ww`X9w^38h4?+-d^Fy3$QO!W<^9m@V>Bxu2^2{HWEPAOe>~Sj;i- zmL(E`@JOeyC@7>|2Mg3l-1J}|pnM%COflt>Au@f0-Iv1$h}GKdg}d+GxcSd{wfgeK z&u5_odswzc>$KgkU5pyt_HnJ#x~)3z^Ip5%Xg_5A#^mvN`ZznaThhobTPIm|ewB_>#}o>-Fu~eICZ0MVvo=Urugl+pprY=8e%j zd!4o}`^{|Blm7eeY;;W;BXK@_7%fgZ$CF?h!^eIYcDFa@_xWJCd(O7a<;C@^t4yCZ z!&DFKOH-Y;tQ)j$?Xa`B#bh?4^Ob9dClKlEj`yElmwi4Q=QsCx0n5egY{6z(aXu(o zZMwTU-WhQXp?N5$6!!zNKP`s`P`C46f`$8?=tM;Qvmn%rK*J@Q-t@=Jtt54l} zS`k`RGZM6(IwnQwghaz33Bk~#4Je`*mzLpigU*9P m8l1%=k$_YbN{ixjoYxSgq0O_8akb@b)KMFC6Cp literal 0 HcmV?d00001 diff --git a/tests/repository_data/project/test-repo/metadata/test-repo-like/role1.json b/tests/repository_data/project/test-repo/metadata/test-repo-like/role1.json new file mode 100644 index 0000000000000000000000000000000000000000..caac5a0dcd78aa315017fb14ee00f9942eafecf7 GIT binary patch literal 980 zcmX|9!EO{W488X&R&%BhJ8|rA;|~zq69^$EvAZiuTkQ_02=(9bYzw2zA&&Fj%k%ql zwOh`|+k0Jqp6tB5-+j5-?f%5STfW=xU z4N}R|t0v{Fz2pHrF)P(5MU9GkZV3f2Zq<-hm`zyJIRMprO^{}>DUDm@s*<>OMwh}+ zYU?A9xSyvXH63H9a7_(t0BEa_rFZDHPoe6gC#xhaH`ggV7>JwZk^{>v2xs(=cSTnv zs2ws8iDRmT59A68{u%WnNtakk^^;Q zlV}5+g^_59oIGFczD8ayp|mY6TNsyb>+eU~B66drTU*bU+$_`X>{i#~!~K@r|Eaxf zo?k+DdboRu_16u1t1b5QczntFf+?r#1hH;XdVg7;U!d1lo`0~9C-dXeJ3ro8e!D)c z|M+&xLC=Q^#f3lc&j&@Sn^-8|VTDs>feAyYbWut%0vtV#tdxO~t|lIX5ly5qV;m`R kEVXZbys8e|JG;MK4}pua)x)UQ2mP|sIXs9HxQg=gU$-3s_W%F@ literal 0 HcmV?d00001 diff --git a/tests/repository_data/project/test-repo/project.cfg b/tests/repository_data/project/test-repo/project.cfg new file mode 100644 index 00000000..e3a93c8d --- /dev/null +++ b/tests/repository_data/project/test-repo/project.cfg @@ -0,0 +1 @@ +{"project_name": "test-repo-like", "targets_location": "/home/santiago/Documents/v2014/TUF/tuf/tests/repository_data/project/test-repo/targets", "prefix": "prefix", "metadata_location": "/home/santiago/Documents/v2014/TUF/tuf/tests/repository_data/project/test-repo/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"} \ No newline at end of file diff --git a/tests/repository_data/project/test-repo/targets/file1.txt b/tests/repository_data/project/test-repo/targets/file1.txt new file mode 100644 index 00000000..7bf3499f --- /dev/null +++ b/tests/repository_data/project/test-repo/targets/file1.txt @@ -0,0 +1 @@ +This is an example target file. \ No newline at end of file diff --git a/tests/repository_data/project/test-repo/targets/file2.txt b/tests/repository_data/project/test-repo/targets/file2.txt new file mode 100644 index 00000000..606f18ef --- /dev/null +++ b/tests/repository_data/project/test-repo/targets/file2.txt @@ -0,0 +1 @@ +This is an another example target file. \ No newline at end of file diff --git a/tests/repository_data/project/test-repo/targets/file3.txt b/tests/repository_data/project/test-repo/targets/file3.txt new file mode 100644 index 00000000..60464604 --- /dev/null +++ b/tests/repository_data/project/test-repo/targets/file3.txt @@ -0,0 +1 @@ +This is role1's target file. \ No newline at end of file