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                    "apikey",
040                    "apipassword",
041                    "apiuser",
042                    "apiusername",
043                    "authenticationtoken",
044                    "authkey",
045                    "authorizationtoken",
046                    "authtoken",
047                    "azureclientid",
048                    "azureclientsecret",
049                    "blobaccesskey",
050                    "blobstoragesharedkeycredential",
051                    "certresourcepassword",
052                    "clientid",
053                    "clientsecret",
054                    "clientsecretcredential",
055                    "connectionstring",
056                    "consumerkey",
057                    "consumersecret",
058                    "emailaddress",
059                    "functionkey",
060                    "hostkey",
061                    "httpproxypassword",
062                    "kerberosauthticket",
063                    "keypassword",
064                    "keystorePassword",
065                    "keystorepassword",
066                    "login",
067                    "oauthclientid",
068                    "oauthclientsecret",
069                    "oauthtoken",
070                    "oauthtokenurl",
071                    "p12filename",
072                    "passcode",
073                    "passphrase",
074                    "password",
075                    "personalaccesstoken",
076                    "privatekey",
077                    "privatekeyfile",
078                    "privatekeyname",
079                    "privatekeypassword",
080                    "proxyauthpassword",
081                    "proxyauthusername",
082                    "proxypassword",
083                    "proxyuser",
084                    "proxyusername",
085                    "publickeyid",
086                    "publishkey",
087                    "queueownerawsaccountid",
088                    "realm",
089                    "refreshtoken",
090                    "sascredential",
091                    "sasljaasconfig",
092                    "saslpassword",
093                    "sassignature",
094                    "secret",
095                    "secretkey",
096                    "securerandom",
097                    "serviceinstanceid",
098                    "sessiontoken",
099                    "sharedaccesskey",
100                    "sourceblobaccesskey",
101                    "sslkeypassword",
102                    "sslkeystorepassword",
103                    "sslpassword",
104                    "ssltruststorepassword",
105                    "storageaccountconnectionstring",
106                    "subscribekey",
107                    "subscriptionid",
108                    "systemid",
109                    "token",
110                    "tokencredential",
111                    "truststorepassword",
112                    "user",
113                    "userauthenticationcredentials",
114                    "username",
115                    "userpassword",
116                    "verificationcode",
117                    "webhookverifytoken",
118                    "zookeeperpassword"
119            // SENSITIVE-KEYS: END
120            )));
121
122    private static final String SENSITIVE_PATTERN = ""
123                                                    // Generated by camel build tools - do NOT edit this list!
124                                                    // SENSITIVE-PATTERN: START
125                                                    + "\\Qaccesskey\\E"
126                                                    + "|\\Qaccesstoken\\E"
127                                                    + "|\\Qaccesstokensecret\\E"
128                                                    + "|\\Qaccountkey\\E"
129                                                    + "|\\Qaccountsid\\E"
130                                                    + "|\\Qacltoken\\E"
131                                                    + "|\\Qapi_key\\E"
132                                                    + "|\\Qapi_secret\\E"
133                                                    + "|\\Qapikey\\E"
134                                                    + "|\\Qapipassword\\E"
135                                                    + "|\\Qapiuser\\E"
136                                                    + "|\\Qapiusername\\E"
137                                                    + "|\\Qauthenticationtoken\\E"
138                                                    + "|\\Qauthkey\\E"
139                                                    + "|\\Qauthorizationtoken\\E"
140                                                    + "|\\Qauthtoken\\E"
141                                                    + "|\\Qazureclientid\\E"
142                                                    + "|\\Qazureclientsecret\\E"
143                                                    + "|\\Qblobaccesskey\\E"
144                                                    + "|\\Qblobstoragesharedkeycredential\\E"
145                                                    + "|\\Qcertresourcepassword\\E"
146                                                    + "|\\Qclientid\\E"
147                                                    + "|\\Qclientsecret\\E"
148                                                    + "|\\Qclientsecretcredential\\E"
149                                                    + "|\\Qconnectionstring\\E"
150                                                    + "|\\Qconsumerkey\\E"
151                                                    + "|\\Qconsumersecret\\E"
152                                                    + "|\\Qemailaddress\\E"
153                                                    + "|\\Qfunctionkey\\E"
154                                                    + "|\\Qhostkey\\E"
155                                                    + "|\\Qhttpproxypassword\\E"
156                                                    + "|\\Qkerberosauthticket\\E"
157                                                    + "|\\Qkeypassword\\E"
158                                                    + "|\\QkeystorePassword\\E"
159                                                    + "|\\Qkeystorepassword\\E"
160                                                    + "|\\Qlogin\\E"
161                                                    + "|\\Qoauthclientid\\E"
162                                                    + "|\\Qoauthclientsecret\\E"
163                                                    + "|\\Qoauthtoken\\E"
164                                                    + "|\\Qoauthtokenurl\\E"
165                                                    + "|\\Qp12filename\\E"
166                                                    + "|\\Qpasscode\\E"
167                                                    + "|\\Qpassphrase\\E"
168                                                    + "|\\Qpassword\\E"
169                                                    + "|\\Qpersonalaccesstoken\\E"
170                                                    + "|\\Qprivatekey\\E"
171                                                    + "|\\Qprivatekeyfile\\E"
172                                                    + "|\\Qprivatekeyname\\E"
173                                                    + "|\\Qprivatekeypassword\\E"
174                                                    + "|\\Qproxyauthpassword\\E"
175                                                    + "|\\Qproxyauthusername\\E"
176                                                    + "|\\Qproxypassword\\E"
177                                                    + "|\\Qproxyuser\\E"
178                                                    + "|\\Qproxyusername\\E"
179                                                    + "|\\Qpublickeyid\\E"
180                                                    + "|\\Qpublishkey\\E"
181                                                    + "|\\Qqueueownerawsaccountid\\E"
182                                                    + "|\\Qrealm\\E"
183                                                    + "|\\Qrefreshtoken\\E"
184                                                    + "|\\Qsascredential\\E"
185                                                    + "|\\Qsasljaasconfig\\E"
186                                                    + "|\\Qsaslpassword\\E"
187                                                    + "|\\Qsassignature\\E"
188                                                    + "|\\Qsecret\\E"
189                                                    + "|\\Qsecretkey\\E"
190                                                    + "|\\Qsecurerandom\\E"
191                                                    + "|\\Qserviceinstanceid\\E"
192                                                    + "|\\Qsessiontoken\\E"
193                                                    + "|\\Qsharedaccesskey\\E"
194                                                    + "|\\Qsourceblobaccesskey\\E"
195                                                    + "|\\Qsslkeypassword\\E"
196                                                    + "|\\Qsslkeystorepassword\\E"
197                                                    + "|\\Qsslpassword\\E"
198                                                    + "|\\Qssltruststorepassword\\E"
199                                                    + "|\\Qstorageaccountconnectionstring\\E"
200                                                    + "|\\Qsubscribekey\\E"
201                                                    + "|\\Qsubscriptionid\\E"
202                                                    + "|\\Qsystemid\\E"
203                                                    + "|\\Qtoken\\E"
204                                                    + "|\\Qtokencredential\\E"
205                                                    + "|\\Qtruststorepassword\\E"
206                                                    + "|\\Quser\\E"
207                                                    + "|\\Quserauthenticationcredentials\\E"
208                                                    + "|\\Qusername\\E"
209                                                    + "|\\Quserpassword\\E"
210                                                    + "|\\Qverificationcode\\E"
211                                                    + "|\\Qwebhookverifytoken\\E"
212                                                    + "|\\Qzookeeperpassword\\E"
213    // SENSITIVE-PATTERN: END
214    ;
215
216    private SensitiveUtils() {
217    }
218
219    /**
220     * All the sensitive keys (unmodifiable) in lower-case
221     */
222    public static Set<String> getSensitiveKeys() {
223        return SENSITIVE_KEYS;
224    }
225
226    /**
227     * All the sensitive keys (unmodifiable) in lower-case for regular expression matching
228     */
229    public static String getSensitivePattern() {
230        return SENSITIVE_PATTERN;
231    }
232
233    /**
234     * Whether the given configuration property contains a sensitive key (such as password, accesstoken, etc.)
235     *
236     * @param  text the configuration property
237     * @return      true if sensitive, false otherwise
238     */
239    public static boolean containsSensitive(String text) {
240        int lastPeriod = text.lastIndexOf('.');
241        if (lastPeriod >= 0) {
242            text = text.substring(lastPeriod + 1);
243        }
244        text = text.toLowerCase(Locale.ENGLISH);
245        text = text.replace("-", "");
246        return SENSITIVE_KEYS.contains(text);
247    }
248
249}