| 1 | /*- |
| 2 | * Copyright (c) 2009 The NetBSD Foundation, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This code is derived from software contributed to The NetBSD Foundation |
| 6 | * by Alistair Crooks (agc@NetBSD.org) |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | * POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | /* |
| 30 | * Copyright (c) 2005-2008 Nominet UK (www.nic.uk) |
| 31 | * All rights reserved. |
| 32 | * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted |
| 33 | * their moral rights under the UK Copyright Design and Patents Act 1988 to |
| 34 | * be recorded as the authors of this copyright work. |
| 35 | * |
| 36 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 37 | * use this file except in compliance with the License. |
| 38 | * |
| 39 | * You may obtain a copy of the License at |
| 40 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 41 | * |
| 42 | * Unless required by applicable law or agreed to in writing, software |
| 43 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 44 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 45 | * |
| 46 | * See the License for the specific language governing permissions and |
| 47 | * limitations under the License. |
| 48 | */ |
| 49 | |
| 50 | /** \file |
| 51 | */ |
| 52 | |
| 53 | #ifndef KEYRING_H_ |
| 54 | #define KEYRING_H_ |
| 55 | |
| 56 | #include <stdio.h> |
| 57 | #include "packet.h" |
| 58 | #include "packet-parse.h" |
| 59 | #include "mj.h" |
| 60 | |
| 61 | enum { |
| 62 | MAX_ID_LENGTH = 128, |
| 63 | MAX_PASSPHRASE_LENGTH = 256 |
| 64 | }; |
| 65 | |
| 66 | typedef struct pgp_key_t pgp_key_t; |
| 67 | |
| 68 | /** \struct pgp_keyring_t |
| 69 | * A keyring |
| 70 | */ |
| 71 | typedef struct pgp_keyring_t { |
| 72 | DYNARRAY(pgp_key_t, key); |
| 73 | pgp_hash_alg_t hashtype; |
| 74 | } pgp_keyring_t; |
| 75 | |
| 76 | const pgp_key_t *pgp_getkeybyid(pgp_io_t *, |
| 77 | const pgp_keyring_t *, |
| 78 | const uint8_t *, |
| 79 | unsigned *, |
| 80 | pgp_pubkey_t **); |
| 81 | const pgp_key_t *pgp_getkeybyname(pgp_io_t *, |
| 82 | const pgp_keyring_t *, |
| 83 | const char *); |
| 84 | const pgp_key_t *pgp_getnextkeybyname(pgp_io_t *, |
| 85 | const pgp_keyring_t *, |
| 86 | const char *, |
| 87 | unsigned *); |
| 88 | void pgp_keydata_free(pgp_key_t *); |
| 89 | void pgp_keyring_free(pgp_keyring_t *); |
| 90 | void pgp_dump_keyring(const pgp_keyring_t *); |
| 91 | const pgp_pubkey_t *pgp_get_pubkey(const pgp_key_t *); |
| 92 | unsigned pgp_is_key_secret(const pgp_key_t *); |
| 93 | const pgp_seckey_t *pgp_get_seckey(const pgp_key_t *); |
| 94 | pgp_seckey_t *pgp_get_writable_seckey(pgp_key_t *); |
| 95 | pgp_seckey_t *pgp_decrypt_seckey(const pgp_key_t *, FILE *); |
| 96 | |
| 97 | unsigned pgp_keyring_fileread(pgp_keyring_t *, const unsigned, |
| 98 | const char *); |
| 99 | unsigned pgp_keyring_filewrite(pgp_keyring_t *, const unsigned, |
| 100 | const char *, uint8_t *); |
| 101 | |
| 102 | int pgp_keyring_list(pgp_io_t *, const pgp_keyring_t *, const int); |
| 103 | int pgp_keyring_json(pgp_io_t *, const pgp_keyring_t *, mj_t *, const int); |
| 104 | |
| 105 | void pgp_set_seckey(pgp_contents_t *, const pgp_key_t *); |
| 106 | void pgp_forget(void *, size_t); |
| 107 | |
| 108 | const uint8_t *pgp_get_key_id(const pgp_key_t *); |
| 109 | unsigned pgp_get_userid_count(const pgp_key_t *); |
| 110 | const uint8_t *pgp_get_userid(const pgp_key_t *, unsigned); |
| 111 | unsigned pgp_is_key_supported(const pgp_key_t *); |
| 112 | |
| 113 | uint8_t *pgp_add_userid(pgp_key_t *, const uint8_t *); |
| 114 | pgp_subpacket_t *pgp_add_subpacket(pgp_key_t *, |
| 115 | const pgp_subpacket_t *); |
| 116 | |
| 117 | unsigned pgp_add_selfsigned_userid(pgp_key_t *, uint8_t *); |
| 118 | |
| 119 | pgp_key_t *pgp_keydata_new(void); |
| 120 | void pgp_keydata_init(pgp_key_t *, const pgp_content_enum); |
| 121 | |
| 122 | int pgp_parse_and_accumulate(pgp_keyring_t *, pgp_stream_t *); |
| 123 | |
| 124 | int pgp_sprint_keydata(pgp_io_t *, const pgp_keyring_t *, |
| 125 | const pgp_key_t *, char **, const char *, |
| 126 | const pgp_pubkey_t *, const int); |
| 127 | int pgp_sprint_mj(pgp_io_t *, const pgp_keyring_t *, |
| 128 | const pgp_key_t *, mj_t *, const char *, |
| 129 | const pgp_pubkey_t *, const int); |
| 130 | int pgp_hkp_sprint_keydata(pgp_io_t *, const pgp_keyring_t *, |
| 131 | const pgp_key_t *, char **, |
| 132 | const pgp_pubkey_t *, const int); |
| 133 | void pgp_print_keydata(pgp_io_t *, const pgp_keyring_t *, const pgp_key_t *, |
| 134 | const char *, const pgp_pubkey_t *, const int); |
| 135 | void pgp_print_sig(pgp_io_t *, const pgp_key_t *, const char *, |
| 136 | const pgp_pubkey_t *); |
| 137 | void pgp_print_pubkey(const pgp_pubkey_t *); |
| 138 | int pgp_sprint_pubkey(const pgp_key_t *, char *, size_t); |
| 139 | |
| 140 | int pgp_list_packets(pgp_io_t *, |
| 141 | char *, |
| 142 | unsigned, |
| 143 | pgp_keyring_t *, |
| 144 | pgp_keyring_t *, |
| 145 | void *, |
| 146 | pgp_cbfunc_t *); |
| 147 | |
| 148 | char *pgp_export_key(pgp_io_t *, const pgp_key_t *, uint8_t *); |
| 149 | |
| 150 | int pgp_add_to_pubring(pgp_keyring_t *, const pgp_pubkey_t *, pgp_content_enum tag); |
| 151 | int pgp_add_to_secring(pgp_keyring_t *, const pgp_seckey_t *); |
| 152 | |
| 153 | int pgp_append_keyring(pgp_keyring_t *, pgp_keyring_t *); |
| 154 | |
| 155 | #endif /* KEYRING_H_ */ |
| 156 | |