use of com.fathomdb.crypto.CryptoKey in project platformlayer by platformlayer.
the class JoinProject method runCommand.
@Override
public Object runCommand() throws RepositoryException, IOException {
UserDatabase userRepository = getContext().getUserRepository();
UserEntity me = getContext().loginDirect();
ProjectEntity project = userRepository.findProjectByKey(projectKey.getKey());
if (project == null) {
throw new CliException("Project not found: " + projectKey.getKey());
}
SecretStore secretStore = new SecretStore(project.secretData);
CryptoKey projectSecret = secretStore.getSecretFromUser(me);
if (projectSecret == null) {
String msg = "Cannot retrieve project secret.";
msg += " Is " + me.key + " a member of " + project.getName() + "?";
throw new CliException(msg);
}
if (Strings.isNullOrEmpty(roleKey)) {
throw new CliException("Role is required");
}
RoleId role = new RoleId(roleKey);
userRepository.addUserToProject(username.getKey(), project.getName(), projectSecret, Collections.singletonList(role));
return project;
}
use of com.fathomdb.crypto.CryptoKey in project platformlayer by platformlayer.
the class SimpleAuthenticationSecrets method buildToken.
@Override
public byte[] buildToken(CryptoKey userSecret) {
byte tokenId = currentTokenId;
CryptoKey secret = secrets.get(tokenId);
if (secret == null) {
throw new IllegalStateException();
}
byte[] plaintext = FathomdbCrypto.serialize(userSecret);
byte[] ciphertext = secret.encrypt(plaintext);
byte[] header = new byte[1];
header[0] = tokenId;
return Bytes.concat(header, ciphertext);
}
use of com.fathomdb.crypto.CryptoKey in project platformlayer by platformlayer.
the class SimpleAuthenticationSecrets method decryptSecretFromToken.
@Override
public CryptoKey decryptSecretFromToken(byte[] tokenSecret) {
if (tokenSecret.length <= 2) {
return null;
}
byte tokenId = tokenSecret[0];
CryptoKey secret = secrets.get(tokenId);
if (secret == null) {
return null;
}
byte[] ciphertext = Arrays.copyOfRange(tokenSecret, 1, tokenSecret.length);
byte[] plaintext = secret.decrypt(ciphertext);
return FathomdbCrypto.deserializeKey(plaintext);
}
use of com.fathomdb.crypto.CryptoKey in project platformlayer by platformlayer.
the class OpsContextBuilder method buildDirectAuthenticator.
private DirectAuthenticator buildDirectAuthenticator(ProjectAuthorization project) {
String auth = DirectAuthenticationToken.encodeToken(project.getId(), project.getName());
CryptoKey secret = project.getProjectSecret();
DirectAuthenticationToken token = new DirectAuthenticationToken(auth, secret);
DirectAuthenticator directAuthenticator = new DirectAuthenticator(token);
return directAuthenticator;
}
use of com.fathomdb.crypto.CryptoKey in project platformlayer by platformlayer.
the class PlatformLayerAuthAdminClient method buildPlatformlayerProjectAuthorization.
private PlatformlayerProjectAuthorization buildPlatformlayerProjectAuthorization(PlatformlayerUserAuthentication user, ProjectValidation project) {
String name = project.getName();
int projectId = Integer.parseInt(project.getId());
List<RoleId> roles = Lists.newArrayList();
for (Role role : project.getRoles()) {
roles.add(new RoleId(role.getName()));
}
CryptoKey projectSecret = FathomdbCrypto.deserializeKey(project.getSecret());
return new PlatformlayerProjectAuthorization(user, name, projectSecret, roles, projectId);
}
Aggregations