@@ -85,7 +85,8 @@ public function seal(string $name, string $value): void
85
85
$ this ->lastMessage = null ;
86
86
$ this ->validateName ($ name );
87
87
$ this ->loadKeys ();
88
- $ this ->export ($ name .'. ' .substr (md5 ($ name ), 0 , 6 ), sodium_crypto_box_seal ($ value , $ this ->encryptionKey ?? sodium_crypto_box_publickey ($ this ->decryptionKey )));
88
+ $ filename = $ this ->getFilename ($ name );
89
+ $ this ->export ($ filename , sodium_crypto_box_seal ($ value , $ this ->encryptionKey ?? sodium_crypto_box_publickey ($ this ->decryptionKey )));
89
90
90
91
$ list = $ this ->list ();
91
92
$ list [$ name ] = null ;
@@ -100,7 +101,8 @@ public function reveal(string $name): ?string
100
101
$ this ->lastMessage = null ;
101
102
$ this ->validateName ($ name );
102
103
103
- if (!is_file ($ file = $ this ->pathPrefix .$ name .'. ' .substr_replace (md5 ($ name ), '.php ' , -26 ))) {
104
+ $ filename = $ this ->getFilename ($ name );
105
+ if (!is_file ($ file = $ this ->pathPrefix .$ filename .'.php ' )) {
104
106
$ this ->lastMessage = sprintf ('Secret "%s" not found in "%s". ' , $ name , $ this ->getPrettyPath (\dirname ($ this ->pathPrefix ).\DIRECTORY_SEPARATOR ));
105
107
106
108
return null ;
@@ -134,7 +136,8 @@ public function remove(string $name): bool
134
136
$ this ->lastMessage = null ;
135
137
$ this ->validateName ($ name );
136
138
137
- if (!is_file ($ file = $ this ->pathPrefix .$ name .'. ' .substr_replace (md5 ($ name ), '.php ' , -26 ))) {
139
+ $ filename = $ this ->getFilename ($ name );
140
+ if (!is_file ($ file = $ this ->pathPrefix .$ filename .'.php ' )) {
138
141
$ this ->lastMessage = sprintf ('Secret "%s" not found in "%s". ' , $ name , $ this ->getPrettyPath (\dirname ($ this ->pathPrefix ).\DIRECTORY_SEPARATOR ));
139
142
140
143
return false ;
@@ -198,16 +201,16 @@ private function loadKeys(): void
198
201
}
199
202
}
200
203
201
- private function export (string $ file , string $ data ): void
204
+ private function export (string $ filename , string $ data ): void
202
205
{
203
- $ b64 = 'decrypt.private ' === $ file ? '// SYMFONY_DECRYPTION_SECRET= ' .base64_encode ($ data )."\n" : '' ;
204
- $ name = basename ($ this ->pathPrefix .$ file );
206
+ $ b64 = 'decrypt.private ' === $ filename ? '// SYMFONY_DECRYPTION_SECRET= ' .base64_encode ($ data )."\n" : '' ;
207
+ $ name = basename ($ this ->pathPrefix .$ filename );
205
208
$ data = str_replace ('% ' , '\x ' , rawurlencode ($ data ));
206
209
$ data = sprintf ("<?php // %s on %s \n\n%sreturn \"%s \"; \n" , $ name , date ('r ' ), $ b64 , $ data );
207
210
208
211
$ this ->createSecretsDir ();
209
212
210
- if (false === file_put_contents ($ this ->pathPrefix .$ file .'.php ' , $ data , \LOCK_EX )) {
213
+ if (false === file_put_contents ($ this ->pathPrefix .$ filename .'.php ' , $ data , \LOCK_EX )) {
211
214
$ e = error_get_last ();
212
215
throw new \ErrorException ($ e ['message ' ] ?? 'Failed to write secrets data. ' , 0 , $ e ['type ' ] ?? \E_USER_WARNING );
213
216
}
@@ -221,4 +224,10 @@ private function createSecretsDir(): void
221
224
222
225
$ this ->secretsDir = null ;
223
226
}
227
+
228
+ private function getFilename (string $ name ): string
229
+ {
230
+ // The MD5 hash allows making secrets case-sensitive. The filename is not enough on Windows.
231
+ return $ name .'. ' .substr (md5 ($ name ), 0 , 6 );
232
+ }
224
233
}
0 commit comments