/** * @since 0.9.15 */ public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type) throws GeneralSecurityException { return new SigningPublicKey(type, pk.getAbyte()); }
/** * 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); }
/** * @param type the SigType to expect on read-in, ignored on write */ private void syncVerificationKey(File keyDir, SigType type) { DataStructure ds; File keyFile = new File(keyDir, KEYFILE_PUBLIC_SIGNING); boolean exists = (_signingPublicKey != null); if (exists) ds = _signingPublicKey; else ds = new SigningPublicKey(type); DataStructure readin = syncKey(keyFile, ds, exists); if (readin != null && !exists) _signingPublicKey = (SigningPublicKey) readin; }
public DataStructure createStructureToRead() { return new SigningPublicKey(); }
/** * */ public static SigningPublicKey fromJavaKey(RSAPublicKey pk, SigType type) throws GeneralSecurityException { BigInteger n = pk.getModulus(); int len = type.getPubkeyLen(); byte[] bn = rectify(n, len); return new SigningPublicKey(type, bn); }
/** * @return null on error or if not initialized or does not have offline keys * @since 0.9.38 */ public SigningPublicKey getTransientSigningPublicKey() { if (_options == null || _destination == null) return null; String s = _options.getProperty(PROP_TRANSIENT_KEY); if (s == null) return null; int colon = s.indexOf(':'); SigType type; if (colon > 0) { String stype = s.substring(0, colon); type = SigType.parseSigType(stype); if (type == null) return null; s = s.substring(colon + 1); } else { type = SigType.DSA_SHA1; } SigningPublicKey rv = new SigningPublicKey(type); try { rv.fromBase64(s); return rv; } catch (DataFormatException dfe) { return null; } }
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(); }
public static SigningPublicKey fromJavaKey(DSAPublicKey pk) throws GeneralSecurityException { BigInteger y = pk.getY(); SigType type = SigType.DSA_SHA1; int len = type.getPubkeyLen(); byte[] by = rectify(y, len); return new SigningPublicKey(type, by); }
if (_log.shouldLog(Log.DEBUG)) _log.debug("Adding " + name + ": " + key); SigningPublicKey signingPublicKey = new SigningPublicKey(); try {
SigningPublicKey signingPublicKey = new SigningPublicKey(); FileInputStream fileInputStream = null;
public static SigningPublicKey fromJavaKey(ECPublicKey pk, SigType type) throws GeneralSecurityException { ECPoint w = pk.getW(); BigInteger x = w.getAffineX(); BigInteger y = w.getAffineY(); int len = type.getPubkeyLen(); byte[] b = combine(x, y, len); return new SigningPublicKey(type, b); }
@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); }
/** * DSA-SHA1 only. * * Same as above but different return type * @since 0.8.7 */ public SimpleDataStructure[] generateSigningKeys() { SimpleDataStructure[] keys = new SimpleDataStructure[2]; BigInteger x = null; // make sure the random key is less than the DSA q and greater than zero do { x = new NativeBigInteger(160, _context.random()); } while (x.compareTo(CryptoConstants.dsaq) >= 0 || x.equals(BigInteger.ZERO)); BigInteger y = CryptoConstants.dsag.modPow(x, CryptoConstants.dsap); keys[0] = new SigningPublicKey(); keys[1] = new SigningPrivateKey(); try { keys[0].setData(SigUtil.rectify(y, SigningPublicKey.KEYSIZE_BYTES)); keys[1].setData(SigUtil.rectify(x, SigningPrivateKey.KEYSIZE_BYTES)); } catch (InvalidKeyException ike) { throw new IllegalStateException(ike); } return keys; }
@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()); }
@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()); }
@Test public void testShortRead() throws Exception{ SigningPublicKey publicKey = new SigningPublicKey(); ByteArrayInputStream in = new ByteArrayInputStream(DataHelper.getASCII("six times nine equals forty-two")); exception.expect(EOFException.class); exception.expectMessage("EOF after reading 31 bytes of " + SigningPublicKey.KEYSIZE_BYTES + " byte value"); publicKey.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); }
@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)); }
/** * Overridden because we have a blinded key, not a dest */ @Override 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 = _signingKey.getType(); _offlineSignature = new Signature(stype); _offlineSignature.readBytes(in); }
/** * Overridden because we have a blinded key, not a dest */ @Override protected void readHeader(InputStream in) throws DataFormatException, IOException { int stype = (int) DataHelper.readLong(in, 2); SigType type = SigType.getByCode(stype); if (type == null) throw new DataFormatException("unknown key type " + stype); _signingKey = new SigningPublicKey(type); _signingKey.readBytes(in); _published = DataHelper.readLong(in, 4) * 1000; _expires = _published + (DataHelper.readLong(in, 2) * 1000); _flags = (int) DataHelper.readLong(in, 2); if (isOffline()) readOfflineBytes(in); }