org.opensc.pkcs11.wrap
Class PKCS11Object

java.lang.Object
  extended by org.opensc.util.DestroyableChild
      extended by org.opensc.pkcs11.wrap.PKCS11Object
All Implemented Interfaces:
Destroyable, PKCS11SessionChild
Direct Known Subclasses:
PKCS11Certificate, PKCS11Key

public class PKCS11Object
extends DestroyableChild
implements PKCS11SessionChild

Author:
wglas This class manages Objects like certificates or keys stored on a PKCS11 device in a specific slot.

Field Summary
protected static int CKA_AC_ISSUER
           
protected static int CKA_ALWAYS_SENSITIVE
           
protected static int CKA_APPLICATION
           
protected static int CKA_ATTR_TYPES
           
protected static int CKA_BASE
           
protected static int CKA_CERTIFICATE_CATEGORY
           
protected static int CKA_CERTIFICATE_TYPE
           
protected static int CKA_CHECK_VALUE
           
protected static int CKA_CLASS
           
protected static int CKA_COEFFICIENT
           
protected static int CKA_DECRYPT
           
protected static int CKA_DERIVE
           
protected static int CKA_ENCRYPT
           
protected static int CKA_END_DATE
           
protected static int CKA_EXPONENT_1
           
protected static int CKA_EXPONENT_2
           
protected static int CKA_EXTRACTABLE
           
protected static int CKA_HASH_OF_ISSUER_PUBLIC_KEY
           
protected static int CKA_HASH_OF_SUBJECT_PUBLIC_KEY
           
protected static int CKA_ID
           
protected static int CKA_ISSUER
           
protected static int CKA_JAVA_MIDP_SECURITY_DOMAIN
           
protected static int CKA_KEY_TYPE
           
protected static int CKA_LABEL
           
protected static int CKA_LOCAL
           
protected static int CKA_MODULUS
           
protected static int CKA_MODULUS_BITS
           
protected static int CKA_NEVER_EXTRACTABLE
           
protected static int CKA_OBJECT_ID
           
protected static int CKA_OWNER
           
protected static int CKA_PRIME
           
protected static int CKA_PRIME_1
           
protected static int CKA_PRIME_2
           
protected static int CKA_PRIME_BITS
           
protected static int CKA_PRIVATE
           
protected static int CKA_PRIVATE_EXPONENT
           
protected static int CKA_PUBLIC_EXPONENT
           
protected static int CKA_SENSITIVE
           
protected static int CKA_SERIAL_NUMBER
           
protected static int CKA_SIGN
           
protected static int CKA_SIGN_RECOVER
           
protected static int CKA_START_DATE
           
protected static int CKA_SUB_PRIME_BITS
           
protected static int CKA_SUBJECT
           
protected static int CKA_SUBPRIME
           
protected static int CKA_TOKEN
           
protected static int CKA_TRUSTED
           
protected static int CKA_UNWRAP
           
protected static int CKA_URL
           
protected static int CKA_VALUE
           
protected static int CKA_VALUE_BITS
           
protected static int CKA_VALUE_LEN
           
protected static int CKA_VERIFY
           
protected static int CKA_VERIFY_RECOVER
           
protected static int CKA_WRAP
           
protected static int CKO_CERTIFICATE
           
protected static int CKO_PRIVATE_KEY
           
protected static int CKO_PUBLIC_KEY
           
protected static int CKO_SECRET_KEY
           
protected  long handle
          The C handle of the object.
protected  long hsession
          The C handle of the session.
protected  long pvh
          The C handle of the provider.
protected  long shandle
          The C handle of the slot.
 
Constructor Summary
protected PKCS11Object(PKCS11Session session, long handle)
          Protected contructor used by subclasses.
 
Method Summary
 void destroy()
           
protected static long[] enumRawObjects(PKCS11Session session, int pkcs11_cls)
          Just a small wrapper atround the native function.
 PKCS11Mechanism[] getAllowedMechanisms()
          Just a small wrapper atround the native function.
protected  boolean getBooleanAttribute(int att)
          Just a small wrapper atround the native function.
protected static boolean getBooleanAttribute(PKCS11Session session, long handle, int att)
          Just a small wrapper atround the native function.
 long getHandle()
           
 int getId()
           
 String getLabel()
           
 PKCS11Provider getProvider()
           
 long getPvh()
           
protected  byte[] getRawAttribute(int att)
          Just a small wrapper atround the native function.
 long getSessionHandle()
           
 long getSlotHandle()
           
protected  int getULongAttribute(int att)
          Just a small wrapper atround the native function.
protected static int getULongAttribute(PKCS11Session session, long handle, int att)
          Just a small wrapper atround the native function.
 
Methods inherited from class org.opensc.util.DestroyableChild
getParent, isDestroyed, unlink
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.security.auth.Destroyable
isDestroyed
 

Field Detail

pvh

protected long pvh
The C handle of the provider.


shandle

protected long shandle
The C handle of the slot.


hsession

protected long hsession
The C handle of the session.


handle

protected long handle
The C handle of the object.


CKO_CERTIFICATE

protected static final int CKO_CERTIFICATE
See Also:
Constant Field Values

CKO_PUBLIC_KEY

protected static final int CKO_PUBLIC_KEY
See Also:
Constant Field Values

CKO_PRIVATE_KEY

protected static final int CKO_PRIVATE_KEY
See Also:
Constant Field Values

CKO_SECRET_KEY

protected static final int CKO_SECRET_KEY
See Also:
Constant Field Values

CKA_CLASS

protected static final int CKA_CLASS
See Also:
Constant Field Values

CKA_TOKEN

protected static final int CKA_TOKEN
See Also:
Constant Field Values

CKA_PRIVATE

protected static final int CKA_PRIVATE
See Also:
Constant Field Values

CKA_LABEL

protected static final int CKA_LABEL
See Also:
Constant Field Values

CKA_APPLICATION

protected static final int CKA_APPLICATION
See Also:
Constant Field Values

CKA_VALUE

protected static final int CKA_VALUE
See Also:
Constant Field Values

CKA_OBJECT_ID

protected static final int CKA_OBJECT_ID
See Also:
Constant Field Values

CKA_CERTIFICATE_TYPE

protected static final int CKA_CERTIFICATE_TYPE
See Also:
Constant Field Values

CKA_ISSUER

protected static final int CKA_ISSUER
See Also:
Constant Field Values

CKA_SERIAL_NUMBER

protected static final int CKA_SERIAL_NUMBER
See Also:
Constant Field Values

CKA_AC_ISSUER

protected static final int CKA_AC_ISSUER
See Also:
Constant Field Values

CKA_OWNER

protected static final int CKA_OWNER
See Also:
Constant Field Values

CKA_ATTR_TYPES

protected static final int CKA_ATTR_TYPES
See Also:
Constant Field Values

CKA_TRUSTED

protected static final int CKA_TRUSTED
See Also:
Constant Field Values

CKA_CERTIFICATE_CATEGORY

protected static final int CKA_CERTIFICATE_CATEGORY
See Also:
Constant Field Values

CKA_JAVA_MIDP_SECURITY_DOMAIN

protected static final int CKA_JAVA_MIDP_SECURITY_DOMAIN
See Also:
Constant Field Values

CKA_URL

protected static final int CKA_URL
See Also:
Constant Field Values

CKA_HASH_OF_SUBJECT_PUBLIC_KEY

protected static final int CKA_HASH_OF_SUBJECT_PUBLIC_KEY
See Also:
Constant Field Values

CKA_HASH_OF_ISSUER_PUBLIC_KEY

protected static final int CKA_HASH_OF_ISSUER_PUBLIC_KEY
See Also:
Constant Field Values

CKA_CHECK_VALUE

protected static final int CKA_CHECK_VALUE
See Also:
Constant Field Values

CKA_KEY_TYPE

protected static final int CKA_KEY_TYPE
See Also:
Constant Field Values

CKA_SUBJECT

protected static final int CKA_SUBJECT
See Also:
Constant Field Values

CKA_ID

protected static final int CKA_ID
See Also:
Constant Field Values

CKA_SENSITIVE

protected static final int CKA_SENSITIVE
See Also:
Constant Field Values

CKA_ENCRYPT

protected static final int CKA_ENCRYPT
See Also:
Constant Field Values

CKA_DECRYPT

protected static final int CKA_DECRYPT
See Also:
Constant Field Values

CKA_WRAP

protected static final int CKA_WRAP
See Also:
Constant Field Values

CKA_UNWRAP

protected static final int CKA_UNWRAP
See Also:
Constant Field Values

CKA_SIGN

protected static final int CKA_SIGN
See Also:
Constant Field Values

CKA_SIGN_RECOVER

protected static final int CKA_SIGN_RECOVER
See Also:
Constant Field Values

CKA_VERIFY

protected static final int CKA_VERIFY
See Also:
Constant Field Values

CKA_VERIFY_RECOVER

protected static final int CKA_VERIFY_RECOVER
See Also:
Constant Field Values

CKA_DERIVE

protected static final int CKA_DERIVE
See Also:
Constant Field Values

CKA_START_DATE

protected static final int CKA_START_DATE
See Also:
Constant Field Values

CKA_END_DATE

protected static final int CKA_END_DATE
See Also:
Constant Field Values

CKA_MODULUS

protected static final int CKA_MODULUS
See Also:
Constant Field Values

CKA_MODULUS_BITS

protected static final int CKA_MODULUS_BITS
See Also:
Constant Field Values

CKA_PUBLIC_EXPONENT

protected static final int CKA_PUBLIC_EXPONENT
See Also:
Constant Field Values

CKA_PRIVATE_EXPONENT

protected static final int CKA_PRIVATE_EXPONENT
See Also:
Constant Field Values

CKA_PRIME_1

protected static final int CKA_PRIME_1
See Also:
Constant Field Values

CKA_PRIME_2

protected static final int CKA_PRIME_2
See Also:
Constant Field Values

CKA_EXPONENT_1

protected static final int CKA_EXPONENT_1
See Also:
Constant Field Values

CKA_EXPONENT_2

protected static final int CKA_EXPONENT_2
See Also:
Constant Field Values

CKA_COEFFICIENT

protected static final int CKA_COEFFICIENT
See Also:
Constant Field Values

CKA_PRIME

protected static final int CKA_PRIME
See Also:
Constant Field Values

CKA_SUBPRIME

protected static final int CKA_SUBPRIME
See Also:
Constant Field Values

CKA_BASE

protected static final int CKA_BASE
See Also:
Constant Field Values

CKA_PRIME_BITS

protected static final int CKA_PRIME_BITS
See Also:
Constant Field Values

CKA_SUB_PRIME_BITS

protected static final int CKA_SUB_PRIME_BITS
See Also:
Constant Field Values

CKA_VALUE_BITS

protected static final int CKA_VALUE_BITS
See Also:
Constant Field Values

CKA_VALUE_LEN

protected static final int CKA_VALUE_LEN
See Also:
Constant Field Values

CKA_EXTRACTABLE

protected static final int CKA_EXTRACTABLE
See Also:
Constant Field Values

CKA_LOCAL

protected static final int CKA_LOCAL
See Also:
Constant Field Values

CKA_NEVER_EXTRACTABLE

protected static final int CKA_NEVER_EXTRACTABLE
See Also:
Constant Field Values

CKA_ALWAYS_SENSITIVE

protected static final int CKA_ALWAYS_SENSITIVE
See Also:
Constant Field Values
Constructor Detail

PKCS11Object

protected PKCS11Object(PKCS11Session session,
                       long handle)
                throws PKCS11Exception
Protected contructor used by subclasses.

Throws:
PKCS11Exception
Method Detail

getRawAttribute

protected byte[] getRawAttribute(int att)
                          throws PKCS11Exception
Just a small wrapper atround the native function.

Parameters:
att - The attribute type to receive.
Returns:
The raw value of the attribute.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

getULongAttribute

protected int getULongAttribute(int att)
                         throws PKCS11Exception
Just a small wrapper atround the native function.

Parameters:
att - The attribute type to receive.
Returns:
The 4-byte integer value of the attribute.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

getULongAttribute

protected static int getULongAttribute(PKCS11Session session,
                                       long handle,
                                       int att)
                                throws PKCS11Exception
Just a small wrapper atround the native function.

Parameters:
att - The attribute type to receive.
Returns:
The 4-byte integer value of the attribute.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

getBooleanAttribute

protected boolean getBooleanAttribute(int att)
                               throws PKCS11Exception
Just a small wrapper atround the native function.

Parameters:
att - The attribute type to receive.
Returns:
The boolean value of the attribute.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

getBooleanAttribute

protected static boolean getBooleanAttribute(PKCS11Session session,
                                             long handle,
                                             int att)
                                      throws PKCS11Exception
Just a small wrapper atround the native function.

Parameters:
att - The attribute type to receive.
Returns:
The 4-byte integer value of the attribute.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

enumRawObjects

protected static long[] enumRawObjects(PKCS11Session session,
                                       int pkcs11_cls)
                                throws PKCS11Exception
Just a small wrapper atround the native function.

Parameters:
session - The session for which to enumerate the objects.
pkcs11_cls - The object class to be seeked. Should be one of the CKO_* constants
Returns:
The object handles of the retrieved objects, which have to be passed to the constructor.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

getAllowedMechanisms

public PKCS11Mechanism[] getAllowedMechanisms()
                                       throws PKCS11Exception
Just a small wrapper atround the native function.

Returns:
The allowed mechanism for this object.
Throws:
PKCS11Exception - Upon errors of the underlying PKCS#11 module.

getId

public int getId()
Returns:
The Id of this object.

getLabel

public String getLabel()
Returns:
The label of this object.

getProvider

public PKCS11Provider getProvider()
Returns:
The underlying PKCS11 security provider. This function throws a runtime exception, if destroy() has been called before.

getPvh

public long getPvh()
Specified by:
getPvh in interface PKCS11SessionChild
Returns:
Returns the C handle of the underlying provider.

getSlotHandle

public long getSlotHandle()
Specified by:
getSlotHandle in interface PKCS11SessionChild
Returns:
Returns the C handle of the slot.

getSessionHandle

public long getSessionHandle()
Specified by:
getSessionHandle in interface PKCS11SessionChild
Returns:
Returns the C handle of the session.

getHandle

public long getHandle()
Specified by:
getHandle in interface PKCS11SessionChild
Returns:
Returns the C handle of the object.

destroy

public void destroy()
             throws DestroyFailedException
Specified by:
destroy in interface Destroyable
Overrides:
destroy in class DestroyableChild
Throws:
DestroyFailedException