API » History » Version 7
Felix Tiede, 05/20/2013 08:50 AM
Support DSA type key-pair generation
| 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 | 6 | Felix Tiede | const QString message() const throw(); |
| 37 | |||
| 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 | TimeConstraint, |
||
| 55 | ExtensionError, |
||
| 56 | ObjectError, |
||
| 57 | }; |
||
| 58 | |||
| 59 | ~SigningException() throw(); |
||
| 60 | |||
| 61 | const Operation operation() const throw(); |
||
| 62 | const Failure failure() const throw(); |
||
| 63 | const QString description() const throw(); |
||
| 64 | |||
| 65 | protected: |
||
| 66 | SigningException(Operation operation, Failure failure, const QString& description) throw(); |
||
| 67 | |||
| 68 | void setFailure(Failure failure) throw(); |
||
| 69 | void setDescription(const QString& description) throw(); |
||
| 70 | }; |
||
| 71 | 6 | Felix Tiede | |
| 72 | |||
| 73 | class Extension { |
||
| 74 | public: |
||
| 75 | struct ObjectID { |
||
| 76 | QString oid; |
||
| 77 | QString shortName; |
||
| 78 | QString longName; |
||
| 79 | }; |
||
| 80 | |||
| 81 | Extension(const ObjectID& oid, const QString& value, |
||
| 82 | bool critical=false, bool replace=false); |
||
| 83 | ~Extension(); |
||
| 84 | |||
| 85 | const ObjectID oid() const; |
||
| 86 | |||
| 87 | const QString value() const; |
||
| 88 | void setValue(const QString& value); |
||
| 89 | |||
| 90 | bool critical() const; |
||
| 91 | void setCritical(bool critical); |
||
| 92 | |||
| 93 | bool replace() const; |
||
| 94 | void setReplace(bool replace); |
||
| 95 | |||
| 96 | bool operator==(const Extension& other) const; |
||
| 97 | Extension& operator=(const Extension& other); |
||
| 98 | |||
| 99 | protected: |
||
| 100 | Extension(const QString& name, const QString& value, |
||
| 101 | bool critical = false, bool replace = false) throw(OpenSSLException); |
||
| 102 | X509_EXTENSION* handle(X509V3_CTX* ctx = NULL) const throw(OpenSSLException); |
||
| 103 | }; |
||
| 104 | typedef QList< Extension > ExtensionList; |
||
| 105 | |||
| 106 | struct CRLEntry { |
||
| 107 | quint64 serial; |
||
| 108 | RevocationReason reason; |
||
| 109 | QDateTime timestamp; |
||
| 110 | }; |
||
| 111 | typedef QList< CRLEntry > CRL; |
||
| 112 | |||
| 113 | QString version(); |
||
| 114 | QString build_information(); |
||
| 115 | |||
| 116 | quint64 random(); |
||
| 117 | 7 | Felix Tiede | const QSslKey generateKeyPair(unsigned int length = 2048, QSsl::KeyType = QSsl::Rsa); |
| 118 | 6 | Felix Tiede | const QByteArray generateRequest(const QSslKey& key, |
| 119 | const QString& subject, |
||
| 120 | const ExtensionList& extensions, |
||
| 121 | Digest digest = SHA256); |
||
| 122 | |||
| 123 | ExtensionList emailCertExtensions(); |
||
| 124 | |||
| 125 | QString requestSubject(const QByteArray& request); |
||
| 126 | ExtensionList requestExtensions(const QByteArray& request); |
||
| 127 | |||
| 128 | 1 | Felix Tiede | |
| 129 | |||
| 130 | class Certificate : public QSslCertificate |
||
| 131 | { |
||
| 132 | public: |
||
| 133 | struct SignatureDetails { |
||
| 134 | quint64 serial; |
||
| 135 | Digest digest; |
||
| 136 | QDateTime effectiveDate; |
||
| 137 | QDateTime expiryDate; |
||
| 138 | }; |
||
| 139 | |||
| 140 | Certificate(const QSslKey& key, const QString& subject, |
||
| 141 | const SignatureDetails& details, const ExtensionList& extensions) throw(SigningException); |
||
| 142 | |||
| 143 | bool isCA() const; |
||
| 144 | bool keyMatch(const QSslKey& key) const; |
||
| 145 | |||
| 146 | const QSslCertificate sign(const QByteArray& request, const QSslKey& signingKey, |
||
| 147 | const SignatureDetails& details, |
||
| 148 | const ExtensionList& extensions) const throw(SigningException); |
||
| 149 | |||
| 150 | const QByteArray sign(const CRL& crl, const QSslKey& signingKey, |
||
| 151 | const SignatureDetails& details, |
||
| 152 | const ExtensionList& extensions) const throw(SigningException); |
||
| 153 | }; |
||
| 154 | |||
| 155 | }; |
||
| 156 | };</code></pre> |