def test_version_hex_too_big(self):
        with self.subTest("hex string too big"):
            with self.assertRaises(ValueError):
                InfGenerator("test_name", "provider",
                             InfGeneratorTest.VALID_GUID_STRING, "x64",
                             "description", "aa.bb", "0x100000000")

        with self.subTest("decimal too big") as b:
            with self.assertRaises(ValueError) as cm:
                InfGenerator("test_name", "provider",
                             InfGeneratorTest.VALID_GUID_STRING, "x64",
                             "description", "aa.bb", "4294967296")
    def test_version_string_format(self):
        with self.subTest(version_string="zero ."):
            with self.assertRaises(ValueError):
                InfGenerator("test_name", "provider",
                             InfGeneratorTest.VALID_GUID_STRING, "x64",
                             "description", "1234", "0x100000000")

        with self.subTest(version_string="> 3 ."):
            with self.assertRaises(ValueError):
                InfGenerator("test_name", "provider",
                             InfGeneratorTest.VALID_GUID_STRING, "x64",
                             "description", "1.2.3.4.5", "0x100000000")
Пример #3
0
    def PackageWindowsCapsuleFiles(OutputFolder,
                                   ProductName,
                                   ProductFmpGuid,
                                   CapsuleVersion_DotString,
                                   CapsuleVersion_HexString,
                                   ProductFwProvider,
                                   ProductFwMfgName,
                                   ProductFwDesc,
                                   CapsuleFileName,
                                   PfxFile=None,
                                   PfxPass=None,
                                   Rollback=False,
                                   Arch='amd64',
                                   OperatingSystem_String='Win10'):

        logging.debug("CapsulePackage: Create Windows Capsule Files")

        #Make INF
        InfFilePath = os.path.join(OutputFolder, ProductName + ".inf")
        InfTool = InfGenerator(ProductName, ProductFwProvider, ProductFmpGuid,
                               Arch, ProductFwDesc, CapsuleVersion_DotString,
                               CapsuleVersion_HexString)
        InfTool.Manufacturer = ProductFwMfgName  #optional
        ret = InfTool.MakeInf(InfFilePath, CapsuleFileName, Rollback)
        if (ret != 0):
            raise Exception("CreateWindowsInf Failed with errorcode %d" % ret)

        #Make CAT
        CatFilePath = os.path.realpath(
            os.path.join(OutputFolder, ProductName + ".cat"))
        CatTool = CatGenerator(Arch, OperatingSystem_String)
        ret = CatTool.MakeCat(CatFilePath)

        if (ret != 0):
            raise Exception("Creating Cat file Failed with errorcode %d" % ret)

        if (PfxFile is not None):
            #Find Signtool
            SignToolPath = os.path.join(os.getenv("ProgramFiles(x86)"),
                                        "Windows Kits", "8.1", "bin", "x64",
                                        "signtool.exe")
            if not os.path.exists(SignToolPath):
                SignToolPath = SignToolPath.replace('8.1', '10')
            if not os.path.exists(SignToolPath):
                raise Exception("Can't find signtool on this machine.")
            #dev sign the cat file
            ret = CatalogSignWithSignTool(SignToolPath, CatFilePath, PfxFile,
                                          PfxPass)
            if (ret != 0):
                raise Exception("Signing Cat file Failed with errorcode %d" %
                                ret)

        return ret
    def test_invalid_name_symbol(self):

        InvalidChars = [
            '~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', ' ',
            '{', '[', '}', ']', '+', '='
        ]
        for a in InvalidChars:
            with self.subTest(name="test{}name".format(a)):
                name = "test{}name".format(a)
                with self.assertRaises(ValueError) as cm:
                    InfGenerator(name, "provider",
                                 InfGeneratorTest.VALID_GUID_STRING, "x64",
                                 "description", "aa.bb", "0xaabbccdd")
    def test_valid(self):
        o = InfGenerator("test_name", "provider",
                         InfGeneratorTest.VALID_GUID_STRING, "x64",
                         "description", "aa.bb.cc.dd", "0xaabbccdd")
        self.assertIsInstance(o, InfGenerator)
        self.assertEqual(o.Name, "test_name")
        self.assertEqual(o.Provider, "provider")
        self.assertEqual(o.EsrtGuid, InfGeneratorTest.VALID_GUID_STRING)
        self.assertEqual(o.Arch, InfGenerator.SUPPORTED_ARCH["x64"])
        self.assertEqual(o.Description, "description")
        self.assertEqual(int(o.VersionHex, 0), int("0xaabbccdd", 0))
        self.assertEqual(o.VersionString, "aa.bb.cc.dd")
        self.assertEqual(o.Manufacturer, "provider")

        #loop thru all supported arch and make sure it works
        for a in InfGenerator.SUPPORTED_ARCH.keys():
            with self.subTest(Arch=a):
                o.Arch = a
                self.assertEqual(InfGenerator.SUPPORTED_ARCH[a], o.Arch)

        #set manufacturer
        o.Manufacturer = "manufacturer"
        self.assertEqual("manufacturer", o.Manufacturer)
 def test_invalid_guid_format(self):
     with self.assertRaises(ValueError):
         o = InfGenerator("test_name", "provider", "NOT A VALID GUID",
                          "x64", "description", "aa.bb", "0x1000000")
 def test_version_hex_can_support_decimal(self):
     o = InfGenerator("test_name", "provider",
                      InfGeneratorTest.VALID_GUID_STRING, "x64",
                      "description", "aa.bb.cc.dd", "12356")
     self.assertEqual(int(o.VersionHex, 0), 12356)
Пример #8
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Generate Windows Firmware Update Platform Files for Capsules')
    parser.add_argument("name", help="Firmware Name. No spaces")
    parser.add_argument("provider", help="Firmware provider listed in INF")
    parser.add_argument("description",
                        help="Firmware description listed in INF")
    parser.add_argument("version_string",
                        help="Version String in form of XX.XX.XX[.XX]")
    parser.add_argument(
        "version_hex",
        help=
        "Version String in Hex 0xAABBCCDD must be representable within 32bit")
    parser.add_argument(
        "esrt_guid",
        help=
        "guid string in registry format (########-####-####-####-############) for this ESRT entry"
    )
    parser.add_argument("firmware_bin_file_path",
                        help="full path to firmware bin / capsule file")
    parser.add_argument('arch',
                        choices=InfGenerator.SUPPORTED_ARCH,
                        help="Architecture targeted by INF and CAT")
    parser.add_argument('operating_sytem',
                        choices=CatGenerator.SUPPORTED_OS,
                        help="operating system targeted by INF and CAT")
    parser.add_argument("--mfgname", help="Manufacturer name listed in INF")
    parser.add_argument("--rollback",
                        action="store_true",
                        dest="rollback",
                        help="build a rollback capsule",
                        default=False)
    parser.add_argument(
        "--pfx_file",
        help=
        "Full Path to PFX file.  If not set then signing will not be performed."
    )
    parser.add_argument(
        "--pfx_pass",
        help="Password for PFX file.  Optional based on PFX file")

    #Turn on dubug level logging
    parser.add_argument("--debug",
                        action="store_true",
                        dest="debug",
                        help="turn on debug logging level for file log",
                        default=False)
    #Output debug log
    parser.add_argument("-l",
                        dest="OutputLog",
                        help="Create an output debug log file: ie -l out.txt",
                        default=None)

    args = parser.parse_args()

    #setup file based logging if outputReport specified
    if (args.OutputLog):
        if (len(args.OutputLog) < 2):
            logging.critical("the output log file parameter is invalid")
            return -2
        else:
            #setup file based logging
            filelogger = logging.FileHandler(filename=args.OutputLog, mode='w')
            if (args.debug):
                filelogger.setLevel(logging.DEBUG)
            else:
                filelogger.setLevel(logging.INFO)

            filelogger.setFormatter(formatter)
            logging.getLogger('').addHandler(filelogger)

    logging.info("Log Started: " + datetime.datetime.strftime(
        datetime.datetime.now(), "%A, %B %d, %Y %I:%M%p"))
    OutputFolder = os.path.dirname(args.firmware_bin_file_path)
    FirmwareFile = os.path.basename(args.firmware_bin_file_path)

    logging.debug("Make INF")
    #Make INF
    InfFilePath = os.path.join(OutputFolder, args.name + ".inf")
    InfTool = InfGenerator(args.name, args.provider, args.esrt_guid, args.arch,
                           args.description, args.version_string,
                           args.version_hex)
    if (args.mfgname is not None):
        InfTool.Manufacturer = args.mfgname  #optional
    ret = InfTool.MakeInf(InfFilePath, FirmwareFile, args.rollback)
    if (ret != 0):
        logging.critical("CreateWindowsInf Failed with errorcode %d" % ret)
        return ret

    #Make CAT
    CatFilePath = os.path.realpath(
        os.path.join(OutputFolder, args.name + ".cat"))
    CatTool = CatGenerator(args.arch, args.operating_sytem)
    ret = CatTool.MakeCat(CatFilePath)

    if (ret != 0):
        logging.critical("Creating Cat file Failed with errorcode %d" % ret)
        return ret

    if (args.pfx_file is not None):
        logging.debug("PFX file set.  Going to do signing")
        #Find Signtool
        SignToolPath = os.path.join(os.getenv("ProgramFiles(x86)"),
                                    "Windows Kits", "8.1", "bin", "x64",
                                    "signtool.exe")
        if not os.path.exists(SignToolPath):
            logging.debug("Failed to find 8.1 version of signtool. Trying 10")
            SignToolPath = SignToolPath.replace('8.1', '10')

        if not os.path.exists(SignToolPath):
            logging.critical("Can't find signtool on this machine.")
            return -3
        #dev sign the cat file
        ret = CatalogSignWithSignTool(SignToolPath, CatFilePath, args.pfx_file,
                                      args.pfx_pass)
        if (ret != 0):
            logging.critical("Signing Cat file Failed with errorcode %d" % ret)
            return ret
    else:
        logging.info("No PFX. Not signing")

    return ret