From dev-return-57160-archive-asf-public=cust-asf.ponee.io@directory.apache.org Wed Feb 7 19:08:11 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id C6CA718065B for ; Wed, 7 Feb 2018 19:08:11 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B6BFD160C5C; Wed, 7 Feb 2018 18:08:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D825C160C3A for ; Wed, 7 Feb 2018 19:08:10 +0100 (CET) Received: (qmail 44433 invoked by uid 500); 7 Feb 2018 18:08:10 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 44422 invoked by uid 99); 7 Feb 2018 18:08:10 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2018 18:08:10 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 50FD1C0042 for ; Wed, 7 Feb 2018 18:08:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -109.511 X-Spam-Level: X-Spam-Status: No, score=-109.511 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 4NJyLmrjelDS for ; Wed, 7 Feb 2018 18:08:07 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id A79C35F11F for ; Wed, 7 Feb 2018 18:08:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id BAD87E0237 for ; Wed, 7 Feb 2018 18:08:04 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 5BA8A240FA for ; Wed, 7 Feb 2018 18:08:02 +0000 (UTC) Date: Wed, 7 Feb 2018 18:08:02 +0000 (UTC) From: "Fabiano Tarlao (JIRA)" To: dev@directory.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (DIRKRB-692) 1)sgtTicket clientPrincipal is not initialized + 2)KrbClient fails to store SGT ticket in cache file MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DIRKRB-692?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:all-tabpanel ] Fabiano Tarlao updated DIRKRB-692: ---------------------------------- Attachment: (was: KrbClientTest.java) > 1)sgtTicket clientPrincipal is not initialized + 2)KrbClient fails to sto= re SGT ticket in cache file > -------------------------------------------------------------------------= --------------------------- > > Key: DIRKRB-692 > URL: https://issues.apache.org/jira/browse/DIRKRB-692 > Project: Directory Kerberos > Issue Type: Bug > Affects Versions: 1.1.0 > Environment: Linux Mint 17.1 + Netbeans 8.1 with a Maven Project = + kerb-core 1.1.0 in Windows AD (KDC is Windows 2016 Server) > Reporter: Fabiano Tarlao > Priority: Major > Labels: easyfix > Attachments: KrbClientTest.java, bug1.diff, bug2.diff > > > Two bugs that interact each other > h1. 1) > *SgtTicket*, returned by *KrbClient.requestSgt(..)*, has a _null_ *client= Principal* field (unassigned). Perhaps this is not mandatory but your code = assumes this property is populated (see later). I highly suggest to populat= e this field. > I have wrote a workaround that overrides the=C2=A0*requestSgt* method and= works for the *USE_TGT* case: > =C2=A0 > {code:java} > @Override > =C2=A0=C2=A0=C2=A0 public SgtTicket requestSgt(KOptions requestOptions) t= hrows KrbException { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SgtTicket requestSgt =3D super= .requestSgt(requestOptions);=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 TgtTicket tgt =3D (TgtTicket) = requestOptions.getOptionValue(KrbOption.USE_TGT); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(tgt !=3D null){ > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 reques= tSgt.setClientPrincipal(tgt.getClientPrincipal()); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return requestSgt; > =C2=A0=C2=A0=C2=A0 }{code} > =C2=A0 > h1. 2) > Creating a new credential cache file when storing only one SGT (service t= icket) fails. (i.e., trying to create a new cache file containing only one = SGT and no TGT) > Invoking *KrbClient.storeTicket(sgtTicket, File)* fails for this reason (= here is the original code in *KrbClientBase* class, my comments in RED ): > {{public void storeTicket(SgtTicket sgtTicket, File ccacheFile) throws Kr= bException {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt t= o the credential cache file.");}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!ccacheFile.exists()) {= }} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cre= ateCacheFile(ccacheFile);{color:#ff0000} //Correctly creates a new file but= ...{color}}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && = ccacheFile.canWrite()) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Cre= dentialCache cCache =3D new CredentialCache();}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try= {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile);{color:#ff0000} //..this line= EXPLODES cause it tries to initialize from an empty file, the unexistent f= ile case is not managed correctly{color}}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.addCredential(new Credential(sgtTicket, sgtTic= ket.getClientPrincipal()));}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.setPrimaryPrincipal(sgtTicket.getClientPrincip= al());}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } c= atch (IOException e) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 thr= ow new IllegalArgumentException("Invalid ccache file, "}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " += ccacheFile.getAbsolutePath());}} > {{}}} > Here follows my proposal/fix, this code correctly manages the MIT ccache = file creation for one SGT, please note that this fix assumes that bug 1 is = already fixed: > {{public static void storeTicket(SgtTicket sgtTicket, File ccacheFile) th= rows KrbException {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOG.info("Storing the sgt t= o the credential cache file.");}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 boolean isFreshNew =3D !cca= cheFile.exists();}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (isFreshNew) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cre= ateCacheFile(ccacheFile);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ccacheFile.exists() && = ccacheFile.canWrite()) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try= {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 CredentialCache cCache;}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if(!isFreshNew){}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCach= e(sgtTicket); {color:#ff0000}//This constructor sets also the cCache princi= pal from sgtTicket principal{color}}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.load(ccacheFile);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.addCredential(new Cred= ential(sgtTicket, sgtTicket.getClientPrincipal()));}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache.setPrimaryPrincipal(sg= tTicket.getClientPrincipal());}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 } else {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cCache =3D new CredentialCach= e(sgtTicket);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 cCache.store(ccacheFile);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } c= atch (IOException e) {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 throw new KrbException("Failed to store sgt", e);}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else {}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 thr= ow new IllegalArgumentException("Invalid ccache file, "}} > {{=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 + "not exist or writable: " += ccacheFile.getAbsolutePath());}} > Please note that *YOUR CredentialCache contructor assumes the clientPrinc= ipal is populated* ;) > Hope useful, > regards > Fabiano > P.s: Attached two paches for the project, bug2.diff for bug 2 is..*I thin= k.. production ready*. > bug1.diff for bug 1 is untested.. I ported the modification of my overrid= ing method to the *AbstractInternalKrbClient.requestSgt()* method. But I ha= ve not performed run/test of modules, your project is big and needs time to= manage well. *BUT* is this the right solution? or SHOULD the *clientPrinci= pal* be already populated from the doRequestSgt method? I suggest to look f= or a solution at a deeper level starting from *DefaultInternalKrbClient*. C= onsider bug1.diff a fair workaround. > P.s.2:Added a pull request on GitHub > Regards -- This message was sent by Atlassian JIRA (v7.6.3#76005)