Skip to content

Commit 4d039db

Browse files
Alter key generation logic V3 (#3041)
* Alter key generation logic v3 * Added the appropriate namespace
1 parent d4c20ad commit 4d039db

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/Azure.Functions.Cli/Kubernetes/FuncKeys/FuncAppKeysHelper.cs

+5-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
using Azure.Functions.Cli.Kubernetes.Models.Kubernetes;
2-
using Colors.Net;
3-
using System;
42
using System.Collections.Generic;
53
using System.Linq;
6-
using System.Runtime.InteropServices.WindowsRuntime;
7-
using System.Security.Cryptography;
8-
using System.Text;
9-
using System.Threading.Tasks;
4+
using Microsoft.Azure.WebJobs.Script.WebHost.Security;
105

116
namespace Azure.Functions.Cli.Kubernetes.FuncKeys
127
{
@@ -30,16 +25,16 @@ public static IDictionary<string, string> CreateKeys(IEnumerable<string> functio
3025
{
3126
var funcAppKeys = new Dictionary<string, string>
3227
{
33-
{ MasterKey, GenerateKey() },
34-
{ HostFunctionKey, GenerateKey() },
35-
{ HostSystemKey, GenerateKey() }
28+
{ MasterKey, SecretGenerator.GenerateMasterKeyValue() },
29+
{ HostFunctionKey, SecretGenerator.GenerateFunctionKeyValue() },
30+
{ HostSystemKey, SecretGenerator.GenerateSystemKeyValue() }
3631
};
3732

3833
if (functionNames?.Any() == true)
3934
{
4035
foreach (var funcName in functionNames)
4136
{
42-
funcAppKeys[$"{FunctionKeyPrefix}{funcName.ToLower()}.{FunctionDefaultKeyName}"] = GenerateKey();
37+
funcAppKeys[$"{FunctionKeyPrefix}{funcName.ToLower()}.{FunctionDefaultKeyName}"] = SecretGenerator.GenerateFunctionKeyValue();
4338
}
4439
}
4540

@@ -93,18 +88,5 @@ public static void CreateFuncAppKeysVolumeMountDeploymentResource(IEnumerable<De
9388
};
9489
}
9590
}
96-
97-
private static string GenerateKey()
98-
{
99-
using (var rng = RandomNumberGenerator.Create())
100-
{
101-
byte[] data = new byte[40];
102-
rng.GetBytes(data);
103-
string secret = Convert.ToBase64String(data);
104-
105-
// Replace pluses as they are problematic as URL values
106-
return secret.Replace('+', 'a');
107-
}
108-
}
10991
}
11092
}

0 commit comments

Comments
 (0)