| 201 | } |
| 202 | |
| 203 | static apr_status_t read_store_file(md_store_fs_t *s_fs, const char *fname, |
| 204 | apr_pool_t *p, apr_pool_t *ptemp) |
| 205 | { |
| 206 | md_json_t *json; |
| 207 | const char *key64; |
| 208 | apr_status_t rv; |
| 209 | double store_version; |
| 210 | |
| 211 | if (MD_OK(md_json_readf(&json, p, fname))) { |
| 212 | store_version = md_json_getn(json, MD_KEY_STORE, MD_KEY_VERSION, NULL); |
| 213 | if (store_version <= 0.0) { |
| 214 | /* ok, an old one, compatible to 1.0 */ |
| 215 | store_version = 1.0; |
| 216 | } |
| 217 | if (store_version > MD_STORE_VERSION) { |
| 218 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "version too new: %f", store_version); |
| 219 | return APR_EINVAL; |
| 220 | } |
| 221 | |
| 222 | key64 = md_json_dups(p, json, MD_KEY_KEY, NULL); |
| 223 | if (!key64) { |
| 224 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "missing key: %s", MD_KEY_KEY); |
| 225 | return APR_EINVAL; |
| 226 | } |
| 227 | |
| 228 | md_util_base64url_decode(&s_fs->key, key64, p); |
| 229 | if (s_fs->key.len != FS_STORE_KLEN) { |
| 230 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, 0, p, "key length unexpected: %" APR_SIZE_T_FMT, |
| 231 | s_fs->key.len); |
| 232 | return APR_EINVAL; |
| 233 | } |
| 234 | |
| 235 | /* Need to migrate format? */ |
| 236 | if (store_version < MD_STORE_VERSION) { |
| 237 | if (store_version <= 1.0) { |
| 238 | md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, p, "migrating store v1 -> v2"); |
| 239 | rv = upgrade_from_1_0(s_fs, p, ptemp); |
| 240 | } |
| 241 | if (store_version <= 2.0) { |
| 242 | md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, p, "migrating store v2 -> v3"); |
| 243 | md_json_del(json, MD_KEY_VERSION, NULL); |
| 244 | } |
| 245 | |
| 246 | if (APR_SUCCESS == rv) { |
| 247 | md_json_setn(MD_STORE_VERSION, json, MD_KEY_STORE, MD_KEY_VERSION, NULL); |
| 248 | rv = md_json_freplace(json, ptemp, MD_JSON_FMT_INDENT, fname, MD_FPROT_F_UONLY); |
| 249 | } |
| 250 | md_log_perror(MD_LOG_MARK, MD_LOG_INFO, rv, p, "migrated store"); |
| 251 | } |
| 252 | } |
| 253 | return rv; |
| 254 | } |
| 255 | |
| 256 | static apr_status_t setup_store_file(void *baton, apr_pool_t *p, apr_pool_t *ptemp, va_list ap) |
| 257 | { |
no test coverage detected