| 1 |
Author: Eric Taylor <[email protected]> |
| 2 |
Last-Update: 2019-02-11 |
| 3 |
Bug-Debian: https://bugs.debian.org/922049 |
| 4 |
Description: Support for ed25519 keys |
| 5 |
Fixme: Does not apply to latest upstream thus not activated |
| 6 |
|
| 7 |
diff --git a/src/pam/auth-method-localdb/Makefile.am b/src/pam/auth-method-localdb/Makefile.am |
| 8 |
index c033f16..ac528b0 100644 |
| 9 |
--- a/src/pam/auth-method-localdb/Makefile.am |
| 10 |
+++ b/src/pam/auth-method-localdb/Makefile.am |
| 11 |
@@ -11,7 +11,7 @@ |
| 12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 14 |
# License for more details. |
| 15 |
-# |
| 16 |
+# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program; if not, write to the Free Software |
| 19 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 |
diff --git a/src/pam/auth-method-localdb/auth-localdb.c b/src/pam/auth-method-localdb/auth-localdb.c |
| 21 |
index d73808d..f9041f7 100644 |
| 22 |
--- a/src/pam/auth-method-localdb/auth-localdb.c |
| 23 |
+++ b/src/pam/auth-method-localdb/auth-localdb.c |
| 24 |
@@ -1,18 +1,18 @@ |
| 25 |
/* auth-localdb.c - localdb authentication method for Poldi. |
| 26 |
Copyright (C) 2004, 2005, 2007, 2008, 2009 g10 Code GmbH |
| 27 |
- |
| 28 |
+ |
| 29 |
This file is part of Poldi. |
| 30 |
- |
| 31 |
+ |
| 32 |
Poldi is free software; you can redistribute it and/or modify it |
| 33 |
under the terms of the GNU General Public License as published by |
| 34 |
the Free Software Foundation; either version 3 of the License, or |
| 35 |
(at your option) any later version. |
| 36 |
- |
| 37 |
+ |
| 38 |
Poldi is distributed in the hope that it will be useful, but |
| 39 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 41 |
General Public License for more details. |
| 42 |
- |
| 43 |
+ |
| 44 |
You should have received a copy of the GNU General Public License |
| 45 |
along with this program; if not, see |
| 46 |
<http://www.gnu.org/licenses/>. */ |
| 47 |
@@ -33,15 +33,17 @@ |
| 48 |
|
| 49 |
#include "scd/scd.h" |
| 50 |
#include "util/support.h" |
| 51 |
+#include "util/key-types.h" |
| 52 |
+#include "util/debugTools.h" |
| 53 |
#include "auth-support/ctx.h" |
| 54 |
#include "auth-support/wait-for-card.h" |
| 55 |
|
| 56 |
#include "usersdb.h" |
| 57 |
#include "key-lookup.h" |
| 58 |
|
| 59 |
- |
| 60 |
|
| 61 |
#if 0 |
| 62 |
+ |
| 63 |
/* Currently, the localdb method doesn't require a special cookie. */ |
| 64 |
|
| 65 |
static gpg_error_t |
| 66 |
@@ -79,6 +81,7 @@ auth_method_localdb_auth_do (poldi_ctx_t ctx, |
| 67 |
size_t challenge_n; |
| 68 |
size_t response_n; |
| 69 |
gcry_sexp_t key; |
| 70 |
+ key_types key_type; |
| 71 |
gpg_error_t err; |
| 72 |
char *card_username; |
| 73 |
const char *username; |
| 74 |
@@ -143,8 +146,24 @@ auth_method_localdb_auth_do (poldi_ctx_t ctx, |
| 75 |
if (err) |
| 76 |
goto out; |
| 77 |
|
| 78 |
+ /* Retrieve key type */ |
| 79 |
+ err = get_key_type(&key_type, key); |
| 80 |
+ if(err) { |
| 81 |
+ //unsupported crypto |
| 82 |
+ log_msg_error (ctx->loghandle, |
| 83 |
+ "Unsupported Key Type\n"); |
| 84 |
+ |
| 85 |
+ goto out; |
| 86 |
+ } |
| 87 |
+ /*Print out key type if debug is enabled */ |
| 88 |
+ if (ctx->debug) { |
| 89 |
+ log_msg_debug (ctx->loghandle, |
| 90 |
+ "Key Type " |
| 91 |
+ "`%s'", key_type_to_str(key_type)); |
| 92 |
+ } |
| 93 |
+ |
| 94 |
/* Generate challenge. */ |
| 95 |
- err = challenge_generate (&challenge, &challenge_n); |
| 96 |
+ err = challenge_generate (&challenge, &challenge_n, key_type); |
| 97 |
if (err) |
| 98 |
{ |
| 99 |
log_msg_error (ctx->loghandle, |
| 100 |
@@ -154,7 +173,7 @@ auth_method_localdb_auth_do (poldi_ctx_t ctx, |
| 101 |
} |
| 102 |
|
| 103 |
/* Let card sign the challenge. */ |
| 104 |
- err = scd_pksign (ctx->scd, "OPENPGP.3", |
| 105 |
+ err = scd_pksign (ctx->scd, "OPENPGP.3", key_type, |
| 106 |
challenge, challenge_n, |
| 107 |
&response, &response_n); |
| 108 |
if (err) |
| 109 |
@@ -165,8 +184,47 @@ auth_method_localdb_auth_do (poldi_ctx_t ctx, |
| 110 |
goto out; |
| 111 |
} |
| 112 |
|
| 113 |
+ /*DEBUG LOG S Expressions */ |
| 114 |
+ if (ctx->debug) { |
| 115 |
+ char outBuff[4096]; |
| 116 |
+ gcry_sexp_t sexp_signature = NULL; |
| 117 |
+ |
| 118 |
+ switch (key_type) |
| 119 |
+ { |
| 120 |
+ case kType_rsa: |
| 121 |
+ err = gcry_sexp_build (&sexp_signature, NULL, "(sig-val(rsa(s%b)))", |
| 122 |
+ response_n,response); |
| 123 |
+ break; |
| 124 |
+ |
| 125 |
+ case kType_ecc_Ed25519: |
| 126 |
+ err = gcry_sexp_build (&sexp_signature, NULL, "(sig-val(eddsa(r%b)(s%b)))", |
| 127 |
+ (int)response_n/2, response, |
| 128 |
+ (int)response_n/2, response + response_n/2); |
| 129 |
+ break; |
| 130 |
+ |
| 131 |
+ default: |
| 132 |
+ err = GPG_ERR_CONFIGURATION; |
| 133 |
+ }//switch |
| 134 |
+ //log public key |
| 135 |
+ //log_msg_debug(ctx->loghandle, "%s","Public_KEY"); |
| 136 |
+ outBuff[0] = 0; |
| 137 |
+ sprintSEXP_Ed25519(key, outBuff, 4096); |
| 138 |
+ log_msg_debug(ctx->loghandle, "Public_KEY: %s",outBuff); |
| 139 |
+ outBuff[0] = 0; |
| 140 |
+ |
| 141 |
+ //log Signature |
| 142 |
+ //log_msg_debug(ctx->loghandle, "%s","Signature"); |
| 143 |
+ sprintSEXP_Ed25519(sexp_signature, outBuff, 4096); |
| 144 |
+ log_msg_debug(ctx->loghandle, "Signature: %s",outBuff); |
| 145 |
+ outBuff[0] = 0; |
| 146 |
+ |
| 147 |
+ //free resources |
| 148 |
+ gcry_sexp_release(sexp_signature); |
| 149 |
+ |
| 150 |
+ }//if debug |
| 151 |
+ |
| 152 |
/* Verify response. */ |
| 153 |
- err = challenge_verify (key, challenge, challenge_n, response, response_n); |
| 154 |
+ err = challenge_verify (key, key_type, challenge, challenge_n, response, response_n); |
| 155 |
if (err) |
| 156 |
{ |
| 157 |
log_msg_error (ctx->loghandle, "failed to verify challenge"); |
| 158 |
diff --git a/src/pam/auth-method-localdb/key-lookup.c b/src/pam/auth-method-localdb/key-lookup.c |
| 159 |
index 20fce4a..708148a 100644 |
| 160 |
--- a/src/pam/auth-method-localdb/key-lookup.c |
| 161 |
+++ b/src/pam/auth-method-localdb/key-lookup.c |
| 162 |
@@ -1,22 +1,22 @@ |
| 163 |
/* key-lookup.c - Lookup keys for localdb authentication |
| 164 |
Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH |
| 165 |
- |
| 166 |
+ |
| 167 |
This file is part of Poldi. |
| 168 |
- |
| 169 |
+ |
| 170 |
Poldi is free software; you can redistribute it and/or modify it |
| 171 |
under the terms of the GNU General Public License as published by |
| 172 |
the Free Software Foundation; either version 3 of the License, or |
| 173 |
(at your option) any later version. |
| 174 |
- |
| 175 |
+ |
| 176 |
Poldi is distributed in the hope that it will be useful, but |
| 177 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 178 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 179 |
General Public License for more details. |
| 180 |
- |
| 181 |
+ |
| 182 |
You should have received a copy of the GNU General Public License |
| 183 |
along with this program; if not, see |
| 184 |
<http://www.gnu.org/licenses/>. */ |
| 185 |
- |
| 186 |
+ |
| 187 |
#include <poldi.h> |
| 188 |
|
| 189 |
#include <unistd.h> |
| 190 |
@@ -28,11 +28,11 @@ |
| 191 |
|
| 192 |
#include "util/support.h" |
| 193 |
#include "util/filenames.h" |
| 194 |
+#include "util/key-types.h" |
| 195 |
#include "key-lookup.h" |
| 196 |
#include "defs-localdb.h" |
| 197 |
|
| 198 |
|
| 199 |
- |
| 200 |
/* This functions construct a new C-string containing the absolute |
| 201 |
path for the file, which is to expected to contain the public key |
| 202 |
for the card identified by SERIALNO. Returns proper error |
| 203 |
@@ -97,4 +97,6 @@ key_lookup_by_serialno (poldi_ctx_t ctx, const char *serialno, gcry_sexp_t *key) |
| 204 |
return err; |
| 205 |
} |
| 206 |
|
| 207 |
+ |
| 208 |
+ |
| 209 |
|
| 210 |
diff --git a/src/pam/auth-method-localdb/key-lookup.h b/src/pam/auth-method-localdb/key-lookup.h |
| 211 |
index a36615d..bae3834 100644 |
| 212 |
--- a/src/pam/auth-method-localdb/key-lookup.h |
| 213 |
+++ b/src/pam/auth-method-localdb/key-lookup.h |
| 214 |
@@ -1,18 +1,18 @@ |
| 215 |
/* key-lookup.c - Lookup keys for localdb authentication |
| 216 |
Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH |
| 217 |
- |
| 218 |
+ |
| 219 |
This file is part of Poldi. |
| 220 |
- |
| 221 |
+ |
| 222 |
Poldi is free software; you can redistribute it and/or modify it |
| 223 |
under the terms of the GNU General Public License as published by |
| 224 |
the Free Software Foundation; either version 3 of the License, or |
| 225 |
(at your option) any later version. |
| 226 |
- |
| 227 |
+ |
| 228 |
Poldi is distributed in the hope that it will be useful, but |
| 229 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 230 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 231 |
General Public License for more details. |
| 232 |
- |
| 233 |
+ |
| 234 |
You should have received a copy of the GNU General Public License |
| 235 |
along with this program; if not, see |
| 236 |
<http://www.gnu.org/licenses/>. */ |
| 237 |
diff --git a/src/pam/auth-method-x509/auth-x509.c b/src/pam/auth-method-x509/auth-x509.c |
| 238 |
index fafdc9e..ea8c756 100644 |
| 239 |
--- a/src/pam/auth-method-x509/auth-x509.c |
| 240 |
+++ b/src/pam/auth-method-x509/auth-x509.c |
| 241 |
@@ -38,7 +38,7 @@ |
| 242 |
#include "util/defs.h" |
| 243 |
#include "util/simplelog.h" |
| 244 |
#include "util/simpleparse.h" |
| 245 |
- |
| 246 |
+#include "util/key-types.h" |
| 247 |
|
| 248 |
|
| 249 |
struct x509_ctx_s |
| 250 |
@@ -198,6 +198,7 @@ verify_challenge_sig (poldi_ctx_t ctx, ksba_cert_t cert, |
| 251 |
{ |
| 252 |
gcry_sexp_t pubkey; |
| 253 |
gpg_error_t err; |
| 254 |
+ key_types key_type = kType_rsa; |
| 255 |
|
| 256 |
pubkey = NULL; |
| 257 |
|
| 258 |
@@ -205,7 +206,7 @@ verify_challenge_sig (poldi_ctx_t ctx, ksba_cert_t cert, |
| 259 |
if (err) |
| 260 |
goto out; |
| 261 |
|
| 262 |
- err = challenge_verify (pubkey, challenge, challenge_n, |
| 263 |
+ err = challenge_verify (pubkey, key_type, challenge, challenge_n, |
| 264 |
response, response_n); |
| 265 |
|
| 266 |
out: |
| 267 |
@@ -472,6 +473,7 @@ auth_method_x509_auth_do (poldi_ctx_t ctx, x509_ctx_t cookie, |
| 268 |
char *card_username; |
| 269 |
ksba_cert_t cert; |
| 270 |
dirmngr_ctx_t dirmngr; |
| 271 |
+ key_types key_type; |
| 272 |
|
| 273 |
dirmngr = NULL; |
| 274 |
challenge = NULL; |
| 275 |
@@ -544,8 +546,8 @@ auth_method_x509_auth_do (poldi_ctx_t ctx, x509_ctx_t cookie, |
| 276 |
} |
| 277 |
|
| 278 |
/*** Generate challenge. ***/ |
| 279 |
- |
| 280 |
- err = challenge_generate (&challenge, &challenge_n); |
| 281 |
+ key_type = kType_rsa; |
| 282 |
+ err = challenge_generate (&challenge, &challenge_n, key_type); |
| 283 |
if (err) |
| 284 |
{ |
| 285 |
log_msg_error (ctx->loghandle, "failed to generate challenge: %s", |
| 286 |
@@ -554,7 +556,7 @@ auth_method_x509_auth_do (poldi_ctx_t ctx, x509_ctx_t cookie, |
| 287 |
} |
| 288 |
|
| 289 |
/*** Let card sign the challenge. ***/ |
| 290 |
- err = scd_pksign (ctx->scd, "OPENPGP.3", |
| 291 |
+ err = scd_pksign (ctx->scd, "OPENPGP.3", key_type, |
| 292 |
challenge, challenge_n, |
| 293 |
&response, &response_n); |
| 294 |
if (err) |
| 295 |
diff --git a/src/scd/scd.c b/src/scd/scd.c |
| 296 |
index 5d1b835..7a6c62d 100644 |
| 297 |
--- a/src/scd/scd.c |
| 298 |
+++ b/src/scd/scd.c |
| 299 |
@@ -1,19 +1,19 @@ |
| 300 |
/* scd.c - Interface to Scdaemon |
| 301 |
Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. |
| 302 |
- Copyright (C) 2007, 2008, 2009 g10code GmbH. |
| 303 |
+ Copyright (C) 2007, 2008, 2009 g10code GmbH. |
| 304 |
|
| 305 |
This file is part of Poldi. |
| 306 |
- |
| 307 |
+ |
| 308 |
Poldi is free software; you can redistribute it and/or modify it |
| 309 |
under the terms of the GNU General Public License as published by |
| 310 |
the Free Software Foundation; either version 3 of the License, or |
| 311 |
(at your option) any later version. |
| 312 |
- |
| 313 |
+ |
| 314 |
Poldi is distributed in the hope that it will be useful, but |
| 315 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 316 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 317 |
General Public License for more details. |
| 318 |
- |
| 319 |
+ |
| 320 |
You should have received a copy of the GNU General Public License |
| 321 |
along with this program; if not, see |
| 322 |
<http://www.gnu.org/licenses/>. */ |
| 323 |
@@ -75,7 +75,7 @@ struct learn_parm_s |
| 324 |
void *sinfo_cb_arg; |
| 325 |
}; |
| 326 |
|
| 327 |
-struct inq_needpin_s |
| 328 |
+struct inq_needpin_s |
| 329 |
{ |
| 330 |
scd_context_t ctx; |
| 331 |
int (*getpin_cb)(void *, const char *, char*, size_t); |
| 332 |
@@ -375,7 +375,7 @@ unescape_status_string (const char *s) |
| 333 |
while (*s) |
| 334 |
{ |
| 335 |
if (*s == '%' && s[1] && s[2]) |
| 336 |
- { |
| 337 |
+ { |
| 338 |
s++; |
| 339 |
*d = xtoi_2 (s); |
| 340 |
if (!*d) |
| 341 |
@@ -391,7 +391,7 @@ unescape_status_string (const char *s) |
| 342 |
else |
| 343 |
*d++ = *s++; |
| 344 |
} |
| 345 |
- *d = 0; |
| 346 |
+ *d = 0; |
| 347 |
return buffer; |
| 348 |
} |
| 349 |
|
| 350 |
@@ -490,7 +490,7 @@ learn_status_cb (void *opaque, const char *line) |
| 351 |
else if (no == 3) |
| 352 |
parm->fpr3valid = unhexify_fpr (line, parm->fpr3); |
| 353 |
} |
| 354 |
- |
| 355 |
+ |
| 356 |
return 0; |
| 357 |
} |
| 358 |
|
| 359 |
@@ -605,7 +605,7 @@ membuf_data_cb (void *opaque, const void *buffer, size_t length) |
| 360 |
put_membuf (data, buffer, length); |
| 361 |
return 0; |
| 362 |
} |
| 363 |
- |
| 364 |
+ |
| 365 |
/* Handle the NEEDPIN inquiry. */ |
| 366 |
static int |
| 367 |
inq_needpin (void *opaque, const char *line) |
| 368 |
@@ -628,7 +628,7 @@ inq_needpin (void *opaque, const char *line) |
| 369 |
line += 7; |
| 370 |
while (*line == ' ') |
| 371 |
line++; |
| 372 |
- |
| 373 |
+ |
| 374 |
pinlen = 90; |
| 375 |
pin = xtrymalloc_secure (pinlen); |
| 376 |
if (!pin) |
| 377 |
@@ -654,7 +654,7 @@ inq_needpin (void *opaque, const char *line) |
| 378 |
line += 17; |
| 379 |
while (*line == ' ') |
| 380 |
line++; |
| 381 |
- |
| 382 |
+ |
| 383 |
rc = parm->getpin_cb (parm->getpin_cb_arg, line, NULL, 1); |
| 384 |
} |
| 385 |
else if (!strncmp (line, "DISMISSPINPADPROMPT", 19) |
| 386 |
@@ -688,11 +688,12 @@ inq_needpin (void *opaque, const char *line) |
| 387 |
the PIN, GETPIN_CB_ARG is passed as opaque argument to |
| 388 |
GETPIN_CB. INDATA/INDATALEN is the input for the signature |
| 389 |
function. The signature created is written into newly allocated |
| 390 |
- memory in *R_BUF, *R_BUFLEN will hold the length of the |
| 391 |
+ memory in *R_BUF, *S_BUF, *R_BUFLEN, S_BUFLEN will hold the length of the |
| 392 |
signature. */ |
| 393 |
gpg_error_t |
| 394 |
scd_pksign (scd_context_t ctx, |
| 395 |
const char *keyid, |
| 396 |
+ key_types key_type, |
| 397 |
const unsigned char *indata, size_t indatalen, |
| 398 |
unsigned char **r_buf, size_t *r_buflen) |
| 399 |
{ |
| 400 |
@@ -703,6 +704,7 @@ scd_pksign (scd_context_t ctx, |
| 401 |
size_t len; |
| 402 |
unsigned char *sigbuf; |
| 403 |
size_t sigbuflen; |
| 404 |
+ const char * hashAlgo; |
| 405 |
|
| 406 |
*r_buf = NULL; |
| 407 |
*r_buflen = 0; |
| 408 |
@@ -735,9 +737,25 @@ scd_pksign (scd_context_t ctx, |
| 409 |
inqparm.getpin_cb = ctx->pincb; |
| 410 |
inqparm.getpin_cb_arg = ctx->pincb_cookie; |
| 411 |
|
| 412 |
- /* Go, sign it. */ |
| 413 |
|
| 414 |
- snprintf (line, DIM(line)-1, "PKSIGN %s", keyid); |
| 415 |
+ //set hash type based on |
| 416 |
+ switch (key_type) |
| 417 |
+ { |
| 418 |
+ case kType_rsa: |
| 419 |
+ hashAlgo = "--hash=sha256"; |
| 420 |
+ break; |
| 421 |
+ |
| 422 |
+ case kType_ecc_Ed25519: |
| 423 |
+ hashAlgo = "";//default is sha512, setting that here causes scd to generate an invalid SIG |
| 424 |
+ break; |
| 425 |
+ |
| 426 |
+ default: |
| 427 |
+ rc = -1; |
| 428 |
+ goto out; |
| 429 |
+ }//switch |
| 430 |
+ |
| 431 |
+ /* Go, sign it. */ |
| 432 |
+ snprintf (line, DIM(line)-1, "PKSIGN %s %s",hashAlgo, keyid); |
| 433 |
line[DIM(line)-1] = 0; |
| 434 |
rc = assuan_transact (ctx->assuan_ctx, line, |
| 435 |
membuf_data_cb, &data, |
| 436 |
@@ -760,7 +778,7 @@ scd_pksign (scd_context_t ctx, |
| 437 |
} |
| 438 |
|
| 439 |
memcpy (p, sigbuf, sigbuflen); |
| 440 |
- |
| 441 |
+ |
| 442 |
out: |
| 443 |
|
| 444 |
xfree (get_membuf (&data, &len)); |
| 445 |
@@ -816,7 +834,7 @@ scd_readkey (scd_context_t ctx, |
| 446 |
out: |
| 447 |
|
| 448 |
xfree (buffer); |
| 449 |
- |
| 450 |
+ |
| 451 |
return rc; |
| 452 |
} |
| 453 |
|
| 454 |
diff --git a/src/scd/scd.h b/src/scd/scd.h |
| 455 |
index 8910497..f85c751 100644 |
| 456 |
--- a/src/scd/scd.h |
| 457 |
+++ b/src/scd/scd.h |
| 458 |
@@ -1,18 +1,18 @@ |
| 459 |
/* scd.h - Interface to Scdaemon |
| 460 |
- Copyright (C) 2007, 2008, 2009 g10code GmbH. |
| 461 |
+ Copyright (C) 2007, 2008, 2009 g10code GmbH. |
| 462 |
|
| 463 |
This file is part of Poldi. |
| 464 |
- |
| 465 |
+ |
| 466 |
Poldi is free software; you can redistribute it and/or modify it |
| 467 |
under the terms of the GNU General Public License as published by |
| 468 |
the Free Software Foundation; either version 3 of the License, or |
| 469 |
(at your option) any later version. |
| 470 |
- |
| 471 |
+ |
| 472 |
Poldi is distributed in the hope that it will be useful, but |
| 473 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 474 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 475 |
General Public License for more details. |
| 476 |
- |
| 477 |
+ |
| 478 |
You should have received a copy of the GNU General Public License |
| 479 |
along with this program; if not, see |
| 480 |
<http://www.gnu.org/licenses/>. */ |
| 481 |
@@ -23,6 +23,7 @@ |
| 482 |
#include <poldi.h> |
| 483 |
|
| 484 |
#include "util/simplelog.h" |
| 485 |
+#include "util/key-types.h" |
| 486 |
|
| 487 |
struct scd_context; |
| 488 |
|
| 489 |
@@ -81,6 +82,7 @@ void scd_release_cardinfo (struct scd_cardinfo cardinfo); |
| 490 |
*R_BUF, *R_BUFLEN will hold the length of the signature. */ |
| 491 |
gpg_error_t scd_pksign (scd_context_t ctx, |
| 492 |
const char *keyid, |
| 493 |
+ key_types key_type, |
| 494 |
const unsigned char *indata, size_t indatalen, |
| 495 |
unsigned char **r_buf, size_t *r_buflen); |
| 496 |
|
| 497 |
diff --git a/src/util/Makefile.am b/src/util/Makefile.am |
| 498 |
index 72cf95e..6f2e93d 100644 |
| 499 |
--- a/src/util/Makefile.am |
| 500 |
+++ b/src/util/Makefile.am |
| 501 |
@@ -11,7 +11,7 @@ |
| 502 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 503 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 504 |
# License for more details. |
| 505 |
-# |
| 506 |
+# |
| 507 |
# You should have received a copy of the GNU General Public License |
| 508 |
# along with this program; if not, write to the Free Software |
| 509 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 510 |
@@ -31,7 +31,9 @@ poldi_util_SOURCES = \ |
| 511 |
convert.c \ |
| 512 |
simplelog.c simplelog.h \ |
| 513 |
simpleparse.c simpleparse.h \ |
| 514 |
- filenames.c filenames.h |
| 515 |
+ filenames.c filenames.h \ |
| 516 |
+ key-types.c key-types.h \ |
| 517 |
+ debugTools.c debugTools.h |
| 518 |
|
| 519 |
poldi_util_CFLAGS = \ |
| 520 |
-Wall \ |
| 521 |
diff --git a/src/util/debugTools.c b/src/util/debugTools.c |
| 522 |
new file mode 100644 |
| 523 |
index 0000000..6269909 |
| 524 |
--- /dev/null |
| 525 |
+++ b/src/util/debugTools.c |
| 526 |
@@ -0,0 +1,95 @@ |
| 527 |
+#include "debugTools.h" |
| 528 |
+#include <string.h> |
| 529 |
+ |
| 530 |
+void sprintSEXP_Ed25519(gcry_sexp_t in, char *rt, size_t strSize) |
| 531 |
+{ |
| 532 |
+ size_t rsaBuff_n; |
| 533 |
+ char *rsaBuff; |
| 534 |
+ char btmpStr[10]; |
| 535 |
+ char tmpStr[10]; |
| 536 |
+ |
| 537 |
+ //allocate buffer memory |
| 538 |
+ rsaBuff_n = gcry_sexp_sprint(in, GCRYSEXP_FMT_CANON, NULL, 0); |
| 539 |
+ rsaBuff = calloc(1, rsaBuff_n); |
| 540 |
+ if(!rsaBuff){printf("Error Allocating Dynamic Memory\n");} |
| 541 |
+ //printf("Buffer Size: %zu\n", rsaBuff_n); |
| 542 |
+ gcry_sexp_sprint(in, GCRYSEXP_FMT_CANON, rsaBuff, rsaBuff_n); |
| 543 |
+ |
| 544 |
+ int k = 0; |
| 545 |
+ char strByteSize[10]; |
| 546 |
+ int byteSize = 0; |
| 547 |
+ int val; |
| 548 |
+ |
| 549 |
+ for(int i=0; i != rsaBuff_n; i++) { |
| 550 |
+ if(rsaBuff[i] == '1') |
| 551 |
+ { |
| 552 |
+ k = i + 1; |
| 553 |
+ strByteSize[0] = 0; |
| 554 |
+ byteSize = 0; |
| 555 |
+ |
| 556 |
+ if(k <= rsaBuff_n) |
| 557 |
+ { |
| 558 |
+ if(rsaBuff[k] == ':') |
| 559 |
+ { |
| 560 |
+ //read 1 |
| 561 |
+ addCToStr(rsaBuff[i], rt, strSize); |
| 562 |
+ i++; |
| 563 |
+ |
| 564 |
+ //read : |
| 565 |
+ addCToStr(rsaBuff[i], rt, strSize); |
| 566 |
+ i++; |
| 567 |
+ |
| 568 |
+ //read control char |
| 569 |
+ addCToStr(rsaBuff[i], rt, strSize); |
| 570 |
+ i++; |
| 571 |
+ |
| 572 |
+ //read in byte size : |
| 573 |
+ while(rsaBuff[i] != ':') |
| 574 |
+ { |
| 575 |
+ addCToStr(rsaBuff[i], strByteSize, 10); |
| 576 |
+ addCToStr(rsaBuff[i], rt, strSize); |
| 577 |
+ i++; |
| 578 |
+ }//while |
| 579 |
+ |
| 580 |
+ byteSize = atoi(strByteSize); |
| 581 |
+ |
| 582 |
+ //read in second : |
| 583 |
+ addCToStr(rsaBuff[i], rt, strSize); |
| 584 |
+ i++; |
| 585 |
+ |
| 586 |
+ //iterate through each byte |
| 587 |
+ for(int j=0; j != byteSize; j++) { |
| 588 |
+ |
| 589 |
+ val = (unsigned char)rsaBuff[i]; |
| 590 |
+ sprintf(tmpStr,"%X",val); |
| 591 |
+ |
| 592 |
+ //need traling zero |
| 593 |
+ if(strlen(tmpStr) < 2) { |
| 594 |
+ strcpy(btmpStr, tmpStr); |
| 595 |
+ |
| 596 |
+ tmpStr[0]='0'; |
| 597 |
+ tmpStr[1]=0; |
| 598 |
+ strcat(tmpStr,btmpStr); |
| 599 |
+ } |
| 600 |
+ strcat(rt, tmpStr); |
| 601 |
+ i++; |
| 602 |
+ }//for |
| 603 |
+ }//if |
| 604 |
+ }//if |
| 605 |
+ }//if key type |
| 606 |
+ |
| 607 |
+ addCToStr(rsaBuff[i], rt, strSize); |
| 608 |
+ }//for |
| 609 |
+}//sprintSEXP_Ed25519 |
| 610 |
+ |
| 611 |
+ |
| 612 |
+ |
| 613 |
+void addCToStr(char c, char *in, size_t maxStrLn) |
| 614 |
+{ |
| 615 |
+ int endOfStr = strlen(in); |
| 616 |
+ if(endOfStr+1 >= maxStrLn){return;} |
| 617 |
+ |
| 618 |
+ in[endOfStr] = c; |
| 619 |
+ endOfStr++; |
| 620 |
+ in[endOfStr] = 0; |
| 621 |
+} |
| 622 |
diff --git a/src/util/debugTools.h b/src/util/debugTools.h |
| 623 |
new file mode 100644 |
| 624 |
index 0000000..dd0d171 |
| 625 |
--- /dev/null |
| 626 |
+++ b/src/util/debugTools.h |
| 627 |
@@ -0,0 +1,8 @@ |
| 628 |
+#include <gcrypt.h> |
| 629 |
+#ifndef DEBUGTOOLS_H |
| 630 |
+#define DEBUGTOOLS_H |
| 631 |
+ |
| 632 |
+void sprintSEXP_Ed25519(gcry_sexp_t in, char *rt, size_t strSize); |
| 633 |
+void addCToStr(char c, char *in, size_t maxStrLn); |
| 634 |
+ |
| 635 |
+#endif |
| 636 |
diff --git a/src/util/key-types.c b/src/util/key-types.c |
| 637 |
new file mode 100644 |
| 638 |
index 0000000..31ad47b |
| 639 |
--- /dev/null |
| 640 |
+++ b/src/util/key-types.c |
| 641 |
@@ -0,0 +1,69 @@ |
| 642 |
+#include "key-types.h" |
| 643 |
+ |
| 644 |
+/* Lookup key type ex, rsa, ecc, returns 1 on error and 0 otherwise |
| 645 |
+ Currenly Only Supporting rsa and ed25519*/ |
| 646 |
+int get_key_type(key_types *key_type, gcry_sexp_t key) { |
| 647 |
+ int err = 0; |
| 648 |
+ size_t strCnt = 0; |
| 649 |
+ size_t maxBuffSize = 4098; |
| 650 |
+ char strbuff[maxBuffSize]; |
| 651 |
+ char *token; |
| 652 |
+ |
| 653 |
+ if(key == NULL) { |
| 654 |
+ return 1; |
| 655 |
+ }//if |
| 656 |
+ |
| 657 |
+ strCnt = gcry_sexp_sprint(key, GCRYSEXP_FMT_DEFAULT, strbuff, maxBuffSize); |
| 658 |
+ if(strCnt == 0) { |
| 659 |
+ return 1; |
| 660 |
+ }//if |
| 661 |
+ |
| 662 |
+ |
| 663 |
+ //parse key type from S Expression |
| 664 |
+ token = strtok(strbuff, "\n"); |
| 665 |
+ token = strtok(NULL, ":"); |
| 666 |
+ token = strtok(NULL, "\n"); |
| 667 |
+ |
| 668 |
+ //if rsa key |
| 669 |
+ err = strcmp(token, "rsa"); |
| 670 |
+ if(err == 0) |
| 671 |
+ { |
| 672 |
+ *key_type = kType_rsa; |
| 673 |
+ return 0; |
| 674 |
+ }//if |
| 675 |
+ |
| 676 |
+ //if ecc key |
| 677 |
+ err = strcmp(token, "ecc"); |
| 678 |
+ if(err == 0) |
| 679 |
+ { |
| 680 |
+ //get flag type |
| 681 |
+ token = strtok(NULL, "\n"); |
| 682 |
+ token = strtok(NULL, ":"); |
| 683 |
+ token = strtok(NULL, ":"); |
| 684 |
+ token = strtok(NULL, ")"); |
| 685 |
+ |
| 686 |
+ err = strcmp(token, "eddsa"); |
| 687 |
+ if(err == 0) |
| 688 |
+ { |
| 689 |
+ *key_type = kType_ecc_Ed25519; |
| 690 |
+ return 0; |
| 691 |
+ }//if |
| 692 |
+ |
| 693 |
+ }//if |
| 694 |
+ |
| 695 |
+ |
| 696 |
+ return 1; |
| 697 |
+}//key_type |
| 698 |
+ |
| 699 |
+/* Returns the String Value of the key type |
| 700 |
+ Returns Empty String on error*/ |
| 701 |
+const char* key_type_to_str(key_types key_type) |
| 702 |
+{ |
| 703 |
+ switch (key_type) |
| 704 |
+ { |
| 705 |
+ case kType_rsa: return "rsa"; |
| 706 |
+ case kType_ecc_Ed25519: return "Ed25519"; |
| 707 |
+ } |
| 708 |
+ |
| 709 |
+ return ""; |
| 710 |
+} |
| 711 |
diff --git a/src/util/key-types.h b/src/util/key-types.h |
| 712 |
new file mode 100644 |
| 713 |
index 0000000..8b30e5e |
| 714 |
--- /dev/null |
| 715 |
+++ b/src/util/key-types.h |
| 716 |
@@ -0,0 +1,15 @@ |
| 717 |
+ |
| 718 |
+#include <gcrypt.h> |
| 719 |
+ |
| 720 |
+#ifndef KEY_TYPES_H |
| 721 |
+#define KEY_TYPES_H |
| 722 |
+ |
| 723 |
+typedef enum{kType_rsa, kType_ecc_Ed25519} key_types; |
| 724 |
+ |
| 725 |
+/* Get Key Type*/ |
| 726 |
+int get_key_type(key_types *key_type, gcry_sexp_t key); |
| 727 |
+ |
| 728 |
+/* returns key type string value*/ |
| 729 |
+const char* key_type_to_str(key_types key_type); |
| 730 |
+ |
| 731 |
+#endif |
| 732 |
diff --git a/src/util/support.c b/src/util/support.c |
| 733 |
index 8e576c6..3e7c358 100644 |
| 734 |
--- a/src/util/support.c |
| 735 |
+++ b/src/util/support.c |
| 736 |
@@ -1,18 +1,18 @@ |
| 737 |
/* support.c - PAM authentication via OpenPGP smartcards. |
| 738 |
Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH |
| 739 |
- |
| 740 |
+ |
| 741 |
This file is part of Poldi. |
| 742 |
- |
| 743 |
+ |
| 744 |
Poldi is free software; you can redistribute it and/or modify it |
| 745 |
under the terms of the GNU General Public License as published by |
| 746 |
the Free Software Foundation; either version 2 of the License, or |
| 747 |
(at your option) any later version. |
| 748 |
- |
| 749 |
+ |
| 750 |
Poldi is distributed in the hope that it will be useful, but |
| 751 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 752 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 753 |
General Public License for more details. |
| 754 |
- |
| 755 |
+ |
| 756 |
You should have received a copy of the GNU General Public License |
| 757 |
along with this program; if not, write to the Free Software |
| 758 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 759 |
@@ -38,7 +38,7 @@ |
| 760 |
#include "support.h" |
| 761 |
#include "defs.h" |
| 762 |
|
| 763 |
-#define CHALLENGE_MD_ALGORITHM GCRY_MD_SHA1 |
| 764 |
+ |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
@@ -50,11 +50,23 @@ |
| 769 |
it's length in bytes is to be stored in *CHALLENGE_N. Returns |
| 770 |
proper error code. */ |
| 771 |
gpg_error_t |
| 772 |
-challenge_generate (unsigned char **challenge, size_t *challenge_n) |
| 773 |
+challenge_generate (unsigned char **challenge, size_t *challenge_n, key_types key_type) |
| 774 |
{ |
| 775 |
gpg_error_t err = GPG_ERR_NO_ERROR; |
| 776 |
unsigned char *challenge_new = NULL; |
| 777 |
- size_t challenge_new_n = gcry_md_get_algo_dlen (CHALLENGE_MD_ALGORITHM); |
| 778 |
+ size_t challenge_new_n = 0; //gcry_md_get_algo_dlen (CHALLENGE_MD_ALGORITHM); |
| 779 |
+ |
| 780 |
+ //determine challange size based on hashing algorithm |
| 781 |
+ switch (key_type) |
| 782 |
+ { |
| 783 |
+ case kType_rsa: |
| 784 |
+ challenge_new_n = gcry_md_get_algo_dlen (GCRY_MD_SHA256); |
| 785 |
+ break; |
| 786 |
+ |
| 787 |
+ case kType_ecc_Ed25519: |
| 788 |
+ challenge_new_n = gcry_md_get_algo_dlen (GCRY_MD_SHA512); |
| 789 |
+ break; |
| 790 |
+ }//switch |
| 791 |
|
| 792 |
challenge_new = xtrymalloc (challenge_new_n); |
| 793 |
if (! challenge_new) |
| 794 |
@@ -79,31 +91,58 @@ challenge_release (unsigned char *challenge) |
| 795 |
} |
| 796 |
|
| 797 |
static gpg_error_t |
| 798 |
-challenge_verify_sexp (gcry_sexp_t sexp_key, |
| 799 |
+challenge_verify_sexp (gcry_sexp_t sexp_key, key_types key_type, |
| 800 |
unsigned char *challenge, size_t challenge_n, |
| 801 |
unsigned char *response, size_t response_n) |
| 802 |
{ |
| 803 |
gpg_error_t err = GPG_ERR_NO_ERROR; |
| 804 |
gcry_sexp_t sexp_signature = NULL; |
| 805 |
gcry_sexp_t sexp_data = NULL; |
| 806 |
- gcry_mpi_t mpi_signature = NULL; |
| 807 |
|
| 808 |
- /* Convert buffers into MPIs. */ |
| 809 |
- if (! err) |
| 810 |
+ /* Create according S-Expressions. */ |
| 811 |
+ if (! err) { |
| 812 |
+ //set data hash type based on key type |
| 813 |
+ switch (key_type) |
| 814 |
{ |
| 815 |
- if (gcry_mpi_scan (&mpi_signature, GCRYMPI_FMT_USG, response, response_n, |
| 816 |
- NULL)) |
| 817 |
- err = gpg_error (GPG_ERR_BAD_MPI); |
| 818 |
- } |
| 819 |
+ case kType_rsa: |
| 820 |
+ err = gcry_sexp_build (&sexp_data, NULL, |
| 821 |
+ "(data (flags pkcs1) (hash sha256 %b))", |
| 822 |
+ challenge_n, challenge); |
| 823 |
+ break; |
| 824 |
+ |
| 825 |
+ case kType_ecc_Ed25519: |
| 826 |
+ err = gcry_sexp_build (&sexp_data, NULL, |
| 827 |
+ "(data(flags eddsa)(hash-algo sha512)(value %b))", |
| 828 |
+ challenge_n, challenge); |
| 829 |
+ break; |
| 830 |
+ |
| 831 |
+ default: |
| 832 |
+ err = GPG_ERR_CONFIGURATION; |
| 833 |
+ }//switch |
| 834 |
+ |
| 835 |
+ |
| 836 |
+ } |
| 837 |
+ |
| 838 |
+ if (! err) { |
| 839 |
+ //set sig value based on key type key type |
| 840 |
+ switch (key_type) |
| 841 |
+ { |
| 842 |
+ case kType_rsa: |
| 843 |
+ err = gcry_sexp_build (&sexp_signature, NULL, "(sig-val(rsa(s%b)))", |
| 844 |
+ response_n,response); |
| 845 |
+ break; |
| 846 |
+ |
| 847 |
+ case kType_ecc_Ed25519: |
| 848 |
+ err = gcry_sexp_build (&sexp_signature, NULL, "(sig-val(eddsa(r%b)(s%b)))", |
| 849 |
+ response_n/2, response, |
| 850 |
+ response_n/2, response + response_n/2); |
| 851 |
+ break; |
| 852 |
+ |
| 853 |
+ default: |
| 854 |
+ err = GPG_ERR_CONFIGURATION; |
| 855 |
+ }//switch |
| 856 |
|
| 857 |
- /* Create according S-Expressions. */ |
| 858 |
- if (! err) |
| 859 |
- err = gcry_sexp_build (&sexp_data, NULL, |
| 860 |
- "(data (flags pkcs1) (hash sha1 %b))", |
| 861 |
- challenge_n, challenge); |
| 862 |
- if (! err) |
| 863 |
- err = gcry_sexp_build (&sexp_signature, NULL, "(sig-val (rsa (s %m)))", |
| 864 |
- mpi_signature); |
| 865 |
+ } |
| 866 |
|
| 867 |
/* Verify. */ |
| 868 |
if (! err) |
| 869 |
@@ -113,8 +152,6 @@ challenge_verify_sexp (gcry_sexp_t sexp_key, |
| 870 |
gcry_sexp_release (sexp_data); |
| 871 |
if (sexp_signature) |
| 872 |
gcry_sexp_release (sexp_signature); |
| 873 |
- if (mpi_signature) |
| 874 |
- gcry_mpi_release (mpi_signature); |
| 875 |
|
| 876 |
return err; |
| 877 |
} |
| 878 |
@@ -125,13 +162,13 @@ challenge_verify_sexp (gcry_sexp_t sexp_key, |
| 879 |
the secret key belonging to the public key given as PUBLIC_KEY. |
| 880 |
Returns proper error code. */ |
| 881 |
gpg_error_t |
| 882 |
-challenge_verify (gcry_sexp_t public_key, |
| 883 |
+challenge_verify (gcry_sexp_t public_key, key_types key_type, |
| 884 |
unsigned char *challenge, size_t challenge_n, |
| 885 |
unsigned char *response, size_t response_n) |
| 886 |
{ |
| 887 |
gpg_error_t err; |
| 888 |
|
| 889 |
- err = challenge_verify_sexp (public_key, |
| 890 |
+ err = challenge_verify_sexp (public_key, key_type, |
| 891 |
challenge, challenge_n, response, response_n); |
| 892 |
|
| 893 |
return err; |
| 894 |
@@ -186,7 +223,7 @@ sexp_to_string (gcry_sexp_t sexp, char **sexp_string) |
| 895 |
|
| 896 |
*sexp_string = buffer; |
| 897 |
err = 0; |
| 898 |
- |
| 899 |
+ |
| 900 |
out: |
| 901 |
|
| 902 |
if (err) |
| 903 |
@@ -372,7 +409,7 @@ int |
| 904 |
my_strlen (const char *s) |
| 905 |
{ |
| 906 |
int ret = 0; |
| 907 |
- |
| 908 |
+ |
| 909 |
while (*s) |
| 910 |
{ |
| 911 |
if (ret == INT_MAX) |
| 912 |
diff --git a/src/util/support.h b/src/util/support.h |
| 913 |
index e25cf01..c64f751 100644 |
| 914 |
--- a/src/util/support.h |
| 915 |
+++ b/src/util/support.h |
| 916 |
@@ -1,18 +1,18 @@ |
| 917 |
/* support.h - PAM authentication via OpenPGP smartcards. |
| 918 |
Copyright (C) 2004, 2005, 2007, 2008 g10 Code GmbH |
| 919 |
- |
| 920 |
+ |
| 921 |
This file is part of Poldi. |
| 922 |
- |
| 923 |
+ |
| 924 |
Poldi is free software; you can redistribute it and/or modify it |
| 925 |
under the terms of the GNU General Public License as published by |
| 926 |
the Free Software Foundation; either version 2 of the License, or |
| 927 |
(at your option) any later version. |
| 928 |
- |
| 929 |
+ |
| 930 |
Poldi is distributed in the hope that it will be useful, but |
| 931 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 932 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 933 |
General Public License for more details. |
| 934 |
- |
| 935 |
+ |
| 936 |
You should have received a copy of the GNU Lesser General Public |
| 937 |
License along with this program; if not, write to the Free Software |
| 938 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 939 |
@@ -23,12 +23,12 @@ |
| 940 |
|
| 941 |
#include <gcrypt.h> |
| 942 |
#include <dirent.h> |
| 943 |
- |
| 944 |
+#include "key-types.h" |
| 945 |
/* This function generates a challenge; the challenge will be stored |
| 946 |
in newly allocated memory, which is to be stored in *CHALLENGE; |
| 947 |
it's length in bytes is to be stored in *CHALLENGE_N. Returns |
| 948 |
proper error code. */ |
| 949 |
-gpg_error_t challenge_generate (unsigned char **challenge, size_t *challenge_n); |
| 950 |
+gpg_error_t challenge_generate (unsigned char **challenge, size_t *challenge_n, key_types key_type); |
| 951 |
|
| 952 |
/* Releases the challenge contained in CHALLENGE generated by |
| 953 |
challenge_generate(). */ |
| 954 |
@@ -39,7 +39,7 @@ void challenge_release (unsigned char *challenge); |
| 955 |
challenge given in CHALLENGE of size CHALLENGE_N (in bytes) with |
| 956 |
the secret key belonging to the public key given as PUBLIC_KEY. |
| 957 |
Returns proper error code. */ |
| 958 |
-gpg_error_t challenge_verify (gcry_sexp_t public_key, |
| 959 |
+gpg_error_t challenge_verify (gcry_sexp_t public_key, key_types key_type, |
| 960 |
unsigned char *challenge, size_t challenge_n, |
| 961 |
unsigned char *response, size_t response_n); |
| 962 |
|