12232f800Sagc /*- 22232f800Sagc * Copyright (c) 2009 The NetBSD Foundation, Inc. 32232f800Sagc * All rights reserved. 42232f800Sagc * 52232f800Sagc * This code is derived from software contributed to The NetBSD Foundation 62232f800Sagc * by Alistair Crooks (agc@NetBSD.org) 72232f800Sagc * 82232f800Sagc * Redistribution and use in source and binary forms, with or without 92232f800Sagc * modification, are permitted provided that the following conditions 102232f800Sagc * are met: 112232f800Sagc * 1. Redistributions of source code must retain the above copyright 122232f800Sagc * notice, this list of conditions and the following disclaimer. 132232f800Sagc * 2. Redistributions in binary form must reproduce the above copyright 142232f800Sagc * notice, this list of conditions and the following disclaimer in the 152232f800Sagc * documentation and/or other materials provided with the distribution. 162232f800Sagc * 172232f800Sagc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 182232f800Sagc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 192232f800Sagc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 202232f800Sagc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 212232f800Sagc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 222232f800Sagc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 232232f800Sagc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 242232f800Sagc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 252232f800Sagc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 262232f800Sagc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 272232f800Sagc * POSSIBILITY OF SUCH DAMAGE. 282232f800Sagc */ 2993bf6008Sagc /* 3093bf6008Sagc * Copyright (c) 2005-2008 Nominet UK (www.nic.uk) 3193bf6008Sagc * All rights reserved. 3293bf6008Sagc * Contributors: Ben Laurie, Rachel Willmer. The Contributors have asserted 3393bf6008Sagc * their moral rights under the UK Copyright Design and Patents Act 1988 to 3493bf6008Sagc * be recorded as the authors of this copyright work. 3593bf6008Sagc * 3693bf6008Sagc * Licensed under the Apache License, Version 2.0 (the "License"); you may not 3793bf6008Sagc * use this file except in compliance with the License. 3893bf6008Sagc * 3993bf6008Sagc * You may obtain a copy of the License at 4093bf6008Sagc * http://www.apache.org/licenses/LICENSE-2.0 4193bf6008Sagc * 4293bf6008Sagc * Unless required by applicable law or agreed to in writing, software 4393bf6008Sagc * distributed under the License is distributed on an "AS IS" BASIS, 4493bf6008Sagc * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 4593bf6008Sagc * 4693bf6008Sagc * See the License for the specific language governing permissions and 4793bf6008Sagc * limitations under the License. 4893bf6008Sagc */ 4993bf6008Sagc 5093bf6008Sagc /** \file 5193bf6008Sagc */ 5293bf6008Sagc 534b3a3e18Sagc #ifndef KEYRING_H_ 544b3a3e18Sagc #define KEYRING_H_ 5593bf6008Sagc 560a8cffecSkhorben #include <stdio.h> 5793bf6008Sagc #include "packet.h" 5893bf6008Sagc #include "packet-parse.h" 5916aefefaSagc #include "mj.h" 6093bf6008Sagc 617478ab55Sagc enum { 627478ab55Sagc MAX_ID_LENGTH = 128, 637478ab55Sagc MAX_PASSPHRASE_LENGTH = 256 647478ab55Sagc }; 657478ab55Sagc 66fc1f8641Sagc typedef struct pgp_key_t pgp_key_t; 6793bf6008Sagc 68fc1f8641Sagc /** \struct pgp_keyring_t 6993bf6008Sagc * A keyring 7093bf6008Sagc */ 71fc1f8641Sagc typedef struct pgp_keyring_t { 72fc1f8641Sagc DYNARRAY(pgp_key_t, key); 73fc1f8641Sagc pgp_hash_alg_t hashtype; 74fc1f8641Sagc } pgp_keyring_t; 7593bf6008Sagc 76fc1f8641Sagc const pgp_key_t *pgp_getkeybyid(pgp_io_t *, 77fc1f8641Sagc const pgp_keyring_t *, 78b15ec256Sagc const uint8_t *, 7969d4f30fSagc unsigned *, 80fc1f8641Sagc pgp_pubkey_t **); 81fc1f8641Sagc const pgp_key_t *pgp_getkeybyname(pgp_io_t *, 82fc1f8641Sagc const pgp_keyring_t *, 8357324b9fSagc const char *); 84fc1f8641Sagc const pgp_key_t *pgp_getnextkeybyname(pgp_io_t *, 85fc1f8641Sagc const pgp_keyring_t *, 86183e04ebSagc const char *, 87183e04ebSagc unsigned *); 88fc1f8641Sagc void pgp_keydata_free(pgp_key_t *); 89fc1f8641Sagc void pgp_keyring_free(pgp_keyring_t *); 90fc1f8641Sagc void pgp_dump_keyring(const pgp_keyring_t *); 91fc1f8641Sagc const pgp_pubkey_t *pgp_get_pubkey(const pgp_key_t *); 92fc1f8641Sagc unsigned pgp_is_key_secret(const pgp_key_t *); 93fc1f8641Sagc const pgp_seckey_t *pgp_get_seckey(const pgp_key_t *); 94fc1f8641Sagc pgp_seckey_t *pgp_get_writable_seckey(pgp_key_t *); 950a8cffecSkhorben pgp_seckey_t *pgp_decrypt_seckey(const pgp_key_t *, FILE *); 9693bf6008Sagc 97fc1f8641Sagc unsigned pgp_keyring_fileread(pgp_keyring_t *, const unsigned, 9857324b9fSagc const char *); 99*3118701fSmlelstv unsigned pgp_keyring_filewrite(pgp_keyring_t *, const unsigned, 100*3118701fSmlelstv const char *, uint8_t *); 10193bf6008Sagc 102fc1f8641Sagc int pgp_keyring_list(pgp_io_t *, const pgp_keyring_t *, const int); 103fc1f8641Sagc int pgp_keyring_json(pgp_io_t *, const pgp_keyring_t *, mj_t *, const int); 10493bf6008Sagc 105fc1f8641Sagc void pgp_set_seckey(pgp_contents_t *, const pgp_key_t *); 106e1d90c49Skhorben void pgp_forget(void *, size_t); 10793bf6008Sagc 108fc1f8641Sagc const uint8_t *pgp_get_key_id(const pgp_key_t *); 109fc1f8641Sagc unsigned pgp_get_userid_count(const pgp_key_t *); 110fc1f8641Sagc const uint8_t *pgp_get_userid(const pgp_key_t *, unsigned); 111fc1f8641Sagc unsigned pgp_is_key_supported(const pgp_key_t *); 11293bf6008Sagc 113fc1f8641Sagc uint8_t *pgp_add_userid(pgp_key_t *, const uint8_t *); 114fc1f8641Sagc pgp_subpacket_t *pgp_add_subpacket(pgp_key_t *, 115fc1f8641Sagc const pgp_subpacket_t *); 11693bf6008Sagc 117fc1f8641Sagc unsigned pgp_add_selfsigned_userid(pgp_key_t *, uint8_t *); 11893bf6008Sagc 119fc1f8641Sagc pgp_key_t *pgp_keydata_new(void); 120fc1f8641Sagc void pgp_keydata_init(pgp_key_t *, const pgp_content_enum); 12193bf6008Sagc 122fc1f8641Sagc int pgp_parse_and_accumulate(pgp_keyring_t *, pgp_stream_t *); 12393bf6008Sagc 124fc1f8641Sagc int pgp_sprint_keydata(pgp_io_t *, const pgp_keyring_t *, 125fc1f8641Sagc const pgp_key_t *, char **, const char *, 126fc1f8641Sagc const pgp_pubkey_t *, const int); 127fc1f8641Sagc int pgp_sprint_mj(pgp_io_t *, const pgp_keyring_t *, 128fc1f8641Sagc const pgp_key_t *, mj_t *, const char *, 129fc1f8641Sagc const pgp_pubkey_t *, const int); 130fc1f8641Sagc int pgp_hkp_sprint_keydata(pgp_io_t *, const pgp_keyring_t *, 131fc1f8641Sagc const pgp_key_t *, char **, 132fc1f8641Sagc const pgp_pubkey_t *, const int); 133fc1f8641Sagc void pgp_print_keydata(pgp_io_t *, const pgp_keyring_t *, const pgp_key_t *, 134fc1f8641Sagc const char *, const pgp_pubkey_t *, const int); 135fc1f8641Sagc void pgp_print_sig(pgp_io_t *, const pgp_key_t *, const char *, 136fc1f8641Sagc const pgp_pubkey_t *); 137fc1f8641Sagc void pgp_print_pubkey(const pgp_pubkey_t *); 138fc1f8641Sagc int pgp_sprint_pubkey(const pgp_key_t *, char *, size_t); 13993bf6008Sagc 140fc1f8641Sagc int pgp_list_packets(pgp_io_t *, 141d21b929eSagc char *, 142d21b929eSagc unsigned, 143fc1f8641Sagc pgp_keyring_t *, 144fc1f8641Sagc pgp_keyring_t *, 14541335e2dSagc void *, 146fc1f8641Sagc pgp_cbfunc_t *); 14793bf6008Sagc 148fc1f8641Sagc char *pgp_export_key(pgp_io_t *, const pgp_key_t *, uint8_t *); 14993bf6008Sagc 150fc1f8641Sagc int pgp_add_to_pubring(pgp_keyring_t *, const pgp_pubkey_t *, pgp_content_enum tag); 151fc1f8641Sagc int pgp_add_to_secring(pgp_keyring_t *, const pgp_seckey_t *); 15291c29c74Sagc 153fc1f8641Sagc int pgp_append_keyring(pgp_keyring_t *, pgp_keyring_t *); 154600b302bSagc 1554b3a3e18Sagc #endif /* KEYRING_H_ */ 156