All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.xml.wss.impl.callback.DecryptionKeyCallback Maven / Gradle / Ivy

The newest version!
/*
 * $Id: DecryptionKeyCallback.java,v 1.3 2006/09/29 12:04:51 kumarjayanti Exp $
 */

/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License).  You may not use this file except in
 * compliance with the License.
 * 
 * You can obtain a copy of the license at
 * https://glassfish.dev.java.net/public/CDDLv1.0.html.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * you own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 * 
 * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
 */

package com.sun.xml.wss.impl.callback;

import javax.security.auth.callback.Callback;

import java.security.cert.X509Certificate;
import java.security.PrivateKey;
import java.security.PublicKey;

import java.math.BigInteger;

import javax.crypto.SecretKey;


/**
 * CallBack implementation for decryption key.
 *
 * @author XWS-Security Team
 */
public class DecryptionKeyCallback extends XWSSCallback implements Callback {

    public static interface Request {
    }

    private Request request;

    public DecryptionKeyCallback(Request request) {
        this.request = request;
    }

    public Request getRequest() {
        return request;
    }

    /**
     * CallBackHandler handling this request should set the private key to be
     * used for decryption on the request.
     */
    public static abstract class PrivateKeyRequest implements Request {

        PrivateKey privateKey;

        /**
         * Set the PrivateKey to be used for Decryption.
         * @param privateKey java.security.PrivateKey
         */
        public void setPrivateKey(PrivateKey privateKey) {
            this.privateKey = privateKey;
        }

        /**
         * Get the PrivateKey.
         * @return java.security.PrivateKey object set on this request.
         */
        public PrivateKey getPrivateKey() {
            return privateKey;
        }
    }

        /**
     * Request for a private key when the X.509 Subject Key Identifier
     * value for a corresponding X.509 Certificate is given.
     */
    public static class X509SubjectKeyIdentifierBasedRequest
        extends PrivateKeyRequest {

        private byte[] x509SubjectKeyIdentifier;

        /** 
         * Constructor.
         * It takes the byte stream of X509SubjectKeyIdentifier.
         */
        public X509SubjectKeyIdentifierBasedRequest(
            byte[] x509SubjectKeyIdentifier) {
            this.x509SubjectKeyIdentifier = x509SubjectKeyIdentifier;
        }

        /**
         * Get the byte stream of X509SubjectKeyIdentifier set on this request.
         * @return byte[] X509SubjectKeyIdentifier value (byte stream).
         */
        public byte[] getSubjectKeyIdentifier() {
            return x509SubjectKeyIdentifier;
        }
    }
    
    /**
     * Request for a private key when the X.509 Thumb print
     * value for a corresponding X.509 Certificate is given.
     * TODO: extends PrivateKeyRequest for now
     */
    public static class ThumbprintBasedRequest
        extends PrivateKeyRequest {

        private byte[] x509Thumbprint;

        /** 
         * Constructor.
         * It takes the byte stream of X509ThumbPrint.
         */
        public ThumbprintBasedRequest(
            byte[] x509Thumbprint) {
            this.x509Thumbprint = x509Thumbprint;
        }

        /**
         * Get the byte stream of X509ThumbPrint set on this request.
         * @return byte[] X509ThumbPrint value (byte stream).
         */
        public byte[] getThumbprintIdentifier() {
            return x509Thumbprint;
        }
    }

    /**
     * Request for a private key when the Issuer Name and Serial Number
     * values for a corresponding X.509 Certificate are given.
     */
    public static class X509IssuerSerialBasedRequest
        extends PrivateKeyRequest {

        private String issuerName;
        private BigInteger serialNumber;

        /**
         * 
         *
         * @param issuerName Name of the issuer.
         * @param serialNumber serial number of the Certificate.
         *
         */
        public X509IssuerSerialBasedRequest(
            String issuerName,
            BigInteger serialNumber) {
            this.issuerName = issuerName;
            this.serialNumber = serialNumber;
        }

        /**
         * Get the issuer name.
         *
         * @return String representation of Certificate Issuer name.
         */
        public String getIssuerName() {
            return issuerName;
        }

        /**
         * Get the Certificate Serial Number.
         *
         * @return java.math.BigInteger representing the Ceritificate's 
         * serial number.
         *
         */
        public BigInteger getSerialNumber() {
            return serialNumber;
        }
    }

    /**
     * Request for a private key when a corresponding X.509 Certificate
     * is given.
     */
    public static class X509CertificateBasedRequest extends PrivateKeyRequest {

        private X509Certificate certificate;

        /**
         * Constructor.
         *
         * @param certificate java.security.X509Certificate 
         * to be used for Decryption.
         */
        public X509CertificateBasedRequest(X509Certificate certificate) {
            this.certificate = certificate;
        }

        /**
         * Get the X509Certificate stored in this Request.
         *
         * @return java.security.X509Certificate
         */
        public X509Certificate getX509Certificate() {
            return certificate;
        }
    }


    /**
     * Request for a symmetric key to be used for decryption.
     */
    public static abstract class SymmetricKeyRequest implements Request {

        SecretKey symmetricKey;

        /**
         * Constructor.
         *
         * @param symmetricKey javax.crypto.SecretKey
         * to be used for Decryption.
         *
         */
        public void setSymmetricKey(SecretKey symmetricKey) {
            this.symmetricKey = symmetricKey;
        }

        /**
         * Get the SymmetricKey stored in this Request.
         *
         * @return javax.crypto.SecretKey
         */
        public SecretKey getSymmetricKey() {
            return symmetricKey;
        }
    }

    /**
     * Given an alias get the javax.crypto.SecretKey
     */
    public static class AliasSymmetricKeyRequest extends SymmetricKeyRequest {

        private String alias;

        /**
         * Constructor.
         *
         * @param alias java.lang.String representing the alias of the 
         * SymmetircKey to be used for Decryption.
         *
         */
        public AliasSymmetricKeyRequest(String alias) {
            this.alias = alias;
        }

        /**
         * Get the alias stored in this Request.
         *
         */
        public String getAlias() {
            return alias;
        }
    }

    /**
     * A Callback initialized with this request should be handled if the
     * private key to be used for decryption is to be retrieved given the PublicKey
     */
    public static class PublicKeyBasedPrivKeyRequest extends PrivateKeyRequest {
                                                                                                                                                         
        private PublicKey pk;
               
        /**
         * Constructor.
         *
         * @param publicKey java.security.PublicKey.
         *
         */
        public PublicKeyBasedPrivKeyRequest(PublicKey publicKey) {
            this.pk = publicKey;
        }
             
        /**
         * Get the PublicKey stored in this Request.
         *
         * @return java.security.PublicKey.
         */
        public PublicKey getPublicKey() {
            return pk;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy