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 "fulltokenid", 056 "httpproxypassword", 057 "keypassword", 058 "keystore", 059 "keystorepassword", 060 "login", 061 "oauthaccesstoken", 062 "oauthappid", 063 "oauthappsecret", 064 "oauthclientid", 065 "oauthclientsecret", 066 "oauthtoken", 067 "oauthtokenurl", 068 "p12filename", 069 "passcode", 070 "passphrase", 071 "password", 072 "privatekey", 073 "privatekeyfile", 074 "privatekeyname", 075 "privatekeypassword", 076 "proxyauthpassword", 077 "proxyauthusername", 078 "proxypassword", 079 "proxyuser", 080 "publickeyid", 081 "publishkey", 082 "queueownerawsaccountid", 083 "refreshtoken", 084 "sascredential", 085 "sasljaasconfig", 086 "sassignature", 087 "secretkey", 088 "securerandom", 089 "sharedaccesskey", 090 "sourceblobaccesskey", 091 "sslkeypassword", 092 "sslkeystore", 093 "sslkeystorepassword", 094 "sslpassword", 095 "ssltruststorepassword", 096 "subscribekey", 097 "systemid", 098 "token", 099 "tokencredential", 100 "user", 101 "userauthenticationcredentials", 102 "username", 103 "userpassword", 104 "verificationcode", 105 "webhookverifytoken", 106 "zookeeperpassword" 107 // SENSITIVE-KEYS: END 108 ))); 109 110 private static final String SENSITIVE_PATTERN = "" 111 // Generated by camel build tools - do NOT edit this list! 112 // SENSITIVE-PATTERN: START 113 + "\\Qaccesskey\\E" 114 + "|\\Qaccesstoken\\E" 115 + "|\\Qaccesstokensecret\\E" 116 + "|\\Qaccountkey\\E" 117 + "|\\Qaccountsid\\E" 118 + "|\\Qacltoken\\E" 119 + "|\\Qapi_key\\E" 120 + "|\\Qapi_secret\\E" 121 + "|\\Qapipassword\\E" 122 + "|\\Qapiuser\\E" 123 + "|\\Qapiusername\\E" 124 + "|\\Qauthkey\\E" 125 + "|\\Qauthorizationtoken\\E" 126 + "|\\Qblobaccesskey\\E" 127 + "|\\Qblobstoragesharedkeycredential\\E" 128 + "|\\Qcertresourcepassword\\E" 129 + "|\\Qcipherkey\\E" 130 + "|\\Qclientid\\E" 131 + "|\\Qclientsecret\\E" 132 + "|\\Qclientsecretcredential\\E" 133 + "|\\Qconnectionstring\\E" 134 + "|\\Qconsumerkey\\E" 135 + "|\\Qconsumersecret\\E" 136 + "|\\Qemailaddress\\E" 137 + "|\\Qfulltokenid\\E" 138 + "|\\Qhttpproxypassword\\E" 139 + "|\\Qkeypassword\\E" 140 + "|\\Qkeystore\\E" 141 + "|\\Qkeystorepassword\\E" 142 + "|\\Qlogin\\E" 143 + "|\\Qoauthaccesstoken\\E" 144 + "|\\Qoauthappid\\E" 145 + "|\\Qoauthappsecret\\E" 146 + "|\\Qoauthclientid\\E" 147 + "|\\Qoauthclientsecret\\E" 148 + "|\\Qoauthtoken\\E" 149 + "|\\Qoauthtokenurl\\E" 150 + "|\\Qp12filename\\E" 151 + "|\\Qpasscode\\E" 152 + "|\\Qpassphrase\\E" 153 + "|\\Qpassword\\E" 154 + "|\\Qprivatekey\\E" 155 + "|\\Qprivatekeyfile\\E" 156 + "|\\Qprivatekeyname\\E" 157 + "|\\Qprivatekeypassword\\E" 158 + "|\\Qproxyauthpassword\\E" 159 + "|\\Qproxyauthusername\\E" 160 + "|\\Qproxypassword\\E" 161 + "|\\Qproxyuser\\E" 162 + "|\\Qpublickeyid\\E" 163 + "|\\Qpublishkey\\E" 164 + "|\\Qqueueownerawsaccountid\\E" 165 + "|\\Qrefreshtoken\\E" 166 + "|\\Qsascredential\\E" 167 + "|\\Qsasljaasconfig\\E" 168 + "|\\Qsassignature\\E" 169 + "|\\Qsecretkey\\E" 170 + "|\\Qsecurerandom\\E" 171 + "|\\Qsharedaccesskey\\E" 172 + "|\\Qsourceblobaccesskey\\E" 173 + "|\\Qsslkeypassword\\E" 174 + "|\\Qsslkeystore\\E" 175 + "|\\Qsslkeystorepassword\\E" 176 + "|\\Qsslpassword\\E" 177 + "|\\Qssltruststorepassword\\E" 178 + "|\\Qsubscribekey\\E" 179 + "|\\Qsystemid\\E" 180 + "|\\Qtoken\\E" 181 + "|\\Qtokencredential\\E" 182 + "|\\Quser\\E" 183 + "|\\Quserauthenticationcredentials\\E" 184 + "|\\Qusername\\E" 185 + "|\\Quserpassword\\E" 186 + "|\\Qverificationcode\\E" 187 + "|\\Qwebhookverifytoken\\E" 188 + "|\\Qzookeeperpassword\\E" 189 // SENSITIVE-PATTERN: END 190 ; 191 192 private SensitiveUtils() { 193 } 194 195 /** 196 * All the sensitive keys (unmodifiable) in lower-case 197 */ 198 public static Set<String> getSensitiveKeys() { 199 return SENSITIVE_KEYS; 200 } 201 202 /** 203 * All the sensitive keys (unmodifiable) in lower-case for regular expression matching 204 */ 205 public static String getSensitivePattern() { 206 return SENSITIVE_PATTERN; 207 } 208 209 /** 210 * Whether the given configuration property contains a sensitive key (such as password, accesstoken, etc.) 211 * 212 * @param text the configuration property 213 * @return true if sensitive, false otherwise 214 */ 215 public static boolean containsSensitive(String text) { 216 int lastPeriod = text.lastIndexOf('.'); 217 if (lastPeriod >= 0) { 218 text = text.substring(lastPeriod + 1); 219 } 220 text = text.toLowerCase(Locale.ENGLISH); 221 text = text.replace("-", ""); 222 return SENSITIVE_KEYS.contains(text); 223 } 224 225}