001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.core.protocol.xkms.generators;
013:
014: import java.security.cert.X509Certificate;
015:
016: import org.ejbca.core.model.ra.UserDataVO;
017: import org.ejbca.core.protocol.xkms.common.XKMSConstants;
018: import org.w3._2002._03.xkms_.KeyBindingAbstractType;
019: import org.w3._2002._03.xkms_.KeyBindingType;
020: import org.w3._2002._03.xkms_.RecoverRequestType;
021: import org.w3._2002._03.xkms_.RecoverResultType;
022: import org.w3c.dom.Document;
023:
024: /**
025: * Class generating a response for a recover call
026: *
027: *
028: * @author Philip Vendil
029: *
030: * @version $Id: RecoverResponseGenerator.java,v 1.1 2007/01/05 05:32:51 herrvendil Exp $
031: */
032:
033: public class RecoverResponseGenerator extends KRSSResponseGenerator {
034: //private static Logger log = Logger.getLogger(RecoverResponseGenerator.class);
035:
036: public RecoverResponseGenerator(String remoteIP,
037: RecoverRequestType req, Document requestDoc) {
038: super (remoteIP, req, requestDoc);
039: }
040:
041: /**
042: * Returns a register response
043: */
044: public RecoverResultType getResponse(boolean requestVerifies) {
045: RecoverResultType result = xkmsFactory
046: .createRecoverResultType();
047: super .populateResponse(result, requestVerifies);
048: RecoverRequestType req = (RecoverRequestType) this .req;
049:
050: if (resultMajor == null) {
051: if (!checkValidRespondWithRequest(req.getRespondWith(),
052: false)) {
053: resultMajor = XKMSConstants.RESULTMAJOR_SENDER;
054: resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
055: }
056:
057: if (resultMajor == null) {
058: if (resultMajor == null) {
059: X509Certificate cert = (X509Certificate) getPublicKeyInfo(
060: req, false);
061:
062: UserDataVO userData = findUserData(cert);
063: if (userData != null) {
064: String password = "";
065: boolean encryptedPassword = isPasswordEncrypted(req);
066: if (encryptedPassword) {
067: password = getEncryptedPassword(requestDoc,
068: userData.getPassword());
069: } else {
070: password = getClearPassword(req, userData
071: .getPassword());
072: }
073:
074: if (password != null) {
075: X509Certificate newCert = registerReissueOrRecover(
076: true, false, result, userData,
077: password, cert.getPublicKey(), null);
078: if (newCert != null) {
079: KeyBindingAbstractType keyBinding = getResponseValues(
080: req.getRecoverKeyBinding(),
081: newCert, false, true);
082: result.getKeyBinding().add(
083: (KeyBindingType) keyBinding);
084: }
085: }
086: }
087:
088: }
089: }
090: }
091:
092: if (resultMajor == null) {
093: resultMajor = XKMSConstants.RESULTMAJOR_SUCCESS;
094: }
095:
096: setResult(result);
097:
098: return result;
099: }
100:
101: }
|