001: /*
002: * $Id: DecryptionKeyCallback.java,v 1.3 2006/09/29 12:04:51 kumarjayanti Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.wss.impl.callback;
028:
029: import javax.security.auth.callback.Callback;
030:
031: import java.security.cert.X509Certificate;
032: import java.security.PrivateKey;
033: import java.security.PublicKey;
034:
035: import java.math.BigInteger;
036:
037: import javax.crypto.SecretKey;
038:
039: /**
040: * CallBack implementation for decryption key.
041: *
042: * @author XWS-Security Team
043: */
044: public class DecryptionKeyCallback extends XWSSCallback implements
045: Callback {
046:
047: public static interface Request {
048: }
049:
050: private Request request;
051:
052: public DecryptionKeyCallback(Request request) {
053: this .request = request;
054: }
055:
056: public Request getRequest() {
057: return request;
058: }
059:
060: /**
061: * CallBackHandler handling this request should set the private key to be
062: * used for decryption on the request.
063: */
064: public static abstract class PrivateKeyRequest implements Request {
065:
066: PrivateKey privateKey;
067:
068: /**
069: * Set the PrivateKey to be used for Decryption.
070: * @param privateKey <code>java.security.PrivateKey</code>
071: */
072: public void setPrivateKey(PrivateKey privateKey) {
073: this .privateKey = privateKey;
074: }
075:
076: /**
077: * Get the PrivateKey.
078: * @return <code>java.security.PrivateKey</code> object set on this request.
079: */
080: public PrivateKey getPrivateKey() {
081: return privateKey;
082: }
083: }
084:
085: /**
086: * Request for a private key when the X.509 Subject Key Identifier
087: * value for a corresponding X.509 Certificate is given.
088: */
089: public static class X509SubjectKeyIdentifierBasedRequest extends
090: PrivateKeyRequest {
091:
092: private byte[] x509SubjectKeyIdentifier;
093:
094: /**
095: * Constructor.
096: * It takes the byte stream of X509SubjectKeyIdentifier.
097: */
098: public X509SubjectKeyIdentifierBasedRequest(
099: byte[] x509SubjectKeyIdentifier) {
100: this .x509SubjectKeyIdentifier = x509SubjectKeyIdentifier;
101: }
102:
103: /**
104: * Get the byte stream of X509SubjectKeyIdentifier set on this request.
105: * @return byte[] X509SubjectKeyIdentifier value (byte stream).
106: */
107: public byte[] getSubjectKeyIdentifier() {
108: return x509SubjectKeyIdentifier;
109: }
110: }
111:
112: /**
113: * Request for a private key when the X.509 Thumb print
114: * value for a corresponding X.509 Certificate is given.
115: * TODO: extends PrivateKeyRequest for now
116: */
117: public static class ThumbprintBasedRequest extends
118: PrivateKeyRequest {
119:
120: private byte[] x509Thumbprint;
121:
122: /**
123: * Constructor.
124: * It takes the byte stream of X509ThumbPrint.
125: */
126: public ThumbprintBasedRequest(byte[] x509Thumbprint) {
127: this .x509Thumbprint = x509Thumbprint;
128: }
129:
130: /**
131: * Get the byte stream of X509ThumbPrint set on this request.
132: * @return byte[] X509ThumbPrint value (byte stream).
133: */
134: public byte[] getThumbprintIdentifier() {
135: return x509Thumbprint;
136: }
137: }
138:
139: /**
140: * Request for a private key when the Issuer Name and Serial Number
141: * values for a corresponding X.509 Certificate are given.
142: */
143: public static class X509IssuerSerialBasedRequest extends
144: PrivateKeyRequest {
145:
146: private String issuerName;
147: private BigInteger serialNumber;
148:
149: /**
150: *
151: *
152: * @param issuerName Name of the issuer.
153: * @param serialNumber serial number of the Certificate.
154: *
155: */
156: public X509IssuerSerialBasedRequest(String issuerName,
157: BigInteger serialNumber) {
158: this .issuerName = issuerName;
159: this .serialNumber = serialNumber;
160: }
161:
162: /**
163: * Get the issuer name.
164: *
165: * @return String representation of Certificate Issuer name.
166: */
167: public String getIssuerName() {
168: return issuerName;
169: }
170:
171: /**
172: * Get the Certificate Serial Number.
173: *
174: * @return <code>java.math.BigInteger</code> representing the Ceritificate's
175: * serial number.
176: *
177: */
178: public BigInteger getSerialNumber() {
179: return serialNumber;
180: }
181: }
182:
183: /**
184: * Request for a private key when a corresponding X.509 Certificate
185: * is given.
186: */
187: public static class X509CertificateBasedRequest extends
188: PrivateKeyRequest {
189:
190: private X509Certificate certificate;
191:
192: /**
193: * Constructor.
194: *
195: * @param certificate <code>java.security.X509Certificate</code>
196: * to be used for Decryption.
197: */
198: public X509CertificateBasedRequest(X509Certificate certificate) {
199: this .certificate = certificate;
200: }
201:
202: /**
203: * Get the X509Certificate stored in this Request.
204: *
205: * @return <code>java.security.X509Certificate</code>
206: */
207: public X509Certificate getX509Certificate() {
208: return certificate;
209: }
210: }
211:
212: /**
213: * Request for a symmetric key to be used for decryption.
214: */
215: public static abstract class SymmetricKeyRequest implements Request {
216:
217: SecretKey symmetricKey;
218:
219: /**
220: * Constructor.
221: *
222: * @param symmetricKey <code>javax.crypto.SecretKey</code>
223: * to be used for Decryption.
224: *
225: */
226: public void setSymmetricKey(SecretKey symmetricKey) {
227: this .symmetricKey = symmetricKey;
228: }
229:
230: /**
231: * Get the SymmetricKey stored in this Request.
232: *
233: * @return <code>javax.crypto.SecretKey</code>
234: */
235: public SecretKey getSymmetricKey() {
236: return symmetricKey;
237: }
238: }
239:
240: /**
241: * Given an alias get the <code>javax.crypto.SecretKey</code>
242: */
243: public static class AliasSymmetricKeyRequest extends
244: SymmetricKeyRequest {
245:
246: private String alias;
247:
248: /**
249: * Constructor.
250: *
251: * @param alias <code>java.lang.String</code> representing the alias of the
252: * SymmetircKey to be used for Decryption.
253: *
254: */
255: public AliasSymmetricKeyRequest(String alias) {
256: this .alias = alias;
257: }
258:
259: /**
260: * Get the alias stored in this Request.
261: *
262: */
263: public String getAlias() {
264: return alias;
265: }
266: }
267:
268: /**
269: * A Callback initialized with this request should be handled if the
270: * private key to be used for decryption is to be retrieved given the PublicKey
271: */
272: public static class PublicKeyBasedPrivKeyRequest extends
273: PrivateKeyRequest {
274:
275: private PublicKey pk;
276:
277: /**
278: * Constructor.
279: *
280: * @param publicKey <code>java.security.PublicKey</code>.
281: *
282: */
283: public PublicKeyBasedPrivKeyRequest(PublicKey publicKey) {
284: this .pk = publicKey;
285: }
286:
287: /**
288: * Get the PublicKey stored in this Request.
289: *
290: * @return <code>java.security.PublicKey</code>.
291: */
292: public PublicKey getPublicKey() {
293: return pk;
294: }
295: }
296:
297: }
|