net.kano.joscar.snaccmd
Class CertificateInfo

java.lang.Object
  extended byCertificateInfo
All Implemented Interfaces:
LiveWritable

public class CertificateInfo
extends java.lang.Object
implements LiveWritable

Contains information about a user's security certificates. This structure contains the certificates themselves as well as MD5 hashes whose significance is unknown at the time of this writing.

See Also:
FullUserInfo.getCertInfoHash(), InfoData.getCertificateInfo()

Field Summary
static int CODE_DEFAULT
          A default value for a "code" sent in certificate information blocks.
static ByteBlock HASHA_DEFAULT
          The value used by the official AIM clients for the first MD5 hash sent in certificate information blocks.
static ByteBlock HASHB_DEFAULT
          The value used by the official AIM clients for the second MD5 hash sent in certificate information blocks.
 
Constructor Summary
CertificateInfo(ByteBlock commonCertData)
          Creates a new certificate information object with the given certificate used for both signing and encrypting data, and MD5 hashes of HASHA_DEFAULT and HASHB_DEFAULT.
CertificateInfo(ByteBlock encCertData, ByteBlock signCertData)
          Creates a new certificate information object with the given encryption and signing certificates, and MD5 hashes of HASHA_DEFAULT and HASHB_DEFAULT.
CertificateInfo(ByteBlock commonCertData, ByteBlock hashA, ByteBlock hashB)
          Creates a new certificate information object with the given certificate used for both signing and encrypting data, and the given MD5 hashes.
CertificateInfo(ByteBlock encCertData, ByteBlock signCertData, ByteBlock hashA, ByteBlock hashB)
          Creates a new certificate information object with the given encryption and signing certificates, and the given MD5 hashes.
 
Method Summary
static byte[] getCertInfoHash(CertificateInfo certInfo)
          Computes the MD5 hash of the given certificate information block.
 ByteBlock getCommonCertData()
          Returns the "common certificate" stored in this certificate information block, if present.
 ByteBlock getEncCertData()
          Returns the encryption certificate stored in this certificate information block, if present.
 ByteBlock getHashA()
          Returns the first MD5 hash contained in this certificate information block, or null if none was sent.
 ByteBlock getHashB()
          Returns the second MD5 hash contained in this certificate information block, or null if none was sent.
 ByteBlock getSignCertData()
          Returns the signing certificate stored in this certificate information block, if present.
 boolean isCommon()
          Returns whether this certificate information block contains a "common certificate," or a certificate used for both encrypting and signing.
static CertificateInfo readCertInfoBlock(ByteBlock block)
          Reads a certificate information block object from the given block of binary data.
 java.lang.String toString()
           
 void write(java.io.OutputStream out)
          Writes a representation of this object to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CODE_DEFAULT

public static final int CODE_DEFAULT
A default value for a "code" sent in certificate information blocks.

See Also:
Constant Field Values

HASHA_DEFAULT

public static final ByteBlock HASHA_DEFAULT
The value used by the official AIM clients for the first MD5 hash sent in certificate information blocks. Note that at the time of this writing, this value is the same as HASHB_DEFAULT.

At the time of this writing, this value is the MD5 hash of an empty string of bytes.


HASHB_DEFAULT

public static final ByteBlock HASHB_DEFAULT
The value used by the official AIM clients for the second MD5 hash sent in certificate information blocks. Note that at the time of this writing, this value is the same as HASHA_DEFAULT.

At the time of this writing, this value is the MD5 hash of an empty string of bytes.

Constructor Detail

CertificateInfo

public CertificateInfo(ByteBlock commonCertData)
Creates a new certificate information object with the given certificate used for both signing and encrypting data, and MD5 hashes of HASHA_DEFAULT and HASHB_DEFAULT.

Note that commonCertData can be null to indicate that no certificate should be sent.

Parameters:
commonCertData - the certificate used to sign and encrypt data

CertificateInfo

public CertificateInfo(ByteBlock commonCertData,
                       ByteBlock hashA,
                       ByteBlock hashB)
Creates a new certificate information object with the given certificate used for both signing and encrypting data, and the given MD5 hashes.

Note that commonCertData can be null to indicate that no certificate should be sent, as can either (or both) of the hashes.

Parameters:
commonCertData - the certificate used to sign and encrypt data
hashA - the first MD5 hash
hashB - the second MD5 hash

CertificateInfo

public CertificateInfo(ByteBlock encCertData,
                       ByteBlock signCertData)
Creates a new certificate information object with the given encryption and signing certificates, and MD5 hashes of HASHA_DEFAULT and HASHB_DEFAULT.

Note that neither encCertData nor signCertData can be null.

Parameters:
encCertData - the certificate used for encrypting data
signCertData - the certificate used for signing data

CertificateInfo

public CertificateInfo(ByteBlock encCertData,
                       ByteBlock signCertData,
                       ByteBlock hashA,
                       ByteBlock hashB)
Creates a new certificate information object with the given encryption and signing certificates, and the given MD5 hashes. Note that the significance of the MD5 hashes is unknown at the time of this writing; the official clients always send HASHA_DEFAULT and HASHB_DEFAULT.

Note that neither encCertData nor signCertData can be null. Either or both of the hashes, however, can be null to indicate that they should not be sent.

Parameters:
encCertData - the certificate used for encrypting data
signCertData - the certificate used for signing data
hashA - the first MD5 hash
hashB - the second MD5 hash
Method Detail

getCertInfoHash

public static byte[] getCertInfoHash(CertificateInfo certInfo)
Computes the MD5 hash of the given certificate information block. This is used to identify whether one's copy of a user's certificate information is up to date (see FullUserInfo.getCertInfoHash()).

Parameters:
certInfo - the certificate information block whose hash should be computed
Returns:
the MD5 hash of the given certificate information block

readCertInfoBlock

public static CertificateInfo readCertInfoBlock(ByteBlock block)
Reads a certificate information block object from the given block of binary data. Note that this method will never return null but will instead return an "empty" certificate information object if no certificate information data is included in the given block of data.

Parameters:
block - a block of data containing a user's certificate information
Returns:
a certificate information block object

isCommon

public final boolean isCommon()
Returns whether this certificate information block contains a "common certificate," or a certificate used for both encrypting and signing. If

If the returned value is true, both getEncCertData() and getSignCertData() will be null; getCommonCertData() will probably be non-null (although the common certificate being non-null cannot be guaranteed).

If the returned value is false, getCommonCertData() will be null; in most cases, getEncCertData() and getSignCertData() will be non-null (although, once again, the encryption and signing certificates being non-null cannot be guaranteed).

Returns:
whether or not this certificate contains a "common certificate"

getCommonCertData

public final ByteBlock getCommonCertData()
Returns the "common certificate" stored in this certificate information block, if present. Note that this method will always return null if isCommon() is false, and it may return null even if isCommon() is true, if no certificate was sent.

Returns:
the "common certificate" stored in this certificate information block, if any
See Also:
isCommon()

getEncCertData

public final ByteBlock getEncCertData()
Returns the encryption certificate stored in this certificate information block, if present. Note that this method will always return null if isCommon() is true, and it may return null even if isCommon() is false, if no encryption certificate was sent.

Returns:
the encryption certificate stored in this certificate information block, if any
See Also:
isCommon()

getSignCertData

public final ByteBlock getSignCertData()
Returns the signing certificate stored in this certificate information block, if present. Note that this method will always return null if isCommon() is true, and it may return null even if isCommon() is false, if no signing certificate was sent.

Returns:
the signing certificate stored in this certificate information block, if any
See Also:
isCommon()

getHashA

public final ByteBlock getHashA()
Returns the first MD5 hash contained in this certificate information block, or null if none was sent. At the time of this writing, the significance of this value is unknown, as it seems to always be HASHA_DEFAULT.

Returns:
the first MD5 hash contained in this certificate information block

getHashB

public final ByteBlock getHashB()
Returns the second MD5 hash contained in this certificate information block, or null if none was sent. At the time of this writing, the significance of this value is unknown, as it seems to always be HASHB_DEFAULT.

Returns:
the second MD5 hash contained in this certificate information block

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Description copied from interface: LiveWritable
Writes a representation of this object to the given stream.

Specified by:
write in interface LiveWritable
Parameters:
out - the stream to which to write
Throws:
java.io.IOException - if an I/O error occurs

toString

public java.lang.String toString()