APIdia Launch Partner
Top Inners Fields Constructors Methods
sun.security.jgss.krb5

pack-priv Class CipherHelper

extends Object
Class Inheritance
Imports
javax.crypto.Cipher, .SecretKey, .CipherInputStream, .CipherOutputStream, javax.crypto.spec.IvParameterSpec, .SecretKeySpec, java.io.InputStream, .OutputStream, .IOException, org.ietf.jgss.*, java.security.MessageDigest, .GeneralSecurityException, .NoSuchAlgorithmException, sun.security.krb5.*, sun.security.krb5.internal.crypto.Aes128Sha2, .Aes256Sha2, .Des3, .Aes128, .Aes256, .ArcFourHmac, .EType

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
CipherHelper.WrapTokenInputStream

This class provides a truncated inputstream needed by WrapToken.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private final int
private static final int
private final byte[]
private static final int
private static final int
private static final int
private static final int
private final int
private final int
private static final byte[]
ZERO_IV

A zero initial vector to be used for checksum calculation and for DesCbc application data encryption/decryption.

private static final byte[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
aes128Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage)

private byte[]
aes128Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage)

private void
aes128Sha2Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage)

private byte[]
aes128Sha2Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage)

private void
aes256Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage)

private byte[]
aes256Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage)

private void
aes256Sha2Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage)

private byte[]
aes256Sha2Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage)

private void
arcFourDecrypt(WrapToken token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart)

private byte[]
arcFourEncrypt(WrapToken token, byte[] confounder, byte[] plaintext, int start, int len, byte[] padding)

pack-priv byte[]
calculateChecksum(int alg, byte[] header, byte[] trailer, byte[] data, int start, int len, int tokenId)

pack-priv byte[]
calculateChecksum(byte[] header, byte[] data, int start, int len, int key_usage)

pack-priv void
decryptData(WrapToken token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart)

pack-priv void
decryptData(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage)

pack-priv void
decryptData(WrapToken token, InputStream cipherStream, int cLen, byte[] plaintext, int pStart)

pack-priv void
decryptData(WrapToken_v2 token, InputStream cipherStream, int cLen, byte[] plaintext, int pStart, int key_usage)

pack-priv byte[]
decryptSeq(byte[] ivec, byte[] ciphertext, int start, int len)

private void
des3KdDecrypt(WrapToken token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart)

private byte[]
des3KdEncrypt(byte[] confounder, byte[] plaintext, int start, int len, byte[] padding)

private void
desCbcDecrypt(WrapToken token, byte[]
the DES key to use
key
,
byte[]
the encrypted data
cipherText
,
int
the offset for the encrypted data
offset
,
int
the length of the encrypted data
len
,
byte[]
the output buffer where the application data should be written
dataOutBuf
,
int
the offset where the application data should be written.
dataOffset
)

Helper routine to decrypt fromm a byte array and write the application data straight to an output array with minimal buffer copies.

private void
desCbcDecrypt(WrapToken token, byte[]
the DES key to use
key
,
InputStream
the InputStream from which the cipher text should be read
is
,
int
the length of the ciphertext data
len
,
byte[]
the output buffer where the application data should be written
dataOutBuf
,
int
the offset where the application data should be written.
dataOffset
)

Helper routine to decrypt from an InputStream and write the application data straight to an output array with minimal buffer copies.

pack-priv void
encryptData(WrapToken token, byte[] confounder, byte[] plaintext, int start, int len, byte[] padding, OutputStream os)

pack-priv byte[]
encryptData(WrapToken_v2 token, byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage)

pack-priv void
encryptData(WrapToken token, byte[] confounder, byte[] plaintext, int pStart, int pLen, byte[] padding, byte[] ciphertext, int cStart)

pack-priv int
encryptData(WrapToken_v2 token, byte[] confounder, byte[] tokenHeader, byte[] plaintext, int pStart, int pLen, byte[] ciphertext, int cStart, int key_usage)

pack-priv byte[]
encryptSeq(byte[] ivec, byte[] plaintext, int start, int len)

pack-priv int
private byte[]
getDesCbcChecksum(byte[]
the bytes for the DES key
key
,
byte[]
a header to process first before the data is.
header
,
byte[]
the data to checksum
data
,
int
the offset where the data begins
offset
,
int
the length of the data
len
)

Computes the DesCbc checksum based on the algorithm published in FIPS Publication 113.

private static byte[]
getDesEncryptionKey(byte[] key)

pack-priv int
private Cipher
getInitializedDes(boolean
true if encryption is desired, false is decryption is desired.
encryptMode
,
byte[]
the bytes for the DES key
key
,
byte[]
the initial vector bytes
ivBytes
)

Obtains an initialized DES cipher.

pack-priv int
pack-priv int
pack-priv int
pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AES_IV_SIZEback to summary
private static final int AES_IV_SIZE
DES_CHECKSUM_SIZEback to summary
private static final int DES_CHECKSUM_SIZE
DES_IV_SIZEback to summary
private static final int DES_IV_SIZE
etypeback to summary
private final int etype
HMAC_CHECKSUM_SIZEback to summary
private static final int HMAC_CHECKSUM_SIZE
keybytesback to summary
private final byte[] keybytes
KG_USAGE_SEALback to summary
private static final int KG_USAGE_SEAL
KG_USAGE_SEQback to summary
private static final int KG_USAGE_SEQ
KG_USAGE_SIGNback to summary
private static final int KG_USAGE_SIGN
KG_USAGE_SIGN_MSback to summary
private static final int KG_USAGE_SIGN_MS
sealAlgback to summary
private final int sealAlg
sgnAlgback to summary
private final int sgnAlg
ZERO_IVback to summary
private static final byte[] ZERO_IV

A zero initial vector to be used for checksum calculation and for DesCbc application data encryption/decryption.

ZERO_IV_AESback to summary
private static final byte[] ZERO_IV_AES

Constructor Detail

CipherHelperback to summary
pack-priv CipherHelper(EncryptionKey key) throws GSSException

Method Detail

aes128Decryptback to summary
private void aes128Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage) throws GSSException
aes128Encryptback to summary
private byte[] aes128Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage) throws GSSException
aes128Sha2Decryptback to summary
private void aes128Sha2Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage) throws GSSException
aes128Sha2Encryptback to summary
private byte[] aes128Sha2Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage) throws GSSException
aes256Decryptback to summary
private void aes256Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage) throws GSSException
aes256Encryptback to summary
private byte[] aes256Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage) throws GSSException
aes256Sha2Decryptback to summary
private void aes256Sha2Decrypt(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage) throws GSSException
aes256Sha2Encryptback to summary
private byte[] aes256Sha2Encrypt(byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage) throws GSSException
arcFourDecryptback to summary
private void arcFourDecrypt(WrapToken token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart) throws GSSException
arcFourEncryptback to summary
private byte[] arcFourEncrypt(WrapToken token, byte[] confounder, byte[] plaintext, int start, int len, byte[] padding) throws GSSException
calculateChecksumback to summary
pack-priv byte[] calculateChecksum(int alg, byte[] header, byte[] trailer, byte[] data, int start, int len, int tokenId) throws GSSException
Annotations
@SuppressWarnings:fallthrough
calculateChecksumback to summary
pack-priv byte[] calculateChecksum(byte[] header, byte[] data, int start, int len, int key_usage) throws GSSException
decryptDataback to summary
pack-priv void decryptData(WrapToken token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart) throws GSSException
decryptDataback to summary
pack-priv void decryptData(WrapToken_v2 token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart, int key_usage) throws GSSException
decryptDataback to summary
pack-priv void decryptData(WrapToken token, InputStream cipherStream, int cLen, byte[] plaintext, int pStart) throws GSSException, IOException
decryptDataback to summary
pack-priv void decryptData(WrapToken_v2 token, InputStream cipherStream, int cLen, byte[] plaintext, int pStart, int key_usage) throws GSSException, IOException
decryptSeqback to summary
pack-priv byte[] decryptSeq(byte[] ivec, byte[] ciphertext, int start, int len) throws GSSException
des3KdDecryptback to summary
private void des3KdDecrypt(WrapToken token, byte[] ciphertext, int cStart, int cLen, byte[] plaintext, int pStart) throws GSSException
des3KdEncryptback to summary
private byte[] des3KdEncrypt(byte[] confounder, byte[] plaintext, int start, int len, byte[] padding) throws GSSException
desCbcDecryptback to summary
private void desCbcDecrypt(WrapToken token, byte[] key, byte[] cipherText, int offset, int len, byte[] dataOutBuf, int dataOffset) throws GSSException

Helper routine to decrypt fromm a byte array and write the application data straight to an output array with minimal buffer copies. The confounder and the padding are stored separately and not copied into this output array.

Parameters
key:byte[]

the DES key to use

cipherText:byte[]

the encrypted data

offset:int

the offset for the encrypted data

len:int

the length of the encrypted data

dataOutBuf:byte[]

the output buffer where the application data should be written

dataOffset:int

the offset where the application data should be written.

Exceptions
GSSException:
is an error occurs while decrypting the data
desCbcDecryptback to summary
private void desCbcDecrypt(WrapToken token, byte[] key, InputStream is, int len, byte[] dataOutBuf, int dataOffset) throws GSSException, IOException

Helper routine to decrypt from an InputStream and write the application data straight to an output array with minimal buffer copies. The confounder and the padding are stored separately and not copied into this output array.

Parameters
key:byte[]

the DES key to use

is:InputStream

the InputStream from which the cipher text should be read

len:int

the length of the ciphertext data

dataOutBuf:byte[]

the output buffer where the application data should be written

dataOffset:int

the offset where the application data should be written.

Exceptions
GSSException:
is an error occurs while decrypting the data
encryptDataback to summary
pack-priv void encryptData(WrapToken token, byte[] confounder, byte[] plaintext, int start, int len, byte[] padding, OutputStream os) throws GSSException, IOException
encryptDataback to summary
pack-priv byte[] encryptData(WrapToken_v2 token, byte[] confounder, byte[] tokenHeader, byte[] plaintext, int start, int len, int key_usage) throws GSSException
encryptDataback to summary
pack-priv void encryptData(WrapToken token, byte[] confounder, byte[] plaintext, int pStart, int pLen, byte[] padding, byte[] ciphertext, int cStart) throws GSSException
encryptDataback to summary
pack-priv int encryptData(WrapToken_v2 token, byte[] confounder, byte[] tokenHeader, byte[] plaintext, int pStart, int pLen, byte[] ciphertext, int cStart, int key_usage) throws GSSException
encryptSeqback to summary
pack-priv byte[] encryptSeq(byte[] ivec, byte[] plaintext, int start, int len) throws GSSException
getChecksumLengthback to summary
pack-priv int getChecksumLength() throws GSSException
getDesCbcChecksumback to summary
private byte[] getDesCbcChecksum(byte[] key, byte[] header, byte[] data, int offset, int len) throws GSSException

Computes the DesCbc checksum based on the algorithm published in FIPS Publication 113. This involves applying padding to the data passed in, then performing DesCbc encryption on the data with a zero initial vector, and finally returning the last 8 bytes of the encryption result.

Parameters
key:byte[]

the bytes for the DES key

header:byte[]

a header to process first before the data is.

data:byte[]

the data to checksum

offset:int

the offset where the data begins

len:int

the length of the data

Exceptions
GSSException:
when an error occuse in the encryption
getDesEncryptionKeyback to summary
private static byte[] getDesEncryptionKey(byte[] key) throws GSSException
getETypeback to summary
pack-priv int getEType()
getInitializedDesback to summary
private Cipher getInitializedDes(boolean encryptMode, byte[] key, byte[] ivBytes) throws GSSException

Obtains an initialized DES cipher.

Parameters
encryptMode:boolean

true if encryption is desired, false is decryption is desired.

key:byte[]

the bytes for the DES key

ivBytes:byte[]

the initial vector bytes

getProtoback to summary
pack-priv int getProto()
getSealAlgback to summary
pack-priv int getSealAlg()
getSgnAlgback to summary
pack-priv int getSgnAlg()
isArcFourback to summary
pack-priv boolean isArcFour()
sun.security.jgss.krb5 back to summary

pack-priv Class CipherHelper.WrapTokenInputStream

extends InputStream
Class Inheritance

This class provides a truncated inputstream needed by WrapToken. The truncated inputstream is passed to CipherInputStream. It prevents the CipherInputStream from treating the bytes of the following token as part fo the ciphertext for this token.

Field Summary

Modifier and TypeField and Description
private final InputStream
private final int
private int
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

public final void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

public final int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public final int
read(byte[] b)

Overrides java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b.

public final int
read(byte[] b, int off, int len)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public final long
skip(long n)

Overrides java.io.InputStream.skip.

Skips over and discards n bytes of data from this input stream.

Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadAllBytesreadNBytesreadNBytesresetskipNBytestransferTo

Field Detail

isback to summary
private final InputStream is
lengthback to summary
private final int length
remainingback to summary
private int remaining
tempback to summary
private int temp

Constructor Detail

WrapTokenInputStreamback to summary
public WrapTokenInputStream(InputStream is, int length)

Method Detail

availableback to summary
public final int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public final void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Exceptions
IOException:
if an I/O error occurs.
readback to summary
public final int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Exceptions
IOException:
if an I/O error occurs.
readback to summary
public final int read(byte[] b) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[0], the next one into b[1], and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b[0] through b[k-1], leaving elements b[k] through b[b.length-1] unaffected.

Exceptions
IOException:
If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.
readback to summary
public final int read(byte[] b, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
skipback to summary
public final long skip(long n) throws IOException

Overrides java.io.InputStream.skip.

Doc from java.io.InputStream.skip.

Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, the skip method for class InputStream always returns 0, and no bytes are skipped. Subclasses may handle the negative value differently.

Exceptions
IOException:
if an I/O error occurs.