Package org.keyczar

Examples of org.keyczar.GenericKeyczar


    public GenericKeyczar find(String key, Crypter crypter) throws KeyczarException {
        KeyczarWriter reader = getReader(key, crypter);
        if (!hasMetadata(reader)) {
            return null;
        }
        return new GenericKeyczar(reader);
    }
View Full Code Here


        KeyczarWriter reader = buildStore(zk, location, crypter);
        if (hasMetadata(reader)) {
            throw new IllegalStateException();
        }

        GenericKeyczar keyczar = GenericKeyczar.create(reader, kmd);
        return keyczar;

    }
View Full Code Here

    }

    private void createKeys() throws KeyczarException {
        {
            Crypter crypter = null;
            GenericKeyczar store = keyczarFactory.find(Secrets.KEY_TOKEN_ENCRYPT, crypter);
            if (store == null) {
                String nameFlag = "Authentication Token Encryption";

                KeyMetadata kmd = new KeyMetadata(nameFlag, KeyPurpose.DECRYPT_AND_ENCRYPT, DefaultKeyType.RSA_PRIV);
                store = keyczarFactory.create(Secrets.KEY_TOKEN_ENCRYPT, kmd, crypter);
            }
            keyczarFactory.ensureKeyCreated(store);
        }

        {
            Crypter crypter = null;
            GenericKeyczar store = keyczarFactory.find(SharedSecretTokenService.KEYSTORE_ID, crypter);
            if (store == null) {
                String nameFlag = "Authentication Token Signing";

                KeyMetadata kmd = new KeyMetadata(nameFlag, KeyPurpose.SIGN_AND_VERIFY, DefaultKeyType.HMAC_SHA1);
                store = keyczarFactory.create(SharedSecretTokenService.KEYSTORE_ID, kmd, crypter);
View Full Code Here

    @Override
    public void ensureCreated(String key, KeyMetadata keyMetadata) {
        try {
            Crypter crypter = null;
            GenericKeyczar store = keyczarFactory.find(key, crypter);
            if (store == null) {
                store = keyczarFactory.create(key, keyMetadata, crypter);
            }
            keyczarFactory.ensureKeyCreated(store);
        } catch (KeyczarException e) {
View Full Code Here

        }

        log.info("Checking for existing password-recovery key");
        {
            Crypter crypter = null;
            GenericKeyczar store = keyczarFactory.find(Secrets.KEY_FORGOT_PASSWORD_PUBLIC, crypter);
            if (store != null) {
                // TODO: Should we allow key rotation? Replacement?
                log.info("Password-recovery key already exists");
                return;
            }
        }

        log.info("Creating password recovery key");

        String nameFlag = "Password recovery keystore";

        String metadata = null;

        {
            path.mkdirs();

            KeyczarFileReader store = new KeyczarFileReader(path.getAbsolutePath());

            try {
                metadata = store.getMetadata();
            } catch (Exception e) {
                log.info("Metadata not found");
            }

            if (metadata == null) {
                KeyMetadata kmd = new KeyMetadata(nameFlag, KeyPurpose.DECRYPT_AND_ENCRYPT, DefaultKeyType.RSA_PRIV);
                GenericKeyczar.create(store, kmd);
            }
        }

        {
            KeyczarFileReader store = new KeyczarFileReader(path.getAbsolutePath());

            GenericKeyczar keyczar = new GenericKeyczar(store);

            for (KeyVersion version : keyczar.getVersions()) {
                log.info("Local password recovery key already exists; exiting for safety");
                return;
            }

            KeyParameters keyParameters = DefaultKeyType.RSA_PRIV.applyDefaultParameters(new RsaKeyParameters() {
                @Override
                public int getKeySize() throws KeyczarException {
                    return 4096;
                }

                @Override
                public RsaPadding getRsaPadding() throws KeyczarException {
                    // Use default
                    return null;
                }
            });
            keyczar.addVersion(KeyStatus.PRIMARY, keyParameters);
            keyczar.write();

            log.info("Storing public key in zookeeper");

            keyczarFactory.publicKeyExport(Secrets.KEY_FORGOT_PASSWORD_PUBLIC, keyczar);
View Full Code Here

TOP

Related Classes of org.keyczar.GenericKeyczar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.