public boolean verifyOfflineSignature() { return verifyOfflineSignature(_destination.getSigningPublicKey()); }
/** * The revocation key. Unused. * Must be the same type as the Destination's SigningPublicKey. * @throws IllegalArgumentException if different type */ public void setSigningKey(SigningPublicKey key) { if (key != null && _destination != null && key.getType() != _destination.getSigningPublicKey().getType()) throw new IllegalArgumentException("Signing key type mismatch"); _signingKey = key; }
/** * @throws IllegalArgumentException on mismatch of spubkey and spk types * @since 0.8.9 */ public PrivateKeyFile(File file, Destination dest, PrivateKey pk, SigningPrivateKey spk) { if (dest.getSigningPublicKey().getType() != spk.getType()) throw new IllegalArgumentException("Signing key type mismatch"); this.file = file; this.client = null; this.dest = dest; this.privKey = pk; this.signingPrivKey = spk; }
/** * Existing crypto keys, new signing key * @param privKeys all EncTypes must be available * @since 0.9.21 */ public LeaseInfo(List<PrivateKey> privKeys, Destination dest) { SimpleDataStructure signKeys[]; try { signKeys = KeyGenerator.getInstance().generateSigningKeys(dest.getSigningPublicKey().getType()); } catch (GeneralSecurityException gse) { throw new IllegalStateException(gse); } _privKeys = privKeys; _pubKeys = new ArrayList<PublicKey>(privKeys.size()); for (PrivateKey privKey : privKeys) { _pubKeys.add(KeyGenerator.getPublicKey(privKey)); } _signingPubKey = (SigningPublicKey) signKeys[0]; _signingPrivKey = (SigningPrivateKey) signKeys[1]; }
/** * Overridden to set the blinded key * * @param dest non-null, must be EdDSA_SHA512_Ed25519 * @throws IllegalStateException if already signed * @throws IllegalArgumentException if not EdDSA */ @Override public void setDestination(Destination dest) { super.setDestination(dest); SigningPublicKey spk = dest.getSigningPublicKey(); if (spk.getType() != SigType.EdDSA_SHA512_Ed25519) throw new IllegalArgumentException(); // TODO generate blinded key _signingKey = blind(spk, null); }
/** * @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; } }
/** * New keys * @param types must be available */ public LeaseInfo(Destination dest, List<EncType> types) { if (types.size() > 1) { Collections.sort(types, Collections.reverseOrder()); } _privKeys = new ArrayList<PrivateKey>(types.size()); _pubKeys = new ArrayList<PublicKey>(types.size()); for (EncType type : types) { KeyPair encKeys = KeyGenerator.getInstance().generatePKIKeys(type); _pubKeys.add(encKeys.getPublic()); _privKeys.add(encKeys.getPrivate()); } // must be same type as the Destination's signing key SimpleDataStructure signKeys[]; try { signKeys = KeyGenerator.getInstance().generateSigningKeys(dest.getSigningPublicKey().getType()); } catch (GeneralSecurityException gse) { throw new IllegalStateException(gse); } _signingPubKey = (SigningPublicKey) signKeys[0]; _signingPrivKey = (SigningPrivateKey) signKeys[1]; }
SigType type = d.getSigningPublicKey().getType(); if (type != SigType.DSA_SHA1 && type.isAvailable()) { newDests.add(0, d);
long begin = System.currentTimeMillis(); System.out.println("Starting hashcash generation now..."); String resource = this.dest.getPublicKey().toBase64() + this.dest.getSigningPublicKey().toBase64(); HashCash hc; try {
/** * Check whether a base64-encoded {dest,privkey,signingprivkey} is valid * * @param dest The base64-encoded destination and keys to be checked (same format as PrivateKeyFile) * @return true if valid */ public static boolean checkPrivateDestination(String dest) { byte[] b = Base64.decode(dest); if (b == null || b.length < 663) return false; ByteArrayInputStream destKeyStream = new ByteArrayInputStream(b); try { Destination d = Destination.create(destKeyStream); new PrivateKey().readBytes(destKeyStream); SigningPrivateKey spk = new SigningPrivateKey(d.getSigningPublicKey().getType()); spk.readBytes(destKeyStream); } catch (DataFormatException e) { return false; } catch (IOException e) { return false; } return destKeyStream.available() == 0; }
/** * Verify that the PublicKey matches the PrivateKey, and * the SigningPublicKey matches the SigningPrivateKey. * * @return success * @since 0.9.16 */ public boolean validateKeyPairs() { try { if (!dest.getPublicKey().equals(KeyGenerator.getPublicKey(privKey))) return false; return dest.getSigningPublicKey().equals(KeyGenerator.getSigningPublicKey(signingPrivKey)); } catch (IllegalArgumentException iae) { return false; } }
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); }
/** * Change cert type - caller must also call write(). * Side effect - creates new Destination object. */ public Certificate setCertType(int t) { if (this.dest == null) throw new IllegalArgumentException("Dest is null"); Certificate c = new Certificate(); c.setCertificateType(t); // dests now immutable, must create new Destination newdest = new Destination(); newdest.setPublicKey(dest.getPublicKey()); newdest.setSigningPublicKey(dest.getSigningPublicKey()); newdest.setCertificate(c); dest = newdest; return c; }
byte[] data = new byte[len]; System.arraycopy(this.dest.getPublicKey().getData(), 0, data, 0, PublicKey.KEYSIZE_BYTES); System.arraycopy(this.dest.getSigningPublicKey().getData(), 0, data, PublicKey.KEYSIZE_BYTES, SigningPublicKey.KEYSIZE_BYTES); byte[] payload = new byte[Hash.HASH_LENGTH + Signature.SIGNATURE_BYTES]; Signature sign = DSAEngine.getInstance().sign(data, spk2);
SigType type = isOffline() ? _transientSigningPublicKey.getType() : _destination.getSigningPublicKey().getType(); _signature = new Signature(type); _signature.readBytes(in);
protected void readOfflineBytes(InputStream in) throws DataFormatException, IOException { _transientExpires = DataHelper.readLong(in, 4) * 1000; int itype = (int) DataHelper.readLong(in, 2); SigType type = SigType.getByCode(itype); if (type == null) throw new DataFormatException("Unknown sig type " + itype); _transientSigningPublicKey = new SigningPublicKey(type); _transientSigningPublicKey.readBytes(in); SigType stype = _destination.getSigningPublicKey().getType(); _offlineSignature = new Signature(stype); _offlineSignature.readBytes(in); }
_encryptionKey = PublicKey.create(in); SigType type = _destination.getSigningPublicKey().getType();
/** * Verify the signature of this datagram (previously loaded with the * loadI2PDatagram() method) * @throws I2PInvalidDatagramException if the signature is invalid */ public void verifySignature() throws I2PInvalidDatagramException { // first check if it already got validated if(this.valid) return; if (rxSign == null || rxSign.getData() == null || rxDest == null) throw new I2PInvalidDatagramException("Datagram not yet read"); // now validate SigningPublicKey spk = rxDest.getSigningPublicKey(); SigType type = spk.getType(); if (type == null) throw new I2PInvalidDatagramException("unsupported sig type"); if (type == SigType.DSA_SHA1) { if (!this.dsaEng.verifySignature(rxSign, rxHash, spk)) throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature"); } else { if (!this.dsaEng.verifySignature(rxSign, rxPayload, 0, rxPayloadLen, spk)) throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature"); } // set validated this.valid = true; } }
/** * If the destination is not set, read it in from the file. * Also sets the local privKey and signingPrivKey. */ public Destination getDestination() throws I2PSessionException, IOException, DataFormatException { if (dest == null) { I2PSession s = open(); if (s != null) { this.dest = new VerifiedDestination(s.getMyDestination()); this.privKey = s.getDecryptionKey(); this.signingPrivKey = s.getPrivateKey(); if (s.isOffline()) { _offlineExpiration = s.getOfflineExpiration(); _transientSigningPubKey = s.getTransientSigningPublicKey(); _offlineSignature = s.getOfflineSignature(); _transientSigningPrivKey = signingPrivKey; // set dummy SPK SigType type = dest.getSigningPublicKey().getType(); byte[] dbytes = new byte[type.getPrivkeyLen()]; signingPrivKey = new SigningPrivateKey(type, dbytes); } } } return this.dest; }
_myDestination.readBytes(destKeyStream); _privateKey.readBytes(destKeyStream); SigType dtype = _myDestination.getSigningPublicKey().getType(); _signingPrivateKey = new SigningPrivateKey(dtype); _signingPrivateKey.readBytes(destKeyStream);