use of org.apache.directory.shared.kerberos.codec.types.EncryptionType in project wildfly by wildfly.
the class AbstractKrb5ConfServerSetupTask method createKeytab.
/**
* Creates a keytab file for given principal.
*
* @param principalName
* @param passPhrase
* @param keytabFile
* @throws IOException
*/
protected void createKeytab(final String principalName, final String passPhrase, final File keytabFile) throws IOException {
LOGGER.trace("Principal name: " + principalName);
final KerberosTime timeStamp = new KerberosTime();
DataOutputStream dos = null;
try {
dos = new DataOutputStream(new FileOutputStream(keytabFile));
dos.write(Keytab.VERSION_0X502_BYTES);
for (Map.Entry<EncryptionType, EncryptionKey> keyEntry : KerberosKeyFactory.getKerberosKeys(principalName, passPhrase).entrySet()) {
final EncryptionKey key = keyEntry.getValue();
final byte keyVersion = (byte) key.getKeyVersion();
// entries.add(new KeytabEntry(principalName, principalType, timeStamp, keyVersion, key));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream entryDos = new DataOutputStream(baos);
// handle principal name
String[] spnSplit = principalName.split("@");
String nameComponent = spnSplit[0];
String realm = spnSplit[1];
String[] nameComponents = nameComponent.split("/");
try {
// increment for v1
entryDos.writeShort((short) nameComponents.length);
entryDos.writeUTF(realm);
// write components
for (String component : nameComponents) {
entryDos.writeUTF(component);
}
// principal type: KRB5_NT_PRINCIPAL
entryDos.writeInt(1);
entryDos.writeInt((int) (timeStamp.getTime() / 1000));
entryDos.write(keyVersion);
entryDos.writeShort((short) key.getKeyType().getValue());
byte[] data = key.getKeyValue();
entryDos.writeShort((short) data.length);
entryDos.write(data);
} finally {
IOUtils.closeQuietly(entryDos);
}
final byte[] entryBytes = baos.toByteArray();
dos.writeInt(entryBytes.length);
dos.write(entryBytes);
}
// } catch (IOException ioe) {
} finally {
IOUtils.closeQuietly(dos);
}
}
use of org.apache.directory.shared.kerberos.codec.types.EncryptionType in project karaf by apache.
the class Krb5LoginModuleTest method createKeytabEntry.
private KeytabEntry createKeytabEntry() throws ParseException {
String principalName = "hnelson@EXAMPLE.COM";
int principalType = 1;
String zuluTime = "20070217235745Z";
Date date = null;
synchronized (KerberosUtils.UTC_DATE_FORMAT) {
date = KerberosUtils.UTC_DATE_FORMAT.parse(zuluTime);
}
KerberosTime timeStamp = new KerberosTime(date.getTime());
byte keyVersion = 1;
String passPhrase = "secret";
Map<EncryptionType, EncryptionKey> keys = KerberosKeyFactory.getKerberosKeys(principalName, passPhrase);
EncryptionKey key = keys.get(EncryptionType.AES128_CTS_HMAC_SHA1_96);
return new KeytabEntry(principalName, principalType, timeStamp, keyVersion, key);
}
Aggregations