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