private List<KeytabEntry> readEntries(KeytabInputStream kis) throws IOException { List<KeytabEntry> entries = new ArrayList<>(); int bytesLeft = kis.available(); while (bytesLeft > 0) { int entrySize = kis.readInt(); if (kis.available() < entrySize) { throw new IOException("Bad input stream with less data than expected: " + entrySize); } KeytabEntry entry = readEntry(kis, entrySize); entries.add(entry); int bytesReadForEntry = bytesLeft - kis.available(); if (bytesReadForEntry != entrySize) { kis.skipBytes(entrySize - bytesReadForEntry); // reposition to the next keytab entry } bytesLeft = kis.available(); } return entries; }
private List<KeytabEntry> readEntries(KeytabInputStream kis) throws IOException { List<KeytabEntry> entries = new ArrayList<>(); int bytesLeft = kis.available(); while (bytesLeft > 0) { int entrySize = kis.readInt(); if (kis.available() < entrySize) { throw new IOException("Bad input stream with less data than expected: " + entrySize); } KeytabEntry entry = readEntry(kis, entrySize); entries.add(entry); int bytesReadForEntry = bytesLeft - kis.available(); if (bytesReadForEntry != entrySize) { kis.skipBytes(entrySize - bytesReadForEntry); // reposition to the next keytab entry } bytesLeft = kis.available(); } return entries; }
void load(KeytabInputStream kis, int version, int entrySize) throws IOException { int bytesLeft = kis.available(); this.principal = kis.readPrincipal(version); this.timestamp = kis.readTime(); this.kvno = kis.readByte(); this.key = kis.readKey(); int entryBytesRead = bytesLeft - kis.available(); // Some implementations of Kerberos recognize a 32-bit key version at the end of an entry, if record length is // at least 4 bytes longer than the entry and the value of those 32 bits is not 0. If present, this key version // supersedes the 8-bit key version. if (entryBytesRead + 4 <= entrySize) { int tmp = kis.readInt(); if (tmp != 0) { this.kvno = tmp; } } else if (entryBytesRead != entrySize) { throw new IOException( String.format("Bad input stream with less data read [%d] than expected [%d] for keytab entry.", entryBytesRead, entrySize)); } }
void load(KeytabInputStream kis, int version, int entrySize) throws IOException { int bytesLeft = kis.available(); this.principal = kis.readPrincipal(version); this.timestamp = kis.readTime(); this.kvno = kis.readByte(); this.key = kis.readKey(); int entryBytesRead = bytesLeft - kis.available(); // Some implementations of Kerberos recognize a 32-bit key version at the end of an entry, if record length is // at least 4 bytes longer than the entry and the value of those 32 bits is not 0. If present, this key version // supersedes the 8-bit key version. if (entryBytesRead + 4 <= entrySize) { int tmp = kis.readInt(); if (tmp != 0) { this.kvno = tmp; } } else if (entryBytesRead != entrySize) { throw new IOException( String.format("Bad input stream with less data read [%d] than expected [%d] for keytab entry.", entryBytesRead, entrySize)); } }