API » History » Version 9
Felix Tiede, 09/08/2013 01:13 PM
API has been changed to use std::exception::what() as well as a serial constraint.
| 1 | 1 | Felix Tiede | h1. Public API |
|---|---|---|---|
| 2 | |||
| 3 | The real code is documented, of course. See header files in source:src. |
||
| 4 | For a history of how it was created, see ticket #34. |
||
| 5 | |||
| 6 | Regardless of the files the API is split into, in C++ it looks like this: |
||
| 7 | <pre><code class="cplusplus">namespace Kca |
||
| 8 | { |
||
| 9 | namespace OpenSSL |
||
| 10 | { |
||
| 11 | enum Digest { |
||
| 12 | RIPEMD160, |
||
| 13 | SHA1, |
||
| 14 | SHA256, |
||
| 15 | SHA384, |
||
| 16 | SHA512, |
||
| 17 | }; |
||
| 18 | |||
| 19 | enum RevocationReason { |
||
| 20 | Unspecified, |
||
| 21 | KeyCompromise, |
||
| 22 | CACompromise, |
||
| 23 | AffilitionChanged, |
||
| 24 | Superseded, |
||
| 25 | CessationOfOperation, |
||
| 26 | CertificateHold, |
||
| 27 | RemoveFromCRL = 8 |
||
| 28 | }; |
||
| 29 | |||
| 30 | |||
| 31 | 6 | Felix Tiede | class OpenSSLException : public std::exception |
| 32 | { |
||
| 33 | public: |
||
| 34 | ~OpenSSLException() throw(); |
||
| 35 | 5 | Felix Tiede | |
| 36 | 9 | Felix Tiede | const char * what() const throw(); |
| 37 | 6 | Felix Tiede | |
| 38 | protected: |
||
| 39 | OpenSSLException(const QString& message) throw(); |
||
| 40 | 1 | Felix Tiede | }; |
| 41 | |||
| 42 | |||
| 43 | class SigningException : public std::exception |
||
| 44 | { |
||
| 45 | public: |
||
| 46 | enum Operation { |
||
| 47 | SignCsr, |
||
| 48 | SignCrl, |
||
| 49 | }; |
||
| 50 | |||
| 51 | enum Failure { |
||
| 52 | NoCACertificate, |
||
| 53 | KeyMismatch, |
||
| 54 | 9 | Felix Tiede | SerialConstraint, |
| 55 | 1 | Felix Tiede | TimeConstraint, |
| 56 | ExtensionError, |
||
| 57 | ObjectError, |
||
| 58 | }; |
||
| 59 | |||
| 60 | ~SigningException() throw(); |
||
| 61 | |||
| 62 | const Operation operation() const throw(); |
||
| 63 | const Failure failure() const throw(); |
||
| 64 | 9 | Felix Tiede | const char * what() const throw(); |
| 65 | 1 | Felix Tiede | |
| 66 | protected: |
||
| 67 | SigningException(Operation operation, Failure failure, const QString& description) throw(); |
||
| 68 | |||
| 69 | void setFailure(Failure failure) throw(); |
||
| 70 | 9 | Felix Tiede | void setMessage(const QString& message) throw(); |
| 71 | 1 | Felix Tiede | }; |
| 72 | 6 | Felix Tiede | |
| 73 | |||
| 74 | class Extension { |
||
| 75 | public: |
||
| 76 | struct ObjectID { |
||
| 77 | QString oid; |
||
| 78 | QString shortName; |
||
| 79 | QString longName; |
||
| 80 | }; |
||
| 81 | |||
| 82 | Extension(const ObjectID& oid, const QString& value, |
||
| 83 | bool critical=false, bool replace=false); |
||
| 84 | ~Extension(); |
||
| 85 | |||
| 86 | const ObjectID oid() const; |
||
| 87 | |||
| 88 | const QString value() const; |
||
| 89 | void setValue(const QString& value); |
||
| 90 | |||
| 91 | bool critical() const; |
||
| 92 | void setCritical(bool critical); |
||
| 93 | |||
| 94 | bool replace() const; |
||
| 95 | void setReplace(bool replace); |
||
| 96 | |||
| 97 | bool operator==(const Extension& other) const; |
||
| 98 | Extension& operator=(const Extension& other); |
||
| 99 | |||
| 100 | protected: |
||
| 101 | Extension(const QString& name, const QString& value, |
||
| 102 | bool critical = false, bool replace = false) throw(OpenSSLException); |
||
| 103 | X509_EXTENSION* handle(X509V3_CTX* ctx = NULL) const throw(OpenSSLException); |
||
| 104 | }; |
||
| 105 | typedef QList< Extension > ExtensionList; |
||
| 106 | |||
| 107 | struct CRLEntry { |
||
| 108 | quint64 serial; |
||
| 109 | RevocationReason reason; |
||
| 110 | QDateTime timestamp; |
||
| 111 | }; |
||
| 112 | typedef QList< CRLEntry > CRL; |
||
| 113 | |||
| 114 | QString version(); |
||
| 115 | QString build_information(); |
||
| 116 | |||
| 117 | quint64 random(); |
||
| 118 | 8 | Felix Tiede | const QSslKey generateKeyPair(unsigned int length = 2048, QSsl::KeyAlgorithm algorithm = QSsl::Rsa); |
| 119 | 6 | Felix Tiede | const QByteArray generateRequest(const QSslKey& key, |
| 120 | const QString& subject, |
||
| 121 | const ExtensionList& extensions, |
||
| 122 | Digest digest = SHA256); |
||
| 123 | |||
| 124 | ExtensionList emailCertExtensions(); |
||
| 125 | |||
| 126 | QString requestSubject(const QByteArray& request); |
||
| 127 | ExtensionList requestExtensions(const QByteArray& request); |
||
| 128 | |||
| 129 | 1 | Felix Tiede | |
| 130 | |||
| 131 | class Certificate : public QSslCertificate |
||
| 132 | { |
||
| 133 | public: |
||
| 134 | struct SignatureDetails { |
||
| 135 | quint64 serial; |
||
| 136 | Digest digest; |
||
| 137 | QDateTime effectiveDate; |
||
| 138 | QDateTime expiryDate; |
||
| 139 | }; |
||
| 140 | |||
| 141 | Certificate(const QSslKey& key, const QString& subject, |
||
| 142 | const SignatureDetails& details, const ExtensionList& extensions) throw(SigningException); |
||
| 143 | |||
| 144 | bool isCA() const; |
||
| 145 | bool keyMatch(const QSslKey& key) const; |
||
| 146 | |||
| 147 | const QSslCertificate sign(const QByteArray& request, const QSslKey& signingKey, |
||
| 148 | const SignatureDetails& details, |
||
| 149 | const ExtensionList& extensions) const throw(SigningException); |
||
| 150 | |||
| 151 | const QByteArray sign(const CRL& crl, const QSslKey& signingKey, |
||
| 152 | const SignatureDetails& details, |
||
| 153 | const ExtensionList& extensions) const throw(SigningException); |
||
| 154 | }; |
||
| 155 | |||
| 156 | }; |
||
| 157 | };</code></pre> |