backupcompatibility.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2014 Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. from multiprocessing import Queue
  24. import os
  25. import shutil
  26. import subprocess
  27. import unittest
  28. import sys
  29. import re
  30. import qubes.tests
  31. QUBESXML_R2B2 = '''
  32. <QubesVmCollection updatevm="3" default_kernel="3.7.6-2" default_netvm="3" default_fw_netvm="2" default_template="1" clockvm="2">
  33. <QubesTemplateVm installed_by_rpm="True" kernel="3.7.6-2" uses_default_kernelopts="True" qid="1" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="fedora-18-x64.conf" label="black" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-18-x64" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/fedora-18-x64"/>
  34. <QubesNetVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="2" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="netvm.conf" label="red" template_qid="1" kernelopts="iommu=soft swiotlb=4096" memory="200" default_user="user" volatile_img="volatile.img" services="{'ntpd': False, 'meminfo-writer': False}" maxmem="1535" pcidevs="['02:00.0', '03:00.0']" name="netvm" netid="1" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/netvm"/>
  35. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="3" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="firewallvm.conf" label="green" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="firewallvm" netid="2" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/firewallvm"/>
  36. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="4" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="True" conf_file="fedora-18-x64-dvm.conf" label="gray" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-18-x64-dvm" private_img="private.img" vcpus="1" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/fedora-18-x64-dvm"/>
  37. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="5" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-work.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-work" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-work"/>
  38. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="6" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="banking.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="banking" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/banking"/>
  39. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="7" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="personal.conf" label="yellow" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="personal" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/personal"/>
  40. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="8" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="untrusted.conf" label="red" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="12" uses_default_netvm="False" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="untrusted" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/untrusted"/>
  41. <QubesTemplateVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="9" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-template-clone.conf" label="green" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-template-clone" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/test-template-clone"/>
  42. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="10" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-custom-template-appvm.conf" label="yellow" template_qid="9" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-custom-template-appvm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-custom-template-appvm"/>
  43. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="11" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-standalonevm.conf" label="blue" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-standalonevm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-standalonevm"/>
  44. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="12" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-testproxy.conf" label="red" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="3" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-testproxy" netid="3" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/test-testproxy"/>
  45. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="13" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="testproxy2.conf" label="red" template_qid="9" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="testproxy2" netid="4" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/testproxy2"/>
  46. <QubesHVm installed_by_rpm="False" netvm_qid="none" qid="14" include_in_backups="True" timezone="localtime" qrexec_timeout="60" conf_file="test-testhvm.conf" label="purple" template_qid="none" internal="False" memory="512" uses_default_netvm="True" services="{'meminfo-writer': False}" default_user="user" pcidevs="[]" name="test-testhvm" qrexec_installed="False" private_img="private.img" drive="None" vcpus="2" root_img="root.img" guiagent_installed="False" debug="False" dir_path="/var/lib/qubes/appvms/test-testhvm"/>
  47. <QubesDisposableVm dispid="50" firewall_conf="firewall.xml" label="red" name="disp50" netvm_qid="2" qid="15" template_qid="1"/>
  48. </QubesVmCollection>
  49. '''
  50. QUBESXML_R2 = '''
  51. <QubesVmCollection updatevm="3" default_kernel="3.7.6-2" default_netvm="3" default_fw_netvm="2" default_template="1" clockvm="2">
  52. <QubesTemplateVm installed_by_rpm="True" kernel="3.7.6-2" uses_default_kernelopts="True" qid="1" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="fedora-20-x64.conf" label="black" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{ 'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-20-x64" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/fedora-20-x64"/>
  53. <QubesNetVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="2" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="netvm.conf" label="red" template_qid="1" kernelopts="iommu=soft swiotlb=4096" memory="200" default_user="user" volatile_img="volatile.img" services="{'ntpd': False, 'meminfo-writer': False}" maxmem="1535" pcidevs="['02:00.0', '03:00.0']" name="netvm" netid="1" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/netvm"/>
  54. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="3" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="firewallvm.conf" label="green" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="firewallvm" netid="2" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/firewallvm"/>
  55. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="4" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="True" conf_file="fedora-20-x64-dvm.conf" label="gray" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{ 'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="fedora-20-x64-dvm" private_img="private.img" vcpus="1" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/fedora-20-x64-dvm"/>
  56. <QubesAppVm backup_content="True" backup_path="appvms/test-work" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="5" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-work.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-work" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-work"/>
  57. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="6" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="banking.conf" label="green" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="banking" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/banking"/>
  58. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="7" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="personal.conf" label="yellow" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="personal" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/personal"/>
  59. <QubesAppVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="8" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="untrusted.conf" label="red" template_qid="1" kernelopts="" memory="400" default_user="user" netvm_qid="12" uses_default_netvm="False" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="untrusted" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/untrusted"/>
  60. <QubesTemplateVm backup_size="104857600" backup_content="True" backup_path="vm-templates/test-template-clone" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="9" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-template-clone.conf" label="green" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-template-clone" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/vm-templates/test-template-clone"/>
  61. <QubesAppVm backup_size="104857600" backup_content="True" backup_path="appvms/test-custom-template-appvm" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="10" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-custom-template-appvm.conf" label="yellow" template_qid="9" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-custom-template-appvm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-custom-template-appvm"/>
  62. <QubesAppVm backup_size="104857600" backup_content="True" backup_path="appvms/test-standalonevm" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="11" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-standalonevm.conf" label="blue" template_qid="none" kernelopts="" memory="400" default_user="user" netvm_qid="3" uses_default_netvm="True" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-standalonevm" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/appvms/test-standalonevm"/>
  63. <QubesProxyVm backup_size="104857600" backup_content="True" backup_path="servicevms/test-testproxy" installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="12" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="test-testproxy.conf" label="red" template_qid="1" kernelopts="" memory="200" default_user="user" netvm_qid="3" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="test-testproxy" netid="3" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/test-testproxy"/>
  64. <QubesProxyVm installed_by_rpm="False" kernel="3.7.6-2" uses_default_kernelopts="True" qid="13" include_in_backups="True" uses_default_kernel="True" qrexec_timeout="60" internal="False" conf_file="testproxy2.conf" label="red" template_qid="9" kernelopts="" memory="200" default_user="user" netvm_qid="2" volatile_img="volatile.img" services="{'meminfo-writer': True}" maxmem="1535" pcidevs="[]" name="testproxy2" netid="4" private_img="private.img" vcpus="2" root_img="root.img" debug="False" dir_path="/var/lib/qubes/servicevms/testproxy2"/>
  65. <QubesHVm backup_size="104857600" backup_content="True" backup_path="appvms/test-testhvm" installed_by_rpm="False" netvm_qid="none" qid="14" include_in_backups="True" timezone="localtime" qrexec_timeout="60" conf_file="test-testhvm.conf" label="purple" template_qid="none" internal="False" memory="512" uses_default_netvm="True" services="{'meminfo-writer': False}" default_user="user" pcidevs="[]" name="test-testhvm" qrexec_installed="False" private_img="private.img" drive="None" vcpus="2" root_img="root.img" guiagent_installed="False" debug="False" dir_path="/var/lib/qubes/appvms/test-testhvm"/>
  66. <QubesDisposableVm dispid="50" firewall_conf="firewall.xml" label="red" name="disp50" netvm_qid="2" qid="15" template_qid="1"/>
  67. </QubesVmCollection>
  68. '''
  69. MANGLED_SUBDIRS_R2 = {
  70. "test-work": "vm5",
  71. "test-template-clone": "vm9",
  72. "test-custom-template-appvm": "vm10",
  73. "test-standalonevm": "vm11",
  74. "test-testproxy": "vm12",
  75. "test-testhvm": "vm14",
  76. }
  77. APPTEMPLATE_R2B2 = '''
  78. [Desktop Entry]
  79. Name=%VMNAME%: {name}
  80. GenericName=%VMNAME%: {name}
  81. GenericName[ca]=%VMNAME%: Navegador web
  82. GenericName[cs]=%VMNAME%: Webový prohlížeč
  83. GenericName[es]=%VMNAME%: Navegador web
  84. GenericName[fa]=%VMNAME%: مرورر اینترنتی
  85. GenericName[fi]=%VMNAME%: WWW-selain
  86. GenericName[fr]=%VMNAME%: Navigateur Web
  87. GenericName[hu]=%VMNAME%: Webböngésző
  88. GenericName[it]=%VMNAME%: Browser Web
  89. GenericName[ja]=%VMNAME%: ウェブ・ブラウザ
  90. GenericName[ko]=%VMNAME%: 웹 브라우저
  91. GenericName[nb]=%VMNAME%: Nettleser
  92. GenericName[nl]=%VMNAME%: Webbrowser
  93. GenericName[nn]=%VMNAME%: Nettlesar
  94. GenericName[no]=%VMNAME%: Nettleser
  95. GenericName[pl]=%VMNAME%: Przeglądarka WWW
  96. GenericName[pt]=%VMNAME%: Navegador Web
  97. GenericName[pt_BR]=%VMNAME%: Navegador Web
  98. GenericName[sk]=%VMNAME%: Internetový prehliadač
  99. GenericName[sv]=%VMNAME%: Webbläsare
  100. Comment={comment}
  101. Comment[ca]=Navegueu per el web
  102. Comment[cs]=Prohlížení stránek World Wide Webu
  103. Comment[de]=Im Internet surfen
  104. Comment[es]=Navegue por la web
  105. Comment[fa]=صفحات شبه جهانی اینترنت را مرور نمایید
  106. Comment[fi]=Selaa Internetin WWW-sivuja
  107. Comment[fr]=Navigue sur Internet
  108. Comment[hu]=A világháló böngészése
  109. Comment[it]=Esplora il web
  110. Comment[ja]=ウェブを閲覧します
  111. Comment[ko]=웹을 돌아 다닙니다
  112. Comment[nb]=Surf på nettet
  113. Comment[nl]=Verken het internet
  114. Comment[nn]=Surf på nettet
  115. Comment[no]=Surf på nettet
  116. Comment[pl]=Przeglądanie stron WWW
  117. Comment[pt]=Navegue na Internet
  118. Comment[pt_BR]=Navegue na Internet
  119. Comment[sk]=Prehliadanie internetu
  120. Comment[sv]=Surfa på webben
  121. Exec=qvm-run -q --tray -a %VMNAME% '{command} %u'
  122. Categories=Network;WebBrowser;
  123. X-Qubes-VmName=%VMNAME%
  124. Icon=%VMDIR%/icon.png
  125. '''
  126. QUBESXML_R1 = '''<?xml version='1.0' encoding='UTF-8'?>
  127. <QubesVmCollection clockvm="2" default_fw_netvm="2" default_kernel="3.2.7-10" default_netvm="3" default_template="1" updatevm="3"><QubesTemplateVm conf_file="fedora-17-x64.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/vm-templates/fedora-17-x64" include_in_backups="True" installed_by_rpm="True" internal="False" kernel="3.2.7-10" kernelopts="" label="gray" maxmem="4063" memory="400" name="fedora-17-x64" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="1" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="none" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesNetVm conf_file="netvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/servicevms/netvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="iommu=soft swiotlb=2048" label="red" maxmem="4063" memory="200" name="netvm" netid="1" pcidevs="[&apos;00:19.0&apos;, &apos;03:00.0&apos;]" private_img="private.img" qid="2" root_img="root.img" services="{&apos;ntpd&apos;: False, &apos;meminfo-writer&apos;: False}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" vcpus="2" volatile_img="volatile.img" /><QubesProxyVm conf_file="firewallvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/servicevms/firewallvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="green" maxmem="4063" memory="200" name="firewallvm" netid="2" netvm_qid="2" pcidevs="[]" private_img="private.img" qid="3" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="fedora-17-x64-dvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/fedora-17-x64-dvm" include_in_backups="True" installed_by_rpm="False" internal="True" kernel="3.2.7-10" kernelopts="" label="gray" maxmem="4063" memory="400" name="fedora-17-x64-dvm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="4" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="1" volatile_img="volatile.img" /><QubesAppVm conf_file="test-work.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-work" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="green" maxmem="4063" memory="400" name="test-work" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="5" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="personal.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/personal" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="yellow" maxmem="4063" memory="400" name="personal" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="6" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="banking.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/banking" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="green" maxmem="4063" memory="400" name="banking" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="7" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="untrusted.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/untrusted" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="red" maxmem="4063" memory="400" name="untrusted" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="8" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="test-standalonevm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-standalonevm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="None" kernelopts="" label="red" maxmem="4063" memory="400" name="test-standalonevm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="9" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="none" uses_default_kernel="False" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="test-testvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-testvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="red" mac="00:16:3E:5E:6C:55" maxmem="4063" memory="400" name="test-testvm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="10" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesTemplateVm conf_file="test-template-clone.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/vm-templates/test-template-clone" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="gray" maxmem="4063" memory="400" name="test-template-clone" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="11" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="none" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesAppVm conf_file="test-custom-template-appvm.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/appvms/test-custom-template-appvm" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="yellow" maxmem="4063" memory="400" name="test-custom-template-appvm" netvm_qid="3" pcidevs="[]" private_img="private.img" qid="12" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="11" uses_default_kernel="True" uses_default_kernelopts="True" uses_default_netvm="True" vcpus="2" volatile_img="volatile.img" /><QubesProxyVm conf_file="test-testproxy.conf" debug="False" default_user="user" dir_path="/var/lib/qubes/servicevms/test-testproxy" include_in_backups="True" installed_by_rpm="False" internal="False" kernel="3.2.7-10" kernelopts="" label="yellow" maxmem="4063" memory="200" name="test-testproxy" netid="3" netvm_qid="2" pcidevs="[]" private_img="private.img" qid="13" root_img="root.img" services="{&apos;meminfo-writer&apos;: True}" template_qid="1" uses_default_kernel="True" uses_default_kernelopts="True" vcpus="2" volatile_img="volatile.img" /></QubesVmCollection>
  128. '''
  129. BACKUP_HEADER_R2 = '''version=3
  130. hmac-algorithm=SHA512
  131. crypto-algorithm=aes-256-cbc
  132. encrypted={encrypted}
  133. compressed={compressed}
  134. compression-filter=gzip
  135. '''
  136. class TC_00_BackupCompatibility(qubes.tests.BackupTestsMixin, qubes.tests.QubesTestCase):
  137. def tearDown(self):
  138. self.remove_test_vms(prefix="test-")
  139. super(TC_00_BackupCompatibility, self).tearDown()
  140. def create_whitelisted_appmenus(self, filename):
  141. f = open(filename, "w")
  142. f.write("gnome-terminal.desktop\n")
  143. f.write("nautilus.desktop\n")
  144. f.write("firefox.desktop\n")
  145. f.write("mozilla-thunderbird.desktop\n")
  146. f.write("libreoffice-startcenter.desktop\n")
  147. f.close()
  148. def create_appmenus(self, dir, template, list):
  149. for name in list:
  150. f = open(os.path.join(dir, name + ".desktop"), "w")
  151. f.write(template.format(name=name, comment=name, command=name))
  152. f.close()
  153. def create_private_img(self, filename):
  154. self.create_sparse(filename, 2*2**30)
  155. subprocess.check_call(["/usr/sbin/mkfs.ext4", "-q", "-F", filename])
  156. def create_volatile_img(self, filename):
  157. self.create_sparse(filename, 11.5*2**30)
  158. sfdisk_input="0,1024,S\n,10240,L\n"
  159. p = subprocess.Popen(["/usr/sbin/sfdisk", "--no-reread", "-u",
  160. "M",
  161. filename], stdout=open("/dev/null","w"),
  162. stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
  163. p.communicate(input=sfdisk_input)
  164. self.assertEqual(p.returncode, 0, "sfdisk failed with code %d" % p
  165. .returncode)
  166. # TODO: mkswap
  167. def fullpath(self, name):
  168. return os.path.join(self.backupdir, name)
  169. def create_v1_files(self, r2b2=False):
  170. appmenus_list = [
  171. "firefox", "gnome-terminal", "evince", "evolution",
  172. "mozilla-thunderbird", "libreoffice-startcenter", "nautilus",
  173. "gedit", "gpk-update-viewer", "gpk-application"
  174. ]
  175. os.mkdir(self.fullpath("appvms"))
  176. os.mkdir(self.fullpath("servicevms"))
  177. os.mkdir(self.fullpath("vm-templates"))
  178. # normal AppVM
  179. os.mkdir(self.fullpath("appvms/test-work"))
  180. self.create_whitelisted_appmenus(self.fullpath(
  181. "appvms/test-work/whitelisted-appmenus.list"))
  182. os.symlink("/usr/share/qubes/icons/green.png",
  183. self.fullpath("appvms/test-work/icon.png"))
  184. self.create_private_img(self.fullpath("appvms/test-work/private.img"))
  185. # StandaloneVM
  186. os.mkdir(self.fullpath("appvms/test-standalonevm"))
  187. self.create_whitelisted_appmenus(self.fullpath(
  188. "appvms/test-standalonevm/whitelisted-appmenus.list"))
  189. os.symlink("/usr/share/qubes/icons/blue.png",
  190. self.fullpath("appvms/test-standalonevm/icon.png"))
  191. self.create_private_img(self.fullpath(
  192. "appvms/test-standalonevm/private.img"))
  193. self.create_sparse(
  194. self.fullpath("appvms/test-standalonevm/root.img"), 10*2**30)
  195. self.fill_image(self.fullpath("appvms/test-standalonevm/root.img"),
  196. 100*1024*1024, True)
  197. os.mkdir(self.fullpath("appvms/test-standalonevm/apps.templates"))
  198. self.create_appmenus(self.fullpath("appvms/test-standalonevm/apps"
  199. ".templates"),
  200. APPTEMPLATE_R2B2,
  201. appmenus_list)
  202. os.mkdir(self.fullpath("appvms/test-standalonevm/kernels"))
  203. for k_file in ["initramfs", "vmlinuz", "modules.img"]:
  204. self.fill_image(self.fullpath("appvms/test-standalonevm/kernels/"
  205. + k_file), 10*1024*1024)
  206. # VM based on custom template
  207. subprocess.check_call(
  208. ["/bin/cp", "-a", self.fullpath("appvms/test-work"),
  209. self.fullpath("appvms/test-custom-template-appvm")])
  210. # HVM
  211. if r2b2:
  212. subprocess.check_call(
  213. ["/bin/cp", "-a", self.fullpath("appvms/test-standalonevm"),
  214. self.fullpath("appvms/test-testhvm")])
  215. # ProxyVM
  216. os.mkdir(self.fullpath("servicevms/test-testproxy"))
  217. self.create_whitelisted_appmenus(self.fullpath(
  218. "servicevms/test-testproxy/whitelisted-appmenus.list"))
  219. self.create_private_img(
  220. self.fullpath("servicevms/test-testproxy/private.img"))
  221. # Custom template
  222. os.mkdir(self.fullpath("vm-templates/test-template-clone"))
  223. self.create_private_img(
  224. self.fullpath("vm-templates/test-template-clone/private.img"))
  225. self.create_sparse(self.fullpath(
  226. "vm-templates/test-template-clone/root-cow.img"), 10*2**30)
  227. self.create_sparse(self.fullpath(
  228. "vm-templates/test-template-clone/root.img"), 10*2**30)
  229. self.fill_image(self.fullpath(
  230. "vm-templates/test-template-clone/root.img"), 1*2**30, True)
  231. self.create_volatile_img(self.fullpath(
  232. "vm-templates/test-template-clone/volatile.img"))
  233. subprocess.check_call([
  234. "/bin/tar", "cS",
  235. "-f", self.fullpath(
  236. "vm-templates/test-template-clone/clean-volatile.img.tar"),
  237. "-C", self.fullpath("vm-templates/test-template-clone"),
  238. "volatile.img"])
  239. self.create_whitelisted_appmenus(self.fullpath(
  240. "vm-templates/test-template-clone/whitelisted-appmenus.list"))
  241. self.create_whitelisted_appmenus(self.fullpath(
  242. "vm-templates/test-template-clone/vm-whitelisted-appmenus.list"))
  243. if r2b2:
  244. self.create_whitelisted_appmenus(self.fullpath(
  245. "vm-templates/test-template-clone/netvm-whitelisted-appmenus"
  246. ".list"))
  247. os.symlink("/usr/share/qubes/icons/green.png",
  248. self.fullpath("vm-templates/test-template-clone/icon.png"))
  249. os.mkdir(
  250. self.fullpath("vm-templates/test-template-clone/apps.templates"))
  251. self.create_appmenus(
  252. self.fullpath("vm-templates/test-template-clone/apps.templates"),
  253. APPTEMPLATE_R2B2,
  254. appmenus_list)
  255. os.mkdir(self.fullpath("vm-templates/test-template-clone/apps"))
  256. self.create_appmenus(
  257. self.fullpath("vm-templates/test-template-clone/apps"),
  258. APPTEMPLATE_R2B2.replace("%VMNAME%", "test-template-clone")
  259. .replace("%VMDIR%", self.fullpath(
  260. "vm-templates/test-template-clone")),
  261. appmenus_list)
  262. def calculate_hmac(self, f_name, algorithm="sha512", password="qubes"):
  263. subprocess.check_call(["openssl", "dgst", "-"+algorithm, "-hmac",
  264. password],
  265. stdin=open(self.fullpath(f_name), "r"),
  266. stdout=open(self.fullpath(f_name+".hmac"), "w"))
  267. def append_backup_stream(self, f_name, stream, basedir=None):
  268. if not basedir:
  269. basedir = self.backupdir
  270. subprocess.check_call(["tar", "-cO", "--posix", "-C", basedir,
  271. f_name],
  272. stdout=stream)
  273. def handle_v3_file(self, f_name, subdir, stream, compressed=True,
  274. encrypted=True):
  275. # create inner archive
  276. tar_cmdline = ["tar", "-Pc", '--sparse',
  277. '-C', self.fullpath(os.path.dirname(f_name)),
  278. '--xform', 's:^%s:%s\\0:' % (
  279. os.path.basename(f_name),
  280. subdir),
  281. os.path.basename(f_name)
  282. ]
  283. if compressed:
  284. tar_cmdline.insert(-1, "--use-compress-program=%s" % "gzip")
  285. tar = subprocess.Popen(tar_cmdline, stdout=subprocess.PIPE)
  286. if encrypted:
  287. encryptor = subprocess.Popen(
  288. ["openssl", "enc", "-e", "-aes-256-cbc", "-pass", "pass:qubes"],
  289. stdin=tar.stdout,
  290. stdout=subprocess.PIPE)
  291. data = encryptor.stdout
  292. else:
  293. data = tar.stdout
  294. stage1_dir = self.fullpath(os.path.join("stage1", subdir))
  295. if not os.path.exists(stage1_dir):
  296. os.makedirs(stage1_dir)
  297. subprocess.check_call(["split", "--numeric-suffixes",
  298. "--suffix-length=3",
  299. "--bytes="+str(100*1024*1024), "-",
  300. os.path.join(stage1_dir,
  301. os.path.basename(f_name+"."))],
  302. stdin=data)
  303. for part in sorted(os.listdir(stage1_dir)):
  304. if not re.match(
  305. r"^{}.[0-9][0-9][0-9]$".format(os.path.basename(f_name)),
  306. part):
  307. continue
  308. part_with_dir = os.path.join(subdir, part)
  309. self.calculate_hmac(os.path.join("stage1", part_with_dir))
  310. self.append_backup_stream(part_with_dir, stream,
  311. basedir=self.fullpath("stage1"))
  312. self.append_backup_stream(part_with_dir+".hmac", stream,
  313. basedir=self.fullpath("stage1"))
  314. def create_v3_backup(self, encrypted=True, compressed=True):
  315. """
  316. Create "backup format 3" backup - used in R2 and R3.0
  317. :param encrypt: Should the backup be encrypted
  318. :return:
  319. """
  320. output = open(self.fullpath("backup.bin"), "w")
  321. f = open(self.fullpath("backup-header"), "w")
  322. f.write(BACKUP_HEADER_R2.format(
  323. encrypted=str(encrypted),
  324. compressed=str(compressed)
  325. ))
  326. f.close()
  327. self.calculate_hmac("backup-header")
  328. self.append_backup_stream("backup-header", output)
  329. self.append_backup_stream("backup-header.hmac", output)
  330. f = open(self.fullpath("qubes.xml"), "w")
  331. if encrypted:
  332. qubesxml = QUBESXML_R2
  333. for vmname, subdir in MANGLED_SUBDIRS_R2.items():
  334. qubesxml = re.sub(r"[a-z-]*/{}".format(vmname),
  335. subdir, qubesxml)
  336. f.write(qubesxml)
  337. else:
  338. f.write(QUBESXML_R2)
  339. f.close()
  340. self.handle_v3_file("qubes.xml", "", output, encrypted=encrypted,
  341. compressed=compressed)
  342. self.create_v1_files(r2b2=True)
  343. for vm_type in ["appvms", "servicevms"]:
  344. for vm_name in os.listdir(self.fullpath(vm_type)):
  345. vm_dir = os.path.join(vm_type, vm_name)
  346. for f_name in os.listdir(self.fullpath(vm_dir)):
  347. if encrypted:
  348. subdir = MANGLED_SUBDIRS_R2[vm_name]
  349. else:
  350. subdir = vm_dir
  351. self.handle_v3_file(
  352. os.path.join(vm_dir, f_name),
  353. subdir+'/', output, encrypted=encrypted)
  354. for vm_name in os.listdir(self.fullpath("vm-templates")):
  355. vm_dir = os.path.join("vm-templates", vm_name)
  356. if encrypted:
  357. subdir = MANGLED_SUBDIRS_R2[vm_name]
  358. else:
  359. subdir = vm_dir
  360. self.handle_v3_file(
  361. os.path.join(vm_dir, "."),
  362. subdir+'/', output, encrypted=encrypted)
  363. output.close()
  364. def test_100_r1(self):
  365. self.create_v1_files(r2b2=False)
  366. f = open(self.fullpath("qubes.xml"), "w")
  367. f.write(QUBESXML_R1)
  368. f.close()
  369. self.restore_backup(self.backupdir,
  370. options={
  371. 'use-default-template': True,
  372. 'use-default-netvm': True,
  373. },
  374. expect_errors=['Kernel None not installed, using default one']
  375. )
  376. with self.assertNotRaises(KeyError):
  377. vm = self.app.domains["test-template-clone"]
  378. vm = self.app.domains["test-testproxy"]
  379. vm = self.app.domains["test-work"]
  380. vm = self.app.domains["test-standalonevm"]
  381. vm = self.app.domains["test-custom-template-appvm"]
  382. self.assertEqual(self.app.domains["test-custom-template-appvm"]
  383. .template,
  384. self.app.domains["test-template-clone"])
  385. def test_200_r2b2(self):
  386. self.create_v1_files(r2b2=True)
  387. f = open(self.fullpath("qubes.xml"), "w")
  388. f.write(QUBESXML_R2B2)
  389. f.close()
  390. self.restore_backup(self.backupdir, options={
  391. 'use-default-template': True,
  392. })
  393. with self.assertNotRaises(KeyError):
  394. vm = self.app.domains["test-template-clone"]
  395. vm = self.app.domains["test-testproxy"]
  396. vm = self.app.domains["test-work"]
  397. vm = self.app.domains["test-testhvm"]
  398. vm = self.app.domains["test-standalonevm"]
  399. vm = self.app.domains["test-custom-template-appvm"]
  400. self.assertEqual(self.app.domains["test-custom-template-appvm"]
  401. .template,
  402. self.app.domains["test-template-clone"])
  403. def test_210_r2(self):
  404. self.create_v3_backup(False)
  405. self.restore_backup(self.fullpath("backup.bin"), options={
  406. 'use-default-template': True,
  407. 'use-default-netvm': True,
  408. })
  409. with self.assertNotRaises(KeyError):
  410. vm = self.app.domains["test-template-clone"]
  411. vm = self.app.domains["test-testproxy"]
  412. vm = self.app.domains["test-work"]
  413. vm = self.app.domains["test-testhvm"]
  414. vm = self.app.domains["test-standalonevm"]
  415. vm = self.app.domains["test-custom-template-appvm"]
  416. self.assertEqual(self.app.domains["test-custom-template-appvm"]
  417. .template,
  418. self.app.domains["test-template-clone"])
  419. def test_220_r2_encrypted(self):
  420. self.create_v3_backup(True)
  421. self.restore_backup(self.fullpath("backup.bin"), options={
  422. 'use-default-template': True,
  423. 'use-default-netvm': True,
  424. })
  425. with self.assertNotRaises(KeyError):
  426. vm = self.app.domains["test-template-clone"]
  427. vm = self.app.domains["test-testproxy"]
  428. vm = self.app.domains["test-work"]
  429. vm = self.app.domains["test-testhvm"]
  430. vm = self.app.domains["test-standalonevm"]
  431. vm = self.app.domains["test-custom-template-appvm"]
  432. self.assertEqual(self.app.domains["test-custom-template-appvm"]
  433. .template,
  434. self.app.domains["test-template-clone"])