2 * Copyright (C) 2012 Reto Buerki
3 * Copyright (C) 2012 Adrian-Ken Rueegsegger
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include <utils/debug.h>
18 #include <tkm/constants.h>
19 #include <tkm/client.h>
21 #include "tkm_utils.h"
22 #include "tkm_types.h"
23 #include "tkm_private_key.h"
25 typedef struct private_tkm_private_key_t private_tkm_private_key_t
;
28 * Private data of a tkm_private_key_t object.
30 struct private_tkm_private_key_t
{
33 * Public interface for this signer.
35 tkm_private_key_t
public;
49 METHOD(private_key_t
, get_type
, key_type_t
,
50 private_tkm_private_key_t
*this)
55 METHOD(private_key_t
, sign
, bool,
56 private_tkm_private_key_t
*this, signature_scheme_t scheme
,
57 chunk_t data
, chunk_t
*signature
)
60 init_message_type msg
;
64 DBG1(DBG_LIB
, "unable to get signature information");
67 sign_info_t sign
= *(sign_info_t
*)(data
.ptr
);
69 chunk_to_sequence(&sign
.init_message
, &msg
, sizeof(init_message_type
));
70 const isa_id_type isa_id
= sign
.isa_id
;
71 chunk_free(&sign
.init_message
);
73 if (ike_isa_sign(isa_id
, 1, msg
, &sig
) != TKM_OK
)
75 DBG1(DBG_LIB
, "signature operation failed");
79 sequence_to_chunk(sig
.data
, sig
.size
, signature
);
83 METHOD(private_key_t
, decrypt
, bool,
84 private_tkm_private_key_t
*this, encryption_scheme_t scheme
,
85 chunk_t crypto
, chunk_t
*plain
)
90 METHOD(private_key_t
, get_keysize
, int,
91 private_tkm_private_key_t
*this)
96 METHOD(private_key_t
, get_public_key
, public_key_t
*,
97 private_tkm_private_key_t
*this)
102 METHOD(private_key_t
, get_encoding
, bool,
103 private_tkm_private_key_t
*this, cred_encoding_type_t type
,
109 METHOD(private_key_t
, get_fingerprint
, bool,
110 private_tkm_private_key_t
*this, cred_encoding_type_t type
, chunk_t
*fp
)
112 *fp
= this->fingerprint
;
116 METHOD(private_key_t
, get_ref
, private_key_t
*,
117 private_tkm_private_key_t
*this)
120 return &this->public.key
;
123 METHOD(private_key_t
, destroy
, void,
124 private_tkm_private_key_t
*this)
126 if (ref_put(&this->ref
))
128 chunk_free(&this->fingerprint
);
136 tkm_private_key_t
*tkm_private_key_init(void)
138 private_tkm_private_key_t
*this;
143 .get_type
= _get_type
,
146 .get_keysize
= _get_keysize
,
147 .get_public_key
= _get_public_key
,
148 .equals
= private_key_equals
,
149 .belongs_to
= private_key_belongs_to
,
150 .get_fingerprint
= _get_fingerprint
,
151 .has_fingerprint
= private_key_has_fingerprint
,
152 .get_encoding
= _get_encoding
,
160 /* fingerprint of alice@strongswan.org keypair */
161 const char fake_fp
[] = "05da04208c02f428470acf6c772d066613da863c";
162 this->fingerprint
= chunk_create((u_char
*)fake_fp
, strlen(fake_fp
));
163 this->fingerprint
= chunk_from_hex(this->fingerprint
, NULL
);
165 return &this->public;