1 /* 2 * This file is part of libaacs 3 * Copyright (C) 2010 gates 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library. If not, see 17 * <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef KEYDBCFG_H 21 #define KEYDBCFG_H 22 23 #include "util/attributes.h" 24 25 #include <stdint.h> 26 #include <stddef.h> /* size_t */ 27 28 /* struct holding a digit and key pair for <ENTRY NUMBER> - <ENTRY> entries */ 29 typedef struct digit_key_pair_t digit_key_pair; 30 struct digit_key_pair_t 31 { 32 unsigned int digit; 33 uint8_t key[16]; 34 }; 35 36 /* list of digit_key_pair struct used in title entry */ 37 typedef struct digit_key_pair_list_t digit_key_pair_list; 38 struct digit_key_pair_list_t 39 { 40 digit_key_pair key_pair; 41 digit_key_pair_list *next; 42 }; 43 44 /* date entry struct */ 45 #if 0 46 typedef struct date_entry_t date_entry; 47 struct date_entry_t 48 { 49 unsigned int year; 50 unsigned int month; 51 unsigned int day; 52 }; 53 #endif 54 55 /* dk entry */ 56 typedef struct dk_entry dk_list; 57 struct dk_entry 58 { 59 uint8_t key[16]; 60 unsigned long node; 61 dk_list *next; 62 63 /* optional, can be calculated */ 64 uint32_t uv; 65 uint8_t u_mask_shift; 66 }; 67 68 /* pk entry */ 69 typedef struct pk_entry pk_list; 70 struct pk_entry 71 { 72 uint8_t key[16]; 73 pk_list *next; 74 }; 75 76 /* certificate entry */ 77 typedef struct cert_entry cert_list; 78 struct cert_entry 79 { 80 uint8_t host_priv_key[20]; 81 uint8_t host_cert[92]; 82 cert_list *next; 83 }; 84 85 /* title entry struct */ 86 typedef struct title_entry_t title_entry; 87 struct title_entry_t 88 { 89 uint8_t discid[20]; 90 //char *title; 91 //date_entry date; 92 uint8_t mk[16]; 93 uint8_t vid[16]; 94 //digit_key_pair_list *bn; 95 uint8_t vuk[16]; 96 //digit_key_pair_list *pak; 97 //digit_key_pair_list *tk; 98 digit_key_pair_list *uk; 99 }; 100 101 /* main struct for title entries, held in a list structure */ 102 typedef struct title_entry_list_t title_entry_list; 103 struct title_entry_list_t 104 { 105 title_entry entry; 106 title_entry_list *next; 107 }; 108 109 /* struct representing the contents of a config file */ 110 typedef struct config_file_t config_file; 111 struct config_file_t 112 { 113 dk_list *dkl; 114 pk_list *pkl; 115 cert_list *host_cert_list; 116 title_entry_list *list; 117 }; 118 119 BD_PRIVATE int keydbcfg_parse_config(config_file *cfgfile, const char *path, const uint8_t *disc_id, int all_discs); 120 BD_PRIVATE config_file *keydbcfg_new_config_file(void); 121 BD_PRIVATE int keydbcfg_config_file_close(config_file *cfgfile); 122 123 /* */ 124 125 BD_PRIVATE config_file *keydbcfg_config_load(const char *configfile_path, const uint8_t *disc_id); 126 127 BD_PRIVATE int keycache_save(const char *type, const uint8_t *disc_id, 128 const uint8_t *key, unsigned int len); 129 BD_PRIVATE int keycache_find(const char *type, const uint8_t *disc_id, 130 uint8_t *key, unsigned int len); 131 132 BD_PRIVATE int cache_get(const char *name, uint32_t *version, uint32_t *len, void *buf, size_t buf_size); /* use buf=NULL to get version and size */ 133 BD_PRIVATE int cache_save(const char *name, uint32_t version, const void *data, uint32_t len); 134 BD_PRIVATE int cache_remove(const char *name); 135 136 BD_PRIVATE int config_get(const char *name, uint32_t *len, void *buf); /* use buf=NULL to get size */ 137 BD_PRIVATE int config_save(const char *name, const void *data, uint32_t len); 138 139 #endif 140