Search in sources :

Example 1 with Attribute

use of com.ingrian.internal.kmip.api.Attribute in project CipherTrust_Application_Protection by thalescpl-io.

the class KMIPGetCustomAttribute method printCustomAttribute.

private static void printCustomAttribute(KMIPAttributes returnedAttributes) {
    for (Attribute a : returnedAttributes.attributes) {
        if (a.getAttributeName().getCustomName() != null) {
            System.out.println("CustomAttribute: " + a.getAttributeName().getCustomName() + " " + a.getAttributeIndex().getAttributeIndex() + " " + returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()));
            String customDataTypes = returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()).toString();
            if (customDataTypes.equals("TextString"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeTextString(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
            else if (customDataTypes.equals("DateTime"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeCalendar(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()).getTimeInMillis());
            else if (customDataTypes.equals("Integer"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeInt(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
            else if (customDataTypes.equals("Boolean"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeBoolean(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
        }
    }
}
Also used : Attribute(com.ingrian.internal.kmip.api.Attribute) KMIPAttribute(com.ingrian.security.nae.KMIPAttributeNames.KMIPAttribute)

Example 2 with Attribute

use of com.ingrian.internal.kmip.api.Attribute in project CipherTrust_Application_Protection by thalescpl-io.

the class KMIPLocateSample method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        usage();
    }
    // add Ingrian provider to the list of JCE providers
    Security.addProvider(new IngrianProvider());
    KMIPSession session = null;
    try {
        // create NAE Session: pass in NAE Client Certificate clicnt key and keystore password
        session = KMIPSession.getSession(new NAEClientCertificate(args[0], args[1].toCharArray()));
        // This set holds the managed object unique identifiers (UIDs)
        Set<String> managedObjectIdentifiers;
        // Locate keys with crypto algorithm = aes and crypto length = 256
        KMIPAttributes queryAttributes = new KMIPAttributes();
        /* 
             * IMPORTANT-In case of locate by name it is compulsory to pass argument for keyName as below 
             *  [-Name locateKeyName] where locateKeyName will be value of userInput.
             * */
        if (args.length > 3) {
            if (args[2] != null && "-Name".equals(args[2])) {
                queryAttributes.add(new Attribute(KMIPAttribute.Name, args[3]));
            }
        }
        // Have the session locate the keys matching the queryAttributes:
        managedObjectIdentifiers = session.locate(queryAttributes);
        // loop through the UIDs of the matching managed objects
        System.out.println("Total Keys: " + managedObjectIdentifiers.size());
        for (String uid : managedObjectIdentifiers) {
            System.out.println("Managed object Unique Identifier: " + uid);
            // get the objects as Java client NAEKeys or KMIPSecretData objects
            // (Note: Secret Data doesn't have KMIP attributes of
            // algorithm or length, and will not be found by this query,
            // but is included here for completeness.
            byte[] keyMaterial = null;
            Object managedObject = session.getManagedObject(uid);
            // not a key
            if (managedObject == null)
                continue;
            if (managedObject instanceof NAEPublicKey) {
                System.out.println(((NAEPublicKey) managedObject).getName());
                keyMaterial = ((NAEKey) managedObject).export();
            } else if (managedObject instanceof NAEPrivateKey) {
                System.out.println(((NAEPrivateKey) managedObject).getName());
                keyMaterial = ((NAEKey) managedObject).export();
            } else if (managedObject instanceof NAESecretKey) {
                System.out.println(((NAESecretKey) managedObject).getName());
                keyMaterial = ((NAEKey) managedObject).export();
            } else if (managedObject instanceof KMIPSecretData) {
                System.out.println(((KMIPSecretData) managedObject).getName());
                keyMaterial = ((KMIPSecretData) managedObject).export();
            } else if (managedObject instanceof NAECertificate) {
                System.out.println(((NAECertificate) managedObject).getName());
                keyMaterial = ((NAECertificate) managedObject).certificateExport();
            }
            System.out.println("Key Material = " + TTLVUtil.toHexString(keyMaterial));
        }
    } catch (Exception e) {
        System.out.println("The Cause is " + e.getMessage() + ".");
        e.printStackTrace();
    } finally {
        if (session != null)
            session.closeSession();
    }
}
Also used : KMIPAttributes(com.ingrian.security.nae.KMIPAttributes) NAEKey(com.ingrian.security.nae.NAEKey) NAEPrivateKey(com.ingrian.security.nae.NAEPrivateKey) Attribute(com.ingrian.internal.kmip.api.Attribute) KMIPAttribute(com.ingrian.security.nae.KMIPAttributeNames.KMIPAttribute) NAESecretKey(com.ingrian.security.nae.NAESecretKey) NAECertificate(com.ingrian.security.nae.NAECertificate) NAEPublicKey(com.ingrian.security.nae.NAEPublicKey) KMIPSecretData(com.ingrian.security.nae.KMIPSecretData) NAEClientCertificate(com.ingrian.security.nae.NAEClientCertificate) IngrianProvider(com.ingrian.security.nae.IngrianProvider) KMIPSession(com.ingrian.security.nae.KMIPSession)

Example 3 with Attribute

use of com.ingrian.internal.kmip.api.Attribute in project CipherTrust_Application_Protection by thalescpl-io.

the class KMIPSecretDataGetCustomAttributeSample method printCustomAttribute.

private static void printCustomAttribute(KMIPAttributes returnedAttributes) {
    for (Attribute a : returnedAttributes.attributes) {
        if (a.getAttributeName().getCustomName() != null) {
            System.out.println("CustomAttribute: " + a.getAttributeName().getCustomName() + " " + a.getAttributeIndex().getAttributeIndex() + " " + returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()));
            String customDataTypes = returnedAttributes.getCustomAttributeType(a.getAttributeName().getCustomName()).toString();
            if (customDataTypes.equals("TextString"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeTextString(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
            else if (customDataTypes.equals("DateTime"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeCalendar(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()).getTimeInMillis());
            else if (customDataTypes.equals("Integer"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeInt(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
            else if (customDataTypes.equals("Interval"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeInt(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
            else if (customDataTypes.equals("Boolean"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeBoolean(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
            else if (customDataTypes.equals("BigInteger"))
                System.out.println("CustomAttribute value: " + returnedAttributes.getCustomAttributeBigInteger(a.getAttributeName().getCustomName(), a.getAttributeIndex().getAttributeIndex()));
        }
    }
}
Also used : Attribute(com.ingrian.internal.kmip.api.Attribute)

Aggregations

Attribute (com.ingrian.internal.kmip.api.Attribute)3 KMIPAttribute (com.ingrian.security.nae.KMIPAttributeNames.KMIPAttribute)2 IngrianProvider (com.ingrian.security.nae.IngrianProvider)1 KMIPAttributes (com.ingrian.security.nae.KMIPAttributes)1 KMIPSecretData (com.ingrian.security.nae.KMIPSecretData)1 KMIPSession (com.ingrian.security.nae.KMIPSession)1 NAECertificate (com.ingrian.security.nae.NAECertificate)1 NAEClientCertificate (com.ingrian.security.nae.NAEClientCertificate)1 NAEKey (com.ingrian.security.nae.NAEKey)1 NAEPrivateKey (com.ingrian.security.nae.NAEPrivateKey)1 NAEPublicKey (com.ingrian.security.nae.NAEPublicKey)1 NAESecretKey (com.ingrian.security.nae.NAESecretKey)1