From patchwork Wed Aug 1 19:03:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10552831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AD3713BF for ; Wed, 1 Aug 2018 19:04:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59E442BA07 for ; Wed, 1 Aug 2018 19:04:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E3D22BACC; Wed, 1 Aug 2018 19:04:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E42D32BA07 for ; Wed, 1 Aug 2018 19:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387542AbeHAUvd (ORCPT ); Wed, 1 Aug 2018 16:51:33 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39620 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387528AbeHAUvc (ORCPT ); Wed, 1 Aug 2018 16:51:32 -0400 Received: by mail-wm0-f67.google.com with SMTP id q8-v6so153995wmq.4 for ; Wed, 01 Aug 2018 12:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=NvEOnXdSkKLj0Litiek/bSZ/qYubTvSJpSdSrsXB4rE=; b=CYEQHudhQGHDa27+AV97MK5Yl8TML/MpeWM2ot6+r2Mb4fZRR7T3Tem1ws/UyoG1kP rGCIuDRNwCepDpfkmYjyVngWc1HLgyUc9KCRVNGTpUduEhUNF7V7OP97HP6Tf4uiByQC fN05E4C/0rmpdxkev8rS4FdJrnRsz9wBQfeRZctQc2NTPa963jerDCFgaJ9I/Ko+9DGG VNGF3BNMFt4anfvp8xmPT+CLVOmkUWIRHxAnRt55rOCx5lynNeuVlWL93X4xzSbZc0G9 CVaF4F6VPW4oIEXSELQbfR54f+Pcgjx4RpvY/UJQbd9zk+K1zFK6M/z7qXn8lWsIWyj8 YMNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NvEOnXdSkKLj0Litiek/bSZ/qYubTvSJpSdSrsXB4rE=; b=OOqP69MPUcYHsXi9c4/X8OyCs/++BpGMXTSE01lt1pOBFPHbDeZ7umg/MViU/FcA1W cm7hSU3fmjQZwd5BtwsDPQHQWM/I6kPQDke8bCHqqhlRXy4SDVEGnsewnZ+rmYOF3fXT 9tSmMJxPuIxKGC00YiaCwUMb/nKgoYpmDU4c4X5JVEyZFxIR9Rc8KaSA1z6VALCyjXJa m+x0BguyGxlAOmJNc5z46UGgJwtKJxfEp9549jwlj5I62OUHllOeJU7ehV0JZOTOajMV ECRN4rUfWkBA1NW3p5el4oCMCJibeLoMDgkRVhshTVbpYgF92ty2/jffD7SH3Wna7iWS iKVQ== X-Gm-Message-State: AOUpUlGQApe3m2mf8vnRj2x3rZfPl6jYExpl55HClquShm0vKrE6dVnU BFXt/reKUziRsV54+1/xxo/teZDX X-Google-Smtp-Source: AAOMgpeUtBJQAPX0eg5pbOK+4ApxTzv9zvcTxDw+qYD79GlX573kD9jKbv4jXfg29Zg5Gm6c6jfAEw== X-Received: by 2002:a1c:6e07:: with SMTP id j7-v6mr81161wmc.126.1533150258912; Wed, 01 Aug 2018 12:04:18 -0700 (PDT) Received: from orange.redhat.com ([213.175.37.12]) by smtp.gmail.com with ESMTPSA id r17-v6sm15401322wrt.44.2018.08.01.12.04.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Aug 2018 12:04:18 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 4/8] libceph: factor out encrypt_authorizer() Date: Wed, 1 Aug 2018 21:03:46 +0200 Message-Id: <20180801190350.857-5-idryomov@gmail.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180801190350.857-1-idryomov@gmail.com> References: <20180801190350.857-1-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Will be used for encrypting both the initial and updated authorizers. Signed-off-by: Ilya Dryomov --- net/ceph/auth_x.c | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c index cd1118d106a5..61cccb93f653 100644 --- a/net/ceph/auth_x.c +++ b/net/ceph/auth_x.c @@ -290,6 +290,38 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac, return -EINVAL; } +/* + * Encode and encrypt the second part (ceph_x_authorize_b) of the + * authorizer. The first part (ceph_x_authorize_a) should already be + * encoded. + */ +static int encrypt_authorizer(struct ceph_x_authorizer *au) +{ + struct ceph_x_authorize_a *msg_a; + struct ceph_x_authorize_b *msg_b; + void *p, *end; + int ret; + + msg_a = au->buf->vec.iov_base; + WARN_ON(msg_a->ticket_blob.secret_id != cpu_to_le64(au->secret_id)); + p = (void *)(msg_a + 1) + le32_to_cpu(msg_a->ticket_blob.blob_len); + end = au->buf->vec.iov_base + au->buf->vec.iov_len; + + msg_b = p + ceph_x_encrypt_offset(); + msg_b->struct_v = 1; + msg_b->nonce = cpu_to_le64(au->nonce); + + ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b)); + if (ret < 0) + return ret; + + p += ret; + WARN_ON(p > end); + au->buf->vec.iov_len = p - au->buf->vec.iov_base; + + return 0; +} + static void ceph_x_authorizer_cleanup(struct ceph_x_authorizer *au) { ceph_crypto_key_destroy(&au->session_key); @@ -306,7 +338,6 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, int maxlen; struct ceph_x_authorize_a *msg_a; struct ceph_x_authorize_b *msg_b; - void *p, *end; int ret; int ticket_blob_len = (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0); @@ -350,21 +381,13 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac, dout(" th %p secret_id %lld %lld\n", th, th->secret_id, le64_to_cpu(msg_a->ticket_blob.secret_id)); - p = msg_a + 1; - p += ticket_blob_len; - end = au->buf->vec.iov_base + au->buf->vec.iov_len; - - msg_b = p + ceph_x_encrypt_offset(); - msg_b->struct_v = 1; get_random_bytes(&au->nonce, sizeof(au->nonce)); - msg_b->nonce = cpu_to_le64(au->nonce); - ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b)); - if (ret < 0) + ret = encrypt_authorizer(au); + if (ret) { + pr_err("failed to encrypt authorizer: %d", ret); goto out_au; + } - p += ret; - WARN_ON(p > end); - au->buf->vec.iov_len = p - au->buf->vec.iov_base; dout(" built authorizer nonce %llx len %d\n", au->nonce, (int)au->buf->vec.iov_len); return 0;