From patchwork Thu Jun 2 09:56:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nayna X-Patchwork-Id: 629161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rL3013Ylkz9t0r for ; Thu, 2 Jun 2016 20:10:57 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rL3012TLYzDvfj for ; Thu, 2 Jun 2016 20:10:57 +1000 (AEST) X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3rL2hy1ChyzDqxv for ; Thu, 2 Jun 2016 19:57:53 +1000 (AEST) Received: from pps.filterd (m0082756.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u529upoS008139 for ; Thu, 2 Jun 2016 05:57:52 -0400 Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) by mx0a-001b2d01.pphosted.com with ESMTP id 23ag2m4hjy-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 02 Jun 2016 05:57:52 -0400 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 2 Jun 2016 19:57:49 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 2 Jun 2016 19:57:46 +1000 X-IBM-Helo: d23dlp02.au.ibm.com X-IBM-MailFrom: nayna@linux.vnet.ibm.com X-IBM-RcptTo: petitboot@lists.ozlabs.org Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 82F6A2BB0054 for ; Thu, 2 Jun 2016 19:57:30 +1000 (EST) Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u529vK1X66453508 for ; Thu, 2 Jun 2016 19:57:25 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u529vJKf019695 for ; Thu, 2 Jun 2016 19:57:20 +1000 Received: from c365f16u1b3.pok.stglabs.ibm.com (c365f16u1b3.pok.stglabs.ibm.com [9.47.77.42]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u529v6cS019479; Thu, 2 Jun 2016 19:57:18 +1000 From: Nayna Jain To: petitboot@lists.ozlabs.org Subject: [PATCH 3/3] discover/pb-discover.c:Initialize security context. Date: Thu, 2 Jun 2016 05:56:58 -0400 X-Mailer: git-send-email 2.5.0 In-Reply-To: <1464861418-19709-1-git-send-email-nayna@linux.vnet.ibm.com> References: <1464861418-19709-1-git-send-email-nayna@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16060209-1617-0000-0000-00000127B623 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16060209-1618-0000-0000-000045FCF721 Message-Id: <1464861418-19709-4-git-send-email-nayna@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-02_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606020110 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hellerda@us.ibm.com, gcwilson@us.ibm.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Modifies discover/pb-discover.c to initialize trusted boot. Add discover/pb-secure.c to keep security initialization separate from other functionality. Signed-off-by: Nayna Jain --- discover/Makefile.am | 4 ++- discover/pb-discover.c | 9 +++++++ discover/pb-secure.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ discover/pb-secure.h | 17 +++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 discover/pb-secure.c create mode 100644 discover/pb-secure.h diff --git a/discover/Makefile.am b/discover/Makefile.am index 899c9a6..2fd5872 100644 --- a/discover/Makefile.am +++ b/discover/Makefile.am @@ -52,7 +52,9 @@ discover_pb_discover_SOURCES = \ discover/user-event.h \ discover/kboot-parser.c \ discover/yaboot-parser.c \ - discover/pxe-parser.c + discover/pxe-parser.c \ + discover/pb-secure.c \ + discover/pb-secure.h discover_pb_discover_LDADD = \ discover/grub2/grub2-parser.ro \ diff --git a/discover/pb-discover.c b/discover/pb-discover.c index fd37068..bfe165b 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -19,6 +19,7 @@ #include "device-handler.h" #include "sysinfo.h" #include "platform.h" +#include "pb-secure.h" static void print_version(void) { @@ -127,6 +128,7 @@ int main(int argc, char *argv[]) struct procset *procset; struct opts opts; FILE *log; + int rc = 0; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -188,6 +190,13 @@ int main(int argc, char *argv[]) if (config_get()->debug) pb_log_set_debug(true); + rc = secure_and_trusted_init(); + if (rc == -1) + { + pb_log("Failed to initialize trust\n"); + //Yet to finalize for action on failure of initializing trust\n"); + } + system_info_init(server); handler = device_handler_init(server, waitset, opts.dry_run == opt_yes); diff --git a/discover/pb-secure.c b/discover/pb-secure.c new file mode 100644 index 0000000..edb4ccc --- /dev/null +++ b/discover/pb-secure.c @@ -0,0 +1,69 @@ +#include + +#include +#include +#include +#include +#include + +#include "platform.h" +#include "pb-secure.h" + +int secure_and_trusted_init() +{ + int rc = 0; + rc = measure_boot_policy(); + return rc; +} + +int measure_boot_policy() +{ + const struct config* config; + unsigned char* config_str = 0; + + uint8_t digest[SHA256_DIGEST_SIZE]; + int rc = 0; + unsigned int i = 0; + + config = config_get(); + + //Record ipmi boot params + config_str = get_ipmi_boot_policy_as_string(config); + + memset(digest, 0, SHA256_DIGEST_SIZE); + rc = calc_digest("sha256", config_str, digest); + if (rc == -1) + return rc; + + for (i=0; i < sizeof(digest); i++) + { + pb_log("%02x ", digest[i]); + } + + pb_log("\n"); + rc = tpm_extend(5, "sha256", digest, SHA256_DIGEST_SIZE); + if (rc == -1) + return rc; + + + //Record nvram boot params + config_str = get_nvram_boot_policy_as_string(config); + + memset(digest, 0, SHA256_DIGEST_SIZE); + rc = calc_digest("sha256", config_str, digest); + if (rc == -1) + return rc; + + for (i=0; i < sizeof(digest); i++) + { + pb_log("%02x ", digest[i]); + } + + pb_log("\n"); + rc = tpm_extend(5, "sha256", digest, SHA256_DIGEST_SIZE); + + if (rc == -1) + return rc; + return 0; + +} diff --git a/discover/pb-secure.h b/discover/pb-secure.h new file mode 100644 index 0000000..f71aab1 --- /dev/null +++ b/discover/pb-secure.h @@ -0,0 +1,17 @@ +#ifndef _PB_SECURE_H +#define _PB_SECURE_H + +/** + * Setups and performs any security related operations or calls. + * Currently it just calls measure_boot_policy. + */ +int secure_and_trusted_init(void); + +/** + * Reads the boot policy, calculates the digest and extends to + * TPM to measure and record boot policy config values. + * It extends ipmi and nvram boot policy separately. + */ +int measure_boot_policy(void); + +#endif /* _PB_SECURE_H */