void pki_multi::fromPEM_BIO(BIO *bio, QString name) { QString text; pki_base *item = NULL; char buf[BUFLEN]; int len, startpos; for (;;) { try { int pos = BIO_tell(bio); len = BIO_read(bio, buf, BUFLEN-1); buf[len] = '\0'; text = buf; item = pkiByPEM(text, &startpos); if (!item) { if (startpos <= 0) break; if (BIO_seek(bio, pos + startpos) == -1) throw errorEx(tr("Seek failed")); continue; } pos += startpos; if (BIO_seek(bio, pos) == -1) throw errorEx(tr("Seek failed")); item->fromPEM_BIO(bio, name); if (pos == BIO_tell(bio)) { /* No progress, do it manually */ if (BIO_seek(bio, pos + 1)) throw errorEx(tr("Seek failed")); printf("Could not load: %s\n", CCHAR(item->getClassName())); delete item; continue; } openssl_error(); multi.append(item); } catch (errorEx &err) { MainWindow::Error(err); if (item) delete item; item = NULL; } } if (multi.size() == 0) throw errorEx(tr("No known PEM encoded items found")); }
void pki_evp::fromPEM_BIO(BIO *bio, QString name) { EVP_PKEY *pkey; int pos; pass_info p(XCA_TITLE, QObject::tr( "Please enter the password to decrypt the private key.")); pos = BIO_tell(bio); pkey = PEM_read_bio_PrivateKey(bio, NULL, MainWindow::passRead, &p); if (!pkey){ pki_ign_openssl_error(); pos = BIO_seek(bio, pos); pkey = PEM_read_bio_PUBKEY(bio, NULL, MainWindow::passRead, &p); } if (pkey){ if (key) EVP_PKEY_free(key); key = pkey; if (EVP_PKEY_isPrivKey(key)) bogusEncryptKey(); setIntName(rmslashdot(name)); } openssl_error(name); }