Search in sources :

Example 6 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method incorrect2.

void incorrect2(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.withKeySpec(DataKeySpec.AES_256);
    request.setNumberOfBytes(32);
    // :: error: argument
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Example 7 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project testcases by coheigea.

the class CommonCallbackHandler method handle.

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof WSPasswordCallback) {
            WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
            if (pc.getUsage() == WSPasswordCallback.SECRET_KEY) {
                final AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
                AWSKMSClient kms = new AWSKMSClient(creds);
                kms.setEndpoint(endpoint);
                if (pc.getEncryptedSecret() != null) {
                    ByteBuffer encryptedKey = ByteBuffer.wrap(pc.getEncryptedSecret());
                    DecryptRequest req = new DecryptRequest().withCiphertextBlob(encryptedKey);
                    ByteBuffer plaintextKey = kms.decrypt(req).getPlaintext();
                    byte[] key = new byte[plaintextKey.remaining()];
                    plaintextKey.get(key);
                    pc.setKey(key);
                } else {
                    GenerateDataKeyRequest dataKeyRequest = new GenerateDataKeyRequest();
                    dataKeyRequest.setKeyId(masterKeyId);
                    String algorithm = "AES_128";
                    if (pc.getAlgorithm() != null && pc.getAlgorithm().contains("aes256")) {
                        algorithm = "AES_256";
                    }
                    dataKeyRequest.setKeySpec(algorithm);
                    GenerateDataKeyResult dataKeyResult = kms.generateDataKey(dataKeyRequest);
                    ByteBuffer plaintextKey = dataKeyResult.getPlaintext();
                    byte[] key = new byte[plaintextKey.remaining()];
                    plaintextKey.get(key);
                    pc.setKey(key);
                    ByteBuffer encryptedKey = dataKeyResult.getCiphertextBlob();
                    byte[] encKey = new byte[encryptedKey.remaining()];
                    encryptedKey.get(encKey);
                    pc.setEncryptedSecret(encKey);
                    // Create a KeyName pointing to the encryption key
                    Document doc = DOMUtils.newDocument();
                    Element keyInfoElement = doc.createElementNS(WSConstants.SIG_NS, WSConstants.SIG_PREFIX + ":" + WSConstants.KEYINFO_LN);
                    keyInfoElement.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:" + WSConstants.SIG_PREFIX, WSConstants.SIG_NS);
                    Element keyNameElement = doc.createElementNS(WSConstants.SIG_NS, WSConstants.SIG_PREFIX + ":KeyName");
                    keyNameElement.setTextContent("1c84a3f2-51cc-4c66-9045-68f51ef8b1eb");
                    keyInfoElement.appendChild(keyNameElement);
                    pc.setKeyInfoReference(keyInfoElement);
                }
            }
        }
    }
}
Also used : GenerateDataKeyResult(com.amazonaws.services.kms.model.GenerateDataKeyResult) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ByteBuffer(java.nio.ByteBuffer) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest) AWSKMSClient(com.amazonaws.services.kms.AWSKMSClient) WSPasswordCallback(org.apache.wss4j.common.ext.WSPasswordCallback) DecryptRequest(com.amazonaws.services.kms.model.DecryptRequest)

Example 8 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method setTwice3.

void setTwice3(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.withNumberOfBytes(32);
    request.setNumberOfBytes(32);
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Example 9 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method correctSetNumberOfBytes.

void correctSetNumberOfBytes(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.setNumberOfBytes(32);
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Example 10 with GenerateDataKeyRequest

use of com.amazonaws.services.kms.model.GenerateDataKeyRequest in project checker-framework by typetools.

the class GenerateDataKeyRequestExamples method setTwice1.

// Calling these methods are idempotent, including between with/set versions of the same.
// TODO: Verify that these calls should be permitted.
void setTwice1(AWSKMS client) {
    GenerateDataKeyRequest request = new GenerateDataKeyRequest();
    request.withKeySpec(DataKeySpec.AES_256);
    request.withKeySpec(DataKeySpec.AES_256);
    client.generateDataKey(request);
}
Also used : GenerateDataKeyRequest(com.amazonaws.services.kms.model.GenerateDataKeyRequest)

Aggregations

GenerateDataKeyRequest (com.amazonaws.services.kms.model.GenerateDataKeyRequest)15 GenerateDataKeyResult (com.amazonaws.services.kms.model.GenerateDataKeyResult)2 ByteBuffer (java.nio.ByteBuffer)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AWSKMS (com.amazonaws.services.kms.AWSKMS)1 AWSKMSClient (com.amazonaws.services.kms.AWSKMSClient)1 DecryptRequest (com.amazonaws.services.kms.model.DecryptRequest)1 WSPasswordCallback (org.apache.wss4j.common.ext.WSPasswordCallback)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1