From patchwork Mon Jun 3 08:56:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1942763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=Ir1EHJvA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::d3a; helo=mail-io1-xd3a.google.com; envelope-from=swupdate+bncbcwivbv7sugrbl4k62zamgqekxfz6ea@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-io1-xd3a.google.com (mail-io1-xd3a.google.com [IPv6:2607:f8b0:4864:20::d3a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vt6yr1STBz20Q1 for ; Mon, 3 Jun 2024 18:56:20 +1000 (AEST) Received: by mail-io1-xd3a.google.com with SMTP id ca18e2360f4ac-7e8e2ea7b4bsf562268139f.0 for ; Mon, 03 Jun 2024 01:56:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717404976; cv=pass; d=google.com; s=arc-20160816; b=hz7kkdpDShoeq1ULaznPj5IWpO14WnmEIx//Ck217QpPXfn8HJh2pjn4xjy50ZVyxF pDI3IiH7MsxpSLeaFagJ9QZUkS6MaUoiRHLRcB8saIllHh1mYYQj58qp0fO+hVQpHVoJ mpuPfuLcTcagOv5S/sisamo1+N8s/IppijH/hPjfAk8YjQxJbvrMQiNl1yppGSWGeyHd RiF84gCN4UKQDX1drWx48Gy6jJYxtmk2uHqncOLMVJl64eZi7QRT9XYPdtIQE9ViJGae 3r4wP8dISSrmC9ysjUJomv8VnwYM8GNSytqDgg1xoFT4Ts0pwUIhlbIefbuBw4Qrot/O 2xmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=aiC//9xgeuHC1agPZcsNrGsug4Cfhx4BgFzYAOCDjD0=; fh=EbMGLvcbZ1eDbsknTbat7edTyFPzO0OrKcdD8Ai7aS8=; b=AfuvEst10mUCZ7sipKCZsea4C4GVVSuVuyAzt8GmNf5QBlE9pGl4yRaHGmKmF7frTJ XK4aJj8KURuoE31IbFeXC3jjz3NwG2zQ/nV/kXnKvSk0je7cjU9hH+R6+IbqeYESov92 gQzju8b4boSSM+aBBCt2/t/Gurk5hrH9E/JtJFVuT7NRqJGM9EUEzRO1+j0fC8IEcnbG 5ZzLyOx0YZM75eJ2KBhCgJeFeTxZJpuU2p59SezI0IZ1etf+tmIqUM2vJMZpl0Mlg0XI xeVXFd39L1JhZsazLQVAjpCcOBj3Vgvxx533oht7WmUJ6SDZnMP3VCHQlAzw9yLJ4Ak6 qCAQ==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=HAn+WpI0; dkim=pass header.i=@atmark-techno.com header.s=google header.b=MaHrexgV; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1717404976; x=1718009776; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=aiC//9xgeuHC1agPZcsNrGsug4Cfhx4BgFzYAOCDjD0=; b=Ir1EHJvAEjsnb9bPGkYSTSKhid1DKjjhyKYyc59g/Qn4hGSG2fZHJ/tUCWvzn5cSQW Vi6QmRvl2AHIm9BahPAmquQpfmqu4rPBqFP2CQRAMqEj/ADvYovJgV89lUp3TVOv+0vS YRyaX7oUY/IXJGNiGuxwRBZrwuE1b3eH5nKGs1IaAHoDbhiSfnUFlcm1FxmKOMn/NI/m /Urb5gx+SqGWU5XaBarEiNWMdsOpD8Ibcju0RDLzAYPi3x/BJUjU95aw6rNIaCnLq11B ALDzcGLtwD2iWxgyE3ACOc5pWoUduGI+lfPsPHVSwnauE8K/lpPk7cSzds43qL8TtxCb FosA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717404976; x=1718009776; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=aiC//9xgeuHC1agPZcsNrGsug4Cfhx4BgFzYAOCDjD0=; b=vmo0N8DAhJvWA1nN85HSUwELQUBadSp5oV/jHkqCaDLQxweAE+7rEbqTDI1pF2qEGD 51U7LgWTVF2h0Zfm78VQlip+hD13S4AMY3I3iT2vPudfDIaDkSoSQwxhVQMisvm+Vq8+ DrmM3hheTa7Cxl8seWffYS+VapOZBfkew9iUrrrKs5/Zt+/iBwDrqwbTXZPvVs8tSEQ+ BgN4PjtwaojbzT0DGm+1sAEidXpOB3Dg36B/sD0BHFDbOng1AvZAGIYVW6F9JO0YFBql CRlPza1w2HFGd++MVPrDSTMSMayRiq7JCNgJVOCwbnfZ26hgrCI3eq5Iblc79Aoel261 9d+A== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCUxH/aoYMGXgEcJxN4Mo2YUn9jaX4WkUjLKjVHqpdCivQe51VC552UMB9l8yBQfJB5pm8SeXB68CgXXkbWAkBRVDUy3gdrogjQSj3jhdA== X-Gm-Message-State: AOJu0Yxh80whl2A09pSdYLp3MoumahY2RKWLisTN/CeQsfA4dHo+5VHw 6+8e3SpG7RLD0JTVW4/KIS1KAt+FApkmthR7vxcGqb+TYiR4nk7G X-Google-Smtp-Source: AGHT+IEY14qyO4SmWr9GjYTBBlulwiLSQmOOrMgX2Xx+CV+hqXUUTmE9aJibFQm769sB8VGmFvqw2Q== X-Received: by 2002:a05:6e02:12e8:b0:374:a3b5:7c47 with SMTP id e9e14a558f8ab-374a3b57f06mr7339905ab.16.1717404976381; Mon, 03 Jun 2024 01:56:16 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a92:c24c:0:b0:374:a461:6a03 with SMTP id e9e14a558f8ab-374a4616d9fls1243565ab.0.-pod-prod-07-us; Mon, 03 Jun 2024 01:56:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXngDnD4DT2ukwoLEsTjwVtwJPRInxU/mEnexYr05oIVKi7rOJFSLtqI5zYwMrb621bxGQ3ztaVGWdmzZYzUNJUMquXgNIqf1KR X-Received: by 2002:a92:d08f:0:b0:374:9307:51ed with SMTP id e9e14a558f8ab-3749307a948mr53401675ab.5.1717404975227; Mon, 03 Jun 2024 01:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717404975; cv=none; d=google.com; s=arc-20160816; b=LwMYzklHj5j2G9Luv/6M4QXaC5SFp4ixg/ACf6GpPvVnd+VVVAALBTyx+NKqZN2/HP pYI5qZQAmwIKOVLKRvVhk07PFkJHT+wNUxuvuI0iva751jCZ2M3w6VpbQpc6yuhJzJrf AXCuhbBKmBW+mSAvO3etl8NrR9aiCm5dzja8PbULjCKnoDrh8ujO0ilY5GpNbpU8L9bg dXzS9zc9Ma9o6+yS4xHVquscBBdSxb09FfWMAYxZE+1ymw8b0UaR4lhBC7sEw2wIwnEx LemKsmjVne104qv1rqOia8f/Otx0WienCSerW5Kw20z+uQd42IoixahClzRKVYARi9+a GXTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=UXHJrxCgqokXBZ6IYOYf2srqXfKv3cvr/CxchLPvD+Y=; fh=iYmKn1X/OIDRUxDaaEMqCeLpY2PkI/4ifttWAXiZSXc=; b=SR41Z7ohAB2Ff7utvFTPJ2wsQpJkuwOKk4IicX/U3aL8KzIRkWDF/KoIf5/cj2wo92 TgMaVDLW3MSdJhRW7pz/+N5rfDsdy7Osf0HySDxfKhk8CfKVBYOQsepVVcgagwblHyAj YY/XDWSYYuGqXGd3Ip3RyXULTx58sIylkF1VETzrELDLpgZjVxEAE9A7QUfGe5fif6en 5rCBPIpYYDajxrpo5U521mDmGrYO/KsfzvfM/TiEErRZpp7WKoJXtwsnsUHwafXXjcB4 9BMqPbtTqxts4txypO2y1qRVL+3/+aah12l76jPtDtL8zs21yvbjDZMIATQ7jx59Zhfk kA7A==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=HAn+WpI0; dkim=pass header.i=@atmark-techno.com header.s=google header.b=MaHrexgV; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTPS id e9e14a558f8ab-3748a1f54b9si3151865ab.1.2024.06.03.01.56.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 01:56:15 -0700 (PDT) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 65B13A88 for ; Mon, 3 Jun 2024 17:56:12 +0900 (JST) Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by gw2.atmark-techno.com (Postfix) with ESMTPS id 644CBA7C for ; Mon, 3 Jun 2024 17:56:10 +0900 (JST) Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-1f67f27bea9so4591195ad.0 for ; Mon, 03 Jun 2024 01:56:10 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXkCf5LCGOgaH4u0kVKmMb1cDMdv+NSOouEV+u3fIVBxmnH4Nq9EAiBumSeKkOjkFtQ4uIDeYftKFfv8J/foYogZZ2l2vk64XHl X-Received: by 2002:a17:902:ecc9:b0:1f6:8832:7e83 with SMTP id d9443c01a7336-1f688328239mr3946905ad.26.1717404969371; Mon, 03 Jun 2024 01:56:09 -0700 (PDT) X-Received: by 2002:a17:902:ecc9:b0:1f6:8832:7e83 with SMTP id d9443c01a7336-1f688328239mr3946735ad.26.1717404968918; Mon, 03 Jun 2024 01:56:08 -0700 (PDT) Received: from pc-0182.atmarktech (145.82.198.104.bc.googleusercontent.com. [104.198.82.145]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f63236692bsm59776905ad.92.2024.06.03.01.56.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2024 01:56:08 -0700 (PDT) Received: from [::1] (helo=pc-0182.atmark.tech) by pc-0182.atmarktech with esmtp (Exim 4.96) (envelope-from ) id 1sE3U6-009riT-1a; Mon, 03 Jun 2024 17:56:06 +0900 From: Dominique Martinet To: stefano.babic@swupdate.org, swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH RFC 8/9] config parsing: add handling for chunked_hashes Date: Mon, 3 Jun 2024 17:56:01 +0900 Message-Id: <20240603085602.2351411-9-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240603085602.2351411-1-dominique.martinet@atmark-techno.com> References: <20240603085602.2351411-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=HAn+WpI0; dkim=pass header.i=@atmark-techno.com header.s=google header.b=MaHrexgV; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , This allows something like this to be fed to the new chunked_hashes code (libconfig syntax): ----- images: ( { filename = "somefile.tar.zst"; name = "version"; version = "1"; install-if-higher = true; compressed = "zstd"; encrypted = true; ivt = "3b627a40272e3ba253794680e6f870c9"; installed-directly = true; sha256 = "e437493d207e7dabfba69997072b938bcb93175eea09d4108b96825d1fc2b079"; chunked_hashes = ( "3028e787495f7a97bfb6c10110affed016d398374d8c2c02fd7d02bc84f75e68", "5280083a531be033af6bb31a579737fb296739c0d9fa100457ce328fdfad01d8", ); type = "archive"; path = "/tmp/swupdate"; properties: { create-destination = "true"; }; }, ); ----- Note the sha256 is ignored if chunked_hashes is found in copyfile(), but we've left it so this is installable by older versions of swupdate. Signed-off-by: Dominique Martinet --- core/cpio_utils.c | 1 + core/installer.c | 1 + core/parsing_library.c | 50 ++++++++++++++++++++++++++++++++++++++++ include/parselib.h | 3 +++ include/swupdate_image.h | 1 + parser/parser.c | 5 ++++ 6 files changed, 61 insertions(+) diff --git a/core/cpio_utils.c b/core/cpio_utils.c index d296fe8d4525..fd52c9ef0ba6 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -847,6 +847,7 @@ int copyimage(void *out, struct img_type *img, writeimage callback) .compressed = img->compressed, .checksum = &img->checksum, .hash = img->sha256, + .chunked_hashes = img->chunked_hashes, .encrypted = img->is_encrypted, .imgivt = img->ivt_ascii, }; diff --git a/core/installer.c b/core/installer.c index 0cb06b2ca419..2a2b0f6cf32b 100644 --- a/core/installer.c +++ b/core/installer.c @@ -512,6 +512,7 @@ static void cleaup_img_entry(struct img_type *img) void free_image(struct img_type *img) { dict_drop_db(&img->properties); + free(img->chunked_hashes); free(img); } diff --git a/core/parsing_library.c b/core/parsing_library.c index 038c6851adf9..b0f0e68df04e 100644 --- a/core/parsing_library.c +++ b/core/parsing_library.c @@ -210,6 +210,56 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) ascii_to_hash(hash, hash_ascii); } +#ifdef CONFIG_CHUNKED_HASH +int get_chunked_hashes(parsertype p, void *elem, unsigned char **chunked_hashes) +{ + void *hashes_node = get_child(p, elem, "chunked_hashes"); + + /* does not have chunked hashes */ + if (!hashes_node) + return 0; + + int count = get_array_length(p, hashes_node); + if (!count) { + ERROR("chunked_hashes is not an array"); + return -EINVAL; + } + + unsigned char *hashes = malloc((count+1) * SHA256_HASH_LENGTH); + if (!hashes) { + ERROR("No memory: failed for %d bytes", (count+1) * SHA256_HASH_LENGTH); + return -ENOMEM; + } + + int idx; + for (idx = 0; idx < count; idx++) { + void *hash_node = get_elem_from_idx(p, hashes_node, idx); + if (!hash_node) { + ERROR("Could not get %dth hash in %d long array?", idx, count); + free(hashes); + return -EINVAL; + } + const char *hash_str = get_field_string(p, hash_node, NULL); + if (!hash_str) { + ERROR("%dth hash in chunked hashes array was not a string?", idx); + free(hashes); + return -EINVAL; + } + if (ascii_to_hash(hashes + idx * SHA256_HASH_LENGTH, hash_str) < 0) { + ERROR("Invalid hash %s", hash_str); + free(hashes); + return -EINVAL; + } + } + + /* zero final hash marking end of array */ + memset(hashes + count * SHA256_HASH_LENGTH, 0, SHA256_HASH_LENGTH); + + *chunked_hashes = hashes; + return 0; +} +#endif + bool set_find_path(const char **nodes, const char *newpath, char ***tmp) { char **paths; diff --git a/include/parselib.h b/include/parselib.h index 48f38d2a8c92..0a8c3842e3fb 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -61,6 +61,9 @@ void iterate_field(parsertype p, void *e, iterate_callback cb, void *data); void get_field(parsertype p, void *e, const char *path, void *dest, field_type_t type); int exist_field_string(parsertype p, void *e, const char *path); void get_hash_value(parsertype p, void *elem, unsigned char *hash); +#ifdef CONFIG_CHUNKED_HASH +int get_chunked_hashes(parsertype p, void *elem, unsigned char **chunked_hashes); +#endif void check_field_string(const char *src, char *dst, const size_t max_len); void *find_root(parsertype p, void *root, const char **nodes); void *get_node(parsertype p, void *root, const char **nodes); diff --git a/include/swupdate_image.h b/include/swupdate_image.h index e214aafc2965..cb51da4325a3 100644 --- a/include/swupdate_image.h +++ b/include/swupdate_image.h @@ -75,6 +75,7 @@ struct img_type { long long size; unsigned int checksum; unsigned char sha256[SHA256_HASH_LENGTH]; /* SHA-256 is 32 byte */ + unsigned char *chunked_hashes; LIST_ENTRY(img_type) next; }; diff --git a/parser/parser.c b/parser/parser.c index 2273796e0452..12420554837c 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -421,6 +421,11 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im GET_FIELD_STRING(p, elem, "type", image->type); GET_FIELD_STRING(p, elem, "data", image->type_data); get_hash_value(p, elem, image->sha256); +#ifdef CONFIG_CHUNKED_HASH + if (get_chunked_hashes(p, elem, &image->chunked_hashes)) { + return -1; + } +#endif /* * offset can be set as number or string. As string,