public DataStructure createStructureToRead() { return new Certificate(); } }
/** * 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; }
/** * @throws IllegalStateException if data already set */ public void readBytes(InputStream in) throws DataFormatException, IOException { if (_publicKey != null || _signingKey != null || _certificate != null) throw new IllegalStateException(); _publicKey = PublicKey.create(in); SigningPublicKey spk = SigningPublicKey.create(in); Certificate cert = Certificate.create(in); if (cert.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) { // convert SPK to new SPK and padding KeyCertificate kcert = cert.toKeyCertificate(); _signingKey = spk.toTypedKey(kcert); _padding = spk.getPadding(kcert); _certificate = kcert; } else { _signingKey = spk; _certificate = cert; } }
@Override public boolean equals(Object object) { if (object == this) return true; if ((object == null) || !(object instanceof Certificate)) return false; Certificate cert = (Certificate) object; return _type == cert.getCertificateType() && Arrays.equals(_payload, cert.getPayload()); }
public int size() { int rv = PublicKey.KEYSIZE_BYTES + _signingKey.length(); if (_certificate.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) { // cert data included in keys rv += 7; if (_padding != null) rv += _padding.length; } else { rv += _certificate.size(); } return rv; }
/** * @return null if not set or unknown * @since 0.9.17 */ public SigType getSigType() { if (_certificate == null) return null; if (_certificate.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) { try { KeyCertificate kcert = _certificate.toKeyCertificate(); return kcert.getSigType(); } catch (DataFormatException dfe) {} } return SigType.DSA_SHA1; }
public DataStructure createDataStructure() throws DataFormatException { Certificate cert = new Certificate(); byte data[] = new byte[32]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i%16); cert.setPayload(data); cert.setCertificateType(Certificate.CERTIFICATE_TYPE_NULL); return cert; } public DataStructure createStructureToRead() { return new Certificate(); }
PublicKey pk = PublicKey.create(in); SigningPublicKey sk = SigningPublicKey.create(in); Certificate c = Certificate.create(in); byte[] padding; if (c.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) { KeyCertificate kcert = c.toKeyCertificate(); padding = sk.getPadding(kcert); sk = sk.toTypedKey(kcert); synchronized(_cache) { rv = _cache.get(sk); if (rv != null && rv.getPublicKey().equals(pk) && rv.getCertificate().equals(c)) {
/** * 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; }
/** * deprecated was used only by Packet.java in streaming, now unused * Warning - used by i2p-bote. Does NOT support alternate key types. DSA-SHA1 only. * * @throws IllegalStateException if data already set */ public int readBytes(byte source[], int offset) throws DataFormatException { if (source == null) throw new DataFormatException("Null source"); if (source.length <= offset + PublicKey.KEYSIZE_BYTES + SigningPublicKey.KEYSIZE_BYTES) throw new DataFormatException("Not enough data (len=" + source.length + " off=" + offset + ")"); if (_publicKey != null || _signingKey != null || _certificate != null) throw new IllegalStateException(); int cur = offset; _publicKey = PublicKey.create(source, cur); cur += PublicKey.KEYSIZE_BYTES; _signingKey = SigningPublicKey.create(source, cur); cur += SigningPublicKey.KEYSIZE_BYTES; _certificate = Certificate.create(source, cur); cur += _certificate.size(); return cur - offset; }
/** * This router specified that they should not be used as a part of a tunnel, * nor queried for the netDb, and that disclosure of their contact information * should be limited. * * This is ONLY if the certificate is a hidden type. * Hidden mode may also be specified with a capability in the RouterInfo. * * Not recommended for direct use. * Use of RouterInfo.isHidden() (which calls this) is preferred. */ public boolean isHidden() { return (_certificate != null) && (_certificate.getCertificateType() == Certificate.CERTIFICATE_TYPE_HIDDEN); }
c.setCertificateType(Certificate.CERTIFICATE_TYPE_SIGNED); c.setPayload(payload); return c;
public int estimateSize() { return _instructions.getSize() + _msg.getMessageSize() + 4 // cloveId + DataHelper.DATE_LENGTH + _certificate.size(); // certificate }
System.out.println("Short Hashcash is: " + hcs); c.setPayload(DataHelper.getUTF8(hcs)); return c;
PrivateKey privateKey = (PrivateKey) keypair[1]; SimpleDataStructure signingKeys[]; if (cert.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) { KeyCertificate kcert = cert.toKeyCertificate(); SigType type = kcert.getSigType(); try { d.setPublicKey(publicKey); d.setSigningPublicKey(signingPubKey); if (cert.getCertificateType() == Certificate.CERTIFICATE_TYPE_KEY) { KeyCertificate kcert = cert.toKeyCertificate(); SigType type = kcert.getSigType(); int len = type.getPubkeyLen();
/** * Up-convert a cert to this class * * @param cert payload 4 bytes minimum if non-null * @throws DataFormatException if cert type != CERTIFICATE_TYPE_KEY */ public KeyCertificate(Certificate cert) throws DataFormatException { this(cert.getPayload()); if (cert.getCertificateType() != CERTIFICATE_TYPE_KEY) throw new DataFormatException("type"); }
StringBuilder buf = new StringBuilder(64); buf.append("[Certificate: type: "); if (getCertificateType() == CERTIFICATE_TYPE_NULL) buf.append("Null"); else if (getCertificateType() == CERTIFICATE_TYPE_KEY) buf.append("Key"); else if (getCertificateType() == CERTIFICATE_TYPE_HASHCASH) buf.append("HashCash"); else if (getCertificateType() == CERTIFICATE_TYPE_HIDDEN) buf.append("Hidden"); else if (getCertificateType() == CERTIFICATE_TYPE_SIGNED) buf.append("Signed"); else buf.append("Unknown type (").append(getCertificateType()).append(')'); } else { buf.append(" payload size: ").append(_payload.length); if (getCertificateType() == CERTIFICATE_TYPE_HASHCASH) { buf.append(" Stamp: ").append(DataHelper.getUTF8(_payload)); } else if (getCertificateType() == CERTIFICATE_TYPE_SIGNED && _payload.length == CERTIFICATE_LENGTH_SIGNED_WITH_HASH) { buf.append(" Signed by hash: ").append(Base64.encode(_payload, Signature.SIGNATURE_BYTES, Hash.HASH_LENGTH)); } else {
return new Certificate(type, null); payload = new byte[length]; System.arraycopy(data, off + 3, payload, 0, length); return new Certificate(type, payload);
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_certificate == null) || (_publicKey == null) || (_signingKey == null)) throw new DataFormatException("Not enough data to format the router identity"); _publicKey.writeBytes(out); if (_padding != null) out.write(_padding); else if (_signingKey.length() < SigningPublicKey.KEYSIZE_BYTES) throw new DataFormatException("No padding set"); _signingKey.writeTruncatedBytes(out); _certificate.writeBytes(out); }