Added OpenPGP library to lib/silcpgp
[crypto.git] / lib / silccrypt / silcpk.c
index 89ec48450153d45adf9d8578b3ca8033e1cbbf6e..b96cb3e9a12e26e71b3e0e6b117ced6bd81bab18 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2007 Pekka Riikonen
+  Copyright (C) 1997 - 2008 Pekka Riikonen
 
   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
@@ -17,7 +17,7 @@
 
 */
 
-#include "silc.h"
+#include "silccrypto.h"
 #include "silcpk_i.h"
 
 /****************************** Key generation *******************************/
@@ -126,7 +126,7 @@ SilcBool silc_pkcs_silc_decode_identifier(const char *identifier,
   int len;
 
   /* Protocol says that at least UN and HN must be provided as identifier */
-  if (!strstr(identifier, "UN=") && !strstr(identifier, "HN=")) {
+  if (!strstr(identifier, "UN=") || !strstr(identifier, "HN=")) {
     SILC_LOG_DEBUG(("The public does not have the required UN= and HN= "
                    "identifiers"));
     return FALSE;
@@ -207,8 +207,10 @@ char *silc_pkcs_silc_encode_identifier(SilcStack stack,
   SilcBufferStruct buf;
   char *identifier;
 
-  if (!username || !host)
+  if (!username || !host) {
+    SILC_LOG_ERROR(("Public key identifier is missing UN and/or HN"));
     return NULL;
+  }
   if (strlen(username) < 1 || strlen(host) < 1)
     return NULL;
 
@@ -264,6 +266,7 @@ char *silc_pkcs_silc_encode_identifier(SilcStack stack,
   if (version) {
     if (strlen(version) > 1 || !isdigit(version[0])) {
       silc_buffer_spurge(stack, &buf);
+      SILC_LOG_ERROR(("Public key identifier has invalid version (V)"));
       return NULL;
     }
     silc_buffer_sformat(stack, &buf,
@@ -962,7 +965,7 @@ SILC_PKCS_IMPORT_PRIVATE_KEY_FILE(silc_pkcs_silc_import_private_key_file)
   silc_cipher_free(aes);
 
   /* Import the private key */
-  ret = silc_pkcs_silc_import_private_key(pkcs, NULL, filedata,
+  ret = silc_pkcs_silc_import_private_key(pkcs, NULL, NULL, 0, filedata,
                                          len, ret_private_key, ret_alg);
 
   silc_free(data);