src/lib/crypto.c
int crypto_keypair_load_cert(X509_KEYPAIR *keypair, const char *file)
{
   BIO *bio;
   X509 *cert;

   /* Open the file */
   if (!(bio = BIO_new_file(file, "r"))) {
      openssl_post_errors(M_ERROR, _("Unable to open certificate file"));
      return false;
   }

   cert = PEM_read_bio_X509(bio, NULL, NULL, NULL);
   BIO_free(bio);
   if (!cert) {
      openssl_post_errors(M_ERROR, _("Unable to read certificate from file"));
      return false;
   }

   /* Extract the public key */
   if (!(keypair->pubkey = X509_get_pubkey(cert))) {
      openssl_post_errors(M_ERROR, _("Unable to extract public key from certificate"));
      goto err;
   }

   /* Extract the subjectKeyIdentifier extension field */
   if ((keypair->keyid = openssl_cert_keyid(cert)) == NULL) {
      Jmsg0(NULL, M_ERROR, 0,
         _("Provided certificate does not include the required subjectKeyIdentifier extension."));
      goto err;
   }

   /* Validate the public key type (only RSA is supported) */
   if (EVP_PKEY_base_id(keypair->pubkey) != EVP_PKEY_RSA) {
       Jmsg1(NULL, M_ERROR, 0,
             _("Unsupported key type provided: %d\n"), EVP_PKEY_id(keypair->pubkey));
       goto err;
   }

   X509_free(cert);
   return true;

err:
   X509_free(cert);
   if (keypair->pubkey) {
      EVP_PKEY_free(keypair->pubkey);
   }
   return false;
}
/*
 * Load a public key from a PEM-encoded x509 certificate.
 *  Returns: true on success
 *           false on failure
 */
Load a public key from a PEM-encoded x509 certificate.
Returns: true on success
false on failure
Load a public key from a PEM - encoded x509 certificate . Returns : true on success false on failure
int crypto_keypair_load_cert(X509_KEYPAIR *keypair, const char *file)
{
   BIO *bio;
   X509 *cert;
   if (!(bio = BIO_new_file(file, "r"))) {
      openssl_post_errors(M_ERROR, _("Unable to open certificate file"));
      return false;
   }
   cert = PEM_read_bio_X509(bio, NULL, NULL, NULL);
   BIO_free(bio);
   if (!cert) {
      openssl_post_errors(M_ERROR, _("Unable to read certificate from file"));
      return false;
   }
   if (!(keypair->pubkey = X509_get_pubkey(cert))) {
      openssl_post_errors(M_ERROR, _("Unable to extract public key from certificate"));
      goto err;
   }
   if ((keypair->keyid = openssl_cert_keyid(cert)) == NULL) {
      Jmsg0(NULL, M_ERROR, 0,
         _("Provided certificate does not include the required subjectKeyIdentifier extension."));
      goto err;
   }
   if (EVP_PKEY_base_id(keypair->pubkey) != EVP_PKEY_RSA) {
       Jmsg1(NULL, M_ERROR, 0,
             _("Unsupported key type provided: %d\n"), EVP_PKEY_id(keypair->pubkey));
       goto err;
   }
   X509_free(cert);
   return true;
err:
   X509_free(cert);
   if (keypair->pubkey) {
      EVP_PKEY_free(keypair->pubkey);
   }
   return false;
}
int crypto_keypair_load_cert ( X509_KEYPAIR * keypair , const char * file ) { BIO * bio ; X509 * cert ; if ( ! ( bio = BIO_new_file ( file , " " ) ) ) { openssl_post_errors ( M_ERROR , _ ( " " ) ) ; return false ; } cert = PEM_read_bio_X509 ( bio , NULL , NULL , NULL ) ; BIO_free ( bio ) ; if ( ! cert ) { openssl_post_errors ( M_ERROR , _ ( " " ) ) ; return false ; } if ( ! ( keypair -> pubkey = X509_get_pubkey ( cert ) ) ) { openssl_post_errors ( M_ERROR , _ ( " " ) ) ; goto err ; } if ( ( keypair -> keyid = openssl_cert_keyid ( cert ) ) == NULL ) { Jmsg0 ( NULL , M_ERROR , 0 , _ ( " " ) ) ; goto err ; } if ( EVP_PKEY_base_id ( keypair -> pubkey ) != EVP_PKEY_RSA ) { Jmsg1 ( NULL , M_ERROR , 0 , _ ( " \n " ) , EVP_PKEY_id ( keypair -> pubkey ) ) ; goto err ; } X509_free ( cert ) ; return true ; err : X509_free ( cert ) ; if ( keypair -> pubkey ) { EVP_PKEY_free ( keypair -> pubkey ) ; } return false ; }
Load a public key from a PEM-encoded x509 certificate.
Load a public key from a PEM - encoded x509 certificate .
/* Open the file */ /* Extract the public key */ /* Extract the subjectKeyIdentifier extension field */ /* Validate the public key type (only RSA is supported) */