-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b88ed00
commit 160f61c
Showing
19 changed files
with
649 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
//using Microsoft.TeamFoundation.DistributedTask.Logging; | ||
using ValueEncoder = Microsoft.TeamFoundation.DistributedTask.Logging.ValueEncoder; | ||
using System; | ||
using Microsoft.Security.Utilities; | ||
|
||
using ISecretMaskerTfs = Microsoft.TeamFoundation.DistributedTask.Logging.ISecretMasker; | ||
|
||
namespace Agent.Sdk.SecretMasking | ||
{ | ||
/// <summary> | ||
/// Extended ISecretMasker interface that is adding support of logging secret masker methods | ||
/// </summary> | ||
public interface ILoggedSecretMasker : ISecretMasker | ||
public interface ILoggedSecretMasker : ISecretMasker, ISecretMaskerTfs | ||
{ | ||
static int MinSecretLengthLimit { get; } | ||
static int MinimumSecretLength { get; } | ||
|
||
void AddRegex(String pattern, string origin); | ||
void AddValue(String value, string origin); | ||
void AddValueEncoder(ValueEncoder encoder, string origin); | ||
void AddValueEncoder(LiteralEncoder encoder, string origin); | ||
void SetTrace(ITraceWriter trace); | ||
new string MaskSecrets(string input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
//using Microsoft.TeamFoundation.DistributedTask.Logging; | ||
using Newtonsoft.Json; | ||
|
||
using System; | ||
using System.Text; | ||
|
||
namespace Agent.Sdk.SecretMasking | ||
{ | ||
public static class LiteralEncoders | ||
{ | ||
public static String JsonStringEscape(String value) | ||
{ | ||
// Convert to a JSON string and then remove the leading/trailing double-quote. | ||
String jsonString = JsonConvert.ToString(value); | ||
String jsonEscapedValue = jsonString.Substring(startIndex: 1, length: jsonString.Length - 2); | ||
return jsonEscapedValue; | ||
} | ||
|
||
public static String BackslashEscape(String value) | ||
{ | ||
return value.Replace(@"\\", @"\").Replace(@"\'", @"'").Replace(@"\""", @"""").Replace(@"\t", "\t"); | ||
} | ||
|
||
public static String UriDataEscape(String value) | ||
{ | ||
return UriDataEscape(value, 65519); | ||
} | ||
|
||
internal static String UriDataEscape( | ||
String value, | ||
Int32 maxSegmentSize) | ||
{ | ||
if (value.Length <= maxSegmentSize) | ||
{ | ||
return Uri.EscapeDataString(value); | ||
} | ||
|
||
// Workaround size limitation in Uri.EscapeDataString | ||
var result = new StringBuilder(); | ||
var i = 0; | ||
do | ||
{ | ||
var length = Math.Min(value.Length - i, maxSegmentSize); | ||
|
||
if (Char.IsHighSurrogate(value[i + length - 1]) && length > 1) | ||
{ | ||
length--; | ||
} | ||
|
||
result.Append(Uri.EscapeDataString(value.Substring(i, length))); | ||
i += length; | ||
} | ||
while (i < value.Length); | ||
|
||
return result.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.