23
23
24
24
int aws_load_cert_from_system_cert_store (const char * cert_path , HCERTSTORE * cert_store , PCCERT_CONTEXT * certs ) {
25
25
26
- AWS_LOGF_INFO (AWS_LS_IO_PKI , "static: loading certificate at windows cert manager path %s ." , cert_path );
26
+ AWS_LOGF_INFO (AWS_LS_IO_PKI , "static: loading certificate at windows cert manager path '%s' ." , cert_path );
27
27
char * location_of_next_segment = strchr (cert_path , '\\' );
28
28
29
29
if (!location_of_next_segment ) {
30
- AWS_LOGF_ERROR (AWS_LS_IO_PKI , "static: invalid certificate path %s ." , cert_path );
30
+ AWS_LOGF_ERROR (AWS_LS_IO_PKI , "static: invalid certificate path '%s'. Must use '\\' as separator ." , cert_path );
31
31
return aws_raise_error (AWS_ERROR_FILE_INVALID_PATH );
32
32
}
33
33
@@ -52,7 +52,13 @@ int aws_load_cert_from_system_cert_store(const char *cert_path, HCERTSTORE *cert
52
52
store_val = CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE ;
53
53
} else {
54
54
AWS_LOGF_ERROR (
55
- AWS_LS_IO_PKI , "static: certificate path %s does not contain a valid cert store identifier." , cert_path );
55
+ AWS_LS_IO_PKI ,
56
+ "static: invalid certificate path '%s'. System store location '%.*s' not recognized."
57
+ " Expected something like 'CurrentUser'." ,
58
+ cert_path ,
59
+ (int )store_name_len ,
60
+ cert_path );
61
+
56
62
return aws_raise_error (AWS_ERROR_FILE_INVALID_PATH );
57
63
}
58
64
@@ -62,22 +68,26 @@ int aws_load_cert_from_system_cert_store(const char *cert_path, HCERTSTORE *cert
62
68
location_of_next_segment = strchr (location_of_next_segment , '\\' );
63
69
64
70
if (!location_of_next_segment ) {
65
- AWS_LOGF_ERROR (AWS_LS_IO_PKI , "static: invalid certificate path %s." , cert_path );
71
+ AWS_LOGF_ERROR (
72
+ AWS_LS_IO_PKI , "static: invalid certificate path '%s'. Expected additional '\\' separator." , cert_path );
66
73
return aws_raise_error (AWS_ERROR_FILE_INVALID_PATH );
67
74
}
68
75
69
76
/* The store_val value has to be only the path segment related to the physical store. Looking
70
77
at the docs, 128 bytes should be plenty to store that segment.
71
78
https://docs.microsoft.com/en-us/windows/desktop/SecCrypto/system-store-locations */
72
79
char store_path [128 ] = {0 };
73
- AWS_FATAL_ASSERT (location_of_next_segment - store_path_start < sizeof (store_path ));
80
+ if (location_of_next_segment - store_path_start >= sizeof (store_path )) {
81
+ AWS_LOGF_ERROR (AWS_LS_IO_PKI , "static: invalid certificate path '%s'. Store name is too long." , cert_path );
82
+ return aws_raise_error (AWS_ERROR_FILE_INVALID_PATH );
83
+ }
74
84
memcpy (store_path , store_path_start , location_of_next_segment - store_path_start );
75
85
76
86
location_of_next_segment += 1 ;
77
87
if (strlen (location_of_next_segment ) != CERT_HASH_STR_LEN ) {
78
88
AWS_LOGF_ERROR (
79
89
AWS_LS_IO_PKI ,
80
- "static: invalid certificate path %s. %s should have been"
90
+ "static: invalid certificate path '%s'. '%s' should have been"
81
91
" 40 bytes of hex encoded data" ,
82
92
cert_path ,
83
93
location_of_next_segment );
@@ -90,7 +100,7 @@ int aws_load_cert_from_system_cert_store(const char *cert_path, HCERTSTORE *cert
90
100
if (!* cert_store ) {
91
101
AWS_LOGF_ERROR (
92
102
AWS_LS_IO_PKI ,
93
- "static: invalid certificate path %s . Failed to load cert store with error code %d" ,
103
+ "static: invalid certificate path '%s' . Failed to load cert store with error code %d" ,
94
104
cert_path ,
95
105
(int )GetLastError ());
96
106
return aws_raise_error (AWS_ERROR_FILE_INVALID_PATH );
@@ -112,7 +122,7 @@ int aws_load_cert_from_system_cert_store(const char *cert_path, HCERTSTORE *cert
112
122
NULL )) {
113
123
AWS_LOGF_ERROR (
114
124
AWS_LS_IO_PKI ,
115
- "static: invalid certificate path %s. %s should have been a hex encoded string" ,
125
+ "static: invalid certificate path '%s'. '%s' should have been a hex encoded string" ,
116
126
cert_path ,
117
127
location_of_next_segment );
118
128
aws_raise_error (AWS_ERROR_FILE_INVALID_PATH );
@@ -125,7 +135,7 @@ int aws_load_cert_from_system_cert_store(const char *cert_path, HCERTSTORE *cert
125
135
if (!* certs ) {
126
136
AWS_LOGF_ERROR (
127
137
AWS_LS_IO_PKI ,
128
- "static: invalid certificate path %s . "
138
+ "static: invalid certificate path '%s' . "
129
139
"The referenced certificate was not found in the certificate store, error code %d" ,
130
140
cert_path ,
131
141
(int )GetLastError ());
0 commit comments