APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.krb5.internal.ktab

public Class KeyTab

extends Object
implements KeyTabConstants
Class Inheritance
All Implemented Interfaces
sun.security.krb5.internal.ktab.KeyTabConstants
Imports
sun.security.krb5.*, sun.security.krb5.internal.*, sun.security.krb5.internal.crypto.*, java.util.ArrayList, .Arrays, .Comparator, .HashMap, .Map, .StringTokenizer, .Vector, java.io.IOException, .FileInputStream, .FileOutputStream, .File, .FileNotFoundException, sun.security.jgss.krb5.ServiceCreds

This class represents key table. The key table functions deal with storing and retrieving service keys for use in authentication exchanges. A KeyTab object is always constructed, if the file specified does not exist, it's still valid but empty. If there is an I/O error or file format error, it's invalid. The class is immutable on the read side (the write side is only used by the ktab tool).
Author
Yanni Zhang

Field Summary

Modifier and TypeField and Description
private static String
private Vector<KeyTabEntry>
private boolean
private boolean
private int
private long
private static Map<String, KeyTab>
private final String

Constructor Summary

AccessConstructor and Description
private
KeyTab(String
path name for the keytab file, must not be null
filename
)

Constructs a KeyTab object.

Method Summary

Modifier and TypeMethod and Description
public void
addEntry(PrincipalName
the service which will have a new entry in the key table.
service
,
char[]
the password which generates the key.
psswd
,
int
the kvno to use, -1 means automatic increasing
kvno
,
boolean
false if entries with old kvno would be removed.

Note

if kvno is not -1, entries with the same kvno are always removed

append
)

Adds a new entry in the key table.

public void
addEntry(PrincipalName
the service which will have a new entry in the key table.
service
,
String
specified non default salt, cannot be null
salt
,
char[]
the password which generates the key.
psswd
,
int
the kvno to use, -1 means automatic increasing
kvno
,
boolean
false if entries with old kvno would be removed.

Note

if kvno is not -1, entries with the same kvno are always removed

append
)

Adds a new entry in the key table.

public void
addEntry(PrincipalName
the service which will have a new entry in the key table.
service
,
EncryptionKey[]
the keys to be added
encKeys
,
int
the kvno to use, -1 means automatic increasing
kvno
,
boolean
false if entries with old kvno would be removed.

Note

if kvno is not -1, entries with the same kvno are always removed

append
)

Adds a new entry in the key table.

public static synchronized KeyTab
create()

Creates a new default key table.

public static synchronized KeyTab
create(String name)

Creates a new default key table.

public synchronized void
createVersion(File
the key table file.
file
)

Creates key table file version.

public int

Returns:

the number of entries deleted
deleteEntries
(PrincipalName
the service PrincipalName.
service
,
int
the etype to match, remove all if -1
etype
,
int
what kvno to remove, -1 for all, -2 for old
kvno
)

Removes entries from the key table.

public boolean

Returns:

true if the entry is found, otherwise, return false.
findServiceEntry
(PrincipalName
the PrincipalName of the requested service.
service
)

Searches for the service entry in the keytab file.

private static String

Returns:

never null
getDefaultTabName
()

The location of keytab file will be read from the configuration file If it is not specified, consider user.home as the keytab file's default location.

public KeyTabEntry[]

Returns:

array of KeyTabEntry.
getEntries
()

Gets the list of service entries in key table.

public static KeyTab

Returns:

the KeyTab object, never null.
getInstance
(String
the key tab file name.
s
)

Gets a KeyTab object.

public static KeyTab

Returns:

the KeyTab object, never null.
getInstance
(File
the key tab file.
file
)

Gets a KeyTab object.

public static KeyTab

Returns:

the KeyTab object, never null.
getInstance
()

Gets the default KeyTab object.

private static synchronized KeyTab

Returns:

the keytab object, can be invalid, but never null.
getInstance0
(String
file name of keytab, must not be null
s
)

Read a keytab file.

public PrincipalName
getOneName()

Returns a principal name in this keytab.

public boolean
public boolean
private void
public static String

Returns:

never null
normalize
(String
never null
name
)

Normalizes some common keytab name formats into the bare file name.

public EncryptionKey[]

Returns:

an array containing all the service keys, never null
readServiceKeys
(PrincipalName
the PrincipalName of the requested service
service
)

Reads all keys for a service from the keytab file that have etypes that have been configured for use.

public synchronized void
save()

Saves the file at the directory.

public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultTabNameback to summary
private static String defaultTabName
entriesback to summary
private Vector<KeyTabEntry> entries
isMissingback to summary
private boolean isMissing
isValidback to summary
private boolean isValid
kt_vnoback to summary
private int kt_vno
lastModifiedback to summary
private long lastModified
mapback to summary
private static Map<String, KeyTab> map
tabNameback to summary
private final String tabName

Constructor Detail

KeyTabback to summary
private KeyTab(String filename)

Constructs a KeyTab object. If there is any I/O error or format error during the loading, the isValid flag is set to false, and all half-read entries are dismissed.

Parameters
filename:String

path name for the keytab file, must not be null

Method Detail

addEntryback to summary
public void addEntry(PrincipalName service, char[] psswd, int kvno, boolean append) throws KrbException

Adds a new entry in the key table.

Parameters
service:PrincipalName

the service which will have a new entry in the key table.

psswd:char[]

the password which generates the key.

kvno:int

the kvno to use, -1 means automatic increasing

append:boolean

false if entries with old kvno would be removed.

Note

if kvno is not -1, entries with the same kvno are always removed

addEntryback to summary
public void addEntry(PrincipalName service, String salt, char[] psswd, int kvno, boolean append) throws KrbException

Adds a new entry in the key table.

Parameters
service:PrincipalName

the service which will have a new entry in the key table.

salt:String

specified non default salt, cannot be null

psswd:char[]

the password which generates the key.

kvno:int

the kvno to use, -1 means automatic increasing

append:boolean

false if entries with old kvno would be removed.

Note

if kvno is not -1, entries with the same kvno are always removed

addEntryback to summary
public void addEntry(PrincipalName service, EncryptionKey[] encKeys, int kvno, boolean append) throws KrbException

Adds a new entry in the key table.

Parameters
service:PrincipalName

the service which will have a new entry in the key table.

encKeys:EncryptionKey[]

the keys to be added

kvno:int

the kvno to use, -1 means automatic increasing

append:boolean

false if entries with old kvno would be removed.

Note

if kvno is not -1, entries with the same kvno are always removed

createback to summary
public static synchronized KeyTab create() throws IOException, RealmException

Creates a new default key table.

createback to summary
public static synchronized KeyTab create(String name) throws IOException, RealmException

Creates a new default key table.

createVersionback to summary
public synchronized void createVersion(File file) throws IOException

Creates key table file version.

Parameters
file:File

the key table file.

deleteEntriesback to summary
public int deleteEntries(PrincipalName service, int etype, int kvno)

Removes entries from the key table.

Parameters
service:PrincipalName

the service PrincipalName.

etype:int

the etype to match, remove all if -1

kvno:int

what kvno to remove, -1 for all, -2 for old

Returns:int

the number of entries deleted

findServiceEntryback to summary
public boolean findServiceEntry(PrincipalName service)

Searches for the service entry in the keytab file. The etype of the key must be one that has been configured to be used.

Parameters
service:PrincipalName

the PrincipalName of the requested service.

Returns:boolean

true if the entry is found, otherwise, return false.

getDefaultTabNameback to summary
private static String getDefaultTabName()

The location of keytab file will be read from the configuration file If it is not specified, consider user.home as the keytab file's default location.

Returns:String

never null

getEntriesback to summary
public KeyTabEntry[] getEntries()

Gets the list of service entries in key table.

Returns:KeyTabEntry[]

array of KeyTabEntry.

getInstanceback to summary
public static KeyTab getInstance(String s)

Gets a KeyTab object.

Parameters
s:String

the key tab file name.

Returns:KeyTab

the KeyTab object, never null.

getInstanceback to summary
public static KeyTab getInstance(File file)

Gets a KeyTab object.

Parameters
file:File

the key tab file.

Returns:KeyTab

the KeyTab object, never null.

getInstanceback to summary
public static KeyTab getInstance()

Gets the default KeyTab object.

Returns:KeyTab

the KeyTab object, never null.

getInstance0back to summary
private static synchronized KeyTab getInstance0(String s)

Read a keytab file. Returns a new object and save it into cache when new content (modified since last read) is available. If keytab file is invalid, the old object will be returned. This is a safeguard for partial-written keytab files or non-stable network. Please note that a missing keytab is valid, which is equivalent to an empty keytab.

Parameters
s:String

file name of keytab, must not be null

Returns:KeyTab

the keytab object, can be invalid, but never null.

getOneNameback to summary
public PrincipalName getOneName()

Returns a principal name in this keytab. Used by ServiceCreds#getKKeys().

isMissingback to summary
public boolean isMissing()
isValidback to summary
public boolean isValid()
loadback to summary
private void load(KeyTabInputStream kis) throws IOException, RealmException
normalizeback to summary
public static String normalize(String name)

Normalizes some common keytab name formats into the bare file name. For example, FILE:/etc/krb5.keytab to /etc/krb5.keytab

Parameters
name:String

never null

Returns:String

never null

readServiceKeysback to summary
public EncryptionKey[] readServiceKeys(PrincipalName service)

Reads all keys for a service from the keytab file that have etypes that have been configured for use.

Parameters
service:PrincipalName

the PrincipalName of the requested service

Returns:EncryptionKey[]

an array containing all the service keys, never null

saveback to summary
public synchronized void save() throws IOException

Saves the file at the directory.

tabNameback to summary
public String tabName()