File: certs.c

package info (click to toggle)
libreswan 5.2-2.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,656 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (84 lines) | stat: -rw-r--r-- 2,481 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Certificate support for IKE authentication
 * Copyright (C) 2002-2004 Andreas Steffen, Zuercher Hochschule Winterthur
 * Copyright (C) 2003-2006 Michael Richardson <mcr@xelerance.com>
 * Copyright (C) 2009 Paul Wouters <paul@xelerance.com>
 * Copyright (C) 2009 Avesh Agarwal <avagarwa@redhat.com>
 * Copyright (C) 2012-2013 Paul Wouters <paul@libreswan.org>
 * Copyright (C) 2017 Paul Wouters <pwouters@redhat.com>
 * Copyright (C) 2013 Tuomo Soini <tis@foobar.fi>
 * Copyright (C) 2013 Matt Rogers <mrogers@redhat.com>
 * Copyright (C) 2019 Andrew Cagney <cagney@gnu.org>
 * Copyright (C) 2019 D. Hugh Redelmeier <hugh@mimosa.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <https://www.gnu.org/licenses/gpl2.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "certs.h"

#include "lswalloc.h"
#include "passert.h"
#include "lswnss.h"		/* for same_secitem_as_shunk() */

void release_certs(struct certs **head)
{
	while (*head != NULL) {
		struct certs *old = *head;
		*head = old->next;
		CERT_DestroyCertificate(old->cert);
		pfree(old);
	}
}

void add_cert(struct certs **head, CERTCertificate *cert)
{
	passert(cert != NULL);
	struct certs *new = alloc_thing(struct certs, __func__);
	new->cert = cert;
	new->next = *head;
	*head = new;
}

CERTCertificate *make_end_cert_first(struct certs **head)
{
	for (struct certs *entry = *head; entry != NULL;
	     entry = entry->next) {
		if (!CERT_IsCACert(entry->cert, NULL)) {
			/*
			 * Swap .cert values of entry and *head.
			 * This will work even if entry == *head.
			 */
			CERTCertificate *end_cert = entry->cert;
			entry->cert = (*head)->cert;
			(*head)->cert = end_cert;
			return end_cert;
		}
	}
	return NULL;
}


enum ike_cert_type cert_ike_type(const struct cert *cert UNUSED)
{
	if (cert == NULL || cert->nss_cert == NULL) {
		return CERT_NONE;
	} else {
		return CERT_X509_SIGNATURE;
	}
}

shunk_t cert_der(const struct cert *cert)
{
	if (cert == NULL || cert->nss_cert == NULL) {
		return null_shunk;
	} else {
		return same_secitem_as_shunk(cert->nss_cert->derCert);
	}
}