@@ -161,8 +161,8 @@ pg_tde_create_key_map_entry(const RelFileLocator *newrlocator, uint32 entry_type
161
161
if (principal_key == NULL )
162
162
{
163
163
ereport (ERROR ,
164
- ( errmsg ("principal key not configured" ),
165
- errhint ("create one using pg_tde_set_principal_key before using encrypted tables" ) ));
164
+ errmsg ("principal key not configured" ),
165
+ errhint ("create one using pg_tde_set_principal_key before using encrypted tables" ));
166
166
}
167
167
168
168
/*
@@ -192,14 +192,14 @@ pg_tde_generate_internal_key(InternalKey *int_key, uint32 entry_type)
192
192
193
193
if (!RAND_bytes (int_key -> key , INTERNAL_KEY_LEN ))
194
194
ereport (ERROR ,
195
- ( errcode (ERRCODE_INTERNAL_ERROR ),
196
- errmsg ("could not generate internal key: %s" ,
197
- ERR_error_string (ERR_get_error (), NULL ) )));
195
+ errcode (ERRCODE_INTERNAL_ERROR ),
196
+ errmsg ("could not generate internal key: %s" ,
197
+ ERR_error_string (ERR_get_error (), NULL )));
198
198
if (!RAND_bytes (int_key -> base_iv , INTERNAL_KEY_IV_LEN ))
199
199
ereport (ERROR ,
200
- ( errcode (ERRCODE_INTERNAL_ERROR ),
201
- errmsg ("could not generate IV: %s" ,
202
- ERR_error_string (ERR_get_error (), NULL ) )));
200
+ errcode (ERRCODE_INTERNAL_ERROR ),
201
+ errmsg ("could not generate IV: %s" ,
202
+ ERR_error_string (ERR_get_error (), NULL )));
203
203
}
204
204
205
205
const char *
@@ -234,8 +234,8 @@ pg_tde_create_wal_key(InternalKey *rel_key_data, const RelFileLocator *newrlocat
234
234
if (principal_key == NULL )
235
235
{
236
236
ereport (ERROR ,
237
- ( errmsg ("principal key not configured" ),
238
- errhint ("create one using pg_tde_set_server_principal_key before using encrypted WAL" ) ));
237
+ errmsg ("principal key not configured" ),
238
+ errhint ("create one using pg_tde_set_server_principal_key before using encrypted WAL" ));
239
239
}
240
240
241
241
/* TODO: no need in generating key if TDE_KEY_TYPE_WAL_UNENCRYPTED */
@@ -300,7 +300,7 @@ pg_tde_save_principal_key(const TDEPrincipalKey *principal_key)
300
300
/* Set the file paths */
301
301
pg_tde_set_db_file_path (principal_key -> keyInfo .databaseId , db_map_path );
302
302
303
- ereport (DEBUG2 , ( errmsg ("pg_tde_save_principal_key" ) ));
303
+ ereport (DEBUG2 , errmsg ("pg_tde_save_principal_key" ));
304
304
305
305
pg_tde_sign_principal_key_info (& signed_key_Info , principal_key );
306
306
@@ -329,19 +329,18 @@ pg_tde_file_header_write(const char *tde_filename, int fd, const TDESignedPrinci
329
329
if (* bytes_written != TDE_FILE_HEADER_SIZE )
330
330
{
331
331
ereport (ERROR ,
332
- (errcode_for_file_access (),
333
- errmsg ("could not write tde file \"%s\": %m" ,
334
- tde_filename )));
332
+ errcode_for_file_access (),
333
+ errmsg ("could not write tde file \"%s\": %m" , tde_filename ));
335
334
}
336
335
337
336
if (pg_fsync (fd ) != 0 )
338
337
{
339
338
ereport (data_sync_elevel (ERROR ),
340
- ( errcode_for_file_access (),
341
- errmsg ("could not fsync file \"%s\": %m" , tde_filename ) ));
339
+ errcode_for_file_access (),
340
+ errmsg ("could not fsync file \"%s\": %m" , tde_filename ));
342
341
}
343
- ereport ( DEBUG2 ,
344
- ( errmsg ("Wrote the header to %s" , tde_filename ) ));
342
+
343
+ ereport ( DEBUG2 , errmsg ("Wrote the header to %s" , tde_filename ));
345
344
346
345
return fd ;
347
346
}
@@ -353,8 +352,8 @@ pg_tde_sign_principal_key_info(TDESignedPrincipalKeyInfo *signed_key_info, const
353
352
354
353
if (!RAND_bytes (signed_key_info -> sign_iv , MAP_ENTRY_EMPTY_IV_SIZE ))
355
354
ereport (ERROR ,
356
- ( errcode (ERRCODE_INTERNAL_ERROR ),
357
- errmsg ("could not generate iv for key map: %s" , ERR_error_string (ERR_get_error (), NULL ) )));
355
+ errcode (ERRCODE_INTERNAL_ERROR ),
356
+ errmsg ("could not generate iv for key map: %s" , ERR_error_string (ERR_get_error (), NULL )));
358
357
359
358
AesGcmEncrypt (principal_key -> keyData , signed_key_info -> sign_iv , (unsigned char * ) & signed_key_info -> data , sizeof (signed_key_info -> data ), NULL , 0 , NULL , signed_key_info -> aead_tag );
360
359
}
@@ -369,8 +368,8 @@ pg_tde_initialize_map_entry(TDEMapEntry *map_entry, const TDEPrincipalKey *princ
369
368
370
369
if (!RAND_bytes (map_entry -> entry_iv , MAP_ENTRY_EMPTY_IV_SIZE ))
371
370
ereport (ERROR ,
372
- ( errcode (ERRCODE_INTERNAL_ERROR ),
373
- errmsg ("could not generate iv for key map: %s" , ERR_error_string (ERR_get_error (), NULL ) )));
371
+ errcode (ERRCODE_INTERNAL_ERROR ),
372
+ errmsg ("could not generate iv for key map: %s" , ERR_error_string (ERR_get_error (), NULL )));
374
373
375
374
AesGcmEncrypt (principal_key -> keyData , map_entry -> entry_iv , (unsigned char * ) map_entry , offsetof(TDEMapEntry , enc_key ), rel_key_data -> key , INTERNAL_KEY_LEN , map_entry -> enc_key .key , map_entry -> aead_tag );
376
375
}
@@ -389,15 +388,14 @@ pg_tde_write_one_map_entry(int fd, const TDEMapEntry *map_entry, off_t *offset,
389
388
if (bytes_written != MAP_ENTRY_SIZE )
390
389
{
391
390
ereport (ERROR ,
392
- (errcode_for_file_access (),
393
- errmsg ("could not write tde map file \"%s\": %m" ,
394
- db_map_path )));
391
+ errcode_for_file_access (),
392
+ errmsg ("could not write tde map file \"%s\": %m" , db_map_path ));
395
393
}
396
394
if (pg_fsync (fd ) != 0 )
397
395
{
398
396
ereport (data_sync_elevel (ERROR ),
399
- ( errcode_for_file_access (),
400
- errmsg ("could not fsync file \"%s\": %m" , db_map_path ) ));
397
+ errcode_for_file_access (),
398
+ errmsg ("could not fsync file \"%s\": %m" , db_map_path ));
401
399
}
402
400
403
401
return (* offset + bytes_written );
@@ -565,9 +563,9 @@ pg_tde_delete_map_entry(const RelFileLocator *rlocator, char *db_map_path, off_t
565
563
if (curr_pos == -1 )
566
564
{
567
565
ereport (ERROR ,
568
- ( errcode_for_file_access (),
569
- errmsg ("could not seek in tde map file \"%s\": %m" ,
570
- db_map_path ) ));
566
+ errcode_for_file_access (),
567
+ errmsg ("could not seek in tde map file \"%s\": %m" ,
568
+ db_map_path ));
571
569
}
572
570
}
573
571
@@ -641,11 +639,11 @@ pg_tde_free_key_map_entry(const RelFileLocator *rlocator, off_t offset)
641
639
if (!found )
642
640
{
643
641
ereport (WARNING ,
644
- ( errcode (ERRCODE_NO_DATA_FOUND ),
645
- errmsg ("could not find the required map entry for deletion of relation %d in tablespace %d in tde map file \"%s\": %m" ,
646
- rlocator -> relNumber ,
647
- rlocator -> spcOid ,
648
- db_map_path ) ));
642
+ errcode (ERRCODE_NO_DATA_FOUND ),
643
+ errmsg ("could not find the required map entry for deletion of relation %d in tablespace %d in tde map file \"%s\": %m" ,
644
+ rlocator -> relNumber ,
645
+ rlocator -> spcOid ,
646
+ db_map_path ));
649
647
650
648
}
651
649
}
@@ -751,8 +749,8 @@ pg_tde_perform_rotate_key(TDEPrincipalKey *principal_key, TDEPrincipalKey *new_p
751
749
752
750
if (pg_pread (new_fd , xlrec -> buff , xlrec -> file_size , 0 ) == -1 )
753
751
ereport (ERROR ,
754
- ( errcode_for_file_access (),
755
- errmsg ("could not write WAL for key rotation: %m" ) ));
752
+ errcode_for_file_access (),
753
+ errmsg ("could not write WAL for key rotation: %m" ));
756
754
757
755
close (new_fd );
758
756
@@ -792,16 +790,16 @@ pg_tde_write_map_keydata_file(off_t file_size, char *file_data)
792
790
if (pg_pwrite (fd_new , file_data , file_size , 0 ) != file_size )
793
791
{
794
792
ereport (WARNING ,
795
- ( errcode_for_file_access (),
796
- errmsg ("could not write tde file \"%s\": %m" , path_new ) ));
793
+ errcode_for_file_access (),
794
+ errmsg ("could not write tde file \"%s\": %m" , path_new ));
797
795
is_err = true;
798
796
goto FINALIZE ;
799
797
}
800
798
if (pg_fsync (fd_new ) != 0 )
801
799
{
802
800
ereport (WARNING ,
803
- ( errcode_for_file_access (),
804
- errmsg ("could not fsync file \"%s\": %m" , path_new ) ));
801
+ errcode_for_file_access (),
802
+ errmsg ("could not fsync file \"%s\": %m" , path_new ));
805
803
is_err = true;
806
804
goto FINALIZE ;
807
805
}
@@ -835,8 +833,8 @@ pg_tde_wal_last_key_set_lsn(XLogRecPtr lsn, const char *keyfile_path)
835
833
if (pg_pwrite (fd , & lsn , sizeof (XLogRecPtr ), write_pos ) != sizeof (XLogRecPtr ))
836
834
{
837
835
ereport (ERROR ,
838
- ( errcode_for_file_access (),
839
- errmsg ("could not write tde key data file: %m" ) ));
836
+ errcode_for_file_access (),
837
+ errmsg ("could not write tde key data file: %m" ));
840
838
}
841
839
842
840
/*
@@ -852,8 +850,8 @@ pg_tde_wal_last_key_set_lsn(XLogRecPtr lsn, const char *keyfile_path)
852
850
if (pg_pread (fd , & prev_map_entry , MAP_ENTRY_SIZE , prev_key_pos ) != MAP_ENTRY_SIZE )
853
851
{
854
852
ereport (ERROR ,
855
- ( errcode_for_file_access (),
856
- errmsg ("could not read previous WAL key: %m" ) ));
853
+ errcode_for_file_access (),
854
+ errmsg ("could not read previous WAL key: %m" ));
857
855
}
858
856
859
857
if (prev_map_entry .enc_key .start_lsn >= lsn )
@@ -863,17 +861,17 @@ pg_tde_wal_last_key_set_lsn(XLogRecPtr lsn, const char *keyfile_path)
863
861
if (pg_pwrite (fd , & prev_map_entry , MAP_ENTRY_SIZE , prev_key_pos ) != MAP_ENTRY_SIZE )
864
862
{
865
863
ereport (ERROR ,
866
- ( errcode_for_file_access (),
867
- errmsg ("could not write invalidated key: %m" ) ));
864
+ errcode_for_file_access (),
865
+ errmsg ("could not write invalidated key: %m" ));
868
866
}
869
867
}
870
868
}
871
869
872
870
if (pg_fsync (fd ) != 0 )
873
871
{
874
872
ereport (data_sync_elevel (ERROR ),
875
- ( errcode_for_file_access (),
876
- errmsg ("could not fsync file: %m" ) ));
873
+ errcode_for_file_access (),
874
+ errmsg ("could not fsync file: %m" ));
877
875
}
878
876
879
877
LWLockRelease (lock_pk );
@@ -959,8 +957,8 @@ pg_tde_get_key_from_file(const RelFileLocator *rlocator, uint32 key_type)
959
957
principal_key = GetPrincipalKey (rlocator -> dbOid , LW_SHARED );
960
958
if (principal_key == NULL )
961
959
ereport (ERROR ,
962
- ( errmsg ("principal key not configured" ),
963
- errhint ("create one using pg_tde_set_principal_key before using encrypted tables" ) ));
960
+ errmsg ("principal key not configured" ),
961
+ errhint ("create one using pg_tde_set_principal_key before using encrypted tables" ));
964
962
965
963
rel_key = tde_decrypt_rel_key (principal_key , map_entry );
966
964
@@ -1033,7 +1031,7 @@ tde_decrypt_rel_key(TDEPrincipalKey *principal_key, TDEMapEntry *map_entry)
1033
1031
1034
1032
if (!AesGcmDecrypt (principal_key -> keyData , map_entry -> entry_iv , (unsigned char * ) map_entry , offsetof(TDEMapEntry , enc_key ), map_entry -> enc_key .key , INTERNAL_KEY_LEN , rel_key_data -> key , map_entry -> aead_tag ))
1035
1033
ereport (ERROR ,
1036
- ( errmsg ("Failed to decrypt key, incorrect principal key or corrupted key file" ) ));
1034
+ errmsg ("Failed to decrypt key, incorrect principal key or corrupted key file" ));
1037
1035
1038
1036
1039
1037
return rel_key_data ;
@@ -1078,9 +1076,8 @@ pg_tde_open_file_basic(const char *tde_filename, int fileFlags, bool ignore_miss
1078
1076
if (fd < 0 && !(errno == ENOENT && ignore_missing == true))
1079
1077
{
1080
1078
ereport (ERROR ,
1081
- (errcode_for_file_access (),
1082
- errmsg ("could not open tde file \"%s\": %m" ,
1083
- tde_filename )));
1079
+ errcode_for_file_access (),
1080
+ errmsg ("could not open tde file \"%s\": %m" , tde_filename ));
1084
1081
}
1085
1082
1086
1083
return fd ;
@@ -1107,9 +1104,8 @@ pg_tde_file_header_read(const char *tde_filename, int fd, TDEFileHeader *fheader
1107
1104
/* Corrupt file */
1108
1105
close (fd );
1109
1106
ereport (FATAL ,
1110
- (errcode_for_file_access (),
1111
- errmsg ("TDE map file \"%s\" is corrupted: %m" ,
1112
- tde_filename )));
1107
+ errcode_for_file_access (),
1108
+ errmsg ("TDE map file \"%s\" is corrupted: %m" , tde_filename ));
1113
1109
}
1114
1110
}
1115
1111
@@ -1171,9 +1167,9 @@ pg_tde_read_one_map_entry2(int fd, int32 key_index, TDEMapEntry *map_entry, Oid
1171
1167
1172
1168
pg_tde_set_db_file_path (databaseId , db_map_path );
1173
1169
ereport (FATAL ,
1174
- ( errcode_for_file_access (),
1175
- errmsg ("could not find the required key at index %d in tde data file \"%s\": %m" ,
1176
- key_index , db_map_path ) ));
1170
+ errcode_for_file_access (),
1171
+ errmsg ("could not find the required key at index %d in tde data file \"%s\": %m" ,
1172
+ key_index , db_map_path ));
1177
1173
}
1178
1174
}
1179
1175
0 commit comments