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