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