-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
base/kra/src/main/java/org/dogtagpki/server/kra/rest/v2/KRAInfoServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Copyright Red Hat, Inc. | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// | ||
package org.dogtagpki.server.kra.rest.v2; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.dogtagpki.common.KRAInfo; | ||
import org.mozilla.jss.netscape.security.util.WrappingParams; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.netscape.certsrv.base.WebAction; | ||
|
||
/** | ||
* @author Marco Fargetta {@literal <[email protected]>} | ||
*/ | ||
@WebServlet( | ||
name = "kraInfo", | ||
urlPatterns = "/v2/info") | ||
public class KRAInfoServlet extends KRAServlet { | ||
private static final long serialVersionUID = 1L; | ||
private static final Logger logger = LoggerFactory.getLogger(KRAInfoServlet.class); | ||
private static final String ENCRYPT_MECHANISM = "encrypt"; | ||
private static final String KEYWRAP_MECHANISM = "keywrap"; | ||
|
||
@WebAction(method = HttpMethod.GET, paths = {""}) | ||
public void getInfo(HttpServletRequest request, HttpServletResponse response) throws Exception { | ||
HttpSession session = request.getSession(); | ||
logger.debug("KRAInfoService.getInfo(): session: {}", session.getId()); | ||
boolean encryptArchival = config.getBoolean("kra.allowEncDecrypt.archival", false); | ||
|
||
KRAInfo info = new KRAInfo(); | ||
String encryptArchivalMechanism = encryptArchival ? | ||
ENCRYPT_MECHANISM : KEYWRAP_MECHANISM; | ||
info.setArchivalMechanism(encryptArchivalMechanism); | ||
|
||
String encryptRecovery = config.getBoolean("kra.allowEncDecrypt.recovery", false) ? | ||
ENCRYPT_MECHANISM : KEYWRAP_MECHANISM; | ||
info.setRecoveryMechanism(encryptRecovery); | ||
|
||
String encryptAlgorithms; | ||
String wrappingParameters; | ||
try { | ||
WrappingParams params = storageUnit.getWrappingParams(encryptArchival); | ||
encryptAlgorithms = params.getPayloadEncryptionAlgorithm().toString(); | ||
wrappingParameters = params.getPayloadWrapAlgorithm().toString(); | ||
} catch (Exception e) { | ||
// return something that should always work | ||
encryptAlgorithms = "AES/CBC/Padding"; | ||
wrappingParameters = "AES/CBC/Padding"; | ||
} | ||
info.setEncryptAlgorithm(encryptAlgorithms); | ||
|
||
info.setWrapAlgorithm(wrappingParameters); | ||
|
||
String rsaWrap = config.getUseOAEPKeyWrap() ? | ||
"RSA_OAEP" : "RSA"; | ||
info.setRsaPublicKeyWrapAlgorithm(rsaWrap); | ||
|
||
PrintWriter out = response.getWriter(); | ||
out.println(info.toJSON()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,35 @@ | |
package org.dogtagpki.server.kra.rest.v2; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletException; | ||
|
||
import org.dogtagpki.server.kra.KRAEngine; | ||
import org.dogtagpki.server.kra.KRAEngineConfig; | ||
import org.dogtagpki.server.rest.v2.PKIServlet; | ||
|
||
import com.netscape.certsrv.security.IStorageKeyUnit; | ||
import com.netscape.kra.KeyRecoveryAuthority; | ||
|
||
/** | ||
* @author Marco Fargetta {@literal <[email protected]>} | ||
*/ | ||
public class KRAServlet extends PKIServlet { | ||
public static final long serialVersionUID = 1L; | ||
|
||
protected KRAEngine engine; | ||
protected KRAEngineConfig config; | ||
protected IStorageKeyUnit storageUnit; | ||
|
||
@Override | ||
public void init() throws ServletException { | ||
super.init(); | ||
|
||
engine = getKRAEngine(); | ||
config = engine.getConfig(); | ||
KeyRecoveryAuthority kra = (KeyRecoveryAuthority) engine.getSubsystem(KeyRecoveryAuthority.ID); | ||
storageUnit = kra.getStorageKeyUnit(); | ||
} | ||
|
||
public KRAEngine getKRAEngine() { | ||
ServletContext servletContext = getServletContext(); | ||
return (KRAEngine) servletContext.getAttribute("engine"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters