public ObjectHandle handleForUserMainRecord(KeyCredentials keyCredentials) { ObjectHandle keyHandle = keyCredentials.getHandle(); ObjectHandle handle = new ObjectHandle(); handle.setContainer(keyHandle.getContainer()); handle.setName(mainRecordFileName); return handle; } }
public KeyCredentials newKeyCredntials (String subject, String userSecret){ KeyCredentials keyCredentials = new KeyCredentials(); String container = nameUserContainer(subject); /* The keystore reference and the keyid have the same name. The user name.*/ ObjectHandle handle = new ObjectHandle(); handle.setContainer(container); handle.setName(keystoreFileName); keyCredentials.setHandle(handle); keyCredentials.setKeyid("mainUserKey"); /*For this version we assume the keypass and the storepass are identicals.*/ keyCredentials.setKeypass(userSecret); keyCredentials.setStorepass(userSecret); return keyCredentials ; }
private KeyStore initKeystore(Payload payload, String storeid, CallbackHandler handler) { KeyStoreType keyStoreType = new KeyStoreType(payload.getStorageMetadata().getUserMetadata().get(KEYSTORE_TYPE_KEY)); return KeyStoreService.loadKeyStore(payload.getData(), storeid, keyStoreType, handler); } }
@Override public Tuple<KeyStore, Map<String, String>> loadKeystoreAndAttributes(ObjectHandle handle, CallbackHandler handler) { BucketPath bucketPath = BucketPath.fromHandle(handle); Payload payload = extendedStoreConnection.getBlob(bucketPath); KeyStore keyStore = initKeystore(payload, handle.getName(), handler); UserMetaData metaInfo = payload.getStorageMetadata().getUserMetadata(); Map<String, String> attributeMap = new HashMap<>(); Set<String> keySet = metaInfo.keySet(); for (String key : keySet) { attributeMap.put(key, metaInfo.get(key)); } attributeMap.remove(KEYSTORE_TYPE_KEY); return new Tuple<>(keyStore, attributeMap); }
@Override public void encryptAndPersistStream(BucketPath bucketPath, PayloadStream payloadStream, KeySource keySource, KeyID keyID) { payloadStream.getStorageMetadata().getUserMetadata().put(ENCRYPTION_SERVICE, encryptionStreamService.getClass().toString()); payloadStream.getStorageMetadata().getUserMetadata().put(ENCRYPTION_KEY_ID, keyID.getValue()); LOGGER.debug("ENCRYPT STREAM WITH " + keyID); InputStream encryptedStream = encryptionStreamService.getEncryptedInputStream(payloadStream.getStorageMetadata().getUserMetadata(), payloadStream.openStream(), keySource, keyID, payloadStream.getStorageMetadata().getShouldBeCompressed()); extendedStoreConnection.putBlobStream(bucketPath, new SimplePayloadStreamImpl(payloadStream.getStorageMetadata(), encryptedStream)); }
private static String bucketDirectory2String(BucketDirectory bucketDirectory) { return bucketDirectory.getObjectHandle().getContainer() + BucketPath.BUCKET_SEPARATOR + bucketDirectory.getObjectHandle().getName(); } }
@Override public void saveKeyStore(KeyStore keystore, CallbackHandler storePassHandler, ObjectHandle handle) { String storeType = keystore.getType(); byte[] bs = KeyStoreService.toByteArray(keystore, handle.getName(), storePassHandler); BucketPath bucketPath = BucketPath.fromHandle(handle); Payload payload = new SimplePayloadImpl(bs); payload.getStorageMetadata().getUserMetadata().put(KEYSTORE_TYPE_KEY, storeType); extendedStoreConnection.putBlob(bucketPath, payload); }
@Override public void removeBlobFolder(BucketDirectory bucketDirectory) { if (bucketDirectory.getObjectHandle().getName() == null) { throw new StorageConnectionException("not a valid bucket directory " + bucketDirectory); } List<StorageMetadata> list = list(bucketDirectory, ListRecursiveFlag.TRUE); list.forEach(metadata -> { if (metadata.getType().equals(StorageType.BLOB)) { removeBlob(new BucketPath(metadata.getName())); } }); }
public Tuple<KeyStore, Map<String, String>> loadKeystoreAndAttributes(ObjectHandle handle, CallbackHandler handler) throws KeystoreNotFoundException, CertificateException, WrongKeystoreCredentialException, MissingKeystoreAlgorithmException, MissingKeystoreProviderException, MissingKeyAlgorithmException, IOException, UnknownContainerException{ KeystoreData keystoreData = loadKeystoreData(handle); KeyStore keyStore = initKeystore(keystoreData, handle.getName(), handler); return new Tuple<>(keyStore, keystoreData.getAttributesMap()); }
/** * * @param keystorePersistence * @param keyStoreAccess bei Passworte muessen gesetzt sein * @return */ public static KeySource getForPrivateKey(KeystorePersistence keystorePersistence, KeyStoreAccess keyStoreAccess) { LOGGER.debug("get keysource for private key of " + keyStoreAccess.getKeyStorePath()); KeyStore userKeystore = keystorePersistence.loadKeystore(keyStoreAccess.getKeyStorePath().getObjectHandle(), keyStoreAccess.getKeyStoreAuth().getReadStoreHandler()); KeySource keySource = new KeyStoreBasedPrivateKeySourceImpl(userKeystore, keyStoreAccess.getKeyStoreAuth().getReadKeyPassword()); return keySource; }
static String cacheKeyToString(KeyStoreAccess keyStoreAccess, DocumentKeyID documentKeyID) { return keyStoreAccess.getKeyStoreAuth().getReadStorePassword() + " " + keyStoreAccess.getKeyStorePath().toString() + " " + documentKeyID.toString(); }
public KeyStore loadKeystore(ObjectHandle handle, CallbackHandler handler) throws KeystoreNotFoundException, CertificateException, WrongKeystoreCredentialException, MissingKeystoreAlgorithmException, MissingKeystoreProviderException, MissingKeyAlgorithmException, IOException, UnknownContainerException{ KeystoreData keystoreData = loadKeystoreData(handle); return initKeystore(keystoreData, handle.getName(), handler); }
@Override public DocumentKeyIDWithKeyAndAccessType get(KeyStoreAccess keyStoreAccess, DocumentKeyID documentKeyID) { DocumentGuardCache documentGuardCache = docusafeCacheWrapper != null ? docusafeCacheWrapper.getDocumentGuardCache() : null; if (documentGuardCache != null) { String cacheKey = DocumentGuardCache.cacheKeyToString(keyStoreAccess, documentKeyID); PasswordAndDocumentKeyIDWithKeyAndAccessType passwordAndDocumentKeyIDWithKeyAndAccessTypeFromCache = documentGuardCache.get(cacheKey); if (passwordAndDocumentKeyIDWithKeyAndAccessTypeFromCache != null) { if (passwordAndDocumentKeyIDWithKeyAndAccessTypeFromCache.getReadKeyPassword().equals(keyStoreAccess.getKeyStoreAuth().getReadKeyPassword())) { LOGGER.debug("AAA return document key for cache key " + cacheKey); return documentGuardCache.get(cacheKey).getDocumentKeyIDWithKeyAndAccessType(); } // Password war falsch, wir lassen den Aufrufer abtauchen und die original Exception erhalten documentGuardCache.remove(cacheKey); } } return null; }
@Override public void putBlobStream(BucketPath bucketPath, PayloadStream payloadStream) { putBlobStreamWithTempFile(bucketPath, payloadStream); storeMetadata(bucketPath, payloadStream.getStorageMetadata()); }
private Location copyLocation(Set<String> ids, org.jclouds.domain.Location l){ if(l==null) return null; if(ids.contains(l.getId())) return null; ids.add(l.getId()); LocationScope scope = l.getScope()==null?null:LocationScope.valueOf(l.getScope().name()); Location parent = copyLocation(ids, l.getParent()); return new LocationImpl(scope, l.getId(), l.getDescription(), parent, l.getIso3166Codes(), l.getMetadata()); } }
/** * Checks if the user with the given key credential has a store. * * @return if the given key credential has a store */ public boolean hasStore() { return keystorePersistence.hasKeystore(keyCredentials.getHandle()); }
private static ReadStorePassword getReadStorePassword(UserID userID) { return new ReadStorePassword("ReadStorePasswordFor" + userID.getValue()); }
private KeyStoreAccess getKeyStoreAccess(UserIDAuth userIDAuth) { BucketPath keyStorePath = UserIDUtil.getKeyStorePath(userIDAuth.getUserID()); KeyStoreAuth keyStoreAuth = UserIDUtil.getKeyStoreAuth(userIDAuth); KeyStoreAccess keyStoreAccess = new KeyStoreAccess(keyStorePath, keyStoreAuth); return keyStoreAccess; }
private static String bucketPath2String(BucketPath bucketPath) { return bucketPath.getObjectHandle().getContainer() + BucketPath.BUCKET_SEPARATOR + bucketPath.getObjectHandle().getName(); }