ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/net/ocsp/TesterOcspResponder.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/net/ocsp/TesterOcspResponder.java
Status
scanned
Type
file
Name
TesterOcspResponder.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4681 (4.6 KB)
MD5
c3d8881945027b7556e22a5f29c48905
SHA1
2bf45508da2f0a7bb33f5723145f5c48d1bb0f1e
SHA256
c4a35111c83ea6d519148ad3fa790ba6016b0d3dabf771afd597f91c5a887292
SHA512

      
    
SHA1_git
659bc88c951177b66e7ca54d0849fbf0826a8f8c
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterOcspResponder.java | 4.6 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.util.net.ocsp; import java.io.IOException; import java.io.PrintStream; import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.apache.tomcat.util.net.TesterSupport; /* * The OpenSSL ocsp tool is great, but it does generate a lot of output. That output needs to be swallowed, else the * process will freeze when the output buffers (stdout and stderr) are full. * * There is a command line option to redirect stdout (which could be redirected to /dev/null), but there is no option to * redirect stderr. Therefore, this class uses a couple of dedicated threads to read stdout and stderr. By default, the * output is ignored, but it can be dumped to Java's stdout/stderr if required for debugging purposes. */ public class TesterOcspResponder { private static List<String> ocspArgs = Arrays.asList("ocsp", "-port", "8888", "-text", "-index", TesterSupport.DB_INDEX, "-CA", TesterSupport.CA_CERT_PEM, "-rkey", TesterSupport.OCSP_RESPONDER_RSA_KEY, "-rsigner", TesterSupport.OCSP_RESPONDER_RSA_CERT, "-nmin", "60"); private Process p; public void start() throws IOException { if (p != null) { throw new IllegalStateException("Already started"); } String openSSLPath = System.getProperty("tomcat.test.openssl.path"); String openSSLLibPath = null; if (openSSLPath == null || openSSLPath.length() == 0) { openSSLPath = "openssl"; } else { // Explicit OpenSSL path may also need explicit lib path // (e.g. Gump needs this) openSSLLibPath = openSSLPath.substring(0, openSSLPath.lastIndexOf('/')); openSSLLibPath = openSSLLibPath + "/../:" + openSSLLibPath + "/../lib:" + openSSLLibPath + "/../lib64"; } List<String> cmd = new ArrayList<>(); cmd.add(openSSLPath); cmd.addAll(ocspArgs); ProcessBuilder pb = new ProcessBuilder(cmd.toArray(new String[0])); if (openSSLLibPath != null) { Map<String,String> env = pb.environment(); String libraryPath = env.get("LD_LIBRARY_PATH"); if (libraryPath == null) { libraryPath = openSSLLibPath; } else { libraryPath = libraryPath + ":" + openSSLLibPath; } env.put("LD_LIBRARY_PATH", libraryPath); } p = pb.start(); redirect(p.inputReader(), System.out, true); redirect(p.errorReader(), System.err, true); Assert.assertTrue(p.isAlive()); } public void stop() { if (p == null) { throw new IllegalStateException("Not started"); } p.destroy(); try { if (!p.waitFor(30, TimeUnit.SECONDS)) { throw new IllegalStateException("Failed to stop"); } } catch (InterruptedException e) { throw new IllegalStateException("Interrupted while waiting to stop", e); } } private void redirect(final Reader r, final PrintStream os, final boolean swallow) { /* * InputStream will close when process ends. Thread will exit once stream closes. */ new Thread( () -> { char[] cbuf = new char[1024]; try { int read; while ((read = r.read(cbuf)) > 0) { if (!swallow) { os.print(new String(cbuf, 0, read)); } } } catch (IOException ignore) { // Ignore } }).start(); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
23.33
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9