src/lib/crypto.c
bool crypto_keypair_has_key(const char *file) {
   BIO *bio;
   char *name = NULL;
   char *header = NULL;
   unsigned char *data = NULL;
   bool retval = false;
   long len;

   if (!(bio = BIO_new_file(file, "r"))) {
      openssl_post_errors(M_ERROR, _("Unable to open private key file"));
      return false;
   }

   while (PEM_read_bio(bio, &name, &header, &data, &len)) {
      /* We don't care what the data is, just that it's there */
      OPENSSL_free(header);
      OPENSSL_free(data);

      /*
       * PEM Header Found, check for a private key
       * Due to OpenSSL limitations, we must specifically
       * list supported PEM private key encodings.
       */
      if (strcmp(name, PEM_STRING_RSA) == 0
            || strcmp(name, PEM_STRING_DSA) == 0
            || strcmp(name, PEM_STRING_PKCS8) == 0
            || strcmp(name, PEM_STRING_PKCS8INF) == 0) {
         retval = true;
         OPENSSL_free(name);
         break;
      } else {
         OPENSSL_free(name);
      }
   }

   /* Free our bio */
   BIO_free(bio);

   /* Post PEM-decoding error messages, if any */
   openssl_post_errors(M_ERROR, _("Unable to read private key from file"));
   return retval;
}
/*
 * Check a PEM-encoded file
 * for the existence of a private key.
 * Returns: true if a private key is found
 *          false otherwise
 */
Check a PEM-encoded file
for the existence of a private key.
Returns: true if a private key is found
false otherwise
Check a PEM - encoded file for the existence of a private key . Returns : true if a private key is found false otherwise
bool crypto_keypair_has_key(const char *file) {
   BIO *bio;
   char *name = NULL;
   char *header = NULL;
   unsigned char *data = NULL;
   bool retval = false;
   long len;
   if (!(bio = BIO_new_file(file, "r"))) {
      openssl_post_errors(M_ERROR, _("Unable to open private key file"));
      return false;
   }
   while (PEM_read_bio(bio, &name, &header, &data, &len)) {
      OPENSSL_free(header);
      OPENSSL_free(data);
      if (strcmp(name, PEM_STRING_RSA) == 0
            || strcmp(name, PEM_STRING_DSA) == 0
            || strcmp(name, PEM_STRING_PKCS8) == 0
            || strcmp(name, PEM_STRING_PKCS8INF) == 0) {
         retval = true;
         OPENSSL_free(name);
         break;
      } else {
         OPENSSL_free(name);
      }
   }
   BIO_free(bio);
   openssl_post_errors(M_ERROR, _("Unable to read private key from file"));
   return retval;
}
bool crypto_keypair_has_key ( const char * file ) { BIO * bio ; char * name = NULL ; char * header = NULL ; unsigned char * data = NULL ; bool retval = false ; long len ; if ( ! ( bio = BIO_new_file ( file , " " ) ) ) { openssl_post_errors ( M_ERROR , _ ( " " ) ) ; return false ; } while ( PEM_read_bio ( bio , & name , & header , & data , & len ) ) { OPENSSL_free ( header ) ; OPENSSL_free ( data ) ; if ( strcmp ( name , PEM_STRING_RSA ) == 0 || strcmp ( name , PEM_STRING_DSA ) == 0 || strcmp ( name , PEM_STRING_PKCS8 ) == 0 || strcmp ( name , PEM_STRING_PKCS8INF ) == 0 ) { retval = true ; OPENSSL_free ( name ) ; break ; } else { OPENSSL_free ( name ) ; } } BIO_free ( bio ) ; openssl_post_errors ( M_ERROR , _ ( " " ) ) ; return retval ; }
Check a PEM-encoded file
 for the existence of a private key.
Check a PEM - encoded file for the existence of a private key .
/* We don't care what the data is, just that it's there */ /*
       * PEM Header Found, check for a private key
       * Due to OpenSSL limitations, we must specifically
       * list supported PEM private key encodings.
       */ /* Free our bio */ /* Post PEM-decoding error messages, if any */