Lines Matching refs:key

91 static isc_result_t	write_public_key(const dst_key_t *key, int type,
99 static isc_result_t computeid(dst_key_t *key);
243 dst_context_create(dst_key_t *key, isc_mem_t *mctx, dst_context_t **dctxp) {
244 return (dst_context_create2(key, mctx,
249 dst_context_create2(dst_key_t *key, isc_mem_t *mctx,
255 REQUIRE(VALID_KEY(key));
259 if (key->func->createctx == NULL)
261 if (key->keydata.generic == NULL)
267 dctx->key = key;
270 result = key->func->createctx(key, dctx);
287 INSIST(dctx->key->func->destroyctx != NULL);
288 dctx->key->func->destroyctx(dctx);
298 INSIST(dctx->key->func->adddata != NULL);
300 return (dctx->key->func->adddata(dctx, data));
305 dst_key_t *key;
310 key = dctx->key;
311 CHECKALG(key->key_alg);
312 if (key->keydata.generic == NULL)
315 if (key->func->sign == NULL)
317 if (key->func->isprivate == NULL ||
318 key->func->isprivate(key) == ISC_FALSE)
321 return (key->func->sign(dctx, sig));
329 CHECKALG(dctx->key->key_alg);
330 if (dctx->key->keydata.generic == NULL)
332 if (dctx->key->func->verify == NULL)
335 return (dctx->key->func->verify(dctx, sig));
364 dst_key_tofile(const dst_key_t *key, int type, const char *directory) {
368 REQUIRE(VALID_KEY(key));
371 CHECKALG(key->key_alg);
373 if (key->func->tofile == NULL)
377 ret = write_public_key(key, type, directory);
383 (key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY)
384 return (key->func->tofile(key, directory));
396 dst_key_t *key;
412 key = NULL;
413 result = dst_key_fromnamedfile(filename, type, mctx, &key);
417 result = computeid(key);
419 dst_key_free(&key);
423 if (!dns_name_equal(name, key->key_name) || id != key->key_id ||
424 alg != key->key_alg) {
425 dst_key_free(&key);
428 key->key_id = id;
430 *keyp = key;
439 dst_key_t *pubkey = NULL, *key = NULL;
455 result = addsuffix(newfilename, newfilenamelen, filename, ".key");
481 key = get_key_struct(pubkey->key_name, pubkey->key_alg,
487 if (key == NULL)
490 if (key->func->parse == NULL)
504 RETERR(key->func->parse(key, lex));
507 RETERR(computeid(key));
509 if (id != key->key_id)
512 *keyp = key;
520 if (key != NULL)
521 dst_key_free(&key);
526 dst_key_todns(const dst_key_t *key, isc_buffer_t *target) {
528 REQUIRE(VALID_KEY(key));
531 CHECKALG(key->key_alg);
533 if (key->func->todns == NULL)
538 isc_buffer_putuint16(target, (isc_uint16_t)(key->key_flags & 0xffff));
539 isc_buffer_putuint8(target, (isc_uint8_t)key->key_proto);
540 isc_buffer_putuint8(target, (isc_uint8_t)key->key_alg);
542 if (key->key_flags & DNS_KEYFLAG_EXTENDED) {
546 (isc_uint16_t)((key->key_flags >> 16)
550 if (key->keydata.generic == NULL) /*%< NULL KEY */
553 return (key->func->todns(key, target));
562 dst_key_t *key = NULL;
587 mctx, &key);
590 key->key_id = id;
592 *keyp = key;
602 dst_key_t *key = NULL;
608 mctx, &key);
612 result = computeid(key);
614 dst_key_free(&key);
618 *keyp = key;
623 dst_key_tobuffer(const dst_key_t *key, isc_buffer_t *target) {
625 REQUIRE(VALID_KEY(key));
628 CHECKALG(key->key_alg);
630 if (key->func->todns == NULL)
633 return (key->func->todns(key, target));
637 dst_key_privatefrombuffer(dst_key_t *key, isc_buffer_t *buffer) {
642 REQUIRE(VALID_KEY(key));
643 REQUIRE(!dst_key_isprivate(key));
646 if (key->func->parse == NULL)
649 RETERR(isc_lex_create(key->mctx, 1500, &lex));
651 RETERR(key->func->parse(key, lex));
659 dst_key_getgssctx(const dst_key_t *key)
661 REQUIRE(key != NULL);
663 return (key->keydata.gssctx);
670 dst_key_t *key;
675 key = get_key_struct(name, DST_ALG_GSSAPI, 0, DNS_KEYPROTO_DNSSEC,
677 if (key == NULL)
680 key->keydata.gssctx = gssctx;
681 *keyp = key;
691 dst_key_t *key;
702 key = get_key_struct(name, alg, flags, protocol, 0, rdclass, mctx);
703 if (key == NULL)
706 if (key->func->fromlabel == NULL) {
707 dst_key_free(&key);
711 result = key->func->fromlabel(key, engine, label, pin);
713 dst_key_free(&key);
717 result = computeid(key);
719 dst_key_free(&key);
723 *keyp = key;
734 dst_key_t *key;
744 key = get_key_struct(name, alg, flags, protocol, bits, rdclass, mctx);
745 if (key == NULL)
749 key->key_flags |= DNS_KEYTYPE_NOKEY;
750 *keyp = key;
754 if (key->func->generate == NULL) {
755 dst_key_free(&key);
759 ret = key->func->generate(key, param);
761 dst_key_free(&key);
765 ret = computeid(key);
767 dst_key_free(&key);
771 *keyp = key;
826 dst_key_t *key;
832 key = *keyp;
833 mctx = key->mctx;
835 isc_refcount_decrement(&key->refs, &refs);
839 isc_refcount_destroy(&key->refs);
840 if (key->keydata.generic != NULL) {
841 INSIST(key->func->destroy != NULL);
842 key->func->destroy(key);
844 if (key->engine != NULL)
845 isc_mem_free(mctx, key->engine);
846 if (key->label != NULL)
847 isc_mem_free(mctx, key->label);
848 dns_name_free(key->key_name, mctx);
849 isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
850 memset(key, 0, sizeof(dst_key_t));
851 isc_mem_put(mctx, key, sizeof(dst_key_t));
856 dst_key_isprivate(const dst_key_t *key) {
857 REQUIRE(VALID_KEY(key));
858 INSIST(key->func->isprivate != NULL);
859 return (key->func->isprivate(key));
863 dst_key_buildfilename(const dst_key_t *key, int type,
866 REQUIRE(VALID_KEY(key));
870 return (buildfilename(key->key_name, key->key_id, key->key_alg,
875 dst_key_sigsize(const dst_key_t *key, unsigned int *n) {
877 REQUIRE(VALID_KEY(key));
881 switch (key->key_alg) {
887 *n = (key->key_size + 7) / 8;
922 dst_key_secretsize(const dst_key_t *key, unsigned int *n) {
924 REQUIRE(VALID_KEY(key));
927 if (key->key_alg == DST_ALG_DH)
928 *n = (key->key_size + 7) / 8;
939 * Allocates a key structure and fills in some of the fields.
947 dst_key_t *key;
950 key = (dst_key_t *) isc_mem_get(mctx, sizeof(dst_key_t));
951 if (key == NULL)
954 memset(key, 0, sizeof(dst_key_t));
956 key->key_name = isc_mem_get(mctx, sizeof(dns_name_t));
957 if (key->key_name == NULL) {
958 isc_mem_put(mctx, key, sizeof(dst_key_t));
962 dns_name_init(key->key_name, NULL);
963 result = dns_name_dup(name, mctx, key->key_name);
965 isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
966 isc_mem_put(mctx, key, sizeof(dst_key_t));
970 result = isc_refcount_init(&key->refs, 1);
972 dns_name_free(key->key_name, mctx);
973 isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
974 isc_mem_put(mctx, key, sizeof(dst_key_t));
977 key->key_alg = alg;
978 key->key_flags = flags;
979 key->key_proto = protocol;
980 key->mctx = mctx;
981 key->keydata.generic = NULL;
982 key->key_size = bits;
983 key->key_class = rdclass;
984 key->func = dst_t_func[alg];
985 key->magic = KEY_MAGIC;
986 return (key);
990 * Reads a public key from disk
1013 * domain.name [ttl] [class] [KEY|DNSKEY] <flags> <protocol> <algorithm> <key>
1016 /* 1500 should be large enough for any key */
1049 * We don't support "@" in .key files.
1114 issymmetric(const dst_key_t *key) {
1116 REQUIRE(VALID_KEY(key));
1119 switch (key->key_alg) {
1138 * Writes a public key to disk in DNS format.
1141 write_public_key(const dst_key_t *key, int type, const char *directory) {
1153 REQUIRE(VALID_KEY(key));
1159 ret = dst_key_todns(key, &keyb);
1164 dns_rdata_fromregion(&rdata, key->key_class, dns_rdatatype_dnskey, &r);
1170 ret = dns_rdataclass_totext(key->key_class, &classb);
1178 ret = dst_key_buildfilename(key, DST_TYPE_PUBLIC, directory, &fileb);
1183 * Create public key file.
1188 if (issymmetric(key)) {
1196 ret = dns_name_print(key->key_name, fp);
1239 suffix = ".key";
1265 computeid(dst_key_t *key) {
1272 ret = dst_key_todns(key, &dnsbuf);
1277 key->key_id = dst_region_computeid(&r, key->key_alg);
1286 dst_key_t *key;
1294 key = get_key_struct(name, alg, flags, protocol, 0, rdclass, mctx);
1295 if (key == NULL)
1301 dst_key_free(&key);
1304 if (key->func->fromdns == NULL) {
1305 dst_key_free(&key);
1309 ret = key->func->fromdns(key, source);
1311 dst_key_free(&key);
1316 *keyp = key;
1348 else if (olen > 4 && strcmp(ofilename + olen - 4, ".key") == 0)