X509KeyFileSystemStore extends AbstractX509FileSystemStore implements KeyStore { @Override public void store(StoreReference store, CertifiedKeyPair keyPair) throws KeyStoreException { storeKeyPair(store, getPublicKey(keyPair.getCertificate()), keyPair.getPrivateKey().getEncoded(), PRIVATE_KEY); }  @Override void store(StoreReference store, CertifiedKeyPair keyPair); @Override void store(StoreReference store, CertifiedKeyPair keyPair, byte[] password); @Override CertifiedKeyPair retrieve(StoreReference store); @Override CertifiedKeyPair retrieve(StoreReference store, byte[] password); @Override CertifiedKeyPair retrieve(StoreReference store, CertifiedPublicKey publicKey); @Override CertifiedKeyPair retrieve(StoreReference store, CertifiedPublicKey publicKey, byte[] password);  }
@Test void storePrivateKeyToFile() throws Exception { store.store(SINGLE_STORE_REF, keyPair); assertThat(FileUtils.readFileToString(FILE), equalTo(FILE_CONTENT)); }
@Test void storePrivateKeyToDirectory() throws Exception { store.store(MULTI_STORE_REF, keyPair); assertThat(FileUtils.readFileToString(KEY_FILE), equalTo(KEY_FILE_CONTENT)); assertThat(FileUtils.readFileToString(CERT_FILE), equalTo(CERTIFICATE_FILE_CONTENT)); }
@Test void storeEncryptedPrivateKeyToFile() throws Exception { store.store(SINGLE_STORE_REF, keyPair, PASSWORD); assertThat(FileUtils.readFileToString(FILE), equalTo(ENCRYPTED_FILE_CONTENT)); }
@Test void storeEncryptedPrivateKeyToDirectory() throws Exception { store.store(MULTI_STORE_REF, keyPair, PASSWORD); assertThat(FileUtils.readFileToString(KEY_FILE), equalTo(ENCRYTEDKEY_FILE_CONTENT)); assertThat(FileUtils.readFileToString(CERT_FILE), equalTo(CERTIFICATE_FILE_CONTENT)); }
@Test void storePrivateKeyToDirectoryWithoutSubjectID() throws Exception { when(certificate.getExtensions()).thenReturn(null); when(certificate.getSubjectKeyIdentifier()).thenReturn(null); store.store(MULTI_STORE_REF, keyPair); assertThat(FileUtils.readFileToString(new File(DIRECTORY, SERIAL + ", " + ISSUER + ".key")), equalTo(KEY_FILE_CONTENT)); assertThat(FileUtils.readFileToString(new File(DIRECTORY, SERIAL + ", " + ISSUER + ".cert")), equalTo(CERTIFICATE_FILE_CONTENT)); }