Search in sources :

Example 1 with CryptoKey

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;
}
Also used : CliException(com.fathomdb.cli.CliException) ProjectEntity(org.platformlayer.auth.ProjectEntity) UserDatabase(org.platformlayer.auth.UserDatabase) CryptoKey(com.fathomdb.crypto.CryptoKey) SecretStore(org.platformlayer.auth.crypto.SecretStore) RoleId(org.platformlayer.model.RoleId) UserEntity(org.platformlayer.auth.UserEntity)

Example 2 with CryptoKey

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);
}
Also used : CryptoKey(com.fathomdb.crypto.CryptoKey)

Example 3 with CryptoKey

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);
}
Also used : CryptoKey(com.fathomdb.crypto.CryptoKey)

Example 4 with CryptoKey

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;
}
Also used : DirectAuthenticationToken(org.platformlayer.auth.DirectAuthenticationToken) CryptoKey(com.fathomdb.crypto.CryptoKey) DirectAuthenticator(org.platformlayer.auth.DirectAuthenticator)

Example 5 with CryptoKey

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);
}
Also used : Role(org.platformlayer.auth.v1.Role) CryptoKey(com.fathomdb.crypto.CryptoKey) RoleId(org.platformlayer.model.RoleId)

Aggregations

CryptoKey (com.fathomdb.crypto.CryptoKey)18 RepositoryException (org.platformlayer.RepositoryException)8 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)6 SQLException (java.sql.SQLException)6 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)5 SecretStore (org.platformlayer.auth.crypto.SecretStore)4 IOException (java.io.IOException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 KeyPair (java.security.KeyPair)2 DirectAuthenticationToken (org.platformlayer.auth.DirectAuthenticationToken)2 DirectAuthenticator (org.platformlayer.auth.DirectAuthenticator)2 UserEntity (org.platformlayer.auth.UserEntity)2 Writer (org.platformlayer.auth.crypto.SecretStore.Writer)2 SecretInfo (org.platformlayer.core.model.SecretInfo)2 ManagedItemId (org.platformlayer.ids.ManagedItemId)2 ProjectAuthorization (org.platformlayer.model.ProjectAuthorization)2 RoleId (org.platformlayer.model.RoleId)2 CliException (com.fathomdb.cli.CliException)1 PublicKey (java.security.PublicKey)1 Certificate (java.security.cert.Certificate)1