Exemplo n.º 1
0
def do_sign(args):
    if args.rsa_pkcs1_15:
        keys.sign_rsa_pss = False

    version_num = next_version_number(args, version.decode_version("0"),
                                      "lastVerNum.txt")

    if args.security_counter is None:
        # Security counter has not been explicitly provided,
        # generate it from the version number
        args.security_counter = ((version_num.major << 24) +
                                 (version_num.minor << 16) +
                                 version_num.revision)

    img = image.Image.load(args.infile,
                           version=version_num,
                           header_size=args.header_size,
                           security_cnt=args.security_counter,
                           included_header=args.included_header,
                           pad=args.pad)
    key = keys.load(args.key) if args.key else None
    img.sign(key, find_load_address(args))

    if args.pad:
        img.pad_to(args.pad, args.align)

    img.save(args.outfile)
Exemplo n.º 2
0
def do_sign(args):
    if args.rsa_pkcs1_15:
        keys.sign_rsa_pss = False

    version_num = next_version_number(args, version.decode_version("0"),
                                      "lastVerNum.txt")

    if args.security_counter is None:
        # Security counter has not been explicitly provided,
        # generate it from the version number
        args.security_counter = ((version_num.major << 24) +
                                 (version_num.minor << 16) +
                                 version_num.revision)

    pad_size = macro_parser.evaluate_macro(args.layout, sign_bin_size_re, 0, 1)
    img = image.Image.load(args.infile,
                           version=version_num,
                           header_size=args.header_size,
                           security_cnt=args.security_counter,
                           included_header=args.included_header,
                           pad=pad_size)
    key = keys.load(args.key, args.public_key_format) if args.key else None
    ram_load_address = macro_parser.evaluate_macro(args.layout,
                                                   image_load_address_re, 0, 1)
    img.sign(key, ram_load_address, args.dependencies)

    if pad_size:
        img.pad_to(pad_size, args.align)

    img.save(args.outfile)
Exemplo n.º 3
0
def get_last_version(path):
    if (os.path.isfile(path) == False):  # Version file not present
        return None
    else:  # Version file is present, check it has a valid number inside it
        with open(path, "r") as oldFile:
            fileContents = oldFile.read()
            if version.version_re.match(fileContents):  # number is valid
                return version.decode_version(fileContents)
            else:
                return None
Exemplo n.º 4
0
def do_sign(args):
    if args.rsa_pkcs1_15:
        keys.sign_rsa_pss = False
    img = image.Image.load(args.infile,
                           version=next_version_number(
                               args, version.decode_version("0"),
                               "lastVerNum.txt"),
                           header_size=args.header_size,
                           included_header=args.included_header,
                           pad=args.pad)
    key = keys.load(args.key) if args.key else None
    img.sign(key, find_load_address(args))

    if args.pad:
        img.pad_to(args.pad, args.align)

    img.save(args.outfile)
Exemplo n.º 5
0
def get_dependencies(text):
    if text is not None:
        versions = []
        images = re.findall(r"\((\d+)", text)
        if len(images) == 0:
            msg = "Image dependency format is invalid: {}".format(text)
            raise argparse.ArgumentTypeError(msg)
        raw_versions = re.findall(r",\s*([0-9.+]+)\)", text)
        if len(images) != len(raw_versions):
            msg = '''There's a mismatch between the number of dependency images
            and versions in: {}'''.format(text)
            raise argparse.ArgumentTypeError(msg)
        for raw_version in raw_versions:
            try:
                versions.append(version.decode_version(raw_version))
            except ValueError as e:
                print(e)
        dependencies = dict()
        dependencies[image.DEP_IMAGES_KEY] = images
        dependencies[image.DEP_VERSIONS_KEY] = versions
        return dependencies