SCT signature verification, encode/decode and accessor functions

On 8 September 2014 16:01, Rob Stradling <notifications@github.com> wrote:

> In crypto/x509v3/x509v3.h:
>
> > +	x509_entry = 0,
> > +	precert_entry = 1
> > +} LogEntryType;
> > +
> > +SCT *SCT_new(void);
> > +void SCT_free(SCT *sct);
> > +SCT *o2i_SCT(SCT **psct, const unsigned char **in, const size_t len);
> > +int i2o_SCT(const SCT *sct, unsigned char **out);
> > +int SCT_set0(SCT *sct, const unsigned char version, const char *logid_base64,
> > +	     const SCT_TIMESTAMP timestamp, const char *extensions_base64,
> > +	     const char *signature_base64);
> > +int SCT_get0_version(const SCT *sct, unsigned char *version);
> > +int SCT_get0_logid(const SCT *sct, unsigned char **logid, size_t *logidlen);
> > +int SCT_get0_timestamp(const SCT *sct, SCT_TIMESTAMP *timestamp);
> > +int SCT_get0_signature_nid(const SCT *sct, int *nid);
> > +int SCT_verify(const SCT *sct, const LogEntryType entry_type, X509 *cert,
>
> "const for the enum value" removed in 090da80
> <https://github.com/openssl/openssl/commit/090da80dd67a60d4ddd97cf6f09170cb12e5c6ac>
> .
>
> TBH, I'm not at all clear where constification is considered appropriate!
>
Value arguments don't need a const in the declaration: "we promise we won't
modify your passed-by-value argument" means nothing.

They could be constified in the definition to indicate that the value is
not changed throughout the method, however this I think is not usually done
in OpenSSL.

Pointer arguments should be const if they're read-only. However this is
often not possible for input arguments because of historical non-const-ness
in called methods. In this case, leave them alone.

Similarly, I think that  getters should generally be constified, e.g.:

/* No need to modify the returned group: can use EC_KEY_set_group instead.
*/
const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key);

The exception is probably SSL_CTX and friends where the interactions are
too messy, consider e.g.

/* Possibly need to modify existing SSL_CTX which is shared between
multiple SSL objects. */
SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);

—
> Reply to this email directly or view it on GitHub
> <https://github.com/openssl/openssl/pull/156/files#r17239096>.
>