@Override public SignerInfo getSignerInfo(byte[] signerId) throws SignatureException { return certPathStore.getSignerInfo(signerId); }
@Override public void putSignerInfo(ProtocolSignerInfo protobuff) throws SignatureException { certPathStore.putSignerInfo(protobuff); }
@Override public synchronized ProtocolSignerInfo retrieveSignerInfo(ByteString signerId) { SignerInfo signerInfo; try { signerInfo = certPathStore.getSignerInfo(signerId.toByteArray()); // null is acceptable for retrieveSignerInfo. The user of the certificate manager should call // prefetchDeltaSignerInfo for the mechanism to actually populate the certificate manager. return signerInfo == null ? null : signerInfo.toProtoBuf(); } catch (SignatureException e) { /* * TODO: This may result in the server endlessly requesting the signer info from the * remote server, a more graceful failure needs to be implemented. */ LOG.severe("Failed to retreive signer info for " + new String(Hex.encodeHex(signerId.toByteArray())), e); return null; } }
@Override public synchronized void storeSignerInfo(ProtocolSignerInfo signerInfo) throws SignatureException { verifier.verifySignerInfo(new SignerInfo(signerInfo)); certPathStore.putSignerInfo(signerInfo); }
@Override public SignerInfo getSignerInfo(byte[] signerId) throws SignatureException { synchronized(certPathStore) { SignerInfo signerInfo = certPathStore.getSignerInfo(signerId); File signerFile = new File(signerIdToFileName(signerId)); if (signerInfo == null) { if (signerFile.exists()) { FileInputStream file = null; try { file = new FileInputStream(signerFile); ProtocolSignerInfo data = ProtocolSignerInfo.newBuilder().mergeFrom(file).build(); signerInfo = new SignerInfo(data); } catch (SignatureException | IOException e) { throw new SignatureException("Failed to parse signer info from file: " + signerFile.getAbsolutePath(), e); } finally { FileUtils.closeAndIgnoreException(file, signerFile, LOG); } } } return signerInfo; } }
@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); } } } }
public void testNotExistingSignerIdGivesNull() throws SignatureException { assertNull("Expected Null for a non-existing Signer Id", newCertPathStore().getSignerInfo(new byte[1])); }
public void testCertificatesAreStored() throws Exception { CertPathStore certPathStore = newCertPathStore(); ProtocolSignerInfo realSignerInfoProto = realSignerInfo.toProtoBuf(); certPathStore.putSignerInfo(realSignerInfoProto); ProtocolSignerInfo exampleSignerInfoProto = exampleSignerInfo.toProtoBuf(); certPathStore.putSignerInfo(exampleSignerInfoProto); checkCertificateExists(realSignerInfo, certPathStore); checkCertificateExists(exampleSignerInfo, certPathStore); }
public void testNotExistingSignerIdGivesNull() throws SignatureException { assertNull("Expected Null for a non-existing Signer Id", newCertPathStore().getSignerInfo(new byte[1])); }
public void testCertificatesAreStored() throws Exception { CertPathStore certPathStore = newCertPathStore(); ProtocolSignerInfo realSignerInfoProto = realSignerInfo.toProtoBuf(); certPathStore.putSignerInfo(realSignerInfoProto); ProtocolSignerInfo exampleSignerInfoProto = exampleSignerInfo.toProtoBuf(); certPathStore.putSignerInfo(exampleSignerInfoProto); checkCertificateExists(realSignerInfo, certPathStore); checkCertificateExists(exampleSignerInfo, certPathStore); }
String authority) throws SignatureException, UnknownSignerException { SignerInfo signer = pathStore.getSignerInfo( signatureInfo.getSignerId().toByteArray());
/** * 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); } }