public void readBytes(InputStream rawConfig) throws DataFormatException, IOException { _destination = Destination.create(rawConfig); _options = DataHelper.readProperties(rawConfig); _creationDate = DataHelper.readDate(rawConfig); _signature = new Signature(_destination.getSigningPublicKey().getType()); _signature.readBytes(rawConfig); }
/** * decrypt the signature (and subsequent pad bytes) with the * additional layer of encryption using the negotiated key along side * the packet's IV * * Caller must synch on this. * Only call this once! Decrypts in-place. */ private void decryptSignature() { if (_receivedEncryptedSignature == null) throw new NullPointerException("encrypted signature is null! this=" + this.toString()); if (_sessionKey == null) throw new NullPointerException("SessionKey is null!"); if (_receivedIV == null) throw new NullPointerException("IV is null!"); _context.aes().decrypt(_receivedEncryptedSignature, 0, _receivedEncryptedSignature, 0, _sessionKey, _receivedIV, _receivedEncryptedSignature.length); // handle variable signature size SigType type = _remotePeer.getSigningPublicKey().getType(); // if type == null throws NPE int sigLen = type.getSigLen(); int mod = sigLen % 16; if (mod != 0) { byte signatureBytes[] = new byte[sigLen]; System.arraycopy(_receivedEncryptedSignature, 0, signatureBytes, 0, sigLen); _receivedSignature = new Signature(type, signatureBytes); } else { _receivedSignature = new Signature(type, _receivedEncryptedSignature); } if (_log.shouldLog(Log.DEBUG)) _log.debug("Decrypted received signature: " + Base64.encode(_receivedSignature.getData())); }
/** * Number of bytes, NOT including signature */ @Override public int size() { int rv = _destination.size() + 10 + (_leases.size() * MetaLease.LENGTH); if (isOffline()) rv += 6 + _transientSigningPublicKey.length() + _offlineSignature.length(); if (_options != null && !_options.isEmpty()) { try { rv += DataHelper.toProperties(_options).length; } catch (DataFormatException dfe) { throw new IllegalStateException("bad options", dfe); } } else { rv += 2; } // revocations TODO // rv += 32 * numRevocations return rv; }
public DataStructure createDataStructure() throws DataFormatException { Signature sig = new Signature(); byte data[] = new byte[Signature.SIGNATURE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); sig.setData(data); return sig; } public DataStructure createStructureToRead() { return new Signature(); }
/** * @since 0.9.8 */ @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append('[').append(getClass().getSimpleName()).append(' ').append(_type).append(": "); int length = length(); if (_data == null) { buf.append("null"); } else if (length <= 32) { buf.append(toBase64()); } else { buf.append("size: ").append(Integer.toString(length)); } buf.append(']'); return buf.toString(); }
Destination from = getOptionalFrom(); if (from != null) { optionSignature = new Signature(from.getSigningPublicKey().getType()); } else { siglen = Signature.SIGNATURE_BYTES; optionSignature = new Signature(type); byte buf[] = new byte[optionSignature.length()]; System.arraycopy(buffer, cur, buf, 0, buf.length); optionSignature.setData(buf); setOptionalSignature(optionSignature); cur += buf.length;
public DataStructure createStructureToRead() { return new Signature(); } }
int min = 2 + ident.length + 4 + sig.length(); int rem = min % AES_SIZE; int padding = 0; if (padding > 0) _context.random().nextBytes(preEncrypt, 2 + ident.length + 4, padding); System.arraycopy(sig.getData(), 0, preEncrypt, 2+ident.length+4+padding, sig.length()); Signature sig = new Signature(type, bobSigData);
/** * Set the offline signing data. * Does NOT validate the signature. * Must be called AFTER setOptions(). Will throw ISE otherwise. * Side effect - modifies options. * * @throws IllegalStateException * @since 0.9.38 */ public void setOfflineSignature(long expires, SigningPublicKey transientSPK, Signature offlineSig) { if (_options == null) throw new IllegalStateException(); _options.setProperty(PROP_OFFLINE_EXPIRATION, Long.toString(expires / 1000)); _options.setProperty(PROP_TRANSIENT_KEY, transientSPK.getType().getCode() + ":" + transientSPK.toBase64()); _options.setProperty(PROP_OFFLINE_SIGNATURE, offlineSig.toBase64()); }
/** * Including sig. This does NOT validate the signature */ @Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_signature == null) throw new DataFormatException("Not enough data to write out a LeaseSet"); writeBytesWithoutSig(out); _signature.writeBytes(out); }
fileOutputStream.write(signature.getData()); fileOutputStream.write(versionHeader); fileInputStream = new FileInputStream(inputFile);
/** * @return null on error or if not initialized or does not have offline keys * @since 0.9.38 */ public Signature getOfflineSignature() { if (_options == null || _destination == null) return null; String s = _options.getProperty(PROP_OFFLINE_SIGNATURE); if (s == null) return null; Signature rv = new Signature(_destination.getSigningPublicKey().getType()); try { rv.fromBase64(s); return rv; } catch (DataFormatException dfe) { return null; } }
/** * Generic raw verify any type * * Warning, nonstandard for EdDSA, double-hashes, not recommended. * * @throws GeneralSecurityException if algorithm unvailable or on other errors * @since 0.9.9 */ private boolean altVerifySigRaw(Signature signature, SimpleDataStructure hash, SigningPublicKey verifyingKey) throws GeneralSecurityException { SigType type = signature.getType(); if (type != verifyingKey.getType()) throw new IllegalArgumentException("type mismatch sig=" + type + " key=" + verifyingKey.getType()); PublicKey pubKey = SigUtil.toJavaKey(verifyingKey); return verifySignature(signature, hash, pubKey); }
/** * Should we allow an unknown type here? * * @param type non-null * @since 0.9.8 */ public Signature(SigType type, byte data[]) { super(); if (type == null) throw new IllegalArgumentException("unknown type"); _type = type; setData(data); }
Destination from = getOptionalFrom(); if (from != null) { optionSignature = new Signature(from.getSigningPublicKey().getType()); } else { siglen = Signature.SIGNATURE_BYTES; optionSignature = new Signature(type); byte buf[] = new byte[optionSignature.length()]; System.arraycopy(buffer, cur, buf, 0, buf.length); optionSignature.setData(buf); setOptionalSignature(optionSignature); cur += buf.length;