/* * Copyright (c) 2019, 2021, Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
privatestaticvoid cleanup() {
String[] configFiles = new String[]{krbConfigName,
krbConfigNameNoCanonicalize}; for (String configFile : configFiles) {
File f = new File(configFile); if (f.exists()) {
f.delete();
}
}
}
/* * The client subject (whose principal is * test@RABBIT.HOLE@RABBIT.HOLE) will obtain a TGT after * realm referral and name canonicalization (TGT cname * will be test@DEV.RABBIT.HOLE). With this TGT, the client will request * a TGS for service http/server.dev.rabbit.hole@RABBIT.HOLE. After * realm referral, a http/server.dev.rabbit.hole@DEV.RABBIT.HOLE TGS * will be obtained. * * Assert that we get the proper TGT and TGS tickets, and that they are * associated to the client subject. * * Assert that if we request a TGS for the same service again (based on the * original service name), we don't get a new one but the previous, * already in the subject credentials.
*/ privatestaticvoid testSubjectCredentials() throws Exception {
Subject clientSubject = new Subject();
Context clientContext = Context.fromUserPass(clientSubject,
clientKDC1Name, password, false);
Set<Principal> clientPrincipals = clientSubject.getPrincipals(); if (clientPrincipals.size() != 1) { thrownew Exception("Only one client subject principal expected");
}
Principal clientPrincipal = clientPrincipals.iterator().next(); if (DEBUG) {
System.out.println("Client subject principal: " +
clientPrincipal.getName());
} if (!clientPrincipal.getName().equals(clientKDC1Name)) { thrownew Exception("Unexpected client subject principal.");
}
clientContext.startAsClient(serviceName, GSSUtil.GSS_KRB5_MECH_OID);
clientContext.take(newbyte[0]);
Set<KerberosTicket> clientTickets =
clientSubject.getPrivateCredentials(KerberosTicket.class); boolean tgtFound = false; boolean tgsFound = false; for (KerberosTicket clientTicket : clientTickets) {
String cname = clientTicket.getClient().getName();
String sname = clientTicket.getServer().getName(); if (cname.equals(clientKDC2Name)) { if (sname.equals(krbtgtKDC2 +
PrincipalName.NAME_REALM_SEPARATOR_STR + realmKDC2)) {
tgtFound = true;
} elseif (sname.equals(serviceKDC2Name)) {
tgsFound = true;
}
} if (DEBUG) {
System.out.println("Client subject KerberosTicket:");
System.out.println(clientTicket);
}
} if (!tgtFound || !tgsFound) { thrownew Exception("client subject tickets (TGT/TGS) not found.");
} int numOfTickets = clientTickets.size();
clientContext.startAsClient(serviceName, GSSUtil.GSS_KRB5_MECH_OID);
clientContext.take(newbyte[0]);
clientContext.status(); int newNumOfTickets =
clientSubject.getPrivateCredentials(KerberosTicket.class).size(); if (DEBUG) {
System.out.println("client subject number of tickets: " +
numOfTickets);
System.out.println("client subject new number of tickets: " +
newNumOfTickets);
} if (numOfTickets != newNumOfTickets) { thrownew Exception("Useless client subject TGS request because" + " TGS was not found in private credentials.");
}
}
/* * The server (http/server.dev.rabbit.hole@DEV.RABBIT.HOLE) * will authenticate on itself on behalf of the client * (test@DEV.RABBIT.HOLE). Cross-realm referrals will occur * when requesting different TGTs and TGSs (including the * request for delegated credentials).
*/ privatestaticvoid testDelegation() throws Exception {
Context c = Context.fromUserPass(clientKDC2Name,
password, false);
c.startAsClient(serviceName, GSSUtil.GSS_KRB5_MECH_OID);
Context s = Context.fromUserPass(serviceKDC2Name,
password, true);
s.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
Context.handshake(c, s);
Context delegatedContext = s.delegated();
delegatedContext.startAsClient(serviceName, GSSUtil.GSS_KRB5_MECH_OID);
delegatedContext.x().requestMutualAuth(false);
Context s2 = Context.fromUserPass(serviceKDC2Name,
password, true);
s2.startAsServer(GSSUtil.GSS_KRB5_MECH_OID);
// Test authentication
Context.handshake(delegatedContext, s2); if (!delegatedContext.x().isEstablished() || !s2.x().isEstablished()) { thrownew Exception("Delegated authentication failed");
}
// Test identities
GSSName contextInitiatorName = delegatedContext.x().getSrcName();
GSSName contextAcceptorName = delegatedContext.x().getTargName(); if (DEBUG) {
System.out.println("Context initiator: " + contextInitiatorName);
System.out.println("Context acceptor: " + contextAcceptorName);
} if (!contextInitiatorName.toString().equals(clientKDC2Name) ||
!contextAcceptorName.toString().equals(serviceName)) { thrownew Exception("Unexpected initiator or acceptor names");
}
}
/* * The server (http/server.dev.rabbit.hole@DEV.RABBIT.HOLE) * will get a TGS ticket for itself on behalf of the client * (user@RABBIT.HOLE). Cross-realm referrals will be handled * in S4U2Self requests because the user and the server are * on different realms.
*/ privatestaticvoid testImpersonation() throws Exception {
testImpersonationSingle();
// Try a second time to force the use of the Referrals Cache. // During this execution, the referral ticket from RABBIT.HOLE // to DEV.RABBIT.HOLE (upon the initial S4U2Self message) will // be obtained from the Cache.
testImpersonationSingle();
}
/* * The server (http/server.dev.rabbit.hole@DEV.RABBIT.HOLE) * will use delegated credentials (user@RABBIT.HOLE) to * authenticate in the backend (cifs/backend.rabbit.hole@RABBIT.HOLE). * Cross-realm referrals will be handled in S4U2Proxy requests * because the server and the backend are on different realms.
*/ privatestaticvoid testDelegationWithReferrals() throws Exception {
testDelegationWithReferralsSingle();
// Try a second time to force the use of the Referrals Cache. // During this execution, the referral ticket from RABBIT.HOLE // to DEV.RABBIT.HOLE (upon the initial S4U2Proxy message) will // be obtained from the Cache.
testDelegationWithReferralsSingle();
}
// Test authentication
Context.handshake(delegatedContext, b); if (!delegatedContext.x().isEstablished() || !b.x().isEstablished()) { thrownew Exception("Delegated authentication failed");
}
// Test identities
GSSName contextInitiatorName = delegatedContext.x().getSrcName();
GSSName contextAcceptorName = delegatedContext.x().getTargName(); if (DEBUG) {
System.out.println("Context initiator: " + contextInitiatorName);
System.out.println("Context acceptor: " + contextAcceptorName);
} if (!contextInitiatorName.toString().equals(userKDC1Name) ||
!contextAcceptorName.toString().equals(backendServiceName)) { thrownew Exception("Unexpected initiator or acceptor names");
}
}
/* * The client tries to get a TGT (AS protocol) as in testSubjectCredentials * but without the canonicalize setting in krb5.conf. The KDC * must not return a referral but a failure because the client * is not in the local database.
*/ privatestaticvoid testNoCanonicalize() throws Exception {
System.setProperty("java.security.krb5.conf",
krbConfigNameNoCanonicalize);
Config.refresh(); try {
Context.fromUserPass(new Subject(),
clientKDC1Name, password, false); thrownew Exception("should not succeed");
} catch (LoginException e) { // expected
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.24 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.