X509KeyFileSystemStore extends AbstractX509FileSystemStore implements KeyStore { @Override public CertifiedKeyPair retrieve(StoreReference store) throws KeyStoreException { return retrieve(store, (byte[]) null); }  @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 retrievePrivateKeyFromFile() throws Exception { FileUtils.writeStringToFile(FILE, FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(SINGLE_STORE_REF); assertThat(keyPair, notNullValue()); assertThat(keyPair.getPrivateKey(), equalTo(privateKey)); assertThat(keyPair.getCertificate(), equalTo((CertifiedPublicKey) certificate)); }
@Test void retrieveEncryptedPrivateKeyFromFile() throws Exception { FileUtils.writeStringToFile(FILE, ENCRYPTED_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(SINGLE_STORE_REF, PASSWORD); assertThat(keyPair, notNullValue()); assertThat(keyPair.getPrivateKey(), equalTo(privateKey)); assertThat(keyPair.getCertificate(), equalTo((CertifiedPublicKey) certificate)); }
@Test void retrievePrivateKeyFromDirectory() throws Exception { DIRECTORY.mkdirs(); FileUtils.writeStringToFile(KEY_FILE, KEY_FILE_CONTENT); FileUtils.writeStringToFile(CERT_FILE, CERTIFICATE_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(MULTI_STORE_REF, certificate); assertThat(keyPair, notNullValue()); assertThat(keyPair.getPrivateKey(), equalTo(privateKey)); assertThat(keyPair.getCertificate(), equalTo((CertifiedPublicKey) certificate)); }
@Test void retrieveEncryptedPrivateKeyFromDirectory() throws Exception { DIRECTORY.mkdirs(); FileUtils.writeStringToFile(KEY_FILE, ENCRYTEDKEY_FILE_CONTENT); FileUtils.writeStringToFile(CERT_FILE, CERTIFICATE_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(MULTI_STORE_REF, certificate, PASSWORD); assertThat(keyPair, notNullValue()); assertThat(keyPair.getPrivateKey(), equalTo(privateKey)); assertThat(keyPair.getCertificate(), equalTo((CertifiedPublicKey) certificate)); }
@Test void retrieveMissingPrivateKeyFromFile() throws Exception { FileUtils.writeStringToFile(FILE, CERTIFICATE_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(SINGLE_STORE_REF); assertThat(keyPair, nullValue()); }
@Test void retrieveMissingCertificateFromFile() throws Exception { FileUtils.writeStringToFile(FILE, KEY_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(SINGLE_STORE_REF); assertThat(keyPair, nullValue()); }
@Test void retrieveMissingPrivateKeyFromDirectory() throws Exception { DIRECTORY.mkdirs(); FileUtils.writeStringToFile(CERT_FILE, CERTIFICATE_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(MULTI_STORE_REF, certificate); assertThat(keyPair, nullValue()); }
@Test void retrieveMissingCertificateFromDirectory() throws Exception { DIRECTORY.mkdirs(); FileUtils.writeStringToFile(KEY_FILE, KEY_FILE_CONTENT); CertifiedKeyPair keyPair = store.retrieve(MULTI_STORE_REF, certificate); assertThat(keyPair, notNullValue()); assertThat(keyPair.getPrivateKey(), equalTo(privateKey)); assertThat(keyPair.getCertificate(), equalTo((CertifiedPublicKey) certificate)); }