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