1
1
using Azure . Functions . Cli . Kubernetes . Models . Kubernetes ;
2
- using Colors . Net ;
3
- using System ;
4
2
using System . Collections . Generic ;
5
3
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 ;
10
5
11
6
namespace Azure . Functions . Cli . Kubernetes . FuncKeys
12
7
{
@@ -30,16 +25,16 @@ public static IDictionary<string, string> CreateKeys(IEnumerable<string> functio
30
25
{
31
26
var funcAppKeys = new Dictionary < string , string >
32
27
{
33
- { MasterKey , GenerateKey ( ) } ,
34
- { HostFunctionKey , GenerateKey ( ) } ,
35
- { HostSystemKey , GenerateKey ( ) }
28
+ { MasterKey , SecretGenerator . GenerateMasterKeyValue ( ) } ,
29
+ { HostFunctionKey , SecretGenerator . GenerateFunctionKeyValue ( ) } ,
30
+ { HostSystemKey , SecretGenerator . GenerateSystemKeyValue ( ) }
36
31
} ;
37
32
38
33
if ( functionNames ? . Any ( ) == true )
39
34
{
40
35
foreach ( var funcName in functionNames )
41
36
{
42
- funcAppKeys [ $ "{ FunctionKeyPrefix } { funcName . ToLower ( ) } .{ FunctionDefaultKeyName } "] = GenerateKey ( ) ;
37
+ funcAppKeys [ $ "{ FunctionKeyPrefix } { funcName . ToLower ( ) } .{ FunctionDefaultKeyName } "] = SecretGenerator . GenerateFunctionKeyValue ( ) ;
43
38
}
44
39
}
45
40
@@ -93,18 +88,5 @@ public static void CreateFuncAppKeysVolumeMountDeploymentResource(IEnumerable<De
93
88
} ;
94
89
}
95
90
}
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
- }
109
91
}
110
92
}
0 commit comments