- identification_t supports now almost all id types
- x509 certificates work with identification_t now - fixes here, fixes there
This commit is contained in:
@@ -133,7 +133,7 @@ struct private_socket_t{
|
|||||||
/**
|
/**
|
||||||
* implementation of socket_t.receive
|
* implementation of socket_t.receive
|
||||||
*/
|
*/
|
||||||
status_t receiver(private_socket_t *this, packet_t **packet)
|
static status_t receiver(private_socket_t *this, packet_t **packet)
|
||||||
{
|
{
|
||||||
char buffer[MAX_PACKET];
|
char buffer[MAX_PACKET];
|
||||||
chunk_t data;
|
chunk_t data;
|
||||||
|
|||||||
@@ -309,8 +309,8 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
|
|||||||
my_host->destroy(my_host);
|
my_host->destroy(my_host);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my_id = identification_create_from_string(ID_IPV4_ADDR,
|
my_id = identification_create_from_string(*msg->add_conn.me.id ?
|
||||||
*msg->add_conn.me.id ? msg->add_conn.me.id : msg->add_conn.me.address);
|
msg->add_conn.me.id : msg->add_conn.me.address);
|
||||||
if (my_id == NULL)
|
if (my_id == NULL)
|
||||||
{
|
{
|
||||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid id: %s", msg->add_conn.me.id);
|
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid id: %s", msg->add_conn.me.id);
|
||||||
@@ -318,8 +318,8 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
|
|||||||
other_host->destroy(other_host);
|
other_host->destroy(other_host);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
other_id = identification_create_from_string(ID_IPV4_ADDR,
|
other_id = identification_create_from_string(*msg->add_conn.other.id ?
|
||||||
*msg->add_conn.other.id ? msg->add_conn.other.id : msg->add_conn.other.address);
|
msg->add_conn.other.id : msg->add_conn.other.address);
|
||||||
if (other_id == NULL)
|
if (other_id == NULL)
|
||||||
{
|
{
|
||||||
my_host->destroy(my_host);
|
my_host->destroy(my_host);
|
||||||
|
|||||||
@@ -31,15 +31,15 @@
|
|||||||
|
|
||||||
+ doxygen cleanup (charon/lib)
|
+ doxygen cleanup (charon/lib)
|
||||||
|
|
||||||
- implement 3DES to load encrypted pem files
|
|
||||||
|
|
||||||
- ipsec.secrets parsing
|
|
||||||
|
|
||||||
- useable certificate support
|
- useable certificate support
|
||||||
- certificate lookup via ID
|
+ more id types (use atodn from pluto)
|
||||||
|
- rewrite certificate storage the clean way
|
||||||
- certificate validation/chaining
|
- certificate validation/chaining
|
||||||
- certificate exchange
|
- certificate exchange
|
||||||
|
|
||||||
|
- implement 3DES to load encrypted pem files
|
||||||
|
- ipsec.secrets parsing
|
||||||
|
|
||||||
- trapping
|
- trapping
|
||||||
- delete notify, when to send?
|
- delete notify, when to send?
|
||||||
- notifys on connection setup failure
|
- notifys on connection setup failure
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "asn1.h"
|
#include "asn1.h"
|
||||||
#include "oid.h"
|
|
||||||
|
|
||||||
#include <utils/logger_manager.h>
|
#include <utils/logger_manager.h>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <gmp.h>
|
#include <gmp.h>
|
||||||
|
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
#include <asn1/oid.h>
|
||||||
|
|
||||||
|
|
||||||
/* Defines some primitive ASN1 types */
|
/* Defines some primitive ASN1 types */
|
||||||
|
|||||||
+16
-13
@@ -172,23 +172,26 @@ const oid_t oid_names[] = {
|
|||||||
{ 0x03, 0, 0, "id-SHA-512" }, /* 159 */
|
{ 0x03, 0, 0, "id-SHA-512" }, /* 159 */
|
||||||
{ 0x86, 0, 1, "" }, /* 160 */
|
{ 0x86, 0, 1, "" }, /* 160 */
|
||||||
{ 0xf8, 0, 1, "" }, /* 161 */
|
{ 0xf8, 0, 1, "" }, /* 161 */
|
||||||
{ 0x42, 171, 1, "netscape" }, /* 162 */
|
{ 0x42, 174, 1, "netscape" }, /* 162 */
|
||||||
{ 0x01, 169, 1, "" }, /* 163 */
|
{ 0x01, 169, 1, "" }, /* 163 */
|
||||||
{ 0x01, 165, 0, "nsCertType" }, /* 164 */
|
{ 0x01, 165, 0, "nsCertType" }, /* 164 */
|
||||||
{ 0x03, 166, 0, "nsRevocationUrl" }, /* 165 */
|
{ 0x03, 166, 0, "nsRevocationUrl" }, /* 165 */
|
||||||
{ 0x04, 167, 0, "nsCaRevocationUrl" }, /* 166 */
|
{ 0x04, 167, 0, "nsCaRevocationUrl" }, /* 166 */
|
||||||
{ 0x08, 168, 0, "nsCaPolicyUrl" }, /* 167 */
|
{ 0x08, 168, 0, "nsCaPolicyUrl" }, /* 167 */
|
||||||
{ 0x0d, 0, 0, "nsComment" }, /* 168 */
|
{ 0x0d, 0, 0, "nsComment" }, /* 168 */
|
||||||
{ 0x04, 0, 1, "policy" }, /* 169 */
|
{ 0x03, 172, 1, "directory" }, /* 169 */
|
||||||
{ 0x01, 0, 0, "nsSGC" }, /* 170 */
|
{ 0x01, 0, 1, "" }, /* 170 */
|
||||||
{ 0x45, 0, 1, "verisign" }, /* 171 */
|
{ 0x03, 0, 0, "employeeNumber" }, /* 171 */
|
||||||
{ 0x01, 0, 1, "pki" }, /* 172 */
|
{ 0x04, 0, 1, "policy" }, /* 172 */
|
||||||
{ 0x09, 0, 1, "attributes" }, /* 173 */
|
{ 0x01, 0, 0, "nsSGC" }, /* 173 */
|
||||||
{ 0x02, 175, 0, "messageType" }, /* 174 */
|
{ 0x45, 0, 1, "verisign" }, /* 174 */
|
||||||
{ 0x03, 176, 0, "pkiStatus" }, /* 175 */
|
{ 0x01, 0, 1, "pki" }, /* 175 */
|
||||||
{ 0x04, 177, 0, "failInfo" }, /* 176 */
|
{ 0x09, 0, 1, "attributes" }, /* 176 */
|
||||||
{ 0x05, 178, 0, "senderNonce" }, /* 177 */
|
{ 0x02, 178, 0, "messageType" }, /* 177 */
|
||||||
{ 0x06, 179, 0, "recipientNonce" }, /* 178 */
|
{ 0x03, 179, 0, "pkiStatus" }, /* 178 */
|
||||||
{ 0x07, 180, 0, "transID" }, /* 179 */
|
{ 0x04, 180, 0, "failInfo" }, /* 179 */
|
||||||
{ 0x08, 0, 0, "extensionReq" } /* 180 */
|
{ 0x05, 181, 0, "senderNonce" }, /* 180 */
|
||||||
|
{ 0x06, 182, 0, "recipientNonce" }, /* 181 */
|
||||||
|
{ 0x07, 183, 0, "transID" }, /* 182 */
|
||||||
|
{ 0x08, 0, 0, "extensionReq" } /* 183 */
|
||||||
};
|
};
|
||||||
|
|||||||
+11
-6
@@ -5,6 +5,9 @@
|
|||||||
* Do not edit manually!
|
* Do not edit manually!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef OID_H_
|
||||||
|
#define OID_H_
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u_char octet;
|
u_char octet;
|
||||||
u_int next;
|
u_int next;
|
||||||
@@ -67,9 +70,11 @@ extern const oid_t oid_names[];
|
|||||||
#define OID_NS_CA_REVOCATION_URL 166
|
#define OID_NS_CA_REVOCATION_URL 166
|
||||||
#define OID_NS_CA_POLICY_URL 167
|
#define OID_NS_CA_POLICY_URL 167
|
||||||
#define OID_NS_COMMENT 168
|
#define OID_NS_COMMENT 168
|
||||||
#define OID_PKI_MESSAGE_TYPE 174
|
#define OID_PKI_MESSAGE_TYPE 177
|
||||||
#define OID_PKI_STATUS 175
|
#define OID_PKI_STATUS 178
|
||||||
#define OID_PKI_FAIL_INFO 176
|
#define OID_PKI_FAIL_INFO 179
|
||||||
#define OID_PKI_SENDER_NONCE 177
|
#define OID_PKI_SENDER_NONCE 180
|
||||||
#define OID_PKI_RECIPIENT_NONCE 178
|
#define OID_PKI_RECIPIENT_NONCE 181
|
||||||
#define OID_PKI_TRANS_ID 179
|
#define OID_PKI_TRANS_ID 182
|
||||||
|
|
||||||
|
#endif /* OID_H_ */
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ print OID_H "/* Object identifiers (OIDs) used by FreeS/WAN\n",
|
|||||||
" * ", $automatic, "\n",
|
" * ", $automatic, "\n",
|
||||||
" * ", $warning, "\n",
|
" * ", $warning, "\n",
|
||||||
" */\n\n",
|
" */\n\n",
|
||||||
|
"#ifndef OID_H_\n",
|
||||||
|
"#define OID_H_\n\n",
|
||||||
"typedef struct {\n",
|
"typedef struct {\n",
|
||||||
" u_char octet;\n",
|
" u_char octet;\n",
|
||||||
" u_int next;\n",
|
" u_int next;\n",
|
||||||
@@ -73,6 +75,8 @@ while ($line = <SRC>)
|
|||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print OID_H "\n#endif /* OID_H_ */\n";
|
||||||
|
|
||||||
close SRC;
|
close SRC;
|
||||||
close OID_H;
|
close OID_H;
|
||||||
|
|
||||||
|
|||||||
@@ -167,6 +167,9 @@
|
|||||||
0x04 "nsCaRevocationUrl" OID_NS_CA_REVOCATION_URL
|
0x04 "nsCaRevocationUrl" OID_NS_CA_REVOCATION_URL
|
||||||
0x08 "nsCaPolicyUrl" OID_NS_CA_POLICY_URL
|
0x08 "nsCaPolicyUrl" OID_NS_CA_POLICY_URL
|
||||||
0x0d "nsComment" OID_NS_COMMENT
|
0x0d "nsComment" OID_NS_COMMENT
|
||||||
|
0x03 "directory"
|
||||||
|
0x01 ""
|
||||||
|
0x03 "employeeNumber"
|
||||||
0x04 "policy"
|
0x04 "policy"
|
||||||
0x01 "nsSGC"
|
0x01 "nsSGC"
|
||||||
0x45 "verisign"
|
0x45 "verisign"
|
||||||
|
|||||||
+112
-869
File diff suppressed because it is too large
Load Diff
@@ -58,14 +58,22 @@ struct x509_t {
|
|||||||
/**
|
/**
|
||||||
* @brief Get the certificate issuers ID.
|
* @brief Get the certificate issuers ID.
|
||||||
*
|
*
|
||||||
* @todo implement!
|
* The resulting ID is always a identification_t
|
||||||
|
* of type ID_DER_ASN1_DN.
|
||||||
|
*
|
||||||
|
* @param this calling object
|
||||||
|
* @return issuers ID
|
||||||
*/
|
*/
|
||||||
identification_t *(*get_issuer) (x509_t *this);
|
identification_t *(*get_issuer) (x509_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the subjects ID.
|
* @brief Get the subjects ID.
|
||||||
*
|
*
|
||||||
* @todo implement!
|
* The resulting ID is always a identification_t
|
||||||
|
* of type ID_DER_ASN1_DN.
|
||||||
|
*
|
||||||
|
* @param this calling object
|
||||||
|
* @return subjects ID
|
||||||
*/
|
*/
|
||||||
identification_t *(*get_subject) (x509_t *this);
|
identification_t *(*get_subject) (x509_t *this);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
#include <definitions.h>
|
#include <definitions.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General purpose boolean type.
|
* General purpose boolean type.
|
||||||
*/
|
*/
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -32,10 +32,6 @@ typedef enum id_type_t id_type_t;
|
|||||||
/**
|
/**
|
||||||
* @brief ID Types in a ID payload.
|
* @brief ID Types in a ID payload.
|
||||||
*
|
*
|
||||||
* @see
|
|
||||||
* - identification_t
|
|
||||||
* - id_payload_t
|
|
||||||
*
|
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
enum id_type_t {
|
enum id_type_t {
|
||||||
@@ -81,7 +77,12 @@ enum id_type_t {
|
|||||||
* specific information necessary to do certain proprietary
|
* specific information necessary to do certain proprietary
|
||||||
* types of identification.
|
* types of identification.
|
||||||
*/
|
*/
|
||||||
ID_KEY_ID = 11
|
ID_KEY_ID = 11,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special type of PRIVATE USE which matches to any other id.
|
||||||
|
*/
|
||||||
|
ID_ANY = 201,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,19 +97,19 @@ typedef struct identification_t identification_t;
|
|||||||
*
|
*
|
||||||
* The following types are possible:
|
* The following types are possible:
|
||||||
* - ID_IPV4_ADDR
|
* - ID_IPV4_ADDR
|
||||||
* - ID_FQDN*
|
* - ID_FQDN
|
||||||
* - ID_RFC822_ADDR*
|
* - ID_RFC822_ADDR
|
||||||
* - ID_IPV6_ADDR*
|
* - ID_IPV6_ADDR
|
||||||
* - ID_DER_ASN1_DN*
|
* - ID_DER_ASN1_DN
|
||||||
* - ID_DER_ASN1_GN*
|
* - ID_DER_ASN1_GN
|
||||||
* - ID_KEY_ID*
|
* - ID_KEY_ID
|
||||||
* (* = string conversion not supported)
|
|
||||||
*
|
*
|
||||||
* @b Constructors:
|
* @b Constructors:
|
||||||
* - identification_create_from_string()
|
* - identification_create_from_string()
|
||||||
* - identification_create_from_encoding()
|
* - identification_create_from_encoding()
|
||||||
*
|
*
|
||||||
* @todo Support for other ID types then ID_IPV4_ADDR.
|
* @todo Support for ID_DER_ASN1_GN is minimal right now. Comparison
|
||||||
|
* between them and ID_IPV4_ADDR/RFC822_ADDR would be nice.
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
@@ -158,10 +159,13 @@ struct identification_t {
|
|||||||
* An identification_t may contain wildcards, such as
|
* An identification_t may contain wildcards, such as
|
||||||
* *@strongswan.org. This call checks if a given ID
|
* *@strongswan.org. This call checks if a given ID
|
||||||
* (e.g. [email protected]) belongs to a such wildcard
|
* (e.g. [email protected]) belongs to a such wildcard
|
||||||
* ID. Returns TRUE if IDs are identical.
|
* ID. Returns TRUE if
|
||||||
|
* - IDs are identical
|
||||||
|
* - other is of type ID_ANY
|
||||||
|
* - other contains a wildcard and matches this
|
||||||
*
|
*
|
||||||
* @param this the ID containing a wildcard
|
* @param this the ID without wildcard
|
||||||
* @param other the ID without wildcard
|
* @param other the ID containing a wildcard
|
||||||
* @return TRUE if other belongs to this
|
* @return TRUE if other belongs to this
|
||||||
*/
|
*/
|
||||||
bool (*belongs_to) (identification_t *this, identification_t *other);
|
bool (*belongs_to) (identification_t *this, identification_t *other);
|
||||||
@@ -185,15 +189,31 @@ struct identification_t {
|
|||||||
/**
|
/**
|
||||||
* @brief Creates an identification_t object from a string.
|
* @brief Creates an identification_t object from a string.
|
||||||
*
|
*
|
||||||
* @param type type of this id, such as ID_IPV4_ADDR
|
|
||||||
* @param string input string, which will be converted
|
* @param string input string, which will be converted
|
||||||
* @return
|
* @return
|
||||||
* - created identification_t object, or
|
* - created identification_t object, or
|
||||||
* - NULL if type not supported.
|
* - NULL if unsupported string supplied.
|
||||||
|
*
|
||||||
|
* The input string may be e.g. one of the following:
|
||||||
|
* - ID_IPV4_ADDR: 192.168.0.1
|
||||||
|
* - ID_IPV6_ADDR: 2001:0db8:85a3:08d3:1319:8a2e:0370:7345
|
||||||
|
* - ID_FQDN: @www.strongswan.org (@indicates FQDN)
|
||||||
|
* - ID_RFC822_ADDR: [email protected]
|
||||||
|
* - ID_DER_ASN1_DN: C=CH, O=Linux strongSwan, CN=bob
|
||||||
|
*
|
||||||
|
* In favour of pluto, domainnames are prepended with an @, since
|
||||||
|
* pluto resolves domainnames without an @ to IPv4 addresses. Since
|
||||||
|
* we use a seperate host_t class for addresses, this doesn't
|
||||||
|
* make sense for us.
|
||||||
|
*
|
||||||
|
* A distinguished name may contain one or more of the following RDNs:
|
||||||
|
* ND, UID, DC, CN, S, SN, serialNumber, C, L, ST, O, OU, T, D,
|
||||||
|
* N, G, I, ID, EN, EmployeeNumber, E, Email, emailAddress, UN,
|
||||||
|
* unstructuredName, TCGID.
|
||||||
*
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
identification_t * identification_create_from_string(id_type_t type, char *string);
|
identification_t * identification_create_from_string(char *string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates an identification_t object from an encoded chunk.
|
* @brief Creates an identification_t object from an encoded chunk.
|
||||||
@@ -202,6 +222,9 @@ identification_t * identification_create_from_string(id_type_t type, char *strin
|
|||||||
* @param encoded encoded bytes, such as from identification_t.get_encoding
|
* @param encoded encoded bytes, such as from identification_t.get_encoding
|
||||||
* @return identification_t object
|
* @return identification_t object
|
||||||
*
|
*
|
||||||
|
* In contrast to identification_create_from_string(), this constructor never
|
||||||
|
* returns NULL, even when the conversion to a sring representation fails.
|
||||||
|
*
|
||||||
* @ingroup utils
|
* @ingroup utils
|
||||||
*/
|
*/
|
||||||
identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
|
identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#include <daemon.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum length of a log entry (only used for logger_s.log).
|
* Maximum length of a log entry (only used for logger_s.log).
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
|
|
||||||
typedef enum log_level_t log_level_t;
|
typedef enum log_level_t log_level_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -137,3 +137,7 @@ $(BUILD_DIR)certificate_test.o : $(TESTCASES_DIR)certificate_test.c $(TESTCASES_
|
|||||||
TEST_OBJS+= $(BUILD_DIR)leak_detective_test.o
|
TEST_OBJS+= $(BUILD_DIR)leak_detective_test.o
|
||||||
$(BUILD_DIR)leak_detective_test.o : $(TESTCASES_DIR)leak_detective_test.c $(TESTCASES_DIR)leak_detective_test.h
|
$(BUILD_DIR)leak_detective_test.o : $(TESTCASES_DIR)leak_detective_test.c $(TESTCASES_DIR)leak_detective_test.h
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
TEST_OBJS+= $(BUILD_DIR)identification_test.o
|
||||||
|
$(BUILD_DIR)identification_test.o : $(TESTCASES_DIR)identification_test.c $(TESTCASES_DIR)identification_test.h
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
@@ -20,14 +20,15 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "certificate_test.h"
|
#include "certificate_test.h"
|
||||||
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <crypto/certificate.h>
|
#include <crypto/x509.h>
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static char certificate_buffer[] = {
|
static char certificate_buffer[] = {
|
||||||
0x30,0x82,0x02,0xf9,0x30,0x82,0x01,0xe1,0xa0,0x03,0x02,0x01,0x02,0x02,0x11,0x00,
|
0x30,0x82,0x02,0xf9,0x30,0x82,0x01,0xe1,0xa0,0x03,0x02,0x01,0x02,0x02,0x11,0x00,
|
||||||
0xfe,0xae,0xe3,0xcf,0x00,0x27,0x8d,0xa0,0xe1,0xfa,0xb2,0x07,0xd4,0x15,0x40,0x93,
|
0xfe,0xae,0xe3,0xcf,0x00,0x27,0x8d,0xa0,0xe1,0xfa,0xb2,0x07,0xd4,0x15,0x40,0x93,
|
||||||
@@ -85,10 +86,27 @@ static char certificate_buffer[] = {
|
|||||||
void test_certificate(protected_tester_t *tester)
|
void test_certificate(protected_tester_t *tester)
|
||||||
{
|
{
|
||||||
chunk_t certificate = {certificate_buffer, sizeof(certificate_buffer)};
|
chunk_t certificate = {certificate_buffer, sizeof(certificate_buffer)};
|
||||||
|
identification_t *id;
|
||||||
|
x509_t *cert;
|
||||||
|
|
||||||
x509_t *cert = x509_create_from_chunk(certificate);
|
cert = x509_create_from_chunk(certificate);
|
||||||
|
id = cert->get_subject(cert);
|
||||||
//certificate_t *cert = certificate_create_from_file("myCert.der");
|
tester->assert_true(tester, strcmp(id->get_string(id), "C=CH, O=Linux strongSwan, CN=maeno") == 0, "subject");
|
||||||
|
id = cert->get_issuer(cert);
|
||||||
|
tester->assert_true(tester, strcmp(id->get_string(id), "C=CH, O=Linux strongSwan, CN=maeno") == 0, "issuer");
|
||||||
cert->destroy(cert);
|
cert->destroy(cert);
|
||||||
|
/*
|
||||||
|
cert = x509_create_from_file("scripts/complex1.der");
|
||||||
|
id = cert->get_subject(cert);
|
||||||
|
printf("Subject: %s\n", id->get_string(id));
|
||||||
|
id = cert->get_issuer(cert);
|
||||||
|
printf("Issuer: %s\n", id->get_string(id));
|
||||||
|
cert->destroy(cert);
|
||||||
|
|
||||||
|
cert = x509_create_from_file("scripts/complex2.der");
|
||||||
|
id = cert->get_subject(cert);
|
||||||
|
printf("Subject: %s\n", id->get_string(id));
|
||||||
|
id = cert->get_issuer(cert);
|
||||||
|
printf("Issuer: %s\n", id->get_string(id));
|
||||||
|
cert->destroy(cert);*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ void test_connection(protected_tester_t *tester)
|
|||||||
{
|
{
|
||||||
host_t *alice = host_create(AF_INET, "192.168.0.1", 500);
|
host_t *alice = host_create(AF_INET, "192.168.0.1", 500);
|
||||||
host_t *bob = host_create(AF_INET, "192.168.0.2", 500);
|
host_t *bob = host_create(AF_INET, "192.168.0.2", 500);
|
||||||
identification_t *alice_id = identification_create_from_string(AF_INET, "192.168.0.1");
|
identification_t *alice_id = identification_create_from_string("192.168.0.1");
|
||||||
identification_t *bob_id = identification_create_from_string(AF_INET, "192.168.0.2");
|
identification_t *bob_id = identification_create_from_string("192.168.0.2");
|
||||||
connection_t *connection = connection_create(alice, bob, alice_id, bob_id, RSA_DIGITAL_SIGNATURE);
|
connection_t *connection = connection_create(alice, bob, alice_id, bob_id, RSA_DIGITAL_SIGNATURE);
|
||||||
proposal_t *prop1, *prop2, *prop3, *prop4;
|
proposal_t *prop1, *prop2, *prop3, *prop4;
|
||||||
linked_list_t *list;
|
linked_list_t *list;
|
||||||
|
|||||||
@@ -0,0 +1,166 @@
|
|||||||
|
/**
|
||||||
|
* @file identification_test.c
|
||||||
|
*
|
||||||
|
* @brief Tests for the identification_t class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2006 Martin Willi
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* 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 <http://www.fsf.org/copyleft/gpl.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 <string.h>
|
||||||
|
|
||||||
|
#include "identification_test.h"
|
||||||
|
|
||||||
|
#include <utils/identification.h>
|
||||||
|
#include <utils/logger.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* described in Header-File
|
||||||
|
*/
|
||||||
|
void test_identification(protected_tester_t *tester)
|
||||||
|
{
|
||||||
|
identification_t *a, *b, *c, *d;
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
{ /* test RFC822_ADDR */
|
||||||
|
char *bob_string = "[email protected]";
|
||||||
|
chunk_t bob_chunk = {bob_string, strlen(bob_string)};
|
||||||
|
|
||||||
|
a = identification_create_from_string("[email protected]");
|
||||||
|
b = identification_create_from_encoding(ID_RFC822_ADDR, bob_chunk);
|
||||||
|
c = identification_create_from_string("*@wonderland.net");
|
||||||
|
d = identification_create_from_string("*@badlands.com");
|
||||||
|
|
||||||
|
result = a->belongs_to(a, c);
|
||||||
|
tester->assert_true(tester, result, "alice belongs to wonderland");
|
||||||
|
result = b->belongs_to(b, c);
|
||||||
|
tester->assert_true(tester, result, "bob belongs to wonderland");
|
||||||
|
result = a->belongs_to(a, d);
|
||||||
|
tester->assert_false(tester, result, "alice does not belong to badlands");
|
||||||
|
result = b->belongs_to(b, d);
|
||||||
|
tester->assert_false(tester, result, "bob does not belong to badlands");
|
||||||
|
result = c->belongs_to(c, d);
|
||||||
|
tester->assert_false(tester, result, "wonderland is not in badlands");
|
||||||
|
result = a->belongs_to(a, a);
|
||||||
|
tester->assert_true(tester, result, "alice belongs to alice alice");
|
||||||
|
result = a->equals(a, a);
|
||||||
|
tester->assert_true(tester, result, "alice is alice");
|
||||||
|
result = a->equals(a, b);
|
||||||
|
tester->assert_false(tester, result, "alice is not bob");
|
||||||
|
|
||||||
|
a->destroy(a);
|
||||||
|
b->destroy(b);
|
||||||
|
c->destroy(c);
|
||||||
|
d->destroy(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ /* test FQDN */
|
||||||
|
char *bob_string = "@dave.nirvana.org";
|
||||||
|
chunk_t bob_chunk = {bob_string, strlen(bob_string)};
|
||||||
|
|
||||||
|
a = identification_create_from_string("@carol.nirvana.org");
|
||||||
|
b = identification_create_from_encoding(ID_FQDN, bob_chunk);
|
||||||
|
c = identification_create_from_string("@*.nirvana.org");
|
||||||
|
d = identification_create_from_string("@*.samsara.com");
|
||||||
|
|
||||||
|
result = a->belongs_to(a, c);
|
||||||
|
tester->assert_true(tester, result, "carol belongs to nirvana");
|
||||||
|
result = b->belongs_to(b, c);
|
||||||
|
tester->assert_true(tester, result, "dave belongs to nirvana");
|
||||||
|
result = a->belongs_to(a, d);
|
||||||
|
tester->assert_false(tester, result, "carol does not belong to samsara");
|
||||||
|
result = b->belongs_to(b, d);
|
||||||
|
tester->assert_false(tester, result, "dave does not belong to samsara");
|
||||||
|
result = c->belongs_to(c, d);
|
||||||
|
tester->assert_false(tester, result, "nirvana is not in samsara");
|
||||||
|
result = a->belongs_to(a, a);
|
||||||
|
tester->assert_true(tester, result, "carol belongs to carol carol");
|
||||||
|
result = a->equals(a, a);
|
||||||
|
tester->assert_true(tester, result, "carol is carol");
|
||||||
|
result = a->equals(a, b);
|
||||||
|
tester->assert_false(tester, result, "carol is not dave");
|
||||||
|
|
||||||
|
a->destroy(a);
|
||||||
|
b->destroy(b);
|
||||||
|
c->destroy(c);
|
||||||
|
d->destroy(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{ /* test ID IPV4 ADDR, no wildcards yet */
|
||||||
|
char bob_addr[] = {192,168,0,2};
|
||||||
|
chunk_t bob_chunk = chunk_from_buf(bob_addr);
|
||||||
|
|
||||||
|
a = identification_create_from_string("192.168.0.1");
|
||||||
|
b = identification_create_from_encoding(ID_IPV4_ADDR, bob_chunk);
|
||||||
|
c = identification_create_from_string("192.168.0.2"); /* as bob */
|
||||||
|
|
||||||
|
result = a->equals(a, a);
|
||||||
|
tester->assert_true(tester, result, "IPV4_ADDR of alice equals IPV4_ADDR of alice");
|
||||||
|
result = b->equals(b, c);
|
||||||
|
tester->assert_true(tester, result, "IPV4_ADDR of bob equals IPV4_ADDR of carol");
|
||||||
|
result = a->equals(a, b);
|
||||||
|
tester->assert_false(tester, result, "IPV4_ADDR of alice doesn't equal IPV4_ADDR of bob");
|
||||||
|
|
||||||
|
a->destroy(a);
|
||||||
|
b->destroy(b);
|
||||||
|
c->destroy(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ /* test ID IPV6 ADDR, no wildcards yet */
|
||||||
|
char bob_addr[] = {0x20,0x01,0x0d,0xb8,0x85,0xa3,0x08,0xd3,0x13,0x19,0x8a,0x2e,0x03,0x70,0x73,0x44};
|
||||||
|
chunk_t bob_chunk = chunk_from_buf(bob_addr);
|
||||||
|
|
||||||
|
a = identification_create_from_string("2001:0db8:85a3:08d3:1319:8a2e:0370:7345");
|
||||||
|
b = identification_create_from_encoding(ID_IPV6_ADDR, bob_chunk);
|
||||||
|
c = identification_create_from_string("2001:0db8:85a3:08d3:1319:8a2e:0370:7344"); /* as bob */
|
||||||
|
|
||||||
|
result = a->equals(a, a);
|
||||||
|
tester->assert_true(tester, result, "IPV6_ADDR of alice equals IPV6_ADDR of alice");
|
||||||
|
result = b->equals(b, c);
|
||||||
|
tester->assert_true(tester, result, "IPV6_ADDR of bob equals IPV6_ADDR of carol");
|
||||||
|
result = a->equals(a, b);
|
||||||
|
tester->assert_false(tester, result, "IPV6_ADDR of alice doesn't equal IPV6_ADDR of bob");
|
||||||
|
|
||||||
|
a->destroy(a);
|
||||||
|
b->destroy(b);
|
||||||
|
c->destroy(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ /* test ID DER_ASN1_DN */
|
||||||
|
a = identification_create_from_string("C=CH, O=Linux strongSwan, CN=alice");
|
||||||
|
b = identification_create_from_string("O=Linux strongSwan, C=CH, CN=bob");
|
||||||
|
c = identification_create_from_string("C=CH, O=Linux strongSwan, CN=*");
|
||||||
|
d = identification_create_from_string("C=CH, O=Linux openswan, CN=*");
|
||||||
|
|
||||||
|
result = a->equals(a, a);
|
||||||
|
tester->assert_true(tester, result, "DN of alice equals DN of alice");
|
||||||
|
result = a->equals(a, b);
|
||||||
|
tester->assert_false(tester, result, "DN of alice doesn't equal DN of bob");
|
||||||
|
result = a->belongs_to(a, c);
|
||||||
|
tester->assert_true(tester, result, "DN of alice belongs to DN of carol");
|
||||||
|
/* TODO: This does NOT work, wildcard check should work with unordered RDNs */
|
||||||
|
result = b->belongs_to(b, c);
|
||||||
|
tester->assert_true(tester, result, "DN of bob belongs to DN of carol");
|
||||||
|
result = b->belongs_to(b, d);
|
||||||
|
tester->assert_false(tester, result, "DN of bob doesn't belong to DN of dave");
|
||||||
|
|
||||||
|
a->destroy(a);
|
||||||
|
b->destroy(b);
|
||||||
|
c->destroy(c);
|
||||||
|
d->destroy(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* @file identification_test.h
|
||||||
|
*
|
||||||
|
* @brief Tests for the identification_t class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2006 Martin Willi
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* 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 <http://www.fsf.org/copyleft/gpl.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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IDENTIFICATION_TEST_H_
|
||||||
|
#define IDENTIFICATION_TEST_H_
|
||||||
|
|
||||||
|
#include <utils/tester.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test function used to test the identification functionality.
|
||||||
|
*
|
||||||
|
* @param tester associated tester object
|
||||||
|
*
|
||||||
|
* @ingroup testcases
|
||||||
|
*/
|
||||||
|
void test_identification(protected_tester_t *tester);
|
||||||
|
|
||||||
|
#endif /* IDENTIFICATION_TEST_H_ */
|
||||||
@@ -46,8 +46,8 @@ void test_policy(protected_tester_t *tester)
|
|||||||
logger = logger_manager->get_logger(logger_manager, TESTER);
|
logger = logger_manager->get_logger(logger_manager, TESTER);
|
||||||
logger->disable_level(logger, FULL);
|
logger->disable_level(logger, FULL);
|
||||||
|
|
||||||
alice = identification_create_from_string(ID_IPV4_ADDR, "152.96.193.131");
|
alice = identification_create_from_string("152.96.193.131");
|
||||||
bob = identification_create_from_string(ID_IPV4_ADDR, "152.96.193.130");
|
bob = identification_create_from_string("152.96.193.130");
|
||||||
policy = policy_create(alice, bob);
|
policy = policy_create(alice, bob);
|
||||||
|
|
||||||
tester->assert_true(tester, (policy != NULL), "policy construction");
|
tester->assert_true(tester, (policy != NULL), "policy construction");
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
#include <crypto/certificate.h>
|
#include <crypto/x509.h>
|
||||||
|
|
||||||
char private_key_buffer[] = {
|
char private_key_buffer[] = {
|
||||||
0x30,0x82,0x04,0xa2,0x02,0x00,0x02,0x82,0x01,0x00,0x6f,0x25,0x74,0x63,0x2a,0x2f,
|
0x30,0x82,0x04,0xa2,0x02,0x00,0x02,0x82,0x01,0x00,0x6f,0x25,0x74,0x63,0x2a,0x2f,
|
||||||
@@ -205,7 +205,7 @@ void test_rsa(protected_tester_t *tester)
|
|||||||
/* key loading */
|
/* key loading */
|
||||||
private_key = rsa_private_key_create_from_file("alice.der", NULL);
|
private_key = rsa_private_key_create_from_file("alice.der", NULL);
|
||||||
tester->assert_true(tester, private_key != NULL, "loading private key from file");
|
tester->assert_true(tester, private_key != NULL, "loading private key from file");
|
||||||
certificate = certificate_create_from_file("alice-cert.der");
|
certificate = x509_create_from_file("alice-cert.der");
|
||||||
tester->assert_true(tester, public_key != NULL, "loading certificate from file");
|
tester->assert_true(tester, public_key != NULL, "loading certificate from file");
|
||||||
public_key = certificate->get_public_key(certificate);
|
public_key = certificate->get_public_key(certificate);
|
||||||
tester->assert_true(tester, public_key != NULL, "loading public key from certificate");
|
tester->assert_true(tester, public_key != NULL, "loading public key from certificate");
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
#include "child_sa_test.h"
|
#include "child_sa_test.h"
|
||||||
#include "certificate_test.h"
|
#include "certificate_test.h"
|
||||||
#include "leak_detective_test.h"
|
#include "leak_detective_test.h"
|
||||||
|
#include "identification_test.h"
|
||||||
|
|
||||||
/* output for test messages */
|
/* output for test messages */
|
||||||
extern FILE * stderr;
|
extern FILE * stderr;
|
||||||
@@ -131,6 +132,7 @@ test_t kernel_interface_test = {test_kernel_interface, "Kernel Interface"};
|
|||||||
test_t child_sa_test = {test_child_sa, "Child SA"};
|
test_t child_sa_test = {test_child_sa, "Child SA"};
|
||||||
test_t certificate_test = {test_certificate, "X509 Certificate"};
|
test_t certificate_test = {test_certificate, "X509 Certificate"};
|
||||||
test_t leak_detective_test = {test_leak_detective, "LEAK detective"};
|
test_t leak_detective_test = {test_leak_detective, "LEAK detective"};
|
||||||
|
test_t identification_test = {test_identification, "identification"};
|
||||||
|
|
||||||
|
|
||||||
daemon_t* charon;
|
daemon_t* charon;
|
||||||
|
|||||||
Reference in New Issue
Block a user