001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.util; 018 019import java.util.Arrays; 020import java.util.Collections; 021import java.util.HashSet; 022import java.util.Locale; 023import java.util.Set; 024 025public final class SensitiveUtils { 026 027 private static final Set<String> SENSITIVE_KEYS = Collections.unmodifiableSet(new HashSet<>( 028 Arrays.asList( 029 // Generated by camel build tools - do NOT edit this list! 030 // SENSITIVE-KEYS: START 031 "accesskey", 032 "accesstoken", 033 "accesstokensecret", 034 "accountkey", 035 "accountsid", 036 "acltoken", 037 "api_key", 038 "api_secret", 039 "apipassword", 040 "apiuser", 041 "apiusername", 042 "authkey", 043 "authorizationtoken", 044 "blobaccesskey", 045 "blobstoragesharedkeycredential", 046 "certresourcepassword", 047 "cipherkey", 048 "clientid", 049 "clientsecret", 050 "clientsecretcredential", 051 "connectionstring", 052 "consumerkey", 053 "consumersecret", 054 "emailaddress", 055 "httpproxypassword", 056 "keystore", 057 "login", 058 "oauthaccesstoken", 059 "oauthappid", 060 "oauthappsecret", 061 "oauthclientid", 062 "oauthclientsecret", 063 "oauthtoken", 064 "oauthtokenurl", 065 "p12filename", 066 "passcode", 067 "passphrase", 068 "password", 069 "privatekey", 070 "privatekeyfile", 071 "privatekeyname", 072 "privatekeypassword", 073 "proxyauthpassword", 074 "proxyauthusername", 075 "proxypassword", 076 "proxyuser", 077 "publickeyid", 078 "publishkey", 079 "queueownerawsaccountid", 080 "refreshtoken", 081 "sascredential", 082 "sasljaasconfig", 083 "sassignature", 084 "secret", 085 "secretkey", 086 "securerandom", 087 "sharedaccesskey", 088 "sourceblobaccesskey", 089 "sslkeypassword", 090 "sslkeystore", 091 "sslkeystorepassword", 092 "sslpassword", 093 "ssltruststorepassword", 094 "subscribekey", 095 "systemid", 096 "token", 097 "tokencredential", 098 "user", 099 "username", 100 "userpassword", 101 "verificationcode", 102 "webhookverifytoken", 103 "zookeeperpassword" 104 // SENSITIVE-KEYS: END 105 ))); 106 107 private static final String SENSITIVE_PATTERN = "" 108 // Generated by camel build tools - do NOT edit this list! 109 // SENSITIVE-PATTERN: START 110 + "\\Qaccesskey\\E" 111 + "|\\Qaccesstoken\\E" 112 + "|\\Qaccesstokensecret\\E" 113 + "|\\Qaccountkey\\E" 114 + "|\\Qaccountsid\\E" 115 + "|\\Qacltoken\\E" 116 + "|\\Qapi_key\\E" 117 + "|\\Qapi_secret\\E" 118 + "|\\Qapipassword\\E" 119 + "|\\Qapiuser\\E" 120 + "|\\Qapiusername\\E" 121 + "|\\Qauthkey\\E" 122 + "|\\Qauthorizationtoken\\E" 123 + "|\\Qblobaccesskey\\E" 124 + "|\\Qblobstoragesharedkeycredential\\E" 125 + "|\\Qcertresourcepassword\\E" 126 + "|\\Qcipherkey\\E" 127 + "|\\Qclientid\\E" 128 + "|\\Qclientsecret\\E" 129 + "|\\Qclientsecretcredential\\E" 130 + "|\\Qconnectionstring\\E" 131 + "|\\Qconsumerkey\\E" 132 + "|\\Qconsumersecret\\E" 133 + "|\\Qemailaddress\\E" 134 + "|\\Qhttpproxypassword\\E" 135 + "|\\Qkeystore\\E" 136 + "|\\Qlogin\\E" 137 + "|\\Qoauthaccesstoken\\E" 138 + "|\\Qoauthappid\\E" 139 + "|\\Qoauthappsecret\\E" 140 + "|\\Qoauthclientid\\E" 141 + "|\\Qoauthclientsecret\\E" 142 + "|\\Qoauthtoken\\E" 143 + "|\\Qoauthtokenurl\\E" 144 + "|\\Qp12filename\\E" 145 + "|\\Qpasscode\\E" 146 + "|\\Qpassphrase\\E" 147 + "|\\Qpassword\\E" 148 + "|\\Qprivatekey\\E" 149 + "|\\Qprivatekeyfile\\E" 150 + "|\\Qprivatekeyname\\E" 151 + "|\\Qprivatekeypassword\\E" 152 + "|\\Qproxyauthpassword\\E" 153 + "|\\Qproxyauthusername\\E" 154 + "|\\Qproxypassword\\E" 155 + "|\\Qproxyuser\\E" 156 + "|\\Qpublickeyid\\E" 157 + "|\\Qpublishkey\\E" 158 + "|\\Qqueueownerawsaccountid\\E" 159 + "|\\Qrefreshtoken\\E" 160 + "|\\Qsascredential\\E" 161 + "|\\Qsasljaasconfig\\E" 162 + "|\\Qsassignature\\E" 163 + "|\\Qsecret\\E" 164 + "|\\Qsecretkey\\E" 165 + "|\\Qsecurerandom\\E" 166 + "|\\Qsharedaccesskey\\E" 167 + "|\\Qsourceblobaccesskey\\E" 168 + "|\\Qsslkeypassword\\E" 169 + "|\\Qsslkeystore\\E" 170 + "|\\Qsslkeystorepassword\\E" 171 + "|\\Qsslpassword\\E" 172 + "|\\Qssltruststorepassword\\E" 173 + "|\\Qsubscribekey\\E" 174 + "|\\Qsystemid\\E" 175 + "|\\Qtoken\\E" 176 + "|\\Qtokencredential\\E" 177 + "|\\Quser\\E" 178 + "|\\Qusername\\E" 179 + "|\\Quserpassword\\E" 180 + "|\\Qverificationcode\\E" 181 + "|\\Qwebhookverifytoken\\E" 182 + "|\\Qzookeeperpassword\\E" 183 // SENSITIVE-PATTERN: END 184 ; 185 186 private SensitiveUtils() { 187 } 188 189 /** 190 * All the sensitive keys (unmodifiable) in lower-case 191 */ 192 public static Set<String> getSensitiveKeys() { 193 return SENSITIVE_KEYS; 194 } 195 196 /** 197 * All the sensitive keys (unmodifiable) in lower-case for regular expression matching 198 */ 199 public static String getSensitivePattern() { 200 return SENSITIVE_PATTERN; 201 } 202 203 /** 204 * Whether the given configuration property contains a sensitive key (such as password, accesstoken, etc.) 205 * 206 * @param text the configuration property 207 * @return true if sensitive, false otherwise 208 */ 209 public static boolean containsSensitive(String text) { 210 int lastPeriod = text.lastIndexOf('.'); 211 if (lastPeriod >= 0) { 212 text = text.substring(lastPeriod + 1); 213 } 214 text = text.toLowerCase(Locale.ENGLISH); 215 text = text.replace("-", ""); 216 return SENSITIVE_KEYS.contains(text); 217 } 218 219}