OpenCard  
 
OCF, the OpenCard Framework is a standard Java framework for working with Smart Cards.  
 

com.ibm.opencard.signature
Class MFCKeyImportService

java.lang.Object
  |
  +--opencard.core.service.CardService
        |
        +--com.ibm.opencard.service.MFCCardService
              |
              +--com.ibm.opencard.signature.MFCSignatureService
                    |
                    +--com.ibm.opencard.signature.MFCKeyImportService
Direct Known Subclasses:
MFCKeyGenService

public class MFCKeyImportService
extends MFCSignatureService
implements KeyImportCardService

MFCKeyImportService extends the base class MFCSignatureService of all MFC signature card services and additionally implements the KeyImportCardService interface defined by OCF. Instances of MFCKeyImportService or one of its subclasses, which talk to a specific physical smart card, delegate execution of the functionality defined in KeyImportCardService to a (singleton) driver for that card, which implements interface MFCKeyImportImpl for a specific card.

Version:
$Id: MFCKeyImportService.java,v 1.1 1999/12/02 16:06:10 damke Exp $
See Also:
MFCCardService, SignatureCardService

Field Summary
protected  MFCKeyConverter keyConv
          Instances of MFCSKeyImportServices share a single instance of a key converter class implementing MFCKeyConverter.
protected  MFCKeyImportImpl keyImpImpl
          Instances of MFCKeyImportServices share a single instance of a card service implementation class implementing MFCKeyImportImpl.
 
Fields inherited from class com.ibm.opencard.signature.MFCSignatureService
kiParser, sigImpl
 
Fields inherited from class com.ibm.opencard.service.MFCCardService
card_type
 
Constructor Summary
MFCKeyImportService()
          Creates a new key import service for MFC smartcards.
 
Method Summary
 boolean importAndValidateKey(CardFilePath parentDirectory, int keyNr, byte[] key, boolean isPrivate, java.lang.String keyAlgorithm, byte[] signature, int valKeyNr)
          Import and validate a key.
 boolean importAndValidatePrivateKey(PrivateKeyRef destination, java.security.PrivateKey key, byte[] keyInfo, byte[] signature, PublicKeyRef valKey)
          Import and validate a private key.
 boolean importAndValidatePublicKey(PublicKeyRef destination, java.security.PublicKey key, byte[] keyInfo, byte[] signature, PublicKeyRef valKey)
          Import and validate a public key to the card.
 void importKey(CardFilePath parentDirectory, int keyNr, byte[] key, boolean isPrivate, java.lang.String keyAlgorithm)
          Import a key.
protected  void importKeyInternal(CardFilePath parentDirectory, int keyNr, byte[] keyfile, java.lang.String keyAlgorithm, boolean isPrivateKey)
          helper method to import a key.
 void importPrivateKey(PrivateKeyRef destination, java.security.PrivateKey key, byte[] keyInfo)
          Import a private key.
 void importPublicKey(PublicKeyRef destination, java.security.PublicKey key, byte[] keyInfo)
          Import a public key to the card.
protected  void initialize(CardServiceScheduler scheduler, SmartCard smartcard, boolean blocking)
          Initializes this service.
 void initKeyImport(MFCKeyImportParameter parameter)
          Initializes this service from encapsulated arguments.
protected  boolean validateKeyInternal(int keyToBeVerified, int verificationKey, byte[] signature, boolean verifyPrivateKey)
          helper method to validate a key just imported
 
Methods inherited from class com.ibm.opencard.signature.MFCSignatureService
initSignature, satisfyAccessConditions, signData, signData, signDataInternal, signHash, signHash, signHashInternal, verifySignedData, verifySignedData, verifySignedDataInternal, verifySignedHash, verifySignedHash, verifySignedHashInternal
 
Methods inherited from class com.ibm.opencard.service.MFCCardService
allocateCardChannel, checkFileArg, getMFCChannel, getRoot, initGeneric, provideCredentials, releaseCardChannel, selectObject, setCHVDialog, setParentChannel
 
Methods inherited from class opencard.core.service.CardService
getCard, getCardChannel, getCHVDialog, setCardChannel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyImpImpl

protected MFCKeyImportImpl keyImpImpl
Instances of MFCKeyImportServices share a single instance of a card service implementation class implementing MFCKeyImportImpl.

keyConv

protected MFCKeyConverter keyConv
Instances of MFCSKeyImportServices share a single instance of a key converter class implementing MFCKeyConverter.
Constructor Detail

MFCKeyImportService

public MFCKeyImportService()
Creates a new key import service for MFC smartcards. The service cannot be used until it has been initialized by invoking initialize. If this service has to be initialized as part of a derived service, initKeyImport has to be invoked instead.
See Also:
initialize(opencard.core.service.CardServiceScheduler, opencard.core.service.SmartCard, boolean), initKeyImport(com.ibm.opencard.signature.MFCKeyImportParameter)
Method Detail

initialize

protected void initialize(CardServiceScheduler scheduler,
                          SmartCard smartcard,
                          boolean blocking)
                   throws CardServiceException
Initializes this service. This is an entry point for initializing the MFC signature service. It invokes initKeyImport to perform the actual initialization. Derived services must not invoke this method, but have to invoke initKeyImport directly.
Parameters:
scheduler - where to allocate channels
smartcard - which smartcard to contact
blocking - whether operation shall be blocking
Overrides:
initialize in class MFCSignatureService
See Also:
initKeyImport(com.ibm.opencard.signature.MFCKeyImportParameter), MFCCardService.initialize(opencard.core.service.CardServiceScheduler, opencard.core.service.SmartCard, boolean)

initKeyImport

public final void initKeyImport(MFCKeyImportParameter parameter)
                         throws CardServiceException
Initializes this service from encapsulated arguments. This method initializes the local attributes and invokes initSignature in the base class.
Parameters:
parameter - an object encapsulating the parameters to this service
Throws:
CardServiceException - if the initialization failed. With the current implementation, this cannot happen.
See Also:
MFCKeyImportParameter, MFCSignatureService.initSignature(com.ibm.opencard.signature.MFCSignatureParameter)

importAndValidateKey

public boolean importAndValidateKey(CardFilePath parentDirectory,
                                    int keyNr,
                                    byte[] key,
                                    boolean isPrivate,
                                    java.lang.String keyAlgorithm,
                                    byte[] signature,
                                    int valKeyNr)
                             throws CardServiceException,
                                    java.security.InvalidKeyException,
                                    CardTerminalException
Import and validate a key. This MFC specific method can be used by callers that already have the key in the MFC specific format.
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

importAndValidatePrivateKey

public boolean importAndValidatePrivateKey(PrivateKeyRef destination,
                                           java.security.PrivateKey key,
                                           byte[] keyInfo,
                                           byte[] signature,
                                           PublicKeyRef valKey)
                                    throws CardServiceException,
                                           java.security.InvalidKeyException,
                                           CardTerminalException
Import and validate a private key.
Specified by:
importAndValidatePrivateKey in interface KeyImportCardService
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

importAndValidatePublicKey

public boolean importAndValidatePublicKey(PublicKeyRef destination,
                                          java.security.PublicKey key,
                                          byte[] keyInfo,
                                          byte[] signature,
                                          PublicKeyRef valKey)
                                   throws CardServiceException,
                                          java.security.InvalidKeyException,
                                          CardTerminalException
Import and validate a public key to the card.
Specified by:
importAndValidatePublicKey in interface KeyImportCardService
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

importKey

public void importKey(CardFilePath parentDirectory,
                      int keyNr,
                      byte[] key,
                      boolean isPrivate,
                      java.lang.String keyAlgorithm)
               throws CardServiceException,
                      java.security.InvalidKeyException,
                      CardTerminalException
Import a key. This MFC specific method can be used by callers that already have the key in the MFC specific format.
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

importKeyInternal

protected void importKeyInternal(CardFilePath parentDirectory,
                                 int keyNr,
                                 byte[] keyfile,
                                 java.lang.String keyAlgorithm,
                                 boolean isPrivateKey)
                          throws CardServiceException,
                                 java.security.InvalidKeyException,
                                 CardTerminalException
helper method to import a key.
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

importPrivateKey

public void importPrivateKey(PrivateKeyRef destination,
                             java.security.PrivateKey key,
                             byte[] keyInfo)
                      throws CardServiceException,
                             java.security.InvalidKeyException,
                             CardTerminalException
Import a private key.
Specified by:
importPrivateKey in interface KeyImportCardService
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

importPublicKey

public void importPublicKey(PublicKeyRef destination,
                            java.security.PublicKey key,
                            byte[] keyInfo)
                     throws CardServiceException,
                            java.security.InvalidKeyException,
                            CardTerminalException
Import a public key to the card.
Specified by:
importPublicKey in interface KeyImportCardService
Throws:
java.security.InvalidKeyException - The key type is not supported by the specific card service.
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException

validateKeyInternal

protected boolean validateKeyInternal(int keyToBeVerified,
                                      int verificationKey,
                                      byte[] signature,
                                      boolean verifyPrivateKey)
                               throws CardServiceException,
                                      CardTerminalException
helper method to validate a key just imported
Parameters:
keyToBeVerified - key number of key to be verified
verificationKey - key number of key used to verify the signature
signature - the signature over the key to be verified
verifyPrivateKey - is the key to be verified a private key
Returns:
true if the validation succeeded
Throws:
CardServiceException - any subclass of CardServiceException
CardTerminalException - any subclass of CardTerminalException