@Override protected byte[] getModifyPinAPDU(Pin pin) { byte pad = pin.getPadChar(); return new byte[] { 0x00, 0x24, 0x00, pin.getReference(), 0x10, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad, pad }; }
@Override public byte[] sign( byte hash[], byte[] pinCode, String digestAlgo, PkAlias pkAlias, RSAPaddingSchemes... sch) throws PinTimeoutException, PinEntryCancelledException, PinBlockedException, POReIDException { ResponseAPDU responseApdu; CommandAPDU cmd; try { RSAPaddingSchemes scheme = sch.length > 0 && null != sch[0] ? sch[0] : RSAPaddingSchemes.PKCS1; CardSpecificReferences csr = getCardSpecificReferences(); Pin gemPin = csr.getCryptoReferences(pkAlias); DigestPrefixes digestPrefixes = csr.getDigestPrefix(digestAlgo); if (null == digestPrefixes) { throw new POReIDException("Algoritmo de resumo desconhecido - " + digestAlgo); } try { beginExclusive(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(0x90); if (0 == digestPrefixes.compareTo(DigestPrefixes.SHA_1)) { baos.write(digestPrefixes.getPrefix().length + hash.length); baos.write(digestPrefixes.getPrefix(), 0, digestPrefixes.getPrefix().length); baos.write(hash, 0, hash.length); } else { baos.write(hash.length); baos.write(hash, 0, hash.length); } if (!CCConfig.isExternalPinCachePermitted() && !isOTPPinChanging()) { pinCode = null; } verifyPin(gemPin, pinCode); // pin introduzido através do dialogo. setSecurityEnvironment(csr.getAlgorithmID(digestAlgo, scheme), gemPin.getKeyReference()); cmd = new CommandAPDU(0x00, 0x2A, 0x90, 0xA0, baos.toByteArray()); responseApdu = channel.transmit(cmd); if (0x9000 != responseApdu.getSW()) { throw new POReIDException( "Código de estado não esperado: " + Integer.toHexString(responseApdu.getSW())); } cmd = new CommandAPDU(0x00, 0x2A, 0x9E, 0x9A, 0x80); responseApdu = channel.transmit(cmd); if (0x9000 != responseApdu.getSW()) { throw new POReIDException( "Código de estado não esperado: " + Integer.toHexString(responseApdu.getSW())); } return responseApdu.getData(); } finally { endExclusive(); } } catch (CardException | IllegalStateException ex) { throw new POReIDException(ex); } }