/** * 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; }
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); }
@Test public void testNullEquals(){ SigningPublicKey publicKey = new SigningPublicKey(); byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%56); publicKey.setData(data); assertFalse(publicKey.equals(null)); }
/** * Do we know about the following key? * @since 0.7.12 */ public boolean haveKey(String key) { if (key.length() != KEYSIZE_B64_BYTES) return false; SigningPublicKey signingPublicKey = new SigningPublicKey(); try { signingPublicKey.fromBase64(key); } catch (DataFormatException dfe) { return false; } return _trustedKeys.containsKey(signingPublicKey); }
public DataStructure createDataStructure() throws DataFormatException { SigningPublicKey publicKey = new SigningPublicKey(); byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); publicKey.setData(data); return publicKey; } public DataStructure createStructureToRead() { return new SigningPublicKey(); }
/** * A KeyCertificate with crypto type 0 (ElGamal) * and the signature type and extra data from the given public key. * * @param spk non-null data non-null * @throws IllegalArgumentException */ public KeyCertificate(SigningPublicKey spk) { super(CERTIFICATE_TYPE_KEY, null); if (spk == null || spk.getData() == null) throw new IllegalArgumentException(); SigType type = spk.getType(); int len = type.getPubkeyLen(); int extra = Math.max(0, len - 128); _payload = new byte[HEADER_LENGTH + extra]; int code = type.getCode(); _payload[0] = (byte) (code >> 8); _payload[1] = (byte) (code & 0xff); // 2 and 3 always 0, it is the only crypto code for now if (extra > 0) System.arraycopy(spk.getData(), 128, _payload, HEADER_LENGTH, extra); }
protected void writeOfflineBytes(OutputStream out) throws DataFormatException, IOException { if (_transientSigningPublicKey == null || _offlineSignature == null) throw new DataFormatException("No offline key/sig"); DataHelper.writeLong(out, 4, _transientExpires / 1000); DataHelper.writeLong(out, 2, _transientSigningPublicKey.getType().getCode()); _transientSigningPublicKey.writeBytes(out); _offlineSignature.writeBytes(out); }
/** * 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()); }
/** * Overridden because we have a blinded key, not a dest. * This is the hash of the signing public key type and the signing public key. * Throws IllegalStateException if not initialized. * * @throws IllegalStateException */ @Override public Hash getHash() { if (__calculatedHash == null) { if (_signingKey == null) throw new IllegalStateException(); int len = _signingKey.length(); byte[] b = new byte[2 + len]; DataHelper.toLong(b, 0, 2, _signingKey.getType().getCode()); System.arraycopy(_signingKey.getData(), 0, b, 2, len); __calculatedHash = SHA256Generator.getInstance().calculateHash(b); } return __calculatedHash; }
SigningPublicKey signingPublicKey = new SigningPublicKey(); FileInputStream fileInputStream = null; signingPublicKey.readBytes(fileInputStream); } catch (IOException ioe) { if (_log.shouldLog(Log.WARN))
/** * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 * @param h hash of secret data, same length as this key * @throws UnsupportedOperationException unless supported */ public static SigningPublicKey blind(SigningPublicKey key, SimpleDataStructure h) { if (key.getType() != TYPE) throw new UnsupportedOperationException(); if (h.length() != key.length()) throw new IllegalArgumentException(); try { EdDSAPublicKey jk = SigUtil.toJavaEdDSAKey(key); EdDSAPublicKey bjk = EdDSABlinding.blind(jk, h.getData()); return SigUtil.fromJavaKey(bjk, TYPE); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse); } }
byte[] bkey = Base64.decode(skey.substring(colon + 1)); if (bkey != null) { spk = new SigningPublicKey(type, bkey); if (!spk.getType().isAvailable()) { _negativeCache.add(h); if (_log.shouldInfo()) sig = new Signature(spk.getType(), bsig); } catch (IllegalArgumentException iae) {
PublicKey pubkey = new PublicKey(); pubkey.readBytes(fis); SigningPublicKey signingPubKey = new SigningPublicKey(); signingPubKey.readBytes(fis); if (!pubkey.equals(KeyGenerator.getPublicKey(privkey))) throw new DataFormatException("Key pairs invalid"); if (!signingPubKey.equals(KeyGenerator.getSigningPublicKey(signingPrivKey))) throw new DataFormatException("Key pairs invalid"); } catch (IllegalArgumentException iae) {
@Test public void testBase64Constructor() throws Exception{ SigningPublicKey publicKey = new SigningPublicKey(); byte data[] = new byte[SigningPublicKey.KEYSIZE_BYTES]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%56); publicKey.setData(data); SigningPublicKey key2 = new SigningPublicKey(publicKey.toBase64()); assertEquals(publicKey, key2); }
/** * @since 0.9.15 */ public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type) throws GeneralSecurityException { return new SigningPublicKey(type, pk.getAbyte()); }
/** * Number of bytes, NOT including signature */ public int size() { return _destination.size() + PublicKey.KEYSIZE_BYTES // encryptionKey + _signingKey.length() // signingKey + 1 // number of leases + _leases.size() * 44; }
@Test public void testShortData() throws Exception{ SigningPublicKey publicKey = new SigningPublicKey(); byte data[] = new byte[56]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i); exception.expect(IllegalArgumentException.class); exception.expectMessage("Bad data length: 56; required: " + SigningPublicKey.KEYSIZE_BYTES); publicKey.setData(data); publicKey.writeBytes(new ByteArrayOutputStream()); }
/** * @since 0.9.8 */ @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("[SigningPublicKey ").append((_type != null) ? _type.toString() : "unknown type").append(' '); int length = length(); if (_data == null) { buf.append("null"); } else if (length <= 32) { buf.append(toBase64()); } else { buf.append("size: ").append(length); } buf.append(']'); return buf.toString(); }
@Test public void testNullData() throws Exception{ SigningPublicKey publicKey = new SigningPublicKey(); publicKey.toString(); exception.expect(DataFormatException.class); exception.expectMessage("No data to write out"); publicKey.writeBytes(new ByteArrayOutputStream()); }
/** * Deprecated, used only by Packet.java in streaming. * Broken for sig types P521 and RSA before 0.9.15 * @return the written length (NOT the new offset) */ public int writeBytes(byte target[], int offset) { int cur = offset; System.arraycopy(_publicKey.getData(), 0, target, cur, PublicKey.KEYSIZE_BYTES); cur += PublicKey.KEYSIZE_BYTES; if (_padding != null) { System.arraycopy(_padding, 0, target, cur, _padding.length); cur += _padding.length; } int spkTrunc = Math.min(SigningPublicKey.KEYSIZE_BYTES, _signingKey.length()); System.arraycopy(_signingKey.getData(), 0, target, cur, spkTrunc); cur += spkTrunc; cur += _certificate.writeBytes(target, cur); return cur - offset; }