Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Improved DB password masking to mask special characters (non alpha-numeric) as well #9

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.iws
build
out
logs
8 changes: 6 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.8.1 (2012/06/26)
------------------
* improved DB password masking to mask special characters (non alpha-numeric) as well

1.8.0 (2012/03/31)
------------------
* implemented [ticket #6](https://github.com/linkedin/linkedin-utils/issues/6): _Using Jackson JSON (de)serializer_ (thanks for the help from Zoran @ LinkedIn)
Expand Down Expand Up @@ -41,7 +45,7 @@ Note that ``prettyPrint`` returns a slightly different output than before (keys
------------------
* fixed [bug #1](https://github.com/linkedin/linkedin-utils/issues/1): _GroovyIOUtils.cat leaks memory_

revisited several concepts dealing with the creation of temporary files
revisited several concepts dealing with the creation of temporary files

1.3.0 (2011/01/17)
------------------
Expand All @@ -59,4 +63,4 @@ Note that ``prettyPrint`` returns a slightly different output than before (keys

1.0.0 (2010/11/05)
------------------
* First release
* First release
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ public class DataMaskingInputStream extends FilterInputStream {
value = "********"
}

if(value.contains('password=')){
value=value.replaceAll("password=[^&]*", "password=********")
}

if (value.contains('oracle')) {
value = value.replaceAll("\\w*/\\w*", '********/********')
value = value.replaceAll("\\w*/[^@]*", '********/********')
}

return "${prefix}${key}${middle}${value}${suffix}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2010 LinkedIn, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package test.util.io

import org.linkedin.groovy.util.io.DataMaskingInputStream

/**
* User: hhan
* Date: 6/18/12
* Time: 3:16 PM
* @author [email protected]
*/
class TestDataMaskingInputStream extends GroovyTestCase {

void testOracleDBContent()
{
def input = '<property name="db.member2.db_url" value="jdbc:oracle:thin:Encrypted-AES/CBC/PKCS5Padding(3QIdAjOKfAqcetGKhHEWez,0VWjpS2ewydmPFX8y-F3M_,umlHnS9A)@//test.prod.linkedin.com:1521/PROD_PMEM2_MEMBER2" /> \n'

DataMaskingInputStream stream = new DataMaskingInputStream(new ByteArrayInputStream(input.getBytes("UTF-8")))
def lines = stream.readLines()
stream.close()
assertTrue(lines.size() == 1)

String line = lines[0].trim()
String expected = '<property name="db.member2.db_url" value="jdbc:oracle:thin:Encrypted-********/********@********/********" />'
assertEquals(line, expected)
}

void testMySQLDBContent()
{
def input = '<property name="repdb.mysql.dbURL" value="jdbc:mysql://localhost/repdb_db?user=repdb&amp;password=test!123#^" /> \n'

DataMaskingInputStream stream = new DataMaskingInputStream(new ByteArrayInputStream(input.getBytes("UTF-8")))
def lines = stream.readLines()
stream.close()
assertTrue(lines.size() == 1)

String line = lines[0].trim()
String expected = '<property name="repdb.mysql.dbURL" value="jdbc:mysql://localhost/repdb_db?user=repdb&amp;password=********" />'
assertEquals(line, expected)
}

}
2 changes: 1 addition & 1 deletion project-spec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
spec = [
name: 'linkedin-utils',
group: 'org.linkedin',
version: '1.8.0',
version: '1.8.1',

versions: [
groovy: '1.7.5',
Expand Down