public void putSignerInfo(ProtocolSignerInfo protobuf) throws SignatureException { SignerInfo signerInfo = new SignerInfo(protobuf); map.put(ByteBuffer.wrap(signerInfo.getSignerId()), signerInfo); } }
/** * Signs a payload and returns a {@link ProtocolSignature} object * representing the signature. * @param payload the bits that are to be signed. * @return the {@link SignerInfo} object. */ public ProtocolSignature sign(byte[] payload) { try { Signature signer = Signature.getInstance( AlgorithmUtil.getJceName(algorithm)); signer.initSign(signingKey); signer.update(payload); return ProtocolSignature.newBuilder() .setSignatureBytes(ByteString.copyFrom(signer.sign())) .setSignerId(ByteString.copyFrom(signerInfo.getSignerId())) .setSignatureAlgorithm(algorithm) .build(); } catch (java.security.SignatureException e) { // This is thrown if the signer object isn't properly initialized. // Since we just made that object from scratch and initialized it, this // really shouldn't happen throw new IllegalStateException(e); } catch (InvalidKeyException e) { // we checked for this in the constructor - this really shouldn't happen throw new IllegalStateException(e); } catch (NoSuchAlgorithmException e) { // we checked for this in the constructor - this really shouldn't happen throw new IllegalStateException(e); } }
private ByteString getRealSignerId() throws Exception { return ByteString.copyFrom(Certificates.getRealSignerInfo().getSignerId()); }
@Override public void putSignerInfo(ProtocolSignerInfo protoSignerInfo) throws SignatureException { synchronized(certPathStore) { SignerInfo signerInfo = new SignerInfo(protoSignerInfo); File signerFile = new File(signerIdToFileName(signerInfo.getSignerId())); FileOutputStream file = null; try { file = new FileOutputStream(signerFile); file.write(protoSignerInfo.toByteArray()); file.flush(); certPathStore.putSignerInfo(protoSignerInfo); } catch (IOException e) { throw new SignatureException("Failed to write signer info to file: " + signerFile.getAbsolutePath(), e); } finally { FileUtils.closeAndIgnoreException(file, signerFile, LOG); } } } }
private ByteString getRealSignerId() throws Exception { return ByteString.copyFrom(Certificates.getRealSignerInfo().getSignerId()); }
public void testGetSigner() throws Exception { InputStream keyStream = new ByteArrayInputStream(PRIVATE_KEY.getBytes()); InputStream certStream = new ByteArrayInputStream(CERTIFICATE.getBytes()); List<InputStream> certStreams = ImmutableList.of(certStream); String domain = "example.com"; WaveSignerFactory factory = new WaveSignerFactory(); WaveSigner signer = factory.getSigner(keyStream, certStreams, domain); ProtocolSignature signature = signer.sign(MESSAGE); assertTrue(Arrays.equals(SIGNATURE, signature.getSignatureBytes().toByteArray())); assertTrue(Arrays.equals(getSignerInfo().getSignerId(), signature.getSignerId().toByteArray())); }
public void testGetSigner() throws Exception { InputStream keyStream = new ByteArrayInputStream(PRIVATE_KEY.getBytes()); InputStream certStream = new ByteArrayInputStream(CERTIFICATE.getBytes()); List<InputStream> certStreams = ImmutableList.of(certStream); String domain = "example.com"; WaveSignerFactory factory = new WaveSignerFactory(); WaveSigner signer = factory.getSigner(keyStream, certStreams, domain); ProtocolSignature signature = signer.sign(MESSAGE); assertTrue(Arrays.equals(SIGNATURE, signature.getSignatureBytes().toByteArray())); assertTrue(Arrays.equals(getSignerInfo().getSignerId(), signature.getSignerId().toByteArray())); }
@Override public void putSignerInfo(ProtocolSignerInfo protocolSignerInfo) throws SignatureException { SignerInfo signerInfo = new SignerInfo(protocolSignerInfo); byte[] signerId = signerInfo.getSignerId(); // Not using a modifier here because rebuilding the object is not a lot of // work. Doing implicit upsert by using save with a DBOBject that has an _id // set. DBObject signerInfoDBObject = getDBObjectForSignerId(signerId); signerInfoDBObject.put("protoBuff", protocolSignerInfo.toByteArray()); getSignerInfoCollection().save(signerInfoDBObject); }
public void testGetSignerId() throws Exception { signerInfo = new SignerInfo(HashAlgorithm.SHA256, certChain, DOMAIN); assertEquals("zBYbw+lLkXGao+LfNWbv/faS+yAlsAmUfCNqXBxeFtI=", base64(signerInfo.getSignerId())); signerInfo = new SignerInfo(HashAlgorithm.SHA512, certChain, DOMAIN); assertEquals("wtbyS7wiCbIoLXJQjuyER6zTxJe9+pRYi3jxtCBl41eE6inQZBC" + "2Eu8V5AoirzWH271i8JXNdn+6x/eV/nog2g==", base64(signerInfo.getSignerId())); }
public void testGetSignerId() throws Exception { signerInfo = new SignerInfo(HashAlgorithm.SHA256, certChain, DOMAIN); assertEquals("zBYbw+lLkXGao+LfNWbv/faS+yAlsAmUfCNqXBxeFtI=", base64(signerInfo.getSignerId())); signerInfo = new SignerInfo(HashAlgorithm.SHA512, certChain, DOMAIN); assertEquals("wtbyS7wiCbIoLXJQjuyER6zTxJe9+pRYi3jxtCBl41eE6inQZBC" + "2Eu8V5AoirzWH271i8JXNdn+6x/eV/nog2g==", base64(signerInfo.getSignerId())); }
private byte[] storeSignerInfo(ImmutableList<X509Certificate> certs) throws Exception { SignerInfo info = new SignerInfo(HashAlgorithm.SHA256, certs, DOMAIN); store.putSignerInfo(info.toProtoBuf()); return info.getSignerId(); }
private byte[] storeSignerInfo(ImmutableList<X509Certificate> certs) throws Exception { SignerInfo info = new SignerInfo(HashAlgorithm.SHA256, certs, DOMAIN); store.putSignerInfo(info.toProtoBuf()); return info.getSignerId(); }
public void testGetSignerId_fromProtobuf() throws Exception { ProtocolSignerInfo protobuf = ProtocolSignerInfo.newBuilder() .setHashAlgorithm(HashAlgorithm.SHA256) .addCertificate(ByteString.copyFrom( CertConstantUtil.SERVER_PUB_CERT.getEncoded())) .addCertificate(ByteString.copyFrom( CertConstantUtil.INTERMEDIATE_PUB_CERT.getEncoded())) .setDomain(DOMAIN) .build(); signerInfo = new SignerInfo(protobuf); assertEquals("zBYbw+lLkXGao+LfNWbv/faS+yAlsAmUfCNqXBxeFtI=", base64(signerInfo.getSignerId())); }
private ProtocolSignature getRealSignature() throws Exception { return ProtocolSignature.newBuilder() .setSignerId(ByteString.copyFrom(Certificates.getRealSignerInfo().getSignerId())) .setSignatureAlgorithm(SignatureAlgorithm.SHA1_RSA) .setSignatureBytes(ByteString.copyFrom(Certificates.REAL_SIGNATURE)) .build(); }
private ProtocolSignature getRealSignature() throws Exception { return ProtocolSignature.newBuilder() .setSignerId(ByteString.copyFrom(Certificates.getRealSignerInfo().getSignerId())) .setSignatureAlgorithm(SignatureAlgorithm.SHA1_RSA) .setSignatureBytes(ByteString.copyFrom(Certificates.REAL_SIGNATURE)) .build(); }
public void testGetSignerId_fromProtobuf() throws Exception { ProtocolSignerInfo protobuf = ProtocolSignerInfo.newBuilder() .setHashAlgorithm(HashAlgorithm.SHA256) .addCertificate(ByteString.copyFrom( CertConstantUtil.SERVER_PUB_CERT.getEncoded())) .addCertificate(ByteString.copyFrom( CertConstantUtil.INTERMEDIATE_PUB_CERT.getEncoded())) .setDomain(DOMAIN) .build(); signerInfo = new SignerInfo(protobuf); assertEquals("zBYbw+lLkXGao+LfNWbv/faS+yAlsAmUfCNqXBxeFtI=", base64(signerInfo.getSignerId())); }
/** * Checks whether for the given {@link SignerInfo} the certificates retrieved * from the {@link CertPathStore} match up. * * @param signerInfo the {@link SignerInfo} to get the certificates from the * {@link CertPathStore} for * @param certPathStore the {@link CertPathStore} to retrieve the certificates * from. */ private void checkCertificateExists(SignerInfo signerInfo, CertPathStore certPathStore) throws SignatureException { List<X509Certificate> retrievedCerts = certPathStore.getSignerInfo(signerInfo.getSignerId()).getCertificates(); assertEquals(signerInfo.getCertificates(), retrievedCerts); } }
/** * Checks whether for the given {@link SignerInfo} the certificates retrieved * from the {@link CertPathStore} match up. * * @param signerInfo the {@link SignerInfo} to get the certificates from the * {@link CertPathStore} for * @param certPathStore the {@link CertPathStore} to retrieve the certificates * from. */ private void checkCertificateExists(SignerInfo signerInfo, CertPathStore certPathStore) throws SignatureException { List<X509Certificate> retrievedCerts = certPathStore.getSignerInfo(signerInfo.getSignerId()).getCertificates(); assertEquals(signerInfo.getCertificates(), retrievedCerts); } }