ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/tribes/membership/cloud/CertificateStreamProvider.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/tribes/membership/cloud/CertificateStreamProvider.java
Status
scanned
Type
file
Name
CertificateStreamProvider.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3784 (3.7 KB)
MD5
1df3ec97162d6cb610908b0d8f4d109f
SHA1
2fcc3063325531d8107147d5db134ed29a846d3b
SHA256
fb5f82dd3592cb2357156bf15ec9da2deb7a3d0605195b0d0790d1b42221398b
SHA512

      
    
SHA1_git
a69a06062da9a37461f02380bef2612ee8533d38
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
CertificateStreamProvider.java | 3.7 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.catalina.tribes.membership.cloud; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; import java.security.PrivateKey; import java.security.cert.Certificate; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.net.jsse.PEMFile; public class CertificateStreamProvider extends AbstractStreamProvider { private static final Log log = LogFactory.getLog(CertificateStreamProvider.class); private final SSLSocketFactory factory; CertificateStreamProvider(String clientCertFile, String clientKeyFile, String clientKeyPassword, String clientKeyAlgo, String caCertFile) throws Exception { char[] password = (clientKeyPassword != null) ? clientKeyPassword.toCharArray() : new char[0]; KeyManager[] keyManagers = configureClientCert(clientCertFile, clientKeyFile, password, clientKeyAlgo); TrustManager[] trustManagers = configureCaCert(caCertFile); SSLContext context = SSLContext.getInstance("TLS"); context.init(keyManagers, trustManagers, null); factory = context.getSocketFactory(); } @Override protected SSLSocketFactory getSocketFactory() { return factory; } private static KeyManager[] configureClientCert(String clientCertFile, String clientKeyFile, char[] clientKeyPassword, String clientKeyAlgo) throws Exception { try (InputStream certInputStream = new FileInputStream(clientCertFile)) { CertificateFactory certFactory = CertificateFactory.getInstance("X509"); X509Certificate cert = (X509Certificate) certFactory.generateCertificate(certInputStream); PEMFile pemFile = new PEMFile(clientKeyFile, new String(clientKeyPassword), clientKeyAlgo); PrivateKey privKey = pemFile.getPrivateKey(); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(null, null); String alias = cert.getSubjectX500Principal().getName(); keyStore.setKeyEntry(alias, privKey, clientKeyPassword, new Certificate[] { cert }); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManagerFactory.init(keyStore, clientKeyPassword); return keyManagerFactory.getKeyManagers(); } catch (IOException ioe) { log.error(sm.getString("certificateStream.clientCertError", clientCertFile, clientKeyFile)); throw ioe; } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
32.51
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