@@ -81,7 +81,8 @@ public function seal(string $name, string $value): void
81
81
$ this ->lastMessage = null ;
82
82
$ this ->validateName ($ name );
83
83
$ this ->loadKeys ();
84
- $ this ->export ($ name .'. ' .substr (md5 ($ name ), 0 , 6 ), sodium_crypto_box_seal ($ value , $ this ->encryptionKey ?? sodium_crypto_box_publickey ($ this ->decryptionKey )));
84
+ $ filename = $ this ->getFilename ($ name );
85
+ $ this ->export ($ filename , sodium_crypto_box_seal ($ value , $ this ->encryptionKey ?? sodium_crypto_box_publickey ($ this ->decryptionKey )));
85
86
86
87
$ list = $ this ->list ();
87
88
$ list [$ name ] = null ;
@@ -96,7 +97,8 @@ public function reveal(string $name): ?string
96
97
$ this ->lastMessage = null ;
97
98
$ this ->validateName ($ name );
98
99
99
- if (!is_file ($ file = $ this ->pathPrefix .$ name .'. ' .substr_replace (md5 ($ name ), '.php ' , -26 ))) {
100
+ $ filename = $ this ->getFilename ($ name );
101
+ if (!is_file ($ file = $ this ->pathPrefix .$ filename .'.php ' )) {
100
102
$ this ->lastMessage = sprintf ('Secret "%s" not found in "%s". ' , $ name , $ this ->getPrettyPath (\dirname ($ this ->pathPrefix ).\DIRECTORY_SEPARATOR ));
101
103
102
104
return null ;
@@ -130,7 +132,8 @@ public function remove(string $name): bool
130
132
$ this ->lastMessage = null ;
131
133
$ this ->validateName ($ name );
132
134
133
- if (!is_file ($ file = $ this ->pathPrefix .$ name .'. ' .substr_replace (md5 ($ name ), '.php ' , -26 ))) {
135
+ $ filename = $ this ->getFilename ($ name );
136
+ if (!is_file ($ file = $ this ->pathPrefix .$ filename .'.php ' )) {
134
137
$ this ->lastMessage = sprintf ('Secret "%s" not found in "%s". ' , $ name , $ this ->getPrettyPath (\dirname ($ this ->pathPrefix ).\DIRECTORY_SEPARATOR ));
135
138
136
139
return false ;
@@ -194,16 +197,16 @@ private function loadKeys(): void
194
197
}
195
198
}
196
199
197
- private function export (string $ file , string $ data ): void
200
+ private function export (string $ filename , string $ data ): void
198
201
{
199
- $ b64 = 'decrypt.private ' === $ file ? '// SYMFONY_DECRYPTION_SECRET= ' .base64_encode ($ data )."\n" : '' ;
200
- $ name = basename ($ this ->pathPrefix .$ file );
202
+ $ b64 = 'decrypt.private ' === $ filename ? '// SYMFONY_DECRYPTION_SECRET= ' .base64_encode ($ data )."\n" : '' ;
203
+ $ name = basename ($ this ->pathPrefix .$ filename );
201
204
$ data = str_replace ('% ' , '\x ' , rawurlencode ($ data ));
202
205
$ data = sprintf ("<?php // %s on %s \n\n%sreturn \"%s \"; \n" , $ name , date ('r ' ), $ b64 , $ data );
203
206
204
207
$ this ->createSecretsDir ();
205
208
206
- if (false === file_put_contents ($ this ->pathPrefix .$ file .'.php ' , $ data , \LOCK_EX )) {
209
+ if (false === file_put_contents ($ this ->pathPrefix .$ filename .'.php ' , $ data , \LOCK_EX )) {
207
210
$ e = error_get_last ();
208
211
throw new \ErrorException ($ e ['message ' ] ?? 'Failed to write secrets data. ' , 0 , $ e ['type ' ] ?? \E_USER_WARNING );
209
212
}
@@ -217,4 +220,10 @@ private function createSecretsDir(): void
217
220
218
221
$ this ->secretsDir = null ;
219
222
}
223
+
224
+ private function getFilename (string $ name ): string
225
+ {
226
+ // The MD5 hash allows making secrets case-sensitive. The filename is not enough on Windows.
227
+ return $ name .'. ' .substr (md5 ($ name ), 0 , 6 );
228
+ }
220
229
}
0 commit comments