Skip to content

Commit

Permalink
[SECURITY-905] Wrap the GSSCredential to prevent it from being tamper…
Browse files Browse the repository at this point in the history
…ed with and disposed.
  • Loading branch information
darranl committed Aug 21, 2015
1 parent c975134 commit 0c7e06f
Showing 1 changed file with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.ietf.jgss.GSSException;
import org.ietf.jgss.GSSManager;
import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;

/**
* A Kerberos {@link LoginModule} that wraps the JDK supplied module and has the additional capability of adding a
Expand Down Expand Up @@ -187,7 +188,7 @@ public boolean commit() throws LoginException {
log.trace("Adding GSSCredential to populated Subject");
final GSSManager manager = GSSManager.getInstance();
try {
GSSCredential credential = Subject.doAs(subject, new PrivilegedExceptionAction<GSSCredential>() {
final GSSCredential credential = Subject.doAs(subject, new PrivilegedExceptionAction<GSSCredential>() {

public GSSCredential run() throws Exception {
Set<KerberosPrincipal> principals = subject.getPrincipals(KerberosPrincipal.class);
Expand All @@ -205,7 +206,61 @@ public GSSCredential run() throws Exception {
}
});

SecurityActions.addPrivateCredential(subject, credential);
GSSCredential wrapped = new GSSCredential() {

public int getUsage(Oid mech) throws GSSException {
return credential.getUsage(mech);
}

public int getUsage() throws GSSException {
return credential.getUsage();
}

public int getRemainingLifetime() throws GSSException {
return credential.getRemainingLifetime();
}

public int getRemainingInitLifetime(Oid mech) throws GSSException {
return credential.getRemainingInitLifetime(mech);
}

public int getRemainingAcceptLifetime(Oid mech) throws GSSException {
return credential.getRemainingAcceptLifetime(mech);
}

public GSSName getName(Oid mech) throws GSSException {
return credential.getName(mech);
}

public GSSName getName() throws GSSException {
return credential.getName();
}

public Oid[] getMechs() throws GSSException {
return credential.getMechs();
}

public void dispose() throws GSSException {
// Prevent disposal of our credential.
}

public void add(GSSName name, int initLifetime, int acceptLifetime, Oid mech, int usage) throws GSSException {
credential.add(name, initLifetime, acceptLifetime, mech, usage);
}

@Override
public int hashCode() {
return credential.hashCode();
}

@Override
public boolean equals(Object obj) {
return credential.equals(obj);
}

};

SecurityActions.addPrivateCredential(subject, wrapped);
log.trace("Added private credential.");
this.credential = credential;
} catch (PrivilegedActionException e) {
Expand Down

0 comments on commit 0c7e06f

Please sign in to comment.