-
Notifications
You must be signed in to change notification settings - Fork 5
QX509Store
BrutalWizard edited this page Sep 23, 2020
·
4 revisions
Example:
#include <QByteArray>
#include "QX509Store.h"
#include "QX509.h"
int main() {
/* Load CA certificate */
QSimpleCrypto::QX509 x509;
X509* caCertificate = x509_lib.loadCertificateFromFile("CAcert.pem");
/* Initialize QX509Store */
QSimpleCrypto::QX509Store store;
X509_STORE* store = X509_STORE_new();
/* Set up X509_STORE */
store.addLookup(store, X509_LOOKUP_file());
store.addCertificateToStore(store, x509);
store.setDepth(store, 0);
store.setFlag(store, X509_V_FLAG_CRL_CHECK);
store.setPurpose(store, X509_PURPOSE_ANY);
store.setTrust(store, X509_TRUST_SSL_SERVER);
store.setDefaultPaths(store);
/* Load certificate file */
QFile certFile("Path/To/File/CAcert.pem");
store.loadLocations(store, certFile);
/* Free memory */
X509_free(caCertificate);
X509_STORE_free(store);
}
bool addCertificateToStore(X509_STORE* store, X509* x509)
- store - OpenSSL X509_STORE
- x509 - OpenSSL X509
Returns true on success and false on failure.
bool addLookup(X509_STORE* store, X509_LOOKUP_METHOD* method)
- store - OpenSSL X509_STORE
- method - OpenSSL X509_LOOKUP_METHOD. Example: X509_LOOKUP_file
Returns true on success and false on failure.
bool setDepth(X509_STORE* store, const int& depth)
- store - OpenSSL X509_STORE
- depth - That is the maximum number of untrusted CA certificates that can appear in a chain. Example: 0
Returns true on success and false on failure.
bool setFlag(X509_STORE* store, const unsigned long& flag)
- store - OpenSSL X509_STORE
- flag - The verification flags consists of zero or more of the following flags ored together. Example: X509_V_FLAG_CRL_CHECK
Returns true on success and false on failure.
bool setPurpose(X509_STORE* store, const int& purpose)
- store - OpenSSL X509_STORE
- purpose - Verification purpose in param to purpose. Example: X509_PURPOSE_ANY
Returns true on success and false on failure.
bool setTrust(X509_STORE* store, const int& trust)
- store - OpenSSL X509_STORE
- trust - Trust Level. Example: X509_TRUST_SSL_SERVER
Returns true on success and false on failure.
bool setDefaultPaths(X509_STORE* store)
- store - OpenSSL X509_STORE
Returns true on success and false on failure.
bool loadLocations(X509_STORE* store, const QByteArray& fileName, const QByteArray& dirPath)
- store - OpenSSL X509_STORE
- fileName - File name. Example: "caCertificate.pem"
- dirPath - Path to file. Example: "path/To/File"
Returns true on success and false on failure.
bool loadLocations(X509_STORE* store, const QFile& file)
- store - OpenSSL X509_STORE
- file - Qt QFile
Returns true on success and false on failure.
bool loadLocations(X509_STORE* store, const QFileInfo& fileInfo)
- store - OpenSSL X509_STORE
- fileInfo - Qt QFileInfo
Returns true on success and false on failure.