RT3963: Allow OCSP stapling with -rev and -www
[openssl.git] / crypto / x509v3 / v3_scts.c
index e70d5e927f362eeb0a88dd17491969fb9f58e882..61e5a83b68f0c1ec923f2288b041967b33554a4f 100644 (file)
  */
 
 #include <stdio.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/asn1.h>
 #include <openssl/x509v3.h>
-#include "../../ssl/ssl_locl.h"
-
-#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
-# define SCT_TIMESTAMP unsigned __int64
-#elif defined(__arch64__)
-# define SCT_TIMESTAMP unsigned long
-#else
-# define SCT_TIMESTAMP unsigned long long
-#endif
-
-#define n2l8(c,l)       (l =((SCT_TIMESTAMP)(*((c)++)))<<56, \
-                         l|=((SCT_TIMESTAMP)(*((c)++)))<<48, \
-                         l|=((SCT_TIMESTAMP)(*((c)++)))<<40, \
-                         l|=((SCT_TIMESTAMP)(*((c)++)))<<32, \
-                         l|=((SCT_TIMESTAMP)(*((c)++)))<<24, \
-                         l|=((SCT_TIMESTAMP)(*((c)++)))<<16, \
-                         l|=((SCT_TIMESTAMP)(*((c)++)))<< 8, \
-                         l|=((SCT_TIMESTAMP)(*((c)++))))
+
+/* Signature and hash algorithms from RFC 5246 */
+#define TLSEXT_hash_sha256                              4
+
+#define TLSEXT_signature_rsa                            1
+#define TLSEXT_signature_ecdsa                          3
+
+
+#define n2s(c,s)        ((s=(((unsigned int)(c[0]))<< 8)| \
+                            (((unsigned int)(c[1]))    )),c+=2)
+
+#define n2l8(c,l)       (l =((uint64_t)(*((c)++)))<<56, \
+                         l|=((uint64_t)(*((c)++)))<<48, \
+                         l|=((uint64_t)(*((c)++)))<<40, \
+                         l|=((uint64_t)(*((c)++)))<<32, \
+                         l|=((uint64_t)(*((c)++)))<<24, \
+                         l|=((uint64_t)(*((c)++)))<<16, \
+                         l|=((uint64_t)(*((c)++)))<< 8, \
+                         l|=((uint64_t)(*((c)++))))
 
 typedef struct SCT_st {
     /* The encoded SCT */
@@ -90,7 +91,7 @@ typedef struct SCT_st {
     unsigned char version;
     unsigned char *logid;
     unsigned short logidlen;
-    SCT_TIMESTAMP timestamp;
+    uint64_t timestamp;
     unsigned char *ext;
     unsigned short extlen;
     unsigned char hash_alg;
@@ -140,7 +141,7 @@ static void tls12_signature_print(BIO *out, const unsigned char hash_alg,
         BIO_printf(out, "%s", OBJ_nid2ln(nid));
 }
 
-static void timestamp_print(BIO *out, SCT_TIMESTAMP timestamp)
+static void timestamp_print(BIO *out, uint64_t timestamp)
 {
     ASN1_GENERALIZEDTIME *gen;
     char genstr[20];
@@ -161,11 +162,10 @@ static void timestamp_print(BIO *out, SCT_TIMESTAMP timestamp)
 
 static void SCT_free(SCT *sct)
 {
-    if (sct) {
-        if (sct->sct)
-            OPENSSL_free(sct->sct);
-        OPENSSL_free(sct);
-    }
+    if (!sct)
+        return;
+    OPENSSL_free(sct->sct);
+    OPENSSL_free(sct);
 }
 
 static void SCT_LIST_free(STACK_OF(SCT) *a)
@@ -204,7 +204,7 @@ static STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a,
             goto err;
         listlen -= sctlen;
 
-        sct = OPENSSL_malloc(sizeof(SCT));
+        sct = OPENSSL_malloc(sizeof(*sct));
         if (!sct)
             goto err;
         if (!sk_SCT_push(sk, sct)) {