Example #1
0
 /**
  * Let the passport sign a message using the passports own private key.
  *
  * @param message The message to sign (can be any size)
  * @return A signature, the response from the passport.
  * @throws CardServiceException Gets thrown when there's a problem communicating with the
  *     passport.
  * @throws NoSuchAlgorithmException Gets thrown when there's no SHA1 provider present.
  */
 public byte[] signWithAA(byte[] message) throws CardServiceException, NoSuchAlgorithmException {
   if (activateTerminal()) {
     DG15File dg15 = new DG15File(_activePassportService.readFile(PassportService.EF_DG15));
     PublicKey publicKey = dg15.getPublicKey();
     MessageDigest digest = MessageDigest.getInstance("SHA1");
     byte[] digestedMessage = digest.digest(message);
     byte[] m2 = new byte[8];
     System.arraycopy(digestedMessage, 0, m2, 0, m2.length);
     return _activePassportService.sendAA(publicKey, m2);
   }
   return new byte[0];
 }
Example #2
0
 /**
  * Performs the Basic Access Control protocol.
  *
  * @param docNumber the document number
  * @param dateOfBirth card holder's birth date
  * @param dateOfExpiry document's expiry date
  * @throws CardServiceException if authentication failed
  * @throws ParseException if at least one of the dates could not be parsed
  */
 public void doBac(String docNumber, String dateOfBirth, String dateOfExpiry)
     throws CardServiceException, ParseException {
   if (activateTerminal()) {
     _activePassportService.doBAC(
         new BACKeySpec(docNumber, SDF.parse(dateOfBirth), SDF.parse(dateOfExpiry)));
   }
 }
Example #3
0
 /** Close the session with the current card and cardreader. */
 public void Close() {
   if (_activePassportService != null) {
     _activePassportService.close();
     _activePassportService = null;
     _activeCardService = null;
     _activeCardTerminal = null;
   }
 }
Example #4
0
 /**
  * Retrieve a DG file from the passport.
  *
  * @param dgTag Tag of the DG file to retrieve.
  * @return The bytes of the DG file.
  * @throws CardServiceException Gets thrown when there's a problem communicating with the
  *     passport.
  * @throws IOException Gets thrown when there's a problem reading the file from the passport.
  */
 public byte[] getDG(int dgTag) throws CardServiceException, IOException {
   if (activateTerminal()) {
     short dgFID = PassportFile.lookupFIDByTag(dgTag);
     CardFileInputStream dgStream = _activePassportService.readFile(dgFID);
     byte[] data = new byte[dgStream.getFileLength()];
     int read = dgStream.read(data, 0, data.length);
     if (read == data.length) return data;
   }
   return new byte[0];
 }
Example #5
0
  private synchronized boolean activateTerminal() {
    Interfacer.getLogger().log("ACTIVATE TERMINAL");
    // select which terminal to use
    if (_cardTerminal != null) _activeCardTerminal = _cardTerminal;
    else {
      while (_activeCardTerminal == null) {
        try {
          for (CardTerminal cardTerminalLoop : _cardTerminals) {
            if (cardTerminalLoop.isCardPresent()
                && !cardTerminalLoop.getName().toUpperCase().contains("EMULATOR")) {
              _activeCardTerminal = cardTerminalLoop;
              break;
            }
          }
          if (_activeCardTerminal == null) {
            Interfacer.getLogger().log("INSERT CARD (s)");
            Thread.sleep(1000);
          }
        } catch (Exception e) {
        }
      }
    }
    Interfacer.getLogger().log("ACTIVE TERMINAL: " + _activeCardTerminal.getName());
    try {
      // wait for a card to be put in the terminal
      while (!_activeCardTerminal.isCardPresent()
          && !_activeCardTerminal.getName().toUpperCase().contains("EMULATOR")) {
        Interfacer.getLogger().log("INSERT CARD (s)");
        Thread.sleep(1000);
      }

      if (_activePassportService == null) {
        _activeCardService = new TerminalCardService(_activeCardTerminal);
        _activePassportService = new PassportService(_activeCardService);
        _activePassportService.open();
      }
      Interfacer.getLogger().log("CARD INSERTED AT: " + _activeCardTerminal.getName());
      return true;
    } catch (Exception e) {
      e.printStackTrace();
    }

    // something went wrong if we reached this point, clear the selected terminal
    Interfacer.getLogger().log("NO TERMINAL COULD BE ACTIVATED");
    return false;
  }