Home | History | Annotate | Download | only in native
      1 /* Copyright (C) 2015 The Android Open Source Project
      2  *
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License. */
     14 
     15 /* This program generates output that is expected to become
     16  * NativeConstants.java. This reifies several OpenSSL constants into Java. */
     17 
     18 #include <stdio.h>
     19 
     20 #include <openssl/ec.h>
     21 #include <openssl/rsa.h>
     22 #include <openssl/ssl.h>
     23 #include <openssl/x509v3.h>
     24 #include <openssl/evp.h>
     25 #if defined(OPENSSL_IS_BORINGSSL)
     26 #include <openssl/aead.h>
     27 #endif
     28 
     29 static const char kCopyright[] =
     30     "/* Copyright (C) 2015 The Android Open Source Project\n"
     31     " *\n"
     32     " * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
     33     " * you may not use this file except in compliance with the License.\n"
     34     " * You may obtain a copy of the License at\n"
     35     " *\n"
     36     " *      http://www.apache.org/licenses/LICENSE-2.0\n"
     37     " *\n"
     38     " * Unless required by applicable law or agreed to in writing, software\n"
     39     " * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
     40     " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or "
     41     "implied.\n"
     42     " * See the License for the specific language governing permissions and\n"
     43     " * limitations under the License. */\n";
     44 
     45 int main(int /* argc */, char ** /* argv */) {
     46   printf("%s\n", kCopyright);
     47   printf("/* This file was generated by generate_constants.cc. */\n\n");
     48   printf("package org.conscrypt;\n\n");
     49   printf("public final class NativeConstants {\n");
     50 
     51   printf("    public static final boolean HAS_EVP_AEAD = %s;\n",
     52 #if defined(EVP_AEAD_DEFAULT_TAG_LENGTH)
     53          "true"
     54 #else
     55          "false"
     56 #endif
     57   );
     58 
     59 #define CONST(x) \
     60   printf("    public static final int %s = %ld;\n", #x, (long int)x)
     61 #define CONST_MINUS_1(x) printf("    public static final int %s = -1;\n", #x)
     62   CONST(OPENSSL_EC_NAMED_CURVE);
     63 
     64   CONST(POINT_CONVERSION_COMPRESSED);
     65   CONST(POINT_CONVERSION_UNCOMPRESSED);
     66 
     67   CONST(EXFLAG_CA);
     68   CONST(EXFLAG_CRITICAL);
     69 
     70   CONST(EVP_PKEY_RSA);
     71   CONST(EVP_PKEY_EC);
     72 
     73   CONST(RSA_PKCS1_PADDING);
     74   CONST(RSA_NO_PADDING);
     75   CONST(RSA_PKCS1_OAEP_PADDING);
     76   CONST(RSA_PKCS1_PSS_PADDING);
     77 
     78   CONST(SSL_MODE_SEND_FALLBACK_SCSV);
     79   CONST(SSL_MODE_CBC_RECORD_SPLITTING);
     80   CONST(SSL_MODE_HANDSHAKE_CUTTHROUGH);
     81 
     82   CONST(SSL_OP_CIPHER_SERVER_PREFERENCE);
     83   CONST(SSL_OP_NO_TICKET);
     84   CONST(SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
     85   CONST(SSL_OP_NO_SSLv3);
     86   CONST(SSL_OP_NO_TLSv1);
     87   CONST(SSL_OP_NO_TLSv1_1);
     88   CONST(SSL_OP_NO_TLSv1_2);
     89 
     90   CONST(SSL_SENT_SHUTDOWN);
     91   CONST(SSL_RECEIVED_SHUTDOWN);
     92 
     93   CONST(TLS_CT_RSA_SIGN);
     94   CONST(TLS_CT_ECDSA_SIGN);
     95 
     96 #if defined(TLS_CT_RSA_FIXED_DH)
     97   CONST(TLS_CT_RSA_FIXED_DH);
     98 #else
     99   CONST_MINUS_1(TLS_CT_RSA_FIXED_DH);
    100 #endif
    101 #if defined(TLS_CT_RSA_FIXED_ECDH)
    102   CONST(TLS_CT_RSA_FIXED_ECDH);
    103 #else
    104   CONST_MINUS_1(TLS_CT_RSA_FIXED_ECDH);
    105 #endif
    106 #if defined(TLS_CT_ECDSA_FIXED_ECDH)
    107   CONST(TLS_CT_ECDSA_FIXED_ECDH);
    108 #else
    109   CONST_MINUS_1(TLS_CT_ECDSA_FIXED_ECDH);
    110 #endif
    111 
    112   CONST(SSL_VERIFY_NONE);
    113   CONST(SSL_VERIFY_PEER);
    114   CONST(SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
    115 
    116   CONST(SSL_ST_CONNECT);
    117   CONST(SSL_ST_ACCEPT);
    118   CONST(SSL_ST_MASK);
    119   CONST(SSL_ST_INIT);
    120   CONST(SSL_ST_OK);
    121   CONST(SSL_ST_RENEGOTIATE);
    122   CONST(SSL_CB_LOOP);
    123   CONST(SSL_CB_EXIT);
    124   CONST(SSL_CB_READ);
    125   CONST(SSL_CB_WRITE);
    126   CONST(SSL_CB_ALERT);
    127   CONST(SSL_CB_READ_ALERT);
    128   CONST(SSL_CB_WRITE_ALERT);
    129   CONST(SSL_CB_ACCEPT_LOOP);
    130   CONST(SSL_CB_ACCEPT_EXIT);
    131   CONST(SSL_CB_CONNECT_LOOP);
    132   CONST(SSL_CB_CONNECT_EXIT);
    133   CONST(SSL_CB_HANDSHAKE_START);
    134   CONST(SSL_CB_HANDSHAKE_DONE);
    135 
    136   CONST(SSL3_RT_MAX_PACKET_SIZE);
    137 #undef CONST
    138 
    139   printf("}\n");
    140 
    141   return 0;
    142 }
    143